Search in sources :

Example 41 with ActionHandler

use of org.eclipse.jface.commands.ActionHandler in project netxms by netxms.

the class MibExplorer method createActions.

/**
 * Create actions
 */
private void createActions() {
    final IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
    actionRefresh = new RefreshAction() {

        @Override
        public void run() {
            mibBrowser.refreshTree();
        }
    };
    actionWalk = new Action(Messages.get().MibExplorer_Walk) {

        @Override
        public void run() {
            doWalk();
        }
    };
    actionWalk.setEnabled(currentNode != null);
    actionSetNode = new Action(Messages.get().MibExplorer_SetNodeObject) {

        @Override
        public void run() {
            ObjectSelectionDialog dlg = new ObjectSelectionDialog(MibExplorer.this.getSite().getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(false));
            dlg.enableMultiSelection(false);
            if (dlg.open() == Window.OK) {
                setNode((AbstractNode) dlg.getSelectedObjects().get(0));
            }
        }
    };
    actionSelect = new Action("Select in MIB tree") {

        @Override
        public void run() {
            selectInTree();
        }
    };
    actionSelect.setEnabled(false);
    actionExportToCsv = new ExportToCsvAction(this, viewer, true);
    actionShowFilter = new Action("Show filter", Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            enableFilter(!initShowFilter);
            actionShowFilter.setChecked(initShowFilter);
        }
    };
    actionShowFilter.setChecked(initShowFilter);
    // $NON-NLS-1$
    actionShowFilter.setActionDefinitionId("org.netxms.ui.eclipse.snmp.commands.showFilter");
    handlerService.activateHandler(actionShowFilter.getActionDefinitionId(), new ActionHandler(actionShowFilter));
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) ExportToCsvAction(org.netxms.ui.eclipse.actions.ExportToCsvAction) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) IHandlerService(org.eclipse.ui.handlers.IHandlerService) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) AbstractNode(org.netxms.client.objects.AbstractNode) ExportToCsvAction(org.netxms.ui.eclipse.actions.ExportToCsvAction) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 42 with ActionHandler

use of org.eclipse.jface.commands.ActionHandler in project netxms by netxms.

the class MappingTableEditor method createActions.

/**
 * Create actions
 */
private void createActions() {
    final IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
    actionRefresh = new RefreshAction(this) {

        @Override
        public void run() {
            if (modified)
                if (!MessageDialogHelper.openQuestion(getSite().getShell(), Messages.get().MappingTableEditor_RefreshConfirmation, Messages.get().MappingTableEditor_RefreshConfirmationText))
                    return;
            refresh();
        }
    };
    actionNewRow = new Action(Messages.get().MappingTableEditor_NewRow, SharedIcons.ADD_OBJECT) {

        @Override
        public void run() {
            addNewRow();
        }
    };
    actionNewRow.setEnabled(false);
    // $NON-NLS-1$
    actionNewRow.setActionDefinitionId("org.netxms.ui.eclipse.serverconfig.commands.add_new_row");
    handlerService.activateHandler(actionNewRow.getActionDefinitionId(), new ActionHandler(actionNewRow));
    actionDelete = new Action(Messages.get().MappingTableEditor_Delete, SharedIcons.DELETE_OBJECT) {

        @Override
        public void run() {
            deleteRows();
        }
    };
    actionDelete.setEnabled(false);
    // $NON-NLS-1$
    actionDelete.setActionDefinitionId("org.netxms.ui.eclipse.serverconfig.commands.delete_rows");
    handlerService.activateHandler(actionDelete.getActionDefinitionId(), new ActionHandler(actionDelete));
    actionSave = new Action(Messages.get().MappingTableEditor_Save, SharedIcons.SAVE) {

        @Override
        public void run() {
            new SaveJob().start();
        }
    };
    actionSave.setEnabled(false);
}
Also used : Action(org.eclipse.jface.action.Action) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) IHandlerService(org.eclipse.ui.handlers.IHandlerService) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 43 with ActionHandler

