org.eclipse.jface.action.ActionContributionItem Java Examples

The following examples show how to use org.eclipse.jface.action.ActionContributionItem. 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: CodesSelectionComposite.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(){
	currentSelection.clear();
	IContributionItem[] items = manager.getItems();
	for (IContributionItem iContributionItem : items) {
		if (iContributionItem instanceof ActionContributionItem) {
			IAction action = ((ActionContributionItem) iContributionItem).getAction();
			if (action instanceof CodeSelectionAction) {
				CodeSelectionAction csAction = (CodeSelectionAction) action;
				csAction.setChecked(true);
				currentSelection.add(csAction);
			}
		}
	}
	fireSelectionChanged();
	manager.update(true);
	
	FindingsUiUtil.saveSelectedCodings(
		currentSelection.stream().map(a -> a.getiCoding()).collect(Collectors.toList()));
}
 
Example #2
Source File: ChartActionBarContributor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s
 * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void depopulateManager(IContributionManager manager,
		Collection<? extends IAction> actions) {
	if (actions != null) {
		IContributionItem[] items = manager.getItems();
		for (int i = 0; i < items.length; i++) {
			// Look into SubContributionItems
			//
			IContributionItem contributionItem = items[i];
			while (contributionItem instanceof SubContributionItem) {
				contributionItem = ((SubContributionItem) contributionItem)
						.getInnerItem();
			}

			// Delete the ActionContributionItems with matching action.
			//
			if (contributionItem instanceof ActionContributionItem) {
				IAction action = ((ActionContributionItem) contributionItem)
						.getAction();
				if (actions.contains(action)) {
					manager.remove(contributionItem);
				}
			}
		}
	}
}
 
Example #3
Source File: SelectAllProjectExplorer_PluginUITest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the menu contribution titles of the project navigator context menu.
 *
 * This only includes {@link ActionContributionItem}s and {@link MenuManager}s.
 */
private List<String> getContextMenuContributions() {
	MenuManager menu = new MenuManager();
	projectExplorer.getNavigatorActionService().fillContextMenu(menu);
	return Arrays.asList(menu.getItems()).stream()
			.map(i -> {
				if (i instanceof ActionContributionItem) {
					// use action name
					return ((ActionContributionItem) i).getAction().getText();
				} else if (i instanceof MenuManager) {
					// use sub-menu title
					return ((MenuManager) i).getMenuText();
				} else {
					// null for other types of contributions
					return null;
				}
			})
			.filter(t -> null != t)
			// remove mnemonics (e.g. Close &Project -> Close Project))
			.map(text -> LegacyActionTools.removeMnemonics(text))
			.collect(Collectors.toList());
}
 
Example #4
Source File: SelectAllProjectExplorer_PluginUITest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Asserts that the context menu for the current navigator selection does not contain any duplicates.
 *
 * That is, two menu items that represent an action of the same class.
 */
private void assertContextMenuNoActionDuplicates() {
	MenuManager menu = new MenuManager();
	projectExplorer.getNavigatorActionService().fillContextMenu(menu);
	List<ActionContributionItem> actionContributions = Arrays.asList(menu.getItems()).stream()
			.filter(i -> i instanceof ActionContributionItem)
			.map(i -> ((ActionContributionItem) i))
			.collect(Collectors.toList());

	Map<String, ActionContributionItem> contributionNameMap = new HashMap<>();

	for (ActionContributionItem item : actionContributions) {
		ActionContributionItem mapItem = contributionNameMap.putIfAbsent(item.getAction().getText(), item);
		if (mapItem != null) {
			IAction mapAction = mapItem.getAction();
			IAction otherAction = item.getAction();

			// Double check if action is of the same type
			if (mapAction.getClass().equals(otherAction.getClass())) {
				fail("Action '" + mapAction.getClass().getSimpleName()
						+ "' is contributed twice to the context menu: "
						+ mapAction.toString() + " " + otherAction.toString());
			}
		}
	}
}
 
Example #5
Source File: BaseFolderImplementation.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public BaseFolderImplementation ( final int index, final String label, final MenuManager mgr )
{
    this.summaryInformation = new SummaryInformation ( Collections.<String, DataValue> emptyMap () );
    this.index = index;
    this.label = label;
    this.mgr = mgr;

    this.dumpAction = new Action ( "Dump summaries for: " + this.label ) {
        @Override
        public void run ()
        {
            BaseFolderImplementation.this.summaryInformation.dump ( System.out );
        };
    };
    this.contribution = new ActionContributionItem ( this.dumpAction );
}
 
