tmf: Fix Unsafe cast error when targetting Luna
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 4 Mar 2014 18:06:17 +0000 (13:06 -0500)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Mon, 10 Mar 2014 14:05:53 +0000 (10:05 -0400)
Change-Id: Iaeeaec5f5ee20c640084b84108bfabc3b48aff6a
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/22878
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
IP-Clean: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/tree/AbstractTmfTreeViewer.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/tree/ITmfTreeViewerEntry.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/tree/TmfTreeViewerEntry.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemViewer.java

index 99dc1639442079d2b6fcdb7c03c877f42c89f611..9a21b5f046ff8530633068c2c4dc810a6ed3995e 100644 (file)
@@ -73,11 +73,8 @@ public abstract class AbstractTmfTreeViewer extends TmfTimeViewer {
 
         @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];
         }
@@ -381,14 +378,14 @@ public abstract class AbstractTmfTreeViewer extends TmfTimeViewer {
         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();
                             }
@@ -407,9 +404,12 @@ public abstract class AbstractTmfTreeViewer extends TmfTimeViewer {
     /**
      * 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
@@ -422,18 +422,18 @@ public abstract class AbstractTmfTreeViewer extends TmfTimeViewer {
      * @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();
     }
 
     // ------------------------------------------------------------------------
index 7abe667484be2ad90eba3794316566cc9db54574..11e5b7af673fd2619963bd78989cb042399a7cdf 100644 (file)
@@ -14,6 +14,8 @@ package org.eclipse.linuxtools.tmf.ui.viewers.tree;
 
 import java.util.List;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * Interface for an entry (row) in a TMF tree viewer
  *
@@ -42,6 +44,7 @@ public interface ITmfTreeViewerEntry {
      *
      * @return an array of child elements
      */
+    @NonNull
     List<? extends ITmfTreeViewerEntry> getChildren();
 
     /**
index b79ae72b7370760c91a52a83ed380bd17f7dbd15..e5e07434606a7c86dcc92d24ab79136931fb51aa 100644 (file)
@@ -15,6 +15,8 @@ package org.eclipse.linuxtools.tmf.ui.viewers.tree;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * Basic implementation of an entry for the TMF tree viewer. A name is all that is needed for this entry.
  *
@@ -27,6 +29,7 @@ public class TmfTreeViewerEntry implements ITmfTreeViewerEntry {
     private ITmfTreeViewerEntry fParent = null;
 
     /** List of child entries */
+    @NonNull
     private final List<ITmfTreeViewerEntry> fChildren = new CopyOnWriteArrayList<>();
 
     /** Name of this entry (default text to show in first column) */
index 34f8fbeb81836f87e101c37a45789fc64a7a2415..e63e0417f0e643fcf1f380b85dc83404e92a0950 100644 (file)
@@ -160,14 +160,14 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
     // ------------------------------------------------------------------------
 
     @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;
         }
 
@@ -175,35 +175,38 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
          * 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;
@@ -253,7 +256,6 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
                 }
             }
         }
-        return entries;
     }
 
     @NonNull
This page took 0.035822 seconds and 5 git commands to generate.