|
27 | 27 | import org.eclipse.jface.viewers.TableViewer; |
28 | 28 | import org.eclipse.jface.viewers.Viewer; |
29 | 29 | import org.eclipse.jface.viewers.ViewerComparator; |
| 30 | +import org.eclipse.jface.viewers.ViewerFilter; |
30 | 31 | import org.eclipse.osgi.util.TextProcessor; |
31 | 32 | import org.eclipse.swt.SWT; |
32 | 33 | import org.eclipse.swt.custom.TableEditor; |
33 | 34 | import org.eclipse.swt.graphics.Image; |
34 | 35 | import org.eclipse.swt.layout.GridData; |
| 36 | +import org.eclipse.swt.layout.GridLayout; |
35 | 37 | import org.eclipse.swt.widgets.Composite; |
36 | 38 | import org.eclipse.swt.widgets.Table; |
37 | 39 | import org.eclipse.swt.widgets.TableColumn; |
| 40 | +import org.eclipse.swt.widgets.Text; |
38 | 41 | import org.eclipse.team.core.Team; |
39 | 42 | import org.eclipse.team.internal.ui.PixelConverter; |
40 | 43 | import org.eclipse.team.internal.ui.SWTUtils; |
@@ -114,10 +117,22 @@ public FileTypeTable(Composite composite, List items, boolean showSaveColumn) { |
114 | 117 | fItems= items; |
115 | 118 |
|
116 | 119 |
|
| 120 | + Composite tableComposite = new Composite(composite, SWT.NONE); |
| 121 | + tableComposite.setLayout(new GridLayout(1, false)); |
| 122 | + tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 123 | + |
| 124 | + /** |
| 125 | + * Create a Text filter. |
| 126 | + */ |
| 127 | + Text filterText = new Text(tableComposite, SWT.SEARCH | SWT.ICON_CANCEL); |
| 128 | + filterText.setMessage(TeamUIMessages.VersionControl_FilterMessage); |
| 129 | + filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 130 | + |
117 | 131 | /** |
118 | 132 | * Create a table. |
119 | 133 | */ |
120 | | - final Table table = new Table(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); |
| 134 | + final Table table = new Table(tableComposite, |
| 135 | + SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); |
121 | 136 | var gd = new GridData(SWT.FILL, SWT.FILL, true, true); |
122 | 137 | gd.heightHint = 300; |
123 | 138 | table.setLayoutData(gd); |
@@ -176,15 +191,33 @@ public FileTypeTable(Composite composite, List items, boolean showSaveColumn) { |
176 | 191 |
|
177 | 192 | if (fShowSaveColumn) { |
178 | 193 | fTableViewer.setCellEditors(new CellEditor[] { null, modeEditor, saveEditor }); |
179 | | - fTableViewer.setColumnProperties(new String [] { ITEM, PROPERTY_MODE, PROPERTY_SAVE }); |
| 194 | + fTableViewer.setColumnProperties(new String[] { ITEM, PROPERTY_MODE, PROPERTY_SAVE }); |
180 | 195 | } else { |
181 | | - fTableViewer.setCellEditors(new CellEditor [] { null, modeEditor }); |
182 | | - fTableViewer.setColumnProperties(new String [] { ITEM, PROPERTY_MODE }); |
| 196 | + fTableViewer.setCellEditors(new CellEditor[] { null, modeEditor }); |
| 197 | + fTableViewer.setColumnProperties(new String[] { ITEM, PROPERTY_MODE }); |
183 | 198 | } |
184 | 199 |
|
185 | 200 | fTableViewer.setCellModifier(this); |
186 | 201 |
|
187 | 202 | fTableViewer.setInput(fItems); |
| 203 | + |
| 204 | + |
| 205 | + ViewerFilter tableFilter = new ViewerFilter() { |
| 206 | + @Override |
| 207 | + public boolean select(Viewer viewer, Object parentElement, Object element) { |
| 208 | + String inputText = filterText.getText().toLowerCase().trim(); |
| 209 | + |
| 210 | + if (inputText.isEmpty()) { |
| 211 | + return true; |
| 212 | + } |
| 213 | + |
| 214 | + Item text = (Item) element; |
| 215 | + return text.name != null && text.name.toLowerCase().contains(inputText); |
| 216 | + } |
| 217 | + }; |
| 218 | + |
| 219 | + fTableViewer.addFilter(tableFilter); |
| 220 | + filterText.addModifyListener(e -> fTableViewer.refresh()); |
188 | 221 | } |
189 | 222 |
|
190 | 223 |
|
@@ -247,7 +280,7 @@ public Image getColumnImage(Object element, int columnIndex) { |
247 | 280 | @Override |
248 | 281 | public String getColumnText(Object element, int columnIndex) { |
249 | 282 |
|
250 | | - final Item item= (Item) element; |
| 283 | + final Item item = (Item) element; |
251 | 284 |
|
252 | 285 | if (columnIndex == 0) { |
253 | 286 | String label = (item instanceof Extension ? "*." : "") + item.name; //$NON-NLS-1$ //$NON-NLS-2$ |
|
0 commit comments