Example #6
Source File: EnhancedTextField.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public void setEditable(boolean unlocked){
	text.setEditable(unlocked);
	IContributionItem[] items = menuMgr.getItems();
	for (IContributionItem iContributionItem : items) {
		if(iContributionItem instanceof ActionContributionItem) {
			IAction action = ((ActionContributionItem) iContributionItem).getAction();
			if(action instanceof RestrictedAction) {
				((RestrictedAction) action).reflectRight();
			} else {
				action.setEnabled(unlocked);
			}
		}
	}
	if(unlocked) {
		text.setForeground(UiDesk.getColor(UiDesk.COL_BLACK));
	} else {
		text.setForeground(UiDesk.getColor(UiDesk.COL_DARKGREY));
	}
}
 
Example #7
Source File: GenconfActionBarContributor.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s
 * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated
 */
protected void depopulateManager(IContributionManager manager, Collection<? extends IAction> actions) {
    if (actions != null) {
        IContributionItem[] items = manager.getItems();
        for (int i = 0; i < items.length; i++) {
            // Look into SubContributionItems
            //
            IContributionItem contributionItem = items[i];
            while (contributionItem instanceof SubContributionItem) {
                contributionItem = ((SubContributionItem) contributionItem).getInnerItem();
            }

            // Delete the ActionContributionItems with matching action.
            //
            if (contributionItem instanceof ActionContributionItem) {
                IAction action = ((ActionContributionItem) contributionItem).getAction();
                if (actions.contains(action)) {
                    manager.remove(contributionItem);
                }
            }
        }
    }
}
 
Example #8
Source File: HdViewPart.java    From http4e with Apache License 2.0 6 votes vote down vote up
public void fireAuthEnable( boolean enabled){
   IToolBarManager toolbar = this.getViewSite().getActionBars().getToolBarManager();
   IContributionItem[] items = toolbar.getItems();

   for (IContributionItem it : items) {
      if (it instanceof ActionContributionItem) {
         ActionContributionItem aci = (ActionContributionItem) it;
         if (aci.getAction() instanceof AuthenticationAction) {
            AuthenticationAction aa = (AuthenticationAction) aci.getAction();
            String img = null;
            if (enabled) {
               img = CoreImages.AUTH_ENABLED;
            } else {
               img = CoreImages.AUTH;
            }
            aa.setImageDescriptor(ImageDescriptor.createFromImage(ResourceUtils.getImage(CoreConstants.PLUGIN_UI, img)));
         }
      }
   }
}
 
Example #9
Source File: HdViewPart.java    From http4e with Apache License 2.0 6 votes vote down vote up
public void fireProxyEnable( boolean enabled){
   IToolBarManager toolbar = this.getViewSite().getActionBars().getToolBarManager();
   IContributionItem[] items = toolbar.getItems();
   for (IContributionItem it : items) {
      if (it instanceof ActionContributionItem) {
         ActionContributionItem aci = (ActionContributionItem) it;
         if (aci.getAction() instanceof ProxyAction) {
            ProxyAction aa = (ProxyAction) aci.getAction();
            String img = null;
            if (enabled) {
               img = CoreImages.PROXY_ENABLED;
            } else {
               img = CoreImages.PROXY;
            }
            aa.setImageDescriptor(ImageDescriptor.createFromImage(ResourceUtils.getImage(CoreConstants.PLUGIN_UI, img)));
         }
      }
   }
}
 
Example #10
Source File: MarkOccurrenceActionContributor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void contributeActions(XtextEditor editor) {
	editor2marker.computeIfAbsent(editor, (e)->{
		Action action = getAction();
		editor.setAction(action.getId(), action);
		IToolBarManager toolBarManager = editor.getEditorSite().getActionBars().getToolBarManager();
		if(toolBarManager.find(action.getId())==null) {
			ActionContributionItem item = new ActionContributionItem(action);
			item.setVisible(false);
			toolBarManager.add(item);				
		}
		OccurrenceMarker occurrenceMarker = occurrenceMarkerProvider.get();
		occurrenceMarker.connect(editor, isPropertySet());
		return occurrenceMarker;
	});
}
 
