@Override
public Object[] getElements(Object inputElement) {
- if (inputElement != null) {
- try {
- return ((List<?>) inputElement).toArray(new ITmfTreeViewerEntry[0]);
- } catch (ClassCastException e) {
- }
+ if (inputElement instanceof ITmfTreeViewerEntry) {
+ return ((ITmfTreeViewerEntry) inputElement).getChildren().toArray(new ITmfTreeViewerEntry[0]);
}
return new ITmfTreeViewerEntry[0];
}
Thread thread = new Thread() {
@Override
public void run() {
- final List<ITmfTreeViewerEntry> entries = updateElements(start, end, isSelection);
+ final ITmfTreeViewerEntry rootEntry = updateElements(start, end, isSelection);
/* Set the input in main thread only if it didn't change */
- if (entries != null) {
+ if (rootEntry != null) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- if (entries != fTreeViewer.getInput()) {
- fTreeViewer.setInput(entries);
+ if (rootEntry != fTreeViewer.getInput()) {
+ fTreeViewer.setInput(rootEntry);
} else {
fTreeViewer.refresh();
}
/**
* Update the entries to the given start/end time. An extra parameter
* defines whether these times correspond to the selection or the visible
- * range, as the viewer may update differently in those cases. If no update
- * is necessary, the method should return <code>null</code>. To empty the
- * tree, an empty list should be returned.
+ * range, as the viewer may update differently in those cases. This methods
+ * returns a root node that is not meant to be visible. The children of this
+ * 'fake' root node are the first level of entries that will appear in the
+ * tree. If no update is necessary, the method should return
+ * <code>null</code>. To empty the tree, a root node containing an empty
+ * list of children should be returned.
*
* This method is not called in the UI thread when using the default viewer
* content update. Resource-intensive calculations here should not block the
* @param isSelection
* <code>true</code> if this time range is for a selection,
* <code>false</code> for the visible time range
- * @return The list of entries to display or <code>null</code> if no update
- * necessary
+ * @return The root entry of the list of entries to display or
+ * <code>null</code> if no update necessary
*/
- protected abstract List<ITmfTreeViewerEntry> updateElements(long start, long end, boolean isSelection);
+ protected abstract ITmfTreeViewerEntry updateElements(long start, long end, boolean isSelection);
/**
* Get the current input displayed by the viewer
*
- * @return The input of the tree viewer
+ * @return The input of the tree viewer, the root entry
*/
- protected Object getInput() {
- return fTreeViewer.getInput();
+ protected ITmfTreeViewerEntry getInput() {
+ return (ITmfTreeViewerEntry) fTreeViewer.getInput();
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
@Override
- protected List<ITmfTreeViewerEntry> updateElements(long start, long end, boolean selection) {
+ protected ITmfTreeViewerEntry updateElements(long start, long end, boolean selection) {
if (getTrace() == null) {
return null;
}
- List<ITmfTreeViewerEntry> entries = (List<ITmfTreeViewerEntry>) getInput();
+ ITmfTreeViewerEntry root = getInput();
- if ((!selection) && (entries != null)) {
+ if ((!selection) && (root != null)) {
return null;
}
* Build the entries if it is the first time or to show only modified
* values
*/
- if (entries == null || fFilterStatus) {
- entries = buildEntriesList(start);
- } else {
+ if (root == null || fFilterStatus) {
+ root = buildEntries(start);
+ } else if (root instanceof TmfTreeViewerEntry) {
/*
* Update the values of the elements of the state systems at time
* 'start'
*/
- entries = updateEntriesList(entries, start);
+ updateEntriesList(((TmfTreeViewerEntry)root).getChildren(), start);
}
- return entries;
+ return root;
}
- private List<ITmfTreeViewerEntry> buildEntriesList(long timestamp) {
- List<ITmfTreeViewerEntry> rootEntries = new ArrayList<>();
+ private ITmfTreeViewerEntry buildEntries(long timestamp) {
+ // 'Fake' root node
+ TmfTreeViewerEntry rootEntry = new TmfTreeViewerEntry(""); //$NON-NLS-1$
+
+ List<ITmfTreeViewerEntry> children = rootEntry.getChildren();
for (final ITmfTrace currentTrace : TmfTraceManager.getTraceSet(getTrace())) {
if (currentTrace == null) {
continue;
}
- buildEntriesForTrace(currentTrace, timestamp, rootEntries);
+ buildEntriesForTrace(currentTrace, timestamp, children);
}
- return rootEntries;
+ return rootEntry;
}
/*
* Update the values of the entries. It will also create trace and state
* system entries if they do not exist yet.
*/
- private List<ITmfTreeViewerEntry> updateEntriesList(List<ITmfTreeViewerEntry> entries, long timestamp) {
+ private void updateEntriesList(List<ITmfTreeViewerEntry> entries, long timestamp) {
for (final ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
if (trace == null) {
continue;
}
}
}
- return entries;
}
@NonNull