|
Lines 11-18
Link Here
|
| 11 |
|
11 |
|
| 12 |
import org.eclipse.core.commands.Command; |
12 |
import org.eclipse.core.commands.Command; |
| 13 |
import org.eclipse.core.commands.CommandManager; |
13 |
import org.eclipse.core.commands.CommandManager; |
| 14 |
import org.eclipse.core.commands.ExecutionEvent; |
|
|
| 15 |
import org.eclipse.core.commands.ExecutionException; |
14 |
import org.eclipse.core.commands.ExecutionException; |
|
|
15 |
import org.eclipse.core.commands.NotEnabledException; |
| 16 |
import org.eclipse.core.commands.NotHandledException; |
| 17 |
import org.eclipse.core.commands.common.NotDefinedException; |
| 16 |
import org.eclipse.jface.action.Action; |
18 |
import org.eclipse.jface.action.Action; |
| 17 |
import org.eclipse.jface.action.IAction; |
19 |
import org.eclipse.jface.action.IAction; |
| 18 |
import org.eclipse.jface.action.MenuManager; |
20 |
import org.eclipse.jface.action.MenuManager; |
|
Lines 20-25
Link Here
|
| 20 |
import org.eclipse.swt.SWT; |
22 |
import org.eclipse.swt.SWT; |
| 21 |
import org.eclipse.swt.graphics.Image; |
23 |
import org.eclipse.swt.graphics.Image; |
| 22 |
import org.eclipse.swt.widgets.Composite; |
24 |
import org.eclipse.swt.widgets.Composite; |
|
|
25 |
import org.eclipse.swt.widgets.Event; |
| 23 |
import org.eclipse.swt.widgets.Menu; |
26 |
import org.eclipse.swt.widgets.Menu; |
| 24 |
import org.eclipse.swt.widgets.ToolBar; |
27 |
import org.eclipse.swt.widgets.ToolBar; |
| 25 |
import org.eclipse.swt.widgets.ToolItem; |
28 |
import org.eclipse.swt.widgets.ToolItem; |
|
Lines 27-32
Link Here
|
| 27 |
import org.eclipse.ui.IWorkbenchWindow; |
30 |
import org.eclipse.ui.IWorkbenchWindow; |
| 28 |
import org.eclipse.ui.PlatformUI; |
31 |
import org.eclipse.ui.PlatformUI; |
| 29 |
import org.eclipse.ui.commands.ICommandService; |
32 |
import org.eclipse.ui.commands.ICommandService; |
|
|
33 |
import org.eclipse.ui.handlers.IHandlerService; |
| 30 |
import org.eclipse.ui.menus.CommandContributionItem; |
34 |
import org.eclipse.ui.menus.CommandContributionItem; |
| 31 |
import org.eclipse.ui.menus.IMenuService; |
35 |
import org.eclipse.ui.menus.IMenuService; |
| 32 |
|
36 |
|
|
Lines 105-117
Link Here
|
| 105 |
result = new Action( text, style ){ |
109 |
result = new Action( text, style ){ |
| 106 |
public void run() { |
110 |
public void run() { |
| 107 |
Command command = param.getCommand(); |
111 |
Command command = param.getCommand(); |
| 108 |
if( command != null ) { |
112 |
executeCommand( command ); |
| 109 |
try { |
|
|
| 110 |
command.getHandler().execute( new ExecutionEvent() ); |
| 111 |
} catch( final ExecutionException e ) { |
| 112 |
e.printStackTrace(); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
113 |
} |
| 116 |
}; |
114 |
}; |
| 117 |
ImageDescriptor desc = new ImageDescriptor() { |
115 |
ImageDescriptor desc = new ImageDescriptor() { |
|
Lines 181-184
Link Here
|
| 181 |
toolbar.dispose(); |
179 |
toolbar.dispose(); |
| 182 |
return result; |
180 |
return result; |
| 183 |
} |
181 |
} |
|
|
182 |
|
| 183 |
public static void executeCommand( final Command command ) { |
| 184 |
if( command != null ) { |
| 185 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
| 186 |
Object service = workbench.getService( IHandlerService.class ); |
| 187 |
if( service != null && service instanceof IHandlerService ) { |
| 188 |
IHandlerService handlerService = ( IHandlerService ) service; |
| 189 |
try { |
| 190 |
handlerService.executeCommand( command.getId(), new Event() ); |
| 191 |
} catch( ExecutionException e ) { |
| 192 |
e.printStackTrace(); |
| 193 |
} catch( NotDefinedException e ) { |
| 194 |
e.printStackTrace(); |
| 195 |
} catch( NotEnabledException e ) { |
| 196 |
e.printStackTrace(); |
| 197 |
} catch( NotHandledException e ) { |
| 198 |
e.printStackTrace(); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 184 |
} |
203 |
} |