下面列出了org.eclipse.ui.part.ViewPart#org.eclipse.core.commands.IHandler 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private TestingTypeHierarchyHandler invokeTestingHandler(XtextEditor xtextEditor, String commandID) throws Exception {
IHandlerService handlerService = xtextEditor.getSite().getService(IHandlerService.class);
final ICommandService commandService = xtextEditor.getSite()
.getService(ICommandService.class);
Command command = commandService.getCommand("org.eclipse.xtext.xbase.ui.hierarchy.OpenTypeHierarchy");
TestingTypeHierarchyHandler testingHandler = new TestingTypeHierarchyHandler();
getInjector().injectMembers(testingHandler);
IHandler originalHandler = command.getHandler();
command.setHandler(testingHandler);
final ExecutionEvent event = new ExecutionEvent(command,
Collections.EMPTY_MAP, null, handlerService.getCurrentState());
command.executeWithChecks(event);
command.setHandler(originalHandler);
return testingHandler;
}
@Test
public void testExtension() {
Extension extension = readCommandExtension();
assertThat( extension.getAttribute( "name" ) ).isNotEmpty();
assertThat( extension.getAttribute( "description" ) ).isNotEmpty();
assertThat( extension.getAttribute( "categoryId" ) ).isEqualTo( "org.eclipse.ui.category.file" );
IHandler handler = extension.createExecutableExtension( "defaultHandler", IHandler.class );
assertThat( handler ).isInstanceOf( OpenWithQuickMenuHandler.class );
}
@Test
public void testExtension() {
Extension extension = readCommandExtension();
assertThat( extension.getAttribute( "name" ) ).isNotEmpty();
assertThat( extension.getAttribute( "description" ) ).isNotEmpty();
assertThat( extension.getAttribute( "categoryId" ) ).isEqualTo( "org.eclipse.ui.category.file" );
IHandler handler = extension.createExecutableExtension( "defaultHandler", IHandler.class );
assertThat( handler ).isInstanceOf( DeleteEditorFileHandler.class );
}
@Test
public void testExtension() {
Extension extension = readCommandExtension();
assertThat( extension.getAttribute( "name" ) ).isNotEmpty();
assertThat( extension.getAttribute( "description" ) ).isNotEmpty();
assertThat( extension.getAttribute( "categoryId" ) ).isEqualTo( "org.eclipse.ui.category.views" );
IHandler handler = extension.createExecutableExtension( "defaultHandler", IHandler.class );
assertThat( handler ).isInstanceOf( CloseViewHandler.class );
}
@Test
public void testExtension() {
Extension extension = readCommandExtension();
assertThat( extension.getAttribute( "name" ) ).isNotEmpty();
assertThat( extension.getAttribute( "description" ) ).isNotEmpty();
assertThat( extension.getAttribute( "categoryId" ) ).isEqualTo( "org.eclipse.debug.ui.category.run" );
IHandler handler = extension.createExecutableExtension( "defaultHandler", IHandler.class );
assertThat( handler ).isInstanceOf( OpenLaunchDialogHander.class );
}
private void installQuickAccessAction() {
fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class);
if (fHandlerService != null) {
IHandler handler= new JDTQuickMenuCreator(fEditor) {
@Override
protected void fillMenu(IMenuManager menu) {
fillQuickMenu(menu);
}
}.createHandler();
fQuickAccessHandlerActivation= fHandlerService.activateHandler(QUICK_MENU_ID, handler);
}
}
private void installQuickAccessAction() {
fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class);
if (fHandlerService != null) {
IHandler handler= new JDTQuickMenuCreator(fEditor) {
@Override
protected void fillMenu(IMenuManager menu) {
fillQuickMenu(menu);
}
}.createHandler();
fQuickAccessHandlerActivation= fHandlerService.activateHandler(QUICK_MENU_ID, handler);
}
}
/**
* Returns a handler that can create and open the quick menu.
*
* @return a handler that can create and open the quick menu
*/
public IHandler createHandler() {
return new AbstractHandler() {
public Object execute(ExecutionEvent event) throws ExecutionException {
createMenu();
return null;
}
};
}
public void preExecute(String commandId, ExecutionEvent event) {
IHandler handler = event.getCommand().getHandler();
// The handler class is not visible
if (handler != null && handler.getClass().getName().startsWith(ASSIST_HANDLER)) {
// disable beep if in content assist
Beeper.setBeepon(false); // will be set back in the finally clause
}
}
/**
* Creates an ActionHandler for the given IAction and registers it to the Site's HandlerService,
* i. e. binds the action to the command so that key bindings get activated. You need to set the
* action's actionDefinitionId to the command id.
*
* @param action
* the action to activate. The action's actionDefinitionId must have been set to the
* command's id (using <code>setActionDefinitionId()</code>)
* @param part
* the view this action should be registered for
*/
public static void registerActionHandler(final ViewPart part, final IAction action){
String commandId = action.getActionDefinitionId();
if (!StringTool.isNothing(commandId)) {
IHandlerService handlerService = part.getSite().getService(IHandlerService.class);
IHandler handler = new ActionHandler(action);
handlerService.activateHandler(commandId, handler);
}
}