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

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

Introduction

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

Prototype

@Override
    public String getActionDefinitionId() 

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;/* w w w  .java2 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);
            }
        }
    }
}

From source file:org.opentravel.schemas.stl2Developer.editor.view.DependeciesView.java

License:Apache License

private void registerAction(Action action) {
    getViewSite().getActionBars().setGlobalActionHandler(action.getActionDefinitionId(), action);
}

From source file:org.talend.designer.runprocess.ui.views.ProcessView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    this.parent = parent;
    parent.setLayout(new FillLayout());

    sash = new SashForm(parent, SWT.HORIZONTAL | SWT.SMOOTH);
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    sash.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    GridLayout layout = new GridLayout();
    sash.setLayout(layout);/*from ww w  .  j av a 2s  .  com*/
    Composite left = new Composite(sash, SWT.NONE);

    left.setLayout(new FillLayout());

    Composite right = new Composite(sash, SWT.NONE);
    right.setLayout(new FormLayout());
    FormData layouDatag = new FormData();
    layouDatag.left = new FormAttachment(0, 0);
    layouDatag.width = 32;
    layouDatag.top = new FormAttachment(0, 0);
    layouDatag.bottom = new FormAttachment(100, 0);
    final Composite buttonComposite = new Composite(right, SWT.ERROR);
    buttonComposite.setLayoutData(layouDatag);
    buttonComposite.setLayout(new GridLayout());

    Composite cotextCom = new Composite(right, SWT.NONE);
    layouDatag = new FormData();
    layouDatag.left = new FormAttachment(0, 32);
    layouDatag.right = new FormAttachment(100, 0);
    layouDatag.top = new FormAttachment(0, 0);
    layouDatag.bottom = new FormAttachment(100, 0);
    cotextCom.setLayoutData(layouDatag);
    cotextCom.setLayout(new GridLayout());

    tabFactory.initComposite(left, false);
    moveButton = new Button(buttonComposite, SWT.PUSH);
    moveButton.setText(">>"); //$NON-NLS-1$
    moveButton.setToolTipText(Messages.getString("ProcessComposite.hideContext"));
    final GridData layoutData = new GridData();
    layoutData.verticalAlignment = GridData.CENTER;
    layoutData.horizontalAlignment = GridData.CENTER;
    layoutData.grabExcessHorizontalSpace = true;
    layoutData.grabExcessVerticalSpace = true;
    moveButton.setLayoutData(layoutData);
    addListeners();
    sash.setSashWidth(5);
    sash.setWeights(new int[] { 18, 5 });

    contextComposite = new ProcessContextComposite(cotextCom, SWT.NONE);
    contextComposite.setBackground(right.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    // processComposite = new ProcessComposite(tabFactory.getTabComposite(), SWT.H_SCROLL | SWT.V_SCROLL |
    // SWT.NO_FOCUS);
    // dc = processComposite;
    // createBasicComposite(tabFactory.getTabComposite(), element, null);
    tabFactory.getTabComposite().layout();
    tabFactory.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            TalendPropertyTabDescriptor descriptor = (TalendPropertyTabDescriptor) selection.getFirstElement();

            if (descriptor == null) {
                return;
            }

            if (currentSelectedTab != null && (currentSelectedTab.getCategory() != descriptor.getCategory())) {
                for (Control curControl : tabFactory.getTabComposite().getChildren()) {
                    curControl.dispose();
                }
            }

            if (currentSelectedTab == null || currentSelectedTab.getCategory() != descriptor.getCategory()
                    || selectedPrimary) {

                currentSelectedTab = descriptor;
                selectedPrimary = false;
                createDynamicComposite(tabFactory.getTabComposite(), (Element) descriptor.getData(),
                        descriptor.getCategory());
            }
        }
    });
    setElement();

    IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
    IHandler handler1;
    IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault()
            .getService(IBrandingService.class);
    if (brandingService.getBrandingConfiguration().isAllowDebugMode()) {
        Action debugAction = new DebugAction();
        handler1 = new ActionHandler(debugAction);
        handlerService.activateHandler(debugAction.getActionDefinitionId(), handler1);
    }
    Action killAction = new KillAction();
    handler1 = new ActionHandler(killAction);
    handlerService.activateHandler(killAction.getActionDefinitionId(), handler1);

    FocusListener fl = new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            log.trace(Messages.getString("ProcessView.gainFocusLog")); //$NON-NLS-1$
            IContextService contextService = (IContextService) RunProcessPlugin.getDefault().getWorkbench()
                    .getAdapter(IContextService.class);
            ca = contextService.activateContext("talend.runProcess"); //$NON-NLS-1$
        }

        @Override
        public void focusLost(FocusEvent e) {
            log.trace(Messages.getString("ProcessView.lostFocusLog")); //$NON-NLS-1$
            if (ca != null) {
                IContextService contextService = (IContextService) RunProcessPlugin.getDefault().getWorkbench()
                        .getAdapter(IContextService.class);
                contextService.deactivateContext(ca);
            }
        }
    };

    addListenerOnChildren(parent, fl);
    rubjobManager.setProcessShell(getSite().getShell());

    contextManagerListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (RunProcessContextManager.PROP_ACTIVE.equals(evt.getPropertyName())) {
                // rubjobManager.setBooleanTrace(false);
                runningProcessChanged();
            }
        }
    };
    RunProcessPlugin.getDefault().getRunProcessContextManager()
            .addPropertyChangeListener(contextManagerListener);
    runAction = new RunAction();
}