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

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

Introduction

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

Prototype

void setMenuCreator(IMenuCreator creator);

Source Link

Document

Sets the menu creator for this action.

Usage

From source file:br.ufmg.dcc.tabuleta.actions.AddToConcernAction.java

License:Open Source License

/**
 * Sets this class as a menu creator of pAction.
 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
 * @param pAction See above.//from   w ww  .j  av  a2  s  .  c o m
 * @param pSelection See above.
 */
public void selectionChanged(IAction pAction, ISelection pSelection) {
    pAction.setMenuCreator(this);
    aSelection = pSelection;
}

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

License:Open Source License

/**
 * Returns action to the pulldown button
 * /*from   w  w w . j  a v a  2 s. c o m*/
 * @return
 */
public IAction getAction() {
    int buttonStyle = IAction.AS_DROP_DOWN_MENU;
    if (actions.size() == 1) {
        buttonStyle = IAction.AS_PUSH_BUTTON;
    }
    IAction dropDownAction = new Action("Dropdown", buttonStyle) {
        @Override
        public void run() {
            getSelected().run();
        }
    };
    dropDownAction.setMenuCreator(this);
    return dropDownAction;
}

From source file:com.bluexml.side.application.ui.menu.DynamicMenuAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection myselection) {
    // System.err.println("selectionChanged" + myselection.toString());
    this.selection = (StructuredSelection) myselection;

    action.setMenuCreator(this);
    action.setEnabled(true);/*from  w  w  w. j  av  a  2s  .c  om*/
}

From source file:com.mobilesorcery.sdk.ui.internal.actions.ChangeBuildConfigContextAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    IStructuredSelection ssel = (IStructuredSelection) selection;
    project = CoreMoSyncPlugin.getDefault().extractProject(ssel.toList());
    action.setMenuCreator(this);
}

From source file:com.nokia.carbide.cpp.internal.project.ui.actions.EditMBMMIFMenuEntryActionBase.java

License:Open Source License

public void selectionChanged(final IAction action, ISelection selection) {
    if (!(selection instanceof IStructuredSelection) || selection.isEmpty()
            || ((IStructuredSelection) selection).size() != 1) {
        modelFile = null;/*from w  w w  .ja v a 2s .  com*/
        return;
    }

    Object element = ((IStructuredSelection) selection).getFirstElement();
    if (element instanceof IFile) {
        modelFile = (IFile) element;
        action.setEnabled(true);
        action.setMenuCreator(new IMenuCreator() {
            public void dispose() {
                if (entryMenu != null) {
                    entryMenu.dispose();
                    entryMenu = null;
                }
            }

            public Menu getMenu(Control parent) {
                return null;
            }

            public Menu getMenu(Menu parent) {
                if (entryMenu == null) {
                    entryMenu = new Menu(parent);
                    entryMenu.addMenuListener(new MenuListener() {

                        public void menuHidden(MenuEvent e) {
                        }

                        public void menuShown(MenuEvent e) {
                            fillMenu(entryMenu);
                        }

                    });
                }
                return entryMenu;
            }

        });
    } else {
        modelFile = null;
        action.setEnabled(false);
        action.setMenuCreator(null);
    }
}

From source file:com.nokia.carbide.cpp.uiq.actions.SelectViewPageActionFilterDelegate.java

License:Open Source License

@Override
protected void updateActionForSelectedObject(IAction action, EObject selected) {
    viewLayout = UiqUtils.getViewLayout(selected);
    EObject[] viewpages = getViewPages(viewLayout);
    action.setEnabled(viewpages.length > 0);
    if (viewpages.length == 0)
        return;//from  w w w .  j a v  a2  s  .com

    action.setMenuCreator(new IMenuCreator() {
        private Menu menu;

        public void dispose() {
            if (menu != null)
                menu.dispose();
            menu = null;
        }

        public Menu getMenu(Control parent) {
            return null;
        }

        private void fillMenu(Menu menu) {
            // clear
            MenuItem[] items = menu.getItems();
            for (int i = 0; i < items.length; i++) {
                items[i].dispose();
            }

            ILayoutContainer lc = ModelUtils.getLayoutContainer(viewLayout);
            EObject[] visChildren = lc.getVisibleChildren();
            if (visChildren.length == 0)
                return;

            final EObject visChild = visChildren[0];
            final EObject[] viewpages = getViewPages(viewLayout);
            for (final EObject viewpage : viewpages) {
                MenuItem item = new MenuItem(menu, SWT.CHECK);
                final IComponentInstance ci = ModelUtils.getComponentInstance(viewpage);
                item.setText(ci.getName());
                if (viewpage.equals(visChild)) {
                    item.setSelection(true);
                } else {
                    item.addSelectionListener(new SelectionListener() {
                        public void widgetDefaultSelected(SelectionEvent e) {
                        }

                        public void widgetSelected(SelectionEvent e) {
                            selectViewPage(viewpage);
                        }

                    });
                }
            }
        }

        public Menu getMenu(Menu parent) {
            if (menu == null) {
                menu = new Menu(parent);
                menu.addMenuListener(new MenuListener() {

                    public void menuHidden(MenuEvent e) {
                    }

                    public void menuShown(MenuEvent e) {
                        fillMenu(menu);
                    }
                });
            }
            return menu;
        }
    });
}

From source file:com.nokia.sdt.component.symbian.actions.SwitchVisibleChildActionDelegate.java

License:Open Source License

