Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.ui.navigator.resources; singleton:=true
Bundle-Version: 3.8.500.qualifier
Bundle-Version: 3.8.600.qualifier
Bundle-Activator: org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorPlugin
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.ui.internal.navigator.resources.actions;

import java.util.Arrays;
import java.util.function.Predicate;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
Expand All @@ -22,13 +25,15 @@
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.NewExampleAction;
import org.eclipse.ui.actions.NewProjectAction;
import org.eclipse.ui.internal.dialogs.WorkbenchWizardElement;
import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorMessages;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonMenuConstants;
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
import org.eclipse.ui.navigator.WizardActionGroup;
import org.eclipse.ui.wizards.IWizardCategory;
import org.eclipse.ui.wizards.IWizardDescriptor;
import org.eclipse.ui.wizards.IWizardRegistry;

/**
Expand Down Expand Up @@ -57,6 +62,9 @@ public class NewActionProvider extends CommonActionProvider {

private static final String NEW_MENU_NAME = "common.new.menu";//$NON-NLS-1$

private static final Predicate<IWizardDescriptor> PROJECT_WIZARD_FILTER = wizardDescriptor -> Arrays
.stream(wizardDescriptor.getTags()).anyMatch(WorkbenchWizardElement.TAG_PROJECT::equals);

private ActionFactory.IWorkbenchAction showDlgAction;

private IAction newProjectAction;
Expand All @@ -67,6 +75,8 @@ public class NewActionProvider extends CommonActionProvider {

private boolean contribute = false;

private WizardActionGroup newProjectWizardActionGroup;

@Override
public void init(ICommonActionExtensionSite anExtensionSite) {

Expand All @@ -75,9 +85,12 @@ public void init(ICommonActionExtensionSite anExtensionSite) {
showDlgAction = ActionFactory.NEW.create(window);
newProjectAction = new NewProjectAction(window);
newExampleAction = new NewExampleAction(window);

newWizardActionGroup = new WizardActionGroup(window, PlatformUI.getWorkbench().getNewWizardRegistry(), WizardActionGroup.TYPE_NEW, anExtensionSite.getContentService());

newProjectWizardActionGroup = new WizardActionGroup(window,
PlatformUI.getWorkbench().getNewWizardRegistry(), WizardActionGroup.TYPE_NEW,
anExtensionSite.getContentService(), PROJECT_WIZARD_FILTER, false);
newWizardActionGroup = new WizardActionGroup(window, PlatformUI.getWorkbench().getNewWizardRegistry(),
WizardActionGroup.TYPE_NEW, anExtensionSite.getContentService(), PROJECT_WIZARD_FILTER.negate(),
true);
contribute = true;
}
}
Expand All @@ -88,9 +101,11 @@ public void init(ICommonActionExtensionSite anExtensionSite) {
*
* <ul>
* <li>a new generic project wizard shortcut action, </li>
* <li>a set of context senstive wizard shortcuts (as defined by
* <b>org.eclipse.ui.navigator.commonWizard</b>) that are marked as project wizards, </li>
* <li>a separator, </li>
* <li>a set of context senstive wizard shortcuts (as defined by
* <b>org.eclipse.ui.navigator.commonWizard</b>), </li>
* <b>org.eclipse.ui.navigator.commonWizard</b>) that are not marked as project wizards, </li>
* <li>another separator, </li>
* <li>a generic examples wizard shortcut action, and finally </li>
* <li>a generic "Other" new wizard shortcut action</li>
Expand All @@ -106,6 +121,9 @@ public void fillContextMenu(IMenuManager menu) {
}
// Add new project wizard shortcut
submenu.add(newProjectAction);
// and all commonWizard contributions that are project wizards
newProjectWizardActionGroup.setContext(getContext());
newProjectWizardActionGroup.fillContextMenu(submenu);
submenu.add(new Separator());

// fill the menu from the commonWizard contributions
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.ui.navigator/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.ui.navigator; singleton:=true
Bundle-Version: 3.10.400.qualifier
Bundle-Version: 3.11.0.qualifier
Bundle-Activator: org.eclipse.ui.internal.navigator.NavigatorPlugin
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.Predicate;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.action.IAction;
Expand Down Expand Up @@ -107,16 +108,20 @@ public final class WizardActionGroup extends ActionGroup {
* the window is passed to created WizardShortcutActions for the shell and
* selection service.
*/
private IWorkbenchWindow window;
private final IWorkbenchWindow window;

/* the correct wizard registry for this action group (getRegistry()) */
private IWizardRegistry wizardRegistry;
private final IWizardRegistry wizardRegistry;

private boolean disposed = false;

private String type;
private final String type;

private INavigatorContentService contentService;
private final INavigatorContentService contentService;

private final Predicate<IWizardDescriptor> descriptorFilter;

private final boolean useSeparators;

/**
*
Expand All @@ -137,17 +142,7 @@ public final class WizardActionGroup extends ActionGroup {
*/
public WizardActionGroup(IWorkbenchWindow aWindow,
IWizardRegistry aWizardRegistry, String aType) {
super();
Assert.isNotNull(aWindow);
Assert.isNotNull(aWizardRegistry);
Assert
.isTrue(aType != null
&& (TYPE_NEW.equals(aType) || TYPE_IMPORT.equals(aType) || TYPE_EXPORT
.equals(aType)));
window = aWindow;
wizardRegistry = aWizardRegistry;
type = aType;

this(aWindow, aWizardRegistry, aType, null);
}