Example #11
Source File: RootActionProvider.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void fillActionBars(IActionBars actionBars) {
	super.fillActionBars(actionBars);
	actionBars.setGlobalActionHandler(OpenAppAction.ACTION_ID, openAppAction);
	actionBars.setGlobalActionHandler(RestartRunModeAction.ACTION_ID, restartRunAction);
	actionBars.setGlobalActionHandler(RestartDebugModeAction.ACTION_ID, restartDebugAction);
	
	IContributionManager cm = actionBars.getToolBarManager();
	IContributionItem[] items = cm.getItems();
	List<IAction> existingActions = new ArrayList<IAction>();
	for (IContributionItem item : items) {
		if (item instanceof ActionContributionItem) {
			existingActions.add(((ActionContributionItem)item).getAction());
		}
	}
	if (!existingActions.contains(openAppAction)) {
		cm.appendToGroup(ICommonMenuConstants.GROUP_OPEN, openAppAction);
	}
	if (!existingActions.contains(restartRunAction)) {
		cm.appendToGroup(ICommonMenuConstants.GROUP_OPEN, restartRunAction);
	}
	if (!existingActions.contains(restartDebugAction)) {
		cm.appendToGroup(ICommonMenuConstants.GROUP_OPEN, restartDebugAction);
	}
}
 
Example #12
Source File: CodesSelectionComposite.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private void updateSelectedCodings(){
	currentSelection.clear();
	List<ICoding> selectedCodings = FindingsUiUtil.loadSelectedCodings();
	if (selectedCodings != null) {
		IContributionItem[] items = manager.getItems();
		for (ICoding iCoding : selectedCodings) {
			for (IContributionItem iContributionItem : items) {
				if (iContributionItem instanceof ActionContributionItem) {
					IAction action = ((ActionContributionItem) iContributionItem).getAction();
					if (action instanceof CodeSelectionAction) {
						CodeSelectionAction csAction = (CodeSelectionAction) action;
						if (csAction.getiCoding().getCode().equals(iCoding.getCode())) {
							csAction.setChecked(true);
							currentSelection.add(csAction);
						}
					}
				}
			}
		}
		fireSelectionChanged();
		manager.update(true);
	}
}
 
Example #13
Source File: OpenSourceCodeAction.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Builder
 *
 * @param actionText
 *            "open" message recommended to be "lookup" if the location can be
 *            erroneous and open if it's accurate.
 * @param sourceLookup
 *            the source code to lookup
 * @param shell
 *            the parent shell for source file dialog
 * @return an contribution item to open a callsite or null if invalid
 */
public static IContributionItem create(String actionText, ITmfSourceLookup sourceLookup, Shell shell) {
    List<ITmfCallsite> cs = sourceLookup.getCallsites();
    if (cs == null) {
        return null;
    }
    List<ITmfCallsite> callsites = cs.stream().filter(callstack -> callstack.getLineNo() != null).collect(Collectors.toList());
    if (callsites.isEmpty()) {
        /* Not enough information to provide a full callsite */
        return null;
    }
    if (callsites.size() == 1) {
        return new ActionContributionItem(new OpenSourceCodeAction(actionText, callsites.get(0), shell));
    }

    MenuManager mgr = new MenuManager(actionText);
    for (ITmfCallsite callsite : callsites) {
        mgr.add(new OpenSourceCodeAction(callsite.toString(), callsite, shell));
    }
    return mgr;
}
 
Example #14
Source File: AbstractWorkbenchTestCase.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
protected IAction getPyUnitViewAction(ViewPart view, Class<?> class1) {
    IAction action = null;
    IContributionItem[] items = view.getViewSite().getActionBars().getToolBarManager().getItems();
    for (IContributionItem iContributionItem : items) {
        if (iContributionItem instanceof ActionContributionItem) {
            ActionContributionItem item = (ActionContributionItem) iContributionItem;
            IAction lAction = item.getAction();
            if (class1.isInstance(lAction)) {
                action = lAction;
            }
        }
    }
    if (action == null) {
        fail("Could not find action of class: " + class1);
    }
    return action;
}
 
Example #15
Source File: GamaActionBarAdvisor.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns the Help menu.
 */
