Example usage for org.eclipse.jface.action ActionContributionItem getAction

List of usage examples for org.eclipse.jface.action ActionContributionItem getAction

Introduction

In this page you can find the example usage for org.eclipse.jface.action ActionContributionItem getAction.

Prototype

public IAction getAction() 

Source Link

Document

Returns the action associated with this contribution item.

Usage

From source file:ch.elexis.core.ui.util.ViewMenus.java

License:Open Source License

private void fillContextMenu(IMenuManager manager, List<IContributionItem> contributionItems) {
    manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    for (IContributionItem contributionItem : contributionItems) {
        if (contributionItem == null) {
            manager.add(new Separator());
            continue;
        } else if (contributionItem instanceof ActionContributionItem) {
            ActionContributionItem ac = (ActionContributionItem) contributionItem;
            if (ac.getAction() instanceof RestrictedAction) {
                ((RestrictedAction) ac.getAction()).reflectRight();
            }/*ww w  .j  av a  2  s .c  om*/
        }
        contributionItem.update();
        manager.add(contributionItem);
    }
}

From source file:com.aptana.ide.search.AptanaFileSearchPage.java

License:Open Source License

/**
 * ovverriden to make it working for matching layout
 * @see org.eclipse.search.internal.ui.text.FileSearchPage#fillContextMenu(org.eclipse.jface.action.IMenuManager)
 */// w  w w.java 2 s.c o m
protected void fillContextMenu(IMenuManager mgr) {
    try {
        super.fillContextMenu(mgr);
        Separator find = (Separator) mgr.find(IContextMenuConstants.GROUP_REORGANIZE);
        IContributionItem[] items = find.getParent().getItems();
        int indexOf = Arrays.asList(items).indexOf(find);
        mgr.remove(items[indexOf + 1]);
        mgr.remove(items[indexOf + 2]);
        doAdd(mgr);
    } catch (ClassCastException e) {
        // should be here if our layout is active
        doAdd(mgr);

    }
    if (this.layout == AptanaFileSearchPage.LAYOUT_MATCHES) {
        Separator find = (Separator) mgr.find(IContextMenuConstants.GROUP_VIEWER_SETUP);
        IContributionItem[] items = find.getParent().getItems();
        int indexOf = Arrays.asList(items).indexOf(find);
        MenuManager contributionItem = (MenuManager) items[indexOf + 1];
        IContributionItem[] items2 = contributionItem.getItems();
        ActionContributionItem it0 = (ActionContributionItem) items2[0];
        ActionContributionItem it1 = (ActionContributionItem) items2[1];
        it0.getAction().setChecked(this.fOrder == AptanaFileSearchPage.SHOW_LABEL_PATH);
        it1.getAction().setChecked(this.fOrder == AptanaFileSearchPage.SHOW_PATH_LABEL);
    }
}

From source file:com.aptana.ide.search.AptanaFileSearchPage.java

License:Open Source License

/**
 * this method manages setting correct layout
 * in case of matching layout it delegates to super for creating table viewer
 * and then reconfigures it. //  w w w  . ja  v a  2 s.c o m
 * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#setLayout(int)
 */
public void setLayout(int layout) {
    if (this.layout == layout) {
        return;
    }
    if (layout == AptanaFileSearchPage.LAYOUT_MATCHES) {
        this.getControl().setRedraw(false);

        if (this.getLayout() != AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT) {
            super.setLayout(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT);
        }
        this.layout = layout;
        this.reconfigureTableViewer();
        this.getControl().setRedraw(true);
        ((Composite) this.getControl()).layout(true, true);
        this.getControl().redraw();
        Separator find = (Separator) this.getSite().getActionBars().getMenuManager()
                .find(IContextMenuConstants.GROUP_VIEWER_SETUP);
        IContributionItem[] items = find.getParent().getItems();
        int indexOf = Arrays.asList(items).indexOf(find);
        SubContributionItem contributionItem = (SubContributionItem) items[indexOf + 1];
        ActionContributionItem ac = (ActionContributionItem) contributionItem.getInnerItem();
        ac.getAction().setChecked(false);
        contributionItem = (SubContributionItem) items[indexOf + 3];
        ac = (ActionContributionItem) contributionItem.getInnerItem();
        ac.getAction().setChecked(true);
        find.update();
        this.getSettings().put(AptanaFileSearchPage.KEY_LAYOUT, layout);
    } else {

        if (this.layout == AptanaFileSearchPage.LAYOUT_MATCHES) {
            this.layout = layout;
            if (layout == AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT) {
                this.getControl().setRedraw(false);
                super.setLayout(AbstractTextSearchViewPage.FLAG_LAYOUT_TREE);
                super.setLayout(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT);
                ((Composite) this.getControl()).layout(true, true);
                this.getControl().setRedraw(true);
                return;
            }
        }
        this.layout = layout;
        super.setLayout(layout);
    }
}

From source file:com.aptana.ide.search.ui.filesystem.AptanaFileSystemSearchPage.java

License:Open Source License

/**
 * @see org.eclipse.search.internal.ui.text.FileSearchPage#fillContextMenu(org.eclipse.jface.action.IMenuManager)
 *///w ww  . j  a  v a2  s. c  o  m
