11/*******************************************************************************
2- * Copyright (c) 2005, 2015 IBM Corporation and others.
2+ * Copyright (c) 2005, 2024 IBM Corporation and others.
33 *
44 * This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License 2.0
1515package org .eclipse .ui .internal .dialogs ;
1616
1717import java .util .ArrayList ;
18+ import java .util .function .Function ;
19+ import java .util .stream .Stream ;
1820import org .eclipse .jface .viewers .Viewer ;
1921import org .eclipse .ui .dialogs .PatternFilter ;
22+ import org .eclipse .ui .wizards .IWizardCategory ;
2023
2124/**
2225 * A class that handles filtering wizard node items based on a supplied matching
@@ -39,27 +42,21 @@ public boolean isElementSelectable(Object element) {
3942
4043 @ Override
4144 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+ }
5653
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 ();
6157 }
62- return false ;
58+ return Stream .iterate (category , current -> current .getParent () != null , IWizardCategory ::getParent )
59+ .map (IWizardCategory ::getLabel );
6360 }
6461
6562 @ Override
0 commit comments