private MenuManager createHelpMenu() {
	final MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_help, IWorkbenchActionConstants.M_HELP);
	addSeparatorOrGroupMarker(menu, "group.intro"); //$NON-NLS-1$
	menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
	addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
	menu.add(helpContentsAction);
	addSeparatorOrGroupMarker(menu, "group.assist"); //$NON-NLS-1$
	menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
	menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
	addSeparatorOrGroupMarker(menu, "group.tutorials"); //$NON-NLS-1$
	addSeparatorOrGroupMarker(menu, "group.tools"); //$NON-NLS-1$
	addSeparatorOrGroupMarker(menu, "group.updates"); //$NON-NLS-1$
	menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
	addSeparatorOrGroupMarker(menu, IWorkbenchActionConstants.MB_ADDITIONS);
	// about should always be at the bottom
	menu.add(new Separator("group.about")); //$NON-NLS-1$

	final ActionContributionItem aboutItem = new ActionContributionItem(aboutAction);
	aboutItem.setVisible(!Util.isMac());
	menu.add(aboutItem);
	menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$
	menu.add(openPreferencesAction);
	return menu;
}
 
Example #16
Source File: CleanupHelper.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private static void changeIcon(final IMenuManager menu, final IContributionItem item,
		final ImageDescriptor image) {
	if (item instanceof ActionContributionItem) {
		((ActionContributionItem) item).getAction().setImageDescriptor(image);
	} else if (item instanceof CommandContributionItem) {
		final CommandContributionItemParameter data = ((CommandContributionItem) item).getData();
		data.commandId = ((CommandContributionItem) item).getCommand().getId();
		data.icon = image;
		final CommandContributionItem newItem = new CommandContributionItem(data);
		newItem.setId(item.getId());
		menu.insertAfter(item.getId(), newItem);
		menu.remove(item);
		item.dispose();
	} else if (item instanceof ActionSetContributionItem) {
		changeIcon(menu, ((ActionSetContributionItem) item).getInnerItem(), image);
	} else if (item instanceof MenuManager) {
		((MenuManager) item).setImageDescriptor(image);
	}
}
 
Example #17
Source File: EipActionBarContributor.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
   * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s
   * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection.
   * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
   * @generated
   */
protected void depopulateManager(IContributionManager manager, Collection<? extends IAction> actions) {
     if (actions != null) {
        IContributionItem[] items = manager.getItems();
        for (int i = 0; i < items.length; i++) {
           // Look into SubContributionItems
           //
           IContributionItem contributionItem = items[i];
           while (contributionItem instanceof SubContributionItem) {
              contributionItem = ((SubContributionItem)contributionItem).getInnerItem();
           }

           // Delete the ActionContributionItems with matching action.
           //
           if (contributionItem instanceof ActionContributionItem) {
              IAction action = ((ActionContributionItem)contributionItem).getAction();
              if (actions.contains(action)) {
                 manager.remove(contributionItem);
              }
           }
        }
     }
  }
 
Example #18
Source File: Zoom.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Set action check state of a view action for a given action ID.
 *
 * @param id The action ID
 * @param checked true to check the action, false to uncheck the action
 */
protected void setActionChecked(String id, boolean checked) {
    if (getView() != null) {
        IActionBars bar = getView().getViewSite().getActionBars();
        if (bar == null) {
            return;
        }
        IToolBarManager barManager = bar.getToolBarManager();
        if (barManager == null) {
            return;
        }
        IContributionItem nextPage = barManager.find(id);
        if (nextPage instanceof ActionContributionItem) {
            IAction action = ((ActionContributionItem) nextPage).getAction();
            if (action != null) {
                action.setChecked(checked);
            }
        }
    }
}
 
Example #19
Source File: ViewMenus.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private void fillContextMenu(IMenuManager manager, List<IContributionItem> contributionItems){
	manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
	for (IContributionItem contributionItem : contributionItems) {
		if (contributionItem == null) {
			manager.add(new Separator());
			continue;
		} else if (contributionItem instanceof ActionContributionItem) {
			ActionContributionItem ac = (ActionContributionItem) contributionItem;
			if (ac.getAction() instanceof RestrictedAction) {
				((RestrictedAction) ac.getAction()).reflectRight();
			}
		}
		contributionItem.update();
		manager.add(contributionItem);
	}
}
 
