Skip to content

Commit c5710ef

Browse files
elsazaclaeubi
authored andcommitted
Add filter text to Version Control preferences
Introduced a search field above the table in the Version Control tab of the Preferences page to allow filtering entries.
1 parent a6bd13c commit c5710ef

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ public class TeamUIMessages extends NLS {
631631

632632
public static String ResourceMappingMergeOperation_4;
633633

634+
public static String VersionControl_FilterMessage;
634635

635636
public static String GenericHistoryView_PinCurrentHistory;
636637

team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ ResourceMappingMergeOperation_2=&Done
355355
ResourceMappingMergeOperation_3=Multiple potential side effects of this operation have been detected.
356356
ResourceMappingMergeOperation_4=Preview the merge before it is performed
357357

358+
VersionControl_FilterMessage=type filter text
359+
358360
CompressedFoldersModelProvider_0=&Compressed Folders
359361
HierarchicalModelProvider_0=&Tree
360362
UIProjectSetSerializationContext_0=Project {0} exists in the workspace. Overwrite {0}?

team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/preferences/FileTypeTable.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@
2727
import org.eclipse.jface.viewers.TableViewer;
2828
import org.eclipse.jface.viewers.Viewer;
2929
import org.eclipse.jface.viewers.ViewerComparator;
30+
import org.eclipse.jface.viewers.ViewerFilter;
3031
import org.eclipse.osgi.util.TextProcessor;
3132
import org.eclipse.swt.SWT;
3233
import org.eclipse.swt.custom.TableEditor;
3334
import org.eclipse.swt.graphics.Image;
3435
import org.eclipse.swt.layout.GridData;
36+
import org.eclipse.swt.layout.GridLayout;
3537
import org.eclipse.swt.widgets.Composite;
3638
import org.eclipse.swt.widgets.Table;
3739
import org.eclipse.swt.widgets.TableColumn;
40+
import org.eclipse.swt.widgets.Text;
3841
import org.eclipse.team.core.Team;
3942
import org.eclipse.team.internal.ui.PixelConverter;
4043
import org.eclipse.team.internal.ui.SWTUtils;
@@ -114,10 +117,22 @@ public FileTypeTable(Composite composite, List items, boolean showSaveColumn) {
114117
fItems= items;
115118

116119

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+
117131
/**
118132
* Create a table.
119133
*/
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);
121136
var gd = new GridData(SWT.FILL, SWT.FILL, true, true);
122137
gd.heightHint = 300;
123138
table.setLayoutData(gd);
@@ -176,15 +191,33 @@ public FileTypeTable(Composite composite, List items, boolean showSaveColumn) {
176191

177192
if (fShowSaveColumn) {
178193
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 });
180195
} 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 });
183198
}
184199

185200
fTableViewer.setCellModifier(this);
186201

187202
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());
188221
}
189222

190223

@@ -247,7 +280,7 @@ public Image getColumnImage(Object element, int columnIndex) {
247280
@Override
248281
public String getColumnText(Object element, int columnIndex) {
249282

250-
final Item item= (Item) element;
283+
final Item item = (Item) element;
251284

252285
if (columnIndex == 0) {
253286
String label = (item instanceof Extension ? "*." : "") + item.name; //$NON-NLS-1$ //$NON-NLS-2$

0 commit comments

Comments
 (0)