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

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

Introduction

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

Prototype

void run();

Source Link

Document

Runs this action.

Usage

From source file:bndtools.utils.MessagesPopupDialog.java

License:Open Source License

@SuppressWarnings("unused")
@Override/*ww  w.j a  v a2s .c o 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

@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);/*from   ww w.j a  v  a  2 s  .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:com.amazonaws.eclipse.core.ui.overview.Toolkit.java

License:Apache License

/**
 * Creates and returns a new Link, which when selected, will run the
 * specified action./*from  www. j  a  va2s .c o  m*/
 *
 * @param parent
 *            The parent composite in which to create the new link.
 * @param text
 *            The text to display in the link.
 * @param action
 *            The action to execute when the Link is selected.
 * @return The new link.
 */
public Link newActionLink(Composite parent, String text, final IAction action) {
    Link link = new Link(parent, SWT.NONE);
    link.setText(createAnchor(text, text));
    link.setBackground(parent.getBackground());

    link.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            action.run();
        }
    });

    return link;
}

From source file:com.amazonaws.eclipse.core.ui.overview.Toolkit.java

License:Apache License

/**
 * Creates a new list item in the specified parent composite. Displays a
 * bulleted list item containing a hyperlink with the specified text and
 * href target, and an optional associated default action to execute if the
 * href target doesn't match any of the basic handlers for web links,
 * Eclipse preference links, Eclipse help links, etc.
 *
 * @param parent//from  w  w w .ja v  a 2 s  .co  m
 *            The parent composite in which the new list item will be
 *            created.
 * @param text
 *            The text for the list item hyperlink.
 * @param href
 *            The hyperlink href target for the new list item.
 * @param defaultAction
 *            The default action to run if the target href doesn't match any
 *            of the standard supported prefixes ('http', 'help:',
 *            'preference:').
 *
 * @return The new link in the list item.
 */
public ImageHyperlink newListItem(Composite parent, String text, String href, final IAction defaultAction) {
    FormToolkit formToolkit = resources.getFormToolkit();

    Composite composite = formToolkit.createComposite(parent);
    TableWrapLayout layout = LayoutUtils.newSlimTableWrapLayout(2);
    layout.leftMargin = 5;
    composite.setLayout(layout);
    composite.setLayoutData(new TableWrapData(TableWrapData.FILL));

    Composite bulletComposite = formToolkit.createComposite(composite);
    GridLayout bulletLayout = new GridLayout();
    bulletLayout.marginTop = 8;
    bulletLayout.marginHeight = 0;
    bulletComposite.setLayout(bulletLayout);

    Label bullet = formToolkit.createLabel(bulletComposite, null);
    bullet.setImage(resources.getImage(OverviewResources.IMAGE_BULLET));
    TableWrapData layoutData = new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE);
    layoutData.grabVertical = true;
    bullet.setLayoutData(new GridData());

    ImageHyperlink link = formToolkit.createImageHyperlink(composite, SWT.RIGHT | SWT.NO_FOCUS | SWT.WRAP);
    link.setText(text);
    link.setHref(href);
    link.setUnderlined(false);
    link.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP));
    link.setFont(resources.getFont("text"));

    // Any external links should be displayed with the external link image
    if (href != null && href.startsWith("http")) {
        link.setImage(OverviewResources.getExternalLinkImage());
    }

    /*
     * Always add a hyperlink listener for the basic action prefixes
     * ('http:', 'help:', 'preference:', etc.) and optionally add a default
     * listener for a custom action.
     */
    link.addHyperlinkListener(new HyperlinkHandler());
    if (defaultAction != null) {
        link.addHyperlinkListener(new HyperlinkAdapter() {
            @Override
            public void linkActivated(HyperlinkEvent e) {
                defaultAction.run();
            }
        });
    }

    return link;
}

From source file:com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor.java

License:Open Source License

/**
 * Commit all dirty pages then saves the contents of the text editor.
 * <p/>//from  w w  w.j  ava 2  s .  c o  m
 * This works by committing all data to the XML model and then
 * asking the Structured XML Editor to save the XML.
 *
 * @see IEditorPart
 */
@Override
public void doSave(IProgressMonitor monitor) {
    commitPages(true /* onSave */);

    if (AdtPrefs.getPrefs().isFormatOnSave()) {
        IAction action = mTextEditor.getAction(ACTION_NAME_FORMAT_DOCUMENT);
        if (action != null) {
            try {
                mIgnoreXmlUpdate = true;
                action.run();
            } finally {
                mIgnoreXmlUpdate = false;
            }
        }
    }

    // The actual "save" operation is done by the Structured XML Editor
    getEditor(mTextPageIndex).doSave(monitor);

    // Check for errors on save, if enabled
    if (AdtPrefs.getPrefs().isLintOnSave()) {
        runLint();
    }
}

