|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2007, 2017 IBM Corporation and others. |
| 2 | + * Copyright (c) 2007, 2025 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 |
|
52 | 52 | import org.eclipse.jface.viewers.CheckboxTreeViewer; |
53 | 53 | import org.eclipse.jface.viewers.IStructuredSelection; |
54 | 54 | import org.eclipse.jface.viewers.ITreeContentProvider; |
| 55 | +import org.eclipse.jface.viewers.Viewer; |
| 56 | +import org.eclipse.jface.viewers.ViewerFilter; |
55 | 57 | import org.eclipse.jface.wizard.WizardPage; |
56 | 58 | import org.eclipse.swt.SWT; |
57 | 59 | import org.eclipse.swt.events.SelectionAdapter; |
@@ -155,12 +157,44 @@ public void createControl(Composite parent) { |
155 | 157 | * @param parent the parent to add the check table viewer to |
156 | 158 | */ |
157 | 159 | protected void createViewer(Composite parent) { |
| 160 | + Text filterText = new Text(parent, SWT.SEARCH | SWT.CANCEL); |
| 161 | + filterText.setMessage(WizardMessages.ImportLaunchTypeToFilter); |
| 162 | + filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 163 | + ViewerFilter filter = new ViewerFilter() { |
| 164 | + @Override |
| 165 | + public boolean select(Viewer viewer2, Object parentElement, Object element) { |
| 166 | + String search = filterText.getText().toLowerCase(); |
| 167 | + if (search.isEmpty()) { |
| 168 | + fViewer.collapseAll(); |
| 169 | + return true; |
| 170 | + } |
| 171 | + if (element instanceof ILaunchConfiguration launchConfig) { |
| 172 | + return launchConfig.getName().toLowerCase().contains(search); |
| 173 | + } |
| 174 | + if (element instanceof ILaunchConfigurationType launchConfigType) { |
| 175 | + try { |
| 176 | + for (ILaunchConfiguration config2 : lm.getLaunchConfigurations(launchConfigType)) { |
| 177 | + if (config2.getName().toLowerCase().contains(search)) { |
| 178 | + return true; |
| 179 | + } |
| 180 | + } |
| 181 | + } catch (Exception e) { |
| 182 | + DebugPlugin.log(e); |
| 183 | + return false; |
| 184 | + } |
| 185 | + return false; |
| 186 | + } |
| 187 | + return true; |
| 188 | + } |
| 189 | + }; |
158 | 190 | SWTFactory.createWrapLabel(parent, WizardMessages.ExportLaunchConfigurationsWizardPage_3, 2); |
159 | 191 | Tree tree = new Tree(parent, SWT.BORDER | SWT.SINGLE | SWT.CHECK); |
160 | 192 | GridData gd = new GridData(GridData.FILL_BOTH); |
161 | 193 | gd.horizontalSpan = 2; |
162 | 194 | tree.setLayoutData(gd); |
163 | 195 | fViewer = new CheckboxTreeViewer(tree); |
| 196 | + fViewer.addFilter(filter); |
| 197 | + |
164 | 198 | fViewer.setLabelProvider(DebugUITools.newDebugModelPresentation()); |
165 | 199 | fViewer.setComparator(new WorkbenchViewerComparator()); |
166 | 200 | fContentProvider = new ConfigContentProvider(); |
@@ -206,6 +240,10 @@ public void widgetSelected(SelectionEvent e) { |
206 | 240 | setPageComplete(isComplete()); |
207 | 241 | } |
208 | 242 | }); |
| 243 | + filterText.addModifyListener(e -> { |
| 244 | + fViewer.refresh(); |
| 245 | + fViewer.expandAll(); |
| 246 | + }); |
209 | 247 | } |
210 | 248 |
|
211 | 249 | /** |
|
0 commit comments