Skip to content

Commit 54ce71c

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 c7d99fd commit 54ce71c

15 files changed

+403
-368
lines changed

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

+8
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

+1
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

+9-5
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

-65
This file was deleted.

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

+24-27
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
@@ -146,24 +147,19 @@ protected void createMainLabel(Composite parent, int span, FormToolkit toolkit)
146147
label.setLayoutData(gd);
147148
}
148149

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

165157
public int getSelectionCount() {
166-
return counter;
158+
CachedCheckboxTableViewer viewer = getTableViewer();
159+
if (viewer == null) {
160+
return 0;
161+
}
162+
return viewer.getAllCheckedCount();
167163
}
168164

169165
public void selectAll(boolean select) {
@@ -172,19 +168,21 @@ public void selectAll(boolean select) {
172168

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

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

190188
protected void handleSelect(boolean select) {
@@ -194,14 +192,13 @@ protected void handleSelect(boolean select) {
194192
for (TableItem selectedItem : selected) {
195193
selectedItem.setChecked(select);
196194
}
197-
updateCounter(viewer.getCheckedElements().length);
195+
updateCounterLabel();
198196
}
199197
}
200198

201199
@Override
202200
protected void elementChecked(Object element, boolean checked) {
203-
int count = getSelectionCount();
204-
updateCounter(checked ? count + 1 : count - 1);
201+
updateCounterLabel();
205202
}
206203

207204
public Label getCounterLabel() {

0 commit comments

Comments
 (0)