Search in sources :

Example 31 with IAction

use of org.eclipse.jface.action.IAction in project cubrid-manager by CUBRID.

the class ActionAdvisor method createItem.

/**
	 *
	 * Create action contribution item for action for show text and icon
	 *
	 * @param id
	 *            action ID
	 * @return ActionContributionItem
	 */
private ActionContributionItem createItem(String id) {
    IAction action = ActionManager.getInstance().getAction(id);
    if (action == null) {
        return null;
    }
    ActionContributionItem item = new ActionContributionItem(action);
    item.setMode(ActionContributionItem.MODE_FORCE_TEXT);
    return item;
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IAction(org.eclipse.jface.action.IAction)

Example 32 with IAction

use of org.eclipse.jface.action.IAction in project cubrid-manager by CUBRID.

the class MonitorDashboardEditor method configureGraphicalViewer.

/**
	 * @see org.eclipse.gef.ui.parts.GraphicalEditor.configureGraphicalViewer
	 */
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    GraphicalViewer viewer = getGraphicalViewer();
    ScalableFreeformRootEditPart rootEditPart = new ScalableFreeformRootEditPart();
    viewer.setRootEditPart(rootEditPart);
    viewer.setEditPartFactory(new MonitorEditPartFacotry());
    ZoomManager manager = rootEditPart.getZoomManager();
    double[] zoomLevels = new double[] { 1.0, 1.2, 1.4, 1.6, 1.8, 2.0 };
    manager.setZoomLevels(zoomLevels);
    getActionRegistry().registerAction(new ZoomInAction(manager));
    getActionRegistry().registerAction(new ZoomOutAction(manager));
    KeyHandler keyHandler = new GefViewerKeyHandler(viewer);
    keyHandler.put(KeyStroke.getReleased('', 97, SWT.CONTROL), getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
    keyHandler.put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
    keyHandler.put(KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
    viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.CTRL), MouseWheelZoomHandler.SINGLETON);
    viewer.setKeyHandler(keyHandler);
    //initialize context menu
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        /**
			 * get menus to show.
			 * 
			 * @param manager IMenuManager
			 */
        public void menuAboutToShow(IMenuManager manager) {
            IStructuredSelection selection = (IStructuredSelection) getGraphicalViewer().getSelection();
            String[] ids = new String[] {};
            if (null == selection || selection.isEmpty() || selection.getFirstElement() instanceof DashboardPart) {
                manager.add(getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
                ids = new String[] { AddHostMonitorAction.ID, SEPARATOR, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof HostMonitorPart) {
                ids = new String[] { MonitorDetailAction.ID, DeleteHostMonitorAction.ID, EditAliasNameAction.ID, SEPARATOR, //HARoleChangeAction.ID, SEPARATOR,
                HostDashboardHistoryAction.ID, AddDatabaseMonitorAction.ID, AddBrokerMonitorAction.ID, SEPARATOR, HideHostAction.ID, MinimizeFigureAction.ID, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof DatabaseMonitorPart) {
                ids = new String[] { MonitorDetailAction.ID, DeleteDatabaseMonitorAction.ID, EditAliasNameAction.ID, SEPARATOR, DbDashboardHistoryAction.ID, OpenApplyLogDBLogAction.ID, OpenCopyLogDBLogAction.ID, OpenDatabaseLogAction.ID, SEPARATOR, ShowHostAction.ID, MinimizeFigureAction.ID, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof BrokerMonitorPart) {
                ids = new String[] { MonitorDetailAction.ID, DeleteBrokerMonitorAction.ID, EditAliasNameAction.ID, SEPARATOR, ShowBrokerClientAction.ID, ShowBrokerDabaseAction.ID, SEPARATOR, ShowHostAction.ID, MinimizeFigureAction.ID, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof ClientMonitorPart) {
                ids = new String[] { EditAliasNameAction.ID };
            } else if (selection.getFirstElement() instanceof BrokerDBListMonitorPart) {
                ids = new String[] { EditAliasNameAction.ID };
            }
            for (String id : ids) {
                if (id.equals(SEPARATOR)) {
                    manager.add(new Separator());
                } else {
                    IAction action = ActionManager.getInstance().getAction(id);
                    ((ISelectionAction) action).setSelectionProvider(getGraphicalViewer());
                    ActionManager.addActionToManager(manager, action);
                }
            }
            manager.update(true);
        }
    });
    viewer.setContextMenu(menuManager);
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) BrokerDBListMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.BrokerDBListMonitorPart) IAction(org.eclipse.jface.action.IAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) BrokerMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.BrokerMonitorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HostMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.HostMonitorPart) IMenuListener(org.eclipse.jface.action.IMenuListener) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ClientMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.ClientMonitorPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) DashboardPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DashboardPart) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) DatabaseMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DatabaseMonitorPart) MonitorEditPartFacotry(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.MonitorEditPartFacotry) KeyHandler(org.eclipse.gef.KeyHandler) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) Separator(org.eclipse.jface.action.Separator)

