Skip to content

Commit 667b23e

Browse files
committed
tmf.ui: make AbstractSelectTreeViewer2 injectable; add AbstractSelectTreeViewer3 and MultiTreePatternFilter2 for column-aware filtering
Signed-off-by: Hong Anh <[email protected]>
1 parent 7f88866 commit 667b23e

File tree

5 files changed

+112
-6
lines changed

5 files changed

+112
-6
lines changed

tmf/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-Vendor: %Bundle-Vendor
5-
Bundle-Version: 9.1.2.qualifier
5+
Bundle-Version: 9.2.0
66
Bundle-Localization: plugin
77
Bundle-SymbolicName: org.eclipse.tracecompass.tmf.ui;singleton:=true
88
Bundle-Activator: org.eclipse.tracecompass.internal.tmf.ui.Activator
@@ -30,7 +30,9 @@ Require-Bundle: org.eclipse.core.expressions,
3030
org.eclipse.tracecompass.tmf.filter.parser,
3131
org.eclipse.e4.ui.css.swt.theme,
3232
org.eclipse.ui.themes,
33-
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional
33+
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional,
34+
org.eclipse.equinox.p2.ui;bundle-version="2.8.500",
35+
org.eclipse.ui.browser;bundle-version="3.8.300"
3436
Export-Package: org.eclipse.tracecompass.internal.provisional.tmf.ui.model;x-internal:=true,
3537
org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart;x-internal:=true,
3638
org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets;x-friends:="org.eclipse.tracecompass.analysis.timing.ui",
@@ -151,5 +153,5 @@ Import-Package: com.google.common.annotations,
151153
org.apache.commons.io,
152154
org.eclipse.emf.common.util,
153155
org.eclipse.emf.ecore,
154-
org.eclipse.tracecompass.traceeventlogger
156+
org.eclipse.tracecompass.traceeventlogger;resolution:=optional
155157
Automatic-Module-Name: org.eclipse.tracecompass.tmf.ui

tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/tree/AbstractSelectTreeViewer2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public String getColumnText(Object element, int columnIndex) {
220220
* @param legendColumnIndex
221221
* index of the legend column (-1 if none)
222222
*/
223-
private AbstractSelectTreeViewer2(Composite parent, TriStateFilteredCheckboxTree checkboxTree,
223+
protected AbstractSelectTreeViewer2(Composite parent, TriStateFilteredCheckboxTree checkboxTree,
224224
int legendIndex, String id) {
225225
super(parent, checkboxTree.getViewer());
226226

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017, 2025 Ericsson, Draeger Auriga
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
11+
12+
package org.eclipse.tracecompass.tmf.ui.viewers.tree;
13+
14+
import org.eclipse.swt.SWT;
15+
import org.eclipse.swt.widgets.Composite;
16+
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider;
17+
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.dialogs.SpecificColumnPatternFilter;
18+
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.dialogs.TriStateFilteredCheckboxTree;
19+
20+
/**
21+
* An abstract tree viewer that supports selection with filtering capabilities.
22+
*
23+
* This viewer extends
24+
* {@link AbstractSelectTreeViewer2}
25+
* to allow filtering based on a specific column index.
26+
*
27+
* @author Hong Anh
28+
* @since 9.2
29+
*/
30+
public abstract class AbstractSelectTreeViewer3 extends AbstractSelectTreeViewer2 {
31+
/**
32+
* Constructor
33+
*
34+
* @param parent
35+
* Parent composite
36+
* @param legendIndex
37+
* index of the legend column (-1 if none)
38+
* @param id
39+
* {@link ITmfTreeDataProvider} ID
40+
* @param indexColumnFilter
41+
* the index of the column to apply the filter on
42+
*/
43+
public AbstractSelectTreeViewer3(Composite parent, int legendIndex, String id, int indexColumnFilter) {
44+
// Initialize the tree viewer with a filtered checkbox tree and column-based filtering
45+
super(parent, new TriStateFilteredCheckboxTree(parent,
46+
SWT.MULTI | SWT.H_SCROLL | SWT.FULL_SELECTION,
47+
new SpecificColumnPatternFilter(indexColumnFilter), true, false), legendIndex, id);
48+
}
49+
}

tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/dialogs/MultiTreePatternFilter.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ protected boolean isLeafMatch(Viewer viewer, Object element) {
7474

7575
// Ensure the tree element and its parent(s) match the filter text
7676
for (Predicate<String> p : fPredicates) {
77-
// Retrieve tree element text and make verification. Text is at column 0
78-
String labelText = labelProvider.getColumnText(node, 0);
77+
// Get the text of the element in the specified column and verify against the predicate
78+
String labelText = labelProvider.getColumnText(node, this.getIndexColumnFilter());
7979
if (labelText == null || !p.test(labelText)) {
8080
return false;
8181
}
@@ -85,4 +85,13 @@ protected boolean isLeafMatch(Viewer viewer, Object element) {
8585
}
8686
return true;
8787
}
88+
89+
/**
90+
* Returns the index of the column used for filtering.
91+
* @return the column index (default is 0)
92+
* @since 9.2
93+
*/
94+
protected int getIndexColumnFilter() {
95+
return 0;
96+
}
8897
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Ericsson
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
11+
12+
package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.dialogs;
13+
14+
15+
/**
16+
* A filter that extends {@link MultiTreePatternFilter} to allow filtering
17+
* based on a specific column index.
18+
*
19+
* This implementation enables users to apply multiple patterns (separated by '/')
20+
* while specifying which column of the tree should be used for matching.
21+
*
22+
* @author Hong Anh
23+
* @since 9.2
24+
*/
25+
26+
public class SpecificColumnPatternFilter extends MultiTreePatternFilter {
27+
private int index = 0;
28+
29+
/**
30+
* Creates a new filter with the specified column index.
31+
* @param indexColumnFilter the index of the column to apply the filter on
32+
*/
33+
34+
public SpecificColumnPatternFilter(int indexColumnFilter) {
35+
this.index = indexColumnFilter;
36+
}
37+
38+
/**
39+
* Returns the index of the column used for filtering.
40+
* @return the column index specified during construction
41+
*/
42+
@Override
43+
protected int getIndexColumnFilter() {
44+
return this.index;
45+
}
46+
}

0 commit comments

Comments
 (0)