Expand All @@ -172,9 +167,42 @@ public WizardActionGroup(IWorkbenchWindow aWindow,
*/
public WizardActionGroup(IWorkbenchWindow aWindow,
IWizardRegistry aWizardRegistry, String aType, INavigatorContentService aContentService) {
this(aWindow, aWizardRegistry, aType);
contentService = aContentService;
this(aWindow, aWizardRegistry, aType, aContentService, null, true);
}

/**
*
* @param aWindow The window that will be used to acquire a Shell and a
* Selection Service
* @param aWizardRegistry The wizard registry will be used to locate the
* correct wizard descriptions.
* @param aType Indicates the value of the type attribute of the
* commonWizard extension point. Use any of the TYPE_XXX
* constants defined on this class.
* @param aContentService The content service to use when deciding visibility.
* @param descriptorFilter the filter to set, might be <code>null</code> if no
* filtering is desired.
* @param useSeparators <code>true</code> if seperators should be used,
* <code>false</code> otherwhise.
* @see PlatformUI#getWorkbench()
* @see IWorkbench#getNewWizardRegistry()
* @see IWorkbench#getImportWizardRegistry()
* @see IWorkbench#getExportWizardRegistry()
* @since 3.11
*/
public WizardActionGroup(IWorkbenchWindow aWindow, IWizardRegistry aWizardRegistry, String aType,
INavigatorContentService aContentService, Predicate<IWizardDescriptor> descriptorFilter,
boolean useSeparators) {
Assert.isNotNull(aWindow);
Assert.isNotNull(aWizardRegistry);
Assert.isNotNull(aType);
Assert.isTrue(TYPE_NEW.equals(aType) || TYPE_IMPORT.equals(aType) || TYPE_EXPORT.equals(aType));
this.window = aWindow;
this.wizardRegistry = aWizardRegistry;
this.type = aType;
this.contentService = aContentService;
this.descriptorFilter = descriptorFilter;
this.useSeparators = useSeparators;
}

@Override
Expand Down Expand Up @@ -204,15 +232,17 @@ public void fillContextMenu(IMenuManager menu) {
Assert.isTrue(!disposed);

if (descriptors != null) {
Map<String, SortedSet> groups = findGroups();
SortedSet sortedWizards = null;
Map<String, SortedSet<IAction>> groups = findGroups();
SortedSet<IAction> sortedWizards = null;
String menuGroupId = null;
for (Entry<String, SortedSet> entry : groups.entrySet()) {
for (Entry<String, SortedSet<IAction>> entry : groups.entrySet()) {
menuGroupId = entry.getKey();
sortedWizards = entry.getValue();
menu.add(new Separator(menuGroupId));
for (Iterator wizardItr = sortedWizards.iterator(); wizardItr.hasNext();) {
menu.add((IAction) wizardItr.next());
if (useSeparators) {
menu.add(new Separator(menuGroupId));
}
for (Iterator<IAction> wizardItr = sortedWizards.iterator(); wizardItr.hasNext();) {
menu.add(wizardItr.next());
}
}
}
Expand All @@ -221,9 +251,9 @@ public void fillContextMenu(IMenuManager menu) {
/**
* @return A Map of menuGroupIds to SortedSets of IActions.
*/
private synchronized Map/*<String, SortedSet<IAction>>*/<String, SortedSet> findGroups() {
private synchronized Map<String, SortedSet<IAction>> findGroups() {
IAction action = null;
Map<String, SortedSet> groups = new TreeMap<>();
Map<String, SortedSet<IAction>> groups = new TreeMap<>();
SortedSet<IAction> sortedWizards = null;
String menuGroupId = null;
for (CommonWizardDescriptor descriptor : descriptors) {
Expand All @@ -245,9 +275,7 @@ public void fillContextMenu(IMenuManager menu) {
public void dispose() {
super.dispose();
actions = null;
window = null;
descriptors = null;
wizardRegistry = null;
disposed = true;
}

Expand All @@ -263,7 +291,7 @@ protected IAction getAction(String id) {
// so that image caching in ActionContributionItem works.
IAction action = getActions().get(id);
if (action == null) {
IWizardDescriptor descriptor = wizardRegistry.findWizard(id);
IWizardDescriptor descriptor = getDescriptor(id);
if (descriptor != null) {
action = new WizardShortcutAction(window, descriptor);
getActions().put(id, action);
Expand All @@ -273,6 +301,17 @@ protected IAction getAction(String id) {
return action;
}


protected IWizardDescriptor getDescriptor(String id) {
IWizardDescriptor descriptor = wizardRegistry.findWizard(id);
if (descriptor != null && descriptorFilter != null) {
if (!descriptorFilter.test(descriptor)) {
return null;
}
}
return descriptor;
}

/**
* @return a map of (id, IAction)-pairs.
*/
Expand Down Expand Up @@ -306,12 +345,12 @@ private synchronized void setWizardActionDescriptors(CommonWizardDescriptor[] th
descriptors = theWizardDescriptors;
}

private static class ActionComparator implements Comparator {
private static class ActionComparator implements Comparator<IAction> {

private static final ActionComparator INSTANCE = new ActionComparator();
@Override
public int compare(Object arg0, Object arg1) {
return ((IAction)arg0).getText().compareTo(((IAction)arg1).getText());
public int compare(IAction arg0, IAction arg1) {
return arg0.getText().compareToIgnoreCase(arg1.getText());
}
}
}