Skip to content

Commit 65893a8

Browse files
committed
Project wizards should be shown in "new project" category
Currently wizard that are marked with project=true are shown with other generic ones instead of in the "new project" section of the navigator. This adds them to the "new project" category so they are easier identified by a user that they create a new project. Fix #502
1 parent b7fe4bc commit 65893a8

File tree

4 files changed

+94
-37
lines changed

4 files changed

+94
-37
lines changed

bundles/org.eclipse.ui.navigator.resources/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Plugin.name
44
Bundle-SymbolicName: org.eclipse.ui.navigator.resources; singleton:=true
5-
Bundle-Version: 3.8.500.qualifier
5+
Bundle-Version: 3.8.600.qualifier
66
Bundle-Activator: org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorPlugin
77
Bundle-Vendor: %Plugin.providerName
88
Bundle-Localization: plugin

bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/NewActionProvider.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.internal.navigator.resources.actions;
1515

16+
import java.util.Arrays;
17+
import java.util.function.Predicate;
18+
1619
import org.eclipse.jface.action.IAction;
1720
import org.eclipse.jface.action.IMenuManager;
1821
import org.eclipse.jface.action.MenuManager;
@@ -22,13 +25,15 @@
2225
import org.eclipse.ui.actions.ActionFactory;
2326
import org.eclipse.ui.actions.NewExampleAction;
2427
import org.eclipse.ui.actions.NewProjectAction;
28+
import org.eclipse.ui.internal.dialogs.WorkbenchWizardElement;
2529
import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorMessages;
2630
import org.eclipse.ui.navigator.CommonActionProvider;
2731
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
2832
import org.eclipse.ui.navigator.ICommonMenuConstants;
2933
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
3034
import org.eclipse.ui.navigator.WizardActionGroup;
3135
import org.eclipse.ui.wizards.IWizardCategory;
36+
import org.eclipse.ui.wizards.IWizardDescriptor;
3237
import org.eclipse.ui.wizards.IWizardRegistry;
3338

3439
/**
@@ -57,6 +62,9 @@ public class NewActionProvider extends CommonActionProvider {
5762

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

65+
private static final Predicate<IWizardDescriptor> PROJECT_WIZARD_FILTER = wizardDescriptor -> Arrays
66+
.stream(wizardDescriptor.getTags()).anyMatch(WorkbenchWizardElement.TAG_PROJECT::equals);
67+
6068
private ActionFactory.IWorkbenchAction showDlgAction;
6169

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

6876
private boolean contribute = false;
6977

78+
private WizardActionGroup newProjectWizardActionGroup;
79+
7080
@Override
7181
public void init(ICommonActionExtensionSite anExtensionSite) {
7282

@@ -75,9 +85,12 @@ public void init(ICommonActionExtensionSite anExtensionSite) {
7585
showDlgAction = ActionFactory.NEW.create(window);
7686
newProjectAction = new NewProjectAction(window);
7787
newExampleAction = new NewExampleAction(window);
78-
79-
newWizardActionGroup = new WizardActionGroup(window, PlatformUI.getWorkbench().getNewWizardRegistry(), WizardActionGroup.TYPE_NEW, anExtensionSite.getContentService());
80-
88+
newProjectWizardActionGroup = new WizardActionGroup(window,
89+
PlatformUI.getWorkbench().getNewWizardRegistry(), WizardActionGroup.TYPE_NEW,
90+
anExtensionSite.getContentService(), PROJECT_WIZARD_FILTER, false);
91+
newWizardActionGroup = new WizardActionGroup(window, PlatformUI.getWorkbench().getNewWizardRegistry(),
92+
WizardActionGroup.TYPE_NEW, anExtensionSite.getContentService(), PROJECT_WIZARD_FILTER.negate(),
93+
true);
8194
contribute = true;
8295
}
8396
}
@@ -88,9 +101,11 @@ public void init(ICommonActionExtensionSite anExtensionSite) {
88101
*
89102
* <ul>
90103
* <li>a new generic project wizard shortcut action, </li>
104+
* <li>a set of context senstive wizard shortcuts (as defined by
105+
* <b>org.eclipse.ui.navigator.commonWizard</b>) that are marked as project wizards, </li>
91106
* <li>a separator, </li>
92107
* <li>a set of context senstive wizard shortcuts (as defined by
93-
* <b>org.eclipse.ui.navigator.commonWizard</b>), </li>
108+
* <b>org.eclipse.ui.navigator.commonWizard</b>) that are not marked as project wizards, </li>
94109
* <li>another separator, </li>
95110
* <li>a generic examples wizard shortcut action, and finally </li>
96111
* <li>a generic "Other" new wizard shortcut action</li>
@@ -106,6 +121,9 @@ public void fillContextMenu(IMenuManager menu) {
106121
}
107122
// Add new project wizard shortcut
108123
submenu.add(newProjectAction);
124+
// and all commonWizard contributions that are project wizards
125+
newProjectWizardActionGroup.setContext(getContext());
126+
newProjectWizardActionGroup.fillContextMenu(submenu);
109127
submenu.add(new Separator());
110128

111129
// fill the menu from the commonWizard contributions

bundles/org.eclipse.ui.navigator/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Plugin.name
44
Bundle-SymbolicName: org.eclipse.ui.navigator; singleton:=true
5-
Bundle-Version: 3.10.400.qualifier
5+
Bundle-Version: 3.11.0.qualifier
66
Bundle-Activator: org.eclipse.ui.internal.navigator.NavigatorPlugin
77
Bundle-Vendor: %Plugin.providerName
88
Bundle-Localization: plugin

bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/WizardActionGroup.java

Lines changed: 70 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.SortedSet;
2323
import java.util.TreeMap;
2424
import java.util.TreeSet;
25+
import java.util.function.Predicate;
2526

2627
import org.eclipse.core.runtime.Assert;
2728
import org.eclipse.jface.action.IAction;
@@ -107,16 +108,20 @@ public final class WizardActionGroup extends ActionGroup {
107108
* the window is passed to created WizardShortcutActions for the shell and
108109
* selection service.
109110
*/
110-
private IWorkbenchWindow window;
111+
private final IWorkbenchWindow window;
111112