Example 33 with IAction

use of org.eclipse.jface.action.IAction in project sling by apache.

the class ServersActionModeFiddlerActionDelegate method init.

@Override
public void init(IViewPart view) {
    this.view = view;
    actionBars = view.getViewSite().getActionBars();
    initToolbarContributedActions();
    for (ActionContributionItem actionContributionItem : prependedToolbarActions) {
        // TODO - this looks wrong
        IAction action = (IAction) actionContributionItem;
        final ActionContributionItem contribution = new ActionContributionItem(action);
        actionBars.getToolBarManager().add(contribution);
    }
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IAction(org.eclipse.jface.action.IAction)

Example 34 with IAction

use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.

the class TextEditorActionContributor method doSetActiveEditor.

/**
 * Internally sets the active editor to the actions provided by this contributor.
 * Cannot be overridden by subclasses.
 *
 * @param part the editor
 */
private void doSetActiveEditor(final IEditorPart part) {
    ITextEditor textEditor = null;
    if (part instanceof ITextEditor)
        textEditor = (ITextEditor) part;
    /**
     * The global actions to be connected with editor actions
     */
    IActionBars actionBars = getActionBars();
    actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId()));
    actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId()));
    IAction action = getAction(textEditor, ITextEditorActionConstants.NEXT);
    actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, action);
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, action);
    action = getAction(textEditor, ITextEditorActionConstants.PREVIOUS);
    actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, action);
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, action);
    action = getAction(textEditor, ITextEditorActionConstants.REFRESH);
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.REFRESH, action);
    fChangeEncodingAction.setAction(getAction(textEditor, ITextEditorActionConstants.CHANGE_ENCODING));
    IAction quickAssistAction = getAction(textEditor, ITextEditorActionConstants.QUICK_ASSIST);
    fQuickAssistAction.setAction(quickAssistAction);
    if (textEditor == null)
        return;
    // Update Quick Assist menu entry - for now don't show disabled entry
    IMenuManager menuMgr = textEditor.getEditorSite().getActionBars().getMenuManager();
    IMenuManager editMenu = menuMgr.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
    if (editMenu != null) {
        boolean isEnabled = quickAssistAction != null && quickAssistAction.isEnabled();
        fQuickAssistMenuEntry.setVisible(isEnabled);
        editMenu.update(true);
    }
    fRetargetShowInformationAction.setAction(getAction(textEditor, ITextEditorActionConstants.SHOW_INFORMATION));
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IAction(org.eclipse.jface.action.IAction) IMenuManager(org.eclipse.jface.action.IMenuManager) IActionBars(org.eclipse.ui.IActionBars)

Example 35 with IAction

use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.

the class GotoLineTest method goToLine.

private void goToLine(int line, int expectedResult) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        IEditorPart part = IDE.openEditor(page, fFile);
        if (part instanceof ITextEditor) {
            ITextEditor editor = (ITextEditor) part;
            IAction action = editor.getAction(ITextEditorActionConstants.GOTO_LINE);
            Accessor accessor = new Accessor(action, GotoLineAction.class);
            accessor.invoke("gotoLine", new Class[] { int.class }, new Integer[] { Integer.valueOf(line) });
            Control control = part.getAdapter(Control.class);
            if (control instanceof StyledText) {
                int caretLine = -1;
                StyledText styledText = (StyledText) control;
                int caret = styledText.getCaretOffset();
                try {
                    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
                    caretLine = document.getLineOfOffset(caret);
                } catch (BadLocationException e1) {
                    fail();
                }
                assertEquals(expectedResult, caretLine);
            } else
                fail();
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Control(org.eclipse.swt.widgets.Control) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) StyledText(org.eclipse.swt.custom.StyledText) IAction(org.eclipse.jface.action.IAction) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) Accessor(org.eclipse.text.tests.Accessor) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IAction (org.eclipse.jface.action.IAction)406 Action (org.eclipse.jface.action.Action)153 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)79 IWorkbenchAction (org.eclipse.ui.actions.ActionFactory.IWorkbenchAction)57 Separator (org.eclipse.jface.action.Separator)54 WebLaunchAction (com.centurylink.mdw.plugin.actions.WebLaunchActions.WebLaunchAction)50 MenuManager (org.eclipse.jface.action.MenuManager)39 ArrayList (java.util.ArrayList)38 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)37 IMenuManager (org.eclipse.jface.action.IMenuManager)37 IContributionItem (org.eclipse.jface.action.IContributionItem)33 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)27 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)22 ActionRegistry (org.eclipse.gef.ui.actions.ActionRegistry)19 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)18 IToolBarManager (org.eclipse.jface.action.IToolBarManager)17 Iterator (java.util.Iterator)15 Point (org.eclipse.swt.graphics.Point)15 IEditorPart (org.eclipse.ui.IEditorPart)15 List (java.util.List)14