tmf: Add filtering and highlighting to the State System Explorer
authorFlorian Wininger <florian.wininger@polymtl.ca>
Wed, 22 May 2013 23:14:44 +0000 (19:14 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 9 Jul 2013 18:55:29 +0000 (14:55 -0400)
Highlight on state changes.
Add a filter button to filter out non-changes completely.
Add a column with the value's type.

Change-Id: I0d206ef15e84707d9556c609ca86eda606689ff1
Signed-off-by: Florian Wininger <florian.wininger@polymtl.ca>
Reviewed-on: https://git.eclipse.org/r/13366
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/Messages.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemExplorer.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/messages.properties

index 7746870295b3b3d0defc9073a8f7466501e5f10d..add80d906e39b9f76f2ff6bc307c2501c3679506 100644 (file)
@@ -45,6 +45,10 @@ public class Messages extends NLS {
     /** Label for the "value" column */
     public static String ValueColumnLabel;
 
+    /** Label for the "type" column
+     * @since 2.1*/
+    public static String TypeColumnLabel;
+
     /** Label for the "start time" column */
     public static String StartTimeColumLabel;
 
@@ -59,4 +63,20 @@ public class Messages extends NLS {
      * outside of the SS's range.
      */
     public static String OutOfRangeMsg;
+
+    /** Label for the Filter button
+     * @since 2.1*/
+    public static String FilterButton;
+
+    /** Label for the type Interger
+     * @since 2.1*/
+    public static String TypeInteger;
+
+    /** Label for the type Long
+     * @since 2.1*/
+    public static String TypeLong;
+
+    /** Label for the type String
+     * @since 2.1*/
+    public static String TypeString;
 }
index 126e0fc623735cab08b185cc4cf489f75cd6db66..f40f33f129ac66b53013730b560277831ab52e76 100644 (file)
 
 package org.eclipse.linuxtools.tmf.ui.views.statesystem;
 
+import java.io.File;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
@@ -36,12 +41,15 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Tree;
 import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IActionBars;
 
 /**
  * Displays the State System at a current time.
@@ -56,19 +64,25 @@ public class TmfStateSystemExplorer extends TmfView {
     public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.ssview"; //$NON-NLS-1$
 
     private static final String emptyString = ""; //$NON-NLS-1$
+    private static final String FS = File.separator;
+    private static final Image FILTER_IMAGE =
+            Activator.getDefault().getImageFromPath(FS + "icons" + FS + "elcl16" + FS + "filter_items.gif"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
     /* Order of columns */
     private static final int ATTRIBUTE_NAME_COL = 0;
     private static final int QUARK_COL = 1;
     private static final int VALUE_COL = 2;
-    private static final int START_TIME_COL = 3;
-    private static final int END_TIME_COL = 4;
-    private static final int ATTRIBUTE_FULLPATH_COL = 5;
+    private static final int TYPE_COL = 3;
+    private static final int START_TIME_COL = 4;
+    private static final int END_TIME_COL = 5;
+    private static final int ATTRIBUTE_FULLPATH_COL = 6;
 
     private ITmfTrace fTrace;
     private Tree fTree;
     private volatile long fCurrentTimestamp = -1L;
 
+    private boolean filterStatus = false ;
+
     /**
      * Default constructor
      */
@@ -86,6 +100,7 @@ public class TmfStateSystemExplorer extends TmfView {
         TreeColumn nameCol = new TreeColumn(fTree, SWT.NONE, ATTRIBUTE_NAME_COL);
         TreeColumn quarkCol = new TreeColumn(fTree, SWT.NONE, QUARK_COL);
         TreeColumn valueCol = new TreeColumn(fTree, SWT.NONE, VALUE_COL);
+        TreeColumn typeCol = new TreeColumn(fTree, SWT.NONE, TYPE_COL);
         TreeColumn startCol = new TreeColumn(fTree, SWT.NONE, START_TIME_COL);
         TreeColumn endCol = new TreeColumn(fTree, SWT.NONE, END_TIME_COL);
         TreeColumn pathCol = new TreeColumn(fTree, SWT.NONE, ATTRIBUTE_FULLPATH_COL);
@@ -93,6 +108,7 @@ public class TmfStateSystemExplorer extends TmfView {
         nameCol.setText(Messages.TreeNodeColumnLabel);
         quarkCol.setText(Messages.QuarkColumnLabel);
         valueCol.setText(Messages.ValueColumnLabel);
+        typeCol.setText(Messages.TypeColumnLabel);
         startCol.setText(Messages.StartTimeColumLabel);
         endCol.setText(Messages.EndTimeColumLabel);
         pathCol.setText(Messages.AttributePathColumnLabel);
@@ -116,6 +132,9 @@ public class TmfStateSystemExplorer extends TmfView {
         if (trace != null) {
             traceSelected(new TmfTraceSelectedSignal(this, trace));
         }
+
+        fillToolBar() ;
+
     }
 
     // ------------------------------------------------------------------------
@@ -126,6 +145,9 @@ public class TmfStateSystemExplorer extends TmfView {
      * Create the initial tree from a trace.
      */
     private synchronized void createTable() {
+
+        long ts = fCurrentTimestamp;
+
         if (fTrace == null) {
             return;
         }
@@ -150,11 +172,13 @@ public class TmfStateSystemExplorer extends TmfView {
                 String ssName = entry.getKey();
                 ITmfStateSystem ss = entry.getValue();
                 ss.waitUntilBuilt();
-                long startTime = ss.getStartTime();
+                if (ts == -1 || ts < ss.getStartTime() || ts > ss.getCurrentEndTime()) {
+                    ts = ss.getStartTime();
+                }
                 try {
-                    fullStates.put(ssName, ss.queryFullState(startTime));
+                    fullStates.put(ssName, ss.queryFullState(ts));
                 } catch (TimeRangeException e) {
-                    /* Should not happen since we're querying at start time */
+                    /* We already checked the limits ourselves */
                     throw new RuntimeException();
                 } catch (StateSystemDisposedException e) {
                     /* Probably shutting down, cancel and return */
@@ -192,6 +216,10 @@ public class TmfStateSystemExplorer extends TmfView {
                         item.setExpanded(true);
                     }
                     packColumns();
+
+                    if (filterStatus) {
+                        filterChildren(traceRoot);
+                    }
                 }
             });
         }
@@ -312,24 +340,29 @@ public class TmfStateSystemExplorer extends TmfView {
      * Populate an 'item' (a row in the tree) with the information found in the
      * interval. This method should only be called by the UI thread.
      */
-    private static void populateColumns(TreeItem item, ITmfStateInterval interval) {
+    private void populateColumns(TreeItem item, ITmfStateInterval interval) {
         try {
             ITmfStateValue state = interval.getStateValue();
+            String value ;
 
             // add the value in the 2nd column
             switch (state.getType()) {
             case INTEGER:
-                item.setText(VALUE_COL, String.valueOf(state.unboxInt()));
+                value = String.valueOf(state.unboxInt());
+                item.setText(TYPE_COL, Messages.TypeInteger);
                 break;
             case LONG:
-                item.setText(VALUE_COL, String.valueOf(state.unboxLong()));
+                value = String.valueOf(state.unboxLong());
+                item.setText(TYPE_COL, Messages.TypeLong);
                 break;
             case STRING:
-                item.setText(VALUE_COL, state.unboxStr());
+                value = state.unboxStr();
+                item.setText(TYPE_COL, Messages.TypeString);
                 break;
             case NULL:
             default:
-                item.setText(VALUE_COL, emptyString);
+                value = emptyString ;
+                item.setText(TYPE_COL, emptyString);
                 break;
             }
 
@@ -339,6 +372,16 @@ public class TmfStateSystemExplorer extends TmfView {
             TmfTimestamp endTime = new TmfTimestamp(interval.getEndTime(), ITmfTimestamp.NANOSECOND_SCALE);
             item.setText(END_TIME_COL, endTime.toString());
 
+            item.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)) ;
+
+            if (!filterStatus) {
+                if (!value.equals(item.getText(VALUE_COL)) || fCurrentTimestamp == startTime.getValue()) {
+                    item.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_YELLOW));
+                }
+            }
+
+            item.setText(VALUE_COL, value) ;
+
         } catch (StateValueTypeException e) {
             /* Should not happen, we're case-switching on the specific types */
             throw new RuntimeException();
@@ -356,6 +399,7 @@ public class TmfStateSystemExplorer extends TmfView {
      */
     private void markOutOfRange(TreeItem root) {
         root.setText(VALUE_COL, Messages.OutOfRangeMsg);
+        root.setText(TYPE_COL, emptyString);
         root.setText(START_TIME_COL, emptyString);
         root.setText(END_TIME_COL, emptyString);
         for (TreeItem item : root.getItems()) {
@@ -439,7 +483,12 @@ public class TmfStateSystemExplorer extends TmfView {
             public void run() {
                 ITmfTimestamp currentTime = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
                 fCurrentTimestamp = currentTime.getValue();
-                updateTable();
+
+                if (filterStatus) {
+                    createTable();
+                } else {
+                    updateTable();
+                }
             }
         };
         thread.start();
@@ -455,4 +504,50 @@ public class TmfStateSystemExplorer extends TmfView {
         thread.start();
     }
 
+    /**
+     * Function for the delete TreeItem
+     */
+    private boolean filterChildren(TreeItem root) {
+        boolean valid = false ;
+        TmfTimestamp startTime = new TmfTimestamp(fCurrentTimestamp, ITmfTimestamp.NANOSECOND_SCALE);
+        valid = root.getText(START_TIME_COL).equals(startTime.toString());
+        root.setExpanded(true);
+
+        for (TreeItem item : root.getItems()) {
+            /* Update children recursively */
+            valid = filterChildren(item) || valid;
+        }
+
+        if (!valid) {
+            root.dispose();
+        }
+        return valid;
+    }
+
+    // ------------------------------------------------------------------------
+    // Part For Button Action
+    // ------------------------------------------------------------------------
+
+
+
+    private void fillToolBar() {
+        Action fFilterAction = new FilterAction();
+        fFilterAction.setImageDescriptor(ImageDescriptor.createFromImage(FILTER_IMAGE));
+        fFilterAction.setToolTipText(Messages.FilterButton) ;
+        fFilterAction.setChecked(false);
+
+        IActionBars bars = getViewSite().getActionBars();
+        IToolBarManager manager = bars.getToolBarManager();
+        manager.add(fFilterAction);
+    }
+
+    private class FilterAction extends Action {
+        @Override
+        public void run() {
+            filterStatus = !filterStatus;
+            if (!filterStatus) {
+                createTable();
+            }
+        }
+    }
 }
index 3f50faa95045a3f89001d3ef8d1d3dc639e6b7a5..25c1f55a64e78cdbe6d7cf5c90bfde780088ed74 100644 (file)
 TreeNodeColumnLabel=State System / Attribute
 QuarkColumnLabel=Quark
 ValueColumnLabel=Value at timestamp
+TypeColumnLabel=Type
 StartTimeColumLabel=Start time
 EndTimeColumLabel=End time
 AttributePathColumnLabel=Full attribute path
 
 # Other messages
-OutOfRangeMsg=Out of range
\ No newline at end of file
+OutOfRangeMsg=Out of range
+FilterButton=Display Only Change
+TypeInteger=Int
+TypeLong=Long
+TypeString=String
\ No newline at end of file
This page took 0.041546 seconds and 5 git commands to generate.