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

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

Introduction

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

Prototype

int AS_DROP_DOWN_MENU

To view the source code for org.eclipse.jface.action IAction AS_DROP_DOWN_MENU.

Click Source Link

Document

Action style constant (value 4) indicating action is a drop down menu.

Usage

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.  ja  v  a2s . 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.aptana.browser.WebBrowserViewer.java

License:Open Source License

private void createCommandBar(Composite parent) {
    final MenuManager menuManager = new MenuManager("#CommandMenu"); //$NON-NLS-1$
    MenuManager sizeMenuManager = new MenuManager(Messages.WebBrowserViewer_LBL_SetSize);
    sizeMenuManager.add(new Action(Messages.WebBrowserViewer_LBL_FullEditor) {

        @Override//from  w  w w .j av  a  2 s .c om
        public void run() {
            currentSize = null;
            layout();
        }
    });
    menuManager.add(sizeMenuManager);

    BrowserSizeCategory[] categories = BrowserPlugin.getDefault().getBrowserConfigurationManager()
            .getSizeCategories();
    Arrays.sort(categories);
    MenuManager categoryMenuManager;
    BrowserSize[] sizes;
    for (BrowserSizeCategory category : categories) {
        // first level has the categories
        categoryMenuManager = new MenuManager(category.getName());
        sizeMenuManager.add(categoryMenuManager);

        sizes = category.getSizes();
        for (final BrowserSize size : sizes) {
            // then shows size configurations for each category
            categoryMenuManager.add(new Action(size.getName()) {

                @Override
                public void run() {
                    disposeImage();

                    currentSize = size;
                    boolean blackBackground = false;
                    BrowserBackgroundImage image = currentSize.getImage();
                    if (image != null) {
                        currentImage = image.getImageDescriptor().createImage();
                        blackBackground = image.isBlackBackground();
                    }
                    Color background = blackBackground ? getDisplay().getSystemColor(SWT.COLOR_BLACK)
                            : getDisplay().getSystemColor(SWT.COLOR_WHITE);
                    setBackground(background);
                    backgroundArea.setBackground(background);
                    resizeBackground();
                }
            });
        }
    }

    sizeMenuManager.add(new Action(Messages.WebBrowserViewer_LBL_Custom) {

        @Override
        public void run() {
            setCustomSize();
        }
    });

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    Action action = new Action("Command", IAction.AS_DROP_DOWN_MENU) //$NON-NLS-1$
    {

        @Override
        public void run() {
            // not doing anything
        }
    };
    action.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_ELCL_COMMAND));
    action.setMenuCreator(new IMenuCreator() {

        public void dispose() {
        }

        public Menu getMenu(Control parent) {
            return menuManager.createContextMenu(parent);
        }

        public Menu getMenu(Menu parent) {
            return null;
        }
    });
    toolBarManager.add(action);
    ToolBar sizeToolBar = toolBarManager.createControl(parent);
    sizeToolBar.setLayoutData(GridDataFactory.fillDefaults().create());
}

From source file:com.aptana.browser.WebBrowserViewer4Mac.java

License:Open Source License

