Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor;
Expand All @@ -42,11 +41,13 @@ public class TmfTreeModelTest {
private static final String TOOLTIP_PREFIX = "tooltip";
private static final String LABEL_PREFIX = "label";
private static final String TEST_SCOPE = "scope";
private static List<@NonNull ITmfTreeDataModel> fTestEntries = new ArrayList<>();
private static List<@NonNull String> fTestHeaders = new ArrayList<>();
private static List<@NonNull String> fExpectedEmptyTooltips = new ArrayList<>();
private static List<@NonNull String> fExpectedTooltips = new ArrayList<>();
private static List<@NonNull ITableColumnDescriptor> fTestDescriptors = new ArrayList<>();
private static final int ALL_LEVELS = -1;
private static final int TEST_LEVEL = 1;
private static List<ITmfTreeDataModel> fTestEntries = new ArrayList<>();
private static List<String> fTestHeaders = new ArrayList<>();
private static List<String> fExpectedEmptyTooltips = new ArrayList<>();
private static List<String> fExpectedTooltips = new ArrayList<>();
private static List<ITableColumnDescriptor> fTestDescriptors = new ArrayList<>();

/**
* Run once
Expand Down Expand Up @@ -82,14 +83,14 @@ public static void initClass() {
*/
@Test
public void testTmfTreeModelConstructor() {
TmfTreeModel<@NonNull ITmfTreeDataModel> testInstance = new TmfTreeModel<>(fTestHeaders, fTestEntries);
verifyInstance(testInstance, fExpectedEmptyTooltips, null);
TmfTreeModel<ITmfTreeDataModel> testInstance = new TmfTreeModel<>(fTestHeaders, fTestEntries);
verifyInstance(testInstance, fExpectedEmptyTooltips, null, ALL_LEVELS);

testInstance = new TmfTreeModel<>(fTestHeaders, fTestEntries, TEST_SCOPE);
verifyInstance(testInstance, fExpectedEmptyTooltips, TEST_SCOPE);
verifyInstance(testInstance, fExpectedEmptyTooltips, TEST_SCOPE, ALL_LEVELS);
}

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

Expand All @@ -102,6 +103,7 @@ private static void verifyInstance(TmfTreeModel<@NonNull ITmfTreeDataModel> test
assertEquals("Incorrect Collumn descriptor header tooltip", tooltips.get(i), columnDescriptors.get(i).getTooltip());
}
assertEquals("Incorrect scope", scope, testInstance.getScope());
assertEquals("Incorrect autoExpandLevel", autoExpandLevel, testInstance.getAutoExpandLevel());
}

