Example usage for org.eclipse.jface.action IAction getText

List of usage examples for org.eclipse.jface.action IAction getText

Introduction

In this page you can find the example usage for org.eclipse.jface.action IAction getText.

Prototype

String getText();

Source Link

Document

Returns the text for this action.

Usage

From source file:bndtools.utils.MessagesPopupDialog.java

License:Open Source License

@SuppressWarnings("unused")
@Override//from   w ww . j a  v  a2  s.  co m
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new GridLayout(1, false));

    for (int i = 0; i < messages.length; i++) {
        if (i > 0) {
            Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
            separator.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1));
        }

        // Message Type Image Label
        Composite pnlTitle = new Composite(composite, SWT.NONE);
        pnlTitle.setLayout(new GridLayout(2, false));
        Label lblImage = new Label(pnlTitle, SWT.NONE);
        lblImage.setImage(getMessageImage(messages[i].getMessageType()));

        // Message Label
        StringBuilder builder = new StringBuilder();
        if (messages[i].getPrefix() != null) {
            builder.append(messages[i].getPrefix());
        }
        builder.append(messages[i].getMessage());
        Label lblText = new Label(pnlTitle, SWT.WRAP);
        lblText.setText(builder.toString());
        lblText.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DIALOG_FONT));
        lblText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        // Fix actions, if present
        Object data = messages[i].getData();
        IAction[] fixes;
        if (data instanceof IAction) {
            fixes = new IAction[] { (IAction) data };
        } else if (data instanceof IAction[]) {
            fixes = (IAction[]) data;
        } else {
            fixes = null;
        }

        if (fixes != null) {
            // new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
            Composite pnlFixes = new Composite(composite, SWT.NONE);
            pnlFixes.setLayout(new GridLayout(3, false));

            Label lblFixes = new Label(pnlFixes, SWT.NONE);
            lblFixes.setText("Available Fixes:");
            lblFixes.setForeground(JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR));

            for (int j = 0; j < fixes.length; j++) {
                if (j > 0)
                    new Label(pnlFixes, SWT.NONE); // Spacer

                new Label(pnlFixes, SWT.NONE).setImage(bulletImg);

                final IAction fix = fixes[j];
                Hyperlink fixLink = new Hyperlink(pnlFixes, SWT.NONE);
                hyperlinkGroup.add(fixLink);
                fixLink.setText(fix.getText());
                fixLink.setHref(fix);
                fixLink.addHyperlinkListener(new HyperlinkAdapter() {
                    @Override
                    public void linkActivated(HyperlinkEvent e) {
                        fix.run();
                        close();
                        // part.getSite().getPage().activate(part);
                        part.setFocus();
                    }
                });
                fixLink.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
            }
        }
    }

    return composite;
}

From source file:ch.elexis.core.ui.laboratory.views.LaborOrderPulldownMenuCreator.java

License:Open Source License

@SuppressWarnings("unchecked")
private void init(final Shell shell) {
    List<IAction> orderActions = Extensions.getClasses(
            Extensions.getExtensions(ExtensionPointConstantsUi.LABORORDER), "ToolbarAction", //$NON-NLS-1$ //$NON-NLS-2$
            false);/*www.  j a v  a2s.  co m*/
    for (IAction action : orderActions) {
        if (action.getId() != null && action.getImageDescriptor() != null && action.getText() != null) {
            this.actions.add(action);
        } else {
            log.log(MessageFormat.format("Missing #id, #imagedescriptor or #text for LaborOrder action: {0}",
                    action.getText()), Log.WARNINGS);
        }
    }
    if (this.actions != null && this.actions.size() > 0) {
        String selectedId = CoreHub.localCfg.get(LAB_ORDER_SELECTED_ACTION_ID, null);
        if (selectedId != null) {
            for (IAction action : this.actions) {
                if (selectedId.equals(action.getId())) {
                    this.selectedAction = action;
                }
            }
        }
        if (this.selectedAction == null) {
            this.selectedAction = this.actions.get(0);
        }
    }
}

From source file:ch.elexis.core.ui.laboratory.views.LaborOrderPulldownMenuCreator.java

License:Open Source License

@Override
public Menu getMenu(final Control parent) {
    if (this.menu == null) {
        this.menu = new Menu(parent);
        for (final IAction action : this.actions) {
            final MenuItem menuItem = new MenuItem(this.menu, SWT.PUSH);
            final Image image = action.getImageDescriptor().createImage();
            menuItem.setImage(image);/*w ww.j  a v  a 2s .c  o m*/
            menuItem.setText(action.getText());

            // Add listeners
            menuItem.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    select(parent, action, image);
                    action.run();
                }
            });
        }

    }

    return this.menu;
}

From source file:ch.elexis.views.LaborOrderPulldownMenuCreator.java

License:Open Source License

