-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Implement filter-based TableViewer as a counterpart to the FilteredTree
Projects such as PDE currently use the FilteredTree in combination with a child-less ITreeContentProvider to simulate a filtered table. This approach brings a big performance overhead, as the tree still has to handle functionality such as expansion and contraction of the (flat) tree structure which especially large trees/tables causes a significant overhead.
Showing
26 changed files
with
1,545 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<component id="org.eclipse.e4.ui.dialogs" version="2"> | ||
<resource path="src/org/eclipse/e4/ui/dialogs/filteredtree/FilteredTable.java" type="org.eclipse.e4.ui.dialogs.filteredtree.FilteredTable$NotifyingTableViewer"> | ||
<filter id="571473929"> | ||
<message_arguments> | ||
<message_argument value="TableViewer"/> | ||
<message_argument value="NotifyingTableViewer"/> | ||
</message_arguments> | ||
</filter> | ||
</resource> | ||
</component> |
465 changes: 465 additions & 0 deletions
465
...s/org.eclipse.e4.ui.dialogs/src/org/eclipse/e4/ui/dialogs/filteredtree/FilteredTable.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<component id="org.eclipse.ui.workbench" version="2"> | ||
<resource path="eclipseui/org/eclipse/ui/dialogs/FilteredTable.java" type="org.eclipse.ui.dialogs.FilteredTable$NotifyingTableViewer"> | ||
<filter id="571473929"> | ||
<message_arguments> | ||
<message_argument value="TableViewer"/> | ||
<message_argument value="NotifyingTableViewer"/> | ||
</message_arguments> | ||
</filter> | ||
</resource> | ||
</component> |
500 changes: 500 additions & 0 deletions
500
bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredTable.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.eclipse.ui.examples.filter</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
2 changes: 2 additions & 0 deletions
2
examples/org.eclipse.ui.examples.filter/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
11 changes: 11 additions & 0 deletions
11
examples/org.eclipse.ui.examples.filter/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=17 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=17 |
12 changes: 12 additions & 0 deletions
12
examples/org.eclipse.ui.examples.filter/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: %Bundle-Name | ||
Bundle-SymbolicName: org.eclipse.ui.examples.filter;singleton:=true | ||
Bundle-Vendor: %Bundle-Vendor | ||
Bundle-Version: 1.0.0.qualifier | ||
Require-Bundle: org.eclipse.ui;bundle-version="3.207.0", | ||
org.eclipse.core.runtime;bundle-version="3.32.100" | ||
Bundle-RequiredExecutionEnvironment: JavaSE-17 | ||
Automatic-Module-Name: org.eclipse.ui.examples.filter | ||
Bundle-Localization: plugin | ||
Bundle-ActivationPolicy: lazy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This examples plug-in demonstrates the following features: | ||
|
||
- Creating a tree viewer with a simple filter | ||
- Creating a table viewer with a simple filter | ||
- Creating a lazy table viewer with a simple filter | ||
|
||
The examples can be seen by opening the "Filter Tree View", "Filter Table View" and "Filter (Virtual) Table View, respectively. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | ||
<title>About</title> | ||
</head> | ||
<body lang="EN-US"> | ||
<h2>About This Content</h2> | ||
|
||
<p>November 30, 2017</p> | ||
<h3>License</h3> | ||
|
||
<p> | ||
The Eclipse Foundation makes available all content in this plug-in | ||
("Content"). Unless otherwise indicated below, the Content | ||
is provided to you under the terms and conditions of the Eclipse | ||
Public License Version 2.0 ("EPL"). A copy of the EPL is | ||
available at <a href="http://www.eclipse.org/legal/epl-2.0">http://www.eclipse.org/legal/epl-2.0</a>. | ||
For purposes of the EPL, "Program" will mean the Content. | ||
</p> | ||
|
||
<p> | ||
If you did not receive this Content directly from the Eclipse | ||
Foundation, the Content is being redistributed by another party | ||
("Redistributor") and different terms and conditions may | ||
apply to your use of any object code in the Content. Check the | ||
Redistributor's license that was provided with the Content. If no such | ||
license exists, contact the Redistributor. Unless otherwise indicated | ||
below, the terms and conditions of the EPL still apply to any source | ||
code in the Content and such source code may be obtained at <a | ||
href="http://www.eclipse.org/">http://www.eclipse.org</a>. | ||
</p> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
plugin.properties,\ | ||
plugin.xml,\ | ||
about.html,\ | ||
. | ||
src.includes = about.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#Properties file for org.eclipse.ui.examples.filter | ||
Bundle-Vendor = Eclipse.org | ||
Bundle-Name = Eclipse Filtered Viewer | ||
|
||
view.tree.name = Filtered Tree View | ||
view.table.name = Filtered Table View | ||
view.table.virtual.name = Filtered (Virtual) Table View |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?eclipse version="3.4"?> | ||
<plugin> | ||
<extension | ||
point="org.eclipse.ui.views"> | ||
<view | ||
class="org.eclipse.ui.examples.filter.FilteredTreeView" | ||
id="org.eclipse.ui.examples.filter.view1" | ||
name="%view.tree.name" | ||
restorable="true"> | ||
</view> | ||
<view | ||
class="org.eclipse.ui.examples.filter.FilteredTableView" | ||
id="org.eclipse.ui.examples.filter.view2" | ||
name="%view.table.name" | ||
restorable="true"> | ||
</view> | ||
<view | ||
class="org.eclipse.ui.examples.filter.FilteredVirtualTableView" | ||
id="org.eclipse.ui.examples.filter.view3" | ||
name="%view.table.virtual.name" | ||
restorable="true"> | ||
</view> | ||
</extension> | ||
|
||
</plugin> |
62 changes: 62 additions & 0 deletions
62
.../org.eclipse.ui.examples.filter/src/org/eclipse/ui/examples/filter/FilteredTableView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
******************************************************************************/ | ||
package org.eclipse.ui.examples.filter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.jface.viewers.ArrayContentProvider; | ||
import org.eclipse.jface.viewers.IContentProvider; | ||
import org.eclipse.jface.viewers.TableViewer; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.ui.dialogs.FilteredTable; | ||
import org.eclipse.ui.dialogs.PatternFilter; | ||
import org.eclipse.ui.part.ViewPart; | ||
|
||
public class FilteredTableView extends ViewPart { | ||
protected FilteredTable filter; | ||
protected TableViewer viewer; | ||
protected List<String> input; | ||
|
||
@Override | ||
public void createPartControl(Composite parent) { | ||
input = generateInput(9); | ||
filter = createFilteredTable(parent); | ||
viewer = filter.getViewer(); | ||
viewer.setContentProvider(createContentProvider()); | ||
viewer.setInput(input); | ||
} | ||
|
||
@Override | ||
public void setFocus() { | ||
viewer.getControl().setFocus(); | ||
} | ||
|
||
protected FilteredTable createFilteredTable(Composite parent) { | ||
return new FilteredTable(parent, SWT.NONE, new PatternFilter(), true, true, 500); | ||
} | ||
|
||
protected IContentProvider createContentProvider() { | ||
return ArrayContentProvider.getInstance(); | ||
} | ||
|
||
private List<String> generateInput(int size) { | ||
List<String> input = new ArrayList<>(); | ||
for (int i = 1; i <= size; ++i) { | ||
input.add(Messages.bind(Messages.FilteredTableView_Element, i)); | ||
} | ||
return input; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...s/org.eclipse.ui.examples.filter/src/org/eclipse/ui/examples/filter/FilteredTreeView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
******************************************************************************/ | ||
package org.eclipse.ui.examples.filter; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import org.eclipse.jface.viewers.ITreeContentProvider; | ||
import org.eclipse.jface.viewers.TreeViewer; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.ui.dialogs.FilteredTree; | ||
import org.eclipse.ui.dialogs.PatternFilter; | ||
import org.eclipse.ui.part.ViewPart; | ||
|
||
public class FilteredTreeView extends ViewPart { | ||
private FilteredTree filter; | ||
private TreeViewer viewer; | ||
|
||
@Override | ||
public void createPartControl(Composite parent) { | ||
filter = new FilteredTree(parent, SWT.NONE, new PatternFilter(), true, true, 500); | ||
viewer = filter.getViewer(); | ||
viewer.setContentProvider(new TreeContentProvider(9)); | ||
viewer.setInput(new Object()); | ||
viewer.expandAll(); | ||
} | ||
|
||
@Override | ||
public void setFocus() { | ||
viewer.getControl().setFocus(); | ||
} | ||
|
||
private static class TreeContentProvider implements ITreeContentProvider { | ||
private Map<String, String> elements = new TreeMap<>(); | ||
|
||
public TreeContentProvider(int size) { | ||
for (int i = 1; i <= size; ++i) { | ||
String key = Messages.bind(Messages.FilteredTreeView_Parent, i); | ||
String value = Messages.bind(Messages.FilteredTreeView_Child, i); | ||
elements.put(key, value); | ||
} | ||
} | ||
|
||
@Override | ||
public Object[] getElements(Object inputElement) { | ||
return elements.keySet().toArray(); | ||
} | ||
|
||
@Override | ||
public Object[] getChildren(Object parentElement) { | ||
if (!hasChildren(parentElement)) { | ||
return new Object[0]; | ||
} | ||
return new Object[] { elements.get(parentElement) }; | ||
} | ||
|
||
@Override | ||
public Object getParent(Object element) { | ||
for (Map.Entry<String, String> entry : elements.entrySet()) { | ||
if (entry.getValue().equals(element)) { | ||
return entry.getKey(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean hasChildren(Object element) { | ||
return elements.containsKey(element); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...lipse.ui.examples.filter/src/org/eclipse/ui/examples/filter/FilteredVirtualTableView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
******************************************************************************/ | ||
package org.eclipse.ui.examples.filter; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.core.runtime.jobs.IJobChangeEvent; | ||
import org.eclipse.core.runtime.jobs.JobChangeAdapter; | ||
import org.eclipse.jface.viewers.IContentProvider; | ||
import org.eclipse.jface.viewers.ILazyContentProvider; | ||
import org.eclipse.jface.viewers.TableViewer; | ||
import org.eclipse.jface.viewers.Viewer; | ||
import org.eclipse.jface.viewers.ViewerFilter; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.ui.dialogs.FilteredTable; | ||
import org.eclipse.ui.dialogs.PatternFilter; | ||
import org.eclipse.ui.progress.WorkbenchJob; | ||
|
||
public class FilteredVirtualTableView extends FilteredTableView { | ||
protected FilteredTable createFilteredTable(Composite parent) { | ||
return new FilteredTable(parent, SWT.VIRTUAL, new PatternFilter(), true, true, 500) { | ||
@Override | ||
protected WorkbenchJob doCreateRefreshJob() { | ||
WorkbenchJob job = super.doCreateRefreshJob(); | ||
job.addJobChangeListener(new JobChangeAdapter() { | ||
@Override | ||
public void done(IJobChangeEvent event) { | ||
if (viewer.getControl().isDisposed()) { | ||
return; | ||
} | ||
ViewerFilter filter = viewer.getFilters()[0]; | ||
Object[] newInput = filter.filter(viewer, (Object) null, input.toArray()); | ||
viewer.setInput(Arrays.asList(newInput)); | ||
} | ||
}); | ||
return job; | ||
} | ||
}; | ||
} | ||
|
||
protected IContentProvider createContentProvider() { | ||
return new ContentProvider(); | ||
} | ||
|
||
private static class ContentProvider implements ILazyContentProvider { | ||
private List<String> input; | ||
private TableViewer viewer; | ||
|
||
@Override | ||
public void updateElement(int index) { | ||
viewer.replace(input.get(index), index); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | ||
this.input = (List<String>) newInput; | ||
this.viewer = (TableViewer) viewer; | ||
this.viewer.setItemCount(input == null ? 0 : input.size()); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
examples/org.eclipse.ui.examples.filter/src/org/eclipse/ui/examples/filter/Messages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
******************************************************************************/ | ||
package org.eclipse.ui.examples.filter; | ||
|
||
import org.eclipse.osgi.util.NLS; | ||
|
||
public class Messages extends NLS { | ||
private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$ | ||
static { | ||
NLS.initializeMessages(BUNDLE_NAME, Messages.class); | ||
} | ||
|
||
public static String FilteredTableView_Element; | ||
public static String FilteredTreeView_Child; | ||
public static String FilteredTreeView_Parent; | ||
|
||
private Messages() { | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...les/org.eclipse.ui.examples.filter/src/org/eclipse/ui/examples/filter/messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FilteredTableView_Element=Element {0} | ||
FilteredTreeView_Child=Child {0} | ||
FilteredTreeView_Parent=Parent {0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...lipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/FilteredTableTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
******************************************************************************/ | ||
package org.eclipse.ui.tests.filteredtree; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.eclipse.core.runtime.jobs.IJobChangeEvent; | ||
import org.eclipse.core.runtime.jobs.JobChangeAdapter; | ||
import org.eclipse.jface.dialogs.Dialog; | ||
import org.eclipse.jface.layout.GridDataFactory; | ||
import org.eclipse.jface.tests.viewers.TestElement; | ||
import org.eclipse.jface.tests.viewers.TestModelContentProvider; | ||
import org.eclipse.jface.viewers.LabelProvider; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Control; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.dialogs.FilteredTable; | ||
import org.eclipse.ui.dialogs.PatternFilter; | ||
import org.eclipse.ui.progress.WorkbenchJob; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class FilteredTableTests { | ||
private final static int NUM_ITEMS = 8000; | ||
private TestFilteredTable tableViewer; | ||
private TestElement rootElement; | ||
|
||
@Before | ||
public void setUp() { | ||
rootElement = TestElement.createModel(1, NUM_ITEMS); | ||
} | ||
|
||
@Test | ||
public void testAddAndRemovePattern() { | ||
Dialog dialog = new FilteredTableDialog(null, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); | ||
dialog.create(); | ||
|
||
assertNotNull(tableViewer); | ||
assertEquals(tableViewer.getItemCount(), NUM_ITEMS); | ||
|
||
tableViewer.applyPattern("0-0 name-"); | ||
assertEquals(tableViewer.getItemCount(), 1); | ||
|
||
tableViewer.applyPattern("0-0 name unknownWord"); | ||
assertEquals(tableViewer.getItemCount(), 0); | ||
|
||
tableViewer.applyPattern(""); | ||
assertEquals(tableViewer.getItemCount(), NUM_ITEMS); | ||
|
||
dialog.close(); | ||
} | ||
|
||
private class TestFilteredTable extends FilteredTable { | ||
private boolean jobScheduled; | ||
|
||
public TestFilteredTable(Composite parent, int style) { | ||
super(parent, style, new PatternFilter(), true, true, 0); | ||
} | ||
|
||
public int getItemCount() { | ||
return getViewer().getTable().getItemCount(); | ||
} | ||
|
||
public void applyPattern(String pattern) { | ||
setFilterText(pattern); | ||
textChanged(); | ||
|
||
while (jobScheduled) { | ||
getDisplay().readAndDispatch(); | ||
} | ||
} | ||
|
||
@Override | ||
protected WorkbenchJob doCreateRefreshJob() { | ||
WorkbenchJob job = super.doCreateRefreshJob(); | ||
job.addJobChangeListener(new JobChangeAdapter() { | ||
@Override | ||
public void scheduled(IJobChangeEvent event) { | ||
jobScheduled = true; | ||
} | ||
|
||
@Override | ||
public void done(IJobChangeEvent event) { | ||
if (event.getResult().isOK()) { | ||
jobScheduled = false; | ||
} | ||
} | ||
}); | ||
return job; | ||
} | ||
} | ||
|
||
|
||
private class FilteredTableDialog extends Dialog { | ||
private final int style; | ||
|
||
public FilteredTableDialog(Shell shell, int tableStyle) { | ||
super(shell); | ||
style = tableStyle; | ||
} | ||
|
||
@Override | ||
protected Control createContents(Composite parent) { | ||
Composite composite = new Composite(parent, SWT.NONE); | ||
composite.setLayout(new GridLayout()); | ||
|
||
tableViewer = new TestFilteredTable(composite, style); | ||
tableViewer.setLayoutData(GridDataFactory.fillDefaults().hint(400, 500).create()); | ||
tableViewer.getViewer().setContentProvider(new TestModelContentProvider()); | ||
tableViewer.getViewer().setLabelProvider(new LabelProvider()); | ||
tableViewer.getViewer().setUseHashlookup(true); | ||
tableViewer.getViewer().setInput(rootElement); | ||
return parent; | ||
} | ||
} | ||
} |