Java Code Examples for org.eclipse.jface.action.IMenuManager#getItems()

The following examples show how to use org.eclipse.jface.action.IMenuManager#getItems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectAllProjectExplorer_PluginUITest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tests that the Top Level Elements
 */
@Test
public void testTopLevelElementsEntryNoDuplicates() {
	IActionBars actionBars = projectExplorer.getViewSite().getActionBars();
	IMenuManager menuManager = actionBars.getMenuManager();

	int topLevelElementsEntriesFound = 0;

	for (IContributionItem item : menuManager.getItems()) {
		if (item instanceof MenuManager) {
			String escapedMenuText = LegacyActionTools.removeMnemonics(((MenuManager) item).getMenuText());
			if (escapedMenuText.equals("Top Level Elements")) {
				topLevelElementsEntriesFound++;
			}
		}
	}

	assertEquals("There was more than one 'Top Level Elements' entry in the navigator action bar.",
			topLevelElementsEntriesFound, 1);
}
 
Example 2
Source File: PerformanceView.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void addDynamicVisualisationSelection(IMenuManager menuManager) {
	if (defaultMenuItems == null) {
		// first call: remember default menu items (as contributed by extensions in plugin.xml)
		defaultMenuItems = menuManager.getItems();
	} else {
		// later calls: clear menu & restore the default menu items
		menuManager.removeAll();
		Stream.of(defaultMenuItems).forEach(item -> menuManager.add(item));
	}

	Set<String> collectorsKeys = CollectedDataAccess.getCollectorsKeys();
	trashUnreachableVisualisations(collectorsKeys);

	// add actions to the menu
	menuManager.add(new Separator());
	collectorsKeys
			.forEach(collectorName -> menuManager.add(createDynamicAction(collectorName, this::selectDataSource)));
}
 
Example 3
Source File: CleanupHelper.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private static void processItems(final IMenuManager menu) {
	// final StringBuilder sb = new StringBuilder();
	// sb.append("Menu ").append(menu.getId()).append(" :: ");
	for (final IContributionItem item : menu.getItems()) {
		final String name = item.getId();
		// DEBUG.LOG(name);
		if (MENU_ITEMS_TO_REMOVE.contains(name)) {
			item.setVisible(false);
			continue;
		}
		if (item.isGroupMarker() || item.isSeparator() || !item.isVisible()) {
			continue;
		}
		if (MENU_IMAGES.containsKey(name)) {
			changeIcon(menu, item, GamaIcons.create(MENU_IMAGES.get(name)).descriptor());
		}
		// sb.append(Strings.LN).append(Strings.TAB);
		// sb.append(name).append('[').append(item.getClass().getSimpleName()).append("]:: ");
	}
	// DEBUG.LOG(sb.toString());
}
 
Example 4
Source File: N4JSEditor.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void editorContextMenuAboutToShow(final IMenuManager menu) {
	super.editorContextMenuAboutToShow(menu);

	final IContributionItem[] items = menu.getItems();
	for (int i = 0; i < items.length; i++) {
		if (items[i] instanceof IMenuManager) {
			final IMenuManager subMenu = (IMenuManager) items[i];
			final IContributionItem testShowIn = subMenu.find(ContributionItemFactory.VIEWS_SHOW_IN.getId());
			if (null != testShowIn) {
				menu.remove(subMenu);
			}
		}
	}
}
 
Example 5
Source File: OpenActionProvider.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private void addOpenWithMenu(final IMenuManager aMenu) {
	final IStructuredSelection ss = (IStructuredSelection) getContext().getSelection();
	if (ss == null || ss.size() != 1) { return; }
	final Object o = ss.getFirstElement();
	// first try IResource
	IAdaptable openable = CloseResourceAction.getAdapter(o, IResource.class);
	// otherwise try ResourceMapping
	if (openable == null) {
		openable = CloseResourceAction.getAdapter(o, ResourceMapping.class);
	} else if (((IResource) openable).getType() != IResource.FILE) {
		openable = null;
	}
	if (openable != null) {
		// Create a menu flyout.
		final IMenuManager submenu =
				new MenuManager(WorkbenchNavigatorMessages.OpenActionProvider_OpenWithMenu_label,
						ICommonMenuConstants.GROUP_OPEN_WITH);
		submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
		submenu.add(new OpenWithMenu(viewSite.getPage(), openable));
		submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));

		// Add the submenu.
		if (submenu.getItems().length > 2 && submenu.isEnabled()) {
			aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
		}
	}
}
 