@SuppressWarnings("unchecked")
private void init(final Shell shell) {
    List<IAction> orderActions = Extensions.getClasses(Extensions.getExtensions("ch.elexis.LaborOrder"), //$NON-NLS-1$
            "ToolbarAction", //$NON-NLS-1$
            false);/*  ww w  .j a  va2s.c om*/
    for (IAction action : orderActions) {
        if (action.getId() != null && action.getImageDescriptor() != null && action.getText() != null) {
            this.actions.add(action);
        } else {
            log.log(MessageFormat.format("Missing #id, #imagedescriptor or #text for LaborOrder action: {0}",
                    action.getText()), Log.WARNINGS);
        }
    }
    if (this.actions != null && this.actions.size() > 0) {
        String selectedId = Hub.localCfg.get(LAB_ORDER_SELECTED_ACTION_ID, null);
        if (selectedId != null) {
            for (IAction action : this.actions) {
                if (selectedId.equals(action.getId())) {
                    this.selectedAction = action;
                }
            }
        }
        if (this.selectedAction == null) {
            this.selectedAction = this.actions.get(0);
        }
    }
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.actions.AbstractCloudFoundryServerAction.java

License:Open Source License

public void run(IAction action) {

    String error = null;//from   w ww  .jav a2s.  com
    DockerFoundryServer cloudServer = selectedServer != null
            ? (DockerFoundryServer) selectedServer.loadAdapter(DockerFoundryServer.class, null)
            : null;
    DockerFoundryApplicationModule appModule = cloudServer != null && selectedModule != null
            ? cloudServer.getExistingCloudModule(selectedModule)
            : null;
    if (selectedServer == null) {
        error = "No Cloud Foundry server instance available to run the selected action."; //$NON-NLS-1$
    }

    if (error == null) {
        doRun(cloudServer, appModule, action);
    } else {
        error += " - " + action.getText(); //$NON-NLS-1$
        DockerFoundryPlugin.logError(error);
    }
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.DynamicContextMenu.java

License:Open Source License

private IAction createPlainAction(final RuleAction action, final List<INode> nodes, final String defaultId) {
    IAction a = new Action(action.getTitle(), IAction.AS_PUSH_BUTTON) {
        @Override//w w w  . ja va 2 s . c  om
        public void run() {
            String label = createActionLabel(action, nodes);
            mEditorDelegate.getEditor().wrapUndoEditXmlModel(label, new Runnable() {
                @Override
                public void run() {
                    action.getCallback().action(action, nodes, null, Boolean.TRUE);
                    applyPendingChanges();
                }
            });
        }
    };

    String id = action.getId();
    if (defaultId != null && id.equals(defaultId)) {
        a.setAccelerator(DEFAULT_ACTION_KEY);
        String text = a.getText();
        text = text + '\t' + DEFAULT_ACTION_SHORTCUT;
        a.setText(text);

    } else if (ATTR_ID.equals(id)) {
        // Keep in sync with {@link LayoutCanvas#handleKeyPressed}
        if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_DARWIN) {
            a.setAccelerator('R' | SWT.MOD1 | SWT.MOD3);
            // Option+Command
            a.setText(a.getText().trim() + "\t\u2325\u2318R"); //$NON-NLS-1$
        } else if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_LINUX) {
            a.setAccelerator('R' | SWT.MOD2 | SWT.MOD3);
            a.setText(a.getText() + "\tShift+Alt+R"); //$NON-NLS-1$
        } else {
            a.setAccelerator('R' | SWT.MOD2 | SWT.MOD3);
            a.setText(a.getText() + "\tAlt+Shift+R"); //$NON-NLS-1$
        }
    }
    a.setId(id);
    return a;
}

From source file:com.aptana.ide.server.ui.views.GenericServersView.java

License:Open Source License

/**
 * Creates and registers the context menu
 *//*w  w w  . j  a  va2  s .com*/
