use of org.eclipse.jface.action.IAction in project n4js by eclipse.
the class SelectAllProjectExplorer_PluginUITest method assertContextMenuNoActionDuplicates.
/**
* 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());
}
}
}
}
use of org.eclipse.jface.action.IAction in project egit by eclipse.
the class ActionUtils method createGlobalAction.
/**
* Create an {@link IAction} taking the text, id, and action definition id
* from the given {@link ActionFactory}.
*
* @param factory
* from which the new {@link IAction} shall be derived
* @param action
* to execute
* @return the new {@link IAction}
*/
public static IAction createGlobalAction(ActionFactory factory, final Runnable action) {
IWorkbenchAction template = factory.create(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
IAction result = new Action(template.getText()) {
@Override
public void run() {
action.run();
}
};
result.setActionDefinitionId(factory.getCommandId());
result.setId(factory.getId());
template.dispose();
return result;
}
use of org.eclipse.jface.action.IAction in project egit by eclipse.
the class StagingView method createSelectionPathCopyAction.
private IAction createSelectionPathCopyAction(final TreeViewer viewer) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
String copyPathActionText = (selection.size() <= 1) ? UIText.StagingView_CopyPath : UIText.StagingView_CopyPaths;
IAction copyAction = ActionUtils.createGlobalAction(ActionFactory.COPY, () -> copyPathOfSelectionToClipboard(viewer));
copyAction.setText(copyPathActionText);
return copyAction;
}
use of org.eclipse.jface.action.IAction in project egit by eclipse.
the class StagingViewTooltips method createToolTipContentArea.
@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
ToolBar bar = new ToolBar(parent, SWT.FLAT | SWT.HORIZONTAL);
for (IAction action : actions) {
ToolItem item = new ToolItem(bar, SWT.PUSH);
item.setImage(UIIcons.getImage(Activator.getDefault().getResourceManager(), action.getImageDescriptor()));
String tooltip = action.getToolTipText();
if (tooltip == null || tooltip.isEmpty()) {
tooltip = action.getText();
}
item.setToolTipText(tooltip);
item.setEnabled(true);
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
hide();
if (action.isEnabled()) {
// Double-check...
action.run();
}
}
});
}
return bar;
}
use of org.eclipse.jface.action.IAction in project egit by eclipse.
the class RepositoryMenuUtil method getRepositoryActions.
/**
* Creates for each configured repository an {@link IAction} that will
* perform the given {@code action} when invoked.
*
* @param includeBare
* {@code true} if bare repositories should be included in the
* list, {@code false} otherwise
* @param currentRepoDir
* git directory of a repository that is to be marked as
* "current"; may be {@code null}.
* @param action
* to perform on the chosen repository
* @return the (possibly empty) list of actions
*/
public static Collection<IAction> getRepositoryActions(boolean includeBare, @Nullable File currentRepoDir, @NonNull Consumer<Repository> action) {
RepositoryUtil util = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil();
RepositoryCache cache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
Set<String> repositories = util.getRepositories();
Map<String, Set<File>> repos = new HashMap<>();
for (String repo : repositories) {
File gitDir = new File(repo);
String name = null;
try {
Repository r = cache.lookupRepository(gitDir);
if (!includeBare && r.isBare()) {
continue;
}
name = util.getRepositoryName(r);
} catch (IOException e) {
continue;
}
Set<File> files = repos.get(name);
if (files == null) {
files = new HashSet<>();
files.add(gitDir);
repos.put(name, files);
} else {
files.add(gitDir);
}
}
String[] repoNames = repos.keySet().toArray(new String[repos.size()]);
Arrays.sort(repoNames, CommonUtils.STRING_ASCENDING_COMPARATOR);
List<IAction> result = new ArrayList<>();
for (String repoName : repoNames) {
Set<File> files = repos.get(repoName);
File[] gitDirs = files.toArray(new File[files.size()]);
Arrays.sort(gitDirs);
for (File f : gitDirs) {
IAction menuItem = new Action(repoName, IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
try {
Repository r = cache.lookupRepository(f);
action.accept(r);
} catch (IOException e) {
Activator.showError(e.getLocalizedMessage(), e);
}
}
};
menuItem.setToolTipText(f.getPath());
if (f.equals(currentRepoDir)) {
menuItem.setChecked(true);
}
result.add(menuItem);
}
}
return result;
}
Aggregations