Example #20
Source File: CoreActionBarContributor.java    From ifml-editor with MIT License 6 votes vote down vote up
/**
 * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s
 * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void depopulateManager(IContributionManager manager, Collection<? extends IAction> actions) {
	if (actions != null) {
		IContributionItem[] items = manager.getItems();
		for (int i = 0; i < items.length; i++) {
			// Look into SubContributionItems
			//
			IContributionItem contributionItem = items[i];
			while (contributionItem instanceof SubContributionItem) {
				contributionItem = ((SubContributionItem)contributionItem).getInnerItem();
			}

			// Delete the ActionContributionItems with matching action.
			//
			if (contributionItem instanceof ActionContributionItem) {
				IAction action = ((ActionContributionItem)contributionItem).getAction();
				if (actions.contains(action)) {
					manager.remove(contributionItem);
				}
			}
		}
	}
}
 
Example #21
Source File: ExtensionsActionBarContributor.java    From ifml-editor with MIT License 6 votes vote down vote up
/**
 * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s
 * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void depopulateManager(IContributionManager manager, Collection<? extends IAction> actions) {
	if (actions != null) {
		IContributionItem[] items = manager.getItems();
		for (int i = 0; i < items.length; i++) {
			// Look into SubContributionItems
			//
			IContributionItem contributionItem = items[i];
			while (contributionItem instanceof SubContributionItem) {
				contributionItem = ((SubContributionItem)contributionItem).getInnerItem();
			}

			// Delete the ActionContributionItems with matching action.
			//
			if (contributionItem instanceof ActionContributionItem) {
				IAction action = ((ActionContributionItem)contributionItem).getAction();
				if (actions.contains(action)) {
					manager.remove(contributionItem);
				}
			}
		}
	}
}
 
Example #22
Source File: AbstractSliceSystem.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
public void setSliceActionsEnabled(boolean enabled) {
	
	if (sliceToolbar==null) return;
	final IContributionItem[] items = sliceToolbar.getItems();
	for (IContributionItem toolItem : items) {
		if (toolItem instanceof ActionContributionItem) {
			((ActionContributionItem)toolItem).getAction().setEnabled(enabled);
		}
	}
	sliceToolbar.update(true);
	
	if (plotTypeActions!=null) {
		if (sliceActionEnabledMap==null) sliceActionEnabledMap = new HashMap<Enum<?>, Boolean>();
		for (Enum<?> type : plotTypeActions.keySet()) sliceActionEnabledMap.put(type, false);
	}

}
 
Example #23
Source File: BeansActionBarContributor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s
 * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void depopulateManager(IContributionManager manager, Collection<? extends IAction> actions) {
	if (actions != null) {
		IContributionItem[] items = manager.getItems();
		for (int i = 0; i < items.length; i++) {
			// Look into SubContributionItems
			//
			IContributionItem contributionItem = items[i];
			while (contributionItem instanceof SubContributionItem) {
				contributionItem = ((SubContributionItem)contributionItem).getInnerItem();
			}

			// Delete the ActionContributionItems with matching action.
			//
			if (contributionItem instanceof ActionContributionItem) {
				IAction action = ((ActionContributionItem)contributionItem).getAction();
				if (actions.contains(action)) {
					manager.remove(contributionItem);
				}
			}
		}
	}
}
 
Example #24
Source File: GraphicalView.java    From eclipsegraphviz with Eclipse Public License 1.0 5 votes vote down vote up
private void updateAutoSyncToggleButtonState() {
    IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
    ActionContributionItem autoSyncToggleContribution = (ActionContributionItem) toolBarManager
            .find("com.abstratt.imageviewer.autoUpdate");
    if (autoSyncToggleContribution != null) {
        IAction action = autoSyncToggleContribution.getAction();
        action.setChecked(isAutoSync());
    }
}
 
Example #25
Source File: SDView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Enables or disables the Pages... menu item, depending on the number of pages
 *
 * @param bar the bar containing the action
 */
protected void updatePagesMenuItem(IActionBars bar) {
    if (fSdPagingProvider instanceof ISDAdvancedPagingProvider) {
        IMenuManager menuManager = bar.getMenuManager();
        ActionContributionItem contributionItem = (ActionContributionItem) menuManager.find(OpenSDPagesDialog.ID);
        IAction openSDPagesDialog = null;
        if (contributionItem != null) {
            openSDPagesDialog = contributionItem.getAction();
        }

        if (openSDPagesDialog instanceof OpenSDPagesDialog) {
            openSDPagesDialog.setEnabled(((ISDAdvancedPagingProvider) fSdPagingProvider).pagesCount() > 1);
        }
    }
}
 
