Skip to content

Commit ff41115

Browse files
committed
Wrap viewer in CheckboxTablePart within a FilteredTable
By using the FilteredTable, we get a quick-filter for all extending parts for free. This includes: - The Cross-platform page of the "Deployable features" export wizard. - The Update Java Classpath page of the "Update classpath..." action - The Selection page of the "Import Plug-ins and Fragments" wizard - The Update Java Classpath page of the "Plug-in from Existing JAR Archives" wizard. - The Template Selection page of the "Plug-in Project" page. Together with the quick-filter comes a caching of the checked table items. Those elements remain checked, even if currently hidden by the filter and will be restored once they become visible again. Furthermore, the PluginListPage has been adapted to use a CheckboxTablePart rather than a CheckboxTreePart (effectively reverting 4c1edad), to match the list of plugins that it displays. Contributes to #1497
1 parent 5d4fd66 commit ff41115

15 files changed

+405
-386
lines changed

ui/org.eclipse.pde.ui/.settings/.api_filters

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@
120120
</message_arguments>
121121
</filter>
122122
</resource>
123+
<resource path="src/org/eclipse/pde/internal/ui/shared/CachedCheckboxTableViewer.java" type="org.eclipse.pde.internal.ui.shared.CachedCheckboxTableViewer">
124+
<filter comment="Extends CheckboxTableViewer to match CachedCheckboxTreeviewer" id="571473929">
125+
<message_arguments>
126+
<message_argument value="CheckboxTableViewer"/>
127+
<message_argument value="CachedCheckboxTableViewer"/>
128+
</message_arguments>
129+
</filter>
130+
</resource>
123131
<resource path="src/org/eclipse/pde/internal/ui/shared/target/EditTargetContainerPage.java" type="org.eclipse.pde.internal.ui.shared.target.EditTargetContainerPage">
124132
<filter id="640712815">
125133
<message_arguments>

ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Require-Bundle:
7777
org.eclipse.pde.core;bundle-version="[3.17.200,4.0.0)";visibility:=reexport,
7878
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
7979
org.eclipse.e4.core.services;bundle-version="[2.4.200,3.0.0)",
80+
org.eclipse.e4.ui.dialogs;bundle-version="[1.6.0,2.0.0)",
8081
org.eclipse.ui.ide;bundle-version="[3.21.200,4.0.0)",
8182
org.eclipse.ui.views;bundle-version="[3.12.100,4.0.0)",
8283
org.eclipse.jface.text;bundle-version="[3.24.200,4.0.0)",

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/CheckboxTablePart.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 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
@@ -13,15 +13,18 @@
1313
*******************************************************************************/
1414
package org.eclipse.pde.internal.ui.parts;
1515

16-
import org.eclipse.jface.viewers.CheckboxTableViewer;
1716
import org.eclipse.jface.viewers.IStructuredSelection;
1817
import org.eclipse.jface.viewers.StructuredViewer;
18+
import org.eclipse.pde.internal.ui.shared.CachedCheckboxTableViewer;
19+
import org.eclipse.pde.internal.ui.shared.FilteredCheckboxTable;
1920
import org.eclipse.swt.SWT;
2021
import org.eclipse.swt.widgets.Button;
2122
import org.eclipse.swt.widgets.Composite;
2223
import org.eclipse.ui.forms.widgets.FormToolkit;
2324

2425
public class CheckboxTablePart extends StructuredViewerPart {
26+
private FilteredCheckboxTable filteredTable;
27+
2528
public CheckboxTablePart(String[] buttonLabels) {
2629
super(buttonLabels);
2730
}
@@ -34,15 +37,16 @@ protected StructuredViewer createStructuredViewer(Composite parent, int style, F
3437
} else {
3538
style |= toolkit.getBorderStyle();
3639
}
37-
CheckboxTableViewer tableViewer = CheckboxTableViewer.newCheckList(parent, style);
40+
filteredTable = new FilteredCheckboxTable(parent, toolkit, style);
41+
CachedCheckboxTableViewer tableViewer = filteredTable.getViewer();
3842
tableViewer
3943
.addSelectionChangedListener(e -> CheckboxTablePart.this.selectionChanged(e.getStructuredSelection()));
4044
tableViewer.addCheckStateListener(event -> elementChecked(event.getElement(), event.getChecked()));
4145
return tableViewer;
4246
}
4347

