Skip to content

Commit 837c7da

Browse files
hriday-panchasarabhufmann
authored andcommitted
tmf: Add auto-expand level in TmfTreeModel
The auto-expand level is supposed to be used for the input of the tree. The value 0 means that there is no auto-expand; 1 means that top-level elements are expanded, but not their children; 2 means that top-level elements are expanded, and their children, but not grand-children; and so on. The value -1 means that all subtrees should be expanded (default). [Added] Add auto-expand level in TmfTreeModel Signed-off-by: Hriday Panchasara [email protected] Signed-off-by: Bernd Hufmann <[email protected]>
1 parent 2ac0ff3 commit 837c7da

File tree

4 files changed

+80
-10
lines changed

4 files changed

+80
-10
lines changed

tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/model/tree/TmfTreeModelTest.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************
2-
* Copyright (c) 2020, 2025 Ericsson
2+
* Copyright (c) 2020 Ericsson
33
*
44
* All rights reserved. This program and the accompanying materials are
55
* made available under the terms of the Eclipse Public License 2.0 which
@@ -41,6 +41,8 @@ public class TmfTreeModelTest {
4141
private static final String TOOLTIP_PREFIX = "tooltip";
4242
private static final String LABEL_PREFIX = "label";
4343
private static final String TEST_SCOPE = "scope";
44+
private static final int ALL_LEVELS = -1;
45+
private static final int TEST_LEVEL = 1;
4446
private static List<ITmfTreeDataModel> fTestEntries = new ArrayList<>();
4547
private static List<String> fTestHeaders = new ArrayList<>();
4648
private static List<String> fExpectedEmptyTooltips = new ArrayList<>();
@@ -82,13 +84,13 @@ public static void initClass() {
8284
@Test
8385
public void testTmfTreeModelConstructor() {
8486
TmfTreeModel<ITmfTreeDataModel> testInstance = new TmfTreeModel<>(fTestHeaders, fTestEntries);
85-
verifyInstance(testInstance, fExpectedEmptyTooltips, null);
87+
verifyInstance(testInstance, fExpectedEmptyTooltips, null, ALL_LEVELS);
8688

8789
testInstance = new TmfTreeModel<>(fTestHeaders, fTestEntries, TEST_SCOPE);
88-
verifyInstance(testInstance, fExpectedEmptyTooltips, TEST_SCOPE);
90+
verifyInstance(testInstance, fExpectedEmptyTooltips, TEST_SCOPE, ALL_LEVELS);
8991
}
9092

91-
private static void verifyInstance(TmfTreeModel<ITmfTreeDataModel> testInstance, List<String> tooltips, @Nullable String scope) {
93+
private static void verifyInstance(TmfTreeModel<ITmfTreeDataModel> testInstance, List<String> tooltips, @Nullable String scope, int autoExpandLevel) {
9294
assertEquals("Incorrect list of entries", fTestEntries, testInstance.getEntries());
9395
assertEquals("Incorrect list of entries", fTestHeaders, testInstance.getHeaders());
9496

@@ -101,6 +103,7 @@ private static void verifyInstance(TmfTreeModel<ITmfTreeDataModel> testInstance,
101103
assertEquals("Incorrect Collumn descriptor header tooltip", tooltips.get(i), columnDescriptors.get(i).getTooltip());
102104
}
103105
assertEquals("Incorrect scope", scope, testInstance.getScope());
106+
assertEquals("Incorrect autoExpandLevel", autoExpandLevel, testInstance.getAutoExpandLevel());
104107
}
105108

106109
/**
@@ -112,13 +115,17 @@ public void testTmfTreeModelConstructor2() {
112115
TmfTreeModel.Builder<ITmfTreeDataModel> builder = new TmfTreeModel.Builder<>();
113116
builder.setColumnDescriptors(fTestDescriptors).setEntries(fTestEntries);
114117
TmfTreeModel<ITmfTreeDataModel> testInstance = builder.build();
115-
verifyInstance(testInstance, fExpectedTooltips, null);
118+
verifyInstance(testInstance, fExpectedTooltips, null, ALL_LEVELS);
116119

117120
builder = new TmfTreeModel.Builder<>();
118121
builder.setColumnDescriptors(fTestDescriptors).setEntries(fTestEntries).setScope(TEST_SCOPE);
122+
testInstance = builder.build();
123+
verifyInstance(testInstance, fExpectedTooltips, TEST_SCOPE, ALL_LEVELS);
119124

125+
builder = new TmfTreeModel.Builder<>();
126+
builder.setColumnDescriptors(fTestDescriptors).setEntries(fTestEntries).setScope(TEST_SCOPE).setAutoExpandLevel(TEST_LEVEL);
120127
testInstance = builder.build();
121-
verifyInstance(testInstance, fExpectedTooltips, TEST_SCOPE);
128+
verifyInstance(testInstance, fExpectedTooltips, TEST_SCOPE, TEST_LEVEL);
122129

123130
builder = new TmfTreeModel.Builder<>();
124131
testInstance = builder.build();

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

Lines changed: 1 addition & 1 deletion
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: 10.0.0.qualifier
5+
Bundle-Version: 10.1.0.qualifier
66
Bundle-Localization: plugin
77
Bundle-SymbolicName: org.eclipse.tracecompass.tmf.core;singleton:=true
88
Bundle-Activator: org.eclipse.tracecompass.internal.tmf.core.Activator

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/model/tree/TmfTreeCompositeDataProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************
2-
* Copyright (c) 2017, 2021 Ericsson
2+
* Copyright (c) 2017, 2025 Ericsson
33
*
44
* All rights reserved. This program and the accompanying materials are
55
* made available under the terms of the Eclipse Public License 2.0 which
@@ -106,6 +106,7 @@ public TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchPara
106106
boolean isComplete = true;
107107
List<Entry<M, Object>> entries = new ArrayList<>();
108108
List<ITableColumnDescriptor> columnDescriptor = null;
109+
int autoExpandLevel = TmfTreeModel.ALL_LEVELS;
109110

110111
Table<Object, Long, @NonNull M> scopedEntries = HashBasedTable.create();
111112
for (P dataProvider : fProviders) {
@@ -155,6 +156,8 @@ public TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchPara
155156
if (columnDescriptor == null) {
156157
columnDescriptor = model.getColumnDescriptors();
157158
}
159+
// All autoExpandLevel are supposed to be the same
160+
autoExpandLevel = model.getAutoExpandLevel();
158161
}
159162
if (monitor != null && monitor.isCanceled()) {
160163
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
@@ -166,7 +169,8 @@ public TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchPara
166169
columnDescriptor = Collections.emptyList();
167170
}
168171
treeModelBuilder.setColumnDescriptors(columnDescriptor)
169-
.setEntries(Lists.transform(entries, e -> e.getKey()));
172+
.setEntries(Lists.transform(entries, e -> e.getKey()))
173+
.setAutoExpandLevel(autoExpandLevel);
170174

171175
if (isComplete) {
172176
return new TmfModelResponse<>(treeModelBuilder.build(), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/model/tree/TmfTreeModel.java

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************
2-
* Copyright (c) 2019 Ericsson
2+
* Copyright (c) 2019, 2025 Ericsson
33
*
44
* All rights reserved. This program and the accompanying materials are
55
* made available under the terms of the Eclipse Public License 2.0 which
@@ -31,11 +31,24 @@
3131
* @since 5.0
3232
*/
3333
public class TmfTreeModel<T extends ITmfTreeDataModel> {
34+
35+
/**
36+
* Expand level to indicate that all tree levels are expanded. (default)
37+
*
38+
* @since 10.1
39+
*/
40+
public static final int ALL_LEVELS = -1;
41+
3442
private List<String> fHeaders;
3543
private List<ITableColumnDescriptor> fColumnDescriptors;
3644
private List<T> fEntries;
3745
private @Nullable String fScope;
3846

47+
/**
48+
* Indicates which level of the tree should be expanded.
49+
*/
50+
private int fAutoExpandLevel = ALL_LEVELS;
51+
3952
/**
4053
* Constructor
4154
*
@@ -88,6 +101,7 @@ private TmfTreeModel(Builder<T> builder) {
88101
fColumnDescriptors = builder.fColumnDescriptors;
89102
fEntries = builder.fEntries;
90103
fScope = builder.fScope;
104+
fAutoExpandLevel = builder.fAutoExpandLevel;
91105
}
92106

93107
/**
@@ -118,6 +132,36 @@ public List<T> getEntries() {
118132
return fScope;
119133
}
120134

135+
/**
136+
* Returns the auto-expand level.
137+
*
138+
* @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
139+
* the tree are expanded automatically
140+
* @see #setAutoExpandLevel
141+
* @since 10.1
142+
*/
143+
public int getAutoExpandLevel() {
144+
return fAutoExpandLevel;
145+
}
146+
147+
/**
148+
* Sets the auto-expand level to be used for the input of the tree. The
149+
* value 0 means that there is no auto-expand; 1 means that top-level
150+
* elements are expanded, but not their children; 2 means that top-level
151+
* elements are expanded, and their children, but not grand-children; and so
152+
* on.
153+
* <p>
154+
* The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
155+
* </p>
156+
*
157+
* @param autoExpandLevel
158+
* The auto expand level to set
159+
* @since 10.1
160+
*/
161+
public void setAutoExpandLevel(int autoExpandLevel) {
162+
this.fAutoExpandLevel = autoExpandLevel;
163+
}
164+
121165
/**
122166
*
123167
* A builder class to build instances implementing interface
@@ -131,6 +175,7 @@ public static class Builder<T extends ITmfTreeDataModel> {
131175
private List<ITableColumnDescriptor> fColumnDescriptors = new ArrayList<>();
132176
private List<T> fEntries;
133177
private @Nullable String fScope;
178+
private int fAutoExpandLevel = ALL_LEVELS;
134179

135180
/**
136181
* Constructor
@@ -175,6 +220,20 @@ public Builder<T> setScope(String scope) {
175220
return this;
176221
}
177222

223+
/**
224+
* Sets which level of the tree should be expanded
225+
*
226+
* @param autoExpandLevel
227+
* expand level of the tree model
228+
* @return this {@link Builder} object
229+
* @see TmfTreeModel#setAutoExpandLevel(int)
230+
* @since 10.1
231+
*/
232+
public Builder<T> setAutoExpandLevel(int autoExpandLevel) {
233+
fAutoExpandLevel = autoExpandLevel;
234+
return this;
235+
}
236+
178237
/**
179238
* The method to construct an instance of {@link TmfTreeModel}
180239
*

0 commit comments

Comments
 (0)