Search in sources :

Example 71 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project org.csstudio.display.builder by kasemir.

the class RCPUtil method doExecuteEclipseCommand.

private static final void doExecuteEclipseCommand(String commandId, String... parameters) {
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    final IHandlerService handlerService = window.getService(IHandlerService.class);
    try {
        if (parameters.length % 2 != 0)
            throw new IllegalArgumentException("Parameterized commands must have " + "an equal number of keys and values");
        if (parameters.length == 0)
            handlerService.executeCommand(commandId, null);
        else {
            final ICommandService commandService = window.getService(ICommandService.class);
            final Parameterization[] params = new Parameterization[parameters.length / 2];
            final Command c = commandService.getCommand(commandId);
            for (int i = 0; i < parameters.length / 2; i++) {
                final String key = parameters[2 * i];
                final String value = parameters[2 * i + 1];
                final IParameter p = c.getParameter(key);
                final Parameterization pp = new Parameterization(p, value);
                params[i] = pp;
            }
            final ParameterizedCommand pc = new ParameterizedCommand(c, params);
            handlerService.executeCommand(pc, null);
        }
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Failed to execute eclipse command '" + commandId + "' " + Arrays.toString(parameters), ex);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IParameter(org.eclipse.core.commands.IParameter) IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) Parameterization(org.eclipse.core.commands.Parameterization) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 72 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project netxms by netxms.

the class NXFindAndReplaceAction method getFindReplaceAction.

public static FindReplaceAction getFindReplaceAction(ViewPart wp) {
    FindReplaceAction action = null;
    try {
        // $NON-NLS-1$
        action = new FindReplaceAction(getResourceBundle(wp), "actions.find_and_replace.", wp);
        IHandlerService hs = (IHandlerService) wp.getSite().getService(IHandlerService.class);
        // $NON-NLS-1$
        hs.activateHandler("org.eclipse.ui.edit.findReplace", new ActionHandler(action));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return action;
}
Also used : FindReplaceAction(org.eclipse.ui.texteditor.FindReplaceAction) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IOException(java.io.IOException) ActionHandler(org.eclipse.ui.commands.ActionHandler)

Example 73 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project netxms by netxms.

the class EventObjectList method createActions.

/**
 * Create actions
 */
private void createActions() {
    actionNew = new Action(Messages.get().EventConfigurator_NewEvent, SharedIcons.ADD_OBJECT) {

        @Override
        public void run() {
            createNewEventTemplate();
        }
    };
    // $NON-NLS-1$
    actionNew.setActionDefinitionId("org.netxms.ui.eclipse.eventmanager.commands.new_event_template");
    actionEdit = new // $NON-NLS-1$
    Action(// $NON-NLS-1$
    Messages.get().EventConfigurator_Properties, // $NON-NLS-1$
    SharedIcons.EDIT) {

        @Override
        public void run() {
            editEventTemplate();
        }
    };
    actionEdit.setEnabled(false);
    actionDelete = new Action(Messages.get().EventConfigurator_Delete, SharedIcons.DELETE_OBJECT) {

        @Override
        public void run() {
            deleteEventTemplate();
        }
    };
    actionDelete.setEnabled(false);
    actionShowFilter = new Action(Messages.get().EventConfigurator_ShowFilter, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            enableFilter(actionShowFilter.isChecked());
        }
    };
    actionRemove = new Action("&Remove from group") {

        @Override
        public void run() {
            removeFromGroup();
        }
    };
    actionShowGroups = new Action("&Show event groups", Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            showEventGroups();
        }
    };
    actionShowGroups.setChecked(showGroups);
    actionNewGroup = new Action("&Add new event group") {

        @Override
        public void run() {
            createNewEventGroup();
        }
    };
    actionShowFilter.setImageDescriptor(SharedIcons.FILTER);
    actionShowFilter.setChecked(filterEnabled);
    // $NON-NLS-1$
    actionShowFilter.setActionDefinitionId("org.netxms.ui.eclipse.eventmanager.commands.show_filter");
    if (viewPart != null) {
        final IHandlerService handlerService = (IHandlerService) viewPart.getSite().getService(IHandlerService.class);
        // $NON-NLS-1$
        actionNew.setActionDefinitionId("org.netxms.ui.eclipse.eventmanager.commands.new_event_template");
        handlerService.activateHandler(actionNew.getActionDefinitionId(), new ActionHandler(actionNew));
        // $NON-NLS-1$
        actionShowFilter.setActionDefinitionId("org.netxms.ui.eclipse.eventmanager.commands.show_filter");
        handlerService.activateHandler(actionShowFilter.getActionDefinitionId(), new ActionHandler(actionShowFilter));
        actionRefresh = new RefreshAction(viewPart) {

            @Override
            public void run() {
                refreshView();
            }
        };
    } else {
        actionRefresh = new RefreshAction() {

            @Override
            public void run() {
                refreshView();
            }
        };
    }
}
Also used : 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) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 74 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project netxms by netxms.