112113
/* the correct wizard registry for this action group (getRegistry()) */
113-
private IWizardRegistry wizardRegistry;
114+
private final IWizardRegistry wizardRegistry;
114115

115116
private boolean disposed = false;
116117

117-
private String type;
118+
private final String type;
118119

119-
private INavigatorContentService contentService;
120+
private final INavigatorContentService contentService;
121+
122+
private final Predicate<IWizardDescriptor> descriptorFilter;
123+
124+
private final boolean useSeparators;
120125

121126
/**
122127
*
@@ -137,17 +142,7 @@ public final class WizardActionGroup extends ActionGroup {
137142
*/
138143
public WizardActionGroup(IWorkbenchWindow aWindow,
139144
IWizardRegistry aWizardRegistry, String aType) {
140-
super();
141-
Assert.isNotNull(aWindow);
142-
Assert.isNotNull(aWizardRegistry);
143-
Assert
144-
.isTrue(aType != null
145-
&& (TYPE_NEW.equals(aType) || TYPE_IMPORT.equals(aType) || TYPE_EXPORT
146-
.equals(aType)));
147-
window = aWindow;
148-
wizardRegistry = aWizardRegistry;
149-
type = aType;
150-
145+
this(aWindow, aWizardRegistry, aType, null);
151146
}
152147

153148