protected void fillContextMenu(IMenuManager mgr) {
    super.fillContextMenu(mgr);

    // should be here if our layout is active
    IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();
    if (!selection.isEmpty()) {
        FileSystemReplaceAction replaceSelection = new FileSystemReplaceAction(getSite().getShell(),
                (FileSystemSearchResult) getInput(), selection.toArray(), true);
        replaceSelection.setText(SearchMessages.ReplaceAction_label_selected);
        mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceSelection);
    }
    FileSystemReplaceAction replaceAll = new FileSystemReplaceAction(getSite().getShell(),
            (FileSystemSearchResult) getInput(), null, true);
    replaceAll.setText(SearchMessages.ReplaceAction_label_all);
    mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll);

    if (this.layout == AptanaFileSystemSearchPage.LAYOUT_MATCHES) {
        Separator find = (Separator) mgr.find(IContextMenuConstants.GROUP_VIEWER_SETUP);
        IContributionItem[] items = find.getParent().getItems();
        int indexOf = Arrays.asList(items).indexOf(find);
        MenuManager contributionItem = (MenuManager) items[indexOf + 1];
        IContributionItem[] items2 = contributionItem.getItems();
        ActionContributionItem it0 = (ActionContributionItem) items2[0];
        ActionContributionItem it1 = (ActionContributionItem) items2[1];
        it0.getAction().setChecked(fOrder == AptanaFileSystemSearchPage.SHOW_LABEL_PATH);
        it1.getAction().setChecked(fOrder == AptanaFileSystemSearchPage.SHOW_PATH_LABEL);
    }
}

From source file:com.aptana.ide.search.ui.filesystem.AptanaFileSystemSearchPage.java

License:Open Source License

/**
 * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#setLayout(int)
 *//*from  w w w .ja  v a2 s  .  com*/
public void setLayout(int layout) {
    if (this.layout == layout) {
        return;
    }
    if (layout == LAYOUT_MATCHES) {
        getControl().setRedraw(false);

        if (getLayout() != FLAG_LAYOUT_FLAT) {
            super.setLayout(FLAG_LAYOUT_FLAT);
        }
        this.layout = layout;
        reconfigureTableViewer();
        getControl().setRedraw(true);
        ((Composite) getControl()).layout(true, true);
        getControl().redraw();
        Separator find = (Separator) getSite().getActionBars().getMenuManager()
                .find(IContextMenuConstants.GROUP_VIEWER_SETUP);
        IContributionItem[] items = find.getParent().getItems();
        int indexOf = Arrays.asList(items).indexOf(find);
        SubContributionItem contributionItem = (SubContributionItem) items[indexOf + 1];
        ActionContributionItem ac = (ActionContributionItem) contributionItem.getInnerItem();
        ac.getAction().setChecked(false);
        contributionItem = (SubContributionItem) items[indexOf + 3];
        ac = (ActionContributionItem) contributionItem.getInnerItem();
        ac.getAction().setChecked(true);
        getSettings().put(KEY_LAYOUT, layout);
    } else {

        if (this.layout == LAYOUT_MATCHES) {
            this.layout = layout;
            if (layout == FLAG_LAYOUT_FLAT) {
                getControl().setRedraw(false);
                super.setLayout(FLAG_LAYOUT_TREE);
                super.setLayout(FLAG_LAYOUT_FLAT);
                ((Composite) this.getControl()).layout(true, true);
                getControl().setRedraw(true);
                return;
            }
        }
        this.layout = layout;
        super.setLayout(layout);
    }
}

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

License:Open Source License

/**
 * Creates and registers the context menu
 *///w  w w.  jav  a  2 s  . c  om
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
 * //from w  ww. jav a 2  s .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.beck.ep.team.ui.FileListMenuMgr.java

License:BSD License

private void saveAs() {
    InputDialog dialog = new InputDialog(input.getShell(), "Save file list", "Input name for file list",
            pref.get("selectedList", ""), null);//new RegexValidator("^[0-9,]+$","Please input number and separator by char ','"));
    if (dialog.open() != InputDialog.OK) {
        return;/*ww w .j  a v a  2s.  com*/
    }
    String key = dialog.getValue();
    if (key.length() == 0) {
        return;
    }
    IContributionItem[] items = getItems();
    boolean exists = false;
    for (int i = 0; i < items.length; i++) {
        if (CFG_ACTION_ID.equals(items[i].getId())) {
            i = items.length;//stop at this node...
        } else {
            ActionContributionItem aitem = (ActionContributionItem) items[i];
            boolean match = aitem.getAction().getId().equals(key);
            if (match) {
                exists = true;
            }
            aitem.getAction().setChecked(match);
        }
    }
    Preferences p = pref.node("fileList");
    p.put(key, input.getText());
    if (!exists) {
        addItems(key, key);
        pref.put("selectedList", key);
    }
}

From source file:com.clustercontrol.view.CommonViewPart.java

License:Open Source License

/**
 * @param enable/*  w  w  w  .  j  ava2 s. co  m*/
 */
public void setEnabledAction(String actionID, boolean enable) {
    ActionContributionItem ci = (ActionContributionItem) getViewSite().getActionBars().getToolBarManager()
            .find(actionID);
    IAction action = ci.getAction();
    action.setEnabled(enable);
}

From source file:com.clustercontrol.view.CommonViewPart.java

License:Open Source License

/**
 * /*from w  w  w.j av a 2  s.  c o m*/
 * @since
 */
public void setEnabledActionAll(boolean enable) {
    IToolBarManager tm = getViewSite().getActionBars().getToolBarManager();
    IContributionItem[] cis = tm.getItems();

    for (int i = 0; i < cis.length; i++) {
        if (cis[i] instanceof ActionContributionItem) {
            ActionContributionItem ci = (ActionContributionItem) cis[i];
            ci.getAction().setEnabled(enable);
        }
    }
}