Example usage for org.eclipse.jface.action ToolBarManager remove

List of usage examples for org.eclipse.jface.action ToolBarManager remove

Introduction

In this page you can find the example usage for org.eclipse.jface.action ToolBarManager remove.

Prototype

@Override
    public IContributionItem remove(String ID) 

Source Link

Usage

From source file:de.loskutov.anyedit.actions.internal.StartupHelper.java

License:Open Source License

private static int insert(IDirtyWorkaround myAction, ToolBarManager manager, int controlIdx) {
    IContributionItem item;// w  w w  . j a v  a  2s  . c  o m
    // get "file->save" action
    item = manager.find(myAction.getId());
    if (item != null) {
        // copy references to opened editor/part
        myAction.copyStateAndDispose(item);
        if (controlIdx < 0) {
            // get/remember position
            IContributionItem[] items = manager.getItems();
            for (int i = 0; i < items.length; i++) {
                if (items[i].isSeparator() || items[i] instanceof ActionContributionItem) {
                    controlIdx++;
                    if (items[i] == item) {
                        break;
                    }
                }
            }
        }
        // clean old one
        manager.remove(item);
        item = new ActionContributionItem(myAction);
        manager.insert(controlIdx, item);
        // refresh menu gui
        manager.update(true);
    } else if (controlIdx >= 0) {
        item = new ActionContributionItem(myAction);
        manager.insert(controlIdx, item);
        // refresh menu gui
        manager.update(true);
    }
    return controlIdx;
}

From source file:net.yatomiya.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.java

License:Open Source License

@Inject
@Optional/* ww  w  .j a v  a 2 s . c  o m*/
private void subscribeTopicUpdateToBeRendered(@UIEventTopic(UIEvents.UIElement.TOPIC_ALL) Event event) {
    // Ensure that this event is for a MMenuItem
    if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) {
        return;
    }

    MToolBarElement itemModel = (MToolBarElement) event.getProperty(UIEvents.EventTags.ELEMENT);
    String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
    if (UIEvents.UIElement.TOBERENDERED.equals(attName)) {
        Object obj = itemModel.getParent();
        if (!(obj instanceof MToolBar)) {
            return;
        }
        ToolBarManager parent = getManager((MToolBar) obj);
        if (itemModel.isToBeRendered()) {
            if (parent != null) {
                modelProcessSwitch(parent, itemModel);
                parent.update(true);
                ToolBar tb = parent.getControl();
                if (tb != null && !tb.isDisposed()) {
                    tb.pack(true);
                    tb.getShell().layout(new Control[] { tb }, SWT.DEFER);
                }
            }
        } else {
            IContributionItem ici = modelToContribution.remove(itemModel);
            if (ici != null && parent != null) {
                parent.remove(ici);
            }
            if (ici != null) {
                ici.dispose();
            }
        }
    } else if (UIEvents.UIElement.VISIBLE.equals(attName)) {
        IContributionItem ici = getContribution(itemModel);
        if (ici == null) {
            return;
        }

        ToolBarManager parent = null;
        if (ici instanceof MenuManager) {
            parent = (ToolBarManager) ((MenuManager) ici).getParent();
        } else if (ici instanceof ContributionItem) {
            parent = (ToolBarManager) ((ContributionItem) ici).getParent();
        }

        if (parent == null) {
            ici.setVisible(itemModel.isVisible());
            return;
        }

        IContributionManagerOverrides ov = parent.getOverrides();
        // partial fix for bug 383569: only change state if there are no
        // extra override mechanics controlling element visibility
        if (ov == null) {
            ici.setVisible(itemModel.isVisible());
        } else {
            Boolean visible = ov.getVisible(ici);
            if (visible == null) {
                // same as above: only change state if there are no extra
                // override mechanics controlling element visibility
                ici.setVisible(itemModel.isVisible());
            }
        }

        parent.markDirty();
        parent.update(true);
        ToolBar tb = parent.getControl();
        if (tb != null && !tb.isDisposed()) {
            tb.pack(true);
            if (tb.getParent() != null) {
                tb.getParent().pack(true);
            }
            tb.getShell().layout(new Control[] { tb }, SWT.DEFER);
        }
    }
}

From source file:org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer.java

License:Open Source License

/**
 * {@inheritDoc}/*from   ww w  .  ja  va 2  s .c  om*/
 * 
 * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#createToolItems(org.eclipse.jface.action.ToolBarManager)
 */