use of org.eclipse.jface.commands.ActionHandler in project egit by eclipse.

the class ActionUtils method setGlobalActions.

/**
 * Hooks up the {@link Control} such that the given {@link IAction}s are
 * registered with the given {@link IHandlerService} while the control has
 * the focus. Ensures that actions are properly de-registered when the
 * control is disposed.
 *
 * @param control
 *            to hook up
 * @param actions
 *            to be registered while the control has the focus
 * @param service
 *            to register the actions with
 */
public static void setGlobalActions(Control control, Collection<? extends IAction> actions, IHandlerService service) {
    Collection<IHandlerActivation> handlerActivations = new ArrayList<>();
    control.addDisposeListener(event -> {
        if (!handlerActivations.isEmpty()) {
            service.deactivateHandlers(handlerActivations);
            handlerActivations.clear();
        }
    });
    final ActiveShellExpression expression = new ActiveShellExpression(control.getShell());
    control.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (!handlerActivations.isEmpty()) {
                service.deactivateHandlers(handlerActivations);
                handlerActivations.clear();
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
            if (!handlerActivations.isEmpty()) {
                // Looks like sometimes we get two focusGained events.
                return;
            }
            for (final IAction action : actions) {
                handlerActivations.add(service.activateHandler(action.getActionDefinitionId(), new ActionHandler(action), expression, false));
                if (action instanceof IUpdate) {
                    ((IUpdate) action).update();
                }
            }
        }
    });
}
Also used : IAction(org.eclipse.jface.action.IAction) IHandlerActivation(org.eclipse.ui.handlers.IHandlerActivation) ArrayList(java.util.ArrayList) ActiveShellExpression(org.eclipse.ui.ActiveShellExpression) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent) ActionHandler(org.eclipse.jface.commands.ActionHandler) IUpdate(org.eclipse.ui.texteditor.IUpdate)

Example 44 with ActionHandler

use of org.eclipse.jface.commands.ActionHandler in project mylyn.docs by eclipse.

the class MarkupEditor method setAction.

