use of org.eclipse.jface.action.ContributionItem in project translationstudio8 by heartsome.
the class WorkingSetRootModeActionGroup method addActions.
/**
* Adds the actions to the given menu manager.
*/
protected void addActions(IMenuManager viewMenu) {
if (actions == null)
actions = createActions();
viewMenu.add(new Separator());
items = new MenuItem[actions.length];
for (int i = 0; i < actions.length; i++) {
final int j = i;
viewMenu.add(new ContributionItem() {
public void fill(Menu menu, int index) {
int style = SWT.CHECK;
if ((actions[j].getStyle() & IAction.AS_RADIO_BUTTON) != 0)
style = SWT.RADIO;
final MenuItem mi = new MenuItem(menu, style, index);
items[j] = mi;
mi.setText(actions[j].getText());
mi.setSelection(currentSelection == j);
mi.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (currentSelection == j) {
items[currentSelection].setSelection(true);
return;
}
actions[j].run();
// Update checked state
items[currentSelection].setSelection(false);
currentSelection = j;
items[currentSelection].setSelection(true);
}
});
}
public boolean isDynamic() {
return false;
}
});
}
}
use of org.eclipse.jface.action.ContributionItem in project n4js by eclipse.
the class SelectTopLevelElementActionGroup method addActions.
private void addActions(final IMenuManager menuManager) {
menuManager.add(new Separator());
// Projects menu item
menuManager.add(new ContributionItem() {
@Override
public void fill(final Menu menu, final int index) {
projectsItem = new MenuItem(menu, SWT.CHECK);
projectsItem.setText("Projects");
projectsItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
projectsItem.setSelection(true);
workingSetsItem.setSelection(false);
workingSetManagerBroker.setWorkingSetTopLevel(false);
}
});
if (!workingSetManagerBroker.isWorkingSetTopLevel()) {
projectsItem.setSelection(true);
}
}
});
menuManager.add(new ContributionItem() {
@Override
public void fill(final Menu menu, final int index) {
workingSetsItem = new MenuItem(menu, SWT.CHECK);
workingSetsItem.setText("Working Sets");
workingSetsItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
workingSetsItem.setSelection(true);
projectsItem.setSelection(false);
workingSetManagerBroker.setWorkingSetTopLevel(true);
}
});
if (workingSetManagerBroker.isWorkingSetTopLevel()) {
workingSetsItem.setSelection(true);
}
}
});
}
use of org.eclipse.jface.action.ContributionItem in project dsl-devkit by dsldevkit.
the class DynamicViewMenu method getMenuItemsInternal.
/**
* Gets the menu items. This is expected to be called from within the UI thread. If not it will throw exceptions
* based on invalid thread access.
*
* @param items
* the menu items to search through
* @param menuPath
* the menu path without the menu item to find.
* @param recursive
* if set to <code>true</code>, will find sub-menus as well.
* @return The list of SWTBotMenu items which match the menu path.
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
private static List<SWTBotMenu> getMenuItemsInternal(final IContributionItem[] items, final List<String> menuPath, final boolean recursive) {
final List<SWTBotMenu> l = new ArrayList<SWTBotMenu>();
final boolean findAnything = (menuPath == null) || menuPath.isEmpty();
for (final IContributionItem item : items) {
try {
if ((item instanceof MenuManager) && recursive) {
// Sub menus
final MenuManager menuManager = (MenuManager) item;
if (findAnything || menuManager.getMenuText().equals(menuPath.get(0))) {
List<String> subList = null;
if (menuPath.size() > 1) {
subList = menuPath.subList(1, menuPath.size());
}
l.addAll(getMenuItemsInternal(menuManager.getItems(), subList, recursive));
}
} else if (item instanceof ContributionItem) {
final ContributionItem dynItem = (ContributionItem) item;
dynItem.fill(originalMenu, 0);
final MenuItem[] items2 = originalMenu.getItems();
for (final MenuItem item2 : items2) {
l.add(new SWTBotMenu(item2));
}
}
} catch (final WidgetNotFoundException widgetNotFoundException) {
// Do nothing
continue;
}
}
return l;
}
Aggregations