Skip to content

Commit a6bd13c

Browse files
SougandhSlaeubi
authored andcommitted
Add filter field and sort launches
This commit adds a filter field to filter the launches and sorts shown in debug/run 'Add to favorite' dialog and sorts the launches based on launch type Fixes : #2113
1 parent 2a9f9bc commit a6bd13c

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,6 @@ public class LaunchConfigurationsMessages extends NLS {
307307
public static String SelectLaunchOptionsDialog_3;
308308
public static String SelectLaunchOptionsDialog_4;
309309

310+
public static String SelectFavTypeToFilter;
311+
310312
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,4 @@ SelectLaunchersDialog_2=This dialog allows you to specify which launcher to use
284284
SelectLaunchersDialog_4=<a href="ws">Change Workspace Settings...</a>
285285
SelectLaunchersDialog_5=Description
286286
SelectLaunchersDialog_launchers=Launc&hers:
287+
SelectFavTypeToFilter= Type to filter

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/SelectFavoritesDialog.java

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2007, 2013 IBM Corporation and others.
2+
* Copyright (c) 2007, 2025 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
@@ -15,6 +15,7 @@
1515

1616
import java.text.MessageFormat;
1717
import java.util.ArrayList;
18+
import java.util.Arrays;
1819
import java.util.List;
1920

2021
import org.eclipse.core.runtime.CoreException;
@@ -24,15 +25,23 @@
2425
import org.eclipse.debug.internal.ui.DebugUIPlugin;
2526
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
2627
import org.eclipse.debug.ui.IDebugUIConstants;
28+
import org.eclipse.jface.viewers.CheckboxTableViewer;
2729
import org.eclipse.jface.viewers.IContentProvider;
2830
import org.eclipse.jface.viewers.IStructuredContentProvider;
31+
import org.eclipse.jface.viewers.StructuredViewer;
2932
import org.eclipse.jface.viewers.Viewer;
3033
import org.eclipse.jface.viewers.ViewerFilter;
34+
import org.eclipse.swt.SWT;
35+
import org.eclipse.swt.layout.GridData;
36+
import org.eclipse.swt.layout.GridLayout;
37+
import org.eclipse.swt.widgets.Composite;
3138
import org.eclipse.swt.widgets.Shell;
32-
import org.eclipse.ui.model.WorkbenchViewerComparator;
39+
import org.eclipse.swt.widgets.Table;
40+
import org.eclipse.swt.widgets.Text;
3341

3442
/**
35-
* This dialog is used to select one or more launch configurations to add to your favorites
43+
* This dialog is used to select one or more launch configurations to add to
44+
* your favorites
3645
*
3746
* @since 3.3.0
3847
*/
@@ -46,7 +55,8 @@ protected class LaunchConfigurationContentProvider implements IStructuredContent
4655
public Object[] getElements(Object inputElement) {
4756
ILaunchConfiguration[] all = null;
4857
try {
49-
all = LaunchConfigurationManager.filterConfigs(DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations());
58+
all = LaunchConfigurationManager
59+
.filterConfigs(DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations());
5060
} catch (CoreException e) {
5161
DebugUIPlugin.log(e);
5262
return new ILaunchConfiguration[0];
@@ -60,14 +70,31 @@ public Object[] getElements(Object inputElement) {
6070
}
6171
list.removeAll(fCurrentFavoriteSet);
6272
Object[] objs = list.toArray();
63-
new WorkbenchViewerComparator().sort(getCheckBoxTableViewer(), objs);
73+
Arrays.sort(objs, (o1, o2) -> {
74+
if (o1 instanceof ILaunchConfiguration launch1 && o2 instanceof ILaunchConfiguration launch2) {
75+
try {
76+
String type1 = launch1.getType().getName();
77+
String type2 = launch2.getType().getName();
78+
int cmp = type1.compareToIgnoreCase(type2);
79+
if (cmp != 0) {
80+
return cmp;
81+
}
82+
return launch1.getName().compareToIgnoreCase(launch2.getName());
83+
} catch (CoreException e) {
84+
DebugUIPlugin.log(e);
85+
}
86+
}
87+
return 0;
88+
});
6489
return objs;
6590
}
6691

6792
@Override
68-
public void dispose() {}
93+
public void dispose() {
94+
}
6995
@Override
70-
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
96+
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
97+
}
7198
}
7299

73100
private final LaunchHistory fHistory;
@@ -118,4 +145,33 @@ protected String getViewerLabel() {
118145
return LaunchConfigurationsMessages.FavoritesDialog_7;
119146
}
120147

148+
@Override
149+
protected StructuredViewer createViewer(Composite parent) {
150+
Composite container = new Composite(parent, SWT.NONE);
151+
container.setLayout(new GridLayout(1, false));
152+
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
153+
154+
Text filterText = new Text(container, SWT.SEARCH | SWT.CANCEL);
155+
filterText.setMessage(LaunchConfigurationsMessages.SelectFavTypeToFilter);
156+
filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
157+
158+
Table table = new Table(container, SWT.BORDER | SWT.SINGLE | SWT.CHECK);
159+
GridData gd = new GridData(GridData.FILL_BOTH);
160+
gd.heightHint = 150;
161+
gd.widthHint = 250;
162+
table.setLayoutData(gd);
163+
CheckboxTableViewer viewer = new CheckboxTableViewer(table);
164+
ViewerFilter filter = new ViewerFilter() {
165+
@Override
166+
public boolean select(Viewer viewer2, Object parentElement, Object element) {
167+
String search = filterText.getText().toLowerCase();
168+
if (search.isEmpty())
169+
return true;
170+
return element.toString().toLowerCase().contains(search);
171+
}
172+
};
173+
viewer.addFilter(filter);
174+
filterText.addModifyListener(e -> viewer.refresh());
175+
return viewer;
176+
}
121177
}

0 commit comments

Comments
 (0)