From source file:com.android.menubar.MenuBarEnhancer.java

License:Open Source License

public static IMenuBarEnhancer setupMenuManager(String appName, Display display, final IMenuManager menuManager,
        final IAction aboutAction, final IAction preferencesAction, final IAction quitAction) {

    IMenuBarCallback callbacks = new IMenuBarCallback() {
        @Override/*w  ww .ja  v  a  2  s . c o  m*/
        public void printError(String format, Object... args) {
            System.err.println(String.format(format, args));
        }

        @Override
        public void onPreferencesMenuSelected() {
            if (preferencesAction != null) {
                preferencesAction.run();
            }
        }

        @Override
        public void onAboutMenuSelected() {
            if (aboutAction != null) {
                aboutAction.run();
            }
        }
    };

    IMenuBarEnhancer enhancer = getEnhancer(callbacks, display);

    // Default implementation for generic platforms
    if (enhancer == null) {
        enhancer = new IMenuBarEnhancer() {

            @Override
            public MenuBarMode getMenuBarMode() {
                return MenuBarMode.GENERIC;
            }

            @Override
            public void setupMenu(String appName, Display display, final IMenuBarCallback callbacks) {
                if (!menuManager.isEmpty()) {
                    menuManager.add(new Separator());
                }

                if (aboutAction != null) {
                    menuManager.add(aboutAction);
                }
                if (preferencesAction != null) {
                    menuManager.add(preferencesAction);
                }
                if (quitAction != null) {
                    if (aboutAction != null || preferencesAction != null) {
                        menuManager.add(new Separator());
                    }
                    menuManager.add(quitAction);
                }
            }
        };
    }

    enhancer.setupMenu(appName, display, callbacks);
    return enhancer;
}

From source file:com.aptana.ide.editors.junit.TestSelectionFormattingAction.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *//*w  w  w  . java 2 s.  c  o  m*/
public void run(IAction action) {
    try {
        IProject project = ProjectTestUtils.createProject("test format");
        Path path = ProjectTestUtils.findFileInPlugin("com.aptana.ide.editors.junit", //$NON-NLS-1$
                "format/dojo.js");
        IFile file = ProjectTestUtils.addFileToProject(path, project);
        final JSEditor editor = (JSEditor) ProjectTestUtils.openInEditor(file, ProjectTestUtils.JS_EDITOR_ID);
        final StyledText text = editor.getViewer().getTextWidget();
        final IDocument document = editor.getViewer().getDocument();

        UIJob cpJob = new UIJob("Copy Pasting") {

            int currentIndex = 0;
            int currentLenght = 1;
            int errors = 0;

            public IStatus runInUIThread(IProgressMonitor monitor) {
                final String original = document.get();

                CodeFormatAction action = new CodeFormatAction();
                action.setActiveEditor(null, editor);
                try {
                    String finalString = null;
                    if (currentIndex < document.getLength()) {
                        text.setSelection(currentIndex, currentLenght);
                        action.run();
                        finalString = text.getText();
                        if (!finalString.equals(original)) {
                            document.set(original);
                            System.out.println("Selection Formatting Error:" + errors + " Position:"
                                    + currentIndex + " Length:" + currentLenght);
                            errors++;
                        }
                        if (currentLenght < document.getLength()) {
                            currentLenght++;
                        } else {
                            currentIndex++;
                            currentLenght = 1;
                        }
                    }
                } catch (Exception e) {
                }
                this.schedule(100);
                return Status.OK_STATUS;
            }

        };
        cpJob.schedule();

    } catch (Exception e) {
        MessageDialog.openError(Display.getDefault().getActiveShell(), "Error formatting", e.getMessage());
    }
}

From source file:com.aptana.ide.intro.browser.CoreURL.java

License:Open Source License

/**
 * Run an action//from  www. j a v a  2s.c o m
 */
