Java 类org.eclipse.jface.action.IMenuCreator 实例源码

项目:swt-widgets    文件:DropDownAction.java   
@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());
  }
}
项目:eclipse-extras    文件:LaunchModeActionTest.java   
@Test
public void testGetMenuCreator() {
  LaunchModeAction action = createLaunchModeAction();

  IMenuCreator menuCreator = action.getMenuCreator();

  assertThat( menuCreator ).isNull();
}
项目:eclipse-extras    文件:LaunchModeDropDownActionTest.java   
@Test
public void testMenuCreator() {
  LaunchModeDropDownAction action = new LaunchModeDropDownAction( launchModeSetting );

  IMenuCreator menuCreator = action.getMenuCreator();

  assertThat( menuCreator ).isSameAs( action );
}
项目:PDFReporter-Studio    文件:ViewSettingsDropDownAction.java   
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);
    }
}
项目:gef-gwt    文件:PaletteCustomizerDialog.java   
/**
 * 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();
}
项目:gef-gwt    文件:ToolbarDropdownContributionItem.java   
/**
 * 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);
    }
}
项目:swt-widgets    文件:ActionContributionItemEx.java   
/**
 * 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();
  }
}
项目:swt-widgets    文件:ActionContributionItemEx.java   
/**
 * 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);
}
项目:cuina    文件:SaveActionContributionItem.java   
/**
 * 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();
    }
}
项目:cuina    文件:SaveActionContributionItem.java   
/**
 * 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);
}
项目:jsbuild-eclipse    文件:OpenAndExpand.java   
public IMenuCreator getMenuCreator() {
    return fOpenAction.getMenuCreator();
}
项目:jsbuild-eclipse    文件:OpenAndExpand.java   
public void setMenuCreator(IMenuCreator creator) {
    fOpenAction.setMenuCreator(creator);
}
项目:EasyShell    文件:Action.java   
@Override
public IMenuCreator getMenuCreator() {
    // TODO Auto-generated method stub
    return null;
}
项目:EasyShell    文件:Action.java   
@Override
public void setMenuCreator(IMenuCreator creator) {
    // TODO Auto-generated method stub

}
项目:OpenSPIFe    文件:TemplatePlanViewAddNewItemPulldownAction.java   
@Override
public IMenuCreator getMenuCreator() {
    return this;
}
项目:Eclipse-Postfix-Code-Completion    文件:ClasspathModifierDropDownAction.java   
@Override
public IMenuCreator getMenuCreator() {
       return this;
   }
项目:Eclipse-Postfix-Code-Completion    文件:OpenAndExpand.java   
@Override
public IMenuCreator getMenuCreator() {
    return fOpenAction.getMenuCreator();
}
项目:Eclipse-Postfix-Code-Completion    文件:OpenAndExpand.java   
@Override
public void setMenuCreator(IMenuCreator creator) {
    fOpenAction.setMenuCreator(creator);
}
项目:gef-gwt    文件:ToolbarDropdownContributionItem.java   
/**
 * 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);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ClasspathModifierDropDownAction.java   
@Override
public IMenuCreator getMenuCreator() {
       return this;
   }
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:OpenAndExpand.java   
@Override
public IMenuCreator getMenuCreator() {
    return fOpenAction.getMenuCreator();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:OpenAndExpand.java   
@Override
public void setMenuCreator(IMenuCreator creator) {
    fOpenAction.setMenuCreator(creator);
}
项目:birt    文件:TabbedPropertyTitle.java   
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 );
}
项目:e4macs    文件:KillRingListeners.java   
public IMenuCreator getMenuCreator() {
    return action.getMenuCreator();
}
项目:e4macs    文件:KillRingListeners.java   
public void setMenuCreator(IMenuCreator creator) {
    action.setMenuCreator(creator);
}
项目:elexis-3-base    文件:PhMRpActions.java   
@Override
public IMenuCreator getMenuCreator() {
    // TODO Auto-generated method stub
    return null;
}
项目:elexis-3-base    文件:PhMRpActions.java   
@Override
public void setMenuCreator(IMenuCreator creator) {
    // TODO Auto-generated method stub

}