/**
Expand All @@ -110,16 +112,20 @@ private static void verifyInstance(TmfTreeModel<@NonNull ITmfTreeDataModel> test
@SuppressWarnings("javadoc")
@Test
public void testTmfTreeModelConstructor2() {
TmfTreeModel.Builder<@NonNull ITmfTreeDataModel> builder = new TmfTreeModel.Builder<>();
TmfTreeModel.Builder<ITmfTreeDataModel> builder = new TmfTreeModel.Builder<>();
builder.setColumnDescriptors(fTestDescriptors).setEntries(fTestEntries);
TmfTreeModel<@NonNull ITmfTreeDataModel> testInstance = builder.build();
verifyInstance(testInstance, fExpectedTooltips, null);
TmfTreeModel<ITmfTreeDataModel> testInstance = builder.build();
verifyInstance(testInstance, fExpectedTooltips, null, ALL_LEVELS);

builder = new TmfTreeModel.Builder<>();
builder.setColumnDescriptors(fTestDescriptors).setEntries(fTestEntries).setScope(TEST_SCOPE);
testInstance = builder.build();
verifyInstance(testInstance, fExpectedTooltips, TEST_SCOPE, ALL_LEVELS);

builder = new TmfTreeModel.Builder<>();
builder.setColumnDescriptors(fTestDescriptors).setEntries(fTestEntries).setScope(TEST_SCOPE).setAutoExpandLevel(TEST_LEVEL);
testInstance = builder.build();
verifyInstance(testInstance, fExpectedTooltips, TEST_SCOPE);
verifyInstance(testInstance, fExpectedTooltips, TEST_SCOPE, TEST_LEVEL);

builder = new TmfTreeModel.Builder<>();
testInstance = builder.build();
Expand Down
2 changes: 1 addition & 1 deletion tmf/org.eclipse.tracecompass.tmf.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Version: 10.0.0.qualifier
Bundle-Version: 10.1.0.qualifier
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tracecompass.tmf.core;singleton:=true
Bundle-Activator: org.eclipse.tracecompass.internal.tmf.core.Activator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2017, 2021 Ericsson
* Copyright (c) 2017, 2025 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -106,6 +106,7 @@ public TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchPara
boolean isComplete = true;
List<Entry<M, Object>> entries = new ArrayList<>();
List<ITableColumnDescriptor> columnDescriptor = null;
int autoExpandLevel = TmfTreeModel.ALL_LEVELS;

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

if (isComplete) {
return new TmfModelResponse<>(treeModelBuilder.build(), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2019 Ericsson
* Copyright (c) 2019, 2025 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -31,11 +31,24 @@
* @since 5.0
*/
public class TmfTreeModel<T extends ITmfTreeDataModel> {

/**
* Expand level to indicate that all tree levels are expanded. (default)
*
* @since 10.1
*/
public static final int ALL_LEVELS = -1;

private List<String> fHeaders;
private List<ITableColumnDescriptor> fColumnDescriptors;
private List<T> fEntries;
private @Nullable String fScope;

/**
* Indicates which level of the tree should be expanded.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the comment to:

   /**
    *  Indicates which level of the tree should be expanded. 
    */

The more detail information

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

private int fAutoExpandLevel = ALL_LEVELS;

/**
* Constructor
*
Expand Down Expand Up @@ -88,6 +101,7 @@ private TmfTreeModel(Builder<T> builder) {
fColumnDescriptors = builder.fColumnDescriptors;
fEntries = builder.fEntries;
fScope = builder.fScope;
fAutoExpandLevel = builder.fAutoExpandLevel;
}

/**
Expand Down Expand Up @@ -118,6 +132,36 @@ public List<T> getEntries() {
return fScope;
}

/**
* Returns the auto-expand level.
*
* @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
* the tree are expanded automatically
* @see #setAutoExpandLevel
* @since 10.1
*/
public int getAutoExpandLevel() {
return fAutoExpandLevel;
}

/**
* Sets the auto-expand level 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.
* <p>
* The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
* </p>
*
* @param autoExpandLevel
* The auto expand level to set
* @since 10.1
*/
public void setAutoExpandLevel(int autoExpandLevel) {
this.fAutoExpandLevel = autoExpandLevel;
}

/**
*
* A builder class to build instances implementing interface
Expand All @@ -131,6 +175,7 @@ public static class Builder<T extends ITmfTreeDataModel> {
private List<ITableColumnDescriptor> fColumnDescriptors = new ArrayList<>();
private List<T> fEntries;
private @Nullable String fScope;
private int fAutoExpandLevel = ALL_LEVELS;

/**
* Constructor
Expand Down Expand Up @@ -175,6 +220,20 @@ public Builder<T> setScope(String scope) {
return this;
}

/**
* Sets which level of the tree should be expanded
*
* @param autoExpandLevel
* expand level of the tree model
* @return this {@link Builder} object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add @since 9.6

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* @see TmfTreeModel#setAutoExpandLevel(int)
* @since 10.1
*/
public Builder<T> setAutoExpandLevel(int autoExpandLevel) {
fAutoExpandLevel = autoExpandLevel;
return this;
}

/**
* The method to construct an instance of {@link TmfTreeModel}
*
Expand Down
Loading