private void createPopupMenu() {
    deleteAction = ActionFactory.DELETE.create(getViewSite().getWorkbenchWindow());
    MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);
    getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.DELETE.getId(), new Action() {

        public void run() {
            doDelete();
        }
    });
    menuMgr.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            IContributionItem[] items = getViewSite().getActionBars().getToolBarManager().getItems();
            for (int i = 0; i < items.length; i++) {

                if (items[i] instanceof ActionContributionItem) {
                    ActionContributionItem aci = (ActionContributionItem) items[i];
                    IAction action = aci.getAction();
                    if (action == openLog) {
                        // adds the Open Log action to the context menu as a push button instead of 
                        // drop-down
                        boolean enabled = action.isEnabled();
                        action = new OpenLogAction(serverViewer, Action.AS_PUSH_BUTTON);
                        action.setEnabled(enabled);
                    }
                    if (action.isEnabled() && action.getStyle() != Action.AS_DROP_DOWN_MENU) {
                        if (action.getText() == null || action.getText().length() == 0) {
                            action.setText(action.getToolTipText());
                        }
                        manager.add(action);
                    }
                } else {
                    if (items[i] instanceof Separator) {
                        manager.add(new Separator());
                    }
                }
            }
            manager.add(new Separator());
            IStructuredSelection selection = (IStructuredSelection) serverViewer.getSelection();
            final IServer server = (IServer) selection.getFirstElement();
            if (server != null) {
                deleteAction.setText(StringUtils.format(Messages.ServersView_DELETE, getShortenName(server)));
                // deleteAction.setEnabled(server.getServerState() == IServer.STATE_STOPPED);
                deleteAction.setEnabled(server.canDelete().isOK());
                manager.add(deleteAction);

                Action action = new Action() {
                    public void run() {
                        doEdit(server);
                    }
                };
                action.setText(StringUtils.format(Messages.ServersView_EDIT, getShortenName(server)));
                IStatus canModify = server.canModify();
                IStatus canModifyInStoppedStateOnly = server.canModifyInStoppedStateOnly();
                action.setEnabled(((canModifyInStoppedStateOnly == null
                        || canModifyInStoppedStateOnly.getCode() == IStatus.OK)
                                ? server.getServerState() == IServer.STATE_STOPPED
                                : true)
                        && (canModify == null || canModify.getCode() == IStatus.OK));
                manager.add(action);
            }
            // deleteAction.setEnabled(!selection.isEmpty());
            manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); // Allow
        }

        private String getShortenName(final IServer server) {
            String name = server.getName();
            int length = name.length();
            if (length > MAX_SHOWN_SERVER_NAME) {
                int delta = (length - 15) / 2;
                int pivot = length / 2;
                int start = pivot - delta;
                int end = pivot + delta;
                String s1 = name.substring(0, start);
                String s2 = name.substring(end, length);
                String s = s1 + ELLIPSIS + s2;
                return s;
            }
            return name;
        }
    });
    Menu menu = menuMgr.createContextMenu(serverViewer.getControl());
    serverViewer.getControl().setMenu(menu);
    getSite().registerContextMenu(menuMgr, serverViewer);
}

From source file:com.aptana.ruby.internal.rake.actions.RakeTasksContributionItem.java

License:Open Source License

/**
 * For inserting submenus under submenus
 * /*w  w  w  .j a va2s.c  o  m*/
 * @param parent
 * @param item
 * @return
 */
private int getInsertIndex(MenuManager parent, MenuManager item) {
    if (parent == null || item == null) {
        return 0;
    }
    String text = item.getMenuText();
    if (text == null) {
        return 0;
    }
    IContributionItem[] items = parent.getItems();
    if (items == null) {
        return 0;
    }
    int index = 0;
    for (int i = 0; i < items.length; i++) {
        if (items[i] == null)
            continue;
        if (items[i] instanceof ActionContributionItem) {
            ActionContributionItem actionItem = (ActionContributionItem) items[i];
            IAction action = actionItem.getAction();
            if (action == null)
                continue;
            String other = action.getText();
            if (text.compareTo(other) >= 0) {
                index = i + 1;
            } else {
                break;
            }
        }
    }
    return index;
}

From source file:com.arc.cdt.debug.seecode.internal.ui.action.AbstractDebugActionDelegate.java

License:Open Source License

/**
 * Runs this action in a background job.
 *//*  w  w  w .  ja va 2  s .c  o  m*/
private void runInBackground(IAction action, IStructuredSelection selection) {
    if (fBackgroundJob == null) {
        fBackgroundJob = new DebugRequestJob(action.getText());
    }
    fBackgroundJob.setTargets(selection.toArray());
    fBackgroundJob.schedule();
}

From source file:com.archimatetool.editor.diagram.AbstractDiagramEditor.java

License:Open Source License

/**
 * Add some extra Actions - *after* the graphical viewer has been created
 *//* w  w w  . j  a  v a 2 s .c  o m*/
@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);
    registry.registerAction(zoomIn);
    registry.registerAction(zoomOut);

    // Add these zoom actions to the key binding service
    IHandlerService service = (IHandlerService) getEditorSite().getService(IHandlerService.class);
    service.activateHandler(zoomIn.getActionDefinitionId(), new ActionHandler(zoomIn));
    service.activateHandler(zoomOut.getActionDefinitionId(), new ActionHandler(zoomOut));

    // 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);
    action.setId(ActionFactory.RENAME.getId()); // Set this for Global Handler
    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());

    // 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);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());

    action = new MatchHeightAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());

    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.LEFT);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());

    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.RIGHT);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());

    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.TOP);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());

    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.BOTTOM);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());

    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.CENTER);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());

    action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.MIDDLE);
    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);

    // Export As Image
    action = new ExportAsImageAction(viewer);
    registry.registerAction(action);

    // Export As Image to Clipboard
    action = new ExportAsImageToClipboardAction(viewer);
    registry.registerAction(action);

    // Connection Router types
    action = new ConnectionRouterAction.BendPointConnectionRouterAction(this);
    registry.registerAction(action);
    action = new ConnectionRouterAction.ShortestPathConnectionRouterAction(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.supportsMacFullScreen()) {
        action = new FullScreenAction(this);
        registry.registerAction(action);
    }

    // Select Element in Tree
    action = new SelectElementInTreeAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
}