/* (non-Javadoc) * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.Menu, int) */ public void fill(Menu parent, int index) { if (menuItem == null || menuItem.isDisposed()) { if (index >= 0) { menuItem = new MenuItem(parent, SWT.CASCADE, index); } else { menuItem = new MenuItem(parent, SWT.CASCADE); } String text = getMenuText(); if (text != null) { menuItem.setText(text); } if (image != null) { LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources()); menuItem.setImage(localManager.createImage(image)); disposeOldImages(); imageManager = localManager; } if (!menuExist()) { menu = new Menu(parent); menu.setData(MANAGER_KEY, this); } menuItem.setMenu(menu); initializeMenu(); setDirty(true); } }
/* (non-Javadoc) * @see org.eclipse.jface.action.IContributionItem#update(java.lang.String) */ public void update(String property) { IContributionItem items[] = getItems(); for (int i = 0; i < items.length; i++) { items[i].update(property); } if (menu != null && !menu.isDisposed() && menu.getParentItem() != null) { if (IAction.TEXT.equals(property)) { String text = getOverrides().getText(this); if (text == null) { text = getMenuText(); } if (text != null) { ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); if (callback != null) { int index = text.indexOf('&'); if (index >= 0 && index < text.length() - 1) { char character = Character.toUpperCase(text.charAt(index + 1)); if (callback.isAcceleratorInUse(SWT.ALT | character) && isTopLevelMenu()) { if (index == 0) { text = text.substring(1); } else { text = text.substring(0, index) + text.substring(index + 1); } } } } menu.getParentItem().setText(text); } } else if (IAction.IMAGE.equals(property) && image != null) { LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources()); menu.getParentItem().setImage(localManager.createImage(image)); disposeOldImages(); imageManager = localManager; } } }
/** * Disposes of this menu manager and frees all allocated SWT resources. Notifies all contribution * items of the dispose. Note that this method does not clean up references between this menu * manager and its associated contribution items. Use <code>removeAll</code> for that purpose. */ public void dispose() { if (menuExist()) { menu.dispose(); } menu = null; if (menuItem != null) { menuItem.dispose(); menuItem = null; } disposeOldImages(); IContributionItem[] items = getItems(); for (int i = 0; i < items.length; i++) { items[i].dispose(); } markDirty(); }