@Override
protected void createToolItems(final ToolBarManager toolBarManager) {
    getHandlerService().setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
    getHandlerService().setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);

    IContributionItem[] items = toolBarManager.getItems();
    for (IContributionItem iContributionItem : items) {
        if (iContributionItem instanceof ActionContributionItem) {
            IAction action = ((ActionContributionItem) iContributionItem).getAction();
            String id = action.getActionDefinitionId();
            if ("org.eclipse.compare.copyAllLeftToRight".equals(id)) {
                toolBarManager.remove(iContributionItem);
            } else if ("org.eclipse.compare.copyAllRightToLeft".equals(id)) {
                toolBarManager.remove(iContributionItem);
            }
        }
    }

    // Add extension point contributions to the content merge viewer toolbar
    if (PlatformUI.isWorkbenchRunning()) {
        IServiceLocator workbench = PlatformUI.getWorkbench();
        final IMenuService menuService = (IMenuService) workbench.getService(IMenuService.class);
        if (menuService != null) {
            menuService.populateContributionManager(toolBarManager,
                    "toolbar:org.eclipse.emf.compare.contentmergeviewer.toolbar"); //$NON-NLS-1$
            toolBarManager.getControl().addDisposeListener(new DisposeListener() {
                public void widgetDisposed(DisposeEvent e) {
                    menuService.releaseContributions(toolBarManager);
                }
            });
        }
    }
}

From source file:org.eclipse.mylyn.internal.xplanner.ui.editor.XPlannerTaskEditor.java

License:Open Source License

@Override
protected Set<TaskEditorPartDescriptor> createPartDescriptors() {
    Set<TaskEditorPartDescriptor> descriptors = super.createPartDescriptors();

    // remove unnecessary default editor parts
    for (Iterator<TaskEditorPartDescriptor> iterator = descriptors.iterator(); iterator.hasNext();) {
        TaskEditorPartDescriptor taskEditorPartDescriptor = iterator.next();

        if (taskEditorPartDescriptor.getId().equals(ID_PART_PEOPLE)
                || taskEditorPartDescriptor.getId().equals(ID_PART_ATTRIBUTES)
                || taskEditorPartDescriptor.getId().equals(ID_PART_DESCRIPTION)
                || taskEditorPartDescriptor.getId().equals(ID_PART_ATTACHMENTS)
                || taskEditorPartDescriptor.getId().equals(ID_PART_COMMENTS)
                || taskEditorPartDescriptor.getId().equals(ID_PART_NEW_COMMENT)
                || taskEditorPartDescriptor.getId().equals(ID_PART_ACTIONS)) {

            iterator.remove();/*ww  w .  ja va2s.c  o m*/
        }
    }
    // Add XPlanner attributes
    descriptors.add(new TaskEditorPartDescriptor(ID_PART_ATTRIBUTES) {
        @Override
        public AbstractTaskEditorPart createPart() {
            return getExtraControls();
        }
    }.setPath(PATH_ATTRIBUTES));

    descriptors.add(new TaskEditorPartDescriptor(ID_PART_DESCRIPTION) {
        @Override
        public AbstractTaskEditorPart createPart() {
            TaskEditorDescriptionPart part = new TaskEditorDescriptionPart() {
                /**
                 * Remove replyTo action -- doesn't apply to description for XPlanner
                 */
                @Override
                protected void fillToolBar(ToolBarManager toolBar) {
                    super.fillToolBar(toolBar);
                    for (IContributionItem contributionItem : toolBar.getItems()) {
                        if (contributionItem instanceof ActionContributionItem
                                && ((ActionContributionItem) contributionItem)
                                        .getAction() instanceof AbstractReplyToCommentAction) {

                            toolBar.remove(contributionItem);
                            break;
                        }
                    }
                }
            };
            if (getModel().getTaskData().isNew()) {
                part.setExpandVertically(true);
                part.setSectionStyle(ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED);
            }
            return part;
        }
    }.setPath(PATH_ATTRIBUTES));

    // Add XPlanner time tracking part
    if (!newTask) {
        try {
            TaskData data = TasksUi.getTaskDataManager().getTaskData(getTask());
            if (data != null) {
                descriptors.add(new TaskEditorPartDescriptor(ID_PART_XPLANNER_TIME_TRACKING) {
                    @Override
                    public AbstractTaskEditorPart createPart() {
                        timeTrackingControls = new XPlannerTimeTrackingEditorPart(getTask(),
                                XPlannerTaskEditor.this);
                        return timeTrackingControls;
                    }
                }.setPath(PATH_ATTRIBUTES));
            }
        } catch (CoreException e) {
            // ignore
        }
    }

    // add actions with context attachment section removed
    descriptors.add(new TaskEditorPartDescriptor(ID_PART_ACTIONS) {
        @Override
        public AbstractTaskEditorPart createPart() {
            return new TaskEditorActionPart() {

                @Override
                protected void addAttachContextButton(Composite buttonComposite, FormToolkit toolkit) {
                    // do not add attachContextButton
                }

            };
        }
    }.setPath(PATH_ACTIONS));
    return descriptors;
}