Example 6
Source File: ApplicationWorkbenchWindowAdvisor.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
private void hideSearchMenu() {
	IMenuManager menuManager = this.actionBarConfigurer.getMenuManager();
	IContributionItem[] menuItems =  menuManager.getItems();
	for (IContributionItem item : menuItems) {
		if(item.getId().equalsIgnoreCase("org.eclipse.search.menu")) {
       		item.setVisible(false);
       		}
	}
}
 
Example 7
Source File: CategoryFilterActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void updateMenu(IMenuManager manager) {
	IContributionItem[] items= manager.getItems();
	if (items != null) {
		for (int i= 0; i < items.length; i++) {
			IContributionItem item= items[i];
			if (item != null && item.getId() != null && item.getId().equals(FILTER_CATEGORY_ACTION_ID)) {
				IContributionItem removed= manager.remove(item);
				if (removed != null) {
					item.dispose();
				}
			}
		}
	}
	List<String> menuEntries= new ArrayList<String>();
	boolean hasUncategorizedMembers= getMenuCategories(menuEntries);
	Collections.sort(menuEntries, Collator.getInstance());

	if (menuEntries.size() > 0 && hasUncategorizedMembers)
		manager.appendToGroup(CATEGORY_MENU_GROUP_NAME, new FilterUncategorizedMembersAction());

	int count= 0;
	for (Iterator<String> iter= menuEntries.iterator(); iter.hasNext();) {
		String category= iter.next();
		manager.appendToGroup(CATEGORY_MENU_GROUP_NAME, new CategoryFilterAction(category, count + 1));
		count++;
	}
}
 
Example 8
Source File: CustomPopupMenuExtender.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void gatherContributions(final IMenuManager mgr) {
    final IContributionItem[] items = mgr.getItems();
    for (IContributionItem item : items) {
        if (item instanceof PluginActionContributionItem) {
            actionContributionCache.add((PluginActionContributionItem) item);
        } else if (item instanceof IMenuManager) {
            gatherContributions(((IMenuManager) item));
        }
    }
}
 
Example 9
Source File: ApplicationActionBarAdvisor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void menuAboutToShow(IMenuManager manager){
	IContributionItem[] items = manager.getItems();
	for (IContributionItem iContributionItem : items) {
		if(iContributionItem instanceof ActionContributionItem) {
			ActionContributionItem aci = (ActionContributionItem) iContributionItem;		
			IAction action = aci.getAction();
			if(action instanceof RestrictedAction) {
				RestrictedAction ra = (RestrictedAction) aci.getAction();
				ra.reflectRight();
				continue;
			}
			String id = action.getActionDefinitionId();
			if(id==null) {
				continue;
			}
			switch (id) {
			case IWorkbenchCommandConstants.FILE_EXIT:
				action.setEnabled(CoreHub.acl.request(AccessControlDefaults.AC_EXIT));
				break;
			case IWorkbenchCommandConstants.WINDOW_NEW_WINDOW:
				action.setEnabled(CoreHub.acl.request(AccessControlDefaults.AC_NEWWINDOW));
				break;
			case IWorkbenchCommandConstants.HELP_ABOUT:
				action.setEnabled(CoreHub.acl.request(AccessControlDefaults.AC_ABOUT));
				break;
			case IWorkbenchCommandConstants.WINDOW_PREFERENCES:
				action.setEnabled(CoreHub.acl.request(AccessControlDefaults.AC_PREFS));
				break;
			default:
				break;
			}
		}
	}
}
 
Example 10
Source File: CodewindApplicationActionProvider.java    From codewind-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
	public void fillContextMenu(IMenuManager menu) {
		selProvider.setSelection(selProvider.getSelection());

		menu.add(openAppAction);
		menu.add(openAppOverviewAction);
		if (containerShellAction.showAction()) {
			menu.add(containerShellAction);
		}
		menu.add(new Separator());

		int numItems = menu.getItems().length;
		if (openAppMonitorAction.showAction()) {
			menu.add(openAppMonitorAction);
		}
		if (openPerfMonitorAction.showAction()) {
			menu.add(openPerfMonitorAction);
		}
		if (enableDisableInjectMetricsAction.showAction()) {
			menu.add(enableDisableInjectMetricsAction);
		}
		if (menu.getItems().length > numItems) {
			menu.add(new Separator());
		}

		menu.add(importProjectAction);
		addLogFileSubMenu(menu);
		menu.add(new Separator());

		numItems = menu.getItems().length;
		if (restartRunAction.showAction()) {
			menu.add(restartRunAction);
		}
		if (restartDebugAction.showAction()) {
			menu.add(restartDebugAction);
		}
		if (attachDebuggerAction.showAction()) {
			menu.add(attachDebuggerAction);
		}
		if (menu.getItems().length > numItems) {
			menu.add(new Separator());
		}
		
		menu.add(manageLinksAction);
		menu.add(new Separator());

		menu.add(startBuildAction);
//		if (validateAction.showAction()) {
//			menu.add(validateAction);
//		}
		menu.add(enableDisableAutoBuildAction);
		menu.add(new Separator());

		menu.add(enableDisableProjectAction);
		menu.add(unbindProjectAction);
	}
 
