Example usage for org.eclipse.jface.action IContributionManager removeAll

List of usage examples for org.eclipse.jface.action IContributionManager removeAll

Introduction

In this page you can find the example usage for org.eclipse.jface.action IContributionManager removeAll.

Prototype

void removeAll();

Source Link

Document

Removes all contribution items from this manager.

Usage

From source file:com.coretek.testcase.projectView.views.NewWizardMenu.java

License:Open Source License

private void fillMenu(IContributionManager innerMgr) {
    // Remove all.
    innerMgr.removeAll();

    IContributionItem[] items = getContributionItems();
    for (int i = 0; i < items.length; i++) {
        innerMgr.add(items[i]);//w  ww  . j  a v  a  2 s.co m
    }
}

From source file:com.nokia.tools.variant.carbidev.ApplicationActionBarAdvisor.java

License:Open Source License

private void hackProperties(IWorkbenchWindow window) {

    window.addPageListener(new IPageListener() {

        public void pageActivated(IWorkbenchPage page) {

            getAndHideProperties(page);/*  w w  w . ja v  a2  s. co  m*/

        }

        public void pageClosed(IWorkbenchPage page) {

        }

        public void pageOpened(IWorkbenchPage page) {
            getAndHideProperties(page);

        }

    });

    window.getPartService().addPartListener(new IPartListener() {

        public void partActivated(IWorkbenchPart part) {
            getAndHideProperties(part.getSite().getPage());
        }

        public void partBroughtToTop(IWorkbenchPart part) {
            getAndHideProperties(part.getSite().getPage());
        }

        public void partClosed(IWorkbenchPart part) {
            handlePropertiesVisibility(part);

        }

        private void handlePropertiesVisibility(IWorkbenchPart part) {
            IWorkbench workbench = PlatformUI.getWorkbench();
            if (workbench != null) {
                IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
                if (activeWorkbenchWindow != null) {
                    IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
                    if (activePage != null) {
                        IEditorPart activeEditor = activePage.getActiveEditor();
                        if (activeEditor != null) {
                            return;
                        }
                    }
                }
            }
            if (propertiesControl != null && !propertiesControl.isDisposed()) {
                propertiesControl.setVisible(false);
            } else {
                getAndHideProperties(part.getSite().getPage());
            }
        }

        public void partDeactivated(IWorkbenchPart part) {
            IWorkbench workbench = PlatformUI.getWorkbench();
            if (workbench != null) {
                IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
                if (activeWorkbenchWindow != null) {
                    IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
                    if (activePage != null) {
                        IEditorPart activeEditor = activePage.getActiveEditor();
                        if (activeEditor != null) {
                            return;
                        }
                    }
                }
            }
            if (propertiesControl != null && !propertiesControl.isDisposed()) {
                propertiesControl.setVisible(false);
            } else {
                getAndHideProperties(part.getSite().getPage());
            }
        }

        public void partOpened(IWorkbenchPart part) {
            IWorkbench workbench = PlatformUI.getWorkbench();
            if (workbench != null) {
                IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
                if (activeWorkbenchWindow != null) {
                    IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
                    if (activePage != null) {
                        IEditorPart activeEditor = activePage.getActiveEditor();
                        if (activeEditor != null) {
                            return;
                        }
                    }
                }
            }
            if (part instanceof PropertySheet) {
                PageBookView findView = (PageBookView) part;
                if (findView.getCurrentPage() instanceof PropertySheetPage) {
                    PropertySheetPage currentPage = (PropertySheetPage) findView.getCurrentPage();
                    SubActionBars actionBars = (SubActionBars) currentPage.getSite().getActionBars();
                    SubToolBarManager toolBarManager = (SubToolBarManager) actionBars.getToolBarManager();
                    IContributionManager parent2 = toolBarManager.getParent();
                    parent2.removeAll();
                    parent2.update(true);
                    propertiesControl = (Composite) currentPage.getControl();
                    propertiesControl.setVisible(false);
                    propertiesControl.addPaintListener(new PaintListener() {

                        public void paintControl(PaintEvent e) {
                            propertiesControl.setVisible(false);

                        }

                    });
                }
            }
        }

    });

}