44-
public CheckboxTableViewer getTableViewer() {
45-
return (CheckboxTableViewer) getViewer();
48+
public CachedCheckboxTableViewer getTableViewer() {
49+
return (CachedCheckboxTableViewer) getViewer();
4650
}
4751

4852
@Override

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/CheckboxTreePart.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/WizardCheckboxTablePart.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 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
@@ -14,9 +14,11 @@
1414
package org.eclipse.pde.internal.ui.parts;
1515

1616
import org.eclipse.jface.viewers.CheckboxTableViewer;
17+
import org.eclipse.jface.viewers.IStructuredContentProvider;
1718
import org.eclipse.jface.viewers.StructuredViewer;
1819
import org.eclipse.osgi.util.NLS;
1920
import org.eclipse.pde.internal.ui.PDEUIMessages;
21+
import org.eclipse.pde.internal.ui.shared.CachedCheckboxTableViewer;
2022
import org.eclipse.pde.internal.ui.util.SWTUtil;
2123
import org.eclipse.pde.internal.ui.wizards.ListUtil;
2224
import org.eclipse.swt.SWT;
@@ -33,7 +35,6 @@ public class WizardCheckboxTablePart extends CheckboxTablePart {
3335
private int selectIndex = -1;
3436
private int deselectIndex = -1;
3537
private final String tableName;
36-
private int counter;
3738
private Label counterLabel;
3839

3940
/**
@@ -92,7 +93,7 @@ public Object[] getSelection() {
9293
public void setSelection(Object[] selected) {
9394
CheckboxTableViewer viewer = getTableViewer();
9495
viewer.setCheckedElements(selected);
95-
updateCounter(viewer.getCheckedElements().length);
96+
updateCounterLabel();
9697
}
9798

9899
public void createControl(Composite parent) {
@@ -105,7 +106,7 @@ public void createControl(Composite parent, int span) {
105106
GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
106107
gd.horizontalSpan = span;
107108
counterLabel.setLayoutData(gd);
108-
updateCounter(0);
109+
updateCounterLabel();
109110
}
110111

111112
public void createControl(Composite parent, int span, boolean multiselect) {
@@ -118,7 +119,7 @@ public void createControl(Composite parent, int span, boolean multiselect) {
118119
GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
119120
gd.horizontalSpan = span;
120121
counterLabel.setLayoutData(gd);
121-
updateCounter(0);
122+
updateCounterLabel();
122123
}
123124

124125
@Override
@@ -147,24 +148,19 @@ protected void createMainLabel(Composite parent, int span, FormToolkit toolkit)
147148
label.setLayoutData(gd);
148149
}
149150

150-
protected void updateCounter(int amount) {
151-
counter = amount;
152-
updateCounterLabel();
153-
}
154-
155-
public void updateCount(int amount) {
156-
updateCounter(amount);
157-
}
158-
159-
protected void updateCounterLabel() {
151+
public void updateCounterLabel() {
160152
String number = "" + getSelectionCount(); //$NON-NLS-1$
161153
String totalNumber = "" + getTotalCount(); //$NON-NLS-1$
162154
String message = NLS.bind(PDEUIMessages.WizardCheckboxTablePart_counter, (new String[] {number, totalNumber}));
163155
counterLabel.setText(message);
164156
}
165157

166158
public int getSelectionCount() {
167-
return counter;
159+
CachedCheckboxTableViewer viewer = getTableViewer();
160+
if (viewer == null) {
161+
return 0;
162+
}
163+
return viewer.getAllCheckedCount();
168164
}
169165

170166
public void selectAll(boolean select) {
@@ -173,19 +169,21 @@ public void selectAll(boolean select) {
173169

174170
private int getTotalCount() {
175171
CheckboxTableViewer viewer = getTableViewer();
176-
return viewer.getTable().getItemCount();
172+
if (viewer == null) {
173+
return 0;
174+
}
175+
176+
IStructuredContentProvider contentProvider = (IStructuredContentProvider) viewer.getContentProvider();
177+
if (contentProvider == null) {
178+
return 0;
179+
}
180+
return contentProvider.getElements(viewer.getInput()).length;
177181
}
178182

179183
protected void handleSelectAll(boolean select) {
180184
CheckboxTableViewer viewer = getTableViewer();
181185
viewer.setAllChecked(select);
182-
int selected;
183-
if (!select) {
184-
selected = 0;
185-
} else {
186-
selected = getTotalCount();
187-
}
188-
updateCounter(selected);
186+
updateCounterLabel();
189187
}
190188

191189
protected void handleSelect(boolean select) {
@@ -195,14 +193,13 @@ protected void handleSelect(boolean select) {
195193
for (TableItem selectedItem : selected) {
196194
selectedItem.setChecked(select);
197195
}
198-
updateCounter(viewer.getCheckedElements().length);
196+
updateCounterLabel();
199197
}
200198
}
201199

202200
@Override
203201
protected void elementChecked(Object element, boolean checked) {
204-
int count = getSelectionCount();
205-
updateCounter(checked ? count + 1 : count - 1);
202+
updateCounterLabel();
206203
}
207204

208205
public Label getCounterLabel() {

0 commit comments

Comments
 (0)