protected void createCommandBar(Composite parent) {
    final MenuManager menuManager = new MenuManager("#CommandMenu"); //$NON-NLS-1$
    menuManager.add(new Action(Messages.WebBrowserViewer_LBL_FullEditor) {
        @Override/*from   w  w w.  j  a va  2s  .  c om*/
        public void run() {
            currentSize = null;
            layout();
        }
    });

    BrowserSizeCategory[] categories = BrowserPlugin.getDefault().getBrowserConfigurationManager()
            .getSizeCategories();
    Arrays.sort(categories);
    BrowserSize[] sizes;
    for (BrowserSizeCategory category : categories) {
        sizes = category.getSizes();
        for (final BrowserSize size : sizes) {
            // then shows size configurations for each category
            menuManager.add(new Action(size.getName()) {

                @Override
                public void run() {
                    disposeImage();

                    currentSize = size;
                    boolean blackBackground = false;
                    BrowserBackgroundImage image = currentSize.getImage();
                    if (image != null) {
                        currentImage = image.getImageDescriptor().createImage();
                        blackBackground = image.isBlackBackground();
                    }
                    Color background = blackBackground ? getDisplay().getSystemColor(SWT.COLOR_BLACK)
                            : getDisplay().getSystemColor(SWT.COLOR_WHITE);
                    setBackground(background);
                    backgroundArea.setBackground(background);
                    resizeBackground();
                }
            });
        }
    }

    menuManager.add(new Action(Messages.WebBrowserViewer_LBL_Custom) {

        @Override
        public void run() {
            setCustomSize();
        }
    });

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    Action action = new Action(Messages.WebBrowserViewer_LBL_Set, IAction.AS_DROP_DOWN_MENU) //$NON-NLS-1$
    {

        @Override
        public void run() {
            // not doing anything
        }
    };
    action.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_ELCL_COMMAND));
    action.setMenuCreator(new IMenuCreator() {

        public void dispose() {
        }

        public Menu getMenu(Control parent) {
            return menuManager.createContextMenu(parent);
        }

        public Menu getMenu(Menu parent) {
            return null;
        }
    });
    toolBarManager.add(action);
    ToolBar sizeToolBar = toolBarManager.createControl(parent);
    sizeToolBar.setLayoutData(GridDataFactory.fillDefaults().create());
}

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

License:Open Source License

/**
 * //www  . j  av  a 2  s .  c  o m
 */
public DynamicEngineMenu(String name, MenuDescriptor menu) {
    super(name, IAction.AS_DROP_DOWN_MENU);
    mMenuDesc = menu;
    setId("seecode." + name);
}

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

License:Open Source License

/**
 * // w ww.  j av  a 2  s.c  om
 */
public SeeCodeDisplayAction(EngineInterface engine) {
    super("Debugger", IAction.AS_DROP_DOWN_MENU);
    mMenuCreator = new SeeCodeSelectorMenuCreator(engine);
    setId("seecode.selectors." + ++sInstanceCount);
}

From source file:com.architexa.org.eclipse.gef.internal.ui.palette.ToolbarDropdownContributionItem.java

License:Open Source License

/**
 * The <code>ToolbarDropdownContributionItem</code> implementation of this 
 * <code>IContributionItem</code> method creates a SWT MenuItem for the action. 
 * If the action's checked property has been set, a toggle button is created 
 * and primed to the value of the checked property.
 * If the action's menu creator property has been set, a cascading submenu is created.
 *///from www .  j  av a 2  s  . c o  m
public void fill(Menu parent, int index) {
    if (widget == null && parent != null) {
        int flags = SWT.PUSH;
        Menu subMenu = null;

        if (action != null) {
            int style = action.getStyle();
            if (style == IAction.AS_CHECK_BOX)
                flags = SWT.CHECK;
            else if (style == IAction.AS_DROP_DOWN_MENU) {
                IMenuCreator mc = action.getMenuCreator();
                subMenu = mc.getMenu(parent);
                flags = SWT.CASCADE;
            }
        }

        MenuItem mi = null;
        if (index >= 0)
            mi = new MenuItem(parent, flags, index);
        else
            mi = new MenuItem(parent, flags);
        widget = mi;

        mi.setData(this);
        mi.addListener(SWT.Arm, listener);
        mi.addListener(SWT.Dispose, listener);
        mi.addListener(SWT.Selection, listener);
        if (action.getHelpListener() != null)
            mi.addHelpListener(action.getHelpListener());

        if (subMenu != null)
            mi.setMenu(subMenu);

        update(null);

        action.addPropertyChangeListener(listener);
    }
}

From source file:com.architexa.org.eclipse.gef.internal.ui.palette.ToolbarDropdownContributionItem.java

License:Open Source License

