List of usage examples for org.eclipse.jface.action IContributionItem fill
void fill(CoolBar parent, int index);
From source file:com.aptana.theme.internal.SwitchThemesPulldownContributionItem.java
License:Open Source License
@Override public void fill(Menu menu, int index) { IThemeManager manager = ThemePlugin.getDefault().getThemeManager(); List<String> themeNames = new ArrayList<String>(manager.getThemeNames()); // sort ignoring case Collections.sort(themeNames, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); }/* w w w . j a v a 2s . c o m*/ }); for (String name : themeNames) { IContributionItem item = new SwitchThemeContributionItem(manager, name); item.fill(menu, menu.getItemCount()); } }
From source file:com.aptana.webserver.ui.internal.actions.ServerTypesContributionItem.java
License:Open Source License
@Override public void fill(Menu menu, int index) { IServerManager manager = WebServerCorePlugin.getDefault().getServerManager(); List<IServerType> serverTypes = new ArrayList<IServerType>(manager.getServerTypes()); // sort ignoring case Collections.sort(serverTypes, new Comparator<IServerType>() { public int compare(IServerType o1, IServerType o2) { return o1.getName().compareToIgnoreCase(o2.getName()); }//from w w w .ja v a2s . c o m }); for (IServerType type : serverTypes) { IContributionItem item = new NewServerContributionItem(type); item.fill(menu, menu.getItemCount()); } }
From source file:com.archimatetool.editor.actions.AbstractDropDownAction.java
License:Open Source License
private void fill() { for (IContributionItem item : fItems) { item.fill(fMenu, -1); } }
From source file:com.github.haixing_hu.swt.menu.MenuManagerEx.java
License:Open Source License
/** * Call an <code>IContributionItem</code>'s fill method with the * implementation's widget. The default is to use the <code>Menu</code> * widget.<br>// w ww . j av a2 s. c o m * <code>fill(Menu menu, int index)</code> * * @param ci * An <code>IContributionItem</code> whose <code>fill()</code> method * should be called. * @param index * The position the <code>fill()</code> method should start inserting * at. * @since 3.4 */ protected void doItemFill(IContributionItem ci, int index) { ci.fill(menu, index); }
From source file:com.isb.datamodeler.internal.ui.views.actions.workingset.CompoundContributionItem.java
License:Open Source License
public void fill(Menu menu, int index) { if (index == -1) { index = menu.getItemCount();/*from w w w . j av a2 s.c o m*/ } if (!dirty && menu.getParentItem() != null) { // insert a dummy item so that the parent item is not disabled new MenuItem(menu, SWT.NONE, index); return; } IContributionItem[] items = getContributionItemsToFill(); for (int i = 0; i < items.length; i++) { IContributionItem item = items[i]; int oldItemCount = menu.getItemCount(); if (item.isVisible()) { item.fill(menu, index); } int newItemCount = menu.getItemCount(); int numAdded = newItemCount - oldItemCount; index += numAdded; } dirty = false; }
From source file:com.safi.workshop.application.OpenWorkspaceAction.java
License:Open Source License
/** * Set definition for this action and text so that it will be used for File -> Open * Workspace in the argument window./*from ww w.j a va2 s. c o m*/ * * @param window * the window in which this action should appear */ public OpenWorkspaceAction(IWorkbenchWindow window) { super(IDEWorkbenchMessages.OpenWorkspaceAction_text, IAction.AS_DROP_DOWN_MENU); if (window == null) { throw new IllegalArgumentException(); } // TODO help? this.window = window; setActionDefinitionId("com.safi.workshop.actions.ActionSwitchWorkspace"); setId("com.safi.workshop.actions.ActionSwitchWorkspace"); setToolTipText("Switch SafiServer Workspace"); setMenuCreator(new IMenuCreator() { private MenuManager dropDownMenuMgr; /** * Creates the menu manager for the drop-down. */ private void createDropDownMenuMgr() { if (dropDownMenuMgr == null) { dropDownMenuMgr = new MenuManager(); final ChooseSafiServerWorkspaceData data = new ChooseSafiServerWorkspaceData( Platform.getInstanceLocation().getURL()); data.readPersistedData(); String current = data.getInitialDefault(); List<SafiWorkspaceProfile> workspaces = data.getRecentWorkspaces(); for (SafiWorkspaceProfile profile : workspaces) { if (!profile.equals(current)) { dropDownMenuMgr.add(new WorkspaceMRUAction(profile, data)); } } if (!dropDownMenuMgr.isEmpty()) dropDownMenuMgr.add(new Separator()); dropDownMenuMgr.add(new OpenDialogAction()); } } /* * (non-Javadoc) * * @see * org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control) */ public Menu getMenu(Control parent) { createDropDownMenuMgr(); return dropDownMenuMgr.createContextMenu(parent); } /* * (non-Javadoc) * * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu) */ public Menu getMenu(Menu parent) { createDropDownMenuMgr(); Menu menu = new Menu(parent); IContributionItem[] items = dropDownMenuMgr.getItems(); for (IContributionItem item : items) { if (item instanceof ActionContributionItem) { item = new ActionContributionItem(((ActionContributionItem) item).getAction()); } item.fill(menu, -1); } return menu; } /* * (non-Javadoc) * * @see org.eclipse.jface.action.IMenuCreator#dispose() */ public void dispose() { if (dropDownMenuMgr != null) { dropDownMenuMgr.dispose(); dropDownMenuMgr = null; } } }); }
From source file:com.sap.dirigible.ide.ui.rap.managers.CoolBarManager.java
License:Open Source License
public void update(final boolean force) { if ((isDirty() || force) && getControl2() != null) { refresh();/*from w w w .j a v a2s .c om*/ boolean changed = false; /* * Make a list of items including only those items that are visible. * Separators are being removed. Because we use only one Toolbar all * ToolBarContributionItems will be extracted in their IContribution * Items. */ final IContributionItem[] items = getItems(); final List<IContributionItem> visibleItems = new ArrayList<IContributionItem>(items.length); for (int i = 0; i < items.length; i++) { final IContributionItem item = items[i]; if (item.isVisible()) { if (item instanceof IToolBarContributionItem) { IToolBarContributionItem toolbarItem = (IToolBarContributionItem) item; IToolBarManager toolBarManager = toolbarItem.getToolBarManager(); IContributionItem[] toolbarItems = toolBarManager.getItems(); for (int j = 0; j < toolbarItems.length; j++) { final IContributionItem toolItem = toolbarItems[j]; if (toolItem.isVisible() && !toolItem.isSeparator()) { visibleItems.add(toolItem); } } } } } /* * Make a list of ToolItem widgets in the tool bar for which there * is no current visible contribution item. These are the widgets to * be disposed. Dynamic items are also removed. */ ToolItem[] toolItems = toolbar.getItems(); final ArrayList<ToolItem> toolItemsToRemove = new ArrayList<ToolItem>(toolItems.length); for (int i = 0; i < toolItems.length; i++) { final Object data = toolItems[i].getData(); if ((data == null) || (!visibleItems.contains(data)) || ((data instanceof IContributionItem) && ((IContributionItem) data).isDynamic())) { toolItemsToRemove.add(toolItems[i]); } } // Dispose of any items in the list to be removed. for (int i = toolItemsToRemove.size() - 1; i >= 0; i--) { ToolItem toolItem = (ToolItem) toolItemsToRemove.get(i); if (!toolItem.isDisposed()) { Control control = toolItem.getControl(); if (control != null) { toolItem.setControl(null); control.dispose(); } toolItem.dispose(); } } // Add any new items by telling them to fill. toolItems = toolbar.getItems(); IContributionItem sourceItem; IContributionItem destinationItem; int sourceIndex = 0; int destinationIndex = 0; final Iterator<IContributionItem> visibleItemItr = visibleItems.iterator(); while (visibleItemItr.hasNext()) { sourceItem = visibleItemItr.next(); // Retrieve the corresponding contribution item from SWT's // data. if (sourceIndex < toolItems.length) { destinationItem = (IContributionItem) toolItems[sourceIndex].getData(); } else { destinationItem = null; } // The items match if they are equal or both separators. if (destinationItem != null) { if (sourceItem.equals(destinationItem)) { sourceIndex++; destinationIndex++; sourceItem.update(); continue; } else if ((destinationItem.isSeparator()) && (sourceItem.isSeparator())) { toolItems[sourceIndex].setData(sourceItem); sourceIndex++; destinationIndex++; sourceItem.update(); continue; } } // Otherwise, a new item has to be added. final int start = toolbar.getItemCount(); sourceItem.fill(toolbar, destinationIndex); final int newItems = toolbar.getItemCount() - start; // add the selection listener for the styling StylingSelectionAdapter listener = new StylingSelectionAdapter(HEADER_TOOLBAR_VARIANT); for (int i = 0; i < newItems; i++) { ToolItem item = toolbar.getItem(destinationIndex++); item.setData(sourceItem); item.addSelectionListener(listener); } changed = true; } // Remove any old widgets not accounted for. for (int i = toolItems.length - 1; i >= sourceIndex; i--) { final ToolItem item = toolItems[i]; if (!item.isDisposed()) { Control control = item.getControl(); if (control != null) { item.setControl(null); control.dispose(); } item.dispose(); changed = true; } } // Update wrap indices. only needed by a coolbar // updateWrapIndices(); // Update the sizes. for (int i = 0; i < items.length; i++) { IContributionItem item = items[i]; item.update(SIZE); } if (changed) { updateToolbarTabOrder(); } // We are no longer dirty. setDirty(false); styleToolItems(); toolbar.pack(); toolbar.layout(true, true); manageOverflow(); } }
From source file:com.sap.dirigible.ide.ui.rap.managers.CoolBarManager.java
License:Open Source License
@SuppressWarnings("deprecation") private void fillOverflowToolbar() { if (overflowToolbar == null) { // scrolled toolbar parent overflowToolbarParent = new ScrolledComposite(overflowLayer, SWT.V_SCROLL); DummyBuilder builder = new DummyBuilder(null, LayoutSetConstants.SET_ID_OVERFLOW); FormData pos = builder.getPosition(LayoutSetConstants.OVERFLOW_POS); overflowToolbarParent.setLayoutData(pos); // parent for the toolbar Composite parent = new Composite(overflowToolbarParent, SWT.NONE); parent.setLayout(new FillLayout()); // toolbar overflowToolbar = new ToolBar(parent, SWT.VERTICAL); overflowToolbar.setBackgroundMode(SWT.INHERIT_FORCE); overflowToolbar.setData(WidgetUtil.CUSTOM_VARIANT, HEADER_OVERFLOW_VARIANT); overflowLayer.getParent().addFocusListener(focusListener); // configure the ScrolledComposite overflowToolbarParent.setContent(parent); overflowToolbarParent.setExpandVertical(true); overflowToolbarParent.setExpandHorizontal(true); overflowToolbarParent.setOrigin(0, 0); overflowToolbarParent.setAlwaysShowScrollBars(false); }/* w ww .j a v a 2s. c o m*/ // clear the old overflow if items exist clearOverflowToolbar(); // fill the toolbar int maxWidth = 0; for (int i = 0; i < overflowItems.size(); i++) { IContributionItem item = overflowItems.get(i); item.fill(overflowToolbar, i); final ToolItem toolItem = overflowToolbar.getItem(i); // add a selection listener for the styling StylingSelectionAdapter listener = new StylingSelectionAdapter(HEADER_OVERFLOW_VARIANT); toolItem.addSelectionListener(listener); toolItem.setData(WidgetUtil.CUSTOM_VARIANT, HEADER_OVERFLOW_VARIANT); if (toolItem.getWidth() > maxWidth) { maxWidth = toolItem.getWidth(); } } // layout the controls overflowLayer.getParent().layout(true, true); overflowLayer.getParent().pack(true); overflowToolbarParent.setMinSize(maxWidth, overflowItems.size() * 25); // bring the scroll position back to it's origin every time the overflow // has opened overflowToolbarParent.setOrigin(0, 0); overflowToolbarParent.layout(); overflowToolbarParent.setFocus(); }
From source file:de.fhg.igd.eclipse.ui.util.extension.AbstractExtensionContribution.java
License:Apache License
/** * @see ContributionItem#fill(Menu, int) *//*from w ww . j a va 2 s . c o m*/ @Override public void fill(Menu menu, int index) { if (extension == null) { extension = initExtension(); } index = fillWithFactories(menu, getFactories(), index); if (allowConfiguration()) { // add a separator new Separator().fill(menu, index++); IAction action = createConfigurationAction(); IContributionItem item = new ActionContributionItem(action); item.fill(menu, index++); } List<ExtensionObjectFactoryCollection<T, F>> collections = extension.getFactoryCollections(); boolean sep = false; if (!collections.isEmpty()) { for (ExtensionObjectFactoryCollection<T, F> collection : collections) { if ((filter == null || filter.acceptCollection(collection)) && (collection.allowAddNew() || collection.allowRemove())) { if (!sep) { // add a separator new Separator().fill(menu, index++); sep = true; } IAction action = createCollectionAction(collection); IContributionItem item = new ActionContributionItem(action); item.fill(menu, index++); } } } dirty = false; }
From source file:de.fhg.igd.eclipse.ui.util.extension.AbstractExtensionContribution.java
License:Apache License
/** * Fill the menu with factory actions/*from w w w . ja v a 2 s. co m*/ * * @param parent the menu * @param factories the available factories * @param index the index to add the items at * @return the index after the inserted items */ protected int fillWithFactories(Menu parent, List<F> factories, int index) { for (F factory : factories) { IAction action = getFactoryAction(factory); IContributionItem item = new ActionContributionItem(action); item.fill(parent, index++); } return index; }