Add entry filter support for TimegraphCombo via dialog
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / TimeGraphControl.java
index 5e0a117a5aeed2a61dbbe49c94e32cc6570f9c70..a9e8483729b753fabbbc98e84150215687d88986 100644 (file)
@@ -25,6 +25,7 @@ import org.eclipse.jface.resource.LocalResourceManager;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTreeListener;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
@@ -114,6 +115,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
     private final List<MenuDetectListener> _timeEventMenuListeners = new ArrayList<MenuDetectListener>();
     private final Cursor _dragCursor3;
     private final Cursor _WaitCursor;
+    private final List<ViewerFilter> _filters = new ArrayList<ViewerFilter>();
 
     // Vertical formatting formatting for the state control view
     private final boolean _visibleVerticalScroll = true;
@@ -366,18 +368,19 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
 
     boolean ensureVisibleItem(int idx, boolean redraw) {
         boolean changed = false;
-        if (idx < 0) {
-            for (idx = 0; idx < _data._expandedItems.length; idx++) {
-                if (_data._expandedItems[idx]._selected) {
+        int index = idx;
+        if (index < 0) {
+            for (index = 0; index < _data._expandedItems.length; index++) {
+                if (_data._expandedItems[index]._selected) {
                     break;
                 }
             }
         }
-        if (idx >= _data._expandedItems.length) {
+        if (index >= _data._expandedItems.length) {
             return changed;
         }
-        if (idx < _topIndex) {
-            setTopIndex(idx);
+        if (index < _topIndex) {
+            setTopIndex(index);
             //FIXME:getVerticalBar().setSelection(_topItem);
             if (redraw) {
                 redraw();
@@ -385,8 +388,8 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
             changed = true;
         } else {
             int page = countPerPage();
-            if (idx >= _topIndex + page) {
-                setTopIndex(idx - page + 1);
+            if (index >= _topIndex + page) {
+                setTopIndex(index - page + 1);
                 //FIXME:getVerticalBar().setSelection(_topItem);
                 if (redraw) {
                     redraw();
@@ -404,9 +407,9 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
      *            The index
      */
     public void setTopIndex(int idx) {
-        idx = Math.min(idx, _data._expandedItems.length - countPerPage());
-        idx = Math.max(0,  idx);
-        _topIndex = idx;
+        int index = Math.min(idx, _data._expandedItems.length - countPerPage());
+        index = Math.max(0,  index);
+        _topIndex = index;
         redraw();
     }
 
@@ -930,12 +933,12 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
     /**
      * Return the time corresponding to an x coordinate
      *
-     * @param x the x coordinate
-     * @return the time corresponding to the x coordinate
+     * @param coord The X coordinate
+     * @return The time corresponding to the x coordinate
      *
      * @since 2.0
      */
-    public long getTimeAtX(int x) {
+    public long getTimeAtX(int coord) {
         if (null == _timeProvider) {
             return -1;
         }
@@ -944,7 +947,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         long time0 = _timeProvider.getTime0();
         long time1 = _timeProvider.getTime1();
         int nameWidth = _timeProvider.getNameSpace();
-        x -= nameWidth;
+        final int x = coord - nameWidth;
         int timeWidth = size.x - nameWidth - RIGHT_MARGIN;
         if (x >= 0 && size.x >= nameWidth) {
             if (time1 - time0 > timeWidth) {
@@ -1394,8 +1397,8 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
                 stateColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
             }
 
-            timeSelected = timeSelected && selected;
-            if (timeSelected) {
+            boolean reallySelected = timeSelected && selected;
+            if (reallySelected) {
                 // modify the color?
             }
             // fill all rect area
@@ -1405,7 +1408,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
             gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
 
             // draw bounds
-            if (!timeSelected) {
+            if (!reallySelected) {
                 // Draw the top and bottom borders i.e. no side borders
                 // top
                 gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
@@ -1762,9 +1765,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
                 redraw();
                 _dragState = DRAG_NONE;
             } else if (e.button == 3 && DRAG_ZOOM == _dragState) {
-                Point size = getCtrlSize();
                 int nameWidth = _timeProvider.getNameSpace();
-                int x = e.x - nameWidth;
                 if (Math.max(_dragX, _dragX0) > nameWidth && _dragX != _dragX0) {
                     long time0 = getTimeAtX(_dragX0);
                     long time1 = getTimeAtX(_dragX);
@@ -1980,6 +1981,24 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
 
     }
 
+    /**
+     * @param filter The filter object to be attached to the view
+     * @since 2.0
+     */
+    public void addFilter(ViewerFilter filter) {
+        if (!_filters.contains(filter)) {
+            _filters.add(filter);
+        }
+    }
+
+    /**
+     * @param filter The filter object to be attached to the view
+     * @since 2.0
+     */
+    public void removeFilter(ViewerFilter filter) {
+        _filters.remove(filter);
+    }
+
     private class ItemData {
         public Item[] _expandedItems = new Item[0];
         public Item[] _items = new Item[0];
@@ -2059,10 +2078,20 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         }
 
         private void refreshExpanded(List<Item> expandedItemList, Item item) {
-            expandedItemList.add(item);
-            if (item._hasChildren && item._expanded) {
-                for (Item child : item.children) {
-                    refreshExpanded(expandedItemList, child);
+            // Check for filters
+            boolean display = true;
+            for (ViewerFilter filter : _filters) {
+                if (!filter.select(null, item._trace.getParent(), item._trace)) {
+                    display = false;
+                    break;
+                }
+            }
+            if (display) {
+                expandedItemList.add(item);
+                if (item._hasChildren && item._expanded) {
+                    for (Item child : item.children) {
+                        refreshExpanded(expandedItemList, child);
+                    }
                 }
             }
         }
This page took 0.026029 seconds and 5 git commands to generate.