@Override public void runWithEvent(Event event) { final IMenuCreator mc = getMenuCreator(); if (mc == null) { logger.error("No menu creator for action: {}", getId()); return; } if (event.widget instanceof ToolItem) { final ToolItem ti = (ToolItem) event.widget; final Menu menu = mc.getMenu(ti.getParent()); // calculate the position where to display the drop-down menu Point point = new Point(event.x, event.y); final Rectangle rect = ti.getBounds(); point.x += rect.x; point.y += rect.y + rect.height; point = ti.getParent().toDisplay(point); // position the menu below the drop down item menu.setLocation(point.x, point.y); menu.setVisible(true); } else { logger.error("Cannot create pop-menu for action: {}", getId()); } }
@Test public void testGetMenuCreator() { LaunchModeAction action = createLaunchModeAction(); IMenuCreator menuCreator = action.getMenuCreator(); assertThat( menuCreator ).isNull(); }
@Test public void testMenuCreator() { LaunchModeDropDownAction action = new LaunchModeDropDownAction( launchModeSetting ); IMenuCreator menuCreator = action.getMenuCreator(); assertThat( menuCreator ).isSameAs( action ); }
private void addActionToMenu(Menu parent, IAction action) { //If the action is a menu creator the create it as submenu if (action instanceof IMenuCreator){ IMenuCreator creator = (IMenuCreator) action; creator.getMenu(parent); } else { ActionContributionItem item = new ActionContributionItem(action); item.fill(parent, -1); } }
/** * Uses a <code>MenuManager</code> to create the context menu for the * outline. The <code>IActions</code> used to create the context menu are * those created in {@link #createOutlineActions()}. * * @return The newly created Menu */ protected Menu createOutlineContextMenu() { // MenuManager for the tree's context menu final MenuManager outlineMenu = new MenuManager(); List actions = getOutlineActions(); // Add all the actions to the context menu for (Iterator iter = actions.iterator(); iter.hasNext();) { IAction action = (IAction) iter.next(); if (action instanceof IMenuCreator) outlineMenu.add(new ActionContributionItem(action) { public boolean isDynamic() { return true; } }); else outlineMenu.add(action); // Add separators after new and delete if (action instanceof NewAction || action instanceof DeleteAction) { outlineMenu.add(new Separator()); } } outlineMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { outlineMenu.update(true); } }); outlineMenu.createContextMenu(tree); return outlineMenu.getMenu(); }
/** * The <code>ToolbarDropdownContributionItem</code> implementation of this * <code>IContributionItem</code> method creates a SWT MenuItem for the * action. If the action's checked property has been set, a toggle 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. */ public void fill(Menu parent, int index) { if (widget == null && parent != null) { int flags = SWT.PUSH; Menu subMenu = null; if (action != null) { int style = action.getStyle(); if (style == IAction.AS_CHECK_BOX) flags = SWT.CHECK; else if (style == IAction.AS_DROP_DOWN_MENU) { IMenuCreator mc = action.getMenuCreator(); subMenu = mc.getMenu(parent); 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.Arm, listener); mi.addListener(SWT.Dispose, listener); mi.addListener(SWT.Selection, listener); if (action.getHelpListener() != null) mi.addHelpListener(action.getHelpListener()); if (subMenu != null) mi.setMenu(subMenu); update(null); action.addPropertyChangeListener(listener); } }
/** * 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(); } }
/** * The proxy menu is being shown, we better get the real menu. * * @param proxy * the proxy menu * @since 3.4 */ private void handleShowProxy(Menu proxy) { proxy.removeListener(SWT.Show, getMenuCreatorListener()); final IMenuCreator mc = action.getMenuCreator(); menuCreatorCalled = true; if (mc == null) { return; } holdMenu = mc.getMenu(proxy.getParentMenu()); if (holdMenu == null) { return; } copyMenu(holdMenu, proxy); }
/** * 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(); } }
/** * The proxy menu is being shown, we better get the real menu. * * @param proxy * the proxy menu * @since 3.4 */ private void handleShowProxy(Menu proxy) { proxy.removeListener(SWT.Show, getMenuCreatorListener()); IMenuCreator mc = action.getMenuCreator(); menuCreatorCalled = true; if (mc == null) { return; } holdMenu = mc.getMenu(proxy.getParentMenu()); if (holdMenu == null) { return; } copyMenu(holdMenu, proxy); }
public IMenuCreator getMenuCreator() { return fOpenAction.getMenuCreator(); }
public void setMenuCreator(IMenuCreator creator) { fOpenAction.setMenuCreator(creator); }
@Override public IMenuCreator getMenuCreator() { // TODO Auto-generated method stub return null; }
@Override public void setMenuCreator(IMenuCreator creator) { // TODO Auto-generated method stub }
@Override public IMenuCreator getMenuCreator() { return this; }
@Override public IMenuCreator getMenuCreator() { return fOpenAction.getMenuCreator(); }
@Override public void setMenuCreator(IMenuCreator creator) { fOpenAction.setMenuCreator(creator); }
/** * Handles a widget selection event. */ private void handleWidgetSelection(Event e) { Widget item = e.widget; if (item != null) { int style = item.getStyle(); if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) { if (action.getStyle() == IAction.AS_CHECK_BOX) { action.setChecked(!action.isChecked()); } } else if ((style & SWT.DROP_DOWN) != 0) { /* * Added by Pratik Shah Do this regardless of whether the down * arrow button on the side was clicked, or the main button * itself */ if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) { IMenuCreator mc = action.getMenuCreator(); ToolItem ti = (ToolItem) item; // we create the menu as a sub-menu of "dummy" so that we // can use // it in a cascading menu too. // If created on a SWT control we would get an SWT error... // Menu dummy= new Menu(ti.getParent()); // Menu m= mc.getMenu(dummy); // dummy.dispose(); Menu m = mc.getMenu(ti.getParent()); if (m != null) { // position the menu below the drop down item Rectangle b = ti.getBounds(); Point p = ti.getParent().toDisplay( new Point(b.x, b.y + b.height)); m.setLocation(p.x, p.y); // waiting for SWT 0.42 m.setVisible(true); return; // we don't fire the action } } } // Ensure action is enabled first. // See 1GAN3M6: ITPUI:WINNT - Any IAction in the workbench can be // executed // while disabled. if (action.isEnabled()) { action.runWithEvent(e); } } }
private void handleWidgetSelection( Event e, ToolItem item ) { boolean selection = item.getSelection( ); int style = item.getStyle( ); IAction action = (IAction) actionMap.get( item ); if ( ( style & ( SWT.TOGGLE | SWT.CHECK ) ) != 0 ) { if ( action.getStyle( ) == IAction.AS_CHECK_BOX ) { action.setChecked( selection ); } } else if ( ( style & SWT.RADIO ) != 0 ) { if ( action.getStyle( ) == IAction.AS_RADIO_BUTTON ) { action.setChecked( selection ); } } else if ( ( style & SWT.DROP_DOWN ) != 0 ) { if ( e.detail == 4 ) { // on drop-down button if ( action.getStyle( ) == IAction.AS_DROP_DOWN_MENU ) { IMenuCreator mc = action.getMenuCreator( ); ToolItem ti = (ToolItem) item; if ( mc != null ) { Menu m = mc.getMenu( ti.getParent( ) ); if ( m != null ) { Point point = ti.getParent( ) .toDisplay( new Point( e.x, e.y ) ); m.setLocation( point.x, point.y ); // waiting m.setVisible( true ); return; // we don't fire the action } } } } } action.runWithEvent( e ); }
public IMenuCreator getMenuCreator() { return action.getMenuCreator(); }
public void setMenuCreator(IMenuCreator creator) { action.setMenuCreator(creator); }