/** * Returns the text shown in the menu, potentially with a shortcut appended. * * @return the menu text */ public String getMenuText() { if (definitionId == null) { return menuText; } final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); if (callback != null) { final String shortCut = callback.getAcceleratorText(definitionId); if (shortCut == null) { return menuText; } return menuText + "\t" + shortCut; //$NON-NLS-1$ } return menuText; }
/** * The <code>ActionContributionItemEx</code> implementation of this * <code>IContributionItem</code> method creates an SWT <code>Button</code> * for the action using the action's style. If the action's checked property * has been set, the button is created and primed to the value of the checked * property. */ @Override public void fill(Composite parent) { if ((widget == null) && (parent != null)) { int flags = SWT.PUSH; if (action != null) { if (action.getStyle() == IAction.AS_CHECK_BOX) { flags = SWT.TOGGLE; } if (action.getStyle() == IAction.AS_RADIO_BUTTON) { flags = SWT.RADIO; } } final Button b = new Button(parent, flags); b.setData(this); b.addListener(SWT.Dispose, getButtonListener()); // Don't hook a dispose listener on the parent b.addListener(SWT.Selection, getButtonListener()); if (action.getHelpListener() != null) { b.addHelpListener(action.getHelpListener()); } widget = b; update(null); // Attach some extra listeners. action.addPropertyChangeListener(propertyListener); if (action != null) { final String commandId = action.getActionDefinitionId(); final ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if ((callback != null) && (commandId != null)) { callback.addPropertyChangeListener(commandId, actionTextListener); } } } }
/** * Handles a widget dispose event for the widget corresponding to this item. */ private void handleWidgetDispose(Event e) { // Check if our widget is the one being disposed. if (e.widget == widget) { // Dispose of the menu creator. if ((action.getStyle() == IAction.AS_DROP_DOWN_MENU) && menuCreatorCalled) { final IMenuCreator mc = action.getMenuCreator(); if (mc != null) { mc.dispose(); } } // Unhook all of the listeners. action.removePropertyChangeListener(propertyListener); if (action != null) { final String commandId = action.getActionDefinitionId(); final ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if ((callback != null) && (commandId != null)) { callback.removePropertyChangeListener(commandId, actionTextListener); } } // Clear the widget field. widget = null; disposeOldImages(); } }
/** * Returns whether the command corresponding to this action is active. */ private boolean isCommandActive() { final IAction actionToCheck = getAction(); if (actionToCheck != null) { final String commandId = actionToCheck.getActionDefinitionId(); final ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if (callback != null) { return callback.isActive(commandId); } } return true; }
/** * Returns the text shown in the menu, potentially with a shortcut * appended. * * @return the menu text */ public String getMenuText() { if (definitionId == null) { return menuText; } ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); if (callback != null) { String shortCut = callback.getAcceleratorText(definitionId); if (shortCut == null) { return menuText; } return menuText + "\t" + shortCut; //$NON-NLS-1$ } return menuText; }
/** * The <code>ActionContributionItem</code> implementation of this * <code>IContributionItem</code> method creates an SWT * <code>Button</code> for the action using the action's style. If the * action's checked property has been set, the button is created and primed * to the value of the checked property. */ @Override public void fill(Composite parent) { if (widget == null && parent != null) { int flags = SWT.PUSH; if (action != null) { if (action.getStyle() == IAction.AS_CHECK_BOX) { flags = SWT.TOGGLE; } if (action.getStyle() == IAction.AS_RADIO_BUTTON) { flags = SWT.RADIO; } } Button b = new Button(parent, flags); b.setData(this); b.addListener(SWT.Dispose, getButtonListener()); // Don't hook a dispose listener on the parent b.addListener(SWT.Selection, getButtonListener()); if (action.getHelpListener() != null) { b.addHelpListener(action.getHelpListener()); } widget = b; update(null); // Attach some extra listeners. action.addPropertyChangeListener(propertyListener); if (action != null) { String commandId = action.getActionDefinitionId(); ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if ((callback != null) && (commandId != null)) { callback.addPropertyChangeListener(commandId, actionTextListener); } } } }
/** * Handles a widget dispose event for the widget corresponding to this item. */ private void handleWidgetDispose(Event e) { // Check if our widget is the one being disposed. if (e.widget == widget) { // Dispose of the menu creator. if (action.getStyle() == IAction.AS_DROP_DOWN_MENU && menuCreatorCalled) { IMenuCreator mc = action.getMenuCreator(); if (mc != null) { mc.dispose(); } } // Unhook all of the listeners. action.removePropertyChangeListener(propertyListener); if (action != null) { String commandId = action.getActionDefinitionId(); ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if ((callback != null) && (commandId != null)) { callback.removePropertyChangeListener(commandId, actionTextListener); } } // Clear the widget field. widget = null; disposeOldImages(); } }
/** * Returns whether the command corresponding to this action is active. */ private boolean isCommandActive() { IAction actionToCheck = getAction(); if (actionToCheck != null) { String commandId = actionToCheck.getActionDefinitionId(); ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if (callback != null) { return callback.isActive(commandId); } } return true; }
@Override public void update(String property) { final IContributionItem items[] = getItems(); for (final IContributionItem item : items) { item.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) { final ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if (callback != null) { final int index = text.indexOf('&'); if ((index >= 0) && (index < (text.length() - 1))) { final 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)) { final LocalResourceManager localManager = new LocalResourceManager( JFaceResources.getResources()); menu.getParentItem().setImage(localManager.createImage(image)); disposeOldImages(); imageManager = localManager; } } }
/** * The <code>ActionContributionItemEx</code> implementation of this * <code>IContributionItem</code> method creates an SWT <code>MenuItem</code> * for the action using the action's style. If the action's checked property * has been set, a button is created and primed to the value of the checked * property. If the action's menu creator property has been set, a cascading * submenu is created. */ @Override public void fill(Menu parent, int index) { if ((widget == null) && (parent != null)) { int flags = SWT.PUSH; if (action != null) { final int style = action.getStyle(); if (style == IAction.AS_CHECK_BOX) { flags = SWT.CHECK; } else if (style == IAction.AS_RADIO_BUTTON) { flags = SWT.RADIO; } else if (style == IAction.AS_DROP_DOWN_MENU) { flags = SWT.CASCADE; } } MenuItem mi = null; if (index >= 0) { mi = new MenuItem(parent, flags, index); } else { mi = new MenuItem(parent, flags); } widget = mi; mi.setData(this); mi.addListener(SWT.Dispose, getMenuItemListener()); mi.addListener(SWT.Selection, getMenuItemListener()); if (action.getHelpListener() != null) { mi.addHelpListener(action.getHelpListener()); } if (flags == SWT.CASCADE) { // just create a proxy for now, if the user shows it then // fill it in final Menu subMenu = new Menu(parent); subMenu.addListener(SWT.Show, getMenuCreatorListener()); subMenu.addListener(SWT.Hide, getMenuCreatorListener()); mi.setMenu(subMenu); } update(null); // Attach some extra listeners. action.addPropertyChangeListener(propertyListener); if (action != null) { final String commandId = action.getActionDefinitionId(); final ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if ((callback != null) && (commandId != null)) { callback.addPropertyChangeListener(commandId, actionTextListener); } } } }
/** * The <code>ActionContributionItemEx</code> implementation of this , * <code>IContributionItem</code> method creates an SWT <code>ToolItem</code> * for the action using the action's style. If the action's checked property * has been set, a button is created and primed to the value of the checked * property. If the action's menu creator property has been set, a drop-down * tool item is created. */ @Override public void fill(ToolBar parent, int index) { if ((widget == null) && (parent != null)) { int flags = SWT.PUSH; if (action != null) { final int style = action.getStyle(); if (style == IAction.AS_CHECK_BOX) { flags = SWT.CHECK; } else if (style == IAction.AS_RADIO_BUTTON) { flags = SWT.RADIO; } else if (style == IAction.AS_DROP_DOWN_MENU) { flags = SWT.DROP_DOWN; } } ToolItem ti = null; if (index >= 0) { ti = new ToolItem(parent, flags, index); } else { ti = new ToolItem(parent, flags); } ti.setData(this); ti.addListener(SWT.Selection, getToolItemListener()); ti.addListener(SWT.Dispose, getToolItemListener()); widget = ti; update(null); // Attach some extra listeners. if (action != null) { action.addPropertyChangeListener(propertyListener); final String commandId = action.getActionDefinitionId(); final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); if ((callback != null) && (commandId != null)) { callback.addPropertyChangeListener(commandId, actionTextListener); } } } }
@Override 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)) { 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; } } }
/** * The <code>ActionContributionItem</code> implementation of this * <code>IContributionItem</code> method creates an SWT * <code>MenuItem</code> for the action using the action's style. If the * action's checked property has been set, a button is created and primed to * the value of the checked property. If the action's menu creator property * has been set, a cascading submenu is created. */ @Override public void fill(Menu parent, int index) { if (widget == null && parent != null) { int flags = SWT.PUSH; if (action != null) { int style = action.getStyle(); if (style == IAction.AS_CHECK_BOX) { flags = SWT.CHECK; } else if (style == IAction.AS_RADIO_BUTTON) { flags = SWT.RADIO; } else if (style == IAction.AS_DROP_DOWN_MENU) { flags = SWT.CASCADE; } } MenuItem mi = null; if (index >= 0) { mi = new MenuItem(parent, flags, index); } else { mi = new MenuItem(parent, flags); } widget = mi; mi.setData(this); mi.addListener(SWT.Dispose, getMenuItemListener()); mi.addListener(SWT.Selection, getMenuItemListener()); if (action.getHelpListener() != null) { mi.addHelpListener(action.getHelpListener()); } if (flags == SWT.CASCADE) { // just create a proxy for now, if the user shows it then // fill it in Menu subMenu = new Menu(parent); subMenu.addListener(SWT.Show, getMenuCreatorListener()); subMenu.addListener(SWT.Hide, getMenuCreatorListener()); mi.setMenu(subMenu); } update(null); // Attach some extra listeners. action.addPropertyChangeListener(propertyListener); if (action != null) { String commandId = action.getActionDefinitionId(); ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if ((callback != null) && (commandId != null)) { callback.addPropertyChangeListener(commandId, actionTextListener); } } } }
/** * The <code>ActionContributionItem</code> implementation of this , * <code>IContributionItem</code> method creates an SWT * <code>ToolItem</code> for the action using the action's style. If the * action's checked property has been set, a button is created and primed to * the value of the checked property. If the action's menu creator property * has been set, a drop-down tool item is created. */ @Override public void fill(ToolBar parent, int index) { if (widget == null && parent != null) { int flags = SWT.PUSH; if (action != null) { int style = action.getStyle(); if (style == IAction.AS_CHECK_BOX) { flags = SWT.CHECK; } else if (style == IAction.AS_RADIO_BUTTON) { flags = SWT.RADIO; } else if (style == IAction.AS_DROP_DOWN_MENU) { flags = SWT.DROP_DOWN; } } ToolItem ti = null; if (index >= 0) { ti = new ToolItem(parent, flags, index); } else { ti = new ToolItem(parent, flags); } ti.setData(this); ti.addListener(SWT.Selection, getToolItemListener()); ti.addListener(SWT.Dispose, getToolItemListener()); widget = ti; update(null); // Attach some extra listeners. action.addPropertyChangeListener(propertyListener); if (action != null) { String commandId = action.getActionDefinitionId(); ExternalActionManager.ICallback callback = ExternalActionManager .getInstance().getCallback(); if ((callback != null) && (commandId != null)) { callback.addPropertyChangeListener(commandId, actionTextListener); } } } }