Example #26
Source File: SDView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Enables/Disables an action with given name.
 *
 * @param actionName The action name
 * @param state true or false
 */
public void setEnableAction(String actionName, boolean state) {
    IActionBars bar = getViewSite().getActionBars();
    if (bar != null) {
        IContributionItem item = bar.getMenuManager().find(actionName);
        if ((item != null) && (item instanceof ActionContributionItem)) {
            IAction action = ((ActionContributionItem) item).getAction();
            if (action != null) {
                action.setEnabled(state);
            }
            item.setVisible(state);
            bar.updateActionBars();
        }
    }
}
 
Example #27
Source File: ShowWhitespaceCharactersActionContributor.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void editorDisposed(XtextEditor editor) {
	IToolBarManager toolBarManager = editor.getEditorSite().getActionBars().getToolBarManager();
	IContributionItem i = toolBarManager.remove(ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS);
	if (i instanceof ActionContributionItem) {
		IAction action = ((ActionContributionItem) i).getAction();
		if (action instanceof ShowWhitespaceCharactersAction) {
			((ShowWhitespaceCharactersAction)action).setEditor(null);
		}
	}
}
 
Example #28
Source File: ActionTreeTester.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tests a tree that is a single node (a button).
 */
@Test
public void checkSingleNode() {
	// Create a JFace Action.
	final Action root = new Action("Root") {
	};

	// Create the ActionTree.
	ActionTree rootTree = new ActionTree(root);

	// Get the ActionContributionItem from the root node and check it.
	ActionContributionItem aci = (ActionContributionItem) rootTree
			.getContributionItem();
	assertNotNull(aci);
	assertSame(root, aci.getAction());
	assertEquals("Root", aci.getAction().getText());
	assertTrue(aci.getAction().isEnabled());

	// The returned ArrayList of child nodes should be null.
	List<ActionTree> children = rootTree.getChildren();
	assertNull(children);

	/* ---- Check enabling/disabling the tree. ---- */
	// Enabling shouldn't change anything.
	rootTree.setEnabled(true);
	assertTrue(aci.getAction().isEnabled());

	// Disabling it should work.
	rootTree.setEnabled(false);
	assertFalse(aci.getAction().isEnabled());

	// Enabling it should work.
	rootTree.setEnabled(true);
	assertTrue(aci.getAction().isEnabled());

	/* -------------------------------------------- */

	return;
}
 
Example #29
Source File: DetailViewActionBarContributor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s
 * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void depopulateManager ( IContributionManager manager, Collection<? extends IAction> actions )
{
    if ( actions != null )
    {
        IContributionItem[] items = manager.getItems ();
        for ( int i = 0; i < items.length; i++ )
        {
            // Look into SubContributionItems
            //
            IContributionItem contributionItem = items[i];
            while ( contributionItem instanceof SubContributionItem )
            {
                contributionItem = ( (SubContributionItem)contributionItem ).getInnerItem ();
            }

            // Delete the ActionContributionItems with matching action.
            //
            if ( contributionItem instanceof ActionContributionItem )
            {
                IAction action = ( (ActionContributionItem)contributionItem ).getAction ();
                if ( actions.contains ( action ) )
                {
                    manager.remove ( contributionItem );
                }
            }
        }
    }
}
 
Example #30
Source File: ProtocolActionBarContributor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s
 * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void depopulateManager ( IContributionManager manager, Collection<? extends IAction> actions )
{
    if ( actions != null )
    {
        IContributionItem[] items = manager.getItems ();
        for ( int i = 0; i < items.length; i++ )
        {
            // Look into SubContributionItems
            //
            IContributionItem contributionItem = items[i];
            while ( contributionItem instanceof SubContributionItem )
            {
                contributionItem = ( (SubContributionItem)contributionItem ).getInnerItem ();
            }

            // Delete the ActionContributionItems with matching action.
            //
            if ( contributionItem instanceof ActionContributionItem )
            {
                IAction action = ( (ActionContributionItem)contributionItem ).getAction ();
                if ( actions.contains ( action ) )
                {
                    manager.remove ( contributionItem );
                }
            }
        }
    }
}