private boolean runAction(String pluginId, String className, Properties parameters, String standbyState) {

    Object actionObject = ModelLoaderUtil.createClassInstance(pluginId, className);
    try {
        if (actionObject instanceof IIntroAction) {
            IIntroAction introAction = (IIntroAction) actionObject;
            introAction.run(null, parameters);
        } else if (actionObject instanceof IAction) {
            IAction action = (IAction) actionObject;
            action.run();

        } else if (actionObject instanceof IActionDelegate) {
            final IActionDelegate delegate = (IActionDelegate) actionObject;
            if (delegate instanceof IWorkbenchWindowActionDelegate) {
                ((IWorkbenchWindowActionDelegate) delegate)
                        .init(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
            }
            Action proxy = new Action(this.action) {

                public void run() {
                    delegate.run(this);
                }
            };
            proxy.run();
        } else {
            // we could not create the class.
            return false;
        }

    } catch (Exception e) {
        return false;
    }
    return true;
}

From source file:com.architexa.diagrams.relo.jdt.actions.Script2Action.java

License:Open Source License

/**
 * @see IActionDelegate#run(IAction)//from  w  w w.j a v  a2s . c  o  m
 */
public void run(IAction action) {
    try {
        //dumpMethodBody((IMethod) selList.get(0));

        //System.err.println(
        //   "trying to execute action: "
        //      + action.getClass()
        //      + " -- "
        //      + action.getText());

        //ReloPlugin
        //   .getDefault()
        //   .getWorkbench()
        //   .getActiveWorkbenchWindow()
        //   .getActivePage()
        //   .openEditor(new ListEditorInput(selList), "com.architexa.diagrams.relo.editor");

        IMethod method = (IMethod) selList.get(0);
        IFile file = (IFile) ((IMember) method).getCompilationUnit().getResource();
        IWorkbenchPage page = getActivePage();
        //IEditorDescriptor editorDesc = IDE.getEditorDescriptor(file);
        JavaEditorlet jelet = (JavaEditorlet) page.openEditor(new FileEditorInput(file),
                "com.architexa.diagrams.relo.jdt.JavaEditorlet", true);

        /*
        String editorId = "com.architexa.diagrams.relo.jdt.JavaEditorlet";
        FileEditorInput input = new FileEditorInput(file);
        JavaEditorlet jelet = null;
                
        IEditorPart editor = null;
                
        // Remember the old visible editor
        IEditorPart oldVisibleEditor = page.getActiveEditor();
                
        // Otherwise, create a new one. This may cause the new editor to
        // become the visible (i.e top) editor.
        IEditorReference ref = null;
        IEditorRegistry reg = WorkbenchPlugin.getDefault().getEditorRegistry();
        EditorDescriptor desc = (EditorDescriptor) reg.findEditor(editorId);
        if (desc == null) {
         throw new PartInitException(WorkbenchMessages.format("EditorManager.unknownEditorIDMessage", new Object[] { editorId })); //$NON-NLS-1$
        }
                
        //ref = getEditorManager().openEditor(editorID, input, true);
        //ref = openEditorFromDescriptor(new Editor(), desc, input);
        //if (ref != null) {
        //   editor = ref.getEditor(true);
        //   addPart(ref);
        //}
                
        // Open the instance.
        editor = createPart(desc);
        EditorSite site = new EditorSite(ref, editor, (WorkbenchPage) page, desc);
        if (desc != null)
         site.setActionBars(createEditorActionBars(desc));
        else
         site.setActionBars(createEmptyEditorActionBars());
                
        part.init(site, input);
                
        createEditorTab(ref, desc, input, setVisible);
                
        /*
        //firePartOpened(editor);
        setEditorAreaVisible(true);
        activate(editor);
        window.firePerspectiveChanged(
            this,
            getPerspective(),
            ref,
            CHANGE_EDITOR_OPEN);
        window.firePerspectiveChanged(
         this,
         getPerspective(),
         CHANGE_EDITOR_OPEN);
        */

        //jelet = (JavaEditorlet) editor;
        //*/

        IAction toggleAction = jelet.getEditorSite().getActionBars()
                .getGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY);
        if (toggleAction != null && toggleAction.isEnabled() && toggleAction.isChecked()) {
            if (toggleAction instanceof TextEditorAction) {
                // Reset the action 
                ((TextEditorAction) toggleAction).setEditor(null);
                // Restore the action 
                ((TextEditorAction) toggleAction).setEditor(jelet);
            } else {
                // Uncheck 
                toggleAction.run();
                // Check
                toggleAction.run();
            }
        }

        // launched editor!!
        //ISourceRange srcRange = ParseUtilities.getBodyRange(method);
        //jelet.setShowRange(srcRange);

        //ConsoleView.setVariable("lm", jelet);

    } catch (Exception e) {
        e.printStackTrace();
    }
    /*
    Shell shell = new Shell();
    MessageDialog.openInformation(
       shell,
       "JBrowse Plug-in",
       "New Action was executed.");
    */
}

From source file:com.architexa.org.eclipse.gef.KeyHandler.java

License:Open Source License

private boolean performStroke(KeyStroke key) {
    if (actions == null)
        return false;
    IAction action = (IAction) actions.get(key);
    if (action == null)
        return false;
    if (action.isEnabled())
        action.run();
    return true;/* ww w .j  av a 2  s  .  co  m*/
}