/**
 * The <code>ToolbarDropdownContributionItem</code> implementation of this 
 * <code>IContributionItem</code> method creates a SWT ToolItem for the action. 
 * If the action's checked property has been set, a toggle button is created 
 * and primed to the value of the checked property.
 * If the action's menu creator property has been set, a drop-down
 * tool item is created.// w  w w.  java  2 s.  c o m
 */
public void fill(ToolBar parent, int index) {
    if (widget == null && parent != null) {
        int flags = SWT.PUSH;

        if (action != null) {
            int style = action.getStyle();
            if (style == IAction.AS_CHECK_BOX)
                flags = SWT.CHECK;
            else if (style == IAction.AS_DROP_DOWN_MENU)
                flags = SWT.DROP_DOWN;
        }

        ToolItem ti = null;
        if (index >= 0)
            ti = new ToolItem(parent, flags, index);
        else
            ti = new ToolItem(parent, flags);
        ti.setData(this);
        ti.addListener(SWT.Selection, listener);
        ti.addListener(SWT.Dispose, listener);

        widget = ti;

        update(null);

        action.addPropertyChangeListener(listener);
    }
}

From source file:com.architexa.org.eclipse.gef.internal.ui.palette.ToolbarDropdownContributionItem.java

License:Open Source License

/**
 * Handles a widget dispose event for the widget corresponding to this item.
 *///from w w w.  ja v a2  s  . c o  m
private void handleWidgetDispose(Event e) {
    if (e.widget == widget) {
        // the item is being disposed
        if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) {
            action.getMenuCreator().dispose();
        }
        action.removePropertyChangeListener(listener);
        widget = null;
    }
}

From source file:com.architexa.org.eclipse.gef.internal.ui.palette.ToolbarDropdownContributionItem.java

License:Open Source License

/**
 * Handles a widget selection event.//from w ww.  j a v a2 s  .c  om
 */
private void handleWidgetSelection(Event e) {
    Widget item = e.widget;
    if (item != null) {

        int style = item.getStyle();

        if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) {
            if (action.getStyle() == IAction.AS_CHECK_BOX) {
                action.setChecked(!action.isChecked());
            }

        } else if ((style & SWT.DROP_DOWN) != 0) {
            /*
             * Added by Pratik Shah
             * Do this regardless of whether the down arrow button on the side was
             * clicked, or the main button itself
             */
            if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) {
                IMenuCreator mc = action.getMenuCreator();
                ToolItem ti = (ToolItem) item;
                // we create the menu as a sub-menu of "dummy" so that we can use
                // it in a cascading menu too.
                // If created on a SWT control we would get an SWT error...
                //Menu dummy= new Menu(ti.getParent());
                //Menu m= mc.getMenu(dummy);
                //dummy.dispose();

                Menu m = mc.getMenu(ti.getParent());
                if (m != null) {
                    // position the menu below the drop down item
                    Rectangle b = ti.getBounds();
                    Point p = ti.getParent().toDisplay(new Point(b.x, b.y + b.height));
                    m.setLocation(p.x, p.y); // waiting for SWT 0.42
                    m.setVisible(true);
                    return; // we don't fire the action
                }
            }
        }

        // Ensure action is enabled first.
        // See 1GAN3M6: ITPUI:WINNT - Any IAction in the workbench can be executed 
        // while disabled.
        if (action.isEnabled()) {
            action.runWithEvent(e);
        }
    }
}

From source file:com.centurylink.mdw.plugin.designer.editors.ProcessEditorActionBarContributor.java

License:Apache License

private IAction createLinkTypeAction() {
    IAction action = new Action(null, IAction.AS_DROP_DOWN_MENU) {
        public IMenuCreator getMenuCreator() {
            return linkTypeMenuCreator;
        }/* ww  w . ja va 2 s  . com*/
    };
    action.setText("Link Style");
    ImageDescriptor descriptor = MdwPlugin.getImageDescriptor("icons/link.gif");
    action.setImageDescriptor(descriptor);
    return action;
}