@Override public void addAction(final IAction action) { Check.notNull(action, "action"); //$NON-NLS-1$ final String commandId = action.getActionDefinitionId(); if (commandId == null) { throw new IllegalArgumentException("action does not have an action definition ID set"); //$NON-NLS-1$ } final TriggerSequence[] bindings = bindingService.getActiveBindingsFor(commandId); if (bindings.length > 0) { final IHandler handler = new ActionHandler(action); /* * Call this deprecated overload for 3.1 support */ final IHandlerActivation activation = handlerService.activateHandler(commandId, handler, expression, sourcePriorities); handlerActivations.add(activation); } }
@Override public void dispose() { for (IHandler h : handlers) { h.dispose(); } handlers.clear(); CoverageTools.removeJavaCoverageListener(coverageListener); CoverageTools.getSessionManager().removeSessionListener(descriptionUpdater); selectiontracker.dispose(); super.dispose(); }
private void executeHandler(IHandler handler, ExecutionEvent event) { UIThreadRunnable.syncExec(()->{ try { return handler.execute(event); } catch (ExecutionException e) { throw new RuntimeException(e); } }); }
@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); } }
/** * 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)) { Beeper.setBeepon(false); // disable beep if in content assist } }
/** * {@inheritDoc} */ @Override public void widgetSelected(SelectionEvent event) { IHandler handler; if (isShow) { handler = new NodeChildrenShowHandler(); } else { handler = new NodeChildrenHideHandler(); } try { handler.execute(null); } catch (Exception e) { e.printStackTrace(); } }
private void activateHandler(String id, IHandler handler) { final IHandlerService hs = (IHandlerService) getSite().getService( IHandlerService.class); hs.activateHandler(id, handler); handlers.add(handler); }
/** * 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); } }
/** * Returns the handler for the given command identifier. * * <p>The same handler instance will be returned when called a more than once with the same * command identifier. * * @param commandId the command identifier * @return the handler for the given command identifier * @throws IllegalArgumentException if the command is not supported by this content assistant * @throws IllegalStateException if called when this content assistant is uninstalled */ IHandler getHandler(String commandId);
/** * Sets the help context identifier to associate with a particular handler. * * @param handler * The handler with which to register a help context identifier; * must not be <code>null</code>. * @param helpContextId * The help context identifier to register; may be * <code>null</code> if the help context identifier should be * removed. * @since 3.2 */ public void setHelpContextId(IHandler handler, String helpContextId);
/** * <p> * Activates the given handler within the context of this service. If this * service was retrieved from the workbench, then this handler will be * active globally. If the service was retrieved from a nested component, * then the handler will only be active within that component. * </p> * <p> * Also, it is guaranteed that the handlers submitted through a particular * service will be cleaned up when that services is destroyed. So, for * example, a service retrieved from a <code>IWorkbenchPartSite</code> would * deactivate all of its handlers when the site is destroyed. * </p> * * @param commandId * The identifier for the command which this handler handles; * must not be <code>null</code>. * @param handler * The handler to activate; must not be <code>null</code>. * @return A token which can be used to later cancel the activation. Only * someone with access to this token can cancel the activation. The * activation will automatically be cancelled if the context from * which this service was retrieved is destroyed. */ public IHandlerActivation activateHandler(String commandId, IHandler handler);
/** * <p> * Activates the given handler within the context of this service. The * handler becomes active when <code>expression</code> evaluates to * <code>true</code>. This is the same as calling * {@link #activateHandler(String, IHandler, Expression, boolean)} with * global==false. * </p> * <p> * Also, it is guaranteed that the handlers submitted through a particular * service will be cleaned up when that service is destroyed. So, for * example, a service retrieved from a <code>IWorkbenchPartSite</code> would * deactivate all of its handlers when the site is destroyed. * </p> * * @param commandId * The identifier for the command which this handler handles; * must not be <code>null</code>. * @param handler * The handler to activate; must not be <code>null</code>. * @param expression * This expression must evaluate to <code>true</code> before this * handler will really become active. The expression may be * <code>null</code> if the handler should always be active. * @return A token which can be used to later cancel the activation. Only * someone with access to this token can cancel the activation. The * activation will automatically be cancelled if the context from * which this service was retrieved is destroyed. * * @see org.eclipse.ui.ISources * @since 3.2 */ public IHandlerActivation activateHandler(String commandId, IHandler handler, Expression expression);
/** * <p> * Activates the given handler within the context of this service. The * handler becomes active when <code>expression</code> evaluates to * <code>true</code>. if global==<code>false</code>, then this handler * service must also be the active service to active the handler. For * example, the handler service on a part is active when that part is * active. * </p> * <p> * Also, it is guaranteed that the handlers submitted through a particular * service will be cleaned up when that services is destroyed. So, for * example, a service retrieved from a <code>IWorkbenchPartSite</code> would * deactivate all of its handlers when the site is destroyed. * </p> * * @param commandId * The identifier for the command which this handler handles; * must not be <code>null</code>. * @param handler * The handler to activate; must not be <code>null</code>. * @param expression * This expression must evaluate to <code>true</code> before this * handler will really become active. The expression may be * <code>null</code> if the handler should always be active. * @param global * Indicates that the handler should be activated irrespectively * of whether the corresponding workbench component (e.g., * window, part, etc.) is active. * @return A token which can be used to later cancel the activation. Only * someone with access to this token can cancel the activation. The * activation will automatically be cancelled if the context from * which this service was retrieved is destroyed. * * @see org.eclipse.ui.ISources * @since 3.2 */ public IHandlerActivation activateHandler(String commandId, IHandler handler, Expression expression, boolean global);
/** * <p> * Activates the given handler within the context of this service. The * handler becomes active when <code>expression</code> evaluates to * <code>true</code>. * </p> * <p> * Also, it is guaranteed that the handlers submitted through a particular * service will be cleaned up when that services is destroyed. So, for * example, a service retrieved from a <code>IWorkbenchPartSite</code> would * deactivate all of its handlers when the site is destroyed. * </p> * * @param commandId * The identifier for the command which this handler handles; * must not be <code>null</code>. * @param handler * The handler to activate; must not be <code>null</code>. * @param expression * This expression must evaluate to <code>true</code> before this * handler will really become active. The expression may be * <code>null</code> if the handler should always be active. * @param sourcePriorities * The source priorities for the expression. * @return A token which can be used to later cancel the activation. Only * someone with access to this token can cancel the activation. The * activation will automatically be cancelled if the context from * which this service was retrieved is destroyed. * * @see org.eclipse.ui.ISources * @deprecated Use * {@link IHandlerService#activateHandler(String, IHandler, Expression)} * instead. */ public IHandlerActivation activateHandler(String commandId, IHandler handler, Expression expression, int sourcePriorities);
/** * Returns the handler that should be activated. * * @return The handler; may be <code>null</code>. */ public IHandler getHandler();