@Override
public void setAction(String actionID, IAction action) {
    if (action != null && action.getActionDefinitionId() != null && !isCommandAction(action)) {
        // bug 336679: don't activate handlers for CommandAction.
        // We do this by class name so that we don't rely on internals
        IHandlerService handlerService = getSite().getService(IHandlerService.class);
        handlerService.activateHandler(action.getActionDefinitionId(), new ActionHandler(action));
    }
    super.setAction(actionID, action);
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 45 with ActionHandler

use of org.eclipse.jface.commands.ActionHandler in project archi by archimatetool.

the class AbstractDiagramEditor method createActions.

/**
 * Add some extra Actions - *after* the graphical viewer has been created
 */
@SuppressWarnings("unchecked")
protected void createActions(GraphicalViewer viewer) {
    ActionRegistry registry = getActionRegistry();
    IAction action;
    // Zoom Manager tweaking
    ZoomManager zoomManager = (ZoomManager) getAdapter(ZoomManager.class);
    double[] zoomLevels = { .25, .5, .75, 1, 1.5, 2, 3, 4, 6, 8 };
    zoomManager.setZoomLevels(zoomLevels);
    List<String> zoomContributionLevels = new ArrayList<String>();
    zoomContributionLevels.add(ZoomManager.FIT_ALL);
    zoomContributionLevels.add(ZoomManager.FIT_WIDTH);
    zoomContributionLevels.add(ZoomManager.FIT_HEIGHT);
    zoomManager.setZoomLevelContributions(zoomContributionLevels);
    // Zoom Actions
    IAction zoomIn = new ZoomInAction(zoomManager);
    IAction zoomOut = new ZoomOutAction(zoomManager);
    IAction zoomNormal = new ZoomNormalAction(zoomManager);
    registry.registerAction(zoomIn);
    registry.registerAction(zoomOut);
    registry.registerAction(zoomNormal);
    // Add these zoom actions to the key binding service
    IHandlerService service = getEditorSite().getService(IHandlerService.class);
    service.activateHandler(zoomIn.getActionDefinitionId(), new ActionHandler(zoomIn));
    service.activateHandler(zoomOut.getActionDefinitionId(), new ActionHandler(zoomOut));
    service.activateHandler(zoomNormal.getActionDefinitionId(), new ActionHandler(zoomNormal));
    // Add our own Select All Action so we can select connections as well
    action = new SelectAllAction(this);
    registry.registerAction(action);
    // Add our own Print Action
    action = new PrintDiagramAction(this);
    registry.registerAction(action);
    // Direct Edit Rename
    action = new DirectEditAction(this);
    // Set this for Global Handler
    action.setId(ActionFactory.RENAME.getId());
    // Externalise this one
    action.setText(Messages.AbstractDiagramEditor_4);
    action.setToolTipText(Messages.AbstractDiagramEditor_13);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Change the Delete Action label
    action = registry.getAction(ActionFactory.DELETE.getId());
    action.setText(Messages.AbstractDiagramEditor_2);
    action.setToolTipText(action.getText());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Paste
    PasteAction pasteAction = new PasteAction(this, viewer);
    registry.registerAction(pasteAction);
    getSelectionActions().add(pasteAction.getId());
    // Paste Special
    PasteSpecialAction pasteSpecialAction = new PasteSpecialAction(this, viewer);
    registry.registerAction(pasteSpecialAction);
    getSelectionActions().add(pasteSpecialAction.getId());
    // Cut
    action = new CutAction(this, pasteAction);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Copy
    action = new CopyAction(this, pasteAction);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Use Grid Action
    action = new ToggleGridEnabledAction();
    registry.registerAction(action);
    // Show Grid Action
    action = new ToggleGridVisibleAction();
    registry.registerAction(action);
    // Snap to Alignment Guides
    action = new ToggleSnapToAlignmentGuidesAction();
    registry.registerAction(action);
    // Ruler
    // IAction showRulers = new ToggleRulerVisibilityAction(getGraphicalViewer());
    // registry.registerAction(showRulers);
    action = new MatchWidthAction(this);
    // Externalise string as it's internal to GEF
    action.setText(Messages.AbstractDiagramEditor_5);
    action.setToolTipText(Messages.AbstractDiagramEditor_14);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new MatchHeightAction(this);
    registry.registerAction(action);
    // Externalise string as it's internal to GEF
    action.setText(Messages.AbstractDiagramEditor_6);
    action.setToolTipText(Messages.AbstractDiagramEditor_15);
    getSelectionActions().add(action.getId());
    action = new MatchSizeAction(this);
    registry.registerAction(action);
    // Externalise string as it's internal to GEF
    action.setText(Messages.AbstractDiagramEditor_22);
    action.setToolTipText(Messages.AbstractDiagramEditor_23);
    getSelectionActions().add(action.getId());
    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.LEFT);
    // Externalise string as it's internal to GEF
    action.setText(Messages.AbstractDiagramEditor_7);
    action.setToolTipText(Messages.AbstractDiagramEditor_16);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.RIGHT);
    // Externalise string as it's internal to GEF
    action.setText(Messages.AbstractDiagramEditor_8);
    action.setToolTipText(Messages.AbstractDiagramEditor_17);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.TOP);
    // Externalise string as it's internal to GEF
    action.setText(Messages.AbstractDiagramEditor_9);
    action.setToolTipText(Messages.AbstractDiagramEditor_18);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.BOTTOM);
    // Externalise string as it's internal to GEF
    action.setText(Messages.AbstractDiagramEditor_10);
    action.setToolTipText(Messages.AbstractDiagramEditor_19);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.CENTER);
    // Externalise string as it's internal to GEF
    action.setText(Messages.AbstractDiagramEditor_11);
    action.setToolTipText(Messages.AbstractDiagramEditor_20);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.MIDDLE);
    // Externalise string as it's internal to GEF
    action.setText(Messages.AbstractDiagramEditor_12);
    action.setToolTipText(Messages.AbstractDiagramEditor_21);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    // Default Size
    action = new DefaultEditPartSizeAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Reset Aspect Ratio
    action = new ResetAspectRatioAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Properties
    action = new PropertiesAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    // Fill Colour
    action = new FillColorAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Connection Line Width
    action = new ConnectionLineWidthAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Connection Line Color
    action = new LineColorAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Font
    action = new FontAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Font Colour
    action = new FontColorAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Fill Opacity
    action = new OpacityAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Outline Opacity
    action = new OutlineOpacityAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Export As Image
    action = new ExportAsImageAction(this);
    registry.registerAction(action);
    // Export As Image to Clipboard
    action = new ExportAsImageToClipboardAction(this);
    registry.registerAction(action);
    // Connection Router types
    action = new ConnectionRouterAction.BendPointConnectionRouterAction(this);
    registry.registerAction(action);
    action = new ConnectionRouterAction.ManhattanConnectionRouterAction(this);
    registry.registerAction(action);
    // Send Backward
    action = new SendBackwardAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Bring Forward
    action = new BringForwardAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Send to Back
    action = new SendToBackAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Bring To Front
    action = new BringToFrontAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Text Alignment Actions
    for (TextAlignmentAction a : TextAlignmentAction.createActions(this)) {
        registry.registerAction(a);
        getSelectionActions().add(a.getId());
        getUpdateCommandStackActions().add(a);
    }
    // Text Position Actions
    for (TextPositionAction a : TextPositionAction.createActions(this)) {
        registry.registerAction(a);
        getSelectionActions().add(a.getId());
        getUpdateCommandStackActions().add(a);
    }
    // Lock Object
    action = new LockObjectAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Border Color
    action = new BorderColorAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    getUpdateCommandStackActions().add((UpdateAction) action);
    // Full Screen
    if (!PlatformUtils.isMac()) {
        action = new FullScreenAction(this);
        registry.registerAction(action);
    }
    // Select Element in Tree
    action = new SelectElementInTreeAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
}
Also used : MatchHeightAction(org.eclipse.gef.ui.actions.MatchHeightAction) MatchSizeAction(org.eclipse.gef.ui.actions.MatchSizeAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) ArrayList(java.util.ArrayList) LineColorAction(com.archimatetool.editor.diagram.actions.LineColorAction) ConnectionRouterAction(com.archimatetool.editor.diagram.actions.ConnectionRouterAction) TextPositionAction(com.archimatetool.editor.diagram.actions.TextPositionAction) FullScreenAction(com.archimatetool.editor.diagram.actions.FullScreenAction) ActionRegistry(org.eclipse.gef.ui.actions.ActionRegistry) PropertiesAction(com.archimatetool.editor.diagram.actions.PropertiesAction) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ZoomNormalAction(com.archimatetool.editor.diagram.actions.ZoomNormalAction) DirectEditAction(org.eclipse.gef.ui.actions.DirectEditAction) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) MatchWidthAction(org.eclipse.gef.ui.actions.MatchWidthAction) FillColorAction(com.archimatetool.editor.diagram.actions.FillColorAction) SendToBackAction(com.archimatetool.editor.diagram.actions.SendToBackAction) ToggleGridEnabledAction(com.archimatetool.editor.diagram.actions.ToggleGridEnabledAction) BringForwardAction(com.archimatetool.editor.diagram.actions.BringForwardAction) ConnectionLineWidthAction(com.archimatetool.editor.diagram.actions.ConnectionLineWidthAction) TextAlignmentAction(com.archimatetool.editor.diagram.actions.TextAlignmentAction) IHandlerService(org.eclipse.ui.handlers.IHandlerService) SelectAllAction(com.archimatetool.editor.diagram.actions.SelectAllAction) ExportAsImageToClipboardAction(com.archimatetool.editor.diagram.actions.ExportAsImageToClipboardAction) OpacityAction(com.archimatetool.editor.diagram.actions.OpacityAction) OutlineOpacityAction(com.archimatetool.editor.diagram.actions.OutlineOpacityAction) ActionHandler(org.eclipse.jface.commands.ActionHandler) PrintDiagramAction(com.archimatetool.editor.diagram.actions.PrintDiagramAction) CutAction(com.archimatetool.editor.diagram.actions.CutAction) PasteSpecialAction(com.archimatetool.editor.diagram.actions.PasteSpecialAction) FontColorAction(com.archimatetool.editor.diagram.actions.FontColorAction) ResetAspectRatioAction(com.archimatetool.editor.diagram.actions.ResetAspectRatioAction) BringToFrontAction(com.archimatetool.editor.diagram.actions.BringToFrontAction) SelectElementInTreeAction(com.archimatetool.editor.diagram.actions.SelectElementInTreeAction) IAction(org.eclipse.jface.action.IAction) CopyAction(com.archimatetool.editor.diagram.actions.CopyAction) TextAlignmentAction(com.archimatetool.editor.diagram.actions.TextAlignmentAction) AlignmentAction(org.eclipse.gef.ui.actions.AlignmentAction) ToggleGridVisibleAction(com.archimatetool.editor.diagram.actions.ToggleGridVisibleAction) FontAction(com.archimatetool.editor.diagram.actions.FontAction) SendBackwardAction(com.archimatetool.editor.diagram.actions.SendBackwardAction) DefaultEditPartSizeAction(com.archimatetool.editor.diagram.actions.DefaultEditPartSizeAction) PasteAction(com.archimatetool.editor.diagram.actions.PasteAction) BorderColorAction(com.archimatetool.editor.diagram.actions.BorderColorAction) ZoomManager(org.eclipse.gef.editparts.ZoomManager) ToggleSnapToAlignmentGuidesAction(com.archimatetool.editor.diagram.actions.ToggleSnapToAlignmentGuidesAction) OutlineOpacityAction(com.archimatetool.editor.diagram.actions.OutlineOpacityAction) ExportAsImageAction(com.archimatetool.editor.diagram.actions.ExportAsImageAction) LockObjectAction(com.archimatetool.editor.diagram.actions.LockObjectAction)