Example 11
Source File: ChartMenuBuilder.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void buildMenu( IMenuManager menu, List selectedList )
{
	if ( selectedList != null
			&& selectedList.size( ) == 1
			&& ChartItemUtil.isChartHandle( selectedList.get( 0 ) ) )
	{
		ExtendedItemHandle handle = (ExtendedItemHandle) selectedList.get( 0 );

		Separator separator = new Separator( "group.chart" ); //$NON-NLS-1$
		if ( menu.getItems( ).length > 0 )
		{
			menu.insertBefore( menu.getItems( )[0].getId( ), separator );
		}
		else
		{
			menu.add( separator );
		}
		menu.appendToGroup( separator.getId( ),
				new OpenChartTaskAction( handle,
						"org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType", //$NON-NLS-1$
						Messages.getString( "OpenChartTaskAction.Text.SelectChartType" ),//$NON-NLS-1$
						UIHelper.getImage( ChartUIConstants.IMAGE_TASK_TYPE ),
						true ) );
		menu.appendToGroup( separator.getId( ),
				new OpenChartTaskAction( handle,
						"org.eclipse.birt.chart.ui.swt.wizard.TaskSelectData", //$NON-NLS-1$
						Messages.getString( "OpenChartTaskAction.Text.SelectData" ), //$NON-NLS-1$
						UIHelper.getImage( ChartUIConstants.IMAGE_TASK_DATA ),
						false ) );
		menu.appendToGroup( separator.getId( ),
				new OpenChartTaskAction( handle,
						"org.eclipse.birt.chart.ui.swt.wizard.TaskFormatChart", //$NON-NLS-1$
						Messages.getString( "OpenChartTaskAction.Text.FormatChart" ),//$NON-NLS-1$
						UIHelper.getImage( ChartUIConstants.IMAGE_TASK_FORMAT ),
						false ) );

		if ( ChartCubeUtil.isPlotChart( handle )
				|| ChartCubeUtil.isAxisChart( handle ) )
		{
			menu.appendToGroup( separator.getId( ),
					new FlipAxisAction( handle ) );
			menu.appendToGroup( separator.getId( ),
					new ShowAxisAction( handle ) );
		}
	}

}
 
Example 12
Source File: RotatedTextMenuBuilder.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void buildMenu( IMenuManager menu, List selectedList )
{
	if ( selectedList != null
			&& selectedList.size( ) == 1
			&& selectedList.get( 0 ) instanceof ExtendedItemHandle )
	{
		ExtendedItemHandle handle = (ExtendedItemHandle) selectedList.get( 0 );

		if ( !RotatedTextItem.EXTENSION_NAME.equals( handle.getExtensionName( ) ) )
		{
			return;
		}

		RotatedTextItem item = null;
		try
		{
			item = (RotatedTextItem) handle.getReportItem( );
		}
		catch ( ExtendedElementException e )
		{
			e.printStackTrace( );
		}

		if ( item == null )
		{
			return;
		}

		Separator separator = new Separator( "group.rotatedtext" ); //$NON-NLS-1$
		if ( menu.getItems( ).length > 0 )
		{
			menu.insertBefore( menu.getItems( )[0].getId( ), separator );
		}
		else
		{
			menu.add( separator );
		}

		menu.appendToGroup( separator.getId( ),
				new RotateAction( item, -90 ) );
		menu.appendToGroup( separator.getId( ), new RotateAction( item, 90 ) );
		menu.appendToGroup( separator.getId( ), new RotateAction( item, 0 ) );
		menu.appendToGroup( separator.getId( ),
				new RotateAction( item, 180 ) );
	}
}