protected void updateActionForContainer(IAction action, EObject container) {
    if (container == null)
        return;//from  ww  w  . j  a  va2  s.  c om
    IComponent component = Utilities.getComponentInstance(container).getComponent();
    IAttributes attributes = (IAttributes) component.getAdapter(IAttributes.class);
    String childLabel = attributes.getAttribute(CommonAttributes.SWITCHABLE_CHILD_CONTEXT_MENU_CHILD_LABEL);
    if (childLabel != null) {
        IFacetContainer facetContainer = (IFacetContainer) component.getAdapter(IFacetContainer.class);
        ILocalizedStrings localizedStrings = facetContainer.getLocalizedStrings();
        if (localizedStrings != null) {
            childLabel = localizedStrings.checkPercentKey(childLabel);
        }
        action.setText(
                MessageFormat.format(Messages.getString("SwitchVisibleChildActionDelegate.SwitchMenuFormat"), //$NON-NLS-1$
                        new Object[] { childLabel }));
    }
    action.setEnabled(!Utilities.getLayoutChildren(container).isEmpty());
    action.setMenuCreator(this);
}

From source file:fr.openpeople.rdal.ide.view.traceability.RequirementTraceabilityViewPage.java

License:Open Source License

private IAction createActSetRootElement() {
    final IAction action = new Action(null, IAction.AS_DROP_DOWN_MENU) {

        @Override/*from  w w  w .  j ava2s  . com*/
        public void run() {
            if (getImageDescriptor() == imgFlatLayout) {
                setImageDescriptor(imgHierarchicalLayout);
                setToolTipText("Hierarchical Layout");
                setFlatLayout(true);
                actExpColl.setEnabled(false);
            } else {
                setImageDescriptor(imgFlatLayout);
                setToolTipText("Flat Layout");
                setFlatLayout(false);
                actExpColl.setEnabled(true);
            }
        }
    };

    action.setMenuCreator(new IMenuCreator() {
        private Menu menu = null;

        @Override
        public void dispose() {
            if (menu != null) {
                menu.dispose();
                menu = null;
            }
        }

        @Override
        public Menu getMenu(final Control p_parent) {
            if (menu == null) {
                menu = new Menu(p_parent);

                createContributor(Specification.class);
                createContributor(RequirementsGroup.class);
                createContributor(AbstractRequirement.class);
            }

            return menu;
        }

        @Override
        public Menu getMenu(final Menu p_parent) {
            return menu;
        }

        private void createContributor(final Class<? extends IdentifiedElement> p_class) {
            final ActionContributionItem item = new ActionContributionItem(new SetRootElementAction(p_class));
            item.fill(menu, -1);
            item.getAction().setChecked(p_class.equals(contentProvider.getRootElementType()));
        }
    });

    if (INITIAL_FLAT_LAYOUT) {
        action.setToolTipText("Hierarchical Layout");
        action.setImageDescriptor(imgHierarchicalLayout);
    } else {
        action.setToolTipText("Flat Layout");
        action.setImageDescriptor(imgFlatLayout);
    }

    return action;
}

From source file:fr.openpeople.rdalte.ide.view.traceability.RequirementTraceabilityViewPage.java

License:Open Source License

private IAction createActSetRootElement() {
    final IAction action = new Action(null, IAction.AS_DROP_DOWN_MENU) {

        @Override/*from  w  w w .j a va 2  s  .com*/
        public void run() {
            if (getImageDescriptor() == imgFlatLayout) {
                setImageDescriptor(imgHierarchicalLayout);
                setToolTipText("Hierarchical Layout");
                setFlatLayout(true);
                actExpColl.setEnabled(false);
            } else {
                setImageDescriptor(imgFlatLayout);
                setToolTipText("Flat Layout");
                setFlatLayout(false);
                actExpColl.setEnabled(true);
            }
        }
    };

    action.setMenuCreator(new IMenuCreator() {
        private Menu menu = null;

        @Override
        public void dispose() {
            if (menu != null) {
                menu.dispose();
                menu = null;
            }
        }

        @Override
        public Menu getMenu(final Control p_parent) {
            if (menu == null) {
                menu = new Menu(p_parent);

                createContributor(Specification.class);
                createContributor(RequirementsPackage.class);
                createContributor(AbstractRequirement.class);
            }

            return menu;
        }

        @Override
        public Menu getMenu(final Menu p_parent) {
            return menu;
        }

        private void createContributor(final Class<? extends IdentifiedElement> p_class) {
            final ActionContributionItem item = new ActionContributionItem(new SetRootElementAction(p_class));
            item.fill(menu, -1);
            item.getAction().setChecked(p_class.equals(contentProvider.getRootElementType()));
        }
    });

    if (INITIAL_FLAT_LAYOUT) {
        action.setToolTipText("Hierarchical Layout");
        action.setImageDescriptor(imgHierarchicalLayout);
    } else {
        action.setToolTipText("Flat Layout");
        action.setImageDescriptor(imgFlatLayout);
    }

    return action;
}

From source file:name.schedenig.eclipse.grepconsole.actions.AddExpressionAction.java

License:Open Source License

/**
 * Updates the currently selected text.//from  w  w  w.ja v  a  2  s  .  com
 * 
 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    if (action.getMenuCreator() != this) {
        action.setMenuCreator(this);
    }

    selected = null;

    if (selection instanceof ITextSelection) {
        ITextSelection ts = (ITextSelection) selection;

        if (ts.getStartLine() == ts.getEndLine() && ts.getText() != null && ts.getText().length() > 0) {
            selected = ts.getText();
        }
    }

    action.setEnabled(selected != null);

    if (menu != null) {
        updateMenu();
    }
}