org.eclipse.core.commands.IHandler Java Examples

The following examples show how to use org.eclipse.core.commands.IHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShowHierarchyTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #2
Source File: OpenWithQuickMenuCommandPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@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 );
}
 
Example #3
Source File: DeleteEditorFileCommandPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@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 );
}
 
Example #4
Source File: CloseViewCommandPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@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 );
}
 
Example #5
Source File: LaunchCommandPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@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 );
}
 
Example #6
Source File: GenerateActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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);
	}
}
 
Example #7
Source File: RefactorActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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);
	}
}
 
Example #8
Source File: JDTQuickMenuCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
		}
	};
}
 
Example #9
Source File: EmacsOverrunHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
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 
	}
}
 
Example #10
Source File: GlobalActions.java    From elexis-3-core with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * 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);
	}
}