1
1
/*******************************************************************************
2
- * Copyright (c) 2005, 2015 IBM Corporation and others.
2
+ * Copyright (c) 2005, 2024 IBM Corporation and others.
3
3
*
4
4
* This program and the accompanying materials
5
5
* are made available under the terms of the Eclipse Public License 2.0
15
15
package org .eclipse .ui .internal .dialogs ;
16
16
17
17
import java .util .ArrayList ;
18
+ import java .util .function .Function ;
19
+ import java .util .stream .Stream ;
18
20
import org .eclipse .jface .viewers .Viewer ;
19
21
import org .eclipse .ui .dialogs .PatternFilter ;
22
+ import org .eclipse .ui .wizards .IWizardCategory ;
20
23
21
24
/**
22
25
* A class that handles filtering wizard node items based on a supplied matching
@@ -39,27 +42,21 @@ public boolean isElementSelectable(Object element) {
39
42
40
43
@ Override
41
44
protected boolean isLeafMatch (Viewer viewer , Object element ) {
42
- if (element instanceof WizardCollectionElement ) {
43
- return false ;
44
- }
45
-
46
- if (element instanceof WorkbenchWizardElement ) {
47
- WorkbenchWizardElement desc = (WorkbenchWizardElement ) element ;
48
- String text = desc .getLabel ();
49
- if (wordMatches (text )) {
50
- return true ;
51
- }
52
- String wizDesc = desc .getDescription ();
53
- if (wordMatches (wizDesc )) {
54
- return true ;
55
- }
45
+ return element instanceof WorkbenchWizardElement desc &&
46
+ Stream .of (getWizardCategories (desc .getCategory ()), //
47
+ Stream .of (desc .getLabel (), desc .getDescription ()), //
48
+ Stream .of (desc .getKeywordLabels ())) //
49
+ // Only works for finite streams
50
+ .flatMap (Function .identity ())
51
+ .anyMatch (this ::wordMatches );
52
+ }
56
53
57
- for (String keywordLabel : desc .getKeywordLabels ()) {
58
- if (wordMatches (keywordLabel ))
59
- return true ;
60
- }
54
+ private Stream <String > getWizardCategories (IWizardCategory category ) {
55
+ if (category == null ) {
56
+ return Stream .empty ();
61
57
}
62
- return false ;
58
+ return Stream .iterate (category , current -> current .getParent () != null , IWizardCategory ::getParent )
59
+ .map (IWizardCategory ::getLabel );
63
60
}
64
61
65
62
@ Override
0 commit comments