From source file:com.nokia.tools.variant.carbidev.ApplicationActionBarAdvisor.java

License:Open Source License

private void getAndHideProperties(IWorkbenchPage page) {
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow != null) {
        IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
        if (activePage != null) {
            IEditorPart activeEditor = activePage.getActiveEditor();
            if (activeEditor != null) {
                return;
            }/*from   w  w  w  . j a  va  2  s  .c o m*/
        }
    }
    PageBookView findView = (PageBookView) page.findView("org.eclipse.ui.views.PropertySheet");
    if (findView != null && findView.getCurrentPage() instanceof PropertySheetPage) {
        PropertySheetPage currentPage = (PropertySheetPage) findView.getCurrentPage();
        SubActionBars actionBars = (SubActionBars) currentPage.getSite().getActionBars();
        SubToolBarManager toolBarManager = (SubToolBarManager) actionBars.getToolBarManager();
        IContributionManager parent2 = toolBarManager.getParent();
        parent2.removeAll();
        parent2.update(true);
        propertiesControl = (Composite) currentPage.getControl();
        propertiesControl.setVisible(false);
        propertiesControl.addPaintListener(new PaintListener() {

            public void paintControl(PaintEvent e) {
                propertiesControl.setVisible(false);

            }

        });
    }
}

From source file:org.eclipse.php.internal.ui.actions.PHPNewWizardMenu.java

License:Open Source License

private void fillMenu(IContributionManager innerMgr) {
    // Remove all.
    innerMgr.removeAll();

    if (this.enabled) {
        // Add new project ..
        innerMgr.add(newProjectAction);//from w  ww . j  a va2 s .c  o m

        // Get visible actions.
        String[] actions = null;
        IWorkbenchPage page = window.getActivePage();
        if (page != null)
            actions = ((WorkbenchPage) page).getNewWizardShortcuts();

        if (actions != null) {
            if (actions.length > 0)
                innerMgr.add(new Separator());
            for (int i = 0; i < actions.length; i++) {
                String id = actions[i];
                IAction action = getAction(id);
                if (action != null) {
                    if (WorkbenchActivityHelper.filterItem(action))
                        continue;
                    innerMgr.add(action);
                }
            }
        }

        if (hasExamples()) {
            // Add examples ..
            innerMgr.add(new Separator());
            innerMgr.add(newExampleAction);
        }

        // Add other ..
        innerMgr.add(new Separator());
        innerMgr.add(showDlgAction);
    }
}

From source file:org.jlibrary.client.actions.NewWizardMenu.java

License:Open Source License

private void fillMenu(IContributionManager innerMgr) {
    // Remove all.
    innerMgr.removeAll();
    innerMgr.add(newRepositoryAction);/*from   ww w .  j  av  a2 s.  c o  m*/
    innerMgr.add(new Separator());
    innerMgr.add(newDirectoryAction);
    innerMgr.add(newDocumentAction);
    innerMgr.add(newResourceAction);
}

From source file:org.nightlabs.base.ui.action.registry.AbstractActionRegistry.java

License:Open Source License

/**
 * This method contributes WITHOUT removing items before.
 *
 * @param contributionManager//from   w w  w.  j  a  va 2 s . c o  m
 * @param kind
 * @return Returns the number of visible contribution items (i.e. actions) that have been added.
 */
