Example usage for org.eclipse.jface.action Action getStyle

List of usage examples for org.eclipse.jface.action Action getStyle

Introduction

In this page you can find the example usage for org.eclipse.jface.action Action getStyle.

Prototype

@Override
    public int getStyle() 

Source Link

Usage

From source file:org.eclipse.mat.ui.util.PopupMenu.java

License:Open Source License

private void addToMenu(Menu menu, Listener hide, Listener show, Listener arm, Listener selection) {
    for (Object item : children) {
        if (item instanceof Action) {
            Action action = (Action) item;

            int flags = SWT.PUSH;

            int style = action.getStyle();
            if (style == IAction.AS_CHECK_BOX)
                flags = SWT.CHECK;/* ww w  .  j  ava 2  s  .c  o m*/
            else if (style == IAction.AS_RADIO_BUTTON)
                flags = SWT.RADIO;

            MenuItem menuItem = new MenuItem(menu, flags);

            String acceleratorText = null;
            ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback();
            String commandId = action.getActionDefinitionId();
            if (commandId != null && callback != null)
                acceleratorText = callback.getAcceleratorText(commandId);

            if (acceleratorText == null)
                menuItem.setText(action.getText());
            else
                menuItem.setText(action.getText() + '\t' + acceleratorText);

            if (flags != SWT.PUSH)
                menuItem.setSelection(action.isChecked());

            if (showImages()) {
                ImageDescriptor id = action.getImageDescriptor();
                if (id != null)
                    menuItem.setImage(id.createImage());
            }

            menuItem.setData(action);
            menuItem.addListener(SWT.Selection, selection);
            menuItem.addListener(SWT.Arm, arm);
        } else if (item instanceof PopupMenu) {
            PopupMenu popup = (PopupMenu) item;

            if (!popup.isEmpty()) {
                ImageDescriptor imageDescriptor = popup.getImageDescriptor();

                Menu subMenu = new Menu(menu.getShell(), SWT.DROP_DOWN);
                subMenu.addListener(SWT.Hide, hide);
                subMenu.addListener(SWT.Show, show);

                popup.addToMenu(subMenu, hide, show, arm, selection);

                MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);

                String acceleratorText = null;
                ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback();
                if (popup.actionDefinitionId != null && callback != null)
                    acceleratorText = callback.getAcceleratorText(popup.actionDefinitionId);

                if (acceleratorText == null)
                    menuItem.setText(popup.name);
                else
                    menuItem.setText(popup.name + '\t' + acceleratorText);

                if (imageDescriptor != null)
                    menuItem.setImage(imageDescriptor.createImage());
                menuItem.setMenu(subMenu);
            }
        } else if (item == SEPARATOR) {
            int count = menu.getItemCount();
            if (count > 0 && ((menu.getItem(count - 1).getStyle() & SWT.SEPARATOR) != SWT.SEPARATOR)) {
                new MenuItem(menu, SWT.SEPARATOR);
            }
        }
    }
}