Search in sources :

Example 96 with IAction

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());
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IN4JSEclipseCore(org.eclipse.n4js.ui.projectModel.IN4JSEclipseCore) Inject(com.google.inject.Inject) IAction(org.eclipse.jface.action.IAction) IWorkbenchCommandConstants(org.eclipse.ui.IWorkbenchCommandConstants) CoreException(org.eclipse.core.runtime.CoreException) WorkingSetManagerBrokerImpl(org.eclipse.n4js.ui.workingsets.WorkingSetManagerBrokerImpl) HashMultimap(com.google.common.collect.HashMultimap) Arrays.asList(java.util.Arrays.asList) IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) FluentIterable.from(com.google.common.collect.FluentIterable.from) Map(java.util.Map) ProjectTypeAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager) CommonViewer(org.eclipse.ui.navigator.CommonViewer) PlatformUI(org.eclipse.ui.PlatformUI) Collection(java.util.Collection) MenuManager(org.eclipse.jface.action.MenuManager) Collectors(java.util.stream.Collectors) List(java.util.List) LegacyActionTools(org.eclipse.jface.action.LegacyActionTools) Entry(java.util.Map.Entry) Optional(java.util.Optional) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Iterables(com.google.common.collect.Iterables) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) URI(org.eclipse.emf.common.util.URI) BeforeClass(org.junit.BeforeClass) ProjectExplorer(org.eclipse.ui.navigator.resources.ProjectExplorer) HashMap(java.util.HashMap) Arrays2(org.eclipse.n4js.utils.collections.Arrays2) Multimap(com.google.common.collect.Multimap) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectWorkingSetDropDownAction(org.eclipse.n4js.ui.navigator.internal.SelectWorkingSetDropDownAction) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) ShowHiddenWorkingSetsDropDownAction(org.eclipse.n4js.ui.navigator.internal.ShowHiddenWorkingSetsDropDownAction) Before(org.junit.Before) CommandManager(org.eclipse.core.commands.CommandManager) TEST(org.eclipse.n4js.n4mf.ProjectType.TEST) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager) UIUtils(org.eclipse.n4js.ui.utils.UIUtils) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) LIBRARY(org.eclipse.n4js.n4mf.ProjectType.LIBRARY) Test(org.junit.Test) ExecutionException(org.eclipse.core.commands.ExecutionException) IActionBars(org.eclipse.ui.IActionBars) TreeItem(org.eclipse.swt.widgets.TreeItem) ProjectType(org.eclipse.n4js.n4mf.ProjectType) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) Command(org.eclipse.core.commands.Command) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IMenuManager(org.eclipse.jface.action.IMenuManager) IResource(org.eclipse.core.resources.IResource) IContributionItem(org.eclipse.jface.action.IContributionItem) IWorkbench(org.eclipse.ui.IWorkbench) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IAction(org.eclipse.jface.action.IAction) HashMap(java.util.HashMap) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 97 with IAction

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;
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) IAction(org.eclipse.jface.action.IAction) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction)

Example 98 with IAction

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;
}
Also used : IAction(org.eclipse.jface.action.IAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 99 with IAction

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;
}
Also used : IAction(org.eclipse.jface.action.IAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 100 with IAction

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;
}
Also used : IAction(org.eclipse.jface.action.IAction) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) Action(org.eclipse.jface.action.Action) HashSet(java.util.HashSet) Set(java.util.Set) IAction(org.eclipse.jface.action.IAction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) Repository(org.eclipse.jgit.lib.Repository) RepositoryCache(org.eclipse.egit.core.RepositoryCache) File(java.io.File)

Aggregations

IAction (org.eclipse.jface.action.IAction)387 Action (org.eclipse.jface.action.Action)147 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)79 IWorkbenchAction (org.eclipse.ui.actions.ActionFactory.IWorkbenchAction)57 Separator (org.eclipse.jface.action.Separator)55 WebLaunchAction (com.centurylink.mdw.plugin.actions.WebLaunchActions.WebLaunchAction)50 MenuManager (org.eclipse.jface.action.MenuManager)39 IMenuManager (org.eclipse.jface.action.IMenuManager)37 ArrayList (java.util.ArrayList)36 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)35 IContributionItem (org.eclipse.jface.action.IContributionItem)31 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)26 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)22 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)18 ActionRegistry (org.eclipse.gef.ui.actions.ActionRegistry)16 IToolBarManager (org.eclipse.jface.action.IToolBarManager)16 IEditorPart (org.eclipse.ui.IEditorPart)15 Point (org.eclipse.swt.graphics.Point)14 Iterator (java.util.Iterator)13 Menu (org.eclipse.swt.widgets.Menu)13