Bug 378401: Implementation of time graph widget.
authorPatrick Tasse <patrick.tasse@gmail.com>
Thu, 7 Jun 2012 22:37:59 +0000 (18:37 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 7 Jun 2012 22:40:38 +0000 (18:40 -0400)
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java

index af93a05f9dac81abf4498e4dcbc56724dec85227..709d8a388db325230297db346160c0140b3e3862 100644 (file)
@@ -272,10 +272,16 @@ public class TimeGraphCombo extends Composite {
         // Bug in Linux. The tree header height is 0 in constructor,\r
         // so we need to reset it later when the control is resized.\r
         tree.addControlListener(new ControlAdapter() {\r
+            int depth = 0;\r
             @Override\r
             public void controlResized(ControlEvent e) {\r
-                fTreeViewer.getTree().getVerticalBar().setEnabled(false);\r
-                fTreeViewer.getTree().getVerticalBar().setVisible(false);\r
+                if (depth == 0) {\r
+                    depth++;\r
+                    tree.getVerticalBar().setEnabled(false);\r
+                    // this can trigger controlResized recursively\r
+                    tree.getVerticalBar().setVisible(false);\r
+                    depth--;\r
+                }\r
                 fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight());\r
             }\r
         });\r
index d6328ac26a86a1af46d7c0975591643975e44f5a..325fbad265025f39bda1f6b988dab0199225bde1 100644 (file)
@@ -253,7 +253,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         redraw();\r
     }\r
 \r