Aggregations

ActionHandler (org.eclipse.jface.commands.ActionHandler)47 IHandlerService (org.eclipse.ui.handlers.IHandlerService)45 Action (org.eclipse.jface.action.Action)36 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)23 IAction (org.eclipse.jface.action.IAction)6 IContextService (org.eclipse.ui.contexts.IContextService)5 ExportToCsvAction (org.netxms.ui.eclipse.actions.ExportToCsvAction)5 ArrayList (java.util.ArrayList)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 FocusEvent (org.eclipse.swt.events.FocusEvent)3 FocusListener (org.eclipse.swt.events.FocusListener)3 ActiveShellExpression (org.eclipse.ui.ActiveShellExpression)3 IHandlerActivation (org.eclipse.ui.handlers.IHandlerActivation)3 IActionBars (org.eclipse.ui.IActionBars)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 ServerAction (org.netxms.client.ServerAction)2 BorderColorAction (com.archimatetool.editor.diagram.actions.BorderColorAction)1 BringForwardAction (com.archimatetool.editor.diagram.actions.BringForwardAction)1 BringToFrontAction (com.archimatetool.editor.diagram.actions.BringToFrontAction)1 ConnectionLineWidthAction (com.archimatetool.editor.diagram.actions.ConnectionLineWidthAction)1