@@ -172,9 +167,42 @@ public WizardActionGroup(IWorkbenchWindow aWindow,
172167
*/
173168
public WizardActionGroup(IWorkbenchWindow aWindow,
174169
IWizardRegistry aWizardRegistry, String aType, INavigatorContentService aContentService) {
175-
this(aWindow, aWizardRegistry, aType);
176-
contentService = aContentService;
170+
this(aWindow, aWizardRegistry, aType, aContentService, null, true);
171+
}
177172

173+
/**
174+
*
175+
* @param aWindow The window that will be used to acquire a Shell and a
176+
* Selection Service
177+
* @param aWizardRegistry The wizard registry will be used to locate the
178+
* correct wizard descriptions.
179+
* @param aType Indicates the value of the type attribute of the
180+
* commonWizard extension point. Use any of the TYPE_XXX
181+
* constants defined on this class.
182+
* @param aContentService The content service to use when deciding visibility.
183+
* @param descriptorFilter the filter to set, might be <code>null</code> if no
184+
* filtering is desired.
185+
* @param useSeparators <code>true</code> if seperators should be used,
186+
* <code>false</code> otherwhise.
187+
* @see PlatformUI#getWorkbench()
188+
* @see IWorkbench#getNewWizardRegistry()
189+
* @see IWorkbench#getImportWizardRegistry()
190+
* @see IWorkbench#getExportWizardRegistry()
191+
* @since 3.11
192+
*/
193+
public WizardActionGroup(IWorkbenchWindow aWindow, IWizardRegistry aWizardRegistry, String aType,
194+
INavigatorContentService aContentService, Predicate<IWizardDescriptor> descriptorFilter,
195+
boolean useSeparators) {
196+
Assert.isNotNull(aWindow);
197+
Assert.isNotNull(aWizardRegistry);
198+
Assert.isNotNull(aType);
199+
Assert.isTrue(TYPE_NEW.equals(aType) || TYPE_IMPORT.equals(aType) || TYPE_EXPORT.equals(aType));
200+
this.window = aWindow;
201+
this.wizardRegistry = aWizardRegistry;
202+
this.type = aType;
203+
this.contentService = aContentService;
204+
this.descriptorFilter = descriptorFilter;
205+
this.useSeparators = useSeparators;
178206
}
179207

180208
@Override
@@ -204,15 +232,17 @@ public void fillContextMenu(IMenuManager menu) {
204232
Assert.isTrue(!disposed);
205233

206234
if (descriptors != null) {
207-
Map<String, SortedSet> groups = findGroups();
208-
SortedSet sortedWizards = null;
235+
Map<String, SortedSet<IAction>> groups = findGroups();
236+
SortedSet<IAction> sortedWizards = null;
209237
String menuGroupId = null;
210-
for (Entry<String, SortedSet> entry : groups.entrySet()) {
238+
for (Entry<String, SortedSet<IAction>> entry : groups.entrySet()) {
211239
menuGroupId = entry.getKey();
212240
sortedWizards = entry.getValue();
213-
menu.add(new Separator(menuGroupId));
214-
for (Iterator wizardItr = sortedWizards.iterator(); wizardItr.hasNext();) {
215-
menu.add((IAction) wizardItr.next());
241+
if (useSeparators) {
242+
menu.add(new Separator(menuGroupId));
243+
}
244+
for (Iterator<IAction> wizardItr = sortedWizards.iterator(); wizardItr.hasNext();) {
245+
menu.add(wizardItr.next());
216246
}
217247
}
218248
}
@@ -221,9 +251,9 @@ public void fillContextMenu(IMenuManager menu) {
221251
/**
222252
* @return A Map of menuGroupIds to SortedSets of IActions.
223253
*/
224-
private synchronized Map/*<String, SortedSet<IAction>>*/<String, SortedSet> findGroups() {
254+
private synchronized Map<String, SortedSet<IAction>> findGroups() {
225255
IAction action = null;
226-
Map<String, SortedSet> groups = new TreeMap<>();
256+
Map<String, SortedSet<IAction>> groups = new TreeMap<>();
227257
SortedSet<IAction> sortedWizards = null;
228258
String menuGroupId = null;
229259
for (CommonWizardDescriptor descriptor : descriptors) {
@@ -245,9 +275,7 @@ public void fillContextMenu(IMenuManager menu) {
245275
public void dispose() {
246276
super.dispose();
247277
actions = null;
248-
window = null;
249278
descriptors = null;
250-
wizardRegistry = null;
251279
disposed = true;
252280
}
253281

@@ -263,7 +291,7 @@ protected IAction getAction(String id) {
263291
// so that image caching in ActionContributionItem works.
264292
IAction action = getActions().get(id);
265293
if (action == null) {
266-
IWizardDescriptor descriptor = wizardRegistry.findWizard(id);
294+
IWizardDescriptor descriptor = getDescriptor(id);
267295
if (descriptor != null) {
268296
action = new WizardShortcutAction(window, descriptor);
269297
getActions().put(id, action);
@@ -273,6 +301,17 @@ protected IAction getAction(String id) {
273301
return action;
274302
}
275303

304+
305+
protected IWizardDescriptor getDescriptor(String id) {
306+
IWizardDescriptor descriptor = wizardRegistry.findWizard(id);
307+
if (descriptor != null && descriptorFilter != null) {
308+
if (!descriptorFilter.test(descriptor)) {
309+
return null;
310+
}
311+
}
312+
return descriptor;
313+
}
314+
276315
/**
277316
* @return a map of (id, IAction)-pairs.
278317
*/
@@ -306,12 +345,12 @@ private synchronized void setWizardActionDescriptors(CommonWizardDescriptor[] th
306345
descriptors = theWizardDescriptors;
307346
}
308347

309-
private static class ActionComparator implements Comparator {
348+
private static class ActionComparator implements Comparator<IAction> {
310349

311350
private static final ActionComparator INSTANCE = new ActionComparator();
312351
@Override
313-
public int compare(Object arg0, Object arg1) {
314-
return ((IAction)arg0).getText().compareTo(((IAction)arg1).getText());
352+
public int compare(IAction arg0, IAction arg1) {
353+
return arg0.getText().compareToIgnoreCase(arg1.getText());
315354
}
316355
}
317356
}

0 commit comments

Comments
 (0)