22
22
import java .util .SortedSet ;
23
23
import java .util .TreeMap ;
24
24
import java .util .TreeSet ;
25
+ import java .util .function .Predicate ;
25
26
26
27
import org .eclipse .core .runtime .Assert ;
27
28
import org .eclipse .jface .action .IAction ;
@@ -107,16 +108,20 @@ public final class WizardActionGroup extends ActionGroup {
107
108
* the window is passed to created WizardShortcutActions for the shell and
108
109
* selection service.
109
110
*/
110
- private IWorkbenchWindow window ;
111
+ private final IWorkbenchWindow window ;
111
112
112
113
/* the correct wizard registry for this action group (getRegistry()) */
113
- private IWizardRegistry wizardRegistry ;
114
+ private final IWizardRegistry wizardRegistry ;
114
115
115
116
private boolean disposed = false ;
116
117
117
- private String type ;
118
+ private final String type ;
118
119
119
- private INavigatorContentService contentService ;
120
+ private final INavigatorContentService contentService ;
121
+
122
+ private final Predicate <IWizardDescriptor > descriptorFilter ;
123
+
124
+ private final boolean useSeparators ;
120
125
121
126
/**
122
127
*
@@ -137,17 +142,7 @@ public final class WizardActionGroup extends ActionGroup {
137
142
*/
138
143
public WizardActionGroup (IWorkbenchWindow aWindow ,
139
144
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 );
151
146
}
152
147
153
148
@@ -172,9 +167,42 @@ public WizardActionGroup(IWorkbenchWindow aWindow,
172
167
*/
173
168
public WizardActionGroup (IWorkbenchWindow aWindow ,
174
169
IWizardRegistry aWizardRegistry , String aType , INavigatorContentService aContentService ) {
175
- this (aWindow , aWizardRegistry , aType );
176
- contentService = aContentService ;
170
+ this (aWindow , aWizardRegistry , aType , aContentService , null , true );
171
+ }
177
172
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 ;
178
206
}
179
207
180
208
@ Override
@@ -204,15 +232,17 @@ public void fillContextMenu(IMenuManager menu) {
204
232
Assert .isTrue (!disposed );
205
233
206
234
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 ;
209
237
String menuGroupId = null ;
210
- for (Entry <String , SortedSet > entry : groups .entrySet ()) {
238
+ for (Entry <String , SortedSet < IAction > > entry : groups .entrySet ()) {
211
239
menuGroupId = entry .getKey ();
212
240
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 ());
216
246
}
217
247
}
218
248
}
@@ -221,9 +251,9 @@ public void fillContextMenu(IMenuManager menu) {
221
251
/**
222
252
* @return A Map of menuGroupIds to SortedSets of IActions.
223
253
*/
224
- private synchronized Map /* <String, SortedSet<IAction>>*/ < String , SortedSet > findGroups () {
254
+ private synchronized Map <String , SortedSet <IAction >> findGroups () {
225
255
IAction action = null ;
226
- Map <String , SortedSet > groups = new TreeMap <>();
256
+ Map <String , SortedSet < IAction > > groups = new TreeMap <>();
227
257
SortedSet <IAction > sortedWizards = null ;
228
258
String menuGroupId = null ;
229
259
for (CommonWizardDescriptor descriptor : descriptors ) {
@@ -245,9 +275,7 @@ public void fillContextMenu(IMenuManager menu) {
245
275
public void dispose () {
246
276
super .dispose ();
247
277
actions = null ;
248
- window = null ;
249
278
descriptors = null ;
250
- wizardRegistry = null ;
251
279
disposed = true ;
252
280
}
253
281
@@ -263,7 +291,7 @@ protected IAction getAction(String id) {
263
291
// so that image caching in ActionContributionItem works.
264
292
IAction action = getActions ().get (id );
265
293
if (action == null ) {
266
- IWizardDescriptor descriptor = wizardRegistry . findWizard (id );
294
+ IWizardDescriptor descriptor = getDescriptor (id );
267
295
if (descriptor != null ) {
268
296
action = new WizardShortcutAction (window , descriptor );
269
297
getActions ().put (id , action );
@@ -273,6 +301,17 @@ protected IAction getAction(String id) {
273
301
return action ;
274
302
}
275
303
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
+
276
315
/**
277
316
* @return a map of (id, IAction)-pairs.
278
317
*/
@@ -306,12 +345,12 @@ private synchronized void setWizardActionDescriptors(CommonWizardDescriptor[] th
306
345
descriptors = theWizardDescriptors ;
307
346
}
308
347
309
- private static class ActionComparator implements Comparator {
348
+ private static class ActionComparator implements Comparator < IAction > {
310
349
311
350
private static final ActionComparator INSTANCE = new ActionComparator ();
312
351
@ 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 ());
315
354
}
316
355
}
317
356
}
0 commit comments