-    public void refreshData(ITimeGraphEntry traces[]) {\r
+    public void refreshData(ITimeGraphEntry[] traces) {\r
         _data.refreshData(traces);\r
         adjustScrolls();\r
         redraw();\r
@@ -294,7 +294,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         boolean changed = false;\r
         if (idx < 0) {\r
             for (idx = 0; idx < _data._expandedItems.length; idx++) {\r
-                if (((TimeGraphItem) _data._expandedItems[idx])._selected)\r
+                if (((Item) _data._expandedItems[idx])._selected)\r
                     break;\r
             }\r
         }\r
@@ -327,7 +327,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
     }\r
 \r
     public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {\r
-        TimeGraphItem item = _data.findItem(entry);\r
+        Item item = _data.findItem(entry);\r
         if (item != null && item._expanded != expanded) {\r
             item._expanded = expanded;\r
             _data.updateExpandedItems();\r
@@ -462,17 +462,17 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         boolean changed = false;\r
         int lastSelection = -1;\r
         for (int i = 0; i < _data._expandedItems.length; i++) {\r
-            TimeGraphItem item = (TimeGraphItem) _data._expandedItems[i];\r
+            Item item = (Item) _data._expandedItems[i];\r
             if (item._selected) {\r
                 lastSelection = i;\r
                 if ((1 == n) && (i < _data._expandedItems.length - 1)) {\r
                     item._selected = false;\r
-                    item = (TimeGraphItem) _data._expandedItems[i + 1];\r
+                    item = (Item) _data._expandedItems[i + 1];\r
                     item._selected = true;\r
                     changed = true;\r
                 } else if ((-1 == n) && (i > 0)) {\r
                     item._selected = false;\r
-                    item = (TimeGraphItem) _data._expandedItems[i - 1];\r
+                    item = (Item) _data._expandedItems[i - 1];\r
                     item._selected = true;\r
                     changed = true;\r
                 }\r
@@ -481,7 +481,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         }\r
 \r
         if (lastSelection < 0 && _data._expandedItems.length > 0) {\r
-            TimeGraphItem item = (TimeGraphItem) _data._expandedItems[0];\r
+            Item item = (Item) _data._expandedItems[0];\r
             item._selected = true;\r
             changed = true;\r
         }\r
@@ -650,7 +650,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
     public int getSelectedIndex() {\r
         int idx = -1;\r
         for (int i = 0; i < _data._expandedItems.length; i++) {\r
-            TimeGraphItem item = (TimeGraphItem) _data._expandedItems[i];\r
+            Item item = (Item) _data._expandedItems[i];\r
             if (item._selected) {\r
                 idx = i;\r
                 break;\r
@@ -662,7 +662,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
     boolean toggle(int idx) {\r
         boolean toggled = false;\r
         if (idx >= 0 && idx < _data._expandedItems.length) {\r
-            TimeGraphItem item = (TimeGraphItem) _data._expandedItems[idx];\r
+            Item item = (Item) _data._expandedItems[idx];\r
             if (item._hasChildren) {\r
                 item._expanded = !item._expanded;\r
                 _data.updateExpandedItems();\r
@@ -709,9 +709,9 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         }\r
     }\r
 \r
-    TimeGraphItem getItem(Point pt) {\r
+    ITimeGraphEntry getEntry(Point pt) {\r
         int idx = getItemIndexAtY(pt.y);\r
-        return idx >= 0 ? (TimeGraphItem) _data._expandedItems[idx] : null;\r
+        return idx >= 0 ? _data._expandedItems[idx]._trace : null;\r
     }\r
 \r
     long getTimeAtX(int x) {\r
@@ -740,13 +740,13 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         boolean changed = false;\r
         if (addSelection) {\r
             if (idx >= 0 && idx < _data._expandedItems.length) {\r
-                TimeGraphItem item = (TimeGraphItem) _data._expandedItems[idx];\r
+                Item item = (Item) _data._expandedItems[idx];\r
                 changed = (item._selected == false);\r
                 item._selected = true;\r
             }\r
         } else {\r
             for (int i = 0; i < _data._expandedItems.length; i++) {\r
-                TimeGraphItem item = (TimeGraphItem) _data._expandedItems[i];\r
+                Item item = (Item) _data._expandedItems[i];\r
                 if ((i == idx && !item._selected) || (idx == -1 && item._selected)) {\r
                     changed = true;\r
                 }\r
@@ -800,7 +800,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
 \r
     public ITimeGraphEntry[] getExpandedElements() {\r
         ArrayList<ITimeGraphEntry> elements = new ArrayList<ITimeGraphEntry>();\r
-        for (TimeGraphItem item : _data._expandedItems) {\r
+        for (Item item : _data._expandedItems) {\r
             elements.add(item._trace);\r
         }\r
         return elements.toArray(new ITimeGraphEntry[0]);\r
@@ -885,9 +885,9 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         }\r
     }\r
 \r
-    public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, TimeGraphItem[] items, int topIndex, int nameSpace, GC gc) {\r
+    public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, Item[] items, int topIndex, int nameSpace, GC gc) {\r
         for (int i = topIndex; i < items.length; i++) {\r
-            TimeGraphItem item = (TimeGraphItem) items[i];\r
+            Item item = (Item) items[i];\r
             drawItem(item, bounds, timeProvider, i, nameSpace, gc);\r
         }\r
         fTimeGraphProvider.postDrawControl(bounds, gc);\r
@@ -902,7 +902,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
      * @param nameSpace the name space\r
      * @param gc\r
      */\r
-    protected void drawItem(TimeGraphItem item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) {\r
+    protected void drawItem(Item item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) {\r
         ITimeGraphEntry entry = item._trace;\r
         long time0 = timeProvider.getTime0();\r
         long time1 = timeProvider.getTime1();\r
@@ -976,7 +976,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         fTimeGraphProvider.postDrawEntry(entry, rect, gc);\r
     }\r
 \r
-    protected void drawName(TimeGraphItem item, Rectangle bounds, GC gc) {\r
+    protected void drawName(Item item, Rectangle bounds, GC gc) {\r
         boolean hasTimeEvents = item._trace.hasTimeEvents();\r
         if (! hasTimeEvents) {\r
             gc.setBackground(_colors.getBkColorGroup(item._selected, _isInFocus));\r
@@ -1367,7 +1367,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
 \r
             idx = getItemIndexAtY(e.y);\r
             if (idx >= 0) {\r
-                TimeGraphItem item = _data._expandedItems[idx];\r
+                Item item = _data._expandedItems[idx];\r
                 if (item._hasChildren && e.x < nameSpace && e.x < MARGIN + (item.level + 1) * EXPAND_SIZE) {\r
                     toggle(idx);\r
                 } else {\r
@@ -1571,124 +1571,148 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
 \r
     }\r
 \r
-}\r
-\r
-class ItemData {\r
-    public TimeGraphItem[] _expandedItems = new TimeGraphItem[0];\r
-    public TimeGraphItem[] _items = new TimeGraphItem[0];\r
-    private ITimeGraphEntry _traces[] = new ITimeGraphEntry[0];\r
-    private boolean traceFilter[] = new boolean[0];\r
-    private Vector<ITimeGraphEntry> filteredOut = new Vector<ITimeGraphEntry>();\r
-    public ITimeGraphPresentationProvider provider;\r
+    private class ItemData {\r
+        public Item[] _expandedItems = new Item[0];\r
+        public Item[] _items = new Item[0];\r
+        private ITimeGraphEntry _traces[] = new ITimeGraphEntry[0];\r
+        private boolean traceFilter[] = new boolean[0];\r
+        private Vector<ITimeGraphEntry> filteredOut = new Vector<ITimeGraphEntry>();\r
+        public ITimeGraphPresentationProvider provider;\r
 \r
-    public ItemData() {\r
-    }\r
+        public ItemData() {\r
+        }\r
 \r
-    TimeGraphItem findItem(ITimeGraphEntry entry) {\r
-        if (entry == null)\r
-            return null;\r
+        Item findItem(ITimeGraphEntry entry) {\r
+            if (entry == null)\r
+                return null;\r
 \r
-        for (int i = 0; i < _items.length; i++) {\r
-            TimeGraphItem item = _items[i];\r
-            if (item._trace == entry) {\r
-                return item;\r
+            for (int i = 0; i < _items.length; i++) {\r
+                Item item = _items[i];\r
+                if (item._trace == entry) {\r
+                    return item;\r
+                }\r
             }\r
+\r
+            return null;\r
         }\r
 \r
-        return null;\r
-    }\r
+        int findItemIndex(ITimeGraphEntry trace) {\r
+            if (trace == null)\r
+                return -1;\r
+\r
+            for (int i = 0; i < _expandedItems.length; i++) {\r
+                Item item = _expandedItems[i];\r
+                if (item._trace == trace) {\r
+                    return i;\r
+                }\r
+            }\r
 \r
-    int findItemIndex(ITimeGraphEntry trace) {\r
-        if (trace == null)\r
             return -1;\r
+        }\r
 \r
-        for (int i = 0; i < _expandedItems.length; i++) {\r
-            TimeGraphItem item = _expandedItems[i];\r
-            if (item._trace == trace) {\r
-                return i;\r
+        public void refreshData() {\r
+            List<Item> itemList = new ArrayList<Item>();\r
+            filteredOut.clear();\r
+            for (int i = 0; i < _traces.length; i++) {\r
+                ITimeGraphEntry entry = _traces[i];\r
+                refreshData(itemList, null, 0, entry);\r
             }\r
+            _items = itemList.toArray(new Item[0]);\r
+            updateExpandedItems();\r
         }\r
 \r
-        return -1;\r
-    }\r
+        private void refreshData(List<Item> itemList, Item parent, int level, ITimeGraphEntry entry) {\r
+            Item item = new Item(entry, entry.getName(), level);\r
+            if (parent != null) {\r
+                parent.children.add(item);\r
+            }\r
+            item.itemHeight = provider.getItemHeight(entry);\r
+            itemList.add(item);\r
+            if (entry.hasChildren()) {\r
+                item._expanded = true;\r
+                item._hasChildren = true;\r
+                for (ITimeGraphEntry child : entry.getChildren()) {\r
+                    refreshData(itemList, item, level + 1, child);\r
+                }\r
+            }\r
+        }\r
 \r
-    public void refreshData() {\r
-        List<TimeGraphItem> itemList = new ArrayList<TimeGraphItem>();\r
-        filteredOut.clear();\r
-        for (int i = 0; i < _traces.length; i++) {\r
-            ITimeGraphEntry entry = _traces[i];\r
-            refreshData(itemList, null, 0, entry);\r
-        }\r
-        _items = itemList.toArray(new TimeGraphItem[0]);\r
-        updateExpandedItems();\r
-    }\r
-\r
-    private void refreshData(List<TimeGraphItem> itemList, TimeGraphItem parent, int level, ITimeGraphEntry entry) {\r
-        TimeGraphItem item = new TimeGraphItem(entry, entry.getName(), level);\r
-        if (parent != null) {\r
-            parent.children.add(item);\r
-        }\r
-        item.itemHeight = provider.getItemHeight(entry);\r
-        itemList.add(item);\r
-        if (entry.hasChildren()) {\r
-            item._expanded = true;\r
-            item._hasChildren = true;\r
-            for (ITimeGraphEntry child : entry.getChildren()) {\r
-                refreshData(itemList, item, level + 1, child);\r
+        public void updateExpandedItems() {\r
+            List<Item> expandedItemList = new ArrayList<Item>();\r
+            for (int i = 0; i < _traces.length; i++) {\r
+                ITimeGraphEntry entry = _traces[i];\r
+                Item item = findItem(entry);\r
+                refreshExpanded(expandedItemList, item);\r
             }\r
+            _expandedItems = expandedItemList.toArray(new Item[0]);\r
         }\r
-    }\r
 \r
-    public void updateExpandedItems() {\r
-        List<TimeGraphItem> expandedItemList = new ArrayList<TimeGraphItem>();\r
-        for (int i = 0; i < _traces.length; i++) {\r
-            ITimeGraphEntry entry = _traces[i];\r
-            TimeGraphItem item = findItem(entry);\r
-            refreshExpanded(expandedItemList, item);\r
+        private void refreshExpanded(List<Item> expandedItemList, Item item) {\r
+            expandedItemList.add(item);\r
+            if (item._hasChildren && item._expanded) {\r
+                for (Item child : item.children) {\r
+                    refreshExpanded(expandedItemList, child);\r
+                }\r
+            }\r
         }\r
-        _expandedItems = expandedItemList.toArray(new TimeGraphItem[0]);\r
-    }\r
 \r
-    private void refreshExpanded(List<TimeGraphItem> expandedItemList, TimeGraphItem item) {\r
-        expandedItemList.add(item);\r
-        if (item._hasChildren && item._expanded) {\r
-            for (TimeGraphItem child : item.children) {\r
-                refreshExpanded(expandedItemList, child);\r
+        public void expandItem(int idx) {\r
+            if (idx < 0 || idx >= _expandedItems.length)\r
+                return;\r
+            Item item = (Item) _expandedItems[idx];\r
+            if (item._hasChildren && !item._expanded) {\r
+                item._expanded = true;\r
+                updateExpandedItems();\r
             }\r
         }\r
-    }\r
 \r
-    public void expandItem(int idx) {\r
-        if (idx < 0 || idx >= _expandedItems.length)\r
-            return;\r
-        TimeGraphItem item = (TimeGraphItem) _expandedItems[idx];\r
-        if (item._hasChildren && !item._expanded) {\r
-            item._expanded = true;\r
-            updateExpandedItems();\r
+        public void refreshData(ITimeGraphEntry traces[]) {\r
+            if (traces == null || traces.length == 0) {\r
+                traceFilter = null;\r
+            } else if (traceFilter == null || traces.length != traceFilter.length) {\r
+                traceFilter = new boolean[traces.length];\r
+                java.util.Arrays.fill(traceFilter, true);\r
+            }\r
+\r
+            _traces = traces;\r
+            refreshData();\r
         }\r
-    }\r
 \r
-    public void refreshData(ITimeGraphEntry traces[]) {\r
-        if (traces == null || traces.length == 0) {\r
-            traceFilter = null;\r
-        } else if (traceFilter == null || traces.length != traceFilter.length) {\r
-            traceFilter = new boolean[traces.length];\r
-            java.util.Arrays.fill(traceFilter, true);\r
+        public ITimeGraphEntry[] getTraces() {\r
+            return _traces;\r
         }\r
 \r
-        _traces = traces;\r
-        refreshData();\r
-    }\r
+        public boolean[] getTraceFilter() {\r
+            return traceFilter;\r
+        }\r
 \r
-    public ITimeGraphEntry[] getTraces() {\r
-        return _traces;\r
+        public Vector<ITimeGraphEntry> getFilteredOut() {\r
+            return filteredOut;\r
+        }\r
     }\r
 \r
-    public boolean[] getTraceFilter() {\r
-        return traceFilter;\r
-    }\r
+    private class Item {\r
+        public boolean _expanded;\r
+        public boolean _selected;\r
+        public boolean _hasChildren;\r
+        public int itemHeight;\r
+        public int level;\r
+        public List<Item> children;\r
+        public String _name;\r
+        public ITimeGraphEntry _trace;\r
 \r
-    public Vector<ITimeGraphEntry> getFilteredOut() {\r
-        return filteredOut;\r
+        public Item(ITimeGraphEntry trace, String name, int level) {\r
+            this._trace = trace;\r
+            this._name = name;\r
+            this.level = level;\r
+            this.children = new ArrayList<Item>();\r
+        }\r
+\r
+        @Override\r
+        public String toString() {\r
+            return _name;\r
+        }\r
     }\r
+\r
 }\r
+\r
index 7e73b43dd0df92805e0a7292a74735233af85eca..87c34f296b771bdc5addc58996e4e6a0f347251c 100644 (file)
@@ -114,16 +114,15 @@ public class TimeGraphTooltipHandler {
                 line.setText(1, value);\r
             }\r
 \r
-            private void fillValues(Point pt, TimeGraphControl threadStates, TimeGraphItem item) {\r
-                if (item == null) {\r
+            private void fillValues(Point pt, TimeGraphControl threadStates, ITimeGraphEntry entry) {\r
+                if (entry == null) {\r
                     return;\r
                 }\r
-                if (item._trace.hasTimeEvents()) {\r
-                    ITimeGraphEntry thrd = item._trace;\r
-                    ITimeEvent threadEvent = Utils.findEvent(thrd, threadStates.getTimeAtX(pt.x), 2);\r
-                    ITimeEvent nextEvent = Utils.findEvent(thrd, threadStates.getTimeAtX(pt.x), 1);\r
+                if (entry.hasTimeEvents()) {\r
+                    ITimeEvent threadEvent = Utils.findEvent(entry, threadStates.getTimeAtX(pt.x), 2);\r
+                    ITimeEvent nextEvent = Utils.findEvent(entry, threadStates.getTimeAtX(pt.x), 1);\r
                     // state name\r
-                    addItem(_utilImp.getStateTypeName(), thrd.getName());\r
+                    addItem(_utilImp.getStateTypeName(), entry.getName());\r
                     if (threadEvent == null) {\r
                         return;\r
                     }\r
@@ -211,9 +210,9 @@ public class TimeGraphTooltipHandler {
             public void mouseHover(MouseEvent event) {\r
                 Point pt = new Point(event.x, event.y);\r
                 TimeGraphControl threadStates = (TimeGraphControl) event.widget;\r
-                TimeGraphItem item = threadStates.getItem(pt);\r
+                ITimeGraphEntry entry = threadStates.getEntry(pt);\r
                 _tipTable.remove(0, _tipTable.getItemCount() - 1);\r
-                fillValues(pt, threadStates, item);\r
+                fillValues(pt, threadStates, entry);\r
                 if (_tipTable.getItemCount() == 0) {\r
                     return;\r
                 }\r
This page took 0.052126 seconds and 5 git commands to generate.