the class AgentFileViewer method createActions.

/**
 * Create actions
 */
private void createActions() {
    final IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
    actionClear = new Action(Messages.get().FileViewer_ClearOutput, SharedIcons.CLEAR_LOG) {

        @Override
        public void run() {
            viewer.clear();
        }
    };
    // $NON-NLS-1$
    actionClear.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.clear_output");
    handlerService.activateHandler(actionClear.getActionDefinitionId(), new ActionHandler(actionClear));
    actionScrollLock = new Action(Messages.get().FileViewer_ScrollLock, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            viewer.setScrollLock(actionScrollLock.isChecked());
        }
    };
    // $NON-NLS-1$
    actionScrollLock.setImageDescriptor(Activator.getImageDescriptor("icons/scroll_lock.gif"));
    actionScrollLock.setChecked(false);
    // $NON-NLS-1$
    actionScrollLock.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.scroll_lock");
    handlerService.activateHandler(actionScrollLock.getActionDefinitionId(), new ActionHandler(actionScrollLock));
    actionCopy = new Action(Messages.get().AgentFileViewer_Copy) {

        @Override
        public void run() {
            viewer.copy();
        }
    };
    actionCopy.setEnabled(false);
    // $NON-NLS-1$
    actionCopy.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.copy");
    handlerService.activateHandler(actionCopy.getActionDefinitionId(), new ActionHandler(actionCopy));
    actionSelectAll = new Action(Messages.get().AgentFileViewer_SelectAll) {

        @Override
        public void run() {
            viewer.selectAll();
        }
    };
    // $NON-NLS-1$
    actionSelectAll.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.select_all");
    handlerService.activateHandler(actionSelectAll.getActionDefinitionId(), new ActionHandler(actionSelectAll));
    actionFind = new Action(Messages.get().AgentFileViewer_Find, SharedIcons.FIND) {

        @Override
        public void run() {
            viewer.showSearchBar();
        }
    };
    // $NON-NLS-1$
    actionFind.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.find");
    handlerService.activateHandler(actionFind.getActionDefinitionId(), new ActionHandler(actionFind));
}
Also used : Action(org.eclipse.jface.action.Action) IHandlerService(org.eclipse.ui.handlers.IHandlerService) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 75 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project netxms by netxms.

the class ScriptEditorView method createActions.

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

        @Override
        public void run() {
            reloadScript();
        }
    };
    actionSave = new Action(Messages.get().ScriptEditorView_Save, SharedIcons.SAVE) {

        @Override
        public void run() {
            saveScript();
        }
    };
    // $NON-NLS-1$
    actionSave.setActionDefinitionId("org.netxms.ui.eclipse.nxsl.commands.save");
    handlerService.activateHandler(actionSave.getActionDefinitionId(), new ActionHandler(actionSave));
    actionCompile = new // $NON-NLS-2$
    Action(// $NON-NLS-2$
    Messages.get().ScriptEditorView_Compile, // $NON-NLS-2$
    Activator.getImageDescriptor("icons/compile.gif")) {

        @Override
        public void run() {
            compileScript();
        }
    };
    // $NON-NLS-1$
    actionCompile.setActionDefinitionId("org.netxms.ui.eclipse.nxsl.commands.compile");
    handlerService.activateHandler(actionCompile.getActionDefinitionId(), new ActionHandler(actionCompile));
}
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.ui.commands.ActionHandler)

Aggregations

IHandlerService (org.eclipse.ui.handlers.IHandlerService)102 ActionHandler (org.eclipse.jface.commands.ActionHandler)44 Action (org.eclipse.jface.action.Action)41 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)25 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)18 Command (org.eclipse.core.commands.Command)17 ICommandService (org.eclipse.ui.commands.ICommandService)17 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)15 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 AbstractHandler (org.eclipse.core.commands.AbstractHandler)10 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)9 IHandler (org.eclipse.core.commands.IHandler)8 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)8 ArrayList (java.util.ArrayList)7 ExecutionException (org.eclipse.core.commands.ExecutionException)7 IAction (org.eclipse.jface.action.IAction)7 IContextService (org.eclipse.ui.contexts.IContextService)7