protected Map<Class<? extends ItemDescriptor>, List<ItemDescriptor>> contribute(
        IContributionManager contributionManager, ContributionManagerKind kind) {
    Map<Class<? extends ItemDescriptor>, List<ItemDescriptor>> visibleItemDescriptors = new HashMap<Class<? extends ItemDescriptor>, List<ItemDescriptor>>();
    ActionVisibilityContext actionVisibilityContext = new ActionVisibilityContext(kind);
    List<ItemDescriptor> menuSorted = contributionManagerKind2menuSorted.get(kind);

    boolean firstRun = menuSorted == null;
    LinkedList<ItemDescriptor> menuRaw = null;
    int lastMenuRawSize = 0;
    if (firstRun) {
        menuRaw = new LinkedList<ItemDescriptor>(this.menuRaw);
        menuRaw.add(new SeparatorDescriptor("additions")); //$NON-NLS-1$
        lastMenuRawSize = menuRaw.size();
        menuSorted = new LinkedList<ItemDescriptor>();
    }

    //      contributionManager.removeAll();

    while ((firstRun && !menuRaw.isEmpty()) || !firstRun) {
        for (Iterator<?> itTopLevel = (firstRun ? menuRaw : menuSorted).iterator(); itTopLevel.hasNext();) {
            ItemDescriptor item = (ItemDescriptor) itTopLevel.next();
            if (item instanceof ActionDescriptor) {
                ActionDescriptor ad = (ActionDescriptor) item;

                String path = getPath(ad, kind);

                IContributionItem anchor = path == null ? null : findUsingPath(contributionManager, path);
                if (anchor != null) {
                    if (actionVisibilityDecider.isVisible(actionVisibilityContext, ad)) {
                        addVisibleItemDescriptor(visibleItemDescriptors, ActionDescriptor.class, ad);

                        if (anchor instanceof MenuManager) {
                            if (ad.getAction() != null)
                                ((MenuManager) anchor).add(ad.getAction());
                            else if (ad.getContributionItem() != null)
                                ((MenuManager) anchor).add(ad.getContributionItem());
                        } else {
                            if (ad.getAction() != null)
                                ((ContributionItem) anchor).getParent().insertAfter(anchor.getId(),
                                        ad.getAction());
                            else if (ad.getContributionItem() != null)
                                ((ContributionItem) anchor).getParent().insertAfter(anchor.getId(),
                                        ad.getContributionItem());
                        }
                    }

                    if (firstRun) {
                        menuSorted.add(item);
                        itTopLevel.remove();
                    }
                }
            } else if (item instanceof SeparatorDescriptor) {
                addVisibleItemDescriptor(visibleItemDescriptors, SeparatorDescriptor.class, item);

                SeparatorDescriptor s = (SeparatorDescriptor) item;
                String path = s.getPath();
                IContributionItem anchor = path == null ? null : findUsingPath(contributionManager, path);
                if (path == null || anchor != null) {
                    Separator separator = new Separator(s.getName());

                    if (anchor == null) {
                        if (contributionManager.find(item.getID()) == null)
                            contributionManager.add(separator);
                    } else {
                        if (((ContributionItem) anchor).getParent().find(item.getID()) == null)
                            ((ContributionItem) anchor).getParent().insertAfter(anchor.getId(), separator);
                    }

                    if (firstRun) {
                        menuSorted.add(item);
                        itTopLevel.remove();
                    }
                }
            } else if (item instanceof GroupMarkerDescriptor) {
                addVisibleItemDescriptor(visibleItemDescriptors, GroupMarkerDescriptor.class, item);

                GroupMarkerDescriptor gm = (GroupMarkerDescriptor) item;
                String path = gm.getPath();
                IContributionItem anchor = path == null ? null : findUsingPath(contributionManager, path);
                if (path == null || anchor != null) {
                    GroupMarker groupMarker = new GroupMarker(gm.getName());

                    if (anchor == null) {
                        if (contributionManager.find(item.getID()) == null)
                            contributionManager.add(groupMarker);
                    } else {
                        if (((ContributionItem) anchor).getParent().find(item.getID()) == null)
                            ((ContributionItem) anchor).getParent().insertAfter(anchor.getId(), groupMarker);
                    }

                    if (firstRun) {
                        menuSorted.add(item);
                        itTopLevel.remove();
                    }
                }
            } else if (item instanceof MenuDescriptor) {
                addVisibleItemDescriptor(visibleItemDescriptors, MenuDescriptor.class, item);
                MenuDescriptor md = (MenuDescriptor) item;
                String path = md.getPath();

                // already existing in the contribution-manager?
                IContributionItem anchor = path == null ? null : findUsingPath(contributionManager, path);
                if (path == null || anchor != null) {
                    MenuManager subMenu = new MenuManager(md.getLabel(), md.getID());

                    for (Iterator<?> itSub = md.getSubItems().iterator(); itSub.hasNext();) {
                        Object obj = itSub.next();
                        if (obj instanceof SeparatorDescriptor) {
                            SeparatorDescriptor separator = (SeparatorDescriptor) obj;
                            subMenu.add(new Separator(separator.getName()));
                        } else if (obj instanceof GroupMarkerDescriptor) {
                            GroupMarkerDescriptor groupMarker = (GroupMarkerDescriptor) obj;
                            subMenu.add(new GroupMarker(groupMarker.getName()));
                        } else
                            throw new IllegalStateException(
                                    "SubItem of menu is neither a SeparatorDescriptor nor a GroupMarkerDescriptor but " //$NON-NLS-1$
                                            + obj.getClass().getName());
                    }

                    if (anchor == null) {
                        if (contributionManager.find(item.getID()) == null)
                            contributionManager.add(subMenu);
                    } else {
                        if (((ContributionItem) anchor).getParent().find(item.getID()) == null)
                            ((ContributionItem) anchor).getParent().insertAfter(anchor.getId(), subMenu);
                    }

                    if (firstRun) {
                        menuSorted.add(item);
                        itTopLevel.remove();
                    }
                }
            } else
                throw new IllegalStateException(
                        "Item in menuRaw of type " + item.getClass() + " is an instance of an unknown class!"); //$NON-NLS-1$ //$NON-NLS-2$
        }

        if (firstRun && (lastMenuRawSize == menuRaw.size())) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not add the following contributions to the menu (kind " + kind + "):"); //$NON-NLS-1$ //$NON-NLS-2$
                for (Iterator<ItemDescriptor> it = menuRaw.iterator(); it.hasNext();) {
                    ItemDescriptor item = it.next();
                    if (item instanceof ActionDescriptor) {
                        logger.debug("    Action with id=" + ((ActionDescriptor) item).getID()); //$NON-NLS-1$
                    } else if (item instanceof MenuDescriptor) {
                        logger.debug("    Menu with id=" + ((MenuDescriptor) item).getID()); //$NON-NLS-1$
                    } else if (item instanceof SeparatorDescriptor) {
                        logger.debug("    Separator with name=" + ((SeparatorDescriptor) item).getName()); //$NON-NLS-1$
                    } else if (item instanceof GroupMarkerDescriptor) {
                        logger.debug("    GroupMarker with name=" + ((GroupMarkerDescriptor) item).getName()); //$NON-NLS-1$
                    } else
                        logger.debug("    " + item); //$NON-NLS-1$
                }
            }
            break;
        }

        if (!firstRun)
            break;

        lastMenuRawSize = menuRaw.size();
    } // while ((firstRun && !menuRaw.isEmpty()) || !firstRun) {

    if (firstRun)
        contributionManagerKind2menuSorted.put(kind, menuSorted);

    // flatten the menus if we're contributing to the toolbar (which doesn't understand sub-menus)
    // the coolbar is handled by contributeToCoolBar(...) directly
    if (ContributionManagerKind.toolBar == kind) {
        IContributionItem[] items = contributionManager.getItems();
        contributionManager.removeAll();
        for (int i = 0; i < items.length; ++i) {
            IContributionItem item = items[i];
            if (item instanceof IMenuManager)
                addFlattenedMenu(contributionManager, null, (IMenuManager) item);
            else
                contributionManager.add(item);
        }
    }
    contributionManager.update(true);

    debugContributions(visibleItemDescriptors, kind, true);

    return visibleItemDescriptors;
}