From fb5cad3db2f5f94eb5a89d75ca1592c9c4130548 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Thu, 3 May 2012 14:36:28 -0400 Subject: [PATCH] Bug 378401: Implementation of time graph widget. --- .../lttng/ui/views/events/EventsTable.java | 2 +- .../lttng/ui/views/latency/LatencyView.java | 8 + .../plugin.xml | 4 +- .../test/stub/adaption/TsfImplProvider.java | 14 +- .../test/stub/model/EventImpl.java | 17 +- .../test/stub/model/TraceImpl.java | 56 +- .../stub/model/TraceModelImplFactory.java | 28 +- .../test/stub/views/TsfTraceAnalysisView.java | 217 +- .../META-INF/MANIFEST.MF | 4 +- .../linuxtools/internal/tmf/ui/Messages.java | 1 - .../internal/tmf/ui/messages.properties | 5 +- .../ui/parsers/custom/CustomEventsTable.java | 2 +- .../tmf/ui/viewers/events/TmfEventsTable.java | 6 +- .../linuxtools/tmf/ui/views/TmfView.java | 15 - .../tmf/ui/views/colors/ColorSetting.java | 4 +- .../ui/views/colors/ColorSettingsManager.java | 4 +- .../tmf/ui/views/colors/ColorsView.java | 33 +- .../tmf/ui/views/colors/TickColorDialog.java | 15 +- .../tmf/ui/views/filter/FilterView.java | 24 +- .../timechart/TimeChartAnalysisEntry.java | 35 +- .../timechart/TimeChartAnalysisProvider.java | 12 +- .../ui/views/timechart/TimeChartEvent.java | 4 +- .../tmf/ui/views/timechart/TimeChartView.java | 70 +- .../tmf/ui/widgets/timegraph/GridUtil.java | 45 - .../timegraph/ITimeAnalysisViewer.java | 195 -- .../widgets/timegraph/ITimeGraphProvider.java | 109 + ...ener.java => ITimeGraphRangeListener.java} | 20 +- ....java => ITimeGraphSelectionListener.java} | 17 +- ...tener.java => ITimeGraphTimeListener.java} | 20 +- .../timegraph/ITimeGraphTreeListener.java | 33 + .../tmf/ui/widgets/timegraph/ITmfViewer.java | 23 - .../ui/widgets/timegraph/TimeGraphCombo.java | 557 +++++ .../widgets/timegraph/TimeGraphProvider.java | 223 ++ .../timegraph/TimeGraphRangeUpdateEvent.java | 55 + .../timegraph/TimeGraphSelectionEvent.java | 44 + .../widgets/timegraph/TimeGraphTimeEvent.java | 42 + .../TimeGraphTreeExpansionEvent.java | 51 + .../ui/widgets/timegraph/TimeGraphViewer.java | 840 +++++++ .../timegraph/TmfTimeAnalysisProvider.java | 328 --- .../timegraph/TmfTimeAnalysisViewer.java | 957 -------- .../TmfTimeFilterSelectionEvent.java | 39 - .../timegraph/TmfTimeScaleSelectionEvent.java | 79 - .../timegraph/TmfTimeSelectionEvent.java | 49 - .../widgets/timegraph/TmfViewerFactory.java | 35 - .../timegraph/dialogs/TimeGraphLegend.java | 216 ++ .../dialogs/TmfTimeFilterDialog.java | 222 -- .../timegraph/dialogs/TmfTimeLegend.java | 279 --- .../widgets/timegraph/model/ITimeEvent.java | 27 +- .../timegraph/model/ITimeGraphEntry.java | 82 + .../model/ITmfTimeAnalysisEntry.java | 53 - .../ui/widgets/timegraph/model/TimeEvent.java | 48 +- .../timegraph/widgets/ITimeDataProvider.java | 68 +- .../timegraph/widgets/PlainSelection.java | 71 - .../widgets/TimeGraphBaseControl.java | 69 + .../widgets/TimeGraphColorScheme.java | 376 +++ .../timegraph/widgets/TimeGraphControl.java | 1594 ++++++++++++ .../timegraph/widgets/TimeGraphItem.java | 40 + ...TimeScaleCtrl.java => TimeGraphScale.java} | 775 +++--- .../timegraph/widgets/TimeGraphSelection.java | 71 + .../widgets/TimeGraphTooltipHandler.java | 247 ++ .../timegraph/widgets/TmfTimeStatesCtrl.java | 2173 ----------------- .../timegraph/widgets/TmfTimeTipHandler.java | 245 -- .../timegraph/widgets/TraceColorScheme.java | 381 --- .../widgets/timegraph/widgets/TraceCtrl.java | 68 - .../ui/widgets/timegraph/widgets/Utils.java | 836 +++---- .../{ => virtualtable}/ColumnData.java | 2 +- .../IDoubleClickListener.java | 2 +- .../{ => virtualtable}/TmfRawEventViewer.java | 2 +- .../{ => virtualtable}/TmfVirtualTable.java | 2 +- .../{ => virtualtable}/TooltipProvider.java | 2 +- 70 files changed, 5768 insertions(+), 6524 deletions(-) rename org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/{timeAnalysis => timegraph}/test/stub/adaption/TsfImplProvider.java (81%) rename org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/{timeAnalysis => timegraph}/test/stub/model/EventImpl.java (75%) rename org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/{timeAnalysis => timegraph}/test/stub/model/TraceImpl.java (68%) rename org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/{timeAnalysis => timegraph}/test/stub/model/TraceModelImplFactory.java (83%) rename org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/{timeAnalysis => timegraph}/test/stub/views/TsfTraceAnalysisView.java (73%) delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/GridUtil.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeAnalysisViewer.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphProvider.java rename org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/{ITmfTimeSelectionListener.java => ITimeGraphRangeListener.java} (53%) rename org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/{ITmfTimeFilterSelectionListener.java => ITimeGraphSelectionListener.java} (52%) rename org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/{ITmfTimeScaleSelectionListener.java => ITimeGraphTimeListener.java} (54%) create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphTreeListener.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfViewer.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphProvider.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphRangeUpdateEvent.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphSelectionEvent.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphTimeEvent.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphTreeExpansionEvent.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeAnalysisProvider.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeAnalysisViewer.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeFilterSelectionEvent.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeScaleSelectionEvent.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeSelectionEvent.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfViewerFactory.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphLegend.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TmfTimeFilterDialog.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TmfTimeLegend.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeGraphEntry.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITmfTimeAnalysisEntry.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/PlainSelection.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphBaseControl.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphColorScheme.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphItem.java rename org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/{TimeScaleCtrl.java => TimeGraphScale.java} (54%) create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphSelection.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TmfTimeStatesCtrl.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TmfTimeTipHandler.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TraceColorScheme.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TraceCtrl.java rename org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/{ => virtualtable}/ColumnData.java (89%) rename org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/{ => virtualtable}/IDoubleClickListener.java (92%) rename org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/{ => virtualtable}/TmfRawEventViewer.java (97%) rename org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/{ => virtualtable}/TmfVirtualTable.java (99%) rename org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/{ => virtualtable}/TooltipProvider.java (91%) diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/events/EventsTable.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/events/EventsTable.java index abdcb4772b..7d0c79524e 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/events/EventsTable.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/events/EventsTable.java @@ -17,7 +17,7 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; -import org.eclipse.linuxtools.tmf.ui.widgets.ColumnData; +import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/latency/LatencyView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/latency/LatencyView.java index ebc14f4b11..5f0a65cfb6 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/latency/LatencyView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/latency/LatencyView.java @@ -219,6 +219,14 @@ public class LatencyView extends TmfView implements IGraphModelListener { } } + /* (non-Javadoc) + * @see org.eclipse.ui.part.WorkbenchPart#setFocus() + */ + @Override + public void setFocus() { + fGraphViewer.setFocus(); + } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml b/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml index d7805e67ff..73084a37db 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml @@ -6,9 +6,9 @@ + name="Time Graph View" restorable="true"> traceEvents = new Vector(); @@ -34,13 +32,10 @@ public class TraceImpl implements ITmfTimeAnalysisEntry { // Constructor // ======================================================================== - public TraceImpl(int id, String name, long sTime, long stopTime, - String groupName, String className) { - this.id = id; + public TraceImpl(String name, long sTime, long stopTime, String className) { this.name = name; this.startTime = sTime; this.stopTime = stopTime; - this.groupName = groupName; this.className = className; } @@ -56,14 +51,6 @@ public class TraceImpl implements ITmfTimeAnalysisEntry { this.className = className; } - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public void setId(int id) { - this.id = id; - } - public void setName(String name) { this.name = name; } @@ -76,16 +63,6 @@ public class TraceImpl implements ITmfTimeAnalysisEntry { this.stopTime = stopTime; } - @Override - public String getGroupName() { - return groupName; - } - - @Override - public int getId() { - return id; - } - @Override public String getName() { return name; @@ -101,24 +78,33 @@ public class TraceImpl implements ITmfTimeAnalysisEntry { return stopTime; } - @Override - @Deprecated public Vector getTraceEvents() { - return traceEvents; - } - @Override - public Iterator getTraceEventsIterator() { + public Iterator getTimeEventsIterator() { return traceEvents.iterator(); } @Override - public Iterator getTraceEventsIterator(long startTime, long stopTime, long maxDuration) { + public Iterator getTimeEventsIterator(long startTime, long stopTime, long maxDuration) { return traceEvents.iterator(); } - @Override public void addTraceEvent(ITimeEvent event) { traceEvents.add(event); } + @Override + public ITimeGraphEntry[] getChildren() { + return null; + } + + @Override + public ITimeGraphEntry getParent() { + return null; + } + + @Override + public boolean hasChildren() { + return false; + } + } diff --git a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/TraceModelImplFactory.java b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceModelImplFactory.java similarity index 83% rename from org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/TraceModelImplFactory.java rename to org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceModelImplFactory.java index f3922c6345..60e5464479 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/TraceModelImplFactory.java +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceModelImplFactory.java @@ -9,7 +9,7 @@ * Contributors: * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model; +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model; import java.util.Date; @@ -39,8 +39,8 @@ public class TraceModelImplFactory { TraceImpl trace; TraceImpl[] traceArr = new TraceImpl[17]; for (int i = 0; i < traceArr.length; i++) { - trace = new TraceImpl(i, traceNames[i].name, timeRef, timeRef + 40, - traceNames[i].groupName, traceNames[i].classNmme); + trace = new TraceImpl(traceNames[i].name, timeRef, timeRef + 40, + traceNames[i].classNmme); count = i; createEvents(trace); traceArr[i] = trace; @@ -59,8 +59,8 @@ public class TraceModelImplFactory { for (int i = 0; i < traceArr.length; i++) { int count = i%17; long sTime = i * (long) 1E6; - trace = new TraceImpl(i, traceNames[count].name, sTime , sTime + 20000, - traceNames[count].groupName, traceNames[count].classNmme); + trace = new TraceImpl(traceNames[count].name, sTime , sTime + 20000, + traceNames[count].classNmme); create5000Events(trace); traceArr[i] = trace; } @@ -140,87 +140,70 @@ public class TraceModelImplFactory { traceNames[0] = new TraceStrings(); traceNames[0].name = "TE Log - TATA BSC11"; traceNames[0].classNmme = "All Boards"; - traceNames[0].groupName = "Trace and Error"; traceNames[1] = new TraceStrings(); traceNames[1].name = "System Log"; traceNames[1].classNmme = "BSC11"; - traceNames[1].groupName = "System"; traceNames[2] = new TraceStrings(); traceNames[2].name = "Alarm Log"; traceNames[2].classNmme = "BSC11"; - traceNames[2].groupName = "System"; traceNames[3] = new TraceStrings(); traceNames[3].name = "Events Log"; traceNames[3].classNmme = "BSC 11"; - traceNames[3].groupName = "System"; traceNames[4] = new TraceStrings(); traceNames[4].name = "CPU Load"; traceNames[4].classNmme = "All Boards"; - traceNames[4].groupName = "System"; traceNames[5] = new TraceStrings(); traceNames[5].name = "Performance Log"; traceNames[5].classNmme = "BSC11"; - traceNames[5].groupName = "System"; traceNames[6] = new TraceStrings(); traceNames[6].name = "TE Log - TATA BSC14"; traceNames[6].classNmme = "Board 24"; - traceNames[6].groupName = "Trace and Error"; traceNames[7] = new TraceStrings(); traceNames[7].name = "TE Log - TATA BSC14"; traceNames[7].classNmme = "Board 23"; - traceNames[7].groupName = "Trace and Error"; traceNames[8] = new TraceStrings(); traceNames[8].name = "TE Log - TATA BSC14"; traceNames[8].classNmme = "Board 11"; - traceNames[8].groupName = "Trace and Error"; traceNames[9] = new TraceStrings(); traceNames[9].name = "TE Log - TATA BSC14"; traceNames[9].classNmme = "Board 14, SPO"; - traceNames[9].groupName = "Trace and Error"; traceNames[10] = new TraceStrings(); traceNames[10].name = "INFO 1"; traceNames[10].classNmme = "All Boards"; - traceNames[10].groupName = "INFO"; traceNames[11] = new TraceStrings(); traceNames[11].name = "INFO2"; traceNames[11].classNmme = "BSC11"; - traceNames[11].groupName = "INFO"; traceNames[12] = new TraceStrings(); traceNames[12].name = "INFO3"; traceNames[12].classNmme = "Board 24"; - traceNames[12].groupName = "INFO"; traceNames[13] = new TraceStrings(); traceNames[13].name = "MISC1"; traceNames[13].classNmme = "Board 23"; - traceNames[13].groupName = "MISC"; traceNames[14] = new TraceStrings(); traceNames[14].name = "MISC2"; traceNames[14].classNmme = "Board 11"; - traceNames[14].groupName = "MISC"; traceNames[15] = new TraceStrings(); traceNames[15].name = "MISC3"; traceNames[15].classNmme = "Board 23"; - traceNames[15].groupName = "MISC"; traceNames[16] = new TraceStrings(); traceNames[16].name = "MISC4"; traceNames[16].classNmme = "Board 11"; - traceNames[16].groupName = "MISC"; } @@ -230,6 +213,5 @@ public class TraceModelImplFactory { private static class TraceStrings { public String name = ""; public String classNmme = name + " class"; - public String groupName = "group " + classNmme; } } diff --git a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/views/TsfTraceAnalysisView.java b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/views/TsfTraceAnalysisView.java similarity index 73% rename from org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/views/TsfTraceAnalysisView.java rename to org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/views/TsfTraceAnalysisView.java index 653c13aff2..87f0261730 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/views/TsfTraceAnalysisView.java +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/views/TsfTraceAnalysisView.java @@ -9,7 +9,7 @@ * Contributors: * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.views; +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.views; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -33,17 +33,18 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.adaption.TsfImplProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model.EventImpl; -import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model.TraceImpl; -import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model.TraceModelImplFactory; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeAnalysisViewer; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITmfTimeScaleSelectionListener; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITmfTimeSelectionListener; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeScaleSelectionEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeSelectionEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfViewerFactory; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.adaption.TsfImplProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.EventImpl; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.TraceImpl; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.TraceModelImplFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.graphics.Image; @@ -58,7 +59,7 @@ import org.eclipse.ui.part.ViewPart; @SuppressWarnings("nls") public class TsfTraceAnalysisView extends ViewPart implements - ITmfTimeSelectionListener, ITmfTimeScaleSelectionListener { + ITimeGraphSelectionListener, ITimeGraphTimeListener, ITimeGraphRangeListener { // ======================================================================== // Data @@ -67,22 +68,19 @@ public class TsfTraceAnalysisView extends ViewPart implements private DrillDownAdapter drillDownAdapter; private Action action1; private Action action2; - private Action actGroup; private Action resetScale; private Action nextEvent; private Action prevEvent; private Action nextTrace; private Action prevTrace; private Action showLegent; - private Action filterTraces; private Action zoomIn; private Action zoomOut; - private Action synch; private Action events300K; private Action doubleClickAction; - private ITimeAnalysisViewer tsfviewer; - private ITimeAnalysisViewer tsfviewer2; + private TimeGraphViewer tsfviewer; + private TimeGraphViewer tsfviewer2; private static SimpleDateFormat stimeformat = new SimpleDateFormat( "yy/MM/dd HH:mm:ss"); @@ -262,10 +260,10 @@ public class TsfTraceAnalysisView extends ViewPart implements final SashForm sashForm = new SashForm(parent, SWT.NONE); final SashForm sashForm2 = new SashForm(sashForm, SWT.NONE); - tsfviewer = TmfViewerFactory.createViewer(sashForm2, - new TsfImplProvider()); - tsfviewer2 = TmfViewerFactory.createViewer(sashForm2, - new TsfImplProvider()); + tsfviewer = new TimeGraphViewer(sashForm2, SWT.NONE); + tsfviewer.setTimeGraphProvider(new TsfImplProvider()); + tsfviewer2 = new TimeGraphViewer(sashForm2, SWT.NONE); + tsfviewer2.setTimeGraphProvider(new TsfImplProvider()); viewer = new TreeViewer(sashForm, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); @@ -279,16 +277,16 @@ public class TsfTraceAnalysisView extends ViewPart implements sashForm2.setWeights(new int[] { 1, 1 }); fact = new TraceModelImplFactory(); - ITmfTimeAnalysisEntry[] traceArr = fact.createTraces(); - tsfviewer.display(traceArr); - tsfviewer.addWidgetSelectionListner(this); - tsfviewer.addWidgetTimeScaleSelectionListner(this); + ITimeGraphEntry[] traceArr = fact.createTraces(); + tsfviewer.setInput(traceArr); + tsfviewer.addSelectionListener(this); + tsfviewer.addRangeListener(this); tsfviewer.setTimeCalendarFormat(true); - tsfviewer2.display(traceArr); - tsfviewer2.addWidgetSelectionListner(this); - tsfviewer2.addWidgetTimeScaleSelectionListner(this); - // tsfviewer2.setTimeFormat(ITimeAnalysisViewer.timeFormat.epoch); + tsfviewer2.setInput(traceArr); + tsfviewer2.addSelectionListener(this); + tsfviewer2.addRangeListener(this); + // tsfviewer2.setTimeFormat(TimeGraphViewer.timeFormat.epoch); makeActions(); hookContextMenu(); @@ -333,25 +331,22 @@ public class TsfTraceAnalysisView extends ViewPart implements private void fillLocalToolBar(IToolBarManager manager) { manager.add(new Separator()); - manager.add(actGroup); manager.add(resetScale); manager.add(nextEvent); manager.add(prevEvent); manager.add(nextTrace); manager.add(prevTrace); manager.add(showLegent); - manager.add(filterTraces); manager.add(zoomIn); manager.add(zoomOut); - manager.add(synch); manager.add(events300K); manager.add(new Separator()); drillDownAdapter.addNavigationActions(manager); } - private ITimeAnalysisViewer getActiveTsfCtrl() { - ITimeAnalysisViewer inFocusViewer = null; + private TimeGraphViewer getActiveTsfCtrl() { + TimeGraphViewer inFocusViewer = null; if (tsfviewer.isInFocus()) inFocusViewer = tsfviewer; else if (tsfviewer2.isInFocus()) @@ -384,29 +379,11 @@ public class TsfTraceAnalysisView extends ViewPart implements action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); - // action3 - actGroup = new Action() { - @Override - public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); - if (inFocusViewer != null) { - if (actGroup.isChecked()) { - inFocusViewer.groupTraces(false); - } else { - inFocusViewer.groupTraces(true); - } - } - } - }; - actGroup.setText("Group"); - actGroup.setToolTipText("Groupped or flat list"); - actGroup.setChecked(true); - // action4 resetScale = new Action() { @Override public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { inFocusViewer.resetStartFinishTime(); } @@ -420,7 +397,7 @@ public class TsfTraceAnalysisView extends ViewPart implements nextEvent = new Action() { @Override public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { inFocusViewer.selectNextEvent(); } @@ -433,7 +410,7 @@ public class TsfTraceAnalysisView extends ViewPart implements prevEvent = new Action() { @Override public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { inFocusViewer.selectPrevEvent(); } @@ -446,7 +423,7 @@ public class TsfTraceAnalysisView extends ViewPart implements nextTrace = new Action() { @Override public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { inFocusViewer.selectNextTrace(); } @@ -459,7 +436,7 @@ public class TsfTraceAnalysisView extends ViewPart implements prevTrace = new Action() { @Override public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { inFocusViewer.selectPrevTrace(); } @@ -472,7 +449,7 @@ public class TsfTraceAnalysisView extends ViewPart implements showLegent = new Action() { @Override public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { inFocusViewer.showLegend(); } @@ -481,24 +458,11 @@ public class TsfTraceAnalysisView extends ViewPart implements showLegent.setText("Legend"); showLegent.setToolTipText("Show Legend"); - // action10 - filterTraces = new Action() { - @Override - public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); - if (inFocusViewer != null) { - inFocusViewer.filterTraces(); - } - } - }; - filterTraces.setText("Filter"); - filterTraces.setToolTipText("Trace Filter options"); - // action10 zoomIn = new Action() { @Override public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { inFocusViewer.zoomIn(); } @@ -511,7 +475,7 @@ public class TsfTraceAnalysisView extends ViewPart implements zoomOut = new Action() { @Override public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { inFocusViewer.zoomOut(); } @@ -530,33 +494,15 @@ public class TsfTraceAnalysisView extends ViewPart implements zoomOut.setText("Zoom Out"); zoomOut.setToolTipText("Zoom Out"); - // action11 - synch = new Action() { - @Override - public void run() { - if (synch.isChecked()) { - tsfviewer.setAcceptSelectionAPIcalls(true); - tsfviewer2.setAcceptSelectionAPIcalls(true); - } else { - tsfviewer.setAcceptSelectionAPIcalls(false); - tsfviewer2.setAcceptSelectionAPIcalls(false); - } - } - }; - synch.setText("Synchronize"); - synch - .setToolTipText("Synchronize by listening to external API selection calls"); - synch.setChecked(false); - // action12 events300K = new Action() { @Override public void run() { - ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { - ITmfTimeAnalysisEntry[] traceArr = fact + ITimeGraphEntry[] traceArr = fact .createLargeTraces(60); - inFocusViewer.display(traceArr); + inFocusViewer.setInput(traceArr); } } }; @@ -596,16 +542,15 @@ public class TsfTraceAnalysisView extends ViewPart implements viewer.getControl().setFocus(); } - @SuppressWarnings("deprecation") @Override - public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event) { + public void selectionChanged(TimeGraphSelectionEvent event) { Object source = event.getSource(); - if (source == null || !(source instanceof ITimeAnalysisViewer)) { + if (source == null || !(source instanceof TimeGraphViewer)) { return; } - ITimeAnalysisViewer rViewer = (ITimeAnalysisViewer) event.getSource(); - ITimeAnalysisViewer synchViewer = null; + TimeGraphViewer rViewer = (TimeGraphViewer) event.getSource(); + TimeGraphViewer synchViewer = null; // Synchronize viewer selections if Enabled, // make sure the selection does not go in loops if (tsfviewer == rViewer) { @@ -615,44 +560,27 @@ public class TsfTraceAnalysisView extends ViewPart implements } Object selection = event.getSelection(); - long selTimens = event.getSelectedTime(); - long tms = (long) (selTimens * 1E-6); - Date date = new Date(tms); - String fDate = stimeformat.format(date); - String ns = formatNs(selTimens); - if (selection instanceof EventImpl) { EventImpl selEvent = (EventImpl) selection; System.out - .println("TsfTmIncubatorListener.tsfTmProcessEvent() Selected Event: \nType: " + .println("TsfTraceAnalysisView.selectionChanged() Selected Event: \nType: " + selEvent.getType().toString() + "\nTime: " + selEvent.getTime() + "\nTrace Name: " - + selEvent.getEntry().getName() - + "\nSelection Type: " - + event.getDType().toString() - + "\nSelected Time: " - + selTimens + " " + fDate + " " + ns); + + selEvent.getEntry().getName()); synchViewer.setSelectedEvent(selEvent, source); } else if (selection instanceof TraceImpl) { TraceImpl selTrace = (TraceImpl) selection; System.out - .println("TsfTmIncubatorListener.tsfTmProcessEvent() Selected Trace: \nName: " + .println("TsfTraceAnalysisView.selectionChanged() Selected Trace: \nName: " + selTrace.getName().toString() + "\nClass Name: " - + selTrace.getClassName() - + "\nNumber of Events: " - + selTrace.getTraceEvents().size() - + "\nSelection Type: " - + event.getDType().toString() - + "\nSelected Time: " - + selTimens + " " + fDate + " " + ns); - - synchViewer.setSelectedTraceTime(selTrace, event.getSelectedTime(), - source); + + selTrace.getClassName()); + + synchViewer.setSelection(selTrace); } else { System.out .println("TsfTmIncubatorListener.tsfTmProcessEvent() Unexpected event source received: " @@ -661,20 +589,45 @@ public class TsfTraceAnalysisView extends ViewPart implements } - @Override - public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event) { + @Override + public void timeSelected(TimeGraphTimeEvent event) { + TimeGraphViewer rViewer = (TimeGraphViewer) event.getSource(); + TimeGraphViewer synchViewer = null; + // Synchronize viewer selections if Enabled, + // make sure the selection does not go in loops + if (tsfviewer == rViewer) { + synchViewer = tsfviewer2; + } else { + synchViewer = tsfviewer; + } + long selTimens = event.getTime(); + long tms = (long) (selTimens * 1E-6); + Date date = new Date(tms); + String fDate = stimeformat.format(date); + String ns = formatNs(selTimens); + + System.out.println("TsfTraceAnalysisView.timeSelected() Selected Event: \nTime: " + + event.getTime() + + "\nSelected Time: " + + selTimens + " " + fDate + " " + ns); + + synchViewer.setSelectedTime(event.getTime(), true, event.getSource()); + } + + @Override + public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) { if (event == null) return; Object source = event.getSource(); - if (source == null || !(source instanceof ITimeAnalysisViewer)) { + if (source == null || !(source instanceof TimeGraphViewer)) { return; } - if (event instanceof TmfTimeScaleSelectionEvent) { - TmfTimeScaleSelectionEvent rEvent = (TmfTimeScaleSelectionEvent) event; - ITimeAnalysisViewer rViewer = (ITimeAnalysisViewer) event + if (event instanceof TimeGraphRangeUpdateEvent) { + TimeGraphRangeUpdateEvent rEvent = (TimeGraphRangeUpdateEvent) event; + TimeGraphViewer rViewer = (TimeGraphViewer) event .getSource(); - ITimeAnalysisViewer synchViewer = null; + TimeGraphViewer synchViewer = null; // Synchronize viewer selections if Enabled, // make sure the selection does not go in loops if (tsfviewer == rViewer) { @@ -684,8 +637,8 @@ public class TsfTraceAnalysisView extends ViewPart implements } - synchViewer.setSelectVisTimeWindow(rEvent.getTime0(), rEvent - .getTime1(), source); + synchViewer.setSelectVisTimeWindow(rEvent.getStartTime(), rEvent + .getEndTime(), source); } } diff --git a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF index ce076f1c21..9a685162d8 100644 --- a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF @@ -44,8 +44,8 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.l org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader, org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences, org.eclipse.linuxtools.tmf.ui.views.uml2sd.util, - org.eclipse.linuxtools.tmf.ui.widgets, org.eclipse.linuxtools.tmf.ui.widgets.timegraph, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model, - org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets + org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets, + org.eclipse.linuxtools.tmf.ui.widgets.virtualtable diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java index 62005b697e..1e752ca2dd 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java @@ -80,7 +80,6 @@ public class Messages extends NLS { public static String TmfTimeLegend_TRACE_STATES_TITLE; public static String TmfTimeLegend_WINDOW_TITLE; - public static String TimeScaleCtrl_Timescale; public static String TmfTimeStatesCtrl_TRACE_GROUP_LABEL; public static String TmfTimeStatesCtrl_UNDEFINED_GROUP; public static String TmfTimeTipHandler_DURATION; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties index e9e0f28fc5..bc7467a02d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties @@ -66,7 +66,7 @@ TmfEventsTable_SourceColumnHeader=Source TmfEventsTable_TimestampColumnHeader=Timestamp TmfEventsTable_TypeColumnHeader=Type -# org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.dialogs +# org.eclipse.linuxtools.tmf.ui.viewers.timegraph.dialogs TmfTimeFilterDialog_EDIT_PROFILING_OPTIONS=Edit Profiling Options TmfTimeFilterDialog_TRACE_FILTER=Trace Filter TmfTimeFilterDialog_TRACE_FILTER_DESC=Define the filter set @@ -77,8 +77,7 @@ TmfTimeLegend_TRACE_STATES=Trace states TmfTimeLegend_TRACE_STATES_TITLE=States Transition Visualizer TmfTimeLegend_WINDOW_TITLE=Trace Visualizer's Legend -# org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets -TimeScaleCtrl_Timescale=Time scale +# org.eclipse.linuxtools.tmf.ui.viewers.timegraph.widgets TmfTimeStatesCtrl_TRACE_GROUP_LABEL=Trace Group [{0}] TmfTimeStatesCtrl_UNDEFINED_GROUP= TmfTimeTipHandler_DURATION=Duration diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java index 8dd4b9583b..19163e1718 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java @@ -19,7 +19,7 @@ import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefiniti import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; -import org.eclipse.linuxtools.tmf.ui.widgets.ColumnData; +import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java index 81f47536f6..f1cc4f784c 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java @@ -73,9 +73,9 @@ import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting; import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager; import org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener; import org.eclipse.linuxtools.tmf.ui.views.filter.FilterManager; -import org.eclipse.linuxtools.tmf.ui.widgets.ColumnData; -import org.eclipse.linuxtools.tmf.ui.widgets.TmfRawEventViewer; -import org.eclipse.linuxtools.tmf.ui.widgets.TmfVirtualTable; +import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData; +import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.TmfRawEventViewer; +import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.TmfVirtualTable; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.TableEditor; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfView.java index bf487fd32e..5d51787bc4 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfView.java @@ -15,7 +15,6 @@ package org.eclipse.linuxtools.tmf.ui.views; import org.eclipse.linuxtools.tmf.core.component.ITmfComponent; import org.eclipse.linuxtools.tmf.core.signal.TmfSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; -import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.part.ViewPart; /** @@ -57,18 +56,4 @@ public abstract class TmfView extends ViewPart implements ITmfComponent { TmfSignalManager.dispatchSignal(signal); } - // ------------------------------------------------------------------------ - // ViewPart - // ------------------------------------------------------------------------ - - @Override - public void createPartControl(Composite parent) { - // TODO Auto-generated method stub - } - - @Override - public void setFocus() { - // TODO Auto-generated method stub - } - } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSetting.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSetting.java index 3fedf5706b..68d8240f40 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSetting.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSetting.java @@ -104,7 +104,7 @@ public class ColorSetting { /** * @return the tick color index (0-15) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme */ public int getTickColorIndex() { return fTickColorIndex; @@ -112,7 +112,7 @@ public class ColorSetting { /** * @param tickColorIndex the tick color index to set (0-15) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme */ public void setTickColorIndex(int tickColorIndex) { fTickColorIndex = tickColorIndex; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsManager.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsManager.java index f748f29f74..31fc9dc8fc 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsManager.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsManager.java @@ -17,7 +17,7 @@ import java.util.Arrays; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; @@ -29,7 +29,7 @@ public class ColorSettingsManager { private static final ColorSetting DEFAULT_COLOR_SETTING = new ColorSetting( Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(), - TraceColorScheme.BLACK_STATE, + TimeGraphColorScheme.BLACK_STATE, null); public static final int PRIORITY_NONE = Integer.MAX_VALUE; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java index 81ab33ecb0..e1ac645bd2 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java @@ -27,10 +27,11 @@ import org.eclipse.linuxtools.internal.tmf.ui.Messages; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; import org.eclipse.linuxtools.tmf.ui.views.TmfView; import org.eclipse.linuxtools.tmf.ui.views.filter.FilterDialog; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.MouseAdapter; @@ -80,14 +81,14 @@ public class ColorsView extends TmfView { private ColorSettingRow fSelectedRow = null; - private TraceColorScheme traceColorScheme = new TraceColorScheme(); - private TmfTimeAnalysisProvider timeAnalysisProvider = new TmfTimeAnalysisProvider() { + private TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme(); + private ITimeGraphProvider timeAnalysisProvider = new TimeGraphProvider() { @Override public StateColor getEventColor(ITimeEvent event) { return null; } @Override - public String getTraceClassName(ITmfTimeAnalysisEntry trace) { + public String getTraceClassName(ITimeGraphEntry trace) { return null; } @Override @@ -123,9 +124,9 @@ public class ColorsView extends TmfView { super("Colors"); //$NON-NLS-1$ } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite) - */ + /* (non-Javadoc) + * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composite) + */ @Override public void createPartControl(Composite parent) { fShell = parent.getShell(); @@ -185,7 +186,15 @@ public class ColorsView extends TmfView { fillToolBar(); } - + + /* (non-Javadoc) + * @see org.eclipse.ui.part.WorkbenchPart#setFocus() + */ + @Override + public void setFocus() { + fScrolledComposite.setFocus(); + } + public void refresh() { fListComposite.layout(); fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); @@ -247,7 +256,7 @@ public class ColorsView extends TmfView { ColorSetting colorSetting = new ColorSetting( Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(), - TraceColorScheme.BLACK_STATE, + TimeGraphColorScheme.BLACK_STATE, null); ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); if (fSelectedRow == null) { @@ -452,7 +461,7 @@ public class ColorsView extends TmfView { @Override public void paintControl(PaintEvent e) { Rectangle bounds = tickCanvas.getBounds(); - e.gc.setForeground(traceColorScheme.getColor(TraceColorScheme.MID_LINE)); + e.gc.setForeground(traceColorScheme.getColor(TimeGraphColorScheme.MID_LINE)); int midy = bounds.y + bounds.height / 2 - 1; //int midy = e.y + e.height / 2; e.gc.drawLine(e.x, midy, e.x + e.width, midy); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java index 98e39c7cf2..8a58338882 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java @@ -16,10 +16,11 @@ import java.util.Map; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; @@ -42,14 +43,14 @@ public class TickColorDialog extends Dialog { int selectedIndex = 0; Composite colorComposite; - TraceColorScheme traceColorScheme = new TraceColorScheme(); - private TmfTimeAnalysisProvider timeAnalysisProvider = new TmfTimeAnalysisProvider() { + TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme(); + private ITimeGraphProvider timeAnalysisProvider = new TimeGraphProvider() { @Override public StateColor getEventColor(ITimeEvent event) { return null; } @Override - public String getTraceClassName(ITmfTimeAnalysisEntry trace) { + public String getTraceClassName(ITimeGraphEntry trace) { return null; } @Override @@ -112,7 +113,7 @@ public class TickColorDialog extends Dialog { addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { - e.gc.setForeground(traceColorScheme.getColor(TraceColorScheme.MID_LINE)); + e.gc.setForeground(traceColorScheme.getColor(TimeGraphColorScheme.MID_LINE)); int midy = e.y + e.height / 2; e.gc.drawLine(e.x, midy, e.x + e.width, midy); int midx = e.x + e.width / 2; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterView.java index 4166ba58f0..a20fdbc1a5 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterView.java @@ -124,10 +124,13 @@ public class FilterView extends TmfView { fViewer.setSelection(node, true); } - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite) - */ + // ------------------------------------------------------------------------ + // ViewPart + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composite) + */ @Override public void createPartControl(Composite parent) { @@ -150,11 +153,14 @@ public class FilterView extends TmfView { }); } - - // ------------------------------------------------------------------------ - // ViewPart - // ------------------------------------------------------------------------ - + /* (non-Javadoc) + * @see org.eclipse.ui.part.WorkbenchPart#setFocus() + */ + @Override + public void setFocus() { + fViewer.setFocus(); + } + /* * (non-Javadoc) * @see java.lang.Object#toString() diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisEntry.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisEntry.java index c261946753..3a9a24a2ac 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisEntry.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisEntry.java @@ -18,12 +18,11 @@ import java.util.Vector; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; -public class TimeChartAnalysisEntry implements ITmfTimeAnalysisEntry { +public class TimeChartAnalysisEntry implements ITimeGraphEntry { private ITmfTrace fTrace; - private String fGroup; private Vector fTraceEvents; private int fPower = 0; // 2^fPower nanoseconds per vector position private long fReferenceTime = -1; // time corresponding to beginning of index 0 @@ -36,21 +35,19 @@ public class TimeChartAnalysisEntry implements ITmfTimeAnalysisEntry { fTraceEvents = new Vector(modelSize); } - TimeChartAnalysisEntry(ITmfTrace trace, String group, int modelSize) { - fTrace = trace; - fTraceEvents = new Vector(modelSize); - fGroup = group; + @Override + public ITimeGraphEntry[] getChildren() { + return null; } - + @Override - public String getGroupName() { - return fGroup; + public ITimeGraphEntry getParent() { + return null; } @Override - public int getId() { - // TODO Auto-generated method stub - return 0; + public boolean hasChildren() { + return false; } @Override @@ -69,17 +66,12 @@ public class TimeChartAnalysisEntry implements ITmfTimeAnalysisEntry { } @Override - @Deprecated public Vector getTraceEvents() { - return null; - } - - @Override - public Iterator getTraceEventsIterator() { + public Iterator getTimeEventsIterator() { return new EntryIterator(0, Long.MAX_VALUE, 0); } @Override - public Iterator getTraceEventsIterator(long startTime, long stopTime, long maxDuration) { + public Iterator getTimeEventsIterator(long startTime, long stopTime, long maxDuration) { return new EntryIterator(startTime, stopTime, maxDuration); } @@ -119,7 +111,7 @@ public class TimeChartAnalysisEntry implements ITmfTimeAnalysisEntry { next = event; return true; } else { - nestedIterator = event.getItemizedEntry().getTraceEventsIterator(fIteratorStartTime, fIteratorStopTime, fIteratorMaxDuration); + nestedIterator = event.getItemizedEntry().getTimeEventsIterator(fIteratorStartTime, fIteratorStopTime, fIteratorMaxDuration); return nestedIterator.hasNext(); } } @@ -153,7 +145,6 @@ public class TimeChartAnalysisEntry implements ITmfTimeAnalysisEntry { } - @Override public void addTraceEvent(ITimeEvent timeEvent) { long time = timeEvent.getTime(); synchronized (fTraceEvents) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisProvider.java index 692fb329f5..1e70ffa7c1 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisProvider.java @@ -15,17 +15,17 @@ package org.eclipse.linuxtools.tmf.ui.views.timechart; import java.util.Map; import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; -public class TimeChartAnalysisProvider extends TmfTimeAnalysisProvider { +public class TimeChartAnalysisProvider extends TimeGraphProvider { private static final Color BOOKMARK_INNER_COLOR = new Color(Display.getDefault(), 115, 165, 224); private static final Color BOOKMARK_OUTER_COLOR = new Color(Display.getDefault(), 2, 70, 140); @@ -52,7 +52,7 @@ public class TimeChartAnalysisProvider extends TmfTimeAnalysisProvider { } @Override - public String getTraceClassName(ITmfTimeAnalysisEntry entry) { + public String getTraceClassName(ITimeGraphEntry entry) { return null; } @@ -72,7 +72,7 @@ public class TimeChartAnalysisProvider extends TmfTimeAnalysisProvider { } @Override - public void drawState(TraceColorScheme colors, ITimeEvent event, Rectangle rect, GC gc, boolean selected, boolean rectBound, boolean timeSelected) { + public void drawState(TimeGraphColorScheme colors, ITimeEvent event, Rectangle rect, GC gc, boolean selected, boolean rectBound, boolean timeSelected) { if (! ((TimeChartEvent) event).isVisible()) { return; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartEvent.java index 8c1c4540d3..7a5b00d511 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartEvent.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartEvent.java @@ -18,7 +18,7 @@ import java.util.Iterator; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; public class TimeChartEvent implements ITimeEvent { @@ -52,7 +52,7 @@ public class TimeChartEvent implements ITimeEvent { } @Override - public ITmfTimeAnalysisEntry getEntry() { + public ITimeGraphEntry getEntry() { return fParentEntry; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartView.java index 9066674605..77d7f0b1f1 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartView.java @@ -43,22 +43,22 @@ import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting; import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager; import org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener; import org.eclipse.linuxtools.tmf.ui.views.timechart.TimeChartEvent.RankRange; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeAnalysisViewer; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITmfTimeScaleSelectionListener; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITmfTimeSelectionListener; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeScaleSelectionEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeSelectionEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfViewerFactory; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; -public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionListener, ITmfTimeSelectionListener, IColorSettingsListener, +public class TimeChartView extends TmfView implements ITimeGraphRangeListener, ITimeGraphSelectionListener, ITimeGraphTimeListener, IColorSettingsListener, IResourceChangeListener, ITmfEventsFilterListener { public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.timechart"; //$NON-NLS-1$ @@ -66,8 +66,7 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList private static final int TIMESTAMP_SCALE = -9; private final int fDisplayWidth; - private Composite fComposite; - private ITimeAnalysisViewer fViewer; + private TimeGraphViewer fViewer; private final ArrayList fTimeAnalysisEntries = new ArrayList(); private final Map, TimeChartDecorationProvider> fDecorationProviders = new HashMap, TimeChartDecorationProvider>(); private ArrayList fDecorateThreads; @@ -84,18 +83,11 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList @Override public void createPartControl(Composite parent) { - fComposite = new Composite(parent, SWT.NONE); - GridLayout gl = new GridLayout(); - gl.marginWidth = 0; - gl.marginHeight = 0; - fComposite.setLayout(gl); - - fViewer = TmfViewerFactory.createViewer(fComposite, new TimeChartAnalysisProvider()); - fViewer.groupTraces(false); + fViewer = new TimeGraphViewer(parent, SWT.NONE); + fViewer.setTimeGraphProvider(new TimeChartAnalysisProvider()); fViewer.setTimeCalendarFormat(true); - fViewer.setAcceptSelectionAPIcalls(true); - fViewer.addWidgetTimeScaleSelectionListner(this); - fViewer.addWidgetSelectionListner(this); + fViewer.addRangeListener(this); + fViewer.addSelectionListener(this); fViewer.setMinimumItemWidth(1); IEditorReference[] editorReferences = getSite().getPage().getEditorReferences(); @@ -113,7 +105,7 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList } } } - fViewer.display(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0])); + fViewer.setInput(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0])); fDecorateThreads = new ArrayList(); ColorSettingsManager.addColorSettingsListener(this); @@ -132,7 +124,6 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList @Override public void setFocus() { - super.setFocus(); fViewer.setFocus(); } @@ -213,9 +204,6 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList } private void refreshViewer(boolean resetTimeIntervals) { - if (fComposite == null) { - return; - } synchronized (fSyncObj) { if (fRefreshBusy) { fRefreshPending = true; @@ -229,9 +217,9 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList Display.getDefault().asyncExec(new Runnable() { @Override public void run() { - if (fComposite.isDisposed()) + if (fViewer.getControl().isDisposed()) return; - fViewer.display(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0])); + fViewer.setInput(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0])); if (reset) { fViewer.resetStartFinishTime(); } @@ -274,7 +262,7 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList } public void itemizeTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry) { - Iterator iterator = timeAnalysisEntry.getTraceEventsIterator(); + Iterator iterator = timeAnalysisEntry.getTimeEventsIterator(); TimeChartEvent event = null; boolean hasNext = true; while (hasNext) { @@ -363,7 +351,7 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList } public void resetTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry) { - Iterator iterator = timeAnalysisEntry.getTraceEventsIterator(); + Iterator iterator = timeAnalysisEntry.getTimeEventsIterator(); TimeChartEvent event = null; boolean hasNext = true; while (!interrupted && hasNext) { @@ -386,7 +374,7 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList public void decorateTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry, TimeChartEvent parentEvent) { // Set max duration high to ensure iterator does not consider // itemized events - Iterator iterator = timeAnalysisEntry.getTraceEventsIterator(0, Long.MAX_VALUE, Long.MAX_VALUE); + Iterator iterator = timeAnalysisEntry.getTimeEventsIterator(0, Long.MAX_VALUE, Long.MAX_VALUE); TimeChartEvent event = null; int entryPriority = ColorSettingsManager.PRIORITY_NONE; boolean entryIsBookmarked = false; @@ -480,15 +468,15 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList // ------------------------------------------------------------------------ @Override - public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event) { - fStartTime = event.getTime0(); - fStopTime = event.getTime1(); + public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) { + fStartTime = event.getStartTime(); + fStopTime = event.getEndTime(); itemize(fStartTime, fStopTime); } @Override - public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event) { - ITmfTimeAnalysisEntry timeAnalysisEntry = null; + public void selectionChanged(TimeGraphSelectionEvent event) { + ITimeGraphEntry timeAnalysisEntry = null; if (event.getSelection() instanceof TimeChartAnalysisEntry) { timeAnalysisEntry = (TimeChartAnalysisEntry) event.getSelection(); } else if (event.getSelection() instanceof TimeChartEvent) { @@ -497,7 +485,11 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList if (timeAnalysisEntry instanceof TimeChartAnalysisEntry) { broadcast(new TmfTraceSelectedSignal(this, ((TimeChartAnalysisEntry) timeAnalysisEntry).getTrace())); } - broadcast(new TmfTimeSynchSignal(this, new TmfTimestamp(event.getSelectedTime(), TIMESTAMP_SCALE))); + } + + @Override + public void timeSelected(TimeGraphTimeEvent event) { + broadcast(new TmfTimeSynchSignal(this, new TmfTimestamp(event.getTime(), TIMESTAMP_SCALE))); } @Override @@ -587,7 +579,7 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList ITmfTrace trace = signal.getTrace(); for (int i = 0; i < fTimeAnalysisEntries.size(); i++) { if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) { - fViewer.setSelectedTrace(fTimeAnalysisEntries.get(i)); + fViewer.setSelection(fTimeAnalysisEntries.get(i)); break; } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/GridUtil.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/GridUtil.java deleted file mode 100644 index d15f80438a..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/GridUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -/********************************************************************** - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * $Id: GridUtil.java,v 1.3 2006/09/20 19:49:13 ewchan Exp $ - * - * Contributors: - * IBM - Initial API and implementation - **********************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; - -/** - * A utility class to create convenient grid data objects. - */ -public class GridUtil -{ - /** - * Creates a grid data object that occupies vertical and horizontal - * space. - */ - static public GridData createFill() - { - return new GridData(SWT.FILL, SWT.FILL, true, true); - } - /** - * Creates a grid data object that occupies horizontal space. - */ - static public GridData createHorizontalFill() - { - return new GridData(SWT.FILL, SWT.DEFAULT, true, false); - } - /** - * Creates a grid data object that occupies vertical space. - */ - static public GridData createVerticalFill() - { - return new GridData(SWT.DEFAULT, SWT.FILL, false, true); - } -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeAnalysisViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeAnalysisViewer.java deleted file mode 100644 index f8ec1e72dd..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeAnalysisViewer.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - *******************************************************************************/ - - package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.ScrollBar; - -/** - * ITimeAnalysisWidget - *

- * - * TODO: Implement me. Please. - */ -public interface ITimeAnalysisViewer extends ITmfViewer { - - public enum TimeFormat { - RELATIVE, ABSOLUTE - }; - - /** - * @param e - */ - public void controlResized(ControlEvent e); - - /** - * - * @param traceArr - * @param start - * Specifies a fixed start time to the information to be - * displayed - * @param end - * Specifies a fixed end time to the information to be displayed - * @param updateTimeBounds - * If True - Time Range boundaries update is required - */ - public abstract void display(ITmfTimeAnalysisEntry[] traceArr, long start, - long end, boolean updateTimeBounds); - - /** - * The start and End time are taken from the limits used by the children - * events - * - * @param traceArr - */ - public abstract void display(ITmfTimeAnalysisEntry[] traceArr); - - public void addWidgetSelectionListner(ITmfTimeSelectionListener listener); - - public void addWidgetTimeScaleSelectionListner( - ITmfTimeScaleSelectionListener listener); - - public void filterTraces(); - - public ITmfTimeAnalysisEntry getSelectedTrace(); - - public ISelection getSelection(); - - public void groupTraces(boolean on); - - public boolean isInFocus(); - - public void removeWidgetSelectionListner(ITmfTimeSelectionListener listener); - - public void removeWidgetTimeScaleSelectionListner( - ITmfTimeScaleSelectionListener listener); - - public void resetStartFinishTime(); - - public void selectNextEvent(); - - public void selectPrevEvent(); - - public void selectNextTrace(); - - public void selectPrevTrace(); - - public void showLegend(); - - public void zoomIn(); - - public void zoomOut(); - - public void setSelectedTime(long time, boolean ensureVisible, Object source); - - public void setSelectedEvent(ITimeEvent event, Object Source); - - public void setSelectedTraceTime(ITmfTimeAnalysisEntry trace, long time, Object Source); - - public void setSelectVisTimeWindow(long time0, long time1, Object Source); - - public void setAcceptSelectionAPIcalls(boolean acceptCalls); - - public void setTimeCalendarFormat(boolean toAbsoluteCaltime); - - public boolean isCalendarFormat(); - - public boolean isVisibleVerticalScroll(); - - public void setVisibleVerticalScroll(boolean visibleVerticalScroll); - - public int getBorderWidth(); - - public void setBorderWidth(int borderWidth); - - public int getHeaderHeight(); - - public void setHeaderHeight(int headerHeight); - - public int getItemHeight(); - - public void setItemHeight(int rowHeight); - - public void setMinimumItemWidth(int width); - - public void resizeControls(); - - public void setSelectedTrace(ITmfTimeAnalysisEntry trace); - - public ISelection getSelectionTrace(); - - public void setNameWidthPref(int width); - - public int getNameWidthPref(int width); - - public void addFilterSelectionListner(ITmfTimeFilterSelectionListener listener); - - public void removeFilterSelectionListner( - ITmfTimeFilterSelectionListener listener); - - public int getTimeSpace(); - - public void itemUpdate(ITmfTimeAnalysisEntry parent, TimeEvent item); - - public Control getControl(); - - public ISelectionProvider getSelectionProvider(); - - /** - *

- * Provide the possibility to control the wait cursor externally - *

- *

- * e.g. data requests in progress - *

- * - * @param waitInd - * - true change to wait cursor - */ - public void waitCursor(boolean waitInd); - - public void setFocus(); - - /** - * Update the time bounds without changing the visible range - * - * @param beginTime - * @param endTime - */ - public void setTimeBounds(long beginTime, long endTime); - - /** - * Get the horizontal scrollbar - * @return the horizontal scrollbar - */ - public ScrollBar getHorizontalBar(); - - /** - * Get the vertical scrollbar - * @return the vertical scrollbar - */ - public ScrollBar getVerticalBar(); - - /** - * Set the top index - * @param index the top index - */ - public void setTopIndex(int index); - -} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphProvider.java new file mode 100644 index 0000000000..de98ea345f --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphProvider.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.Map; + +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider.StateColor; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphItem; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; + +public interface ITimeGraphProvider { + + public abstract void setTimeGraphControl(TimeGraphControl timeGraphControl); + + public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, TimeGraphItem[] items, int topIndex, int nameSpace, GC gc); + + /** + * Draws the item + * + * @param item the item to draw + * @param bounds the container rectangle + * @param timeProvider the time provider + * @param i the item index + * @param nameSpace the name space + * @param gc + */ + public abstract void drawItem(TimeGraphItem item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc); + + public abstract void drawState(TimeGraphColorScheme colors, ITimeEvent event, Rectangle rect, GC gc, boolean selected, boolean rectBound, boolean timeSelected); + + public abstract void drawState(TimeGraphColorScheme colors, int colorIdx, Rectangle rect, GC gc, boolean selected, boolean rectBound, boolean timeSelected); + + /** + * Uses the abstract method getEventcolor to obtain an enum value and + * convert it to an internal color index + * + * @param event + * @return the internal color index + */ + public abstract int getEventColorVal(ITimeEvent event); + + /** + * Select the color for the different internal variants of events. + * + * @param event + * @return the corresponding event color + */ + public abstract StateColor getEventColor(ITimeEvent event); + + /** + * This values is appended between braces to the right of Trace Name e.g. + * Trace And Error Log [Board 17] or for a Thread trace e.g. State Server + * [java.lang.Thread] + * + * @param trace + * @return the trace class name + */ + public abstract String getTraceClassName(ITimeGraphEntry trace); + + public abstract String getEventName(ITimeEvent event); + + /** + * Specify a Name for the event depending on its type or state e.g. blocked, + * running, etc.. + * + * @param event + * @param upper + * True return String value in Upper case + * @param extInfo + * Verbose, add additional information if applicable + * @return the event name + */ + public abstract String getEventName(ITimeEvent event, boolean upper, boolean extInfo); + + public abstract String composeTraceName(ITimeGraphEntry trace, boolean inclState); + + public abstract String composeEventName(ITimeEvent event); + + public abstract Map getEventHoverToolTipInfo(ITimeEvent event); + + /** + * Provides the image icon for a given Event or Trace e.g. customize to use + * different icons according to specific event /state combination + * + * @param obj + * @return the image icon + */ + public abstract Image getItemImage(Object obj); + + public abstract String getStateName(StateColor color); + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfTimeSelectionListener.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphRangeListener.java similarity index 53% rename from org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfTimeSelectionListener.java rename to org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphRangeListener.java index 7a6a531f0d..7957fa0f9d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfTimeSelectionListener.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphRangeListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson + * Copyright (c) 2012 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -7,18 +7,22 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Initial API and implementation *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; import java.util.EventListener; -/** - * Implemented by any user of TsfTm in order to be notified of available events, - * upon registration - * +/** + * A listener which is notified when a timegraph changes its visible time range. */ -public interface ITmfTimeSelectionListener extends EventListener { - public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event); +public interface ITimeGraphRangeListener extends EventListener { + + /** + * Notifies that the timegraph range has changed. + * + * @param event event object describing details + */ + public void timeRangeUpdated(TimeGraphRangeUpdateEvent event); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfTimeFilterSelectionListener.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphSelectionListener.java similarity index 52% rename from org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfTimeFilterSelectionListener.java rename to org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphSelectionListener.java index 008e52da13..7d77f2f800 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfTimeFilterSelectionListener.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphSelectionListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson + * Copyright (c) 2012 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -7,13 +7,22 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Initial API and implementation *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; import java.util.EventListener; -public interface ITmfTimeFilterSelectionListener extends EventListener { - public void tmfTaProcessFilterSelection(TmfTimeFilterSelectionEvent event); +/** + * A listener which is notified when a timegraph changes its selected time. + */ +public interface ITimeGraphSelectionListener extends EventListener { + + /** + * Notifies that the timegraph selected entry has changed. + * + * @param event event object describing details + */ + public void selectionChanged(TimeGraphSelectionEvent event); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfTimeScaleSelectionListener.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphTimeListener.java similarity index 54% rename from org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfTimeScaleSelectionListener.java rename to org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphTimeListener.java index 173862b7ea..40a6b7a193 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfTimeScaleSelectionListener.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphTimeListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson + * Copyright (c) 2012 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -7,18 +7,22 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Initial API and implementation *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; import java.util.EventListener; -/** - * Implemented by any user of TmfTime in order to be notified of available events, - * upon registration - * +/** + * A listener which is notified when a timegraph changes its selected time. */ -public interface ITmfTimeScaleSelectionListener extends EventListener { - public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event); +public interface ITimeGraphTimeListener extends EventListener { + + /** + * Notifies that the timegraph selected time has changed. + * + * @param event event object describing details + */ + public void timeSelected(TimeGraphTimeEvent event); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphTreeListener.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphTreeListener.java new file mode 100644 index 0000000000..3f9233252a --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphTreeListener.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +/** + * A listener which is notified when a timegraph expands or collapses an entry. + */ +public interface ITimeGraphTreeListener { + + /** + * Notifies that an entry in the timegraph has been collapsed. + * + * @param event event object describing details + */ + public void treeCollapsed(TimeGraphTreeExpansionEvent event); + + /** + * Notifies that an entry in the timegraph has been expanded. + * + * @param event event object describing details + */ + public void treeExpanded(TimeGraphTreeExpansionEvent event); +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfViewer.java deleted file mode 100644 index 57b6197eaf..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITmfViewer.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Francois Chouinard - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -/** - * ITmfWidget - *

- * - * TODO: Implement me. Please. - */ -public interface ITmfViewer { - -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java new file mode 100644 index 0000000000..82634c1158 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java @@ -0,0 +1,557 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ITreeViewerListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeExpansionEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; +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.Slider; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.swt.widgets.TreeItem; + +public class TimeGraphCombo extends Composite { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + private static final Object FILLER = new Object(); + + // ------------------------------------------------------------------------ + // Fields + // ------------------------------------------------------------------------ + + // The tree viewer + private TreeViewer fTreeViewer; + + // The time viewer + private TimeGraphViewer fTimeGraphViewer; + + // The selection listener map + private HashMap fSelectionListenerMap = new HashMap(); + + // Flag to block the tree selection changed listener when triggered by the time graph combo + private boolean fInhibitTreeSelection = false; + + // Number of filler rows used by the tree content provider + private static int fNumFillerRows; + + // ------------------------------------------------------------------------ + // Classes + // ------------------------------------------------------------------------ + + private class TreeContentProviderWrapper implements ITreeContentProvider { + private ITreeContentProvider contentProvider; + + public TreeContentProviderWrapper(ITreeContentProvider contentProvider) { + this.contentProvider = contentProvider; + } + + @Override + public void dispose() { + contentProvider.dispose(); + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + contentProvider.inputChanged(viewer, oldInput, newInput); + } + + @Override + public Object[] getElements(Object inputElement) { + Object[] elements = contentProvider.getElements(inputElement); + // add filler elements to ensure alignment with time analysis viewer + Object[] oElements = Arrays.copyOf(elements, elements.length + fNumFillerRows, new Object[0].getClass()); + for (int i = 0; i < fNumFillerRows; i++) { + oElements[elements.length + i] = FILLER; + } + return oElements; + } + + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof ITimeGraphEntry) { + return contentProvider.getChildren(parentElement); + } else { + return new Object[0]; + } + } + + @Override + public Object getParent(Object element) { + if (element instanceof ITimeGraphEntry) { + return contentProvider.getParent(element); + } else { + return null; + } + } + + @Override + public boolean hasChildren(Object element) { + if (element instanceof ITimeGraphEntry) { + return contentProvider.hasChildren(element); + } else { + return false; + } + } + } + + private class TreeLabelProviderWrapper implements ITableLabelProvider { + private ITableLabelProvider labelProvider; + + public TreeLabelProviderWrapper(ITableLabelProvider labelProvider) { + this.labelProvider = labelProvider; + } + + @Override + public void addListener(ILabelProviderListener listener) { + labelProvider.addListener(listener); + } + + @Override + public void dispose() { + labelProvider.dispose(); + } + + @Override + public boolean isLabelProperty(Object element, String property) { + if (element instanceof ITimeGraphEntry) { + return labelProvider.isLabelProperty(element, property); + } else { + return false; + } + } + + @Override + public void removeListener(ILabelProviderListener listener) { + labelProvider.removeListener(listener); + } + + @Override + public Image getColumnImage(Object element, int columnIndex) { + if (element instanceof ITimeGraphEntry) { + return labelProvider.getColumnImage(element, columnIndex); + } else { + return null; + } + } + + @Override + public String getColumnText(Object element, int columnIndex) { + if (element instanceof ITimeGraphEntry) { + return labelProvider.getColumnText(element, columnIndex); + } else { + return null; + } + } + + } + + private class SelectionListenerWrapper implements ISelectionChangedListener, ITimeGraphSelectionListener { + private ITimeGraphSelectionListener listener; + private ITimeGraphEntry selection = null; + + public SelectionListenerWrapper(ITimeGraphSelectionListener listener) { + this.listener = listener; + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + if (fInhibitTreeSelection) { + return; + } + ITimeGraphEntry entry = (ITimeGraphEntry) ((IStructuredSelection) event.getSelection()).getFirstElement(); + if (entry != selection) { + selection = entry; + listener.selectionChanged(new TimeGraphSelectionEvent(event.getSource(), selection)); + } + } + + @Override + public void selectionChanged(TimeGraphSelectionEvent event) { + ITimeGraphEntry entry = event.getSelection(); + if (entry != selection) { + selection = entry; + listener.selectionChanged(new TimeGraphSelectionEvent(event.getSource(), selection)); + } + } + } + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public TimeGraphCombo(Composite parent, int style) { + super(parent, style); + setLayout(new FillLayout()); + + final SashForm sash = new SashForm(this, SWT.NONE); + + fTreeViewer = new TreeViewer(sash, SWT.FULL_SELECTION | SWT.H_SCROLL); + final Tree tree = fTreeViewer.getTree(); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + + fTimeGraphViewer = new TimeGraphViewer(sash, SWT.NONE); + fTimeGraphViewer.setItemHeight(tree.getItemHeight() + getTreeItemHeightAdjustement()); + fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight()); + fTimeGraphViewer.setBorderWidth(tree.getBorderWidth()); + fTimeGraphViewer.setNameWidthPref(0); + + fTreeViewer.addTreeListener(new ITreeViewerListener() { + @Override + public void treeCollapsed(TreeExpansionEvent event) { + fTimeGraphViewer.setExpandedState((ITimeGraphEntry) event.getElement(), false); + } + + @Override + public void treeExpanded(TreeExpansionEvent event) { + fTimeGraphViewer.setExpandedState((ITimeGraphEntry) event.getElement(), true); + } + }); + + fTimeGraphViewer.addTreeListener(new ITimeGraphTreeListener() { + @Override + public void treeCollapsed(TimeGraphTreeExpansionEvent event) { + fTreeViewer.setExpandedState(event.getEntry(), false); + } + + @Override + public void treeExpanded(TimeGraphTreeExpansionEvent event) { + fTreeViewer.setExpandedState(event.getEntry(), true); + } + }); + + // prevent mouse button from selecting a filler tree item + tree.addListener(SWT.MouseDown, new Listener() { + @Override + public void handleEvent(Event event) { + TreeItem treeItem = tree.getItem(new Point(event.x, event.y)); + if (treeItem == null || treeItem.getData() == FILLER) { + event.doit = false; + ArrayList treeItems = getVisibleExpandedItems(tree); + if (treeItems.size() == 0) { + return; + } + // this prevents from scrolling up when selecting + // the partially visible tree item at the bottom + tree.select(treeItems.get(treeItems.size() - 1)); + fTreeViewer.setSelection(new StructuredSelection()); + fTimeGraphViewer.setSelection(null); + } + } + }); + + tree.addListener(SWT.MouseWheel, new Listener() { + @Override + public void handleEvent(Event event) { + event.doit = false; + Slider scrollBar = fTimeGraphViewer.getVerticalBar(); + fTimeGraphViewer.setTopIndex(scrollBar.getSelection() - event.count); + ArrayList treeItems = getVisibleExpandedItems(tree); + if (treeItems.size() == 0) { + return; + } + TreeItem treeItem = treeItems.get(fTimeGraphViewer.getTopIndex()); + tree.setTopItem(treeItem); + } + }); + + // prevent key stroke from selecting a filler tree item + tree.addListener(SWT.KeyDown, new Listener() { + @Override + public void handleEvent(Event event) { + ArrayList treeItems = getVisibleExpandedItems(tree); + if (treeItems.size() == 0) { + return; + } + if (event.keyCode == SWT.ARROW_DOWN) { + int index = Math.min(fTimeGraphViewer.getSelectionIndex() + 1, treeItems.size() - 1); + fTimeGraphViewer.setSelection((ITimeGraphEntry) treeItems.get(index).getData()); + event.doit = false; + } else if (event.keyCode == SWT.PAGE_DOWN) { + int height = tree.getSize().y - tree.getHeaderHeight() - tree.getHorizontalBar().getSize().y; + int countPerPage = height / (tree.getItemHeight() + getTreeItemHeightAdjustement()); + int index = Math.min(fTimeGraphViewer.getSelectionIndex() + countPerPage - 1, treeItems.size() - 1); + fTimeGraphViewer.setSelection((ITimeGraphEntry) treeItems.get(index).getData()); + event.doit = false; + } else if (event.keyCode == SWT.END) { + fTimeGraphViewer.setSelection((ITimeGraphEntry) treeItems.get(treeItems.size() - 1).getData()); + event.doit = false; + } + TreeItem treeItem = treeItems.get(fTimeGraphViewer.getTopIndex()); + tree.setTopItem(treeItem); + if (fTimeGraphViewer.getSelectionIndex() >= 0) { + fTreeViewer.setSelection(new StructuredSelection(fTimeGraphViewer.getSelection())); + } else { + fTreeViewer.setSelection(new StructuredSelection()); + } + } + }); + + fTimeGraphViewer.getTimeGraphControl().addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + ArrayList treeItems = getVisibleExpandedItems(tree); + if (treeItems.size() == 0) { + return; + } + TreeItem treeItem = treeItems.get(fTimeGraphViewer.getTopIndex()); + tree.setTopItem(treeItem); + } + }); + + fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + if (fInhibitTreeSelection) { + return; + } + if (event.getSelection() instanceof IStructuredSelection) { + Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement(); + ArrayList treeItems = getVisibleExpandedItems(tree); + if (selection instanceof ITimeGraphEntry) { + fTimeGraphViewer.setSelection((ITimeGraphEntry) selection); + } + TreeItem treeItem = treeItems.get(fTimeGraphViewer.getTopIndex()); + tree.setTopItem(treeItem); + } + } + }); + + fTimeGraphViewer.addSelectionListener(new ITimeGraphSelectionListener() { + @Override + public void selectionChanged(TimeGraphSelectionEvent event) { + ITimeGraphEntry entry = fTimeGraphViewer.getSelection(); + fInhibitTreeSelection = true; // block the tree selection changed listener + if (entry != null) { + StructuredSelection selection = new StructuredSelection(entry); + fTreeViewer.setSelection(selection); + } else { + fTreeViewer.setSelection(new StructuredSelection()); + } + fInhibitTreeSelection = false; + ArrayList treeItems = getVisibleExpandedItems(tree); + if (treeItems.size() == 0) { + return; + } + TreeItem treeItem = treeItems.get(fTimeGraphViewer.getTopIndex()); + tree.setTopItem(treeItem); + } + }); + + fTimeGraphViewer.getVerticalBar().addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + ArrayList treeItems = getVisibleExpandedItems(tree); + if (treeItems.size() == 0) { + return; + } + TreeItem treeItem = treeItems.get(fTimeGraphViewer.getTopIndex()); + tree.setTopItem(treeItem); + } + }); + + fNumFillerRows = Display.getDefault().getBounds().height / (tree.getItemHeight() + getTreeItemHeightAdjustement()); + + sash.setWeights(new int[] { 1, 1 }); + } + + private ArrayList getVisibleExpandedItems(Tree tree) { + ArrayList items = new ArrayList(); + for (TreeItem item : tree.getItems()) { + if (item.getData() == FILLER) { + break; + } + items.add(item); + if (item.getExpanded()) { + items.addAll(getVisibleExpandedItems(item)); + } + } + return items; + } + + private ArrayList getVisibleExpandedItems(TreeItem treeItem) { + ArrayList items = new ArrayList(); + for (TreeItem item : treeItem.getItems()) { + items.add(item); + if (item.getExpanded()) { + items.addAll(getVisibleExpandedItems(item)); + } + } + return items; + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + /** + * Returns this time graph combo's tree viewer. + * + * @return the tree viewer + */ + public TreeViewer getTreeViewer() { + return fTreeViewer; + } + + /** + * Returns this time graph combo's time graph viewer. + * + * @return the time graph viewer + */ + public TimeGraphViewer getTimeGraphViewer() { + return fTimeGraphViewer; + } + + // ------------------------------------------------------------------------ + // Internal + // ------------------------------------------------------------------------ + + /* + * SWT doesn't seem to report correctly the tree item height, at least in + * the case of KDE. + * + * This method provides an adjustment term according to the desktop session. + * + * @return Height adjustment + */ + private int getTreeItemHeightAdjustement() { + int ajustement = 0; + String desktopSession = System.getenv("DESKTOP_SESSION"); //$NON-NLS-1$ + + if (desktopSession != null) { + if (desktopSession.equals("kde")) { //$NON-NLS-1$ + ajustement = 2; + } + } + + return ajustement; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Sets the tree content provider used by this time graph combo. + * + * @param contentProvider the tree content provider + */ + public void setTreeContentProvider(ITreeContentProvider contentProvider) { + fTreeViewer.setContentProvider(new TreeContentProviderWrapper(contentProvider)); + } + + /** + * Sets the tree label provider used by this time graph combo. + * + * @param treeLabelProvider the tree label provider + */ + public void setTreeLabelProvider(ITableLabelProvider labelProvider) { + fTreeViewer.setLabelProvider(new TreeLabelProviderWrapper(labelProvider)); + } + + /** + * Sets the tree columns for this time graph combo. + * + * @param columnNames the tree column names + */ + public void setTreeColumns(String[] columnNames) { + final Tree tree = fTreeViewer.getTree(); + for (String columnName : columnNames) { + TreeColumn column = new TreeColumn(tree, SWT.LEFT); + column.setText(columnName); + column.pack(); + } + } + + + /** + * Sets the time graph provider used by this time graph combo. + * + * @param timeGraphProvider the time graph provider + */ + public void setTimeGraphProvider(ITimeGraphProvider timeGraphProvider) { + fTimeGraphViewer.setTimeGraphProvider(timeGraphProvider); + } + + /** + * Sets or clears the input for this time graph combo. + * + * @param input the input of this time graph combo, or null if none + */ + public void setInput(ITimeGraphEntry[] input) { + fTreeViewer.setInput(input); + fTreeViewer.expandAll(); + fTreeViewer.getTree().getVerticalBar().setEnabled(false); + fTimeGraphViewer.setInput(input); + } + + /** + * Refreshes this time graph completely with information freshly obtained from its model. + */ + public void refresh() { + fTreeViewer.refresh(); + fTimeGraphViewer.refresh(); + } + + /** + * Adds a listener for selection changes in this time graph combo. + * + * @param listener a selection listener + */ + public void addSelectionListener(ITimeGraphSelectionListener listener) { + SelectionListenerWrapper listenerWrapper = new SelectionListenerWrapper(listener); + fTreeViewer.addSelectionChangedListener(listenerWrapper); + fSelectionListenerMap.put(listener, listenerWrapper); + fTimeGraphViewer.addSelectionListener(listenerWrapper); + } + + /** + * Removes the given selection listener from this time graph combo. + * + * @param listener a selection changed listener + */ + public void removeSelectionListener(ITimeGraphSelectionListener listener) { + SelectionListenerWrapper listenerWrapper = fSelectionListenerMap.remove(listener); + fTreeViewer.removeSelectionChangedListener(listenerWrapper); + fTimeGraphViewer.removeSelectionListener(listenerWrapper); + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphProvider.java new file mode 100644 index 0000000000..453676064f --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphProvider.java @@ -0,0 +1,223 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010, 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Refactoring + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.Map; + +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphItem; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; + +public abstract class TimeGraphProvider implements ITimeGraphProvider { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + public enum StateColor { + GREEN, DARK_BLUE, RED, GOLD, ORANGE, GRAY, BLACK, DARK_GREEN, DARK_YELLOW, MAGENTA3, PURPLE1, PINK1, AQUAMARINE, LIGHT_BLUE, CADET_BLUE, OLIVE; + + private String stateName; + + StateColor() { + String undef = "Undefined"; //$NON-NLS-1$ + this.stateName = undef; + } + + public String getStateName() { + return stateName; + } + + public void setStateName(String stateName) { + this.stateName = stateName; + } + } + + // ------------------------------------------------------------------------ + // Fields + // ------------------------------------------------------------------------ + + protected TimeGraphControl fTimeGraphControl; + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + public void setTimeGraphControl(TimeGraphControl timeGraphControl) { + fTimeGraphControl = timeGraphControl; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#drawItems(org.eclipse.swt.graphics.Rectangle, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider.Item[], int, int, org.eclipse.swt.graphics.GC) + */ + public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, TimeGraphItem[] items, int topIndex, int nameSpace, GC gc) { + fTimeGraphControl.drawItems(bounds, timeProvider, items, topIndex, nameSpace, gc); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#drawItem(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider.Item, org.eclipse.swt.graphics.Rectangle, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider, int, int, org.eclipse.swt.graphics.GC) + */ + @Override + public void drawItem(TimeGraphItem item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) { + fTimeGraphControl.drawItem(item, bounds, timeProvider, i, nameSpace, gc); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#drawState(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC, boolean, boolean, boolean) + */ + @Override + public void drawState(TimeGraphColorScheme colors, ITimeEvent event, + Rectangle rect, GC gc, boolean selected, boolean rectBound, + boolean timeSelected) { + int colorIdx = getEventColorVal(event); + drawState(colors, colorIdx, rect, gc, selected, rectBound, timeSelected); + + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#drawState(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme, int, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC, boolean, boolean, boolean) + */ + @Override + public void drawState(TimeGraphColorScheme colors, int colorIdx, + Rectangle rect, GC gc, boolean selected, boolean rectBound, + boolean timeSelected) { + fTimeGraphControl.drawState(colors, colorIdx, rect, gc, selected, rectBound, timeSelected); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventColorVal(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public int getEventColorVal(ITimeEvent event) { + StateColor colors = getEventColor(event); + if (colors == StateColor.GREEN) { + return TimeGraphColorScheme.GREEN_STATE; + } else if (colors == StateColor.DARK_BLUE) { + return TimeGraphColorScheme.DARK_BLUE_STATE; + } else if (colors == StateColor.RED) { + return TimeGraphColorScheme.RED_STATE; + } else if (colors == StateColor.GOLD) { + return TimeGraphColorScheme.GOLD_STATE; + } else if (colors == StateColor.ORANGE) { + return TimeGraphColorScheme.ORANGE_STATE; + } else if (colors == StateColor.GRAY) { + return TimeGraphColorScheme.GRAY_STATE; + } else if (colors == StateColor.DARK_GREEN) { + return TimeGraphColorScheme.DARK_GREEN_STATE; + } else if (colors == StateColor.DARK_YELLOW) { + return TimeGraphColorScheme.DARK_YELLOW_STATE; + } else if (colors == StateColor.MAGENTA3) { + return TimeGraphColorScheme.MAGENTA3_STATE; + } else if (colors == StateColor.PURPLE1) { + return TimeGraphColorScheme.PURPLE1_STATE; + } else if (colors == StateColor.PINK1) { + return TimeGraphColorScheme.PINK1_STATE; + } else if (colors == StateColor.AQUAMARINE) { + return TimeGraphColorScheme.AQUAMARINE_STATE; + } else if (colors == StateColor.LIGHT_BLUE) { + return TimeGraphColorScheme.LIGHT_BLUE_STATE; + } else if (colors == StateColor.CADET_BLUE) { + return TimeGraphColorScheme.CADET_BLUE_STATE_SEL; + } else if (colors == StateColor.OLIVE) { + return TimeGraphColorScheme.OLIVE_STATE; + } + + return TimeGraphColorScheme.BLACK_STATE; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventColor(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public abstract StateColor getEventColor(ITimeEvent event); + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getTraceClassName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) + */ + @Override + public abstract String getTraceClassName(ITimeGraphEntry trace); + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public String getEventName(ITimeEvent event) { + return getEventName(event, true, false); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent, boolean, boolean) + */ + @Override + public abstract String getEventName(ITimeEvent event, boolean upper, + boolean extInfo); + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#composeTraceName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry, boolean) + */ + @Override + public String composeTraceName(ITimeGraphEntry trace, boolean inclState) { + String name = trace.getName(); + String threadClass = getTraceClassName(trace); + if (threadClass != null && threadClass.length() > 0) { + name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#composeEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public String composeEventName(ITimeEvent event) { + String name = event.getEntry().getName(); + String threadClass = getTraceClassName(event.getEntry()); + if (threadClass != null && threadClass.length() > 0) { + name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + name += " (" + getEventName(event, false, true) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventHoverToolTipInfo(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public abstract Map getEventHoverToolTipInfo(ITimeEvent event); + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getItemImage(java.lang.Object) + */ + @Override + public Image getItemImage(Object obj) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getStateName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider.StateColor) + */ + @Override + public abstract String getStateName(StateColor color); + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphRangeUpdateEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphRangeUpdateEvent.java new file mode 100644 index 0000000000..7ecfdea92d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphRangeUpdateEvent.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.EventObject; + +public class TimeGraphRangeUpdateEvent extends EventObject { + + /** + * Default serial version UID for this class. + * @since 1.0 + */ + private static final long serialVersionUID = 1L; + + /** + * The start time. + */ + private long fStartTime; + + /** + * The end time. + */ + private long fEndTime; + + public TimeGraphRangeUpdateEvent(Object source, long startTime, long endTime) { + super(source); + fStartTime = startTime; + fEndTime = endTime; + } + + /** + * @return the start time + */ + public long getStartTime() { + return fStartTime; + } + + /** + * @return the end time + */ + public long getEndTime() { + return fEndTime; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphSelectionEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphSelectionEvent.java new file mode 100644 index 0000000000..a955e708e1 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphSelectionEvent.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.EventObject; + +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; + +public class TimeGraphSelectionEvent extends EventObject { + + /** + * Default serial version UID for this class. + * @since 1.0 + */ + private static final long serialVersionUID = 1L; + + /** + * The selected entry. + */ + private ITimeGraphEntry fSelection; + + public TimeGraphSelectionEvent(Object source, ITimeGraphEntry selection) { + super(source); + fSelection = selection; + } + + /** + * @return the selected entry or null if the selection is empty. + */ + public ITimeGraphEntry getSelection() { + return fSelection; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphTimeEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphTimeEvent.java new file mode 100644 index 0000000000..9c1fc09365 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphTimeEvent.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.EventObject; + +public class TimeGraphTimeEvent extends EventObject { + + /** + * Default serial version UID for this class. + * @since 1.0 + */ + private static final long serialVersionUID = 1L; + + /** + * The selected time. + */ + private long fTime; + + public TimeGraphTimeEvent(Object source, long time) { + super(source); + fTime = time; + } + + /** + * @return the selected time + */ + public long getTime() { + return fTime; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphTreeExpansionEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphTreeExpansionEvent.java new file mode 100644 index 0000000000..2092c3a224 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphTreeExpansionEvent.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.EventObject; + +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; + +public class TimeGraphTreeExpansionEvent extends EventObject { + + /** + * Default serial version UID for this class. + * @since 1.0 + */ + private static final long serialVersionUID = 1L; + + /** + * The entry that was expanded or collapsed. + */ + private ITimeGraphEntry fEntry; + + /** + * Creates a new event for the given source and entry. + * + * @param source the tree viewer + * @param entry the entry + */ + public TimeGraphTreeExpansionEvent(Object source, ITimeGraphEntry entry) { + super(source); + fEntry = entry; + } + + /** + * Returns the entry that got expanded or collapsed. + * + * @return the entry + */ + public ITimeGraphEntry getEntry() { + return fEntry; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java new file mode 100644 index 0000000000..914dbf3ef4 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java @@ -0,0 +1,840 @@ +/***************************************************************************** + * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2010, 2011, 2012 Ericsson. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - Initial API and implementation + * Ruslan A. Scherbakov, Intel - Initial API and implementation + * Alexander N. Alexeev, Intel - Add monitors statistics support + * Alvaro Sanchez-Leon - Adapted for TMF + * Patrick Tasse - Refactoring + * + *****************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.ArrayList; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs.TimeGraphLegend; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphScale; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphTooltipHandler; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.swt.widgets.Slider; + +public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { + + /** vars */ + private long _minTimeInterval; + private long _selectedTime; + private ITimeGraphEntry _selectedEntry; + private long _beginTime; + private long _endTime; + private long _time0; + private long _time1; + private long _time0_; + private long _time1_; + private long _time0_extSynch = 0; + private long _time1_extSynch = 0; + private boolean _timeRangeFixed; + private int _nameWidthPref = 200; + private int _minNameWidth = 6; + private int _nameWidth; + private Composite _dataViewer; + + private TimeGraphControl _stateCtrl; + private TimeGraphScale _timeScaleCtrl; + private Slider _verticalScrollBar; + private TimeGraphTooltipHandler _threadTip; + private TimeGraphColorScheme _colors; + private ITimeGraphProvider fTimeGraphProvider; + + ArrayList fSelectionListeners = new ArrayList(); + ArrayList fTimeListeners = new ArrayList(); + ArrayList fRangeListeners = new ArrayList(); + + // Calender Time format, using Epoch reference or Relative time + // format(default + private boolean calendarTimeFormat = false; + private int borderWidth = 4; + private int timeScaleHeight = 22; + + /** ctor */ + public TimeGraphViewer(Composite parent, int style) { + createDataViewer(parent, style); + } + + /** + * Sets the timegraph provider used by this timegraph viewer. + * + * @param timeGraphProvider the timegraph provider + */ + public void setTimeGraphProvider(ITimeGraphProvider timeGraphProvider) { + fTimeGraphProvider = timeGraphProvider; + _stateCtrl.setTimeGraphProvider(timeGraphProvider); + _threadTip = new TimeGraphTooltipHandler(_dataViewer.getShell(), fTimeGraphProvider, this); + _threadTip.activateHoverHelp(_stateCtrl); + } + + public void setInput(ITimeGraphEntry[] input) { + if (null != _stateCtrl) { + if (null == input) { + input = new ITimeGraphEntry[0]; + } + setTimeRange(input); + _verticalScrollBar.setEnabled(true); + setTopIndex(0); + refreshAllData(input); + } + } + + public void refresh() { + _stateCtrl.redraw(); + _timeScaleCtrl.redraw(); + } + + public void controlMoved(ControlEvent e) { + } + + public void controlResized(ControlEvent e) { + resizeControls(); + } + + // called from the display order in the API + public void modelUpdate(ITimeGraphEntry[] traces, long start, + long end, boolean updateTimeBounds) { + if (null != _stateCtrl) { + //loadOptions(); + updateInternalData(traces, start, end); + if (updateTimeBounds) { + _timeRangeFixed = true; + // set window to match limits + setStartFinishTime(_time0_, _time1_); + } else { + _stateCtrl.redraw(); + _timeScaleCtrl.redraw(); + } + } + } + + public void selectionChanged() { + } + + protected String getViewTypeStr() { + return "viewoption.threads"; //$NON-NLS-1$ + } + + int getMarginWidth(int idx) { + return 0; + } + + int getMarginHeight(int idx) { + return 0; + } + + void loadOptions() { + _minTimeInterval = 1; + _selectedTime = -1; + _nameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$ + _nameWidthPref, _minNameWidth, 1000); + } + + void saveOptions() { + Utils.saveIntOption(getPreferenceString("namewidth"), _nameWidth); //$NON-NLS-1$ + } + + protected Control createDataViewer(Composite parent, int style) { + loadOptions(); + _colors = new TimeGraphColorScheme(); + _dataViewer = new Composite(parent, style); + GridLayout gl = new GridLayout(2, false); + gl.marginHeight = borderWidth; + gl.marginWidth = 0; + gl.verticalSpacing = 0; + gl.horizontalSpacing = 0; + _dataViewer.setLayout(gl); + + _timeScaleCtrl = new TimeGraphScale(_dataViewer, _colors); + _timeScaleCtrl.setTimeProvider(this); + _timeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false)); + _timeScaleCtrl.setHeight(timeScaleHeight); + + _verticalScrollBar = new Slider(_dataViewer, SWT.VERTICAL | SWT.NO_FOCUS); + _verticalScrollBar.setLayoutData(new GridData(SWT.DEFAULT, SWT.FILL, false, true, 1, 2)); + _verticalScrollBar.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setTopIndex(_verticalScrollBar.getSelection()); + } + }); + _verticalScrollBar.setEnabled(false); + + _stateCtrl = createTimeGraphControl(); + + _stateCtrl.setTimeProvider(this); + _stateCtrl.addSelectionListener(this); + _stateCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2)); + + Composite filler = new Composite(_dataViewer, SWT.NONE); + GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false); + gd.heightHint = _stateCtrl.getHorizontalBar().getSize().y; + filler.setLayoutData(gd); + filler.setLayout(new FillLayout()); + + _stateCtrl.addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent event) { + resizeControls(); + } + }); + resizeControls(); + _dataViewer.update(); + adjustVerticalScrollBar(); + return _dataViewer; + } + + public void dispose() { + saveOptions(); + _stateCtrl.dispose(); + _dataViewer.dispose(); + _colors.dispose(); + } + + protected TimeGraphControl createTimeGraphControl() { + return new TimeGraphControl(_dataViewer, _colors); + } + + public void resizeControls() { + Rectangle r = _dataViewer.getClientArea(); + if (r.isEmpty()) + return; + + int width = r.width; + if (_nameWidth > width - _minNameWidth) + _nameWidth = width - _minNameWidth; + if (_nameWidth < _minNameWidth) + _nameWidth = _minNameWidth; + adjustVerticalScrollBar(); + } + + /** Tries to set most convenient time range for display. */ + void setTimeRange(Object traces[]) { + _endTime = 0; + _beginTime = -1; + // ITimeEvent event; + for (int i = 0; i < traces.length; i++) { + ITimeGraphEntry entry = (ITimeGraphEntry) traces[i]; + if (entry.getStopTime() >= entry.getStartTime() && entry.getStopTime() > 0) { + if (_beginTime < 0 || entry.getStartTime() < _beginTime) { + _beginTime = entry.getStartTime(); + } + if (entry.getStopTime() > _endTime) { + _endTime = entry.getStopTime(); + } + } + /* + * This is not needed if entry startTime and stopTime are properly set! + List list = entry.getTraceEvents(); + int len = list.size(); + if (len > 0) { + event = (ITimeEvent) list.get(0); + if (_beginTime < 0 || event.getTime() < _beginTime) { + _beginTime = event.getTime(); + } + event = (ITimeEvent) list.get(list.size() - 1); + long eventEndTime = event.getTime() + (event.getDuration() > 0 ? event.getDuration() : 0); + if (eventEndTime > _endTime) { + _endTime = eventEndTime; + } + } + */ + } + + if (_beginTime < 0) + _beginTime = 0; + } + + void setTimeBounds() { + //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02); + _time0_ = _beginTime; + if (_time0_ < 0) + _time0_ = 0; + // _time1_ = _time0_ + (_endTime - _time0_) * 1.05; + _time1_ = _endTime; + // _time0_ = Math.floor(_time0_); + // _time1_ = Math.ceil(_time1_); + if (!_timeRangeFixed) { + _time0 = _time0_; + _time1 = _time1_; + } + if (_time1 - _time0 < _minTimeInterval) { + _time1 = _time0 + _minTimeInterval; + } + } + + /** + * @param traces + * @param start + * @param end + */ + void updateInternalData(ITimeGraphEntry[] traces, long start, long end) { + if (null == traces) + traces = new ITimeGraphEntry[0]; + if ((start == 0 && end == 0) || start < 0 || end < 0) { + // Start and end time are unspecified and need to be determined from + // individual processes + setTimeRange(traces); + } else { + _beginTime = start; + _endTime = end; + } + + refreshAllData(traces); + } + + /** + * @param traces + */ + private void refreshAllData(ITimeGraphEntry[] traces) { + setTimeBounds(); + if (_selectedTime < _beginTime) { + _selectedTime = _beginTime; + } else if (_selectedTime > _endTime) { + _selectedTime = _endTime; + } + _stateCtrl.refreshData(traces); + adjustVerticalScrollBar(); + } + + public void setFocus() { + if (null != _stateCtrl) + _stateCtrl.setFocus(); + } + + public boolean isInFocus() { + return _stateCtrl.isInFocus(); + } + + public ITimeGraphEntry getSelection() { + return _stateCtrl.getSelectedTrace(); + } + + public int getSelectionIndex() { + return _stateCtrl.getSelectedIndex(); + } + + @Override + public long getTime0() { + return _time0; + } + + @Override + public long getTime1() { + return _time1; + } + + @Override + public long getMinTimeInterval() { + return _minTimeInterval; + } + + @Override + public int getNameSpace() { + return _nameWidth; + } + + @Override + public void setNameSpace(int width) { + _nameWidth = width; + width = _stateCtrl.getClientArea().width; + if (_nameWidth > width - 6) + _nameWidth = width - 6; + if (_nameWidth < 6) + _nameWidth = 6; + _stateCtrl.adjustScrolls(); + _stateCtrl.redraw(); + _timeScaleCtrl.redraw(); + } + + @Override + public int getTimeSpace() { + int w = _stateCtrl.getClientArea().width; + return w - _nameWidth; + } + + @Override + public long getSelectedTime() { + return _selectedTime; + } + + @Override + public long getBeginTime() { + return _beginTime; + } + + @Override + public long getEndTime() { + return _endTime; + } + + @Override + public long getMaxTime() { + return _time1_; + } + + @Override + public long getMinTime() { + return _time0_; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider + * #setStartFinishTimeNotify(long, long) + */ + @Override + public void setStartFinishTimeNotify(long time0, long time1) { + setStartFinishTime(time0, time1); + notifyRangeListeners(time0, time1); + } + + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime() + */ + @Override + public void notifyStartFinishTime() { + notifyRangeListeners(_time0, _time1); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider + * #setStartFinishTime(long, long) + */ + @Override + public void setStartFinishTime(long time0, long time1) { + _time0 = time0; + if (_time0 < _time0_) + _time0 = _time0_; + if (_time0 > _time1_) + _time0 = _time1_; + _time1 = time1; + if (_time1 < _time0_) + _time1 = _time0_; + if (_time1 > _time1_) + _time1 = _time1_; + if (_time1 - _time0 < _minTimeInterval) + _time1 = _time0 + _minTimeInterval; + _timeRangeFixed = true; + _stateCtrl.adjustScrolls(); + _stateCtrl.redraw(); + _timeScaleCtrl.redraw(); + } + + public void setTimeBounds(long beginTime, long endTime) { + _beginTime = beginTime; + _endTime = endTime; + _time0_ = beginTime; + _time1_ = endTime; + _stateCtrl.adjustScrolls(); + } + + @Override + public void resetStartFinishTime() { + setStartFinishTimeNotify(_time0_, _time1_); + _timeRangeFixed = false; + } + + @Override + public void setSelectedTimeInt(long time, boolean ensureVisible) { + // Trace.debug("currentTime:" + _selectedTime + " new time:" + time); + if (time > _endTime) { + _endTime = time; + _time1_ = time; + } + if (time < _beginTime) { + _beginTime = time; + _time0_ = time; + } + long time0 = _time0; + long time1 = _time1; + if (ensureVisible) { + double timeSpace = (_time1 - _time0) * .02; + double timeMid = (_time1 - _time0) * .1; + if (time < _time0 + timeSpace) { + long dt = (long) (_time0 - time + timeMid); + _time0 -= dt; + _time1 -= dt; + } else if (time > _time1 - timeSpace) { + long dt = (long) (time - _time1 + timeMid); + _time0 += dt; + _time1 += dt; + } + if (_time0 < _time0_) { + _time1 = Math.min(_time1_, _time1 + (_time0_ - _time0)); + _time0 = _time0_; + } else if (_time1 > _time1_) { + _time0 = Math.max(_time0_, _time0 - (_time1 - _time1_)); + _time1 = _time1_; + } + } + if (_time1 - _time0 < _minTimeInterval) { + _time1 = _time0 + _minTimeInterval; + } + _stateCtrl.adjustScrolls(); + _stateCtrl.redraw(); + _timeScaleCtrl.redraw(); + if (time0 != _time0 || time1 != _time1) { + notifyRangeListeners(_time0, _time1); + } + if (time != _selectedTime) { + _selectedTime = time; + notifyTimeListeners(_selectedTime); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + if (_selectedEntry != getSelection()) { + _selectedEntry = getSelection(); + notifySelectionListeners(_selectedEntry); + } + } + + @Override + public void widgetSelected(SelectionEvent e) { + if (_selectedEntry != getSelection()) { + _selectedEntry = getSelection(); + notifySelectionListeners(_selectedEntry); + } + } + + public void selectNextEvent() { + _stateCtrl.selectNextEvent(); + adjustVerticalScrollBar(); + } + + public void selectPrevEvent() { + _stateCtrl.selectPrevEvent(); + adjustVerticalScrollBar(); + } + + public void selectNextTrace() { + _stateCtrl.selectNextTrace(); + adjustVerticalScrollBar(); + } + + public void selectPrevTrace() { + _stateCtrl.selectPrevTrace(); + adjustVerticalScrollBar(); + } + + public void showLegend() { + if (_dataViewer == null || _dataViewer.isDisposed()) + return; + + TimeGraphLegend.open(_dataViewer.getShell(), fTimeGraphProvider); + } + + public void zoomIn() { + _stateCtrl.zoomIn(); + } + + public void zoomOut() { + _stateCtrl.zoomOut(); + } + + private String getPreferenceString(String string) { + return getViewTypeStr() + "." + string; //$NON-NLS-1$ + } + + public void addSelectionListener(ITimeGraphSelectionListener listener) { + fSelectionListeners.add(listener); + } + + public void removeSelectionListener(ITimeGraphSelectionListener listener) { + fSelectionListeners.remove(listener); + } + + private void notifySelectionListeners(ITimeGraphEntry selection) { + TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection); + + for (ITimeGraphSelectionListener listener : fSelectionListeners) { + listener.selectionChanged(event); + } + } + + public void addTimeListener(ITimeGraphTimeListener listener) { + fTimeListeners.add(listener); + } + + public void removeTimeListener(ITimeGraphTimeListener listener) { + fTimeListeners.remove(listener); + } + + private void notifyTimeListeners(long time) { + TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, time); + + for (ITimeGraphTimeListener listener : fTimeListeners) { + listener.timeSelected(event); + } + } + + public void addRangeListener(ITimeGraphRangeListener listener) { + fRangeListeners.add(listener); + } + + public void removeRangeListener(ITimeGraphRangeListener listener) { + fRangeListeners.remove(listener); + } + + private void notifyRangeListeners(long startTime, long endTime) { + // Check if the time has actually changed from last notification + if (startTime != _time0_extSynch || endTime != _time1_extSynch) { + // Notify Time Scale Selection Listeners + TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime); + + for (ITimeGraphRangeListener listener : fRangeListeners) { + listener.timeRangeUpdated(event); + } + + // update external synch timers + updateExtSynchTimers(); + } + } + + public void setSelectedTime(long time, boolean ensureVisible, Object source) { + if (this == source) { + return; + } + + setSelectedTimeInt(time, ensureVisible); + } + + public void setSelectedEvent(ITimeEvent event, Object source) { + if (event == null || source == this) { + return; + } + ITimeGraphEntry trace = event.getEntry(); + if (trace != null) { + _stateCtrl.selectItem(trace, false); + } + + setSelectedTimeInt(event.getTime(), true); + adjustVerticalScrollBar(); + } + + public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) { + if (trace == null || source == this) { + return; + } + + if (trace != null) { + _stateCtrl.selectItem(trace, false); + } + + setSelectedTimeInt(time, true); + } + + public void setSelection(ITimeGraphEntry trace) { + _stateCtrl.selectItem(trace, false); + adjustVerticalScrollBar(); + } + + public void setSelectVisTimeWindow(long time0, long time1, Object source) { + if (source == this) { + return; + } + + setStartFinishTime(time0, time1); + + // update notification time values since we are now in synch with the + // external application + updateExtSynchTimers(); + } + + /** + * update the cache timers used to identify the need to send a time window + * update to external registered listeners + */ + private void updateExtSynchTimers() { + // last time notification cache + _time0_extSynch = _time0; + _time1_extSynch = _time1; + } + + public void setTimeCalendarFormat(boolean toAbsoluteCaltime) { + calendarTimeFormat = toAbsoluteCaltime; + } + + @Override + public boolean isCalendarFormat() { + return calendarTimeFormat; + } + + public int getBorderWidth() { + return borderWidth; + } + + public void setBorderWidth(int borderWidth) { + if (borderWidth > -1) { + this.borderWidth = borderWidth; + GridLayout gl = (GridLayout)_dataViewer.getLayout(); + gl.marginHeight = borderWidth; + } + } + + public int getHeaderHeight() { + return timeScaleHeight; + } + + public void setHeaderHeight(int headerHeight) { + if (headerHeight > -1) { + this.timeScaleHeight = headerHeight; + _timeScaleCtrl.setHeight(headerHeight); + } + } + + public int getItemHeight() { + if (_stateCtrl != null) { + return _stateCtrl.getItemHeight(); + } + return 0; + } + + public void setItemHeight(int rowHeight) { + if (_stateCtrl != null) { + _stateCtrl.setItemHeight(rowHeight); + } + } + + public void setMinimumItemWidth(int width) { + if (_stateCtrl != null) { + _stateCtrl.setMinimumItemWidth(width); + } + } + + public void setNameWidthPref(int width) { + _nameWidthPref = width; + if (width == 0) { + _minNameWidth = 0; + _nameWidth = 0; + } + } + + public int getNameWidthPref(int width) { + return _nameWidthPref; + } + + /** + * Returns the primary control associated with this viewer. + * + * @return the SWT control which displays this viewer's content + */ + public Control getControl() { + return _dataViewer; + } + + /** + * Returns the time graph control associated with this viewer. + * + * @return the time graph control + */ + TimeGraphControl getTimeGraphControl() { + return _stateCtrl; + } + + /** + * Get the selection provider + * + * @return the selection provider + */ + public ISelectionProvider getSelectionProvider() { + return _stateCtrl; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer + * #waitCursor(boolean) + */ + public void waitCursor(boolean waitInd) { + _stateCtrl.waitCursor(waitInd); + } + + public ScrollBar getHorizontalBar() { + return _stateCtrl.getHorizontalBar(); + } + + public Slider getVerticalBar() { + return _verticalScrollBar; + } + + public void setTopIndex(int index) { + _stateCtrl.setTopIndex(index); + adjustVerticalScrollBar(); + } + + public int getTopIndex() { + return _stateCtrl.getTopIndex(); + } + + public void setExpandedState(ITimeGraphEntry entry, boolean expanded) { + _stateCtrl.setExpandedState(entry, expanded); + adjustVerticalScrollBar(); + } + + public void addTreeListener(ITimeGraphTreeListener listener) { + _stateCtrl.addTreeListener(listener); + } + + public void removeTreeListener(ITimeGraphTreeListener listener) { + _stateCtrl.removeTreeListener(listener); + } + + private void adjustVerticalScrollBar() { + int topIndex = _stateCtrl.getTopIndex(); + int countPerPage = _stateCtrl.countPerPage(); + int expandedElementCount = _stateCtrl.getExpandedElementCount(); + if (topIndex + countPerPage > expandedElementCount) { + _stateCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage)); + } + + int selection = _stateCtrl.getTopIndex(); + int min = 0; + int max = Math.max(1, expandedElementCount - 1); + int thumb = Math.min(max, Math.max(1, countPerPage - 1)); + int increment = 1; + int pageIncrement = Math.max(1, countPerPage); + _verticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement); + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeAnalysisProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeAnalysisProvider.java deleted file mode 100644 index 4207f06309..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeAnalysisProvider.java +++ /dev/null @@ -1,328 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import java.util.Map; - -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Rectangle; - -public abstract class TmfTimeAnalysisProvider { - - static public final int IMG_THREAD_RUNNING = 0; - static public final int IMG_THREAD_SUSPENDED = 1; - static public final int IMG_THREAD_STOPPED = 2; - static public final int IMG_METHOD_RUNNING = 3; - static public final int IMG_METHOD = 4; - static public final int IMG_NUM = 5; - - public enum StateColor { - GREEN, DARK_BLUE, RED, GOLD, ORANGE, GRAY, BLACK, DARK_GREEN, DARK_YELLOW, MAGENTA3, PURPLE1, PINK1, AQUAMARINE, LIGHT_BLUE, CADET_BLUE, OLIVE; - - private String stateName; - - StateColor() { - String undef = "Undefined"; //$NON-NLS-1$ - this.stateName = undef; - } - - public String getStateName() { - return stateName; - } - - public void setStateName(String stateName) { - this.stateName = stateName; - } - } - - // static private String _externalPath[] = { - // "icons/full/obj16/thread_obj.gif", // running thread - // "icons/full/obj16/threads_obj.gif", // suspended - // "icons/full/obj16/threadt_obj.gif", // stopped - // "icons/full/obj16/stckframe_running_obj.gif", // running stack frame - // "icons/full/obj16/stckframe_obj.gif", // stack frame - // }; - // - // static private String _externalPlugin[] = { "org.eclipse.debug.ui", - // "org.eclipse.debug.ui", "org.eclipse.debug.ui", - // "org.eclipse.debug.ui", "org.eclipse.debug.ui", }; - // - // static private Image getImage(int idx) { - // if (idx < 0 || idx >= IMG_NUM) - // SWT.error(SWT.ERROR_INVALID_ARGUMENT); - // String key = "trace.img." + idx; - // Image img = TmfUiPlugin.getDefault().getImageRegistry().get(key); - // if (null == img) { - // ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin( - // _externalPlugin[idx], _externalPath[idx]); - // TmfUiPlugin.getDefault().getImageRegistry().put(key, desc); - // img = TmfUiPlugin.getDefault().getImageRegistry().get(key); - // } - // return img; - // } - - public void drawState(TraceColorScheme colors, ITimeEvent event, - Rectangle rect, GC gc, boolean selected, boolean rectBound, - boolean timeSelected) { - int colorIdx = getEventColorVal(event); - drawState(colors, colorIdx, rect, gc, selected, rectBound, timeSelected); - - } - - public void drawState(TraceColorScheme colors, int colorIdx, - Rectangle rect, GC gc, boolean selected, boolean rectBound, - boolean timeSelected) { - - boolean visible = rect.width == 0 ? false : true; - int colorIdx1 = colorIdx; - - timeSelected = timeSelected && selected; - if (timeSelected) { - colorIdx1 = colorIdx + TraceColorScheme.STATES_SEL0 - - TraceColorScheme.STATES0; - } - - if (visible) { - // fill all rect area - if (rect.isEmpty()) - return; - - gc.setBackground(colors.getColor(colorIdx1)); - gc.fillRectangle(rect); - colorIdx1 = colorIdx + TraceColorScheme.STATES_BORDER0 - - TraceColorScheme.STATES0; - gc.setForeground(colors.getColor(colorIdx1)); - - // draw bounds - if (!timeSelected) { - if (rectBound && rect.width >= 3) { - gc.drawRectangle(rect.x, rect.y, rect.width - 1, - rect.height - 1); - } else { - // 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); - // bottom - gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x - + rect.width - 1, rect.y + rect.height - 1); - } - } - // draw decoration middle line - // int mindy = rect.y + rect.height / 2; - // if (TraceColorScheme.GOLD_STATE == colorIdx - // || TraceColorScheme.ORANGE_STATE == colorIdx) { - // int s = gc.getLineStyle(); - // int w = gc.getLineWidth(); - // gc.setLineStyle(SWT.LINE_DOT); - // gc.setLineWidth(2); - // gc.drawLine(rect.x, mindy, rect.x + rect.width, mindy); - // gc.setLineStyle(s); - // gc.setLineWidth(w); - // } else if (TraceColorScheme.RED_STATE == colorIdx - // || TraceColorScheme.GRAY_STATE == colorIdx) { - // int w = gc.getLineWidth(); - // gc.setLineWidth(2); - // gc.drawLine(rect.x, mindy, rect.x + rect.width, mindy); - // gc.setLineWidth(w); - // } - // // draw selection bounds - // if (timeSelected) { - // gc.setForeground(colors - // .getColor(TraceColorScheme.SELECTED_TIME)); - // if (rect.width >= 3) { - // gc.drawRectangle(rect.x, rect.y, rect.width - 1, - // rect.height - 1); - // // gc.drawRectangle(rect.x + 1, rect.y + 1, rect.width - 3, - // // rect.height - 3); - // } else { - // gc - // .drawLine(rect.x, rect.y, rect.x + rect.width - 1, - // rect.y); - // gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x - // + rect.width - 1, rect.y + rect.height - 1); - // } - // gc.drawLine(rect.x, rect.y + 1, rect.x + rect.width - 1, - // rect.y + 1); - // gc.drawLine(rect.x, rect.y + rect.height - 2, rect.x - // + rect.width - 1, rect.y + rect.height - 2); - // } - } else { - // selected rectangle area is not visible but can be represented - // with a broken vertical line of specified width. - int width = 2; - rect.width = width; - // check if height is greater than zero. - if (rect.isEmpty()) - return; - // colorIdx1 = TraceColorScheme.BLACK; - gc.setForeground(colors.getColor(colorIdx)); - int s = gc.getLineStyle(); - int w = gc.getLineWidth(); - gc.setLineStyle(SWT.LINE_DOT); - gc.setLineWidth(width); - // Trace.debug("Reactangle not visible, drawing vertical line with: " - // + rect.x + "," + rect.y + "," + rect.x + "," + rect.y - // + rect.height); - gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height); - gc.setLineStyle(s); - gc.setLineWidth(w); - } - } - - /** - * Uses the abstract method getEventcolor to obtain an enum value and - * convert it to an internal color index - * - * @param event - * @return the internal color index - */ - public int getEventColorVal(ITimeEvent event) { - StateColor colors = getEventColor(event); - if (colors == StateColor.GREEN) { - return TraceColorScheme.GREEN_STATE; - } else if (colors == StateColor.DARK_BLUE) { - return TraceColorScheme.DARK_BLUE_STATE; - } else if (colors == StateColor.RED) { - return TraceColorScheme.RED_STATE; - } else if (colors == StateColor.GOLD) { - return TraceColorScheme.GOLD_STATE; - } else if (colors == StateColor.ORANGE) { - return TraceColorScheme.ORANGE_STATE; - } else if (colors == StateColor.GRAY) { - return TraceColorScheme.GRAY_STATE; - } else if (colors == StateColor.DARK_GREEN) { - return TraceColorScheme.DARK_GREEN_STATE; - } else if (colors == StateColor.DARK_YELLOW) { - return TraceColorScheme.DARK_YELLOW_STATE; - } else if (colors == StateColor.MAGENTA3) { - return TraceColorScheme.MAGENTA3_STATE; - } else if (colors == StateColor.PURPLE1) { - return TraceColorScheme.PURPLE1_STATE; - } else if (colors == StateColor.PINK1) { - return TraceColorScheme.PINK1_STATE; - } else if (colors == StateColor.AQUAMARINE) { - return TraceColorScheme.AQUAMARINE_STATE; - } else if (colors == StateColor.LIGHT_BLUE) { - return TraceColorScheme.LIGHT_BLUE_STATE; - } else if (colors == StateColor.CADET_BLUE) { - return TraceColorScheme.CADET_BLUE_STATE_SEL; - } else if (colors == StateColor.OLIVE) { - return TraceColorScheme.OLIVE_STATE; - } - - return TraceColorScheme.BLACK_STATE; - } - - /** - * Select the color for the different internal variants of events. - * - * @param event - * @return the corresponding event color - */ - public abstract StateColor getEventColor(ITimeEvent event); - - /** - * This values is appended between braces to the right of Trace Name e.g. - * Trace And Error Log [Board 17] or for a Thread trace e.g. State Server - * [java.lang.Thread] - * - * @param trace - * @return the trace class name - */ - public abstract String getTraceClassName(ITmfTimeAnalysisEntry trace); - - public String getEventName(ITimeEvent event) { - return getEventName(event, true, false); - } - - /** - * Specify a Name for the event depending on its type or state e.g. blocked, - * running, etc.. - * - * @param event - * @param upper - * True return String value in Upper case - * @param extInfo - * Verbose, add additional information if applicable - * @return the event name - */ - public abstract String getEventName(ITimeEvent event, boolean upper, - boolean extInfo); - - public String composeTraceName(ITmfTimeAnalysisEntry trace, boolean inclState) { - String name = trace.getName(); - String threadClass = getTraceClassName(trace); - if (threadClass != null && threadClass.length() > 0) { - name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - /* - * Check if this is still necessary! - if (inclState) { - List list = trace.getTraceEvents(); - if (null != list && list.size() > 0) { - ITimeEvent event = (ITimeEvent) list.get(list.size() - 1); - name += " (" + getEventName(event, false, true) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - */ - return name; - } - - public String composeEventName(ITimeEvent event) { - String name = event.getEntry().getName(); - String threadClass = getTraceClassName(event.getEntry()); - if (threadClass != null && threadClass.length() > 0) { - name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - name += " (" + getEventName(event, false, true) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - return name; - } - - public abstract Map getEventHoverToolTipInfo( - ITimeEvent event); - - /** - * Provides the image icon for a given Event or Trace e.g. customize to use - * different icons according to specific event /state combination - * - * @param obj - * @return the image icon - */ - public Image getItemImage(Object obj) { - /* - if (obj instanceof ITmfTimeAnalysisEntry) { - List list = ((ITmfTimeAnalysisEntry) obj).getTraceEvents(); - if (null != list && list.size() > 0) - obj = list.get(list.size() - 1); - else if (((ITmfTimeAnalysisEntry) obj).getStopTime() > 0) - return getImage(IMG_THREAD_STOPPED); - else - return getImage(IMG_THREAD_RUNNING); - } - if (obj instanceof TimeEvent) { - return getImage(IMG_THREAD_RUNNING); - } - */ - return null; - } - - public abstract String getStateName(StateColor color); - -} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeAnalysisViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeAnalysisViewer.java deleted file mode 100644 index 39f0b95c3d..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeAnalysisViewer.java +++ /dev/null @@ -1,957 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2007, 2008, 2009, 2010 Intel Corporation, Ericsson - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Intel Corporation - Initial API and implementation - * Ruslan A. Scherbakov, Intel - Initial API and implementation - * Alexander N. Alexeev, Intel - Add monitors statistics support - * Alvaro Sanchez-Leon - Adapted for TMF - * - * $Id: ThreadStatesView.java,v 1.7 2008/05/19 15:07:21 jkubasta Exp $ - *****************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import java.util.Iterator; -import java.util.Vector; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs.TmfTimeFilterDialog; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs.TmfTimeLegend; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeScaleCtrl; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TmfTimeStatesCtrl; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TmfTimeTipHandler; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlAdapter; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.ScrollBar; - -public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProvider, SelectionListener { - - /** vars */ - private long _minTimeInterval; - private long _selectedTime; - private long _beginTime; - private long _endTime; - private long _time0; - private long _time1; - private long _time0_; - private long _time1_; - private long _time0_extSynch = 0; - private long _time1_extSynch = 0; - private boolean _timeRangeFixed; - private int _nameWidthPref = 200; - private int _minNameWidth = 6; - private int _nameWidth; - private Composite _dataViewer; - - private TmfTimeStatesCtrl _stateCtrl; - private TimeScaleCtrl _timeScaleCtrl; - private TmfTimeTipHandler _threadTip; - private TraceColorScheme _colors; - private TmfTimeAnalysisProvider _utilImplm; - - private boolean _acceptSetSelAPICalls = false; - Vector widgetSelectionListners = new Vector(); - Vector widgetTimeScaleSelectionListners = new Vector(); - Vector widgetFilterSelectionListeners = new Vector(); - - // Calender Time format, using Epoch reference or Relative time - // format(default - private boolean calendarTimeFormat = false; - private int borderWidth = 4; - private int timeScaleHeight = 22; - - /** ctor */ - public TmfTimeAnalysisViewer(Composite parent, TmfTimeAnalysisProvider provider) { - createDataViewer(parent, provider); - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.api.ITimeAnalysisWidget#display(org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.model.TmfTaTrace[]) - */ - @Override - public void display(ITmfTimeAnalysisEntry[] traceArr) { - modelUpdate(traceArr); - } - - @Override - public void display(ITmfTimeAnalysisEntry[] traceArr, long start, long end, - boolean updateTimeBounds) { - modelUpdate(traceArr, start, end, updateTimeBounds); - } - - public void controlMoved(ControlEvent e) { - } - - @Override - public void controlResized(ControlEvent e) { - resizeControls(); - } - - // called from the display order in the API - public void modelUpdate(ITmfTimeAnalysisEntry[] traces) { - if (null != _stateCtrl) { - //loadOptions(); - updateInternalData(traces); - _stateCtrl.redraw(); - _timeScaleCtrl.redraw(); - } - } - - // called from the display order in the API - public void modelUpdate(ITmfTimeAnalysisEntry[] traces, long start, - long end, boolean updateTimeBounds) { - if (null != _stateCtrl) { - //loadOptions(); - updateInternalData(traces, start, end); - if (updateTimeBounds) { - _timeRangeFixed = true; - // set window to match limits - setStartFinishTime(_time0_, _time1_); - } else { - _stateCtrl.redraw(); - _timeScaleCtrl.redraw(); - } - } - } - - @Override - public void itemUpdate(ITmfTimeAnalysisEntry parent, TimeEvent item) { - if (null != parent && null != item) { - _stateCtrl.refreshPartial(parent, item); - _stateCtrl.redraw(); - _timeScaleCtrl.redraw(); - } - } - - public void selectionChanged() { - } - - protected String getViewTypeStr() { - return "viewoption.threads"; //$NON-NLS-1$ - } - - int getMarginWidth(int idx) { - return 0; - } - - int getMarginHeight(int idx) { - return 0; - } - - void loadOptions() { - _minTimeInterval = 1; - _selectedTime = -1; - _nameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$ - _nameWidthPref, _minNameWidth, 1000); - } - - void saveOptions() { - Utils.saveIntOption(getPreferenceString("namewidth"), _nameWidth); //$NON-NLS-1$ - } - - protected Control createDataViewer(Composite parent, - TmfTimeAnalysisProvider utilImplm) { - loadOptions(); - _utilImplm = utilImplm; - _colors = new TraceColorScheme(); - _dataViewer = new Composite(parent, SWT.NULL); - _dataViewer.setLayoutData(GridUtil.createFill()); - GridLayout gl = new GridLayout(); - gl.marginHeight = borderWidth; - gl.marginWidth = 0; - gl.verticalSpacing = 0; - gl.horizontalSpacing = 0; - _dataViewer.setLayout(gl); - - _timeScaleCtrl = new TimeScaleCtrl(_dataViewer, _colors); - _timeScaleCtrl.setTimeProvider(this); - _timeScaleCtrl.setLayoutData(GridUtil.createHorizontalFill()); - _timeScaleCtrl.setHeight(timeScaleHeight); - - _stateCtrl = new TmfTimeStatesCtrl(_dataViewer, _colors, _utilImplm); - - _stateCtrl.setTimeProvider(this); - _stateCtrl.addSelectionListener(this); - _stateCtrl.setLayoutData(GridUtil.createFill()); - _dataViewer.addControlListener(new ControlAdapter() { - @Override - public void controlResized(ControlEvent event) { - resizeControls(); - } - }); - resizeControls(); - _dataViewer.update(); - _threadTip = new TmfTimeTipHandler(parent.getShell(), _utilImplm, this); - _threadTip.activateHoverHelp(_stateCtrl); - return _dataViewer; - } - - public void dispose() { - saveOptions(); - _stateCtrl.dispose(); - _dataViewer.dispose(); - _colors.dispose(); - } - - @Override - public void resizeControls() { - Rectangle r = _dataViewer.getClientArea(); - if (r.isEmpty()) - return; - - int width = r.width; - if (_nameWidth > width - _minNameWidth) - _nameWidth = width - _minNameWidth; - if (_nameWidth < _minNameWidth) - _nameWidth = _minNameWidth; - } - - /** Tries to set most convenient time range for display. */ - void setTimeRange(Object traces[]) { - _endTime = 0; - _beginTime = -1; -// ITimeEvent event; - for (int i = 0; i < traces.length; i++) { - ITmfTimeAnalysisEntry entry = (ITmfTimeAnalysisEntry) traces[i]; - if (entry.getStopTime() >= entry.getStartTime() && entry.getStopTime() > 0) { - if (_beginTime < 0 || entry.getStartTime() < _beginTime) { - _beginTime = entry.getStartTime(); - } - if (entry.getStopTime() > _endTime) { - _endTime = entry.getStopTime(); - } - } - /* - * This is not needed if entry startTime and stopTime are properly set! - List list = entry.getTraceEvents(); - int len = list.size(); - if (len > 0) { - event = (ITimeEvent) list.get(0); - if (_beginTime < 0 || event.getTime() < _beginTime) { - _beginTime = event.getTime(); - } - event = (ITimeEvent) list.get(list.size() - 1); - long eventEndTime = event.getTime() + (event.getDuration() > 0 ? event.getDuration() : 0); - if (eventEndTime > _endTime) { - _endTime = eventEndTime; - } - } - */ - } - - if (_beginTime < 0) - _beginTime = 0; - } - - void setTimeBounds() { - //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02); - _time0_ = _beginTime; - if (_time0_ < 0) - _time0_ = 0; - // _time1_ = _time0_ + (_endTime - _time0_) * 1.05; - _time1_ = _endTime; - // _time0_ = Math.floor(_time0_); - // _time1_ = Math.ceil(_time1_); - if (!_timeRangeFixed) { - _time0 = _time0_; - _time1 = _time1_; - } - if (_time1 - _time0 < _minTimeInterval) { - _time1 = _time0 + _minTimeInterval; - } - } - - /** - * @param traces - */ - void updateInternalData(ITmfTimeAnalysisEntry[] traces) { - if (null == traces) - traces = new ITmfTimeAnalysisEntry[0]; - setTimeRange(traces); - refreshAllData(traces); - } - - /** - * @param traces - * @param start - * @param end - */ - void updateInternalData(ITmfTimeAnalysisEntry[] traces, long start, long end) { - if (null == traces) - traces = new ITmfTimeAnalysisEntry[0]; - if ((start == 0 && end == 0) || start < 0 || end < 0) { - // Start and end time are unspecified and need to be determined from - // individual processes - setTimeRange(traces); - } else { - _beginTime = start; - _endTime = end; - } - - refreshAllData(traces); - } - - /** - * @param traces - */ - private void refreshAllData(ITmfTimeAnalysisEntry[] traces) { - setTimeBounds(); - if (_selectedTime < _beginTime) { - _selectedTime = _beginTime; - } else if (_selectedTime > _endTime) { - _selectedTime = _endTime; - } - _stateCtrl.refreshData(traces); - filterOutNotification(); - } - - @Override - public void setFocus() { - if (null != _stateCtrl) - _stateCtrl.setFocus(); - } - - @Override - public boolean isInFocus() { - return _stateCtrl.isInFocus(); - } - - @Override - public ITmfTimeAnalysisEntry getSelectedTrace() { - return _stateCtrl.getSelectedTrace(); - } - - @Override - public ISelection getSelection() { - return _stateCtrl.getSelection(); - } - - @Override - public ISelection getSelectionTrace() { - return _stateCtrl.getSelectionTrace(); - } - - @Override - public long getTime0() { - return _time0; - } - - @Override - public long getTime1() { - return _time1; - } - - @Override - public long getMinTimeInterval() { - return _minTimeInterval; - } - - @Override - public int getNameSpace() { - return _nameWidth; - } - - @Override - public void setNameSpace(int width) { - _nameWidth = width; - width = _stateCtrl.getClientArea().width; - if (_nameWidth > width - 6) - _nameWidth = width - 6; - if (_nameWidth < 6) - _nameWidth = 6; - _stateCtrl.adjustScrolls(); - _stateCtrl.redraw(); - _timeScaleCtrl.redraw(); - } - - @Override - public int getTimeSpace() { - int w = _stateCtrl.getClientArea().width; - return w - _nameWidth; - } - - @Override - public long getSelectedTime() { - return _selectedTime; - } - - @Override - public long getBeginTime() { - return _beginTime; - } - - @Override - public long getEndTime() { - return _endTime; - } - - @Override - public long getMaxTime() { - return _time1_; - } - - @Override - public long getMinTime() { - return _time0_; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider - * #setStartFinishTimeNotify(long, long) - */ - @Override - public void setStartFinishTimeNotify(long time0, long time1) { - setStartFinishTime(time0, time1); - notifyStartFinishTimeSelectionListeners(time0, time1); - } - - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime() - */ - @Override - public void notifyStartFinishTime() { - notifyStartFinishTimeSelectionListeners(_time0, _time1); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider - * #setStartFinishTime(long, long) - */ - @Override - public void setStartFinishTime(long time0, long time1) { - _time0 = time0; - if (_time0 < _time0_) - _time0 = _time0_; - if (_time0 > _time1_) - _time0 = _time1_; - _time1 = time1; - if (_time1 < _time0_) - _time1 = _time0_; - if (_time1 > _time1_) - _time1 = _time1_; - if (_time1 - _time0 < _minTimeInterval) - _time1 = _time0 + _minTimeInterval; - _timeRangeFixed = true; - _stateCtrl.adjustScrolls(); - _stateCtrl.redraw(); - _timeScaleCtrl.redraw(); - } - - @Override - public void setTimeBounds(long beginTime, long endTime) { - _beginTime = beginTime; - _endTime = endTime; - _time0_ = beginTime; - _time1_ = endTime; - _stateCtrl.adjustScrolls(); - } - - @Override - public void resetStartFinishTime() { - setStartFinishTimeNotify(_time0_, _time1_); - _timeRangeFixed = false; - } - - @Override - public void setSelectedTimeInt(long time, boolean ensureVisible) { - // Trace.debug("currentTime:" + _selectedTime + " new time:" + time); - _selectedTime = time; - if (_selectedTime > _endTime) { - _endTime = _selectedTime; - _time1_ = _selectedTime; - } - if (_selectedTime < _beginTime) { - _beginTime = _selectedTime; - _time0_ = _selectedTime; - } - long time0 = _time0; - long time1 = _time1; - if (ensureVisible) { - double timeSpace = (_time1 - _time0) * .02; - double timeMid = (_time1 - _time0) * .1; - if (_selectedTime < _time0 + timeSpace) { - long dt = (long) (_time0 - _selectedTime + timeMid); - _time0 -= dt; - _time1 -= dt; - } else if (_selectedTime > _time1 - timeSpace) { - long dt = (long) (_selectedTime - _time1 + timeMid); - _time0 += dt; - _time1 += dt; - } - if (_time0 < _time0_) { - _time1 = Math.min(_time1_, _time1 + (_time0_ - _time0)); - _time0 = _time0_; - } else if (_time1 > _time1_) { - _time0 = Math.max(_time0_, _time0 - (_time1 - _time1_)); - _time1 = _time1_; - } - } - if (_time1 - _time0 < _minTimeInterval) { - _time1 = _time0 + _minTimeInterval; - } - _stateCtrl.adjustScrolls(); - _stateCtrl.redraw(); - _timeScaleCtrl.redraw(); - if (time0 != _time0 || time1 != _time1) { - notifyStartFinishTimeSelectionListeners(_time0, _time1); - } - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - // TODO: Opening call stack shall be replaced to a configurable view - // new OpenCallStackViewAction().openView(false); - // Replaced by event notification - // updateModelSelection(); - notifySelectionListeners(TmfTimeSelectionEvent.Type.WIDGET_DEF_SEL); - } - - @Override - public void widgetSelected(SelectionEvent e) { - // Replace by event notification - // updateModelSelection(); - notifySelectionListeners(TmfTimeSelectionEvent.Type.WIDGET_SEL); - } - - @Override - public void selectNextEvent() { - _stateCtrl.selectNextEvent(); - } - - @Override - public void selectPrevEvent() { - _stateCtrl.selectPrevEvent(); - } - - @Override - public void selectNextTrace() { - _stateCtrl.selectNextTrace(); - } - - @Override - public void selectPrevTrace() { - _stateCtrl.selectPrevTrace(); - } - - @Override - public void groupTraces(boolean on) { - _stateCtrl.groupTraces(on); - } - - @Override - public void filterTraces() { - if (_dataViewer == null || _dataViewer.isDisposed()) - return; - - if (TmfTimeFilterDialog.getTraceFilter(_dataViewer.getShell(), _stateCtrl - .getTraces(), _stateCtrl.getTraceFilter())) { - _stateCtrl.refreshData(); - filterOutNotification(); - } - } - - @Override - public void showLegend() { - if (_dataViewer == null || _dataViewer.isDisposed()) - return; - - TmfTimeLegend.open(_dataViewer.getShell(), _utilImplm); - } - - public void toggleThreadsInteractionDrawing() { - _stateCtrl.toggleTraceInteractionDrawing(); - } - - public void setThreadJoinDrawing(boolean on) { - _stateCtrl.setTraceJoinDrawing(on); - } - - public void setThreadWaitDrawing(boolean on) { - _stateCtrl.setTraceWaitDrawing(on); - } - - public void setThreadReleaseDrawing(boolean on) { - _stateCtrl.setTraceReleaseDrawing(on); - } - - public boolean getThreadInteractionDrawing() { - return _stateCtrl.getTracesInteractionDrawing(); - } - - public boolean getThreadJoinDrawing() { - return _stateCtrl.getTraceJoinDrawing(); - } - - public boolean getThreadWaitDrawing() { - return _stateCtrl.getTraceWaitDrawing(); - } - - public boolean getThreadReleaseDrawing() { - return _stateCtrl.getTraceReleaseDrawing(); - } - - protected void select(Object obj) { - if (obj == null) - return; - // TODO: ThreadDetails Adaption removed, might need replacement - // if (obj instanceof ThreadDetails) { - // obj = ((ThreadDetails) obj).getThread(); - // } - if (obj instanceof ITmfTimeAnalysisEntry) { - // _stateCtrl.selectThread((TsfTmTrace) obj); - } - } - - @Override - public void zoomIn() { - _stateCtrl.zoomIn(); - } - - @Override - public void zoomOut() { - _stateCtrl.zoomOut(); - } - - private String getPreferenceString(String string) { - return getViewTypeStr() + "." + string; //$NON-NLS-1$ - } - - @Override - public void addWidgetSelectionListner(ITmfTimeSelectionListener listener) { - widgetSelectionListners.add(listener); - } - - @Override - public void removeWidgetSelectionListner(ITmfTimeSelectionListener listener) { - widgetSelectionListners.removeElement(listener); - } - - @Override - public void addWidgetTimeScaleSelectionListner( - ITmfTimeScaleSelectionListener listener) { - widgetTimeScaleSelectionListners.add(listener); - } - - @Override - public void removeWidgetTimeScaleSelectionListner( - ITmfTimeScaleSelectionListener listener) { - widgetTimeScaleSelectionListners.removeElement(listener); - } - - @Override - public void setSelectedTime(long time, boolean ensureVisible, Object source) { - if (_acceptSetSelAPICalls == false || this == source) { - return; - } - - setSelectedTimeInt(time, ensureVisible); - } - - @Override - public void setSelectedEvent(ITimeEvent event, Object source) { - if (_acceptSetSelAPICalls == false || event == null || source == this) { - return; - } - ITmfTimeAnalysisEntry trace = event.getEntry(); - if (trace != null) { - _stateCtrl.selectItem(trace, false); - } - - setSelectedTimeInt(event.getTime(), true); - } - - @Override - public void setSelectedTraceTime(ITmfTimeAnalysisEntry trace, long time, Object source) { - if (_acceptSetSelAPICalls == false || trace == null || source == this) { - return; - } - - if (trace != null) { - _stateCtrl.selectItem(trace, false); - } - - setSelectedTimeInt(time, true); - } - - @Override - public void setSelectedTrace(ITmfTimeAnalysisEntry trace) { - if (trace == null) { - return; - } - - _stateCtrl.selectItem(trace, false); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer - * #setSelectVisTimeWindow(long, long, java.lang.Object) - */ - @Override - public void setSelectVisTimeWindow(long time0, long time1, Object source) { - if (_acceptSetSelAPICalls == false || source == this) { - return; - } - - setStartFinishTime(time0, time1); - - // update notification time values since we are now in synch with the - // external application - updateExtSynchTimers(); - } - - @Override - public void setAcceptSelectionAPIcalls(boolean acceptCalls) { - _acceptSetSelAPICalls = acceptCalls; - } - - private synchronized void notifySelectionListeners( - TmfTimeSelectionEvent.Type rtype) { - // Any listeners out there ? - if (widgetSelectionListners.size() > 0) { - // Locate the event selected - ISelection selection = getSelection(); - Object sel = null; - if (selection != null && !selection.isEmpty()) { - sel = ((IStructuredSelection) selection).getFirstElement(); - } - - if (sel != null) { - // Notify Selection Listeners - TmfTimeSelectionEvent event = new TmfTimeSelectionEvent(this, - rtype, sel, getSelectedTime()); - - for (Iterator iter = widgetSelectionListners - .iterator(); iter.hasNext();) { - ITmfTimeSelectionListener listener = (ITmfTimeSelectionListener) iter - .next(); - listener.tsfTmProcessSelEvent(event); - } - } - } - } - - public void notifyStartFinishTimeSelectionListeners(long _time0, long _time1) { - if (widgetTimeScaleSelectionListners.size() > 0) { - // Check if the time has actually changed from last notification - if (_time0 != _time0_extSynch || _time1 != _time1_extSynch) { - // Notify Time Scale Selection Listeners - TmfTimeScaleSelectionEvent event = new TmfTimeScaleSelectionEvent( - this, _time0, _time1, getTimeSpace(), getSelectedTime()); - - for (Iterator iter = widgetTimeScaleSelectionListners - .iterator(); iter.hasNext();) { - ITmfTimeScaleSelectionListener listener = (ITmfTimeScaleSelectionListener) iter - .next(); - listener.tsfTmProcessTimeScaleEvent(event); - } - - // update external synch timers - updateExtSynchTimers(); - } - } - } - - /** - * update the cache timers used to identify the need to send a time window - * update to external registered listeners - */ - private void updateExtSynchTimers() { - // last time notification cache - _time0_extSynch = _time0; - _time1_extSynch = _time1; - } - - @Override - public void setTimeCalendarFormat(boolean toAbsoluteCaltime) { - calendarTimeFormat = toAbsoluteCaltime; - } - - @Override - public boolean isCalendarFormat() { - return calendarTimeFormat; - } - - @Override - public int getBorderWidth() { - return borderWidth; - } - - @Override - public void setBorderWidth(int borderWidth) { - if (borderWidth > -1) { - this.borderWidth = borderWidth; - GridLayout gl = (GridLayout)_dataViewer.getLayout(); - gl.marginHeight = borderWidth; - } - } - - @Override - public int getHeaderHeight() { - return timeScaleHeight; - } - - @Override - public void setHeaderHeight(int headerHeight) { - if (headerHeight > -1) { - this.timeScaleHeight = headerHeight; - _timeScaleCtrl.setHeight(headerHeight); - } - } - - @Override - public int getItemHeight() { - if (_stateCtrl != null) { - return _stateCtrl.getItemHeight(); - } - return 0; - } - - @Override - public void setItemHeight(int rowHeight) { - if (_stateCtrl != null) { - _stateCtrl.setItemHeight(rowHeight); - } - } - - @Override - public void setMinimumItemWidth(int width) { - if (_stateCtrl != null) { - _stateCtrl.setMinimumItemWidth(width); - } - } - - @Override - public boolean isVisibleVerticalScroll() { - if (_stateCtrl != null) { - _stateCtrl.isVisibleVerticalScroll(); - } - return false; - } - - @Override - public void setVisibleVerticalScroll(boolean visibleVerticalScroll) { - if (_stateCtrl != null) { - _stateCtrl.setVisibleVerticalScroll(visibleVerticalScroll); - } - } - - @Override - public void setNameWidthPref(int width) { - _nameWidthPref = width; - if (width == 0) { - _minNameWidth = 0; - _nameWidth = 0; - } - } - - @Override - public int getNameWidthPref(int width) { - return _nameWidthPref; - } - - @Override - public void addFilterSelectionListner(ITmfTimeFilterSelectionListener listener) { - widgetFilterSelectionListeners.add(listener); - } - - @Override - public void removeFilterSelectionListner( - ITmfTimeFilterSelectionListener listener) { - widgetFilterSelectionListeners.remove(listener); - } - - private void filterOutNotification() { - TmfTimeFilterSelectionEvent event = new TmfTimeFilterSelectionEvent(this); - event.setFilteredOut(_stateCtrl.getFilteredOut()); - for (ITmfTimeFilterSelectionListener listener : widgetFilterSelectionListeners) { - listener.tmfTaProcessFilterSelection(event); - } - } - - /** - * needed in case there's a need to associate a context menu - * - * @return the state control (selection provider) - */ - @Override - public Control getControl() { - return _stateCtrl; - } - - /** - * Get the selection provider - * - * @return the selection provider - */ - @Override - public ISelectionProvider getSelectionProvider() { - return _stateCtrl; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer - * #waitCursor(boolean) - */ - @Override - public void waitCursor(boolean waitInd) { - _stateCtrl.waitCursor(waitInd); - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer#getHorizontalBar() - */ - @Override - public ScrollBar getHorizontalBar() { - return _stateCtrl.getHorizontalBar(); - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer#getVerticalBar() - */ - @Override - public ScrollBar getVerticalBar() { - return _stateCtrl.getVerticalBar(); - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer#setTopIndex(int) - */ - @Override - public void setTopIndex(int index) { - _stateCtrl.setTopIndex(index); - } - -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeFilterSelectionEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeFilterSelectionEvent.java deleted file mode 100644 index 96757c9be0..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeFilterSelectionEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import java.util.EventObject; -import java.util.Vector; - -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; - -public class TmfTimeFilterSelectionEvent extends EventObject { - /** - * - */ - private static final long serialVersionUID = -150960748016449093L; - - Vector filteredOut = null; - - public TmfTimeFilterSelectionEvent(Object source) { - super(source); - } - - public Vector getFilteredOut() { - return filteredOut; - } - - public void setFilteredOut(Vector rfilteredOut) { - this.filteredOut = rfilteredOut; - } -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeScaleSelectionEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeScaleSelectionEvent.java deleted file mode 100644 index 36ee71b65b..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeScaleSelectionEvent.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import java.util.EventObject; - -public class TmfTimeScaleSelectionEvent extends EventObject { - - /** - * - */ - private static final long serialVersionUID = -4177428788761351379L; - - - long time0 = 0; - long time1 = 0; - long selectedTime = 0; - int width = 0; - - /** - * - * @param arg0 - * source of event - * @param time0 - * time0 the start time - * @param time1 - * @param width - * pixels used to draw the width of the time space - * @param selTime - * carries the selected time if available otherwise is 0 - */ - public TmfTimeScaleSelectionEvent(Object arg0, long time0, long time1, - int width, long selTime) { - super(arg0); - this.time0 = time0; - this.time1 = time1; - this.width = width; - this.selectedTime = selTime; - } - - /** - * @return the start time - */ - public long getTime0() { - return time0; - } - - /** - * @return the end time - */ - public long getTime1() { - return time1; - } - - /** - * @return the selection width - */ - public int getWidth() { - return width; - } - - /** - * @return the selected time - */ - public long getSelectedTime() { - return selectedTime; - } - -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeSelectionEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeSelectionEvent.java deleted file mode 100644 index 955e1da6c8..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfTimeSelectionEvent.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import java.util.EventObject; - -public class TmfTimeSelectionEvent extends EventObject { - - /** - * - */ - private static final long serialVersionUID = 1L; - - public enum Type {WIDGET_DEF_SEL, WIDGET_SEL} - Type dType; - Object selection = null; - long selTime = 0; - int index = 0; - - public TmfTimeSelectionEvent(Object arg0, Type rType, Object sel, long selectedTime) { - super(arg0); - dType = rType; - selection = sel; - selTime = selectedTime; - } - - public Type getDType() { - return dType; - } - - public Object getSelection() { - return selection; - } - - public long getSelectedTime() { - return selTime; - } - -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfViewerFactory.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfViewerFactory.java deleted file mode 100644 index 61fcf6d394..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TmfViewerFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import org.eclipse.swt.widgets.Composite; - -/** - * TmfWidgetFactory - *

- * - * TODO: Generalize when extension points are introduced - * TODO: Today, it is specific for the TimeAnalysis widget - */ -public class TmfViewerFactory { - -// public static ITmfWidget createWidget(String id, Composite parent) { -// return null; -// } - - public static ITimeAnalysisViewer createViewer(Composite parent, - TmfTimeAnalysisProvider provider) { - return new TmfTimeAnalysisViewer(parent, provider); - } - -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphLegend.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphLegend.java new file mode 100644 index 0000000000..c8668b76de --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphLegend.java @@ -0,0 +1,216 @@ +/******************************************************************************* + * Copyright (c) 2009, 2012 Ericsson. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Refactoring + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.linuxtools.internal.tmf.ui.Messages; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider.StateColor; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; + + +public class TimeGraphLegend extends TitleAreaDialog { + + public static final int interactionColors[] = { + TimeGraphColorScheme.TI_START_THREAD, + TimeGraphColorScheme.TI_NOTIFY_JOINED, TimeGraphColorScheme.TI_NOTIFY, + TimeGraphColorScheme.TI_INTERRUPT, TimeGraphColorScheme.TI_HANDOFF_LOCK }; + + protected TimeGraphColorScheme colors; + private ITimeGraphProvider ifUtil; + + public static void open(Shell parent, ITimeGraphProvider rifUtil) { + (new TimeGraphLegend(parent, rifUtil)).open(); + } + + public TimeGraphLegend(Shell parent, ITimeGraphProvider rifUtil) { + super(parent); + colors = new TimeGraphColorScheme(); + this.ifUtil = rifUtil; + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite dlgArea = (Composite) super.createDialogArea(parent); + Composite composite = new Composite(dlgArea, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + composite.setLayoutData(gd); + + createThreadStatesGroup(composite); + + setMessage(Messages.TmfTimeLegend_LEGEND); + setTitle(Messages.TmfTimeLegend_TRACE_STATES_TITLE); + setDialogHelpAvailable(false); + setHelpAvailable(false); + + return composite; + } + + private void createThreadStatesGroup(Composite composite) { + Group gs = new Group(composite, SWT.NONE); + gs.setText(Messages.TmfTimeLegend_TRACE_STATES); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + gs.setLayoutData(gd); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginWidth = 20; + layout.marginBottom = 10; + gs.setLayout(layout); + + // Go through all the defined colors and only add the ones you need. + // This will not handle several colors assigned to a color, we have + // 16 mil colors, and should not pick two to mean the same thing. + for (int i = 0; i < TimeGraphColorScheme.getStateColors().length; i++) { + //Get the color enum related to the index + StateColor stateColor = TimeGraphColorScheme.getStateColors()[i]; + //Get the given name, provided by the interface to the application + String stateName = ifUtil.getStateName(stateColor); + if( stateName != "Not mapped" ) { //$NON-NLS-1$ + Bar bar = new Bar(gs, i); + gd = new GridData(); + gd.widthHint = 40; + gd.heightHint = 20; + gd.verticalIndent = 8; + bar.setLayoutData(gd); + Label name = new Label(gs, SWT.NONE); + name.setText(stateName); + gd = new GridData(); + gd.horizontalIndent = 10; + gd.verticalIndent = 8; + name.setLayoutData(gd); + } + } + } + + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(Messages.TmfTimeLegend_WINDOW_TITLE); + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, + true); + } + + class Bar extends Canvas { + private Color color; + + public Bar(Composite parent, int colorIdx) { + super(parent, SWT.NONE); + + color = colors.getColor(colorIdx); + addListener(SWT.Paint, new Listener() { + @Override + public void handleEvent(Event event) { + draw(event.gc); + } + }); + } + + private void draw(GC gc) { + Rectangle r = getClientArea(); + gc.setBackground(color); + gc.fillRectangle(r); + gc.setForeground(colors.getColor(TimeGraphColorScheme.BLACK)); + gc.drawRectangle(0, 0, r.width - 1, r.height - 1); + } + } + + class Arrow extends Canvas { + public final static int HEIGHT = 12; + public final static int DX = 3; + + private Color color; + + public Arrow(Composite parent, int colorIdx) { + super(parent, SWT.NONE); + + color = colors.getColor(colorIdx); + addListener(SWT.Paint, new Listener() { + @Override + public void handleEvent(Event event) { + draw(event.gc); + } + }); + } + + private void draw(GC gc) { + Rectangle r = getClientArea(); + gc.setForeground(color); + + int y0, y1; + if (r.height > HEIGHT) { + y0 = (r.height - HEIGHT) / 2; + y1 = y0 + HEIGHT; + } else { + y0 = 0; + y1 = r.height; + } + + gc.drawLine(DX, y0, DX, y1); + + gc.drawLine(0, y0 + 3, DX, y0); + gc.drawLine(2 * DX, y0 + 3, DX, y0); + } + } + + class Mark extends Canvas { + public final static int DX = 3; + + private Color color; + + public Mark(Composite parent, int colorIdx) { + super(parent, SWT.NONE); + + color = colors.getColor(colorIdx); + addListener(SWT.Paint, new Listener() { + @Override + public void handleEvent(Event event) { + draw(event.gc); + } + }); + } + + private void draw(GC gc) { + Rectangle r = getClientArea(); + gc.setBackground(color); + + int y = (r.height - DX) / 2; + int c[] = { 0, y, DX, y + DX, 2 * DX, y }; + gc.fillPolygon(c); + } + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TmfTimeFilterDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TmfTimeFilterDialog.java deleted file mode 100644 index 804f25a246..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TmfTimeFilterDialog.java +++ /dev/null @@ -1,222 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2008 Intel Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Intel Corporation - Initial API and implementation - * - * $Id: ThreadFilterDialog.java,v 1.2 2008/03/05 17:31:07 ewchan Exp $ - *****************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs; - -import java.util.Arrays; - -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.window.Window; -import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; - -public class TmfTimeFilterDialog extends TitleAreaDialog { - private CheckboxTableViewer viewer; - private Object[] threads; - private boolean[] filter; - private ViewContentProvider viewContentProvider; - private TraceComparator viewTraceComparator; - private ViewLabelProvider viewViewLabelProvider; - - public TmfTimeFilterDialog(Shell parentShell, Object[] threads, - boolean[] filter) { - super(parentShell); - - this.threads = (threads != null) ? Arrays.copyOf(threads, threads.length) : null; - if (filter != null) - this.filter = (boolean[]) filter.clone(); - - viewContentProvider = new ViewContentProvider(); - viewTraceComparator = new TraceComparator(); - viewViewLabelProvider = new ViewLabelProvider(); - } - - public static boolean getTraceFilter(Shell parentShell, Object[] threads, - boolean[] filter) { - TmfTimeFilterDialog dlg = new TmfTimeFilterDialog(parentShell, threads, - filter); - if (dlg.open() != Window.OK) - return false; - - boolean f[] = dlg.getFilter(); - if (java.util.Arrays.equals(f, filter)) - return false; - for (int i = f.length - 1; i >= 0; i--) - filter[i] = f[i]; - - return true; - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite composite = (Composite) super.createDialogArea(parent); - - viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER - | SWT.V_SCROLL); - - Table table = viewer.getTable(); - table.setLayoutData(new GridData(GridData.FILL_BOTH)); - table.setBackground(parent.getBackground()); - createColumns(table); - - //Assign providers to the viewer. - viewer.setContentProvider(viewContentProvider); - viewer.setComparator(viewTraceComparator); - viewer.setLabelProvider(viewViewLabelProvider); - - viewer.setInput(new Object()); - - viewer.addCheckStateListener(new ICheckStateListener() { - @Override - public void checkStateChanged(CheckStateChangedEvent event) { - Object o = event.getElement(); - for (int i = threads.length - 1; i >= 0; i--) { - if (threads[i].equals(o)) - filter[i] = event.getChecked(); - } - } - }); - - if (filter != null) { - for (int i = 0; i < filter.length; i++) - viewer.setChecked(threads[i], filter[i]); - } - - setMessage(Messages.TmfTimeFilterDialog_TRACE_FILTER_DESC); - setTitle(Messages.TmfTimeFilterDialog_TRACE_FILTER); - setDialogHelpAvailable(false); - setHelpAvailable(false); - -// setTitleImage(org.eclipse.hyades.trace.internal.ui.PDPluginImages.DESC_IMG_UI_WZ_EDITPROFSET -// .createImage()); - - return composite; - } - - private void createColumns(Table table) { - table.setHeaderVisible(true); - - String headers[] = { "", Messages.TmfTimeFilterDialog_TRACE_ID, Messages.TmfTimeFilterDialog_TRACE_NAME }; //$NON-NLS-1$ - int width[] = { 20, 80, 400 }; - - for (int i = 0; i < headers.length; i++) { - TableColumn tc = new TableColumn(table, SWT.NONE, i); - tc.setResizable(true); - tc.setText(headers[i]); - tc.setWidth(width[i]); - } - } - - @Override - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText(Messages.TmfTimeFilterDialog_EDIT_PROFILING_OPTIONS); - } - - public boolean[] getFilter() { - return (filter != null) ? Arrays.copyOf(filter, filter.length) : null; - } - - /** - * @param viewContentProvider - */ - public void setViewContentProvider(ViewContentProvider viewContentProvider) { - this.viewContentProvider = viewContentProvider; - } - - /** - * @param viewThreadComparator - */ - public void setViewThreadComparator(TraceComparator viewThreadComparator) { - this.viewTraceComparator = viewThreadComparator; - } - - /** - * @param viewViewLabelProvider - */ - public void setViewViewLabelProvider(ViewLabelProvider viewViewLabelProvider) { - this.viewViewLabelProvider = viewViewLabelProvider; - } - - class ViewContentProvider implements IStructuredContentProvider { - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - @Override - public Object[] getElements(Object input) { - return threads; - } - } - - private static class ViewLabelProvider extends LabelProvider implements - ITableLabelProvider { - @Override - public Image getImage(Object obj) { - return null; - } - - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - @Override - public String getColumnText(Object element, int columnIndex) { - // TODO: AA: Provide Label Provider externally - ITmfTimeAnalysisEntry t = (ITmfTimeAnalysisEntry) element; - - if (columnIndex == 1) - return String.valueOf(t.getId()); - else if (columnIndex == 2) - return t.getName(); - else - return ""; //$NON-NLS-1$ - } - } - - private static class TraceComparator extends ViewerComparator { - @Override - public int compare(Viewer viewer, Object e1, Object e2) { - // TODO: AA: Provide comparator externally - int id1 = ((ITmfTimeAnalysisEntry) e1).getId(); - int id2 = ((ITmfTimeAnalysisEntry) e2).getId(); - - if (id1 == id2) - return 0; - - return (id1 < id2) ? -1 : 1; - // return 0; - } - } -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TmfTimeLegend.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TmfTimeLegend.java deleted file mode 100644 index 2878611024..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TmfTimeLegend.java +++ /dev/null @@ -1,279 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider.StateColor; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Canvas; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; - - -public class TmfTimeLegend extends TitleAreaDialog { - - // public static final String stateNames[] = { - // UIMessages._Unknown, // "Unknown", - // UIMessages._Running, // "Running", - // UIMessages._Sleeping, // "Sleeping", - // UIMessages._Waiting, // "Waiting", - // UIMessages._Blocked, // "Blocked", - // UIMessages._Deadlocked, // "Deadlock", - // UIMessages._Stopped, // "Stopped", - // }; - - // public static final String interactionNames[] = { - // UIMessages._START_THREAD, - // UIMessages._JOIN_TERMINATE, - // UIMessages._WAIT_NOTIFY, - // UIMessages._INTERRUPT, - // UIMessages._RELEASE_ACQUIRE - // }; - - public static final int interactionColors[] = { - TraceColorScheme.TI_START_THREAD, - TraceColorScheme.TI_NOTIFY_JOINED, TraceColorScheme.TI_NOTIFY, - TraceColorScheme.TI_INTERRUPT, TraceColorScheme.TI_HANDOFF_LOCK }; - - protected TraceColorScheme colors; - private TmfTimeAnalysisProvider ifUtil; - - public static void open(Shell parent, TmfTimeAnalysisProvider rifUtil) { - (new TmfTimeLegend(parent, rifUtil)).open(); - } - - public TmfTimeLegend(Shell parent, TmfTimeAnalysisProvider rifUtil) { - super(parent); - colors = new TraceColorScheme(); - this.ifUtil = rifUtil; - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite dlgArea = (Composite) super.createDialogArea(parent); - Composite composite = new Composite(dlgArea, SWT.NONE); - - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - composite.setLayout(layout); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - composite.setLayoutData(gd); - - createThreadStatesGroup(composite); - // createThreadInteractionsGroup(composite); - - setMessage(Messages.TmfTimeLegend_LEGEND); - setTitle(Messages.TmfTimeLegend_TRACE_STATES_TITLE); - setDialogHelpAvailable(false); - setHelpAvailable(false); - - //setTitleImage(org.eclipse.hyades.trace.internal.ui.PDPluginImages.DESC_IMG_UI_WZ_EDITPROFSET.createImage()); - - return composite; - } - - private void createThreadStatesGroup(Composite composite) { - Group gs = new Group(composite, SWT.NONE); - gs.setText(Messages.TmfTimeLegend_TRACE_STATES); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - gs.setLayoutData(gd); - - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginWidth = 20; - layout.marginBottom = 10; - gs.setLayout(layout); - - // Go through all the defined colors and only add the ones you need. - // This will not handle several colors assigned to a color, we have - // 16 mil colors, and should not pick two to mean the same thing. - for (int i = 0; i < TraceColorScheme.getStateColors().length; i++) { - //Get the color enum related to the index - StateColor stateColor = TraceColorScheme.getStateColors()[i]; - //Get the given name, provided by the interface to the application - String stateName = ifUtil.getStateName(stateColor); - if( stateName != "Not mapped" ) { //$NON-NLS-1$ - Bar bar = new Bar(gs, i); - gd = new GridData(); - gd.widthHint = 40; - gd.heightHint = 20; - gd.verticalIndent = 8; - bar.setLayoutData(gd); - Label name = new Label(gs, SWT.NONE); - name.setText(stateName); - gd = new GridData(); - gd.horizontalIndent = 10; - gd.verticalIndent = 8; - name.setLayoutData(gd); - } - } - } - - // private void createThreadInteractionsGroup(Composite composite) { - // Group g = new Group (composite, SWT.NONE); - // g.setText(UIMessages._THREAD_INTERACTIONS); - // GridData gd = new GridData (SWT.FILL, SWT.FILL, true, true); - // g.setLayoutData(gd); - // - // GridLayout layout = new GridLayout(); - // layout.numColumns = 2; - // layout.marginWidth = 20; - // layout.marginBottom = 10; - // g.setLayout(layout); - // - // for (int i=0; i<5; i++) { - // Arrow a = new Arrow(g, interactionColors[i]); - // gd = new GridData(); - // gd.widthHint = 10; - // gd.heightHint = 20; - // gd.verticalIndent = 8; - // a.setLayoutData(gd); - // - // Label name = new Label (g, SWT.NONE); - // name.setText(interactionNames[i]); - // gd = new GridData (); - // gd.horizontalIndent = 4; - // gd.verticalIndent = 8; - // name.setLayoutData(gd); - // } - // - // Mark m = new Mark(g, TraceColorScheme.TI_WAIT_EXCEEDED); - // gd = new GridData(); - // gd.widthHint = 10; - // gd.heightHint = 20; - // gd.verticalIndent = 8; - // m.setLayoutData(gd); - // - // Label name = new Label (g, SWT.NONE); - // name.setText(UIMessages._WAIT_TIMEOUT_EXCEED); - // gd = new GridData (); - // gd.horizontalIndent = 4; - // gd.verticalIndent = 8; - // name.setLayoutData(gd); - // } - - @Override - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText(Messages.TmfTimeLegend_WINDOW_TITLE); - } - - @Override - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, - true); - } - - class Bar extends Canvas { - private Color color; - - public Bar(Composite parent, int colorIdx) { - super(parent, SWT.NONE); - - color = colors.getColor(colorIdx); - addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event event) { - draw(event.gc); - } - }); - } - - private void draw(GC gc) { - Rectangle r = getClientArea(); - gc.setBackground(color); - gc.fillRectangle(r); - gc.setForeground(colors.getColor(TraceColorScheme.BLACK)); - gc.drawRectangle(0, 0, r.width - 1, r.height - 1); - } - } - - class Arrow extends Canvas { - public final static int HEIGHT = 12; - public final static int DX = 3; - - private Color color; - - public Arrow(Composite parent, int colorIdx) { - super(parent, SWT.NONE); - - color = colors.getColor(colorIdx); - addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event event) { - draw(event.gc); - } - }); - } - - private void draw(GC gc) { - Rectangle r = getClientArea(); - gc.setForeground(color); - - int y0, y1; - if (r.height > HEIGHT) { - y0 = (r.height - HEIGHT) / 2; - y1 = y0 + HEIGHT; - } else { - y0 = 0; - y1 = r.height; - } - - gc.drawLine(DX, y0, DX, y1); - - gc.drawLine(0, y0 + 3, DX, y0); - gc.drawLine(2 * DX, y0 + 3, DX, y0); - } - } - - class Mark extends Canvas { - public final static int DX = 3; - - private Color color; - - public Mark(Composite parent, int colorIdx) { - super(parent, SWT.NONE); - - color = colors.getColor(colorIdx); - addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event event) { - draw(event.gc); - } - }); - } - - private void draw(GC gc) { - Rectangle r = getClientArea(); - gc.setBackground(color); - - int y = (r.height - DX) / 2; - int c[] = { 0, y, DX, y + DX, 2 * DX, y }; - gc.fillPolygon(c); - } - } -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeEvent.java index fbd64782b5..02afa7a193 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeEvent.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeEvent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson + * Copyright (c) 2009, 2012 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,6 +8,7 @@ * * Contributors: * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Refactoring *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model; @@ -15,19 +16,19 @@ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model; public interface ITimeEvent { - public ITmfTimeAnalysisEntry getEntry(); + public ITimeGraphEntry getEntry(); - public long getTime(); + public long getTime(); - /** - * @return - * - *

  • -1: Considers duration to be from current event till the next
  • - *
  • 0: Duration is not relevant e.g. a Burst / no state associated
  • - *
  • >0: Valid duration value specified
  • - * - *

    - */ - public long getDuration(); + /** + * @return + * + *

  • -1: Considers duration to be from current event till the next
  • + *
  • 0: Duration is not relevant e.g. a Burst / no state associated
  • + *
  • >0: Valid duration value specified
  • + * + *

    + */ + public long getDuration(); } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeGraphEntry.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeGraphEntry.java new file mode 100644 index 0000000000..e34ef01528 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeGraphEntry.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2009, 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Refactoring + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model; + +import java.util.Iterator; + +public interface ITimeGraphEntry { + + /** + * Returns the parent of this entry, or null if it has none. + * + * @return the parent element, or null if it has none + */ + public ITimeGraphEntry getParent(); + + /** + * Returns whether this entry has children. + * + * @return true if the given element has children, + * and false if it has no children + */ + public boolean hasChildren(); + + /** + * Returns the child elements of this entry. + * + * @return an array of child elements + */ + public ITimeGraphEntry[] getChildren(); + + /** + * Returns the name of this entry. + * + * @return the entry name + */ + public String getName(); + + /** + * Returns the start time of this entry in nanoseconds. + * + * @return the start time + */ + public long getStartTime(); + + /** + * Returns the stop time of this entry in nanoseconds. + * + * @return the stop time + */ + public long getStopTime(); + + /** + * Get an iterator which returns all timeevents + * + * @return the iterator + */ + public Iterator getTimeEventsIterator(); + + /** + * Get an iterator which only returns events that fall within the start time and the stop time. + * The visible duration is the event duration below which further detail is not discernible. + * If no such iterator is implemented, provide a basic iterator which returns all events. + * + * @param startTime start time in nanoseconds + * @param stopTime stop time in nanoseconds + * @param visibleDuration duration of one pixel in nanoseconds + * + * @return the iterator + */ + public Iterator getTimeEventsIterator(long startTime, long stopTime, long visibleDuration); +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITmfTimeAnalysisEntry.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITmfTimeAnalysisEntry.java deleted file mode 100644 index 76ddfc330e..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITmfTimeAnalysisEntry.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model; - -import java.util.Iterator; -import java.util.Vector; - -public interface ITmfTimeAnalysisEntry { - - public String getGroupName(); - - public int getId(); - - public String getName(); - - public long getStartTime(); - - public long getStopTime(); - - /** - * Get a vector containing all events - * @deprecated replaced by {@link #getTraceEventsIterator()} - */ - @Deprecated public Vector getTraceEvents(); - - /** - * Get an iterator which returns all events - */ - public Iterator getTraceEventsIterator(); - - /** - * Get an iterator which only returns events that fall within the start time and the stop time. - * The visible duration is the event duration below which further detail is not discernible. - * If no such iterator is implemented, provide a basic iterator which returns all events. - * - * @param startTime start time in nanoseconds - * @param stopTime stop time in nanoseconds - * @param visibleDuration duration of one pixel in nanoseconds - */ - public Iterator getTraceEventsIterator(long startTime, long stopTime, long visibleDuration); - - public void addTraceEvent(T event); -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeEvent.java index ebdcdde6ba..ee58e90772 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeEvent.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeEvent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson + * Copyright (c) 2012 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -7,30 +7,34 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Initial API and implementation *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model; +public class TimeEvent implements ITimeEvent { + protected ITimeGraphEntry fEntry; + protected long fTime; + protected long fDuration; -public abstract class TimeEvent implements ITimeEvent { - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tlf.widgets.timeAnalysis.model.TmTaEventI#getTrace() - */ - @Override - public abstract ITmfTimeAnalysisEntry getEntry(); - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tlf.widgets.timeAnalysis.model.TmTaEventI#getTime() - */ - @Override - public abstract long getTime(); - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tlf.widgets.timeAnalysis.model.TmTaEventI#getDuration() - */ - @Override - public long getDuration() { - return -1; - } + public TimeEvent(ITimeGraphEntry entry, long time, long duration) { + fEntry = entry; + fTime = time; + fDuration = duration; + } + + @Override + public ITimeGraphEntry getEntry() { + return fEntry; + } + + @Override + public long getTime() { + return fTime; + } + + @Override + public long getDuration() { + return fDuration; + } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java index 73cba5e318..c813a48876 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java @@ -1,68 +1,68 @@ /***************************************************************************** - * Copyright (c) 2007, 2010 Intel Corporation. + * Copyright (c) 2007 Intel Corporation, 2010, 2012 Ericsson. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Intel Corporation - Initial API and implementation - * Ruslan A. Scherbakov, Intel - Initial API and implementation - * Alvaro Sanchex-Leon - Updated for TMF + * Intel Corporation - Initial API and implementation + * Ruslan A. Scherbakov, Intel - Initial API and implementation + * Alvaro Sanchez-Leon - Updated for TMF + * Patrick Tasse - Refactoring * - * $Id: ITimeDataProvider.java,v 1.2 2007/02/27 18:37:36 ewchan Exp $ *****************************************************************************/ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; public interface ITimeDataProvider { - long getSelectedTime(); + long getSelectedTime(); - long getBeginTime(); + long getBeginTime(); - long getEndTime(); + long getEndTime(); - long getMinTime(); + long getMinTime(); - long getMaxTime(); + long getMaxTime(); - long getTime0(); + long getTime0(); - long getTime1(); + long getTime1(); - long getMinTimeInterval(); + long getMinTimeInterval(); - /** - * Updates the time range and notify registered listeners - * - * @param time0 - * @param time1 - */ - void setStartFinishTimeNotify(long time0, long time1); + /** + * Updates the time range and notify registered listeners + * + * @param time0 + * @param time1 + */ + void setStartFinishTimeNotify(long time0, long time1); - /** - * Update the time range but do not trigger event notification - * - * @param time0 - * @param time1 - */ - void setStartFinishTime(long time0, long time1); + /** + * Update the time range but do not trigger event notification + * + * @param time0 + * @param time1 + */ + void setStartFinishTime(long time0, long time1); /** * Notify registered listeners without updating the time range */ void notifyStartFinishTime(); - void setSelectedTimeInt(long time, boolean ensureVisible); + void setSelectedTimeInt(long time, boolean ensureVisible); + + void resetStartFinishTime(); - void resetStartFinishTime(); + int getNameSpace(); - int getNameSpace(); + void setNameSpace(int width); - void setNameSpace(int width); + int getTimeSpace(); - int getTimeSpace(); - - boolean isCalendarFormat(); + boolean isCalendarFormat(); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/PlainSelection.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/PlainSelection.java deleted file mode 100644 index f163fd6afe..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/PlainSelection.java +++ /dev/null @@ -1,71 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2007 Intel Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Intel Corporation - Initial API and implementation - * Ruslan A. Scherbakov, Intel - Initial API and implementation - * Alvaro Sanchex-Leon - Udpated for TMF - * - * $Id: PlainSelection.java,v 1.1 2007/04/20 13:06:49 ewchan Exp $ - *****************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.viewers.IStructuredSelection; - -public class PlainSelection implements IStructuredSelection { - - List list = new ArrayList(); - - public PlainSelection() { - } - - public PlainSelection(Object sel) { - add(sel); - } - - public void add(Object sel) { - if (null != sel && !list.contains(sel)) - list.add(sel); - } - - @Override - public Object getFirstElement() { - if (!list.isEmpty()) - return list.get(0); - return null; - } - - @Override - public Iterator iterator() { - return list.iterator(); - } - - @Override - public int size() { - return list.size(); - } - - @Override - public Object[] toArray() { - return list.toArray(); - } - - @Override - public List toList() { - return list; - } - - @Override - public boolean isEmpty() { - return list.isEmpty(); - } -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphBaseControl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphBaseControl.java new file mode 100644 index 0000000000..d974b4bb32 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphBaseControl.java @@ -0,0 +1,69 @@ +/***************************************************************************** + * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - Initial API and implementation + * Ruslan A. Scherbakov, Intel - Initial API and implementation + * Alvaro Sanchez-Leon - Updated for TMF + * Patrick Tasse - Refactoring + * + *****************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; + +public abstract class TimeGraphBaseControl extends Canvas implements PaintListener { + + static public final int MARGIN = 4; + static public final int EXPAND_SIZE = 9; // the [+] or [-] control size + static public final int RIGHT_MARGIN = 2; // 2 pixels less to make sure end time is visible + static public final int SMALL_ICON_SIZE = 16; + + protected TimeGraphColorScheme _colors; + protected int _fontHeight = 0; + + public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors) { + this(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS); + } + + public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors, int style) { + super(parent, style); + _colors = colors; + addPaintListener(this); + } + + @Override + public void dispose() { + super.dispose(); + } + + @Override + public void paintControl(PaintEvent e) { + if (e.widget != this) + return; + _fontHeight = e.gc.getFontMetrics().getHeight(); + Rectangle bound = getClientArea(); + if (!bound.isEmpty()) { + Color colBackup = e.gc.getBackground(); + paint(bound, e); + e.gc.setBackground(colBackup); + } + } + + public int getFontHeight() { + return _fontHeight; + } + + abstract void paint(Rectangle bound, PaintEvent e); +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphColorScheme.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphColorScheme.java new file mode 100644 index 0000000000..3572c98e9b --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphColorScheme.java @@ -0,0 +1,376 @@ +/***************************************************************************** + * Copyright (c) 2008 Intel Corporation, 2009, 2012 Ericsson. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - Initial API and implementation + * Ruslan A. Scherbakov, Intel - Initial API and implementation + * Alvaro Sanchez-Leon - Updated for TMF + * Patrick Tasse - Refactoring + * + *****************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; + +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider.StateColor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; + + +public class TimeGraphColorScheme { + + // elements color indices + static public final int BLACK_STATE = 0; + static public final int GREEN_STATE = 1; + static public final int DARK_BLUE_STATE = 2; + static public final int ORANGE_STATE = 3; + static public final int GOLD_STATE = 4; + static public final int RED_STATE = 5; + static public final int GRAY_STATE = 6; + static public final int DARK_GREEN_STATE = 7; + static public final int DARK_YELLOW_STATE = 8; + static public final int MAGENTA3_STATE = 9; + static public final int PURPLE1_STATE = 10; + static public final int PINK1_STATE = 11; + static public final int AQUAMARINE_STATE = 12; + static public final int LIGHT_BLUE_STATE = 13; + static public final int CADET_BLUE_STATE = 14; + static public final int OLIVE_STATE = 15; + + static public final int STATES0 = 0; + static public final int STATES1 = 15; + + // State element index to name mapping, must keep the same order as above + public static final StateColor stateColors[] = { StateColor.BLACK, + StateColor.GREEN, StateColor.DARK_BLUE, StateColor.ORANGE, + StateColor.GOLD, StateColor.RED, StateColor.GRAY, StateColor.DARK_GREEN, StateColor.DARK_YELLOW, StateColor.MAGENTA3, StateColor.PURPLE1, + StateColor.PINK1, StateColor.AQUAMARINE, StateColor.LIGHT_BLUE, StateColor.CADET_BLUE, StateColor.OLIVE + }; + + // selected state elements color indices + static public final int BLACK_STATE_SEL = 16; + static public final int GREEN_STATE_SEL = 17; + static public final int DARK_BLUE_STATE_SEL = 18; + static public final int ORANGE_STATE_SEL = 19; + static public final int GOLD_STATE_SEL = 20; + static public final int RED_STATE_SEL = 21; + static public final int GRAY_STATE_SEL = 22; + static public final int DARK_GREEN_STATE_SEL = 23; + static public final int DARK_YELLOW_STATE_SEL = 24; + static public final int MAGENTA3_STATE_SEL = 25; + static public final int PURPLE1_STATE_SEL = 26; + static public final int PINK1_STATE_SEL = 27; + static public final int AQUAMARINE_STATE_SEL = 28; + static public final int LIGHT_BLUE_STATE_SEL = 29; + static public final int CADET_BLUE_STATE_SEL = 30; + static public final int OLIVE_STATE_SEL = 31; + + static public final int STATES_SEL0 = 16; + static public final int STATES_SEL1 = 31; + + // colors indices for viewer controls + static public final int BACKGROUND = 32; + static public final int FOREGROUND = 33; + static public final int BACKGROUND_SEL = 34; + static public final int FOREGROUND_SEL = 35; + static public final int BACKGROUND_SEL_NOFOCUS = 36; + static public final int FOREGROUND_SEL_NOFOCUS = 37; + static public final int TOOL_BACKGROUND = 38; + static public final int TOOL_FOREGROUND = 39; + + // misc colors + static public final int FIX_COLOR = 40; + static public final int WHITE = 41; + static public final int GRAY = 42; + static public final int BLACK = 43; + static public final int DARK_GRAY = 44; + + // selected border color indices + static public final int BLACK_BORDER = 45; + static public final int GREEN_BORDER = 46; + static public final int DARK_BLUE_BORDER = 47; + static public final int ORANGE_BORDER = 48; + static public final int GOLD_BORDER = 49; + static public final int RED_BORDER = 50; + static public final int GRAY_BORDER = 51; + static public final int DARK_GREEN_BORDER1 = 52; + static public final int DARK_YELLOW_BORDER1 = 53; + static public final int MAGENTA3_BORDER1 = 54; + static public final int PURPLE1_BORDER1 = 55; + static public final int PINK1_BORDER1 = 56; + static public final int AQUAMARINE_BORDER1 = 57; + static public final int LIGHT_BLUE_BORDER1 = 58; + static public final int CADET_BLUE_STATE_BORDER = 59; + static public final int OLIVE_BORDER2 = 60; + + static public final int STATES_BORDER0 = 45; + static public final int STATES_BORDER1 = 60; + + static public final int MID_LINE = 61; + static public final int RED = 62; + static public final int GREEN = 63; + static public final int BLUE = 64; + static public final int YELLOW = 65; + static public final int CYAN = 66; + static public final int MAGENTA = 67; + + static public final int SELECTED_TIME = 68; + static public final int LEGEND_BACKGROUND = 69; + static public final int LEGEND_FOREGROUND = 70; + + // group items' colors + static public final int GR_BACKGROUND = 71; + static public final int GR_FOREGROUND = 72; + static public final int GR_BACKGROUND_SEL = 73; + static public final int GR_FOREGROUND_SEL = 74; + static public final int GR_BACKGROUND_SEL_NOFOCUS = 75; + static public final int GR_FOREGROUND_SEL_NOFOCUS = 76; + + static public final int LIGHT_LINE = 77; + static public final int BACKGROUND_NAME = 78; + static public final int BACKGROUND_NAME_SEL = 79; + static public final int BACKGROUND_NAME_SEL_NOFOCUS = 80; + + // Interraction's colors + static public final int TI_START_THREAD = BLACK; + static public final int TI_HANDOFF_LOCK = BLUE; + static public final int TI_NOTIFY_ALL = GREEN; + static public final int TI_NOTIFY = GREEN; + static public final int TI_NOTIFY_JOINED = DARK_GRAY; + static public final int TI_INTERRUPT = RED; + static public final int TI_WAIT_EXCEEDED = BLUE; + + static interface IColorProvider { + public Color get(); + } + + static class SysCol implements IColorProvider { + int syscol; + + SysCol(int syscol) { + this.syscol = syscol; + } + + @Override + public Color get() { + return Utils.getSysColor(syscol); + } + } + + static class RGB implements IColorProvider { + int r; + int g; + int b; + + RGB(int r, int g, int b) { + this.r = r; + this.g = g; + this.b = b; + } + + @Override + public Color get() { + return new Color(null, r, g, b); + } + } + + static class Mix implements IColorProvider { + IColorProvider cp1; + IColorProvider cp2; + int w1; + int w2; + + Mix(IColorProvider cp1, IColorProvider cp2, int w1, int w2) { + this.cp1 = cp1; + this.cp2 = cp2; + this.w1 = w1; + this.w2 = w2; + } + + Mix(IColorProvider cp1, IColorProvider cp2) { + this.cp1 = cp1; + this.cp2 = cp2; + this.w1 = 1; + this.w2 = 1; + } + + @Override + public Color get() { + Color col1 = cp1.get(); + Color col2 = cp2.get(); + Color col = Utils.mixColors(col1, col2, w1, w2); + return col; + } + } + + static private final IColorProvider _providersMap[] = { + // + new RGB(100, 100, 100), // UNKNOWN + new RGB(174, 200, 124), // RUNNING + new Mix(new SysCol(SWT.COLOR_BLUE), new SysCol(SWT.COLOR_GRAY), 1, 3), // SLEEPING + new RGB(210, 150, 60), // WAITING + new RGB(242, 225, 168), // BLOCKED + new Mix(new SysCol(SWT.COLOR_RED), new SysCol(SWT.COLOR_GRAY), 1, 3), // DEADLOCK + new RGB(200, 200, 200), // STOPPED + new RGB(35, 107, 42), // STEEL BLUE + new RGB(205,205,0), // DARK YELLOW + new RGB(205, 0, 205), // MAGENTA + new RGB(171, 130, 255), // PURPLE + new RGB(255, 181, 197), // PINK + new RGB(112, 219, 147), // AQUAMARINE + new RGB(198, 226, 255), // SLATEGRAY + new RGB(95, 158, 160), // CADET BLUE + new RGB(107, 142, 35), // OLIVE + + + //TODO: Does not seem to be used, check during clean-up + new SysCol(SWT.COLOR_WHITE), // UNKNOWN_SEL + new SysCol(SWT.COLOR_GREEN), // RUNNING_SEL + new SysCol(SWT.COLOR_BLUE), // SLEEPING_SEL + new SysCol(SWT.COLOR_CYAN), // WAITING_SEL + new SysCol(SWT.COLOR_YELLOW), // BLOCKED_SEL + new SysCol(SWT.COLOR_RED), // DEADLOCK_SEL + new SysCol(SWT.COLOR_DARK_GRAY), // STOPPED_SEL + new SysCol(SWT.COLOR_WHITE), + new SysCol(SWT.COLOR_GREEN), + new SysCol(SWT.COLOR_BLUE), + new SysCol(SWT.COLOR_CYAN), + new SysCol(SWT.COLOR_YELLOW), + new SysCol(SWT.COLOR_RED), + new SysCol(SWT.COLOR_DARK_GRAY), + new SysCol(SWT.COLOR_WHITE), + new SysCol(SWT.COLOR_GREEN), + + + new SysCol(SWT.COLOR_LIST_BACKGROUND), // BACKGROUND + new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND + new RGB(232, 242, 254), // BACKGROUND_SEL + new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND_SEL + new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // BACKGROUND_SEL_NOFOCUS + new SysCol(SWT.COLOR_WIDGET_FOREGROUND), // FOREGROUND_SEL_NOFOCUS + new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // TOOL_BACKGROUND + new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // TOOL_FOREGROUND + + new SysCol(SWT.COLOR_GRAY), // FIX_COLOR + new SysCol(SWT.COLOR_WHITE), // WHITE + new SysCol(SWT.COLOR_GRAY), // GRAY + new SysCol(SWT.COLOR_BLACK), // BLACK + new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GRAY + + new SysCol(SWT.COLOR_DARK_GRAY), // BLACK_BORDER + new RGB(75, 115, 120), // GREEN_BORDER + new SysCol(SWT.COLOR_DARK_BLUE), // DARK_BLUE_BORDER + new RGB(242, 225, 168), // ORANGE_BORDER + new RGB(210, 150, 60), // GOLD_BORDER + new SysCol(SWT.COLOR_DARK_RED), // RED_BORDER + new SysCol(SWT.COLOR_BLACK), // GRAY_BORDER + new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GREEN_BORDER + new RGB(75, 115, 120), // DARK_YELLOW_BORDER + new SysCol(SWT.COLOR_DARK_BLUE), // MAGENTA3_BORDER + new RGB(242, 225, 168), // PURPLE1_BORDER + new RGB(210, 150, 60), // PINK1_BORDER + new SysCol(SWT.COLOR_DARK_RED), // AQUAMARINE_BORDER + new SysCol(SWT.COLOR_BLACK), // LIGHT_BLUE_BORDER + new SysCol(SWT.COLOR_DARK_GRAY), // BLUE_BORDER + new RGB(75, 115, 120), // OLIVE_BORDER + + + new SysCol(SWT.COLOR_GRAY), // MID_LINE + new SysCol(SWT.COLOR_RED), // RED + new SysCol(SWT.COLOR_GREEN), // GREEN + new SysCol(SWT.COLOR_BLUE), // BLUE + new SysCol(SWT.COLOR_YELLOW), // YELLOW + new SysCol(SWT.COLOR_CYAN), // CYAN + new SysCol(SWT.COLOR_MAGENTA), // MAGENTA + + new SysCol(SWT.COLOR_BLUE), // SELECTED_TIME + new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // LEGEND_BACKGROUND + new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // LEGEND_FOREGROUND + + new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_LIST_BACKGROUND)), // GR_BACKGROUND + new RGB(0, 0, 50), // GR_FOREGROUND + new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_WHITE), 6, 1), // GR_BACKGROUND_SEL + new RGB(0, 0, 50), // GR_FOREGROUND_SEL + new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_WHITE), 6, 1), // GR_BACKGROUND_SEL_NOFOCUS + new RGB(0, 0, 50), // GR_FOREGROUND_SEL_NOFOCUS + + new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 3), // LIGHT_LINE + + new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 6), // BACKGROUND_NAME + new Mix(new SysCol(SWT.COLOR_GRAY), new RGB(232, 242, 254), 1, 6), // BACKGROUND_NAME_SEL + new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_WIDGET_BACKGROUND), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS + }; + + private Color _colors[]; + + public TimeGraphColorScheme() { + _colors = new Color[_providersMap.length]; + } + + public void dispose() { + for (int i = 0; i < _colors.length; i++) { + Utils.dispose(_colors[i]); + _colors[i] = null; + } + } + + public Color getColor(int idx) { + if (null == _colors[idx]) { + if (idx >= STATES_SEL0 && idx <= STATES_SEL1) { + Color col1 = getColor(idx - STATES_SEL0); + Color col2 = getColor(BACKGROUND_SEL); + _colors[idx] = Utils.mixColors(col1, col2, 3, 1); + } else { + _colors[idx] = _providersMap[idx].get(); + } + } + return _colors[idx]; + } + + public Color getBkColor(boolean selected, boolean focused, boolean name) { + if (name) { + if (selected && focused) + return getColor(BACKGROUND_NAME_SEL); + if (selected) + return getColor(BACKGROUND_NAME_SEL_NOFOCUS); + return getColor(BACKGROUND_NAME); + } else { + if (selected && focused) + return getColor(BACKGROUND_SEL); + if (selected) + return getColor(BACKGROUND_SEL_NOFOCUS); + return getColor(BACKGROUND); + } + } + + public Color getFgColor(boolean selected, boolean focused) { + if (selected && focused) + return getColor(FOREGROUND_SEL); + if (selected) + return getColor(FOREGROUND_SEL_NOFOCUS); + return getColor(FOREGROUND); + } + + public Color getBkColorGroup(boolean selected, boolean focused) { + if (selected && focused) + return getColor(GR_BACKGROUND_SEL); + if (selected) + return getColor(GR_BACKGROUND_SEL_NOFOCUS); + return getColor(GR_BACKGROUND); + } + + public Color getFgColorGroup(boolean selected, boolean focused) { + if (selected && focused) + return getColor(GR_FOREGROUND_SEL); + if (selected) + return getColor(GR_FOREGROUND_SEL_NOFOCUS); + return getColor(GR_FOREGROUND); + } + + public static StateColor[] getStateColors() { + return stateColors; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java new file mode 100644 index 0000000000..c49332aead --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java @@ -0,0 +1,1594 @@ +/***************************************************************************** + * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2010, 2011, 2012 Ericsson. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - Initial API and implementation + * Ruslan A. Scherbakov, Intel - Initial API and implementation + * Alvaro Sanchez-Leon - Updated for TMF + * Patrick Tasse - Refactoring + * + *****************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTreeListener; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTreeExpansionEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.MouseMoveListener; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.events.MouseWheelListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.ScrollBar; + +public class TimeGraphControl extends TimeGraphBaseControl implements FocusListener, KeyListener, MouseMoveListener, MouseListener, MouseWheelListener, ControlListener, SelectionListener, MouseTrackListener, TraverseListener, ISelectionProvider { + + private static final int DRAG_NONE = 0; + private static final int DRAG_TRACE_ITEM = 1; + private static final int DRAG_SPLIT_LINE = 2; + public static final boolean DEFAULT_DRAW_THREAD_JOIN = true; + public static final boolean DEFAULT_DRAW_THREAD_WAIT = true; + public static final boolean DEFAULT_DRAW_THREAD_RELEASE = true; + public static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1; + + private static final double zoomCoeff = 1.5; + + private ITimeDataProvider _timeProvider; + private boolean _isInFocus = false; + private boolean _isDragCursor3 = false; + private boolean _isWaitCursor = true; + private boolean _mouseOverSplitLine = false; + private int _itemHeightDefault = 19; + private int _itemHeight = _itemHeightDefault; + private int _minimumItemWidth = 0; + private int _topIndex = 0; + private int _dragState = DRAG_NONE; + private int _dragX0 = 0; + private int _dragX = 0; + private int _idealNameSpace = 0; + // private double _timeStep = 10000000; + private long _time0bak; + private long _time1bak; + private ITimeGraphProvider fTimeGraphProvider = null; + private ItemData _data = null; + private List _selectionListeners; + private List _selectionChangedListeners = new ArrayList(); + private List _treeListeners = new ArrayList(); + private Cursor _dragCursor3; + private Cursor _WaitCursor; + + // Vertical formatting formatting for the state control view + private boolean _visibleVerticalScroll = true; + private int _borderWidth = 0; + private int _headerHeight = 0; + + private Listener mouseScrollFilterListener; + + public TimeGraphControl(Composite parent, TimeGraphColorScheme colors) { + + super(parent, colors, SWT.NO_BACKGROUND | SWT.H_SCROLL | SWT.DOUBLE_BUFFERED); + + _data = new ItemData(); + + addFocusListener(this); + addMouseListener(this); + addMouseMoveListener(this); + addMouseTrackListener(this); + addMouseWheelListener(this); + addTraverseListener(this); + addKeyListener(this); + addControlListener(this); + ScrollBar scrollHor = getHorizontalBar(); + + if (scrollHor != null) { + scrollHor.addSelectionListener(this); + } + + _dragCursor3 = new Cursor(super.getDisplay(), SWT.CURSOR_SIZEWE); + _WaitCursor = new Cursor(super.getDisplay(), SWT.CURSOR_WAIT); + } + + @Override + public void dispose() { + super.dispose(); + _dragCursor3.dispose(); + _WaitCursor.dispose(); + } + + /** + * Sets the timegraph provider used by this timegraph viewer. + * + * @param timeGraphProvider the timegraph provider + */ + public void setTimeGraphProvider(ITimeGraphProvider timeGraphProvider) { + fTimeGraphProvider = timeGraphProvider; + fTimeGraphProvider.setTimeGraphControl(this); + } + + public void setTimeProvider(ITimeDataProvider timeProvider) { + _timeProvider = timeProvider; + adjustScrolls(); + redraw(); + } + + public void addSelectionListener(SelectionListener listener) { + if (listener == null) + SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (null == _selectionListeners) + _selectionListeners = new ArrayList(); + _selectionListeners.add(listener); + } + + public void removeSelectionListener(SelectionListener listener) { + if (null != _selectionListeners) + _selectionListeners.remove(listener); + } + + public void fireSelectionChanged() { + if (null != _selectionListeners) { + Iterator it = _selectionListeners.iterator(); + while (it.hasNext()) { + SelectionListener listener = it.next(); + listener.widgetSelected(null); + } + } + } + + public void fireDefaultSelection() { + if (null != _selectionListeners) { + Iterator it = _selectionListeners.iterator(); + while (it.hasNext()) { + SelectionListener listener = it.next(); + listener.widgetDefaultSelected(null); + } + } + } + + public Object[] getTraces() { + return _data.getTraces(); + } + + public boolean[] getTraceFilter() { + return _data.getTraceFilter(); + } + + public void refreshData() { + _data.refreshData(); + adjustScrolls(); + redraw(); + } + + public void refreshData(ITimeGraphEntry traces[]) { + _data.refreshData(traces); + adjustScrolls(); + redraw(); + } + + public void adjustScrolls() { + if (null == _timeProvider) { + getHorizontalBar().setValues(0, 1, 1, 1, 1, 1); + return; + } + + // HORIZONTAL BAR + // Visible window + long time0 = _timeProvider.getTime0(); + long time1 = _timeProvider.getTime1(); + // Time boundaries + long timeMin = _timeProvider.getMinTime(); + long timeMax = _timeProvider.getMaxTime(); + + long delta = timeMax - timeMin; + + int timePos = 0; + int thumb = H_SCROLLBAR_MAX; + + if (delta != 0) { + // Thumb size (page size) + thumb = Math.max(1, (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta))); + // At the beginning of visible window + timePos = (int) (H_SCROLLBAR_MAX * ((double) (time0 - timeMin) / delta)); + } + + // position, minimum, maximum, thumb size, increment (half page)t, page + // increment size (full page) + getHorizontalBar().setValues(timePos, 0, H_SCROLLBAR_MAX, thumb, Math.max(1, thumb / 2), Math.max(2, thumb)); + } + + boolean ensureVisibleItem(int idx, boolean redraw) { + boolean changed = false; + if (idx < 0) { + for (idx = 0; idx < _data._expandedItems.length; idx++) { + if (((TimeGraphItem) _data._expandedItems[idx])._selected) + break; + } + } + if (idx >= _data._expandedItems.length) + return changed; + if (idx < _topIndex) { + _topIndex = idx; + //FIXME:getVerticalBar().setSelection(_topItem); + if (redraw) + redraw(); + changed = true; + } else { + int page = countPerPage(); + if (idx >= _topIndex + page) { + _topIndex = idx - page + 1; + //FIXME:getVerticalBar().setSelection(_topItem); + if (redraw) + redraw(); + changed = true; + } + } + return changed; + } + + public void setTopIndex(int idx) { + idx = Math.min(idx, _data._expandedItems.length - countPerPage()); + idx = Math.max(0, idx); + _topIndex = idx; + redraw(); + } + + public void setExpandedState(ITimeGraphEntry entry, boolean expanded) { + TimeGraphItem item = _data.findItem(entry); + if (item != null && item._expanded != expanded) { + item._expanded = expanded; + _data.updateExpandedItems(); + redraw(); + } + } + + public void addTreeListener (ITimeGraphTreeListener listener) { + if (!_treeListeners.contains(listener)) { + _treeListeners.add(listener); + } + } + + public void removeTreeListener (ITimeGraphTreeListener listener) { + if (_treeListeners.contains(listener)) { + _treeListeners.remove(listener); + } + } + + public void fireTreeEvent(ITimeGraphEntry entry, boolean expanded) { + TimeGraphTreeExpansionEvent event = new TimeGraphTreeExpansionEvent(this, entry); + for (ITimeGraphTreeListener listener : _treeListeners) { + if (expanded) { + listener.treeExpanded(event); + } else { + listener.treeCollapsed(event); + } + } + } + + @Override + public ISelection getSelection() { + TimeGraphSelection sel = new TimeGraphSelection(); + ITimeGraphEntry trace = getSelectedTrace(); + if (null != trace && null != _timeProvider) { + long selectedTime = _timeProvider.getSelectedTime(); + ITimeEvent event = Utils.findEvent(trace, selectedTime, 0); + if (event != null) + sel.add(event); + else + sel.add(trace); + } + return sel; + } + + public ISelection getSelectionTrace() { + TimeGraphSelection sel = new TimeGraphSelection(); + ITimeGraphEntry trace = getSelectedTrace(); + if (null != trace) { + sel.add(trace); + } + return sel; + } + + public void selectTrace(int n) { + if (n != 1 && n != -1) + return; + boolean changed = false; + int lastSelection = -1; + for (int i = 0; i < _data._expandedItems.length; i++) { + TimeGraphItem item = (TimeGraphItem) _data._expandedItems[i]; + if (item._selected) { + lastSelection = i; + if (1 == n && i < _data._expandedItems.length - 1) { + item._selected = false; + if (item._hasChildren) { + _data.expandItem(i); + fireTreeEvent(item._trace, item._expanded); + } + item = (TimeGraphItem) _data._expandedItems[i + 1]; + if (item._hasChildren) { + _data.expandItem(i + 1); + fireTreeEvent(item._trace, item._expanded); + item = (TimeGraphItem) _data._expandedItems[i + 2]; + } + item._selected = true; + changed = true; + } else if (-1 == n && i > 0) { + i--; + TimeGraphItem prevItem = (TimeGraphItem) _data._expandedItems[i]; + if (prevItem._hasChildren) { + if (prevItem._expanded) { + if (i > 0) { + i--; + prevItem = (TimeGraphItem) _data._expandedItems[i]; + } + } + if (!prevItem._expanded) { + _data.expandItem(i); + fireTreeEvent(prevItem._trace, prevItem._expanded); + prevItem = (TimeGraphItem) _data._expandedItems[i + prevItem.children.size()]; + item._selected = false; + prevItem._selected = true; + changed = true; + } + } else { + item._selected = false; + prevItem._selected = true; + changed = true; + } + } + break; + } + } + if (lastSelection < 0 && _data._expandedItems.length > 0) { + TimeGraphItem item = (TimeGraphItem) _data._expandedItems[0]; + if (item._hasChildren) { + _data.expandItem(0); + fireTreeEvent(item._trace, item._expanded); + item = (TimeGraphItem) _data._expandedItems[1]; + item._selected = true; + changed = true; + } else { + item._selected = true; + changed = true; + } + } + if (changed) { + ensureVisibleItem(-1, false); + redraw(); + fireSelectionChanged(); + } + } + + public void selectEvent(int n) { + if (null == _timeProvider) + return; + ITimeGraphEntry trace = getSelectedTrace(); + if (trace == null) + return; + long selectedTime = _timeProvider.getSelectedTime(); + long endTime = _timeProvider.getEndTime(); + ITimeEvent nextEvent; + if (-1 == n && selectedTime > endTime) + nextEvent = Utils.findEvent(trace, selectedTime, 0); + else + nextEvent = Utils.findEvent(trace, selectedTime, n); + if (null == nextEvent && -1 == n) + nextEvent = Utils.getFirstEvent(trace); + if (null != nextEvent) { + long nextTime = nextEvent.getTime(); + // If last event detected e.g. going back or not moving to a next + // event + if (nextTime <= selectedTime && n == 1) { + // Select to the end of this last event + nextTime = nextEvent.getTime() + nextEvent.getDuration(); + // but not beyond the end of the trace + if (nextTime > endTime) { + nextTime = endTime; + } + } + _timeProvider.setSelectedTimeInt(nextTime, true); + fireSelectionChanged(); + } else if (1 == n) { + _timeProvider.setSelectedTimeInt(endTime, true); + fireSelectionChanged(); + } + } + + public void selectNextEvent() { + selectEvent(1); + // Notify if visible time window has been adjusted + _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1()); + } + + public void selectPrevEvent() { + selectEvent(-1); + // Notify if visible time window has been adjusted + _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1()); + } + + public void selectNextTrace() { + selectTrace(1); + } + + public void selectPrevTrace() { + selectTrace(-1); + } + + /** + * Zooming based on mouse cursor location with mouse scrolling + * + * @param zoomIn + */ + public void zoom(boolean zoomIn) { + int globalX = getDisplay().getCursorLocation().x; + Point p = toControl(globalX, 0); + int nameSpace = _timeProvider.getNameSpace(); + int timeSpace = _timeProvider.getTimeSpace(); + int xPos = Math.max(nameSpace, Math.min(nameSpace + timeSpace, p.x)); + long time0 = _timeProvider.getTime0(); + long time1 = _timeProvider.getTime1(); + long interval = time1 - time0; + if (interval == 0) { + interval = 1; + } // to allow getting out of single point interval + long newInterval; + if (zoomIn) { + newInterval = Math.max(Math.round((double) interval * 0.8), _timeProvider.getMinTimeInterval()); + } else { + newInterval = (long) Math.ceil((double) interval * 1.25); + } + long center = time0 + Math.round(((double) (xPos - nameSpace) / timeSpace * interval)); + long newTime0 = center - Math.round((double) newInterval * (center - time0) / interval); + long newTime1 = newTime0 + newInterval; + _timeProvider.setStartFinishTime(newTime0, newTime1); + } + + /** + * zoom in using single click + */ + public void zoomIn() { + long _time0 = _timeProvider.getTime0(); + long _time1 = _timeProvider.getTime1(); + long _range = _time1 - _time0; + long selTime = _timeProvider.getSelectedTime(); + if (selTime <= _time0 || selTime >= _time1) { + selTime = (_time0 + _time1) / 2; + } + long time0 = selTime - (long) ((selTime - _time0) / zoomCoeff); + long time1 = selTime + (long) ((_time1 - selTime) / zoomCoeff); + + long inaccuracy = (_timeProvider.getMaxTime() - _timeProvider.getMinTime()) - (time1 - time0); + + // Trace.debug("selTime:" + selTime + " time0:" + time0 + " time1:" + // + time1 + " inaccuracy:" + inaccuracy); + + if (inaccuracy > 0 && inaccuracy < 100) { + _timeProvider.setStartFinishTimeNotify(_timeProvider.getMinTime(), _timeProvider.getMaxTime()); + return; + } + + long m = _timeProvider.getMinTimeInterval(); + if ((time1 - time0) < m) { + time0 = selTime - (long) ((selTime - _time0) * m / _range); + time1 = time0 + m; + } + + _timeProvider.setStartFinishTimeNotify(time0, time1); + } + + /** + * zoom out using single click + */ + public void zoomOut() { + long _time0 = _timeProvider.getTime0(); + long _time1 = _timeProvider.getTime1(); + long selTime = _timeProvider.getSelectedTime(); + if (selTime <= _time0 || selTime >= _time1) { + selTime = (_time0 + _time1) / 2; + } + long time0 = (long) (selTime - (selTime - _time0) * zoomCoeff); + long time1 = (long) (selTime + (_time1 - selTime) * zoomCoeff); + + long inaccuracy = (_timeProvider.getMaxTime() - _timeProvider.getMinTime()) - (time1 - time0); + if (inaccuracy > 0 && inaccuracy < 100) { + _timeProvider.setStartFinishTimeNotify(_timeProvider.getMinTime(), _timeProvider.getMaxTime()); + return; + } + + _timeProvider.setStartFinishTimeNotify(time0, time1); + } + + public ITimeGraphEntry getSelectedTrace() { + ITimeGraphEntry trace = null; + int idx = getSelectedIndex(); + if (idx >= 0) + trace = _data._expandedItems[idx]._trace; + return trace; + } + + public int getSelectedIndex() { + int idx = -1; + for (int i = 0; i < _data._expandedItems.length; i++) { + TimeGraphItem item = (TimeGraphItem) _data._expandedItems[i]; + if (item._selected) { + idx = i; + break; + } + } + return idx; + } + + boolean toggle(int idx) { + boolean toggled = false; + if (idx >= 0 && idx < _data._expandedItems.length) { + TimeGraphItem item = (TimeGraphItem) _data._expandedItems[idx]; + if (item._hasChildren) { + item._expanded = !item._expanded; + _data.updateExpandedItems(); + adjustScrolls(); + redraw(); + toggled = true; + fireTreeEvent(item._trace, item._expanded); + } + } + return toggled; + } + + int getItemIndexAtY(int y) { + if (y < 0) { + return -1; + } + int idx = y / _itemHeight; + idx += _topIndex; + if (idx < _data._expandedItems.length) { + return idx; + } + return -1; + } + + boolean isOverSplitLine(int x) { + if (x < 0 || null == _timeProvider) + return false; + int w = 4; + int nameWidth = _timeProvider.getNameSpace(); + if (x > nameWidth - w && x < nameWidth + w) { + return true; + } else { + return false; + } + } + + TimeGraphItem getItem(Point pt) { + int idx = getItemIndexAtY(pt.y); + return idx >= 0 ? (TimeGraphItem) _data._expandedItems[idx] : null; + } + + long getTimeAtX(int x) { + if (null == _timeProvider) + return -1; + long hitTime = -1; + Point size = getCtrlSize(); + long time0 = _timeProvider.getTime0(); + long time1 = _timeProvider.getTime1(); + int nameWidth = _timeProvider.getNameSpace(); + x -= nameWidth; + if (x >= 0 && size.x >= nameWidth) { + if (time1 - time0 > size.x - nameWidth - RIGHT_MARGIN) { + // get the last possible time represented by the pixel position + // by taking the time of the next pixel position minus 1 + // nanosecond + hitTime = time0 + (long) ((time1 - time0) * ((double) (x + 1) / (size.x - nameWidth - RIGHT_MARGIN))) - 1; + } else { + hitTime = time0 + (long) ((time1 - time0) * ((double) (x) / (size.x - nameWidth - RIGHT_MARGIN))); + } + } + return hitTime; + } + + void selectItem(int idx, boolean addSelection) { + boolean changed = false; + if (addSelection) { + if (idx >= 0 && idx < _data._expandedItems.length) { + TimeGraphItem item = (TimeGraphItem) _data._expandedItems[idx]; + changed = (item._selected == false); + item._selected = true; + } + } else { + for (int i = 0; i < _data._expandedItems.length; i++) { + TimeGraphItem item = (TimeGraphItem) _data._expandedItems[i]; + if ((i == idx && !item._selected) || (idx == -1 && item._selected)) { + changed = true; + } + item._selected = i == idx; + } + } + changed |= ensureVisibleItem(idx, true); + if (changed) + redraw(); + } + + public void selectItem(ITimeGraphEntry trace, boolean addSelection) { + int idx = _data.findItemIndex(trace); + selectItem(idx, addSelection); + } + + public int countPerPage() { + int height = getCtrlSize().y; + int count = 0; + if (height > 0) + count = height / _itemHeight; + return count; + } + + public int getTopIndex() { + return _topIndex; + } + + public int getExpandedElementCount() { + return _data._expandedItems.length; + } + + Point getCtrlSize() { + Point size = getSize(); + if (getHorizontalBar().isVisible()) { + size.y -= getHorizontalBar().getSize().y; + } + return size; + } + + Rectangle getNameRect(Rectangle bound, int idx, int nameWidth) { + idx -= _topIndex; + int x = bound.x; + int y = bound.y + idx * _itemHeight; + int width = nameWidth; + int height = _itemHeight; + return new Rectangle(x, y, width, height); + } + + Rectangle getStatesRect(Rectangle bound, int idx, int nameWidth) { + idx -= _topIndex; + int x = bound.x + nameWidth; + int y = bound.y + idx * _itemHeight; + int width = bound.width - x; + int height = _itemHeight; + return new Rectangle(x, y, width, height); + } + + public void drawTraceEvent(Rectangle bound, ITimeEvent e, int nItem, int color, GC gc) { + int nameWidth = _timeProvider.getNameSpace(); + + long time0 = _timeProvider.getTime0(); + long time1 = _timeProvider.getTime1(); + if (time0 == time1) + return; + + int xr = bound.x + nameWidth; + double pixelsPerNanoSec = (bound.width - xr <= RIGHT_MARGIN) ? 0 : (double) (bound.width - xr - RIGHT_MARGIN) / (time1 - time0); + + int x0 = xr + (int) ((e.getTime() - time0) * pixelsPerNanoSec); + if (x0 < xr) + return; + + int y0 = bound.y + (nItem - _topIndex) * _itemHeight + 3; + + gc.setBackground(_colors.getColor(color)); + int c[] = { x0 - 3, y0 - 3, x0, y0, x0 + 3, y0 - 3 }; + gc.fillPolygon(c); + } + + @Override + void paint(Rectangle bounds, PaintEvent e) { + GC gc = e.gc; + gc.setBackground(_colors.getColor(TimeGraphColorScheme.BACKGROUND)); + drawBackground(gc, bounds.x, bounds.y, bounds.width, bounds.height); + + if (bounds.width < 2 || bounds.height < 2 || null == _timeProvider) + return; + + _idealNameSpace = 0; + int nameSpace = _timeProvider.getNameSpace(); + + // draw empty name space background + int nbDrawn = _data._expandedItems.length - _topIndex; + if (_itemHeight * nbDrawn < bounds.height) { + gc.setBackground(_colors.getBkColor(false, false, true)); + drawBackground(gc, bounds.x, _itemHeight * nbDrawn, nameSpace, bounds.height - _itemHeight * nbDrawn); + } + + fTimeGraphProvider.drawItems(bounds, _timeProvider, _data._expandedItems, _topIndex, nameSpace, gc); + + // draw selected time + long time0 = _timeProvider.getTime0(); + long time1 = _timeProvider.getTime1(); + long selectedTime = _timeProvider.getSelectedTime(); + double pixelsPerNanoSec = (bounds.width - nameSpace <= RIGHT_MARGIN) ? 0 : (double) (bounds.width - nameSpace - RIGHT_MARGIN) / (time1 - time0); + int x = bounds.x + nameSpace + (int) ((double) (selectedTime - time0) * pixelsPerNanoSec); + if (x >= nameSpace && x < bounds.x + bounds.width) { + gc.setForeground(_colors.getColor(TimeGraphColorScheme.SELECTED_TIME)); + gc.drawLine(x, bounds.y, x, bounds.y + bounds.height); + } + + // draw drag line, no line if name space is 0. + if (DRAG_SPLIT_LINE == _dragState) { + gc.setForeground(_colors.getColor(TimeGraphColorScheme.BLACK)); + gc.drawLine(bounds.x + nameSpace, bounds.y, bounds.x + nameSpace, bounds.y + bounds.height - 1); + } else if (DRAG_NONE == _dragState && _mouseOverSplitLine && _timeProvider.getNameSpace() > 0) { + gc.setForeground(_colors.getColor(TimeGraphColorScheme.RED)); + gc.drawLine(bounds.x + nameSpace, bounds.y, bounds.x + nameSpace, bounds.y + bounds.height - 1); + } + } + + public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, TimeGraphItem[] items, int topIndex, int nameSpace, GC gc) { + // draw trace states + for (int i = topIndex; i < items.length; i++) { + TimeGraphItem item = (TimeGraphItem) items[i]; + fTimeGraphProvider.drawItem(item, bounds, timeProvider, i, nameSpace, gc); + } + } + + /** + * Draws the item + * + * @param item the item to draw + * @param bounds the container rectangle + * @param i the item index + * @param nameSpace the name space + * @param gc + */ + public void drawItem(TimeGraphItem item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) { + long time0 = timeProvider.getTime0(); + long time1 = timeProvider.getTime1(); + long endTime = timeProvider.getEndTime(); + long selectedTime = timeProvider.getSelectedTime(); + + Rectangle nameRect = getNameRect(bounds, i, nameSpace); + if (nameRect.y >= bounds.y + bounds.height) { + return; + } + + if (item._trace.getTimeEventsIterator() == null) { + Rectangle statesRect = getStatesRect(bounds, i, nameSpace); + nameRect.width += statesRect.width; + drawName(item, nameRect, gc); + } else { + drawName(item, nameRect, gc); + } + Rectangle rect = getStatesRect(bounds, i, nameSpace); + if (rect.isEmpty()) + return; + if (time1 <= time0) { + gc.setBackground(_colors.getBkColor(false, false, false)); + gc.fillRectangle(rect); + return; + } + + // Initialize _rect1 to same values as enclosing rectangle rect + Rectangle stateRect = Utils.clone(rect); + boolean selected = item._selected; + // K pixels per second + double pixelsPerNanoSec = (rect.width <= RIGHT_MARGIN) ? 0 : (double) (rect.width - RIGHT_MARGIN) / (time1 - time0); + + boolean group = item._trace.getTimeEventsIterator() == null; + + if (group) { + // gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus)); + // gc.fillRectangle(rect); + } else { + ITimeGraphEntry trace = item._trace; + + double x0 = rect.x; + long maxDuration = (timeProvider.getTimeSpace() == 0) ? Long.MAX_VALUE : 1 * (time1 - time0) / timeProvider.getTimeSpace(); + Iterator iterator = trace.getTimeEventsIterator(time0, time1, maxDuration); + // Drawing rectangle is smaller than reserved space + stateRect.y += 3; + stateRect.height -= 6; + + // Clean up to empty line to draw on top + int xEnd = rect.x + rect.width; + fillSpace(rect, gc, selected); + if (iterator.hasNext()) { + ITimeEvent currEvent = iterator.next(); + ITimeEvent nextEvent = null; + long currEventTime = currEvent.getTime(); + long currEventDuration = currEvent.getDuration(); + // initial value + long nextEventTime = currEventTime; + // x0 - Points to the beginning of the event being drawn + double step = (double) ((currEventTime - time0) * pixelsPerNanoSec); + x0 = rect.x + step; + // xEnd - Points to the end of the events rectangle + double x1 = -1; + double xNext = 0; + + // draw event states + while (/* x0 <= xEnd && */null != currEvent) { + boolean stopped = false;// currEvent instanceof + // refresh current event duration as the loop moves + currEventDuration = currEvent.getDuration(); + // TsfTmTraceDeadEvent; + if (iterator.hasNext()) { + nextEvent = iterator.next(); + nextEventTime = nextEvent.getTime(); + } else if (stopped) { + nextEvent = null; + nextEventTime = time1; + } else { + nextEvent = null; + nextEventTime = endTime; + } + + // Calculate position to next event + xNext = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); + + // Calculate end position of current event + if (currEventDuration < 0) { + x1 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); + } else if (currEventDuration == 0) { + x1 = x0; + } else { + x1 = x0 + (double) ((currEventDuration) * pixelsPerNanoSec); + } + + // If event end position x1 further away than start position + // of next event, cut width till next event + if (currEventDuration != 0) { + x1 = x1 > xNext ? xNext : x1; + } + // if event end boundary is within time range + if (x1 >= rect.x && x0 <= xEnd) { + if (currEventDuration != 0) { + x0 = (double) (x0 >= rect.x ? x0 : rect.x); + stateRect.width = (int) ((x1 <= xEnd ? x1 : xEnd) - x0); + } else { + stateRect.width = 1; + } + stateRect.width = Math.max(getMinimumItemWidth(), stateRect.width); + stateRect.x = (int) x0; + boolean timeSelected = currEventTime <= selectedTime && selectedTime < nextEventTime; + fTimeGraphProvider.drawState(_colors, currEvent, stateRect, gc, selected, false, timeSelected); + // Advance rectangle to next start position and Fill + // with space until next event + stateRect.x += stateRect.width; + x0 = stateRect.x; + } + + // lastEvent = currEvent; + currEvent = nextEvent; + currEventTime = nextEventTime; + // Move x0 to the beginning of next event + x0 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); + } + } + } + } + + void drawName(TimeGraphItem item, Rectangle bounds, GC gc) { + boolean group = item._trace.getTimeEventsIterator() == null; + if (group) { + gc.setBackground(_colors.getBkColorGroup(item._selected, _isInFocus)); + gc.fillRectangle(bounds); + if (item._selected && _isInFocus) { + gc.setForeground(_colors.getBkColor(item._selected, _isInFocus, false)); + gc.drawRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1); + } + } else { + gc.setBackground(_colors.getBkColor(item._selected, _isInFocus, true)); + gc.setForeground(_colors.getFgColor(item._selected, _isInFocus)); + gc.fillRectangle(bounds); + } + + // No name to be drawn + if (_timeProvider.getNameSpace() == 0) { + return; + } + + int leftMargin = MARGIN + item.level * EXPAND_SIZE; + if (item._hasChildren) { + gc.setForeground(_colors.getFgColorGroup(false, false)); + gc.setBackground(_colors.getBkColor(false, false, false)); + Rectangle rect = Utils.clone(bounds); + rect.x += leftMargin; + rect.y += (bounds.height - EXPAND_SIZE) / 2; + rect.width = EXPAND_SIZE; + rect.height = EXPAND_SIZE; + gc.fillRectangle(rect); + gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1); + int midy = rect.y + rect.height / 2; + gc.drawLine(rect.x + 2, midy, rect.x + rect.width - 3, midy); + if (!item._expanded) { + int midx = rect.x + rect.width / 2; + gc.drawLine(midx, rect.y + 2, midx, rect.y + rect.height - 3); + } + } + leftMargin += EXPAND_SIZE + MARGIN; + + Image img = fTimeGraphProvider.getItemImage(item._trace); + if (img != null) { + // draw icon + int imgHeight = img.getImageData().height; + int imgWidth = img.getImageData().width; + int x = leftMargin; + int y = bounds.y + (bounds.height - imgHeight) / 2; + gc.drawImage(img, x, y); + leftMargin += imgWidth + MARGIN; + } + String name = item._name; + Point size = gc.stringExtent(name); + if (_idealNameSpace < leftMargin + size.x + MARGIN) { + _idealNameSpace = leftMargin + size.x + MARGIN; + } + if (!group) { + // cut long string with "..." + int width = bounds.width - leftMargin; + int cuts = 0; + while (size.x > width && name.length() > 1) { + cuts++; + name = name.substring(0, name.length() - 1); + size = gc.stringExtent(name + "..."); //$NON-NLS-1$ + } + if (cuts > 0) { + name += "..."; //$NON-NLS-1$ + } + } + Rectangle rect = Utils.clone(bounds); + rect.x += leftMargin; + rect.width -= leftMargin; + // draw text + if (rect.width > 0) { + rect.y += 2; + int textWidth = Utils.drawText(gc, name, rect, true); + leftMargin += textWidth + MARGIN; + rect.y -= 2; + + if (!group) { + // draw middle line + int x = bounds.x + leftMargin; + int width = bounds.width - x; + int midy = bounds.y + bounds.height / 2; + gc.setForeground(_colors.getColor(TimeGraphColorScheme.MID_LINE)); + gc.drawLine(x, midy, x + width, midy); + } + } + } + + public void drawState(TimeGraphColorScheme colors, int colorIdx, + Rectangle rect, GC gc, boolean selected, boolean rectBound, + boolean timeSelected) { + + boolean visible = rect.width == 0 ? false : true; + int colorIdx1 = colorIdx; + + timeSelected = timeSelected && selected; + if (timeSelected) { + colorIdx1 = colorIdx + TimeGraphColorScheme.STATES_SEL0 - TimeGraphColorScheme.STATES0; + } + + if (visible) { + // fill all rect area + if (rect.isEmpty()) + return; + + gc.setBackground(colors.getColor(colorIdx1)); + gc.fillRectangle(rect); + colorIdx1 = colorIdx + TimeGraphColorScheme.STATES_BORDER0 - TimeGraphColorScheme.STATES0; + gc.setForeground(colors.getColor(colorIdx1)); + + // draw bounds + if (!timeSelected) { + if (rectBound && rect.width >= 3) { + gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1); + } else { + // 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); + // bottom + gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1); + } + } + } else { + // selected rectangle area is not visible but can be represented + // with a broken vertical line of specified width. + int width = 2; + rect.width = width; + // check if height is greater than zero. + if (rect.isEmpty()) + return; + // colorIdx1 = TraceColorScheme.BLACK; + gc.setForeground(colors.getColor(colorIdx)); + int s = gc.getLineStyle(); + int w = gc.getLineWidth(); + gc.setLineStyle(SWT.LINE_DOT); + gc.setLineWidth(width); + // Trace.debug("Reactangle not visible, drawing vertical line with: " + // + rect.x + "," + rect.y + "," + rect.x + "," + rect.y + // + rect.height); + gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height); + gc.setLineStyle(s); + gc.setLineWidth(w); + } + } + + private void fillSpace(Rectangle rect, GC gc, boolean selected) { + gc.setBackground(_colors.getBkColor(selected, _isInFocus, false)); + gc.fillRectangle(rect); + // draw middle line + gc.setForeground(_colors.getColor(TimeGraphColorScheme.MID_LINE)); + int midy = rect.y + rect.height / 2; + gc.drawLine(rect.x, midy, rect.x + rect.width, midy); + } + + @Override + public void keyTraversed(TraverseEvent e) { + if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) + e.doit = true; + } + + @Override + public void keyPressed(KeyEvent e) { + int idx = -1; + if (_data._expandedItems.length == 0) { + return; + } + if (SWT.HOME == e.keyCode) { + idx = 0; + } else if (SWT.END == e.keyCode) { + idx = _data._expandedItems.length - 1; + } else if (SWT.ARROW_DOWN == e.keyCode) { + idx = getSelectedIndex(); + if (idx < 0) + idx = 0; + else if (idx < _data._expandedItems.length - 1) + idx++; + } else if (SWT.ARROW_UP == e.keyCode) { + idx = getSelectedIndex(); + if (idx < 0) + idx = 0; + else if (idx > 0) + idx--; + } else if (SWT.ARROW_LEFT == e.keyCode) { + selectPrevEvent(); + } else if (SWT.ARROW_RIGHT == e.keyCode) { + selectNextEvent(); + } else if (SWT.PAGE_DOWN == e.keyCode) { + int page = countPerPage(); + idx = getSelectedIndex(); + if (idx < 0) + idx = 0; + idx += page; + if (idx >= _data._expandedItems.length) + idx = _data._expandedItems.length - 1; + } else if (SWT.PAGE_UP == e.keyCode) { + int page = countPerPage(); + idx = getSelectedIndex(); + if (idx < 0) + idx = 0; + idx -= page; + if (idx < 0) + idx = 0; + } else if (SWT.CR == e.keyCode) { + idx = getSelectedIndex(); + if (idx >= 0) { + if (_data._expandedItems[idx]._hasChildren) { + toggle(idx); + } else { + fireDefaultSelection(); + } + } + idx = -1; + } + if (idx >= 0) { + selectItem(idx, false); + fireSelectionChanged(); + } + } + + @Override + public void keyReleased(KeyEvent e) { + } + + @Override + public void focusGained(FocusEvent e) { + _isInFocus = true; + redraw(); + } + + @Override + public void focusLost(FocusEvent e) { + _isInFocus = false; + if (DRAG_NONE != _dragState) { + setCapture(false); + _dragState = DRAG_NONE; + } + redraw(); + } + + public boolean isInFocus() { + return _isInFocus; + } + + @Override + public void mouseMove(MouseEvent e) { + if (null == _timeProvider) + return; + Point size = getCtrlSize(); + if (DRAG_TRACE_ITEM == _dragState) { + int nameWidth = _timeProvider.getNameSpace(); + int x = e.x - nameWidth; + if (x > 0 && size.x > nameWidth && _dragX != x) { + _dragX = x; + double pixelsPerNanoSec = (size.x - nameWidth <= RIGHT_MARGIN) ? 0 : (double) (size.x - nameWidth - RIGHT_MARGIN) / (_time1bak - _time0bak); + long timeDelta = (long) ((pixelsPerNanoSec == 0) ? 0 : ((_dragX - _dragX0) / pixelsPerNanoSec)); + long time1 = _time1bak - timeDelta; + long maxTime = _timeProvider.getMaxTime(); + if (time1 > maxTime) + time1 = maxTime; + long time0 = time1 - (_time1bak - _time0bak); + if (time0 < _timeProvider.getMinTime()) { + time0 = _timeProvider.getMinTime(); + time1 = time0 + (_time1bak - _time0bak); + } + _timeProvider.setStartFinishTime(time0, time1); + } + } else if (DRAG_SPLIT_LINE == _dragState) { + _dragX = e.x; + _timeProvider.setNameSpace(e.x); + } else if (DRAG_NONE == _dragState) { + boolean mouseOverSplitLine = isOverSplitLine(e.x); + if (_mouseOverSplitLine != mouseOverSplitLine) { + redraw(); + } + _mouseOverSplitLine = mouseOverSplitLine; + // Make sure any time changes are notified to the application e.g. + // getting back from the horizontal scroll bar or zoomed using the + // mouse wheel + _timeProvider.notifyStartFinishTime(); + } + updateCursor(e.x, e.y); + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + if (null == _timeProvider) + return; + if (1 == e.button) { + if (isOverSplitLine(e.x) && _timeProvider.getNameSpace() != 0) { + _timeProvider.setNameSpace(_idealNameSpace); + boolean mouseOverSplitLine = isOverSplitLine(e.x); + if (_mouseOverSplitLine != mouseOverSplitLine) { + redraw(); + } + _mouseOverSplitLine = mouseOverSplitLine; + return; + } + int idx = getItemIndexAtY(e.y); + if (idx >= 0) { + selectItem(idx, false); + fireDefaultSelection(); + } + } + } + + /** + *

    + * If the x, y position is over the vertical split line (name to time + * ranges), then change the cursor to a drag cursor to indicate the user the + * possibility of resizing + *

    + * + * @param x + * @param y + */ + void updateCursor(int x, int y) { + // if Wait cursor not active, check for the need to change to a drag + // cursor + if (_isWaitCursor == false) { + boolean isSplitLine = isOverSplitLine(x); + // No dragcursor is name space is fixed to zero + if (isSplitLine && !_isDragCursor3 && _timeProvider.getNameSpace() > 0) { + setCursor(_dragCursor3); + _isDragCursor3 = true; + } else if (!isSplitLine && _isDragCursor3) { + setCursor(null); + _isDragCursor3 = false; + } + } + } + + /** + * Provide the possibilty to control the wait cursor externally e.g. data + * requests in progress + * + * @param waitInd + */ + public void waitCursor(boolean waitInd) { + // Update cursor as indicated + if (waitInd) { + setCursor(_WaitCursor); + _isWaitCursor = true; + } else { + setCursor(null); + _isWaitCursor = false; + } + + // Get ready for next mouse move + _isDragCursor3 = false; + } + + @Override + public void mouseDown(MouseEvent e) { + if (null == _timeProvider) + return; + int idx; + if (1 == e.button) { + int nameSpace = _timeProvider.getNameSpace(); + if (nameSpace != 0) { + if (isOverSplitLine(e.x)) { + _dragState = DRAG_SPLIT_LINE; + _dragX = _dragX0 = e.x; + _time0bak = _timeProvider.getTime0(); + _time1bak = _timeProvider.getTime1(); + redraw(); + return; + } + } + + idx = getItemIndexAtY(e.y); + if (idx >= 0) { + TimeGraphItem item = _data._expandedItems[idx]; + if (item._hasChildren && e.x < nameSpace && e.x < MARGIN + (item.level + 1) * EXPAND_SIZE) { + toggle(idx); + } else { + long hitTime = getTimeAtX(e.x); + if (hitTime >= 0) { + // _timeProvider.setSelectedTimeInt(hitTime, false); + setCapture(true); + _dragState = DRAG_TRACE_ITEM; + _dragX = _dragX0 = e.x - nameSpace; + _time0bak = _timeProvider.getTime0(); + _time1bak = _timeProvider.getTime1(); + } + } + selectItem(idx, false); + fireSelectionChanged(); + } else { + selectItem(idx, false); // clear selection + redraw(); + fireSelectionChanged(); + } + } + } + + @Override + public void mouseUp(MouseEvent e) { + if (DRAG_NONE != _dragState) { + setCapture(false); + if (DRAG_TRACE_ITEM == _dragState) { + // Notify time provider to check the need for listener + // notification + _timeProvider.notifyStartFinishTime(); + if (_dragX == _dragX0) { // click without drag + long time = getTimeAtX(e.x); + _timeProvider.setSelectedTimeInt(time, false); + } + } else if (DRAG_SPLIT_LINE == _dragState) { + redraw(); + } + _dragState = DRAG_NONE; + } + } + + @Override + public void controlMoved(ControlEvent e) { + } + + @Override + public void controlResized(ControlEvent e) { + adjustScrolls(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + + @Override + public void widgetSelected(SelectionEvent e) { + if (e.widget == getVerticalBar()) { + _topIndex = getVerticalBar().getSelection(); + if (_topIndex < 0) + _topIndex = 0; + redraw(); + } else if (e.widget == getHorizontalBar() && null != _timeProvider) { + int start = getHorizontalBar().getSelection(); + long time0 = _timeProvider.getTime0(); + long time1 = _timeProvider.getTime1(); + long timeMin = _timeProvider.getMinTime(); + long timeMax = _timeProvider.getMaxTime(); + long delta = timeMax - timeMin; + + long range = time1 - time0; + // _timeRangeFixed = true; + time0 = timeMin + Math.round(delta * ((double) start / H_SCROLLBAR_MAX)); + time1 = time0 + range; + + // TODO: Follow-up with Bug 310310 + // In Linux SWT.DRAG is the only value received + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310 + if (e.detail == SWT.DRAG) { + _timeProvider.setStartFinishTime(time0, time1); + } else { + _timeProvider.setStartFinishTimeNotify(time0, time1); + } + } + } + + @Override + public void mouseEnter(MouseEvent e) { + if (mouseScrollFilterListener == null) { + mouseScrollFilterListener = new Listener() { + // This filter is used to prevent scrolling of the view when the + // mouse wheel is used to zoom + @Override + public void handleEvent(Event event) { + event.doit = false; + } + }; + getDisplay().addFilter(SWT.MouseWheel, mouseScrollFilterListener); + } + } + + @Override + public void mouseExit(MouseEvent e) { + if (mouseScrollFilterListener != null) { + getDisplay().removeFilter(SWT.MouseWheel, mouseScrollFilterListener); + mouseScrollFilterListener = null; + } + if (_mouseOverSplitLine) { + _mouseOverSplitLine = false; + redraw(); + } + } + + @Override + public void mouseHover(MouseEvent e) { + } + + @Override + public void mouseScrolled(MouseEvent e) { + if ((mouseScrollFilterListener == null) || _dragState != DRAG_NONE) { + return; + } + if (e.x < _timeProvider.getNameSpace()) { + setTopIndex(getTopIndex() - e.count); + } else { + if (e.count > 0) { + zoom(true); + } else if (e.count < 0) { + zoom(false); + } + } + } + + public boolean isVisibleVerticalScroll() { + return _visibleVerticalScroll; + } + + @Override + public int getBorderWidth() { + return _borderWidth; + } + + public void setBorderWidth(int borderWidth) { + this._borderWidth = borderWidth; + } + + public int getHeaderHeight() { + return _headerHeight; + } + + public void setHeaderHeight(int headerHeight) { + this._headerHeight = headerHeight; + } + + public int getItemHeight() { + return _itemHeight; + } + + public void setItemHeight(int rowHeight) { + this._itemHeight = rowHeight; + } + + public void setMinimumItemWidth(int width) { + this._minimumItemWidth = width; + } + + public int getMinimumItemWidth() { + return _minimumItemWidth; + } + + public Vector getFilteredOut() { + return _data.getFilteredOut(); + } + + // @Override + @Override + public void addSelectionChangedListener(ISelectionChangedListener listener) { + if (listener != null) { + if (!_selectionChangedListeners.contains(listener)) { + _selectionChangedListeners.add(listener); + } + } + } + + // @Override + @Override + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + if (listener != null) { + _selectionChangedListeners.remove(listener); + } + } + + // @Override + @Override + public void setSelection(ISelection selection) { + if (selection instanceof TimeGraphSelection) { + TimeGraphSelection sel = (TimeGraphSelection) selection; + Object ob = sel.getFirstElement(); + if (ob instanceof ITimeGraphEntry) { + ITimeGraphEntry trace = (ITimeGraphEntry) ob; + selectItem(trace, false); + } + } + + } + +} + +class ItemData { + public TimeGraphItem[] _expandedItems = new TimeGraphItem[0]; + public TimeGraphItem[] _items = new TimeGraphItem[0]; + private ITimeGraphEntry _traces[] = new ITimeGraphEntry[0]; + private boolean traceFilter[] = new boolean[0]; + private Vector filteredOut = new Vector(); + + public ItemData() { + } + + TimeGraphItem findItem(ITimeGraphEntry entry) { + if (entry == null) + return null; + + for (int i = 0; i < _items.length; i++) { + TimeGraphItem item = _items[i]; + if (item._trace == entry) { + return item; + } + } + + return null; + } + + int findItemIndex(ITimeGraphEntry trace) { + if (trace == null) + return -1; + + for (int i = 0; i < _expandedItems.length; i++) { + TimeGraphItem item = _expandedItems[i]; + if (item._trace == trace) { + return i; + } + } + + return -1; + } + + public void refreshData() { + List itemList = new ArrayList(); + filteredOut.clear(); + for (int i = 0; i < _traces.length; i++) { + ITimeGraphEntry entry = _traces[i]; + refreshData(itemList, null, 0, entry); + } + _items = itemList.toArray(new TimeGraphItem[0]); + updateExpandedItems(); + } + + private void refreshData(List itemList, TimeGraphItem parent, int level, ITimeGraphEntry entry) { + TimeGraphItem item = new TimeGraphItem(entry, entry.getName(), level); + if (parent != null) { + parent.children.add(item); + } + itemList.add(item); + if (entry.hasChildren()) { + item._expanded = true; + item._hasChildren = true; + for (ITimeGraphEntry child : entry.getChildren()) { + refreshData(itemList, item, level + 1, child); + } + } + } + + public void updateExpandedItems() { + List expandedItemList = new ArrayList(); + for (int i = 0; i < _traces.length; i++) { + ITimeGraphEntry entry = _traces[i]; + TimeGraphItem item = findItem(entry); + refreshExpanded(expandedItemList, item); + } + _expandedItems = expandedItemList.toArray(new TimeGraphItem[0]); + } + + private void refreshExpanded(List expandedItemList, TimeGraphItem item) { + expandedItemList.add(item); + if (item._hasChildren && item._expanded) { + for (TimeGraphItem child : item.children) { + refreshExpanded(expandedItemList, child); + } + } + } + + public void expandItem(int idx) { + if (idx < 0 || idx >= _expandedItems.length) + return; + TimeGraphItem item = (TimeGraphItem) _expandedItems[idx]; + if (item._hasChildren && !item._expanded) { + item._expanded = true; + updateExpandedItems(); + } + } + + public void refreshData(ITimeGraphEntry traces[]) { + if (traces == null || traces.length == 0) { + traceFilter = null; + } else if (traceFilter == null || traces.length != traceFilter.length) { + traceFilter = new boolean[traces.length]; + java.util.Arrays.fill(traceFilter, true); + } + + _traces = traces; + refreshData(); + } + + public Object[] getTraces() { + return _traces; + } + + public boolean[] getTraceFilter() { + return traceFilter; + } + + public Vector getFilteredOut() { + return filteredOut; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphItem.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphItem.java new file mode 100644 index 0000000000..c93643b009 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphItem.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; + +public class TimeGraphItem { + public boolean _expanded; + public boolean _selected; + public boolean _hasChildren; + public int level; + public List children; + public String _name; + public ITimeGraphEntry _trace; + + public TimeGraphItem(ITimeGraphEntry trace, String name, int level) { + this._trace = trace; + this._name = name; + this.level = level; + this.children = new ArrayList(); + } + + @Override + public String toString() { + return _name; + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeScaleCtrl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java similarity index 54% rename from org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeScaleCtrl.java rename to org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java index 44409b882d..5640c4ee21 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeScaleCtrl.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java @@ -1,16 +1,16 @@ /***************************************************************************** - * Copyright (c) 2007, 2008, 2010 Intel Corporation and others. + * Copyright (c) 2007, 2008 Intel Corporation, 2010, 2012 Ericsson. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Intel Corporation - Initial API and implementation - * Ruslan A. Scherbakov, Intel - Initial API and implementation - * Alvaro Sanchex-Leon - Udpated for TMF + * Intel Corporation - Initial API and implementation + * Ruslan A. Scherbakov, Intel - Initial API and implementation + * Alvaro Sanchez-Leon - Updated for TMF + * Patrick Tasse - Refactoring * - * $Id: TimeScaleCtrl.java,v 1.5 2008/06/16 21:04:49 jkubasta Exp $ *****************************************************************************/ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; @@ -21,7 +21,6 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; -import org.eclipse.linuxtools.internal.tmf.ui.Messages; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; @@ -33,15 +32,15 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; -public class TimeScaleCtrl extends TraceCtrl implements MouseListener, - MouseMoveListener { +public class TimeGraphScale extends TimeGraphBaseControl implements MouseListener, +MouseMoveListener { - public TimeScaleCtrl(Composite parent, TraceColorScheme colors) { - super(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS - | SWT.DOUBLE_BUFFERED); - addMouseListener(this); - addMouseMoveListener(this); - } + public TimeGraphScale(Composite parent, TimeGraphColorScheme colors) { + super(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS + | SWT.DOUBLE_BUFFERED); + addMouseListener(this); + addMouseMoveListener(this); + } private static final long SEC_IN_NS = 1000000000; private static final long MIN_IN_NS = 60 * SEC_IN_NS; @@ -49,31 +48,31 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener, private static final long DAY_IN_NS = 24 * HOUR_IN_NS; private static final long MONTH_IN_NS = 31 * DAY_IN_NS; // upper limit private static final long YEAR_IN_NS = 366 * DAY_IN_NS; // upper limit - + private static final double LOG10_1 = Math.log10(1); private static final double LOG10_2 = Math.log10(2); private static final double LOG10_3 = Math.log10(3); private static final double LOG10_5 = Math.log10(5); - + private static final Calendar GREGORIAN_CALENDAR = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$ - - private ITimeDataProvider _timeProvider; - private int _dragState = 0; - private int _dragX0 = 0; - private int _dragX = 0; - private long _time0bak; - private long _time1bak; - private boolean _isInUpdate; - private Rectangle _rect0 = new Rectangle(0, 0, 0, 0); + + private ITimeDataProvider _timeProvider; + private int _dragState = 0; + private int _dragX0 = 0; + private int _dragX = 0; + private long _time0bak; + private long _time1bak; + private boolean _isInUpdate; + private Rectangle _rect0 = new Rectangle(0, 0, 0, 0); private int _height; - public void setTimeProvider(ITimeDataProvider timeProvider) { - _timeProvider = timeProvider; - } + public void setTimeProvider(ITimeDataProvider timeProvider) { + _timeProvider = timeProvider; + } - private long _timeDelta; + private long _timeDelta; - @Override + @Override public Point computeSize(int wHint, int hHint, boolean changed) { return super.computeSize(wHint, _height, changed); } @@ -81,7 +80,7 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener, public void setHeight(int height) { this._height = height; } - + private void calcTimeDelta(int width, double pixelsPerNanoSec) { double minDelta = (double) ((pixelsPerNanoSec == 0) ? YEAR_IN_NS : width / pixelsPerNanoSec); long unit = 1; @@ -139,9 +138,9 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener, private static TimeDraw TIMEDRAW_ABS_MONTH = new TimeDrawAbsMonth(); private static TimeDraw TIMEDRAW_ABS_YEAR = new TimeDrawAbsYear(); - TimeDraw getTimeDraw(long timeDelta) { - TimeDraw timeDraw; - if (_timeProvider != null && _timeProvider.isCalendarFormat()) { + TimeDraw getTimeDraw(long timeDelta) { + TimeDraw timeDraw; + if (_timeProvider != null && _timeProvider.isCalendarFormat()) { if (timeDelta >= YEAR_IN_NS) timeDraw = TIMEDRAW_ABS_YEAR; else if (timeDelta >= MONTH_IN_NS) @@ -154,80 +153,76 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener, timeDraw = TIMEDRAW_ABS_MIN; else if (timeDelta >= SEC_IN_NS) timeDraw = TIMEDRAW_ABS_SEC; - else if (timeDelta >= 1000000) - timeDraw = TIMEDRAW_ABS_MILLISEC; - else if (timeDelta >= 1000) - timeDraw = TIMEDRAW_ABS_MICROSEC; - else - timeDraw = TIMEDRAW_ABS_NANOSEC; - return timeDraw; - } - if (timeDelta >= 1000000000) - timeDraw = TIMEDRAW_SEC; - else if (timeDelta >= 1000000) - timeDraw = TIMEDRAW_MILLISEC; - else if (timeDelta >= 1000) - timeDraw = TIMEDRAW_MICROSEC; - else - timeDraw = TIMEDRAW_NANOSEC; - return timeDraw; - } - - @Override - void paint(Rectangle rect, PaintEvent e) { - - if (_isInUpdate || null == _timeProvider) - return; - - GC gc = e.gc; - gc.fillRectangle(rect); - - long time0 = _timeProvider.getTime0(); - long time1 = _timeProvider.getTime1(); - long selectedTime = _timeProvider.getSelectedTime(); - int leftSpace = _timeProvider.getNameSpace(); - int timeSpace = _timeProvider.getTimeSpace(); - - gc.setBackground(_colors.getColor(TraceColorScheme.TOOL_BACKGROUND)); - gc.setForeground(_colors.getColor(TraceColorScheme.TOOL_FOREGROUND)); - Utils.init(_rect0, rect); - - // draw top left area - _rect0.width = leftSpace; - _rect0.x += 4; - _rect0.width -= 4; - if (_rect0.width > 0) { - Utils.drawText(gc, Messages.TimeScaleCtrl_Timescale + ":", _rect0, true); //$NON-NLS-1$ - } - int messageWidth = gc.stringExtent(Messages.TimeScaleCtrl_Timescale + ":").x + 4; //$NON-NLS-1$ - Rectangle absHeaderRect = new Rectangle(_rect0.x + messageWidth, _rect0.y, _rect0.width - messageWidth, _rect0.height); - _rect0.x -= 4; - _rect0.width += 4; - - // prepare and draw right rect of the timescale - _rect0.x += leftSpace; - _rect0.width = rect.width - leftSpace; - - // draw bottom border and erase all other area - gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, - rect.y + rect.height - 1); - _rect0.height--; - gc.fillRectangle(_rect0); - - if (time1 <= time0 || timeSpace < 2) { - return; - } - - int numDigits = calculateDigits(time0, time1); - - int labelWidth = gc.getCharWidth('0') * numDigits; - double pixelsPerNanoSec = (timeSpace <= RIGHT_MARGIN) ? 0 : - (double) (timeSpace - RIGHT_MARGIN) / (time1 - time0); - calcTimeDelta(labelWidth, pixelsPerNanoSec); - - TimeDraw timeDraw = getTimeDraw(_timeDelta); - - // draw zoom rectangle + else if (timeDelta >= 1000000) + timeDraw = TIMEDRAW_ABS_MILLISEC; + else if (timeDelta >= 1000) + timeDraw = TIMEDRAW_ABS_MICROSEC; + else + timeDraw = TIMEDRAW_ABS_NANOSEC; + return timeDraw; + } + if (timeDelta >= 1000000000) + timeDraw = TIMEDRAW_SEC; + else if (timeDelta >= 1000000) + timeDraw = TIMEDRAW_MILLISEC; + else if (timeDelta >= 1000) + timeDraw = TIMEDRAW_MICROSEC; + else + timeDraw = TIMEDRAW_NANOSEC; + return timeDraw; + } + + @Override + void paint(Rectangle rect, PaintEvent e) { + + if (_isInUpdate || null == _timeProvider) + return; + + GC gc = e.gc; + gc.fillRectangle(rect); + + long time0 = _timeProvider.getTime0(); + long time1 = _timeProvider.getTime1(); + long selectedTime = _timeProvider.getSelectedTime(); + int leftSpace = _timeProvider.getNameSpace(); + int timeSpace = _timeProvider.getTimeSpace(); + + gc.setBackground(_colors.getColor(TimeGraphColorScheme.TOOL_BACKGROUND)); + gc.setForeground(_colors.getColor(TimeGraphColorScheme.TOOL_FOREGROUND)); + Utils.init(_rect0, rect); + + // draw top left area + _rect0.width = leftSpace; + _rect0.x += 4; + _rect0.width -= 4; + Rectangle absHeaderRect = new Rectangle(_rect0.x, _rect0.y, _rect0.width, _rect0.height); + _rect0.x -= 4; + _rect0.width += 4; + + // prepare and draw right rect of the timescale + _rect0.x += leftSpace; + _rect0.width = rect.width - leftSpace; + + // draw bottom border and erase all other area + gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, + rect.y + rect.height - 1); + _rect0.height--; + gc.fillRectangle(_rect0); + + if (time1 <= time0 || timeSpace < 2) { + return; + } + + int numDigits = calculateDigits(time0, time1); + + int labelWidth = gc.getCharWidth('0') * numDigits; + double pixelsPerNanoSec = (timeSpace <= RIGHT_MARGIN) ? 0 : + (double) (timeSpace - RIGHT_MARGIN) / (time1 - time0); + calcTimeDelta(labelWidth, pixelsPerNanoSec); + + TimeDraw timeDraw = getTimeDraw(_timeDelta); + + // draw zoom rectangle if (3 == _dragState && null != _timeProvider) { if (_dragX0 < _dragX) { gc.drawRectangle(leftSpace + _dragX0, rect.y, _dragX - _dragX0 - 1, rect.height - 8); @@ -236,54 +231,52 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener, } } - if (_rect0.isEmpty()) - return; - - // draw selected time - int x = _rect0.x + (int) ((double)(selectedTime - time0) * pixelsPerNanoSec); - if (x >= _rect0.x && x < _rect0.x + _rect0.width) { - gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME)); - gc.drawLine(x, _rect0.y + _rect0.height - 6, x, _rect0.y - + _rect0.height); - gc - .setForeground(_colors - .getColor(TraceColorScheme.TOOL_FOREGROUND)); - } - - // draw time scale ticks - _rect0.y = rect.y; - _rect0.height = rect.height - 4; - _rect0.width = labelWidth; - - long time; + if (_rect0.isEmpty()) + return; + + // draw selected time + int x = _rect0.x + (int) ((double)(selectedTime - time0) * pixelsPerNanoSec); + if (x >= _rect0.x && x < _rect0.x + _rect0.width) { + gc.setForeground(_colors.getColor(TimeGraphColorScheme.SELECTED_TIME)); + gc.drawLine(x, _rect0.y + _rect0.height - 6, x, _rect0.y + + _rect0.height); + gc.setForeground(_colors.getColor(TimeGraphColorScheme.TOOL_FOREGROUND)); + } + + // draw time scale ticks + _rect0.y = rect.y; + _rect0.height = rect.height - 4; + _rect0.width = labelWidth; + + long time; if (_timeProvider != null && _timeProvider.isCalendarFormat()) { time = floorToCalendar(time0, _timeDelta); } else { time = (long) (Math.ceil((double) time0 / _timeDelta) * _timeDelta); } - - // long t = (long) (time * 1000000000); - int y = _rect0.y + _rect0.height; + + // long t = (long) (time * 1000000000); + int y = _rect0.y + _rect0.height; if (_timeProvider != null && _timeProvider.isCalendarFormat()) { timeDraw.drawAbsHeader(gc, time, absHeaderRect); } - - while (true) { - x = rect.x + leftSpace + (int) (Math.floor((time - time0) * pixelsPerNanoSec)); - if (x >= rect.x + leftSpace + rect.width - _rect0.width) { - break; - } - if (x >= rect.x + leftSpace) { - gc.drawLine(x, y, x, y + 4); - _rect0.x = x; - if (x + _rect0.width <= rect.x + rect.width) - timeDraw.draw(gc, time, _rect0); - } - if (pixelsPerNanoSec == 0 || time > Long.MAX_VALUE - _timeDelta || _timeDelta == 0) { - break; - } - time += _timeDelta; + + while (true) { + x = rect.x + leftSpace + (int) (Math.floor((time - time0) * pixelsPerNanoSec)); + gc.drawLine(x, y, x, y + 4); + if (x >= rect.x + leftSpace + rect.width - _rect0.width) { + break; + } + if (x >= rect.x + leftSpace) { + _rect0.x = x; + if (x + _rect0.width <= rect.x + rect.width) + timeDraw.draw(gc, time, _rect0); + } + if (pixelsPerNanoSec == 0 || time > Long.MAX_VALUE - _timeDelta || _timeDelta == 0) { + break; + } + time += _timeDelta; if (_timeProvider != null && _timeProvider.isCalendarFormat()) { if (_timeDelta >= YEAR_IN_NS) { GREGORIAN_CALENDAR.setTime(new Date(time / 1000000)); @@ -296,10 +289,10 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener, time = GREGORIAN_CALENDAR.getTimeInMillis() * 1000000; } } - } - } + } + } - private long floorToCalendar(long time, long timeDelta) { + private long floorToCalendar(long time, long timeDelta) { if (_timeDelta >= YEAR_IN_NS) { GREGORIAN_CALENDAR.setTime(new Date(time / 1000000)); int year = GREGORIAN_CALENDAR.get(Calendar.YEAR); @@ -329,143 +322,143 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener, time = (time / timeDelta) * timeDelta; } return time; - } - - private int calculateDigits(long time0, long time1) { - int numDigits = 5; - long timeRange = time1 - time0; - - if (_timeProvider.isCalendarFormat()) { - // Calculate the number of digits to represent the minutes provided - // 11:222 - // HH:mm:ss - numDigits += 8; - if (timeRange < 10000) { - // HH:11:222:333:444__ - numDigits += 10; - } else if (timeRange < 10000000) { - // HH:11:222:333__ - numDigits += 6; - } - } else { - // Calculate the number of digits to represent the minutes provided - long min = (long) ((time1 * 1E-9) / 60); // to sec then to minutes - String strMinutes = String.valueOf(min); - // 11:222 - if (strMinutes != null) { - numDigits += strMinutes.length(); - } else { - numDigits += 2; - } - if (timeRange < 10000) { - // 11:222:333:444__ - numDigits += 8; - } else if (timeRange < 10000000) { - // 11:222:333__ - numDigits += 4; - } - } - -// Trace.debug("timeRange: " + timeRange + " numDigits: " + numDigits); - return numDigits; - } - - @Override - public void mouseDown(MouseEvent e) { - if (_dragState == 0 && null != _timeProvider) { - if (1 == e.button) { - setCapture(true); - _dragState = 1; - } else if (3 == e.button) { - _dragState = 3; - } - int x = e.x - _timeProvider.getNameSpace(); - if (x < 0) { - x = 0; - } else if (x > getSize().x - _timeProvider.getNameSpace()) { - x = getSize().x - _timeProvider.getNameSpace(); - } - _dragX = _dragX0 = x; - _time0bak = _timeProvider.getTime0(); - _time1bak = _timeProvider.getTime1(); - } - } - - @Override - public void mouseUp(MouseEvent e) { - if (e.button == 1 && _dragState == 1) { - setCapture(false); - _dragState = 0; - - // Notify time provider to check the need for listener notification - if (_dragX != _dragX0) { - _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1()); - } - } else if (e.button == 3 && _dragState == 3 && null != _timeProvider) { - _dragState = 0; - if (_dragX0 == _dragX) { - return; - } - int timeSpace = _timeProvider.getTimeSpace(); - int leftSpace = _timeProvider.getNameSpace(); - int x = e.x - leftSpace; - if (timeSpace > 0) { - _dragX = x; - if (_dragX0 > _dragX) { // drag right to left - _dragX = _dragX0; - _dragX0 = x; - } - long time0 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / timeSpace)); - long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX / timeSpace)); - - _timeProvider.setStartFinishTimeNotify(time0, time1); - _time0bak = _timeProvider.getTime0(); - _time1bak = _timeProvider.getTime1(); - } - } - } - - @Override - public void mouseMove(MouseEvent e) { - if (_dragX0 < 0 || _dragState == 0 || _timeProvider == null) { - return; - } - Point size = getSize(); - int leftSpace = _timeProvider.getNameSpace(); - int timeSpace = _timeProvider.getTimeSpace(); - int x = e.x - leftSpace; - if (1 == _dragState) { - if (x > 0 && size.x > leftSpace && _dragX != x) { - _dragX = x; - long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / _dragX)); - _timeProvider.setStartFinishTime(_time0bak, time1); - } - } else if (3 == _dragState) { - if (x < 0) { - _dragX = 0; - } else if (x > timeSpace) { - _dragX = timeSpace; - } else { + } + + private int calculateDigits(long time0, long time1) { + int numDigits = 5; + long timeRange = time1 - time0; + + if (_timeProvider.isCalendarFormat()) { + // Calculate the number of digits to represent the minutes provided + // 11:222 + // HH:mm:ss + numDigits += 8; + if (timeRange < 10000) { + // HH:11:222:333:444__ + numDigits += 10; + } else if (timeRange < 10000000) { + // HH:11:222:333__ + numDigits += 6; + } + } else { + // Calculate the number of digits to represent the minutes provided + long min = (long) ((time1 * 1E-9) / 60); // to sec then to minutes + String strMinutes = String.valueOf(min); + // 11:222 + if (strMinutes != null) { + numDigits += strMinutes.length(); + } else { + numDigits += 2; + } + if (timeRange < 10000) { + // 11:222:333:444__ + numDigits += 8; + } else if (timeRange < 10000000) { + // 11:222:333__ + numDigits += 4; + } + } + + // Trace.debug("timeRange: " + timeRange + " numDigits: " + numDigits); + return numDigits; + } + + @Override + public void mouseDown(MouseEvent e) { + if (_dragState == 0 && null != _timeProvider) { + if (1 == e.button) { + setCapture(true); + _dragState = 1; + } else if (3 == e.button) { + _dragState = 3; + } + int x = e.x - _timeProvider.getNameSpace(); + if (x < 0) { + x = 0; + } else if (x > getSize().x - _timeProvider.getNameSpace()) { + x = getSize().x - _timeProvider.getNameSpace(); + } + _dragX = _dragX0 = x; + _time0bak = _timeProvider.getTime0(); + _time1bak = _timeProvider.getTime1(); + } + } + + @Override + public void mouseUp(MouseEvent e) { + if (e.button == 1 && _dragState == 1) { + setCapture(false); + _dragState = 0; + + // Notify time provider to check the need for listener notification + if (_dragX != _dragX0) { + _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1()); + } + } else if (e.button == 3 && _dragState == 3 && null != _timeProvider) { + _dragState = 0; + if (_dragX0 == _dragX) { + return; + } + int timeSpace = _timeProvider.getTimeSpace(); + int leftSpace = _timeProvider.getNameSpace(); + int x = e.x - leftSpace; + if (timeSpace > 0) { + _dragX = x; + if (_dragX0 > _dragX) { // drag right to left + _dragX = _dragX0; + _dragX0 = x; + } + long time0 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / timeSpace)); + long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX / timeSpace)); + + _timeProvider.setStartFinishTimeNotify(time0, time1); + _time0bak = _timeProvider.getTime0(); + _time1bak = _timeProvider.getTime1(); + } + } + } + + @Override + public void mouseMove(MouseEvent e) { + if (_dragX0 < 0 || _dragState == 0 || _timeProvider == null) { + return; + } + Point size = getSize(); + int leftSpace = _timeProvider.getNameSpace(); + int timeSpace = _timeProvider.getTimeSpace(); + int x = e.x - leftSpace; + if (1 == _dragState) { + if (x > 0 && size.x > leftSpace && _dragX != x) { + _dragX = x; + long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / _dragX)); + _timeProvider.setStartFinishTime(_time0bak, time1); + } + } else if (3 == _dragState) { + if (x < 0) { + _dragX = 0; + } else if (x > timeSpace) { + _dragX = timeSpace; + } else { _dragX = x; } - redraw(); - } - } - - @Override - public void mouseDoubleClick(MouseEvent e) { - if (null != _timeProvider) { - _timeProvider.resetStartFinishTime(); + redraw(); + } + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + if (null != _timeProvider) { + _timeProvider.resetStartFinishTime(); _time0bak = _timeProvider.getTime0(); _time1bak = _timeProvider.getTime1(); - } - } + } + } } abstract class TimeDraw { - static String S = ":" ; //$NON-NLS-1$ - static String S0 = ":0" ; //$NON-NLS-1$ - static String S00 = ":00"; //$NON-NLS-1$ + static String S = ":" ; //$NON-NLS-1$ + static String S0 = ":0" ; //$NON-NLS-1$ + static String S00 = ":00"; //$NON-NLS-1$ protected static final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$ protected static final SimpleDateFormat stimeformatheader = new SimpleDateFormat("yyyy MMM dd"); //$NON-NLS-1$ protected static final SimpleDateFormat sminformat = new SimpleDateFormat("HH:mm"); //$NON-NLS-1$ @@ -488,15 +481,15 @@ abstract class TimeDraw { smonthformat.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$ syearformat.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$ } - - static String pad(long n) { - String s = S; - if (n < 10) - s = S00; - else if (n < 100) - s = S0; - return s + n; - } + + static String pad(long n) { + String s = S; + if (n < 10) + s = S00; + else if (n < 100) + s = S0; + return s + n; + } public abstract void draw(GC gc, long time, Rectangle rect); @@ -504,79 +497,79 @@ abstract class TimeDraw { // Override to draw absolute time header // This is for the time information not shown in the draw of each tick } - - public abstract String hint(); + + public abstract String hint(); } class TimeDrawSec extends TimeDraw { - static String _hint = "sec"; //$NON-NLS-1$ - - @Override - public void draw(GC gc, long time, Rectangle rect) { - time /= 1000000000; - Utils.drawText(gc, time + "", rect, true); //$NON-NLS-1$ - } - - @Override - public String hint() { - return _hint; - } + static String _hint = "sec"; //$NON-NLS-1$ + + @Override + public void draw(GC gc, long time, Rectangle rect) { + time /= 1000000000; + Utils.drawText(gc, time + "", rect, true); //$NON-NLS-1$ + } + + @Override + public String hint() { + return _hint; + } } class TimeDrawMillisec extends TimeDraw { - static String _hint = "s:ms"; //$NON-NLS-1$ - - @Override - public void draw(GC gc, long time, Rectangle rect) { - time /= 1000000; - long ms = time % 1000; - time /= 1000; - Utils.drawText(gc, time + pad(ms), rect, true); - } - - @Override - public String hint() { - return _hint; - } + static String _hint = "s:ms"; //$NON-NLS-1$ + + @Override + public void draw(GC gc, long time, Rectangle rect) { + time /= 1000000; + long ms = time % 1000; + time /= 1000; + Utils.drawText(gc, time + pad(ms), rect, true); + } + + @Override + public String hint() { + return _hint; + } } class TimeDrawMicrosec extends TimeDraw { - static String _hint = "s:ms:mcs"; //$NON-NLS-1$ - - @Override - public void draw(GC gc, long time, Rectangle rect) { - time /= 1000; - long mcs = time % 1000; - time /= 1000; - long ms = time % 1000; - time /= 1000; - Utils.drawText(gc, time + pad(ms) + pad(mcs), rect, true); - } - - @Override - public String hint() { - return _hint; - } + static String _hint = "s:ms:mcs"; //$NON-NLS-1$ + + @Override + public void draw(GC gc, long time, Rectangle rect) { + time /= 1000; + long mcs = time % 1000; + time /= 1000; + long ms = time % 1000; + time /= 1000; + Utils.drawText(gc, time + pad(ms) + pad(mcs), rect, true); + } + + @Override + public String hint() { + return _hint; + } } class TimeDrawNanosec extends TimeDraw { - static String _hint = "s:ms:mcs:ns"; //$NON-NLS-1$ - - @Override - public void draw(GC gc, long time, Rectangle rect) { - long ns = time % 1000; - time /= 1000; - long mcs = time % 1000; - time /= 1000; - long ms = time % 1000; - time /= 1000; - Utils.drawText(gc, time + pad(ms) + pad(mcs) + pad(ns), rect, true); - } - - @Override - public String hint() { - return _hint; - } + static String _hint = "s:ms:mcs:ns"; //$NON-NLS-1$ + + @Override + public void draw(GC gc, long time, Rectangle rect) { + long ns = time % 1000; + time /= 1000; + long mcs = time % 1000; + time /= 1000; + long ms = time % 1000; + time /= 1000; + Utils.drawText(gc, time + pad(ms) + pad(mcs) + pad(ns), rect, true); + } + + @Override + public String hint() { + return _hint; + } } class TimeDrawAbsYear extends TimeDraw { @@ -627,7 +620,7 @@ class TimeDrawAbsDay extends TimeDraw { Utils.drawText(gc, header, rect, true); } } - + @Override public String hint() { return _hint; @@ -652,7 +645,7 @@ class TimeDrawAbsHrs extends TimeDraw { Utils.drawText(gc, header, rect, true); } } - + @Override public String hint() { return _hint; @@ -677,8 +670,8 @@ class TimeDrawAbsMin extends TimeDraw { Utils.drawText(gc, header, rect, true); } } - - + + @Override public String hint() { return _hint; @@ -703,7 +696,7 @@ class TimeDrawAbsSec extends TimeDraw { Utils.drawText(gc, header, rect, true); } } - + @Override public String hint() { return _hint; @@ -711,15 +704,15 @@ class TimeDrawAbsSec extends TimeDraw { } class TimeDrawAbsMillisec extends TimeDraw { - static String _hint = "HH:ss:ms"; //$NON-NLS-1$ + static String _hint = "HH:ss:ms"; //$NON-NLS-1$ - @Override - public void draw(GC gc, long time, Rectangle rect) { - String stime = stimeformat.format(new Date((long) (time / 1000000))); - String ns = Utils.formatNs(time, Resolution.MILLISEC); + @Override + public void draw(GC gc, long time, Rectangle rect) { + String stime = stimeformat.format(new Date((long) (time / 1000000))); + String ns = Utils.formatNs(time, Resolution.MILLISEC); - Utils.drawText(gc, stime + " " + ns, rect, true); //$NON-NLS-1$ - } + Utils.drawText(gc, stime + " " + ns, rect, true); //$NON-NLS-1$ + } @Override public void drawAbsHeader(GC gc, long time, Rectangle rect) { @@ -730,22 +723,22 @@ class TimeDrawAbsMillisec extends TimeDraw { Utils.drawText(gc, header, rect, true); } } - - @Override - public String hint() { - return _hint; - } + + @Override + public String hint() { + return _hint; + } } class TimeDrawAbsMicroSec extends TimeDraw { - static String _hint = "HH:ss:ms:mcs"; //$NON-NLS-1$ + static String _hint = "HH:ss:ms:mcs"; //$NON-NLS-1$ - @Override - public void draw(GC gc, long time, Rectangle rect) { - String stime = stimeformat.format(new Date((long) (time / 1000000))); - String micr = Utils.formatNs(time, Resolution.MICROSEC); - Utils.drawText(gc, stime + " " + micr, rect, true); //$NON-NLS-1$ - } + @Override + public void draw(GC gc, long time, Rectangle rect) { + String stime = stimeformat.format(new Date((long) (time / 1000000))); + String micr = Utils.formatNs(time, Resolution.MICROSEC); + Utils.drawText(gc, stime + " " + micr, rect, true); //$NON-NLS-1$ + } @Override public void drawAbsHeader(GC gc, long time, Rectangle rect) { @@ -756,22 +749,22 @@ class TimeDrawAbsMicroSec extends TimeDraw { Utils.drawText(gc, header, rect, true); } } - - @Override - public String hint() { - return _hint; - } + + @Override + public String hint() { + return _hint; + } } class TimeDrawAbsNanoSec extends TimeDraw { - static String _hint = "HH:ss:ms:mcs:ns"; //$NON-NLS-1$ + static String _hint = "HH:ss:ms:mcs:ns"; //$NON-NLS-1$ - @Override - public void draw(GC gc, long time, Rectangle rect) { - String stime = stimeformat.format(new Date((long) (time / 1000000))); - String ns = Utils.formatNs(time, Resolution.NANOSEC); - Utils.drawText(gc, stime + " " + ns, rect, true); //$NON-NLS-1$ - } + @Override + public void draw(GC gc, long time, Rectangle rect) { + String stime = stimeformat.format(new Date((long) (time / 1000000))); + String ns = Utils.formatNs(time, Resolution.NANOSEC); + Utils.drawText(gc, stime + " " + ns, rect, true); //$NON-NLS-1$ + } @Override public void drawAbsHeader(GC gc, long time, Rectangle rect) { @@ -782,9 +775,9 @@ class TimeDrawAbsNanoSec extends TimeDraw { Utils.drawText(gc, header, rect, true); } } - - @Override - public String hint() { - return _hint; - } + + @Override + public String hint() { + return _hint; + } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphSelection.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphSelection.java new file mode 100644 index 0000000000..b0962af63e --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphSelection.java @@ -0,0 +1,71 @@ +/***************************************************************************** + * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - Initial API and implementation + * Ruslan A. Scherbakov, Intel - Initial API and implementation + * Alvaro Sanchez-Leon - Updated for TMF + * Patrick Tasse - Refactoring + * + *****************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredSelection; + +public class TimeGraphSelection implements IStructuredSelection { + + List list = new ArrayList(); + + public TimeGraphSelection() { + } + + public TimeGraphSelection(Object sel) { + add(sel); + } + + public void add(Object sel) { + if (null != sel && !list.contains(sel)) + list.add(sel); + } + + @Override + public Object getFirstElement() { + if (!list.isEmpty()) + return list.get(0); + return null; + } + + @Override + public Iterator iterator() { + return list.iterator(); + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Object[] toArray() { + return list.toArray(); + } + + @Override + public List toList() { + return list; + } + + @Override + public boolean isEmpty() { + return list.isEmpty(); + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java new file mode 100644 index 0000000000..265b08f1a1 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java @@ -0,0 +1,247 @@ +/***************************************************************************** + * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - Initial API and implementation + * Vitaly A. Provodin, Intel - Initial API and implementation + * Alvaro Sanchez-Leon - Updated for TMF + * Patrick Tasse - Refactoring + * + *****************************************************************************/ +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; + +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.linuxtools.internal.tmf.ui.Messages; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Widget; + + +public class TimeGraphTooltipHandler { + + private Shell _tipShell; + private Table _tipTable; + private TimeGraphItem _tipItem; + private Point _tipPosition; + private ITimeDataProvider _timeDataProvider; + ITimeGraphProvider _utilImp = null; + + public TimeGraphTooltipHandler(Shell parent, ITimeGraphProvider rUtilImpl, + ITimeDataProvider timeProv) { + final Display display = parent.getDisplay(); + + this._utilImp = rUtilImpl; + this._timeDataProvider = timeProv; + _tipShell = new Shell(parent, SWT.ON_TOP | SWT.TOOL); + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + gridLayout.marginWidth = 2; + gridLayout.marginHeight = 2; + _tipShell.setLayout(gridLayout); + GridData data = new GridData(GridData.BEGINNING, GridData.BEGINNING, + true, true); + _tipShell.setLayoutData(data); + _tipShell.setBackground(display + .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + + _tipTable = new Table(_tipShell, SWT.NONE); + _tipTable.setForeground(display + .getSystemColor(SWT.COLOR_INFO_FOREGROUND)); + _tipTable.setBackground(display + .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + _tipTable.setHeaderVisible(false); + _tipTable.setLinesVisible(false); + + // tipTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL + // | GridData.VERTICAL_ALIGN_CENTER)); + } + + public void activateHoverHelp(final Control control) { + //FIXME: remove old listeners + control.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + if (_tipShell.isVisible()) + _tipShell.setVisible(false); + } + }); + + control.addMouseTrackListener(new MouseTrackAdapter() { + @Override + public void mouseExit(MouseEvent e) { + if (_tipShell.isVisible()) + _tipShell.setVisible(false); + _tipItem = null; + + } + + private void addItem(String name, String value) { + TableItem line = new TableItem(_tipTable, SWT.NONE); + line.setText(0, name); + line.setText(1, value); + } + + private void fillValues(Point pt, TimeGraphControl threadStates, TimeGraphItem item) { + if (item == null) { + return; + } + if (item._trace.getTimeEventsIterator() == null) { + addItem(Messages.TmfTimeTipHandler_TRACE_GROUP_NAME, item.toString()); + addItem(Messages.TmfTimeTipHandler_NUMBER_OF_TRACES, "" + item.children.size()); //$NON-NLS-1$ + } else { + ITimeGraphEntry thrd = item._trace; + ITimeEvent threadEvent = Utils.findEvent(thrd, threadStates.getTimeAtX(pt.x), 2); + ITimeEvent nextEvent = Utils.findEvent(thrd, threadStates.getTimeAtX(pt.x), 1); + // thread name + addItem(Messages.TmfTimeTipHandler_TRACE_NAME, thrd.getName()); + // class name + String traceClass = _utilImp.getTraceClassName(thrd); + if (traceClass != null) { + addItem(Messages.TmfTimeTipHandler_TRACE_CLASS_NAME, traceClass); + } + // thread state + String state = _utilImp.getEventName(threadEvent); + if (state != null) { + addItem(Messages.TmfTimeTipHandler_TRACE_STATE, state); + } + + // This block receives a + // list of values to be added to the tip + // table + Map eventAddOns = _utilImp.getEventHoverToolTipInfo(threadEvent); + if (eventAddOns != null) { + for (Iterator iter = eventAddOns.keySet().iterator(); iter.hasNext();) { + String message = (String) iter.next(); + addItem(message, eventAddOns.get(message)); + } + } + + long eventStartTime = -1; + long eventDuration = -1; + long eventEndTime = -1; + + if (threadEvent != null) { + eventStartTime = threadEvent.getTime(); + eventDuration = threadEvent.getDuration(); + if (eventDuration < 0 && nextEvent != null) { + eventEndTime = nextEvent.getTime(); + eventDuration = eventEndTime - eventStartTime; + } else { + eventEndTime = eventStartTime + eventDuration; + } + } + + // TODO: Check if we need "format" + // TimeFormat format = TimeFormat.RELATIVE; + Resolution res = Resolution.NANOSEC; + if (_timeDataProvider.isCalendarFormat()) { + // format = TimeFormat.ABSOLUTE; // Absolute format + // // (calendar) + // Add Date + addItem(Messages.TmfTimeTipHandler_TRACE_DATE, eventStartTime > -1 ? + Utils.formatDate(eventStartTime) + : "?"); //$NON-NLS-1$ + if (eventDuration > 0) { + addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ? + Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res) + : "?"); //$NON-NLS-1$ + + addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ? + Utils.formatTime(eventEndTime, TimeFormat.ABSOLUTE, res) + : "?"); //$NON-NLS-1$ + } else { + addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ? + Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res) + : "?"); //$NON-NLS-1$ + } + } else { + if (eventDuration > 0) { + addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ? + Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res) + : "?"); //$NON-NLS-1$ + + addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ? + Utils.formatTime(eventEndTime, TimeFormat.RELATIVE, res) + : "?"); //$NON-NLS-1$ + } else { + addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ? + Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res) + : "?"); //$NON-NLS-1$ + } + } + + if (eventDuration > 0) { + // Duration in relative format in any case + addItem(Messages.TmfTimeTipHandler_DURATION, eventDuration > -1 ? + Utils.formatTime(eventDuration, TimeFormat.RELATIVE, res) + : "?"); //$NON-NLS-1$ + } + } + } + + @Override + public void mouseHover(MouseEvent event) { + Point pt = new Point(event.x, event.y); + Widget widget = event.widget; + TimeGraphItem item = null; + if (widget instanceof TimeGraphControl) { + TimeGraphControl threadStates = (TimeGraphControl) widget; + item = (TimeGraphItem) threadStates.getItem(pt); + _tipTable.remove(0, _tipTable.getItemCount() - 1); + new TableColumn(_tipTable, SWT.NONE); + new TableColumn(_tipTable, SWT.NONE); + fillValues(pt, threadStates, item); + _tipTable.getColumn(0).setWidth(200); + _tipTable.getColumn(1).pack(); + _tipTable.setSize(_tipTable.computeSize(SWT.DEFAULT, 200)); + _tipShell.pack(); + } else if (widget == null) { + _tipShell.setVisible(false); + _tipItem = null; + return; + } + if (item == _tipItem) + return; + _tipItem = item; + _tipPosition = control.toDisplay(pt); + _tipShell.pack(); + setHoverLocation(_tipShell, _tipPosition); + _tipShell.setVisible(true); + } + }); + } + + private void setHoverLocation(Shell shell, Point position) { + Rectangle displayBounds = shell.getDisplay().getBounds(); + Rectangle shellBounds = shell.getBounds(); + shellBounds.x = Math.max(Math.min(position.x, displayBounds.width + - shellBounds.width), 0); + shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height + - shellBounds.height), 0); + shell.setBounds(shellBounds); + } + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TmfTimeStatesCtrl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TmfTimeStatesCtrl.java deleted file mode 100644 index 6731ce095d..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TmfTimeStatesCtrl.java +++ /dev/null @@ -1,2173 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2007, 2008 Intel Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Intel Corporation - Initial API and implementation - * Ruslan A. Scherbakov, Intel - Initial API and implementation - * Alvaro Sanchex-Leon - Udpated for TMF - * - * $Id: ThreadStatesCtrl.java,v 1.15 2008/07/11 13:49:01 aalexeev Exp $ - *****************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.ControlListener; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.MouseMoveListener; -import org.eclipse.swt.events.MouseTrackListener; -import org.eclipse.swt.events.MouseWheelListener; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.events.TraverseEvent; -import org.eclipse.swt.events.TraverseListener; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.ScrollBar; - -/** - * @author alvaro - * - */ -public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener, KeyListener, MouseMoveListener, MouseListener, MouseWheelListener, ControlListener, SelectionListener, MouseTrackListener, TraverseListener, ISelectionProvider { - - private static final int DRAG_NONE = 0; - private static final int DRAG_TRACE_ITEM = 1; - private static final int DRAG_GROUP_ITEM = 2; - private static final int DRAG_SPLIT_LINE = 3; - public static final boolean DEFAULT_DRAW_THREAD_JOIN = true; - public static final boolean DEFAULT_DRAW_THREAD_WAIT = true; - public static final boolean DEFAULT_DRAW_THREAD_RELEASE = true; - public static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1; - - private static final double zoomCoeff = 1.5; - - private ITimeDataProvider _timeProvider; - private boolean _isInFocus = false; - private boolean _isDragCursor3 = false; - private boolean _isWaitCursor = true; - private boolean _mouseHover = false; - private int _itemHeightDefault = 19; - private int _itemHeight = _itemHeightDefault; - private int _minimumItemWidth = 0; - private int _topItem = 0; - private int _dragState = DRAG_NONE; - private int _hitIdx = 0; - private int _dragX0 = 0; - private int _dragX = 0; - private int _idealNameWidth = 0; - // private double _timeStep = 10000000; - private long _time0bak; - private long _time1bak; - private TmfTimeAnalysisProvider utilImpl = null; - private ItemData _data = null; - private List _selectionListeners; - private List _selectionChangedListeners = new ArrayList(); - private Rectangle _rect0 = new Rectangle(0, 0, 0, 0); - private Rectangle _rect1 = new Rectangle(0, 0, 0, 0); - private Cursor _dragCursor3; - private Cursor _WaitCursor; - private boolean drawTracesInteraction = false; - private boolean drawTraceJoins = DEFAULT_DRAW_THREAD_JOIN; - private boolean drawTraceWaits = DEFAULT_DRAW_THREAD_WAIT; - private boolean drawTraceReleases = DEFAULT_DRAW_THREAD_RELEASE; - - // Vertical formatting formatting for the state control view - private boolean _visibleVerticalScroll = true; - private int _borderWidth = 0; - private int _headerHeight = 0; - - private Listener mouseScrollFilterListener; - - public TmfTimeStatesCtrl(Composite parent, TraceColorScheme colors, TmfTimeAnalysisProvider rutilImp) { - - super(parent, colors, SWT.NO_BACKGROUND | SWT.V_SCROLL | SWT.H_SCROLL | SWT.DOUBLE_BUFFERED); - - this.utilImpl = rutilImp; - _data = new ItemData(utilImpl); - - addFocusListener(this); - addMouseListener(this); - addMouseMoveListener(this); - addMouseTrackListener(this); - addMouseWheelListener(this); - addTraverseListener(this); - addKeyListener(this); - addControlListener(this); - ScrollBar scrollVer = getVerticalBar(); - ScrollBar scrollHor = getHorizontalBar(); - if (scrollVer != null) { - scrollVer.addSelectionListener(this); - scrollVer.setVisible(_visibleVerticalScroll); - } - - if (scrollHor != null) { - scrollHor.addSelectionListener(this); - } - - _dragCursor3 = new Cursor(super.getDisplay(), SWT.CURSOR_SIZEWE); - _WaitCursor = new Cursor(super.getDisplay(), SWT.CURSOR_WAIT); - } - - @Override - public void dispose() { - super.dispose(); - _dragCursor3.dispose(); - _WaitCursor.dispose(); - } - - public void setTimeProvider(ITimeDataProvider timeProvider) { - _timeProvider = timeProvider; - adjustScrolls(); - redraw(); - } - - public void addSelectionListener(SelectionListener listener) { - if (listener == null) - SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (null == _selectionListeners) - _selectionListeners = new ArrayList(); - _selectionListeners.add(listener); - } - - public void removeSelectionListener(SelectionListener listener) { - if (null != _selectionListeners) - _selectionListeners.remove(listener); - } - - public void fireSelectionChanged() { - if (null != _selectionListeners) { - Iterator it = _selectionListeners.iterator(); - while (it.hasNext()) { - SelectionListener listener = it.next(); - listener.widgetSelected(null); - } - } - } - - public void fireDefaultSelection() { - if (null != _selectionListeners) { - Iterator it = _selectionListeners.iterator(); - while (it.hasNext()) { - SelectionListener listener = it.next(); - listener.widgetDefaultSelected(null); - } - } - } - - public Object[] getTraces() { - return _data.getTraces(); - } - - public boolean[] getTraceFilter() { - return _data.getTraceFilter(); - } - - public void refreshData() { - _data.refreshData(); - adjustScrolls(); - redraw(); - } - - public void refreshData(Object traces[]) { - _data.refreshData(traces); - adjustScrolls(); - redraw(); - } - - public void refreshPartial(ITmfTimeAnalysisEntry parent, TimeEvent item) { - _data.refreshPartial(parent, item); - adjustScrolls(); - redraw(); - } - - public void adjustScrolls() { - if (null == _timeProvider) { - getVerticalBar().setValues(0, 1, 1, 1, 1, 1); - getHorizontalBar().setValues(0, 1, 1, 1, 1, 1); - return; - } - - // Vertical scroll bar - int page = countPerPage(); - if (_topItem + page > _data._items.length) - _topItem = _data._items.length - page; - if (_topItem < 0) - _topItem = 0; - getVerticalBar().setValues(_topItem, 0, _data._items.length, page, 1, page); - - // HORIZONTAL BAR - // Visible window - long time0 = _timeProvider.getTime0(); - long time1 = _timeProvider.getTime1(); - // Time boundaries - long timeMin = _timeProvider.getMinTime(); - long timeMax = _timeProvider.getMaxTime(); - - long delta = timeMax - timeMin; - - int timePos = 0; - int thumb = H_SCROLLBAR_MAX; - - if (delta != 0) { - // Thumb size (page size) - thumb = Math.max(1, (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta))); - // At the beginning of visible window - timePos = (int) (H_SCROLLBAR_MAX * ((double) (time0 - timeMin) / delta)); - } - - // position, minimum, maximum, thumb size, increment (half page)t, page - // increment size (full page) - getHorizontalBar().setValues(timePos, 0, H_SCROLLBAR_MAX, thumb, Math.max(1, thumb / 2), Math.max(2, thumb)); - } - - boolean ensureVisibleItem(int idx, boolean redraw) { - boolean changed = false; - if (idx < 0) { - for (idx = 0; idx < _data._items.length; idx++) { - if (((Item) _data._items[idx])._selected) - break; - } - } - if (idx >= _data._items.length) - return changed; - if (idx < _topItem) { - _topItem = idx; - getVerticalBar().setSelection(_topItem); - if (redraw) - redraw(); - changed = true; - } else { - int page = countPerPage(); - if (idx >= _topItem + page) { - _topItem = idx - page + 1; - getVerticalBar().setSelection(_topItem); - if (redraw) - redraw(); - changed = true; - } - } - return changed; - } - - public void setTopIndex(int idx) { - idx = Math.min(idx, _data._items.length - countPerPage()); - idx = Math.max(0, idx); - _topItem = idx; - getVerticalBar().setSelection(_topItem); - redraw(); - } - - @Override - public ISelection getSelection() { - PlainSelection sel = new PlainSelection(); - ITmfTimeAnalysisEntry trace = getSelectedTrace(); - if (null != trace && null != _timeProvider) { - long selectedTime = _timeProvider.getSelectedTime(); - ITimeEvent event = Utils.findEvent(trace, selectedTime, 0); - if (event != null) - sel.add(event); - else - sel.add(trace); - } - return sel; - } - - public ISelection getSelectionTrace() { - PlainSelection sel = new PlainSelection(); - ITmfTimeAnalysisEntry trace = getSelectedTrace(); - if (null != trace) { - sel.add(trace); - } - return sel; - } - - public void selectTrace(int n) { - if (n != 1 && n != -1) - return; - boolean changed = false; - int lastSelection = -1; - for (int i = 0; i < _data._items.length; i++) { - Item item = (Item) _data._items[i]; - if (item._selected) { - lastSelection = i; - if (1 == n && i < _data._items.length - 1) { - item._selected = false; - if (item._hasChildren) - _data.expandItem(i, true); - item = (Item) _data._items[i + 1]; - if (item._hasChildren) { - _data.expandItem(i + 1, true); - item = (Item) _data._items[i + 2]; - } - item._selected = true; - changed = true; - } else if (-1 == n && i > 0) { - i--; - Item prevItem = (Item) _data._items[i]; - if (prevItem._hasChildren) { - if (prevItem._expanded) { - if (i > 0) { - i--; - prevItem = (Item) _data._items[i]; - } - } - if (!prevItem._expanded) { - int added = _data.expandItem(i, true); - prevItem = (Item) _data._items[i + added]; - item._selected = false; - prevItem._selected = true; - changed = true; - } - } else { - item._selected = false; - prevItem._selected = true; - changed = true; - } - } - break; - } - } - if (lastSelection < 0 && _data._items.length > 0) { - Item item = (Item) _data._items[0]; - if (item._hasChildren) { - _data.expandItem(0, true); - item = (Item) _data._items[1]; - item._selected = true; - changed = true; - } else { - item._selected = true; - changed = true; - } - } - if (changed) { - ensureVisibleItem(-1, false); - redraw(); - fireSelectionChanged(); - } - } - - public void selectEvent(int n) { - if (null == _timeProvider) - return; - ITmfTimeAnalysisEntry trace = getSelectedTrace(); - if (trace == null) - return; - long selectedTime = _timeProvider.getSelectedTime(); - long endTime = _timeProvider.getEndTime(); - ITimeEvent nextEvent; - if (-1 == n && selectedTime > endTime) - nextEvent = Utils.findEvent(trace, selectedTime, 0); - else - nextEvent = Utils.findEvent(trace, selectedTime, n); - if (null == nextEvent && -1 == n) - nextEvent = Utils.getFirstEvent(trace); - if (null != nextEvent) { - long nextTime = nextEvent.getTime(); - // If last event detected e.g. going back or not moving to a next - // event - if (nextTime <= selectedTime && n == 1) { - // Select to the end of this last event - nextTime = nextEvent.getTime() + nextEvent.getDuration(); - // but not beyond the end of the trace - if (nextTime > endTime) { - nextTime = endTime; - } - } - _timeProvider.setSelectedTimeInt(nextTime, true); - fireSelectionChanged(); - } else if (1 == n) { - _timeProvider.setSelectedTimeInt(endTime, true); - fireSelectionChanged(); - } - } - - public void selectNextEvent() { - selectEvent(1); - // Notify if visible time window has been adjusted - _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1()); - } - - public void selectPrevEvent() { - selectEvent(-1); - // Notify if visible time window has been adjusted - _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1()); - } - - public void selectNextTrace() { - selectTrace(1); - } - - public void selectPrevTrace() { - selectTrace(-1); - } - - /** - * Zooming based on mouse cursor location with mouse scrolling - * - * @param zoomIn - */ - public void zoom(boolean zoomIn) { - int globalX = getDisplay().getCursorLocation().x; - Point p = toControl(globalX, 0); - int nameSpace = _timeProvider.getNameSpace(); - int timeSpace = _timeProvider.getTimeSpace(); - int xPos = Math.max(nameSpace, Math.min(nameSpace + timeSpace, p.x)); - long time0 = _timeProvider.getTime0(); - long time1 = _timeProvider.getTime1(); - long interval = time1 - time0; - if (interval == 0) { - interval = 1; - } // to allow getting out of single point interval - long newInterval; - if (zoomIn) { - newInterval = Math.max(Math.round((double) interval * 0.8), _timeProvider.getMinTimeInterval()); - } else { - newInterval = (long) Math.ceil((double) interval * 1.25); - } - long center = time0 + Math.round(((double) (xPos - nameSpace) / timeSpace * interval)); - long newTime0 = center - Math.round((double) newInterval * (center - time0) / interval); - long newTime1 = newTime0 + newInterval; - _timeProvider.setStartFinishTime(newTime0, newTime1); - } - - /** - * zoom in using single click - */ - public void zoomIn() { - long _time0 = _timeProvider.getTime0(); - long _time1 = _timeProvider.getTime1(); - long _range = _time1 - _time0; - long selTime = _timeProvider.getSelectedTime(); - if (selTime <= _time0 || selTime >= _time1) { - selTime = (_time0 + _time1) / 2; - } - long time0 = selTime - (long) ((selTime - _time0) / zoomCoeff); - long time1 = selTime + (long) ((_time1 - selTime) / zoomCoeff); - - long inaccuracy = (_timeProvider.getMaxTime() - _timeProvider.getMinTime()) - (time1 - time0); - - // Trace.debug("selTime:" + selTime + " time0:" + time0 + " time1:" - // + time1 + " inaccuracy:" + inaccuracy); - - if (inaccuracy > 0 && inaccuracy < 100) { - _timeProvider.setStartFinishTimeNotify(_timeProvider.getMinTime(), _timeProvider.getMaxTime()); - return; - } - - long m = _timeProvider.getMinTimeInterval(); - if ((time1 - time0) < m) { - time0 = selTime - (long) ((selTime - _time0) * m / _range); - time1 = time0 + m; - } - - _timeProvider.setStartFinishTimeNotify(time0, time1); - } - - /** - * zoom out using single click - */ - public void zoomOut() { - long _time0 = _timeProvider.getTime0(); - long _time1 = _timeProvider.getTime1(); - long selTime = _timeProvider.getSelectedTime(); - if (selTime <= _time0 || selTime >= _time1) { - selTime = (_time0 + _time1) / 2; - } - long time0 = (long) (selTime - (selTime - _time0) * zoomCoeff); - long time1 = (long) (selTime + (_time1 - selTime) * zoomCoeff); - - long inaccuracy = (_timeProvider.getMaxTime() - _timeProvider.getMinTime()) - (time1 - time0); - if (inaccuracy > 0 && inaccuracy < 100) { - _timeProvider.setStartFinishTimeNotify(_timeProvider.getMinTime(), _timeProvider.getMaxTime()); - return; - } - - _timeProvider.setStartFinishTimeNotify(time0, time1); - } - - public void groupTraces(boolean on) { - _data.groupTraces(on); - adjustScrolls(); - redraw(); - } - - public void toggleTraceInteractionDrawing() { - drawTracesInteraction = !drawTracesInteraction; - redraw(); - } - - public void setTraceJoinDrawing(boolean on) { - drawTraceJoins = on; - drawTracesInteraction = true; - redraw(); - } - - public void setTraceWaitDrawing(boolean on) { - drawTraceWaits = on; - drawTracesInteraction = true; - redraw(); - } - - public void setTraceReleaseDrawing(boolean on) { - drawTraceReleases = on; - drawTracesInteraction = true; - redraw(); - } - - public boolean getTracesInteractionDrawing() { - return drawTracesInteraction; - } - - public boolean getTraceJoinDrawing() { - return drawTraceJoins; - } - - public boolean getTraceWaitDrawing() { - return drawTraceWaits; - } - - public boolean getTraceReleaseDrawing() { - return drawTraceReleases; - } - - public ITmfTimeAnalysisEntry getSelectedTrace() { - ITmfTimeAnalysisEntry trace = null; - int idx = getSelectedIndex(); - if (idx >= 0 && _data._items[idx] instanceof TraceItem) - trace = ((TraceItem) _data._items[idx])._trace; - return trace; - } - - public int getSelectedIndex() { - int idx = -1; - for (int i = 0; i < _data._items.length; i++) { - Item item = (Item) _data._items[i]; - if (item._selected) { - idx = i; - break; - } - } - return idx; - } - - boolean toggle(int idx) { - boolean toggled = false; - if (idx >= 0 && idx < _data._items.length) { - Item item = (Item) _data._items[idx]; - if (item._hasChildren) { - item._expanded = !item._expanded; - _data.updateItems(); - adjustScrolls(); - redraw(); - toggled = true; - } - } - return toggled; - } - - int hitTest(int x, int y) { - if (x < 0 || y < 0) - return -1; - int hit = -1; - int idx = y / _itemHeight; - idx += _topItem; - if (idx < _data._items.length) - hit = idx; - return hit; - } - - int hitSplitTest(int x, int y) { - if (x < 0 || y < 0 || null == _timeProvider) - return -1; - int w = 4; - int hit = -1; - int nameWidth = _timeProvider.getNameSpace(); - if (x > nameWidth - w && x < nameWidth + w) - hit = 1; - return hit; - } - - Item getItem(Point pt) { - int idx = hitTest(pt.x, pt.y); - return idx >= 0 ? (Item) _data._items[idx] : null; - } - - long hitTimeTest(int x) { - if (null == _timeProvider) - return -1; - long hitTime = -1; - Point size = getCtrlSize(); - long time0 = _timeProvider.getTime0(); - long time1 = _timeProvider.getTime1(); - int nameWidth = _timeProvider.getNameSpace(); - x -= nameWidth; - if (x >= 0 && size.x >= nameWidth) { - if (time1 - time0 > size.x - nameWidth - RIGHT_MARGIN) { - // get the last possible time represented by the pixel position - // by taking the time of the next pixel position minus 1 - // nanosecond - hitTime = time0 + (long) ((time1 - time0) * ((double) (x + 1) / (size.x - nameWidth - RIGHT_MARGIN))) - 1; - } else { - hitTime = time0 + (long) ((time1 - time0) * ((double) (x) / (size.x - nameWidth - RIGHT_MARGIN))); - } - } - return hitTime; - } - - void selectItem(int idx, boolean addSelection) { - boolean changed = false; - if (addSelection) { - if (idx >= 0 && idx < _data._items.length) { - Item item = (Item) _data._items[idx]; - changed = (item._selected == false); - item._selected = true; - } - } else { - for (int i = 0; i < _data._items.length; i++) { - Item item = (Item) _data._items[i]; - if (i == idx && item._selected == false) { - changed = true; - } - item._selected = i == idx; - } - } - changed |= ensureVisibleItem(idx, true); - if (changed) - redraw(); - } - - public void selectItem(ITmfTimeAnalysisEntry trace, boolean addSelection) { - Integer idx = _data.findTraceItemIndex(trace); - if (idx != null) { - selectItem(idx, addSelection); - } - } - - public int countPerPage() { - int height = getCtrlSize().y; - int count = 0; - if (height > 0) - count = height / _itemHeight; - return count; - } - - public int getTopIndex() { - int idx = -1; - if (_data._items.length > 0) - idx = 0; - return idx; - } - - public int getBottomIndex() { - int idx = _data._items.length - 1; - return idx; - } - - Point getCtrlSize() { - Point size = getSize(); - if (getVerticalBar().isVisible()) { - size.x -= getVerticalBar().getSize().x; - } - if (getHorizontalBar().isVisible()) { - size.y -= getHorizontalBar().getSize().y; - } - return size; - } - - void getNameRect(Rectangle rect, Rectangle bound, int idx, int nameWidth) { - idx -= _topItem; - rect.x = bound.x; - rect.y = bound.y + idx * _itemHeight; - rect.width = nameWidth; - rect.height = _itemHeight; - } - - void getStatesRect(Rectangle rect, Rectangle bound, int idx, int nameWidth) { - idx -= _topItem; - rect.x = bound.x + nameWidth; - rect.y = bound.y + idx * _itemHeight; - rect.width = bound.width - rect.x; - rect.height = _itemHeight; - } - - // private int getTraceNumber(int tid) { - // int num = -1; - // - // Object[] items = _data._items; - // for (int i = _topItem; i < items.length; i++) { - // Item item = (Item) items[i]; - // if ((item instanceof TraceItem)) { - // TsfTmTrace trace = ((TraceItem) item)._trace; - // if (trace != null && trace.getId() == tid) { - // num = i; - // break; - // } - // } - // } - // - // return num; - // } - - // private void drawArrow(GC gc, int x0, int y0, int x1, int y1, Color c) { - // gc.setForeground(c); - // gc.drawLine(x0, y0, x1, y1); - // - // if (y1 > y0) { - // gc.drawLine(x1 - 3, y1 - 3, x1, y1); - // gc.drawLine(x1 + 3, y1 - 3, x1, y1); - // } else { - // gc.drawLine(x1 - 3, y1 + 3, x1, y1); - // gc.drawLine(x1 + 3, y1 + 3, x1, y1); - // } - // } - - // TODO: CC: used in the removed functionality to draw thread interactions. - // private void drawTraceThreadEvent(Rectangle bound, TsfTmEvent e, - // TsfTmTrace trace, int nItem, int color, GC gc) { - // if (trace == null) - // return; - // - // int tid = trace.getId(); - // if (tid < 0 || getTraceNumber(tid) == -1) - // return; - // - // int nameWidth = _timeProvider.getNameSpace(); - // - // double time0 = _timeProvider.getTime0(); - // double time1 = _timeProvider.getTime1(); - // if (time0 == time1) - // return; - // - // int xr = bound.x + nameWidth; - // double K = (double) (bound.width - xr) / (time1 - time0); - // - // int x0 = xr + (int) ((e.getTime() - time0) * K); - // if (x0 < xr) - // x0 = xr; - // - // int x1 = xr + (int) ((trace.getStartTime() - time0) * K); - // if (x1 < xr) - // return; - // - // int y0 = bound.y + (nItem - _topItem) * _itemHeight + 3 - // + (_itemHeight - 6) / 2; - // int y1 = bound.y + (getTraceNumber(tid) - _topItem) * _itemHeight + 3 - // + (_itemHeight - 6) / 2; - // - // drawArrow(gc, x0, y0, x1, y1, _colors.getColor(color)); - // } - - public void drawTraceEvent(Rectangle bound, ITimeEvent e, int nItem, int color, GC gc) { - int nameWidth = _timeProvider.getNameSpace(); - - long time0 = _timeProvider.getTime0(); - long time1 = _timeProvider.getTime1(); - if (time0 == time1) - return; - - int xr = bound.x + nameWidth; - double pixelsPerNanoSec = (bound.width - xr <= RIGHT_MARGIN) ? 0 : (double) (bound.width - xr - RIGHT_MARGIN) / (time1 - time0); - - int x0 = xr + (int) ((e.getTime() - time0) * pixelsPerNanoSec); - if (x0 < xr) - return; - - int y0 = bound.y + (nItem - _topItem) * _itemHeight + 3; - - gc.setBackground(_colors.getColor(color)); - int c[] = { x0 - 3, y0 - 3, x0, y0, x0 + 3, y0 - 3 }; - gc.fillPolygon(c); - } - - // TODO: CC: - // private void drawExecEvent(Rectangle bound, TsfTmTraceExecEventImpl e, - // int nitem, int color, GC gc) { - // List runnings = e.getRunningEvents(); - // if (runnings == null) - // return; - // - // int nameWidth = _timeProvider.getNameSpace(); - // - // double time0 = _timeProvider.getTime0(); - // double time1 = _timeProvider.getTime1(); - // if (time0 == time1) - // return; - // - // int xr = bound.x + nameWidth; - // double K = (double) (bound.width - xr) / (time1 - time0); - // - // int x0 = xr + (int) ((e.getTime() - time0) * K); - // if (x0 < xr) - // x0 = xr; - // - // Iterator it = runnings.iterator(); - // while (it.hasNext()) { - // TsfTmTraceRunningEventImpl re = (TsfTmTraceRunningEventImpl) it - // .next(); - // int tid = re.getThread().getId(); - // if (tid < 0 || getThreadNumber(tid) == -1) - // continue; - // - // int x1 = xr + (int) ((re.getTime() - time0) * K); - // if (x1 < xr) - // continue; - // - // int y0 = bound.y + (nitem - _topItem) * _itemHeight + 3 - // + (_itemHeight - 6) / 2; - // int y1 = bound.y + (getThreadNumber(tid) - _topItem) * _itemHeight - // + 3 + (_itemHeight - 6) / 2; - // - // drawArrow(gc, x0, y0, x1, y1, _colors.getColor(color)); - // } - // } - - public void drawTraceInteractions(Rectangle bound, GC gc) { - // int nameWidth = _timeProvider.getNameSpace(); - // Object[] items = _data._items; - // - // double time0 = _timeProvider.getTime0(); - // double time1 = _timeProvider.getTime1(); - // - // if (time0 == time1) - // return; - // - // int xr = bound.x + nameWidth; - // double K = (double) (bound.width - xr) / (time1 - time0); - - // for (int i = 0; i < items.length; i++) { - // Item item = (Item) items[i]; - // if (!(item instanceof TraceItem)) - // continue; - // - // TsfTmTrace trace = ((TraceItem) item)._trace; - // if (trace == null) - // continue; - // - // List list = trace.getTraceEvents(); - // Iterator it = list.iterator(); - // while (it.hasNext()) { - // TsfTmEvent te = (TsfTmEvent) it.next(); - // TODO: CC: Thread Interactions, - // This needs to be accessed externally via a specific - // implementation. - // if (te instanceof TsfTmTraceStartThreadEventImpl) { - // TsfTmTrace child = ((TsfTmTraceStartThreadEventImpl) te) - // .getStartedThread(); - // drawThreadThreadEvent(bound, te, child, i, - // TraceColorScheme.TI_START_THREAD, gc); - // } else if (te instanceof TsfTmTraceHandoffLockEventImpl) { - // if (drawThreadReleases) - // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i, - // TraceColorScheme.TI_HANDOFF_LOCK, gc); - // } else if (te instanceof TsfTmTraceNotifyAllEventImpl) { - // if (drawThreadWaits) - // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i, - // TraceColorScheme.TI_NOTIFY_ALL, gc); - // } else if (te instanceof TsfTmTraceNotifyEventImpl) { - // if (drawThreadWaits) - // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i, - // TraceColorScheme.TI_NOTIFY, gc); - // } else if (te instanceof - // TsfTmTraceDeadAndNotifyJoinedEventImpl) { - // if (drawThreadJoins) - // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i, - // TraceColorScheme.TI_NOTIFY_JOINED, gc); - // } else if (te instanceof TsfTmTraceInterruptThreadEventImpl) - // { - // if (drawThreadWaits) - // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i, - // TraceColorScheme.TI_INTERRUPT, gc); - // } else if (te instanceof - // TsfTmTraceWaitTimeoutExceedEventImpl) { - // drawThreadEvent(bound, te, i, - // TraceColorScheme.TI_WAIT_EXCEEDED, gc); - // } - // } - // } - } - - @Override - void paint(Rectangle bound, PaintEvent e) { - GC gc = e.gc; - gc.setBackground(_colors.getColor(TraceColorScheme.BACKGROUND)); - drawBackground(gc, bound.x, bound.y, bound.width, bound.height); - - if (bound.width < 2 || bound.height < 2 || null == _timeProvider) - return; - - _idealNameWidth = 0; - int nameWidth = _timeProvider.getNameSpace(); - long time0 = _timeProvider.getTime0(); - long time1 = _timeProvider.getTime1(); - long endTime = _timeProvider.getEndTime(); - long selectedTime = _timeProvider.getSelectedTime(); - // draw trace states - Object[] items = _data._items; - for (int i = _topItem; i < items.length; i++) { - Item item = (Item) items[i]; - - getNameRect(_rect0, bound, i, nameWidth); - if (_rect0.y >= bound.y + bound.height) - break; - - if (item instanceof GroupItem) { - getStatesRect(_rect1, bound, i, nameWidth); - _rect0.width += _rect1.width; - drawName(item, _rect0, gc); - } else { - drawName(item, _rect0, gc); - } - getStatesRect(_rect0, bound, i, nameWidth); - drawItemDataDurations(item, _rect0, time0, time1, endTime, selectedTime, gc); - } - - if (drawTracesInteraction) - drawTraceInteractions(bound, e.gc); - - // draw empty name space background - if (_itemHeight * items.length < bound.height) { - gc.setBackground(_colors.getBkColor(false, false, true)); - drawBackground(gc, bound.x, _itemHeight * items.length, nameWidth, bound.height - _itemHeight * items.length); - } - - // draw drag line, no line if name space is 0. - if (DRAG_SPLIT_LINE == _dragState) { - gc.setForeground(_colors.getColor(TraceColorScheme.BLACK)); - gc.drawLine(bound.x + nameWidth, bound.y, bound.x + nameWidth, bound.y + bound.height - 1); - } else if (DRAG_NONE == _dragState && _mouseHover && _timeProvider.getNameSpace() > 0) { - gc.setForeground(_colors.getColor(TraceColorScheme.RED)); - gc.drawLine(bound.x + nameWidth, bound.y, bound.x + nameWidth, bound.y + bound.height - 1); - } - } - - void drawName(Item item, Rectangle rect, GC gc) { - // No name to be drawn - if (_timeProvider.getNameSpace() == 0) - return; - boolean group = item instanceof GroupItem; - - int elemHeight = rect.height / 2; - int elemWidth = elemHeight; - String name = item._name; - if (group) { - gc.setBackground(_colors.getBkColorGroup(item._selected, _isInFocus)); - gc.fillRectangle(rect); - if (item._selected && _isInFocus) { - gc.setForeground(_colors.getBkColor(item._selected, _isInFocus, false)); - gc.drawRectangle(rect.x, rect.y, rect.width - 2, rect.height - 2); - } - gc.setForeground(_colors.getBkColor(false, false, false)); - gc.drawLine(rect.x, rect.y + rect.height - 1, rect.width - 1, rect.y + rect.height - 1); - gc.setForeground(_colors.getFgColorGroup(false, false)); - gc.setBackground(_colors.getBkColor(false, false, false)); - Utils.init(_rect1, rect); - _rect1.x += MARGIN; - _rect1.y += (rect.height - elemHeight) / 2; - _rect1.width = elemWidth; - _rect1.height = elemHeight; - // Get the icon rectangle in the group items - gc.fillRectangle(_rect1); - gc.drawRectangle(_rect1.x, _rect1.y, _rect1.width - 1, _rect1.height - 1); - int p = _rect1.y + _rect1.height / 2; - gc.drawLine(_rect1.x + 2, p, _rect1.x + _rect1.width - 3, p); - if (!item._expanded) { - p = _rect1.x + _rect1.width / 2; - gc.drawLine(p, _rect1.y + 2, p, _rect1.y + _rect1.height - 3); - } - gc.setForeground(_colors.getFgColorGroup(item._selected, _isInFocus)); - elemWidth += MARGIN; - } else { - gc.setBackground(_colors.getBkColor(item._selected, _isInFocus, true)); - gc.setForeground(_colors.getFgColor(item._selected, _isInFocus)); - gc.fillRectangle(rect); - Utils.init(_rect1, rect); - _rect1.x += MARGIN; - // draw icon - ITmfTimeAnalysisEntry trace = ((TraceItem) item)._trace; - Image img = utilImpl.getItemImage(trace); - if (null != img) { - _rect1.y += (rect.height - img.getImageData().height) / 2; - gc.drawImage(img, _rect1.x, _rect1.y); - } - elemWidth = SMALL_ICON_SIZE; - // cut long string with "..." - Point size = gc.stringExtent(name); - if (_idealNameWidth < size.x) - _idealNameWidth = size.x; - int width = rect.width - MARGIN - MARGIN - elemWidth; - int cuts = 0; - while (size.x > width && name.length() > 1) { - cuts++; - name = name.substring(0, name.length() - 1); - size = gc.stringExtent(name + "..."); //$NON-NLS-1$ - } - if (cuts > 0) - name += "..."; //$NON-NLS-1$ - elemWidth += MARGIN; - } - Utils.init(_rect1, rect); - int leftMargin = MARGIN + elemWidth; - _rect1.x += leftMargin; - _rect1.width -= leftMargin; - int textWidth = 0; - // draw text - if (_rect1.width > 0) { - _rect1.y += 2; - textWidth = Utils.drawText(gc, name, _rect1, true) + 8; - _rect1.y -= 2; - } - // draw middle line - if (_rect1.width > 0 && !group) { - Utils.init(_rect1, rect); - _rect1.x += leftMargin + textWidth; - _rect1.width -= textWidth; - gc.setForeground(_colors.getColor(TraceColorScheme.MID_LINE)); - int midy = _rect1.y + _rect1.height / 2; - gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy); - } - // gc.drawLine(_rect1.x + _rect1.width - 1, _rect1.y, _rect1.x + - // _rect1.width - 1, _rect1.y + _rect1.height); - } - - void drawItemData(Item item, Rectangle rect, long time0, long time1, long endTime, long selectedTime, GC gc) { - if (rect.isEmpty()) - return; - if (time1 <= time0) { - gc.setBackground(_colors.getBkColor(false, false, false)); - gc.fillRectangle(rect); - return; - } - - Utils.init(_rect1, rect); - boolean selected = item._selected; - double pixelsPerNanoSec = (rect.width <= RIGHT_MARGIN) ? 0 : (double) (rect.width - RIGHT_MARGIN) / (time1 - time0); - boolean group = item instanceof GroupItem; - - if (group) { - // gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus)); - // gc.fillRectangle(rect); - } else if (item instanceof TraceItem) { - ITmfTimeAnalysisEntry trace = ((TraceItem) item)._trace; - - int x0 = rect.x; - Iterator iterator = trace.getTraceEventsIterator(); - ITimeEvent lastEvent = null; - if (iterator.hasNext()) { - ITimeEvent currEvent = iterator.next(); - ITimeEvent nextEvent = null; - long currEventTime = currEvent.getTime(); - long nextEventTime = currEventTime; - x0 = rect.x + (int) ((currEventTime - time0) * pixelsPerNanoSec); - int xEnd = rect.x + (int) ((time1 - time0) * pixelsPerNanoSec); - int x1 = -1; - - // reduce rect - _rect1.y += 3; - _rect1.height -= 6; - fillSpace(rect, gc, selected); - - // draw event states - while (x0 <= xEnd && null != currEvent) { - boolean stopped = false;// currEvent instanceof - // TsfTmTraceDeadEvent; - if (iterator.hasNext()) { - nextEvent = iterator.next(); - nextEventTime = nextEvent.getTime(); - } else if (stopped) { - nextEvent = null; - nextEventTime = time1; - } else { - nextEvent = null; - nextEventTime = endTime; - } - x1 = rect.x + (int) ((nextEventTime - time0) * pixelsPerNanoSec); - if (x1 >= rect.x) { - _rect1.x = x0 >= rect.x ? x0 : rect.x; - _rect1.width = (x1 <= xEnd ? x1 : xEnd) - _rect1.x; - boolean timeSelected = currEventTime <= selectedTime && selectedTime < nextEventTime; - // Trace.debug("Drawing rectangle: " + _rect1.x + "," - // + _rect1.y + "," + _rect1.height + ", " - // + _rect1.width + "-->" - // + ((int) _rect1.x + (int) _rect1.width)); - utilImpl.drawState(_colors, currEvent, _rect1, gc, selected, false, timeSelected); - } - lastEvent = currEvent; - currEvent = nextEvent; - currEventTime = nextEventTime; - x0 = x1; - } - } - - // fill space after last event - int xEnd = rect.x + rect.width; - if (x0 < xEnd) { - _rect1.x = x0 >= rect.x ? x0 : rect.x; - _rect1.width = xEnd - _rect1.x; - gc.setBackground(_colors.getBkColor(selected, _isInFocus, false)); - gc.fillRectangle(_rect1); - // draw middle line - gc.setForeground(_colors.getColor(utilImpl.getEventColorVal(lastEvent))); - int midy = _rect1.y + _rect1.height / 2; - int lw = gc.getLineWidth(); - gc.setLineWidth(2); - gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy); - gc.setLineWidth(lw); - } - } - - // draw selected time - int x = rect.x + (int) ((selectedTime - time0) * pixelsPerNanoSec); - if (x >= rect.x && x < rect.x + rect.width) { - gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME)); - if (group) - gc.drawLine(x, rect.y + rect.height - 1, x, rect.y + rect.height); - else - gc.drawLine(x, rect.y, x, rect.y + rect.height); - } - } - - /** - * Represent the event in series of bursts rather than sequence of states - * - * @param item - * @param rect - * - The container rectangle to be colored to different states - * @param time0 - * - Base time of all events - * @param time1 - * - End time of all events - * @param endTime - * @param selectedTime - * @param gc - */ - void drawItemDataBurst(Item item, Rectangle rect, long time0, long time1, long endTime, long selectedTime, GC gc) { - if (rect.isEmpty()) - return; - if (time1 <= time0) { - gc.setBackground(_colors.getBkColor(false, false, false)); - gc.fillRectangle(rect); - return; - } - - // Initialize _rect1 to same values as enclosing rectangle rect - Utils.init(_rect1, rect); - boolean selected = item._selected; - // K pixels per second - double pixelsPerNanoSec = (rect.width <= RIGHT_MARGIN) ? 0 : (double) (rect.width - RIGHT_MARGIN) / (time1 - time0); - // Trace.debug("Value of K: " + K + " width:" + rect.width + " time0: " - // + time0 + " time1:" + time1 + " endTime: " + endTime); - - boolean group = item instanceof GroupItem; - - if (group) { - // gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus)); - // gc.fillRectangle(rect); - // if (Trace.isDEBUG()) { - // Trace.debug("Group"); - // } - } else if (item instanceof TraceItem) { - ITmfTimeAnalysisEntry trace = ((TraceItem) item)._trace; - - double x0 = rect.x; - Iterator iterator = trace.getTraceEventsIterator(); - ITimeEvent lastEvent = null; - // Trace.debug("count is: " + count); - if (iterator.hasNext()) { - ITimeEvent currEvent = iterator.next(); - ITimeEvent nextEvent = null; - long currEventTime = currEvent.getTime(); - long nextEventTime = currEventTime; - // x0 - Points to the beginning of the event being drawn - double step = (double) ((currEventTime - time0) * pixelsPerNanoSec); - x0 = rect.x + step; - // xEnd - Points to the end of the events rectangle - double xEnd = rect.x + (double) ((time1 - time0) * pixelsPerNanoSec); - double x1 = -1; - //double xNext = 0; - - // Drawing rectangle is smaller than reserved space - _rect1.y += 3; - _rect1.height -= 6; - - // Clean up to empty line to draw on top - fillSpace(rect, gc, selected); - // draw event states - while (x0 <= xEnd && null != currEvent) { - boolean stopped = false;// currEvent instanceof - // TsfTmTraceDeadEvent; - if (iterator.hasNext()) { - nextEvent = iterator.next(); - nextEventTime = nextEvent.getTime(); - } else if (stopped) { - nextEvent = null; - nextEventTime = time1; - } else { - nextEvent = null; - nextEventTime = endTime; - // Trace - // .debug("nexEventTime is endTime: " - // + nextEventTime); - } - - // Draw it as a burst, one unit of width. - x1 = x0 + (int) 2; - if (x1 >= rect.x && x0 <= xEnd) { - // Fill with space until x0 - _rect1.x = (int) (x0 >= rect.x ? x0 : rect.x); - _rect1.width = (int) ((x1 <= xEnd ? x1 : xEnd) - _rect1.x); - boolean timeSelected = currEventTime <= selectedTime && selectedTime < nextEventTime; - utilImpl.drawState(_colors, currEvent, _rect1, gc, selected, false, timeSelected); - // Trace.debug("Drawing rectangle: " + _rect1.x + "," - // + _rect1.y + "," + _rect1.height + ", " - // + _rect1.width + "-->" - // + ((int) _rect1.x + (int) _rect1.width)); - // Advance rectangle to next start position and Fill - // with space until next event - _rect1.x += _rect1.width; - x0 = x1; - //xNext = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); - } - // Fill space till next event - fillSpace(rect, gc, selected); - - lastEvent = currEvent; - currEvent = nextEvent; - currEventTime = nextEventTime; - // Move x0 to the beginning of next event - x0 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); - // Trace.debug("rect.x: " + rect.x + " + " + - // "(nextEvenTime: " - // + nextEventTime + "- time0: " + time0 + ") * K: " - // + K + " = " + x0); - } - } - - // fill space after last event - int xEnd = rect.x + rect.width; - if (x0 < xEnd) { - // Trace.debug("Space after last event, x0: " + x0 + ", xEnd: " - // + xEnd); - _rect1.x = (int) (x0 >= rect.x ? x0 : rect.x); - _rect1.width = xEnd - _rect1.x; - gc.setBackground(_colors.getBkColor(selected, _isInFocus, false)); - gc.fillRectangle(_rect1); - // draw middle line - gc.setForeground(_colors.getColor(utilImpl.getEventColorVal(lastEvent))); - int midy = _rect1.y + _rect1.height / 2; - int lw = gc.getLineWidth(); - gc.setLineWidth(2); - gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy); - gc.setLineWidth(lw); - } - } - - // draw selected time - int x = rect.x + (int) ((selectedTime - time0) * pixelsPerNanoSec); - if (x >= rect.x && x < rect.x + rect.width) { - gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME)); - if (group) - gc.drawLine(x, rect.y + rect.height - 1, x, rect.y + rect.height); - else - gc.drawLine(x, rect.y, x, rect.y + rect.height); - } - } - - /** - * Represent the series of events with specified durations - * - * @param item - * @param rect - * - The container rectangle to be colored to different states - * @param time0 - * - Base time of all events - start of visible window - * @param time1 - * - End time of visible events - end time of visible window - * @param endTime - * - End time of all events - may not be visible in selected - * visible window - * @param selectedTime - * @param gc - */ - void drawItemDataDurations(Item item, Rectangle rect, long time0, long time1, long endTime, long selectedTime, GC gc) { - if (rect.isEmpty()) - return; - if (time1 <= time0) { - gc.setBackground(_colors.getBkColor(false, false, false)); - gc.fillRectangle(rect); - return; - } - - // Initialize _rect1 to same values as enclosing rectangle rect - Utils.init(_rect1, rect); - boolean selected = item._selected; - // K pixels per second - double pixelsPerNanoSec = (rect.width <= RIGHT_MARGIN) ? 0 : (double) (rect.width - RIGHT_MARGIN) / (time1 - time0); - // Trace.debug("Value of K: " + K + " width:" + rect.width + " time0: " - // + time0 + " time1:" + time1 + " endTime: " + endTime); - - boolean group = item instanceof GroupItem; - - if (group) { - // gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus)); - // gc.fillRectangle(rect); - } else if (item instanceof TraceItem) { - ITmfTimeAnalysisEntry trace = ((TraceItem) item)._trace; - - double x0 = rect.x; - long maxDuration = (_timeProvider.getTimeSpace() == 0) ? Long.MAX_VALUE : 1 * (_timeProvider.getTime1() - _timeProvider.getTime0()) / _timeProvider.getTimeSpace(); - Iterator iterator = trace.getTraceEventsIterator(_timeProvider.getTime0(), _timeProvider.getTime1(), maxDuration); - // ITimeEvent lastEvent = null; - // if (Trace.isDEBUG()) { - // Trace.debug("\n\t\t\tTrace: " + trace.getName() - // + utilImpl.getTraceClassName(trace)); - // } - // Trace.debug("count is: " + count); - // Drawing rectangle is smaller than reserved space - _rect1.y += 3; - _rect1.height -= 6; - - // Clean up to empty line to draw on top - int xEnd = rect.x + rect.width; - fillSpace(rect, gc, selected); - if (iterator.hasNext()) { - ITimeEvent currEvent = iterator.next(); - ITimeEvent nextEvent = null; - long currEventTime = currEvent.getTime(); - long currEventDuration = currEvent.getDuration(); - // initial value - long nextEventTime = currEventTime; - // x0 - Points to the beginning of the event being drawn - double step = (double) ((currEventTime - time0) * pixelsPerNanoSec); - x0 = rect.x + step; - // xEnd - Points to the end of the events rectangle - double x1 = -1; - double xNext = 0; - - // draw event states - while (/* x0 <= xEnd && */null != currEvent) { - boolean stopped = false;// currEvent instanceof - // refresh current event duration as the loop moves - currEventDuration = currEvent.getDuration(); - // TsfTmTraceDeadEvent; - if (iterator.hasNext()) { - nextEvent = iterator.next(); - nextEventTime = nextEvent.getTime(); - } else if (stopped) { - nextEvent = null; - nextEventTime = time1; - } else { - nextEvent = null; - nextEventTime = endTime; - // Trace - // .debug("nexEventTime is endTime: " - // + nextEventTime); - } - - // Calculate position to next event - xNext = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); - - // Calculate end position of current event - if (currEventDuration < 0) { - x1 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); - } else if (currEventDuration == 0) { - x1 = x0; - } else { - x1 = x0 + (double) ((currEventDuration) * pixelsPerNanoSec); - } - - // If event end position x1 further away than start position - // of - // next event, cut width till next event - // Trace.debug("Next Event Pos: " + xNext - // + " End Of Current at: " + x1 + " Event Duration: " - // + currEventDuration); - if (currEventDuration != 0) { - x1 = x1 > xNext ? xNext : x1; - } - // if event end boundary is within time range - if (x1 >= rect.x && x0 <= xEnd) { - if (currEventDuration != 0) { - x0 = (double) (x0 >= rect.x ? x0 : rect.x); - _rect1.width = (int) ((x1 <= xEnd ? x1 : xEnd) - x0); - } else { - _rect1.width = 1; - } - _rect1.width = Math.max(_minimumItemWidth, _rect1.width); - _rect1.x = (int) x0; - boolean timeSelected = currEventTime <= selectedTime && selectedTime < nextEventTime; - utilImpl.drawState(_colors, currEvent, _rect1, gc, selected, false, timeSelected); - // Trace.debug("Drawing rectangle: " + _rect1.x + "," - // + _rect1.y + "," + _rect1.height + ", " - // + _rect1.width + "-->" - // + ((int) _rect1.x + (int) _rect1.width)); - // Advance rectangle to next start position and Fill - // with space until next event - _rect1.x += _rect1.width; - x0 = _rect1.x; - } - - // Fill space till next event - // fillSpace(rect, gc, selected, x0, xNext, xEnd); - - // lastEvent = currEvent; - currEvent = nextEvent; - currEventTime = nextEventTime; - // Move x0 to the beginning of next event - x0 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); - // Trace.debug("rect.x: " + rect.x + " + " + - // "(nextEvenTime: " - // + nextEventTime + "- time0: " + time0 + ") * K: " - // + K + " = " + x0); - } - } - } - - // draw selected time - int x = rect.x + (int) ((double) (selectedTime - time0) * pixelsPerNanoSec); - if (x >= rect.x && x < rect.x + rect.width) { - gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME)); - if (group) - gc.drawLine(x, rect.y + rect.height - 1, x, rect.y + rect.height); - else - gc.drawLine(x, rect.y, x, rect.y + rect.height); - } - } - - private void fillSpace(Rectangle rect, GC gc, boolean selected) { - gc.setBackground(_colors.getBkColor(selected, _isInFocus, false)); - gc.fillRectangle(rect); - // draw middle line - gc.setForeground(_colors.getColor(TraceColorScheme.MID_LINE)); - int midy = rect.y + rect.height / 2; - gc.drawLine(rect.x, midy, rect.x + rect.width, midy); - } - - @Override - public void keyTraversed(TraverseEvent e) { - if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) - e.doit = true; - } - - @Override - public void keyPressed(KeyEvent e) { - int idx = -1; - if (SWT.HOME == e.keyCode) { - idx = getTopIndex(); - } else if (SWT.END == e.keyCode) { - idx = getBottomIndex(); - } else if (SWT.ARROW_DOWN == e.keyCode) { - idx = getSelectedIndex(); - if (idx < 0) - idx = 0; - else if (idx < _data._items.length - 1) - idx++; - } else if (SWT.ARROW_UP == e.keyCode) { - idx = getSelectedIndex(); - if (idx < 0) - idx = 0; - else if (idx > 0) - idx--; - } else if (SWT.ARROW_LEFT == e.keyCode) { - selectPrevEvent(); - } else if (SWT.ARROW_RIGHT == e.keyCode) { - selectNextEvent(); - } else if (SWT.PAGE_DOWN == e.keyCode) { - int page = countPerPage(); - idx = getSelectedIndex(); - if (idx < 0) - idx = 0; - idx += page; - if (idx >= _data._items.length) - idx = _data._items.length - 1; - } else if (SWT.PAGE_UP == e.keyCode) { - int page = countPerPage(); - idx = getSelectedIndex(); - if (idx < 0) - idx = 0; - idx -= page; - if (idx < 0) - idx = 0; - } else if (SWT.CR == e.keyCode) { - idx = getSelectedIndex(); - if (idx >= 0) { - if (_data._items[idx] instanceof TraceItem) - fireDefaultSelection(); - else if (_data._items[idx] instanceof GroupItem) - toggle(idx); - } - idx = -1; - } - if (idx >= 0) { - selectItem(idx, false); - fireSelectionChanged(); - } - } - - @Override - public void keyReleased(KeyEvent e) { - } - - @Override - public void focusGained(FocusEvent e) { - _isInFocus = true; - redraw(); - } - - @Override - public void focusLost(FocusEvent e) { - _isInFocus = false; - if (DRAG_NONE != _dragState) { - setCapture(false); - _dragState = DRAG_NONE; - } - redraw(); - } - - public boolean isInFocus() { - return _isInFocus; - } - - @Override - public void mouseMove(MouseEvent e) { - if (null == _timeProvider) - return; - Point size = getCtrlSize(); - if (DRAG_TRACE_ITEM == _dragState) { - int nameWidth = _timeProvider.getNameSpace(); - int x = e.x - nameWidth; - if (x > 0 && size.x > nameWidth && _dragX != x) { - _dragX = x; - double pixelsPerNanoSec = (size.x - nameWidth <= RIGHT_MARGIN) ? 0 : (double) (size.x - nameWidth - RIGHT_MARGIN) / (_time1bak - _time0bak); - long timeDelta = (long) ((pixelsPerNanoSec == 0) ? 0 : ((_dragX - _dragX0) / pixelsPerNanoSec)); - long time1 = _time1bak - timeDelta; - long maxTime = _timeProvider.getMaxTime(); - if (time1 > maxTime) - time1 = maxTime; - long time0 = time1 - (_time1bak - _time0bak); - if (time0 < _timeProvider.getMinTime()) { - time0 = _timeProvider.getMinTime(); - time1 = time0 + (_time1bak - _time0bak); - } - _timeProvider.setStartFinishTime(time0, time1); - } - } else if (DRAG_SPLIT_LINE == _dragState) { - _dragX = e.x; - _timeProvider.setNameSpace(_hitIdx + _dragX - _dragX0); - } else if (DRAG_NONE == _dragState) { - boolean mouseHover = hitSplitTest(e.x, e.y) > 0; - if (_mouseHover != mouseHover) - redraw(); - _mouseHover = mouseHover; - // Make sure any time changes are notified to the application e.g. - // getting back from the horizontal scroll bar or zoomed using the - // mouse wheel - _timeProvider.notifyStartFinishTime(); - } - updateCursor(e.x, e.y); - } - - @Override - public void mouseDoubleClick(MouseEvent e) { - if (null == _timeProvider) - return; - if (1 == e.button) { - int idx = hitSplitTest(e.x, e.y); - if (idx >= 0) { - _timeProvider.setNameSpace(_idealNameWidth + 3 * MARGIN + SMALL_ICON_SIZE); - return; - } - idx = hitTest(e.x, e.y); - if (idx >= 0) { - selectItem(idx, false); - if (_data._items[idx] instanceof TraceItem) { - fireDefaultSelection(); - } - } - } - } - - /** - *

    - * If the x, y position is over the vertical split line (name to time - * ranges), then change the cursor to a drag cursor to indicate the user the - * possibility of resizing - *

    - * - * @param x - * @param y - */ - void updateCursor(int x, int y) { - // if Wait cursor not active, check for the need to change to a drag - // cursor - if (_isWaitCursor == false) { - int idx = hitSplitTest(x, y); - // No dragcursor is name space is fixed to zero - if (idx > 0 && !_isDragCursor3 && _timeProvider.getNameSpace() > 0) { - setCursor(_dragCursor3); - _isDragCursor3 = true; - } else if (idx <= 0 && _isDragCursor3) { - setCursor(null); - _isDragCursor3 = false; - } - } - } - - /** - * Provide the possibilty to control the wait cursor externally e.g. data - * requests in progress - * - * @param waitInd - */ - public void waitCursor(boolean waitInd) { - // Update cursor as indicated - if (waitInd) { - setCursor(_WaitCursor); - _isWaitCursor = true; - } else { - setCursor(null); - _isWaitCursor = false; - } - - // Get ready for next mouse move - _isDragCursor3 = false; - } - - @Override - public void mouseDown(MouseEvent e) { - if (null == _timeProvider) - return; - int idx; - if (1 == e.button) { - int namewidth = _timeProvider.getNameSpace(); - if (namewidth != 0) { - idx = hitSplitTest(e.x, e.y); - if (idx > 0) { - _dragState = DRAG_SPLIT_LINE; - _dragX = _dragX0 = e.x; - _hitIdx = _timeProvider.getNameSpace(); - ; - _time0bak = _timeProvider.getTime0(); - _time1bak = _timeProvider.getTime1(); - redraw(); - return; - } - } - - idx = hitTest(e.x, e.y); - if (idx >= 0) { - if (_data._items[idx] instanceof TraceItem) { - long hitTime = hitTimeTest(e.x); - if (hitTime >= 0) { - // _timeProvider.setSelectedTimeInt(hitTime, false); - setCapture(true); - _dragState = DRAG_TRACE_ITEM; - _dragX = _dragX0 = e.x - _timeProvider.getNameSpace(); - _hitIdx = idx; - _time0bak = _timeProvider.getTime0(); - _time1bak = _timeProvider.getTime1(); - return; - } - } else if (_data._items[idx] instanceof GroupItem) { - _dragX0 = e.x; - _dragState = DRAG_GROUP_ITEM; - } - selectItem(idx, false); - fireSelectionChanged(); - } else { - selectItem(idx, false); // clear selection - redraw(); - } - } - } - - @Override - public void mouseUp(MouseEvent e) { - if (DRAG_NONE != _dragState) { - setCapture(false); - if (DRAG_TRACE_ITEM == _dragState) { - // Notify time provider to check the need for listener - // notification - _timeProvider.notifyStartFinishTime(); - if (_dragX == _dragX0) { // click without drag - long time = hitTimeTest(e.x); - _timeProvider.setSelectedTimeInt(time, false); - selectItem(_hitIdx, false); - fireSelectionChanged(); - } - } else if (DRAG_GROUP_ITEM == _dragState) { - if (e.x == _dragX0) // click without drag - toggle(_hitIdx); - } else if (DRAG_SPLIT_LINE == _dragState) { - redraw(); - } - _dragState = DRAG_NONE; - } - } - - @Override - public void controlMoved(ControlEvent e) { - } - - @Override - public void controlResized(ControlEvent e) { - adjustScrolls(); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - } - - @Override - public void widgetSelected(SelectionEvent e) { - if (e.widget == getVerticalBar()) { - _topItem = getVerticalBar().getSelection(); - if (_topItem < 0) - _topItem = 0; - redraw(); - } else if (e.widget == getHorizontalBar() && null != _timeProvider) { - int start = getHorizontalBar().getSelection(); - long time0 = _timeProvider.getTime0(); - long time1 = _timeProvider.getTime1(); - long timeMin = _timeProvider.getMinTime(); - long timeMax = _timeProvider.getMaxTime(); - long delta = timeMax - timeMin; - - long range = time1 - time0; - // _timeRangeFixed = true; - time0 = timeMin + (long) (delta * ((double) start / H_SCROLLBAR_MAX)); - time1 = time0 + range; - - // TODO: Follow-up with Bug 310310 - // In Linux SWT.DRAG is the only value received - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310 - if (e.detail == SWT.DRAG) { - _timeProvider.setStartFinishTime(time0, time1); - } else { - _timeProvider.setStartFinishTimeNotify(time0, time1); - } - } - } - - @Override - public void mouseEnter(MouseEvent e) { - if (mouseScrollFilterListener == null) { - mouseScrollFilterListener = new Listener() { - // This filter is used to prevent scrolling of the view when the - // mouse wheel is used to zoom - @Override - public void handleEvent(Event event) { - event.doit = false; - } - }; - getDisplay().addFilter(SWT.MouseWheel, mouseScrollFilterListener); - } - } - - @Override - public void mouseExit(MouseEvent e) { - if (mouseScrollFilterListener != null) { - getDisplay().removeFilter(SWT.MouseWheel, mouseScrollFilterListener); - mouseScrollFilterListener = null; - } - if (_mouseHover) { - _mouseHover = false; - redraw(); - } - } - - @Override - public void mouseHover(MouseEvent e) { - } - - @Override - public void mouseScrolled(MouseEvent e) { - if ((mouseScrollFilterListener == null) || _dragState != DRAG_NONE) - return; - if (e.count > 0) { - zoom(true); - } else if (e.count < 0) { - zoom(false); - } - } - - public boolean isVisibleVerticalScroll() { - return _visibleVerticalScroll; - } - - public void setVisibleVerticalScroll(boolean visibleVerticalScroll) { - ScrollBar scrollVer = getVerticalBar(); - if (scrollVer != null) { - scrollVer.setVisible(visibleVerticalScroll); - } - this._visibleVerticalScroll = visibleVerticalScroll; - } - - @Override - public int getBorderWidth() { - return _borderWidth; - } - - public void setBorderWidth(int borderWidth) { - this._borderWidth = borderWidth; - } - - public int getHeaderHeight() { - return _headerHeight; - } - - public void setHeaderHeight(int headerHeight) { - this._headerHeight = headerHeight; - } - - public int getItemHeight() { - return _itemHeight; - } - - public void setItemHeight(int rowHeight) { - this._itemHeight = rowHeight; - } - - public void setMinimumItemWidth(int width) { - this._minimumItemWidth = width; - } - - public Vector getFilteredOut() { - return _data.getFilteredOut(); - } - - // @Override - @Override - public void addSelectionChangedListener(ISelectionChangedListener listener) { - if (listener != null) { - if (!_selectionChangedListeners.contains(listener)) { - _selectionChangedListeners.add(listener); - } - } - } - - // @Override - @Override - public void removeSelectionChangedListener(ISelectionChangedListener listener) { - if (listener != null) { - _selectionChangedListeners.remove(listener); - } - } - - // @Override - @Override - public void setSelection(ISelection selection) { - if (selection instanceof PlainSelection) { - PlainSelection sel = (PlainSelection) selection; - Object ob = sel.getFirstElement(); - if (ob instanceof ITmfTimeAnalysisEntry) { - ITmfTimeAnalysisEntry trace = (ITmfTimeAnalysisEntry) ob; - selectItem(trace, false); - } - } - - } -} - -class Item { - public boolean _expanded; - public boolean _selected; - public boolean _hasChildren; - public String _name; - - Item(String name) { - _name = name; - } - - @Override - public String toString() { - return _name; - } -} - -class TraceItem extends Item { - public ITmfTimeAnalysisEntry _trace; - - TraceItem(ITmfTimeAnalysisEntry trace, String name) { - super(name); - _trace = trace; - } -} - -class GroupItem extends Item { - public List _traces; - - GroupItem(String name) { - super(name); - _traces = new ArrayList(); - _hasChildren = true; - } - - void add(ITmfTimeAnalysisEntry trace) { - _traces.add(trace); - } -} - -class ItemData { - public Object[] _items = new Object[0]; - private Object _traces[] = new Object[0]; - private boolean traceFilter[] = new boolean[0]; - private Map _groupTable = new HashMap(); - private boolean _flatList = false; - private TmfTimeAnalysisProvider utilsImp; - private Vector filteredOut = new Vector(); - - public ItemData(TmfTimeAnalysisProvider utils) { - this.utilsImp = utils; - } - - protected void groupTraces(boolean on) { - if (_flatList == on) { - _flatList = !on; - updateItems(); - } - } - - void clearGroups() { - Iterator it = _groupTable.values().iterator(); - while (it.hasNext()) { - GroupItem group = it.next(); - group._traces.clear(); - } - } - - void deleteEmptyGroups() { - Iterator it = _groupTable.values().iterator(); - while (it.hasNext()) { - GroupItem group = it.next(); - if (group._traces.size() == 0) - it.remove(); - } - } - - TraceItem findTraceItem(ITmfTimeAnalysisEntry trace) { - if (trace == null) - return null; - - int traceId = trace.getId(); - TraceItem traceItem = null; - - for (int i = 0; i < _items.length; i++) { - Object item = _items[i]; - if (item instanceof TraceItem) { - TraceItem ti = (TraceItem) item; - if (ti._trace.getId() == traceId) { - traceItem = ti; - break; - } - } - } - - return traceItem; - } - - Integer findTraceItemIndex(ITmfTimeAnalysisEntry trace) { - if (trace == null) - return null; - - for (int i = 0; i < _items.length; i++) { - Object item = _items[i]; - if (item instanceof TraceItem) { - TraceItem ti = (TraceItem) item; - if (ti._trace == trace) { - return i; - } - } - } - - return null; - } - - public void updateItems() { - List itemList = new ArrayList(); - String name = ""; //$NON-NLS-1$ - - Iterator it = _groupTable.values().iterator(); - while (it.hasNext()) { - GroupItem group = it.next(); - if (!_flatList) - itemList.add(group); - - if (_flatList || group._expanded) { - Iterator it2 = group._traces.iterator(); - while (it2.hasNext()) { - ITmfTimeAnalysisEntry trace = it2.next(); - TraceItem traceItem = findTraceItem(trace); - name = utilsImp.composeTraceName(trace, false); - traceItem = new TraceItem(trace, name); - itemList.add(traceItem); - } - } - } - _items = itemList.toArray(); - } - - public int expandItem(int idx, boolean expand) { - if (idx < 0 || idx >= _items.length) - return 0; - int ret = 0; - Item item = (Item) _items[idx]; - if (item._hasChildren && !item._expanded) { - item._expanded = expand; - ret = _items.length; - updateItems(); - ret = _items.length - ret; - } - return ret; - } - - public void refreshData(Object traces[]) { - if (traces == null || traces.length == 0) { - traceFilter = null; - } else if (traceFilter == null || traces.length != traceFilter.length) { - traceFilter = new boolean[traces.length]; - java.util.Arrays.fill(traceFilter, true); - } - - _traces = traces; - refreshData(); - } - - /** - * Allows to update the GUI from a stream of events handling addition one by - * one over known TmfTaTrace parents. - * - * @param parent - * @param childItem - */ - public void refreshPartial(ITmfTimeAnalysisEntry parent, TimeEvent childItem) { - // Find the Trace item within the current list -// TraceItem item = findTraceItem(parent); - - // This method is not used (yet) so this code can be commented out for - // now - // FIXME: Arrays.copyOf is a Java6 feature - // if (item == null) { - // // If the parent item is not found, make room for it in the current - // // array - // int length = 1; - // Object[] traces; - // if (_traces != null) { - // length = _traces.length + 1; - // traces = Arrays.copyOf(_traces, length); - // } else { - // traces = new Object[length]; - // } - // - // // Add the new parent element to the end of the array. - // traces[length - 1] = parent; - // - // // update the filter array to accomodate a postion to the new - // // element - // traceFilter = new boolean[traces.length]; - // java.util.Arrays.fill(traceFilter, true); - // - // // rebuild internal data - // _traces = traces; - // refreshData(); - // - // // item must be there - // item = findTraceItem(parent); - // } - - /* - * Check if this is still needed! - ITmfTimeAnalysisEntry localTraceItem = item._trace; - // Local trace found - Vector children = localTraceItem.getTraceEvents(); - TimeEvent lastChildIn = children.lastElement(); - long lastChildSTime = lastChildIn.getTime(); - long newChildSTime = childItem.getTime(); - if (newChildSTime < lastChildSTime) { - // The children are expected to arrive sorted by time - // since the new time is earlier than the last child - // The infomation is being refreshed from start, remove all - // children and start over - children.clear(); - } - // Add the new item - children.add(childItem); - */ - - } - - public void refreshData() { - clearGroups(); - filteredOut.clear(); - String undef = Messages.TmfTimeStatesCtrl_UNDEFINED_GROUP; - List groupList = new ArrayList(); - for (int i = 0; i < _traces.length; i++) { - ITmfTimeAnalysisEntry trace = (ITmfTimeAnalysisEntry) _traces[i]; - if (!traceFilter[i]) { - filteredOut.add(trace); - continue; - } - - String groupName = trace.getGroupName(); - if (null == groupName) - groupName = undef; - - GroupItem group = _groupTable.get(groupName); - if (null == group) { - group = new GroupItem(NLS.bind(Messages.TmfTimeStatesCtrl_TRACE_GROUP_LABEL, groupName)); - group._expanded = !groupName.equalsIgnoreCase("system") && !groupName.equalsIgnoreCase(undef); //$NON-NLS-1$ - _groupTable.put(groupName, group); - groupList.add(group); - } - group.add(trace); - } - - deleteEmptyGroups(); - updateItems(); - } - - public Object[] getTraces() { - return _traces; - } - - public boolean[] getTraceFilter() { - return traceFilter; - } - - public Vector getFilteredOut() { - return filteredOut; - } -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TmfTimeTipHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TmfTimeTipHandler.java deleted file mode 100644 index 80c95c108d..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TmfTimeTipHandler.java +++ /dev/null @@ -1,245 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2007, Intel Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Intel Corporation - Initial API and implementation - * Vitaly A. Provodin, Intel - Initial API and implementation - * Alvaro Sanchex-Leon - Udpated for TMF - * - * $Id: ThreadsTipHandler.java,v 1.5 2007/06/06 19:16:16 gnagarajan Exp $ - *****************************************************************************/ -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; - -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeAnalysisViewer.TimeFormat; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseTrackAdapter; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Widget; - - -public class TmfTimeTipHandler { - - private Shell _tipShell; - private Table _tipTable; - private Item _tipItem; - private Point _tipPosition; - private ITimeDataProvider _timeDataProvider; - TmfTimeAnalysisProvider _utilImp = null; - - public TmfTimeTipHandler(Shell parent, TmfTimeAnalysisProvider rUtilImpl, - ITimeDataProvider timeProv) { - final Display display = parent.getDisplay(); - - this._utilImp = rUtilImpl; - this._timeDataProvider = timeProv; - _tipShell = new Shell(parent, SWT.ON_TOP | SWT.TOOL); - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - gridLayout.marginWidth = 2; - gridLayout.marginHeight = 2; - _tipShell.setLayout(gridLayout); - GridData data = new GridData(GridData.BEGINNING, GridData.BEGINNING, - true, true); - _tipShell.setLayoutData(data); - _tipShell.setBackground(display - .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - - _tipTable = new Table(_tipShell, SWT.NONE); - _tipTable.setForeground(display - .getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - _tipTable.setBackground(display - .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - _tipTable.setHeaderVisible(false); - _tipTable.setLinesVisible(false); - - // tipTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL - // | GridData.VERTICAL_ALIGN_CENTER)); - } - - public void activateHoverHelp(final Control control) { - control.addMouseListener(new MouseAdapter() { - @Override - public void mouseDown(MouseEvent e) { - if (_tipShell.isVisible()) - _tipShell.setVisible(false); - } - }); - - control.addMouseTrackListener(new MouseTrackAdapter() { - @Override - public void mouseExit(MouseEvent e) { - if (_tipShell.isVisible()) - _tipShell.setVisible(false); - _tipItem = null; - - } - - private void addItem(String name, String value) { - TableItem line = new TableItem(_tipTable, SWT.NONE); - line.setText(0, name); - line.setText(1, value); - } - - private void fillValues(Point pt, TmfTimeStatesCtrl threadStates, - Item item) { - if (item instanceof TraceItem) { - ITmfTimeAnalysisEntry thrd = ((TraceItem) item)._trace; - ITimeEvent threadEvent = Utils.findEvent(thrd, threadStates.hitTimeTest(pt.x), 2); - ITimeEvent nextEvent = Utils.findEvent(thrd, threadStates.hitTimeTest(pt.x), 1); - // thread name - addItem(Messages.TmfTimeTipHandler_TRACE_NAME, thrd.getName()); - // class name - String traceClass = _utilImp.getTraceClassName(thrd); - if (traceClass != null) { - addItem(Messages.TmfTimeTipHandler_TRACE_CLASS_NAME, traceClass); - } - // thread state - String state = _utilImp.getEventName(threadEvent); - if (state != null) { - addItem(Messages.TmfTimeTipHandler_TRACE_STATE, state); - } - - // This block receives a - // list of values to be added to the tip - // table - Map eventAddOns = _utilImp.getEventHoverToolTipInfo(threadEvent); - if (eventAddOns != null) { - for (Iterator iter = eventAddOns.keySet().iterator(); iter.hasNext();) { - String message = (String) iter.next(); - addItem(message, eventAddOns.get(message)); - } - } - - long eventStartTime = -1; - long eventDuration = -1; - long eventEndTime = -1; - - if (threadEvent != null) { - eventStartTime = threadEvent.getTime(); - eventDuration = threadEvent.getDuration(); - if (eventDuration < 0 && nextEvent != null) { - eventEndTime = nextEvent.getTime(); - eventDuration = eventEndTime - eventStartTime; - } else { - eventEndTime = eventStartTime + eventDuration; - } - } - -// TODO: Check if we need "format" -// TimeFormat format = TimeFormat.RELATIVE; - Resolution res = Resolution.NANOSEC; - if (_timeDataProvider.isCalendarFormat()) { -// format = TimeFormat.ABSOLUTE; // Absolute format -// // (calendar) - // Add Date - addItem(Messages.TmfTimeTipHandler_TRACE_DATE, eventStartTime > -1 ? - Utils.formatDate(eventStartTime) - : "?"); //$NON-NLS-1$ - if (eventDuration > 0) { - addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ? - Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res) - : "?"); //$NON-NLS-1$ - - addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ? - Utils.formatTime(eventEndTime, TimeFormat.ABSOLUTE, res) - : "?"); //$NON-NLS-1$ - } else { - addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ? - Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res) - : "?"); //$NON-NLS-1$ - } - } else { - if (eventDuration > 0) { - addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ? - Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res) - : "?"); //$NON-NLS-1$ - - addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ? - Utils.formatTime(eventEndTime, TimeFormat.RELATIVE, res) - : "?"); //$NON-NLS-1$ - } else { - addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ? - Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res) - : "?"); //$NON-NLS-1$ - } - } - - if (eventDuration > 0) { - // Duration in relative format in any case - addItem(Messages.TmfTimeTipHandler_DURATION, eventDuration > -1 ? - Utils.formatTime(eventDuration, TimeFormat.RELATIVE, res) - : "?"); //$NON-NLS-1$ - } - - } else if (item instanceof GroupItem) { - addItem(Messages.TmfTimeTipHandler_TRACE_GROUP_NAME, item.toString()); - addItem(Messages.TmfTimeTipHandler_NUMBER_OF_TRACES, "" + ((GroupItem) item)._traces.size()); //$NON-NLS-1$ - } - } - - @Override - public void mouseHover(MouseEvent event) { - Point pt = new Point(event.x, event.y); - Widget widget = event.widget; - Item item = null; - if (widget instanceof TmfTimeStatesCtrl) { - TmfTimeStatesCtrl threadStates = (TmfTimeStatesCtrl) widget; - item = (Item) threadStates.getItem(pt); - _tipTable.remove(0, _tipTable.getItemCount() - 1); - new TableColumn(_tipTable, SWT.NONE); - new TableColumn(_tipTable, SWT.NONE); - fillValues(pt, threadStates, item); - _tipTable.getColumn(0).setWidth(200); - _tipTable.getColumn(1).pack(); - _tipTable.setSize(_tipTable.computeSize(SWT.DEFAULT, 200)); - _tipShell.pack(); - } else if (widget == null) { - _tipShell.setVisible(false); - _tipItem = null; - return; - } - if (item == _tipItem) - return; - _tipItem = item; - _tipPosition = control.toDisplay(pt); - _tipShell.pack(); - setHoverLocation(_tipShell, _tipPosition); - _tipShell.setVisible(true); - } - }); - } - - private void setHoverLocation(Shell shell, Point position) { - Rectangle displayBounds = shell.getDisplay().getBounds(); - Rectangle shellBounds = shell.getBounds(); - shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - - shellBounds.width), 0); - shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height - - shellBounds.height), 0); - shell.setBounds(shellBounds); - } - -} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TraceColorScheme.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TraceColorScheme.java deleted file mode 100644 index e4e62440ad..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TraceColorScheme.java +++ /dev/null @@ -1,381 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2008 Intel Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Intel Corporation - Initial API and implementation - * Ruslan A. Scherbakov, Intel - Initial API and implementation - * Alvaro Sanchex-Leon - Udpated for TMF - * - * $Id: TraceColorScheme.java,v 1.3 2008/05/09 16:11:24 jkubasta Exp $ - *****************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; - -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider.StateColor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; - - -public class TraceColorScheme { - - // elements color indices - static public final int BLACK_STATE = 0; - static public final int GREEN_STATE = 1; - static public final int DARK_BLUE_STATE = 2; - static public final int ORANGE_STATE = 3; - static public final int GOLD_STATE = 4; - static public final int RED_STATE = 5; - static public final int GRAY_STATE = 6; - static public final int DARK_GREEN_STATE = 7; - static public final int DARK_YELLOW_STATE = 8; - static public final int MAGENTA3_STATE = 9; - static public final int PURPLE1_STATE = 10; - static public final int PINK1_STATE = 11; - static public final int AQUAMARINE_STATE = 12; - static public final int LIGHT_BLUE_STATE = 13; - static public final int CADET_BLUE_STATE = 14; - static public final int OLIVE_STATE = 15; - - static public final int STATES0 = 0; - static public final int STATES1 = 15; - - // State element index to name mapping, must keep the same order as above - public static final StateColor stateColors[] = { StateColor.BLACK, - StateColor.GREEN, StateColor.DARK_BLUE, StateColor.ORANGE, - StateColor.GOLD, StateColor.RED, StateColor.GRAY, StateColor.DARK_GREEN, StateColor.DARK_YELLOW, StateColor.MAGENTA3, StateColor.PURPLE1, - StateColor.PINK1, StateColor.AQUAMARINE, StateColor.LIGHT_BLUE, StateColor.CADET_BLUE, StateColor.OLIVE - }; - - // selected state elements color indices - static public final int BLACK_STATE_SEL = 16; - static public final int GREEN_STATE_SEL = 17; - static public final int DARK_BLUE_STATE_SEL = 18; - static public final int ORANGE_STATE_SEL = 19; - static public final int GOLD_STATE_SEL = 20; - static public final int RED_STATE_SEL = 21; - static public final int GRAY_STATE_SEL = 22; - static public final int DARK_GREEN_STATE_SEL = 23; - static public final int DARK_YELLOW_STATE_SEL = 24; - static public final int MAGENTA3_STATE_SEL = 25; - static public final int PURPLE1_STATE_SEL = 26; - static public final int PINK1_STATE_SEL = 27; - static public final int AQUAMARINE_STATE_SEL = 28; - static public final int LIGHT_BLUE_STATE_SEL = 29; - static public final int CADET_BLUE_STATE_SEL = 30; - static public final int OLIVE_STATE_SEL = 31; - - static public final int STATES_SEL0 = 16; - static public final int STATES_SEL1 = 31; - - // colors indices for viewer controls - static public final int BACKGROUND = 32; - static public final int FOREGROUND = 33; - static public final int BACKGROUND_SEL = 34; - static public final int FOREGROUND_SEL = 35; - static public final int BACKGROUND_SEL_NOFOCUS = 36; - static public final int FOREGROUND_SEL_NOFOCUS = 37; - static public final int TOOL_BACKGROUND = 38; - static public final int TOOL_FOREGROUND = 39; - - // misc colors - static public final int FIX_COLOR = 40; - static public final int WHITE = 41; - static public final int GRAY = 42; - static public final int BLACK = 43; - static public final int DARK_GRAY = 44; - - // selected border color indices - static public final int BLACK_BORDER = 45; - static public final int GREEN_BORDER = 46; - static public final int DARK_BLUE_BORDER = 47; - static public final int ORANGE_BORDER = 48; - static public final int GOLD_BORDER = 49; - static public final int RED_BORDER = 50; - static public final int GRAY_BORDER = 51; - static public final int DARK_GREEN_BORDER1 = 52; - static public final int DARK_YELLOW_BORDER1 = 53; - static public final int MAGENTA3_BORDER1 = 54; - static public final int PURPLE1_BORDER1 = 55; - static public final int PINK1_BORDER1 = 56; - static public final int AQUAMARINE_BORDER1 = 57; - static public final int LIGHT_BLUE_BORDER1 = 58; - static public final int CADET_BLUE_STATE_BORDER = 59; - static public final int OLIVE_BORDER2 = 60; - - static public final int STATES_BORDER0 = 45; - static public final int STATES_BORDER1 = 60; - - static public final int MID_LINE = 61; - static public final int RED = 62; - static public final int GREEN = 63; - static public final int BLUE = 64; - static public final int YELLOW = 65; - static public final int CYAN = 66; - static public final int MAGENTA = 67; - - static public final int SELECTED_TIME = 68; - static public final int LEGEND_BACKGROUND = 69; - static public final int LEGEND_FOREGROUND = 70; - - // group items' colors - static public final int GR_BACKGROUND = 71; - static public final int GR_FOREGROUND = 72; - static public final int GR_BACKGROUND_SEL = 73; - static public final int GR_FOREGROUND_SEL = 74; - static public final int GR_BACKGROUND_SEL_NOFOCUS = 75; - static public final int GR_FOREGROUND_SEL_NOFOCUS = 76; - - static public final int LIGHT_LINE = 77; - static public final int BACKGROUND_NAME = 78; - static public final int BACKGROUND_NAME_SEL = 79; - static public final int BACKGROUND_NAME_SEL_NOFOCUS = 80; - - // Interraction's colors - static public final int TI_START_THREAD = BLACK; - static public final int TI_HANDOFF_LOCK = BLUE; - static public final int TI_NOTIFY_ALL = GREEN; - static public final int TI_NOTIFY = GREEN; - static public final int TI_NOTIFY_JOINED = DARK_GRAY; - static public final int TI_INTERRUPT = RED; - static public final int TI_WAIT_EXCEEDED = BLUE; - - static interface IColorProvider { - public Color get(); - } - - static class SysCol implements IColorProvider { - int syscol; - - SysCol(int syscol) { - this.syscol = syscol; - } - - @Override - public Color get() { - return Utils.getSysColor(syscol); - } - } - - static class RGB implements IColorProvider { - int r; - int g; - int b; - - RGB(int r, int g, int b) { - this.r = r; - this.g = g; - this.b = b; - } - - @Override - public Color get() { - return new Color(null, r, g, b); - } - } - - static class Mix implements IColorProvider { - IColorProvider cp1; - IColorProvider cp2; - int w1; - int w2; - - Mix(IColorProvider cp1, IColorProvider cp2, int w1, int w2) { - this.cp1 = cp1; - this.cp2 = cp2; - this.w1 = w1; - this.w2 = w2; - } - - Mix(IColorProvider cp1, IColorProvider cp2) { - this.cp1 = cp1; - this.cp2 = cp2; - this.w1 = 1; - this.w2 = 1; - } - - @Override - public Color get() { - Color col1 = cp1.get(); - Color col2 = cp2.get(); - Color col = Utils.mixColors(col1, col2, w1, w2); - return col; - } - } - - static private final IColorProvider _providersMap[] = { - // - new RGB(100, 100, 100), // UNKNOWN - new RGB(174, 200, 124), // RUNNING - new Mix(new SysCol(SWT.COLOR_BLUE), new SysCol(SWT.COLOR_GRAY), 1, 3), // SLEEPING - new RGB(210, 150, 60), // WAITING - new RGB(242, 225, 168), // BLOCKED - new Mix(new SysCol(SWT.COLOR_RED), new SysCol(SWT.COLOR_GRAY), 1, 3), // DEADLOCK - new RGB(200, 200, 200), // STOPPED - new RGB(35, 107, 42), // STEEL BLUE - new RGB(205,205,0), // DARK YELLOW - new RGB(205, 0, 205), // MAGENTA - new RGB(171, 130, 255), // PURPLE - new RGB(255, 181, 197), // PINK - new RGB(112, 219, 147), // AQUAMARINE - new RGB(198, 226, 255), // SLATEGRAY - new RGB(95, 158, 160), // CADET BLUE - new RGB(107, 142, 35), // OLIVE - - - //TODO: Does not seem to be used, check during clean-up - new SysCol(SWT.COLOR_WHITE), // UNKNOWN_SEL - new SysCol(SWT.COLOR_GREEN), // RUNNING_SEL - new SysCol(SWT.COLOR_BLUE), // SLEEPING_SEL - new SysCol(SWT.COLOR_CYAN), // WAITING_SEL - new SysCol(SWT.COLOR_YELLOW), // BLOCKED_SEL - new SysCol(SWT.COLOR_RED), // DEADLOCK_SEL - new SysCol(SWT.COLOR_DARK_GRAY), // STOPPED_SEL - new SysCol(SWT.COLOR_WHITE), - new SysCol(SWT.COLOR_GREEN), - new SysCol(SWT.COLOR_BLUE), - new SysCol(SWT.COLOR_CYAN), - new SysCol(SWT.COLOR_YELLOW), - new SysCol(SWT.COLOR_RED), - new SysCol(SWT.COLOR_DARK_GRAY), - new SysCol(SWT.COLOR_WHITE), - new SysCol(SWT.COLOR_GREEN), - - - new SysCol(SWT.COLOR_LIST_BACKGROUND), // BACKGROUND - new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND - new RGB(232, 242, 254), // BACKGROUND_SEL - new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND_SEL - new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // BACKGROUND_SEL_NOFOCUS - new SysCol(SWT.COLOR_WIDGET_FOREGROUND), // FOREGROUND_SEL_NOFOCUS - new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // TOOL_BACKGROUND - new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // TOOL_FOREGROUND - - new SysCol(SWT.COLOR_GRAY), // FIX_COLOR - new SysCol(SWT.COLOR_WHITE), // WHITE - new SysCol(SWT.COLOR_GRAY), // GRAY - new SysCol(SWT.COLOR_BLACK), // BLACK - new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GRAY - - new SysCol(SWT.COLOR_DARK_GRAY), // BLACK_BORDER - new RGB(75, 115, 120), // GREEN_BORDER - new SysCol(SWT.COLOR_DARK_BLUE), // DARK_BLUE_BORDER - new RGB(242, 225, 168), // ORANGE_BORDER - new RGB(210, 150, 60), // GOLD_BORDER - new SysCol(SWT.COLOR_DARK_RED), // RED_BORDER - new SysCol(SWT.COLOR_BLACK), // GRAY_BORDER - new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GREEN_BORDER - new RGB(75, 115, 120), // DARK_YELLOW_BORDER - new SysCol(SWT.COLOR_DARK_BLUE), // MAGENTA3_BORDER - new RGB(242, 225, 168), // PURPLE1_BORDER - new RGB(210, 150, 60), // PINK1_BORDER - new SysCol(SWT.COLOR_DARK_RED), // AQUAMARINE_BORDER - new SysCol(SWT.COLOR_BLACK), // LIGHT_BLUE_BORDER - new SysCol(SWT.COLOR_DARK_GRAY), // BLUE_BORDER - new RGB(75, 115, 120), // OLIVE_BORDER - - - new SysCol(SWT.COLOR_GRAY), // MID_LINE - new SysCol(SWT.COLOR_RED), // RED - new SysCol(SWT.COLOR_GREEN), // GREEN - new SysCol(SWT.COLOR_BLUE), // BLUE - new SysCol(SWT.COLOR_YELLOW), // YELLOW - new SysCol(SWT.COLOR_CYAN), // CYAN - new SysCol(SWT.COLOR_MAGENTA), // MAGENTA - - new SysCol(SWT.COLOR_BLUE), // SELECTED_TIME - new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // LEGEND_BACKGROUND - new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // LEGEND_FOREGROUND - - new Mix(new RGB(150, 200, 240), new SysCol( - SWT.COLOR_LIST_BACKGROUND)),// GR_BACKGROUND - new RGB(0, 0, 50), // GR_FOREGROUND - new Mix(new RGB(200, 200, 100), - new SysCol(SWT.COLOR_LIST_SELECTION)), // GR_BACKGROUND_SEL - new Mix(new RGB(150, 200, 240), new SysCol( - SWT.COLOR_LIST_SELECTION_TEXT)), // GR_FOREGROUND_SEL - new Mix(new RGB(222, 222, 155), new SysCol( - SWT.COLOR_WIDGET_BACKGROUND)), // GR_BACKGROUND_SEL_NOFOCUS - new RGB(0, 0, 50), // GR_FOREGROUND_SEL_NOFOCUS - - new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol( - SWT.COLOR_LIST_BACKGROUND), 1, 3), // LIGHT_LINE - - new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 6), // BACKGROUND_NAME - new Mix(new SysCol(SWT.COLOR_GRAY), new RGB(232, 242, 254), 1, 6), // BACKGROUND_NAME_SEL - new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_WIDGET_BACKGROUND), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS - }; - - private Color _colors[]; - - public TraceColorScheme() { - _colors = new Color[_providersMap.length]; - } - - public void dispose() { - for (int i = 0; i < _colors.length; i++) { - Utils.dispose(_colors[i]); - _colors[i] = null; - } - } - - public Color getColor(int idx) { - if (null == _colors[idx]) { - if (idx >= STATES_SEL0 && idx <= STATES_SEL1) { - Color col1 = getColor(idx - STATES_SEL0); - Color col2 = getColor(BACKGROUND_SEL); - _colors[idx] = Utils.mixColors(col1, col2, 3, 1); - } else { - _colors[idx] = _providersMap[idx].get(); - } - } - return _colors[idx]; - } - - public Color getBkColor(boolean selected, boolean focused, boolean name) { - if (name) { - if (selected && focused) - return getColor(BACKGROUND_NAME_SEL); - if (selected) - return getColor(BACKGROUND_NAME_SEL_NOFOCUS); - return getColor(BACKGROUND_NAME); - } else { - if (selected && focused) - return getColor(BACKGROUND_SEL); - if (selected) - return getColor(BACKGROUND_SEL_NOFOCUS); - return getColor(BACKGROUND); - } - } - - public Color getFgColor(boolean selected, boolean focused) { - if (selected && focused) - return getColor(FOREGROUND_SEL); - if (selected) - return getColor(FOREGROUND_SEL_NOFOCUS); - return getColor(FOREGROUND); - } - - public Color getBkColorGroup(boolean selected, boolean focused) { - if (selected && focused) - return getColor(GR_BACKGROUND_SEL); - if (selected) - return getColor(GR_BACKGROUND_SEL_NOFOCUS); - return getColor(GR_BACKGROUND); - } - - public Color getFgColorGroup(boolean selected, boolean focused) { - if (selected && focused) - return getColor(GR_FOREGROUND_SEL); - if (selected) - return getColor(GR_FOREGROUND_SEL_NOFOCUS); - return getColor(GR_FOREGROUND); - } - - public static StateColor[] getStateColors() { - return stateColors; - } -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TraceCtrl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TraceCtrl.java deleted file mode 100644 index 85e16aad21..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TraceCtrl.java +++ /dev/null @@ -1,68 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2007, Intel Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Intel Corporation - Initial API and implementation - * Ruslan A. Scherbakov, Intel - Initial API and implementation - * Alvaro Sanchex-Leon - Udpated for TMF - * - * $Id: TraceCtrl.java,v 1.2 2007/02/27 18:37:36 ewchan Exp $ - *****************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Canvas; -import org.eclipse.swt.widgets.Composite; - -public abstract class TraceCtrl extends Canvas implements PaintListener { - - static public final int MARGIN = 4; - static public final int RIGHT_MARGIN = 2; // 2 pixels less to make sure end time is visible - static public final int SMALL_ICON_SIZE = 16; - - protected TraceColorScheme _colors; - protected int _fontHeight = 0; - - public TraceCtrl(Composite parent, TraceColorScheme colors) { - this(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS); - } - - public TraceCtrl(Composite parent, TraceColorScheme colors, int style) { - super(parent, style); - _colors = colors; - addPaintListener(this); - } - - @Override - public void dispose() { - super.dispose(); - } - - @Override - public void paintControl(PaintEvent e) { - if (e.widget != this) - return; - _fontHeight = e.gc.getFontMetrics().getHeight(); - Rectangle bound = getClientArea(); - if (!bound.isEmpty()) { - Color colBackup = e.gc.getBackground(); - paint(bound, e); - e.gc.setBackground(colBackup); - } - } - - public int getFontHeight() { - return _fontHeight; - } - - abstract void paint(Rectangle bound, PaintEvent e); -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java index 7f2b41fe60..e50cf37394 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java @@ -1,16 +1,16 @@ /***************************************************************************** - * Copyright (c) 2007, 2008 Intel Corporation and others. + * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2012 Ericsson. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Intel Corporation - Initial API and implementation - * Ruslan A. Scherbakov, Intel - Initial API and implementation - * Alvaro Sanchex-Leon - Udpated for TMF + * Intel Corporation - Initial API and implementation + * Ruslan A. Scherbakov, Intel - Initial API and implementation + * Alvaro Sanchez-Leon - Udpated for TMF + * Patrick Tasse - Refactoring * - * $Id: Utils.java,v 1.11 2008/06/16 21:04:49 jkubasta Exp $ *****************************************************************************/ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; @@ -20,9 +20,8 @@ import java.util.Date; import java.util.Iterator; import java.util.TimeZone; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeAnalysisViewer.TimeFormat; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Device; import org.eclipse.swt.graphics.GC; @@ -32,316 +31,295 @@ import org.eclipse.swt.widgets.Display; public class Utils { - static public final int IMG_THREAD_RUNNING = 0; - static public final int IMG_THREAD_SUSPENDED = 1; - static public final int IMG_THREAD_STOPPED = 2; - static public final int IMG_METHOD_RUNNING = 3; - static public final int IMG_METHOD = 4; - static public final int IMG_NUM = 5; + public enum TimeFormat { + RELATIVE, ABSOLUTE + }; - static public final Object[] _empty = new Object[0]; + static public final int IMG_THREAD_RUNNING = 0; + static public final int IMG_THREAD_SUSPENDED = 1; + static public final int IMG_THREAD_STOPPED = 2; + static public final int IMG_METHOD_RUNNING = 3; + static public final int IMG_METHOD = 4; + static public final int IMG_NUM = 5; - static enum Resolution { - SECONDS, MILLISEC, MICROSEC, NANOSEC - }; + static public final Object[] _empty = new Object[0]; - static private final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$ - static private final SimpleDateFormat sdateformat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$ - static { + static enum Resolution { + SECONDS, MILLISEC, MICROSEC, NANOSEC + }; + + static private final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$ + static private final SimpleDateFormat sdateformat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$ + static { stimeformat.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$ sdateformat.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$ - } - -// static private String _externalPlugin[] = { "org.eclipse.debug.ui", -// "org.eclipse.debug.ui", "org.eclipse.debug.ui", -// "org.eclipse.debug.ui", "org.eclipse.debug.ui", }; -// -// static private String _externalPath[] = { -// "icons/full/obj16/thread_obj.gif", // running thread -// "icons/full/obj16/threads_obj.gif", // suspended -// "icons/full/obj16/threadt_obj.gif", // stopped -// "icons/full/obj16/stckframe_running_obj.gif", // running stack frame -// "icons/full/obj16/stckframe_obj.gif", // stack frame -// }; - -// static public Image getImage(int idx) { -// if (idx < 0 || idx >= IMG_NUM) -// SWT.error(SWT.ERROR_INVALID_ARGUMENT); -// String key = "trace.img." + idx; -// Image img = TimeAnalysisPlugin.getDefault().getImageRegistry().get(key); -// if (null == img) { -// ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin( -// _externalPlugin[idx], _externalPath[idx]); -// TimeAnalysisPlugin.getDefault().getImageRegistry().put(key, desc); -// img = TimeAnalysisPlugin.getDefault().getImageRegistry().get(key); -// } -// return img; -// } - - static public void init(Rectangle rect) { - rect.x = 0; - rect.y = 0; - rect.width = 0; - rect.height = 0; - } - - static public void init(Rectangle rect, int x, int y, int width, int height) { - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - } - - static public void init(Rectangle rect, Rectangle source) { - rect.x = source.x; - rect.y = source.y; - rect.width = source.width; - rect.height = source.height; - } - - static public void deflate(Rectangle rect, int x, int y) { - rect.x += x; - rect.y += y; - rect.width -= x + x; - rect.height -= y + y; - } - - static public void inflate(Rectangle rect, int x, int y) { - rect.x -= x; - rect.y -= y; - rect.width += x + x; - rect.height += y + y; - } - - static void dispose(Color col) { - if (null != col) - col.dispose(); - } - - static public Color mixColors(Device display, Color c1, Color c2, int w1, - int w2) { - return new Color(display, (w1 * c1.getRed() + w2 * c2.getRed()) - / (w1 + w2), (w1 * c1.getGreen() + w2 * c2.getGreen()) - / (w1 + w2), (w1 * c1.getBlue() + w2 * c2.getBlue()) - / (w1 + w2)); - } - - static public Color getSysColor(int id) { - Color col = Display.getCurrent().getSystemColor(id); - return new Color(col.getDevice(), col.getRGB()); - } - - static public Color mixColors(Color col1, Color col2, int w1, int w2) { - return mixColors(Display.getCurrent(), col1, col2, w1, w2); - } - - static public int drawText(GC gc, String text, Rectangle rect, - boolean transp) { - Point size = gc.stringExtent(text); - gc.drawText(text, rect.x, rect.y, transp); - return size.x; - } - - static public int drawText(GC gc, String text, int x, int y, boolean transp) { - Point size = gc.stringExtent(text); - gc.drawText(text, x, y, transp); - return size.x; - } - - /** + } + + static Rectangle clone(Rectangle source) { + return new Rectangle(source.x, source.y, source.width, source.height); + } + + static public void init(Rectangle rect) { + rect.x = 0; + rect.y = 0; + rect.width = 0; + rect.height = 0; + } + + static public void init(Rectangle rect, int x, int y, int width, int height) { + rect.x = x; + rect.y = y; + rect.width = width; + rect.height = height; + } + + static public void init(Rectangle rect, Rectangle source) { + rect.x = source.x; + rect.y = source.y; + rect.width = source.width; + rect.height = source.height; + } + + static public void deflate(Rectangle rect, int x, int y) { + rect.x += x; + rect.y += y; + rect.width -= x + x; + rect.height -= y + y; + } + + static public void inflate(Rectangle rect, int x, int y) { + rect.x -= x; + rect.y -= y; + rect.width += x + x; + rect.height += y + y; + } + + static void dispose(Color col) { + if (null != col) + col.dispose(); + } + + static public Color mixColors(Device display, Color c1, Color c2, int w1, + int w2) { + return new Color(display, (w1 * c1.getRed() + w2 * c2.getRed()) + / (w1 + w2), (w1 * c1.getGreen() + w2 * c2.getGreen()) + / (w1 + w2), (w1 * c1.getBlue() + w2 * c2.getBlue()) + / (w1 + w2)); + } + + static public Color getSysColor(int id) { + Color col = Display.getCurrent().getSystemColor(id); + return new Color(col.getDevice(), col.getRGB()); + } + + static public Color mixColors(Color col1, Color col2, int w1, int w2) { + return mixColors(Display.getCurrent(), col1, col2, w1, w2); + } + + static public int drawText(GC gc, String text, Rectangle rect, boolean transp) { + Point size = gc.stringExtent(text); + gc.drawText(text, rect.x, rect.y, transp); + return size.x; + } + + static public int drawText(GC gc, String text, int x, int y, boolean transp) { + Point size = gc.stringExtent(text); + gc.drawText(text, x, y, transp); + return size.x; + } + + /** * Formats time in format: MM:SS:NNN * - * @param time time - * @param format 0: MMMM:ss:nnnnnnnnn, 1: HH:MM:ss MMM.mmmm.nnn - * @param resolution the resolution - * @return the formatted time - */ - static public String formatTime(long time, TimeFormat format, Resolution resolution) { - // if format is absolute (Calendar) - if (format == TimeFormat.ABSOLUTE) { - return formatTimeAbs(time, resolution); - } - - StringBuffer str = new StringBuffer(); - boolean neg = time < 0; - if (neg) { - time = -time; - str.append('-'); - } - - long sec = (long) (time * 1E-9); - // TODO: Expand to make it possible to select the minute, second, nanosecond format - //printing minutes is suppressed just sec and ns - // if (sec / 60 < 10) - // str.append('0'); - // str.append(sec / 60); - // str.append(':'); - // sec %= 60; - // if (sec < 10) - // str.append('0'); - str.append(sec); - String ns = formatNs(time, resolution); - if (!ns.equals("")) { //$NON-NLS-1$ - str.append(':'); - str.append(ns); - } - - return str.toString(); - } - - /** - * From input time in nanoseconds, convert to Date format YYYY-MM-dd - * - * @param absTime - * @return the formatted date - */ - public static String formatDate(long absTime) { - String sdate = sdateformat.format(new Date((long) (absTime * 1E-6))); - return sdate; - } - - /** - * Formats time in ns to Calendar format: HH:MM:SS MMM.mmm.nnn - * - * @param time - * @return the formatted time - */ - static public String formatTimeAbs(long time, Resolution res) { - StringBuffer str = new StringBuffer(); - - // format time from nanoseconds to calendar time HH:MM:SS - String stime = stimeformat.format(new Date((long) (time * 1E-6))); - str.append(stime + " "); //$NON-NLS-1$ - // append the Milliseconds, MicroSeconds and NanoSeconds as specified in - // the Resolution - str.append(formatNs(time, res)); - return str.toString(); - } - - /** - * Obtains the remainder fraction on unit Seconds of the entered value in - * nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction - * seconds can be obtained by removing the last 9 digits: 1241207054 the - * fractional portion of seconds, expressed in ns is: 171080214 - * - * @param time - * @param res - * @return the formatted nanosec - */ - public static String formatNs(long time, Resolution res) { - StringBuffer temp = new StringBuffer(); - boolean neg = time < 0; - if (neg) { - time = -time; - } - - // The following approach could be used although performance - // decreases in half. - // String strVal = String.format("%09d", time); - // String tmp = strVal.substring(strVal.length() - 9); - - // number of segments to be included - int segments = 0; - switch (res) { - case MILLISEC: - segments = 1; - break; - case MICROSEC: - segments = 2; - break; - case NANOSEC: - segments = 3; - break; - default: - break; - } - - long ns = time; - ns %= 1000000000; - if (ns < 10) { - temp.append("00000000"); //$NON-NLS-1$ - } else if (ns < 100) { - temp.append("0000000"); //$NON-NLS-1$ - } else if (ns < 1000) { - temp.append("000000"); //$NON-NLS-1$ - } else if (ns < 10000) { - temp.append("00000"); //$NON-NLS-1$ - } else if (ns < 100000) { - temp.append("0000"); //$NON-NLS-1$ - } else if (ns < 1000000) { - temp.append("000"); //$NON-NLS-1$ - } else if (ns < 10000000) { - temp.append("00"); //$NON-NLS-1$ - } else if (ns < 100000000) { - temp.append("0"); //$NON-NLS-1$ - } - temp.append(ns); - - StringBuffer str = new StringBuffer(); - if (segments > 0) { - // append ms - str.append(temp.substring(0, 3)); - } - if (segments > 1) { - // append Micro secs - str.append("."); //$NON-NLS-1$ - str.append(temp.substring(3, 6)); - } - if (segments > 2) { - // append Nano seconds - str.append("."); //$NON-NLS-1$ - str.append(temp.substring(6)); - } - - return str.toString(); - } - - static public int loadIntOption(String opt, int def, int min, int max) { - // int val = - // TraceUIPlugin.getDefault().getPreferenceStore().getInt(opt); - // if (0 == val) - // val = def; - // if (val < min) - // val = min; - // if (val > max) - // val = max; - return def; - } - - // static public int loadIntOption(String opt) { - // int val = TraceUIPlugin.getDefault().getPreferenceStore().getInt(opt); - // return val; - // } - - static public void saveIntOption(String opt, int val) { - // TraceUIPlugin.getDefault().getPreferenceStore().setValue(opt, val); - } - - static ITimeEvent getFirstEvent(ITmfTimeAnalysisEntry thread) { - if (null == thread) - return null; - Iterator iterator = thread.getTraceEventsIterator(); - if (iterator.hasNext()) { - return iterator.next(); - } else { - return null; - } - } - - /** - * N means:
  • -1: Previous Event
  • 0: Current Event
  • - * 1: Next Event
  • 2: Previous Event when located in a non Event Area - * - * - * @param thread - * @param time - * @param n - * @return - */ - static ITimeEvent findEvent(ITmfTimeAnalysisEntry thread, long time, int n) { + * @param time time + * @param format 0: MMMM:ss:nnnnnnnnn, 1: HH:MM:ss MMM.mmmm.nnn + * @param resolution the resolution + * @return the formatted time + */ + static public String formatTime(long time, TimeFormat format, Resolution resolution) { + // if format is absolute (Calendar) + if (format == TimeFormat.ABSOLUTE) { + return formatTimeAbs(time, resolution); + } + + StringBuffer str = new StringBuffer(); + boolean neg = time < 0; + if (neg) { + time = -time; + str.append('-'); + } + + long sec = (long) (time * 1E-9); + // TODO: Expand to make it possible to select the minute, second, nanosecond format + //printing minutes is suppressed just sec and ns + // if (sec / 60 < 10) + // str.append('0'); + // str.append(sec / 60); + // str.append(':'); + // sec %= 60; + // if (sec < 10) + // str.append('0'); + str.append(sec); + String ns = formatNs(time, resolution); + if (!ns.equals("")) { //$NON-NLS-1$ + str.append(':'); + str.append(ns); + } + + return str.toString(); + } + + /** + * From input time in nanoseconds, convert to Date format YYYY-MM-dd + * + * @param absTime + * @return the formatted date + */ + public static String formatDate(long absTime) { + String sdate = sdateformat.format(new Date((long) (absTime * 1E-6))); + return sdate; + } + + /** + * Formats time in ns to Calendar format: HH:MM:SS MMM.mmm.nnn + * + * @param time + * @return the formatted time + */ + static public String formatTimeAbs(long time, Resolution res) { + StringBuffer str = new StringBuffer(); + + // format time from nanoseconds to calendar time HH:MM:SS + String stime = stimeformat.format(new Date((long) (time * 1E-6))); + str.append(stime + " "); //$NON-NLS-1$ + // append the Milliseconds, MicroSeconds and NanoSeconds as specified in + // the Resolution + str.append(formatNs(time, res)); + return str.toString(); + } + + /** + * Obtains the remainder fraction on unit Seconds of the entered value in + * nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction + * seconds can be obtained by removing the last 9 digits: 1241207054 the + * fractional portion of seconds, expressed in ns is: 171080214 + * + * @param time + * @param res + * @return the formatted nanosec + */ + public static String formatNs(long time, Resolution res) { + StringBuffer temp = new StringBuffer(); + boolean neg = time < 0; + if (neg) { + time = -time; + } + + // The following approach could be used although performance + // decreases in half. + // String strVal = String.format("%09d", time); + // String tmp = strVal.substring(strVal.length() - 9); + + // number of segments to be included + int segments = 0; + switch (res) { + case MILLISEC: + segments = 1; + break; + case MICROSEC: + segments = 2; + break; + case NANOSEC: + segments = 3; + break; + default: + break; + } + + long ns = time; + ns %= 1000000000; + if (ns < 10) { + temp.append("00000000"); //$NON-NLS-1$ + } else if (ns < 100) { + temp.append("0000000"); //$NON-NLS-1$ + } else if (ns < 1000) { + temp.append("000000"); //$NON-NLS-1$ + } else if (ns < 10000) { + temp.append("00000"); //$NON-NLS-1$ + } else if (ns < 100000) { + temp.append("0000"); //$NON-NLS-1$ + } else if (ns < 1000000) { + temp.append("000"); //$NON-NLS-1$ + } else if (ns < 10000000) { + temp.append("00"); //$NON-NLS-1$ + } else if (ns < 100000000) { + temp.append("0"); //$NON-NLS-1$ + } + temp.append(ns); + + StringBuffer str = new StringBuffer(); + if (segments > 0) { + // append ms + str.append(temp.substring(0, 3)); + } + if (segments > 1) { + // append Micro secs + str.append("."); //$NON-NLS-1$ + str.append(temp.substring(3, 6)); + } + if (segments > 2) { + // append Nano seconds + str.append("."); //$NON-NLS-1$ + str.append(temp.substring(6)); + } + + return str.toString(); + } + + static public int loadIntOption(String opt, int def, int min, int max) { + // int val = + // TraceUIPlugin.getDefault().getPreferenceStore().getInt(opt); + // if (0 == val) + // val = def; + // if (val < min) + // val = min; + // if (val > max) + // val = max; + return def; + } + + static public void saveIntOption(String opt, int val) { + // TraceUIPlugin.getDefault().getPreferenceStore().setValue(opt, val); + } + + static ITimeEvent getFirstEvent(ITimeGraphEntry thread) { + if (null == thread) + return null; + Iterator iterator = thread.getTimeEventsIterator(); + if (iterator != null && iterator.hasNext()) { + return iterator.next(); + } else { + return null; + } + } + + /** + * N means:
  • -1: Previous Event
  • 0: Current Event
  • + * 1: Next Event
  • 2: Previous Event when located in a non Event Area + * + * + * @param thread + * @param time + * @param n + * @return + */ + static ITimeEvent findEvent(ITimeGraphEntry thread, long time, int n) { if (null == thread) return null; - Iterator iterator = thread.getTraceEventsIterator(); + Iterator iterator = thread.getTimeEventsIterator(); + if (iterator == null) { + return null; + } ITimeEvent nextEvent = null; ITimeEvent currEvent = null; ITimeEvent prevEvent = null; @@ -349,17 +327,17 @@ public class Utils { while (iterator.hasNext()) { nextEvent = (ITimeEvent) iterator.next(); long nextStartTime = nextEvent.getTime(); - + if (nextStartTime > time) { break; } - + if (currEvent == null || currEvent.getTime() != nextStartTime) { prevEvent = currEvent; currEvent = nextEvent; } } - + if (n == -1) { //previous if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) { return prevEvent; @@ -377,159 +355,93 @@ public class Utils { } else if (n == 2) { //current or previous when in empty space return currEvent; } - + return null; } - // static public TRCPackage getPackage(Object element) { - // if (element instanceof TRCPackage) - // return (TRCPackage) element; - // if (element instanceof TRCClass) - // return ((TRCClass) element).getPackage(); - // return null; - // } - - // static public TRCObjectAllocationAnnotation getAllocationAnnotation( - // TRCClass cls) { - // TRCObjectAllocationAnnotation aa = null; - // EList list = cls.getAnnotations(); - // int len = list.size(); - // for (int i = 0; i < len; i++) { - // TRCAnnotation annotation = (TRCAnnotation) list.get(i); - // if (annotation instanceof TRCObjectAllocationAnnotation) - // aa = (TRCObjectAllocationAnnotation) annotation; - // } - // return aa; - // } - - static public String fixMethodSignature(String sig) { - int pos = sig.indexOf('('); - if (pos >= 0) { - String ret = sig.substring(0, pos); - sig = sig.substring(pos); - sig = sig + " " + ret; //$NON-NLS-1$ - } - return sig; - } - - static public String restoreMethodSignature(String sig) { - String ret = ""; //$NON-NLS-1$ - int pos = sig.indexOf('('); - if (pos >= 0) { - ret = sig.substring(0, pos); - sig = sig.substring(pos + 1); - } - pos = sig.indexOf(')'); - if (pos >= 0) { - sig = sig.substring(0, pos); - } - String args[] = sig.split(","); //$NON-NLS-1$ + static public String fixMethodSignature(String sig) { + int pos = sig.indexOf('('); + if (pos >= 0) { + String ret = sig.substring(0, pos); + sig = sig.substring(pos); + sig = sig + " " + ret; //$NON-NLS-1$ + } + return sig; + } + + static public String restoreMethodSignature(String sig) { + String ret = ""; //$NON-NLS-1$ + int pos = sig.indexOf('('); + if (pos >= 0) { + ret = sig.substring(0, pos); + sig = sig.substring(pos + 1); + } + pos = sig.indexOf(')'); + if (pos >= 0) { + sig = sig.substring(0, pos); + } + String args[] = sig.split(","); //$NON-NLS-1$ StringBuffer result = new StringBuffer("("); //$NON-NLS-1$ - for (int i = 0; i < args.length; i++) { - String arg = args[i].trim(); - if (arg.length() == 0 && args.length == 1) - break; - result.append(getTypeSignature(arg)); - } - result.append(")").append(getTypeSignature(ret)); //$NON-NLS-1$ - return result.toString(); - } - - static public String getTypeSignature(String type) { - int dim = 0; - for (int j = 0; j < type.length(); j++) { - if (type.charAt(j) == '[') - dim++; - } - int pos = type.indexOf('['); - if (pos >= 0) - type = type.substring(0, pos); - StringBuffer sig = new StringBuffer(""); //$NON-NLS-1$ - for (int j = 0; j < dim; j++) - sig.append("["); //$NON-NLS-1$ - if (type.equals("boolean")) //$NON-NLS-1$ - sig.append("Z"); //$NON-NLS-1$ - else if (type.equals("byte")) //$NON-NLS-1$ - sig.append("B"); //$NON-NLS-1$ - else if (type.equals("char")) //$NON-NLS-1$ - sig.append("C"); //$NON-NLS-1$ - else if (type.equals("short")) //$NON-NLS-1$ - sig.append("S"); //$NON-NLS-1$ - else if (type.equals("int")) //$NON-NLS-1$ - sig.append("I"); //$NON-NLS-1$ - else if (type.equals("long")) //$NON-NLS-1$ - sig.append("J"); //$NON-NLS-1$ - else if (type.equals("float")) //$NON-NLS-1$ - sig.append("F"); //$NON-NLS-1$ - else if (type.equals("double")) //$NON-NLS-1$ - sig.append("D"); //$NON-NLS-1$ - else if (type.equals("void")) //$NON-NLS-1$ - sig.append("V"); //$NON-NLS-1$ - else - sig.append("L").append(type.replace('.', '/')).append(";"); //$NON-NLS-1$ //$NON-NLS-2$ - return sig.toString(); - } - - // static public boolean openSource(Object element) { - // if (element instanceof String) { - // final String pattern = (String) element; - // final int javaType = IJavaSearchConstants.METHOD; - // BusyIndicator.showWhile(Display.getDefault(), new Runnable() { - // public void run() { - // if (!OpenJavaSource.openSource(pattern, javaType, - // SearchEngine.createWorkspaceScope(), true)) { - // MessageDialog.openInformation(UIPlugin.getDefault() - // .getWorkbench().getActiveWorkbenchWindow() - // .getShell(), TraceMessages.TRC_MSGT, NLS.bind( - // TraceUIMessages._68, pattern)); - // } - // } - // }); - // } - // OpenSource.openSource(element); - // return true; - // } - - // static public int getObjAge(TRCFullTraceObject obj, EList listGC) { - // int age = 0; - // double t0 = obj.getCreateTime(); - // double t1 = obj.getCollectTime(); - // int len = listGC.size(); - // for (int j = 0; j < len; j++) { - // TRCGCEvent gcEvent = (TRCGCEvent) listGC.get(j); - // if (gcEvent.getType().equals("finish")) { - // double time = gcEvent.getTime(); - // if (time <= t0) - // continue; - // if (t1 > 0 && time >= t1) - // break; - // age++; - // } - // } - // return age; - // } - - static public int compare(double d1, double d2) { - if (d1 > d2) - return 1; - if (d1 < d2) - return 1; - return 0; - } - - static public int compare(String s1, String s2) { - if (s1 != null && s2 != null) - return s1.compareToIgnoreCase(s2); - if (s1 != null) - return 1; - if (s2 != null) - return -1; - return 0; - } - - // static public String formatPercent(int val, int max) { - // String s = max > 0 && max >= val ? TString - // .formatAsPercentage((double) val / (double) max) : ""; - // return s; - // } + for (int i = 0; i < args.length; i++) { + String arg = args[i].trim(); + if (arg.length() == 0 && args.length == 1) + break; + result.append(getTypeSignature(arg)); + } + result.append(")").append(getTypeSignature(ret)); //$NON-NLS-1$ + return result.toString(); + } + + static public String getTypeSignature(String type) { + int dim = 0; + for (int j = 0; j < type.length(); j++) { + if (type.charAt(j) == '[') + dim++; + } + int pos = type.indexOf('['); + if (pos >= 0) + type = type.substring(0, pos); + StringBuffer sig = new StringBuffer(""); //$NON-NLS-1$ + for (int j = 0; j < dim; j++) + sig.append("["); //$NON-NLS-1$ + if (type.equals("boolean")) //$NON-NLS-1$ + sig.append("Z"); //$NON-NLS-1$ + else if (type.equals("byte")) //$NON-NLS-1$ + sig.append("B"); //$NON-NLS-1$ + else if (type.equals("char")) //$NON-NLS-1$ + sig.append("C"); //$NON-NLS-1$ + else if (type.equals("short")) //$NON-NLS-1$ + sig.append("S"); //$NON-NLS-1$ + else if (type.equals("int")) //$NON-NLS-1$ + sig.append("I"); //$NON-NLS-1$ + else if (type.equals("long")) //$NON-NLS-1$ + sig.append("J"); //$NON-NLS-1$ + else if (type.equals("float")) //$NON-NLS-1$ + sig.append("F"); //$NON-NLS-1$ + else if (type.equals("double")) //$NON-NLS-1$ + sig.append("D"); //$NON-NLS-1$ + else if (type.equals("void")) //$NON-NLS-1$ + sig.append("V"); //$NON-NLS-1$ + else + sig.append("L").append(type.replace('.', '/')).append(";"); //$NON-NLS-1$ //$NON-NLS-2$ + return sig.toString(); + } + + static public int compare(double d1, double d2) { + if (d1 > d2) + return 1; + if (d1 < d2) + return 1; + return 0; + } + + static public int compare(String s1, String s2) { + if (s1 != null && s2 != null) + return s1.compareToIgnoreCase(s2); + if (s1 != null) + return 1; + if (s2 != null) + return -1; + return 0; + } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/ColumnData.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/ColumnData.java similarity index 89% rename from org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/ColumnData.java rename to org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/ColumnData.java index 6c20fa53ca..b7272a6014 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/ColumnData.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/ColumnData.java @@ -10,7 +10,7 @@ * Matthew Khouzam - Extracted from TmfEventsView ******************************************************************************/ -package org.eclipse.linuxtools.tmf.ui.widgets; +package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable; public class ColumnData { public final String header; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/IDoubleClickListener.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/IDoubleClickListener.java similarity index 92% rename from org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/IDoubleClickListener.java rename to org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/IDoubleClickListener.java index 9c6c3ed552..7ed4717963 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/IDoubleClickListener.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/IDoubleClickListener.java @@ -9,7 +9,7 @@ * Contributors: * Xavier Raynaud - Initial API and implementation ******************************************************************************/ -package org.eclipse.linuxtools.tmf.ui.widgets; +package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable; import org.eclipse.swt.widgets.TableItem; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/TmfRawEventViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TmfRawEventViewer.java similarity index 97% rename from org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/TmfRawEventViewer.java rename to org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TmfRawEventViewer.java index b0c9ae14fa..ac27090573 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/TmfRawEventViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TmfRawEventViewer.java @@ -10,7 +10,7 @@ * Patrick Tasse - Initial API and implementation ******************************************************************************/ -package org.eclipse.linuxtools.tmf.ui.widgets; +package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable; import java.util.ArrayList; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/TmfVirtualTable.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TmfVirtualTable.java similarity index 99% rename from org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/TmfVirtualTable.java rename to org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TmfVirtualTable.java index 344481ef00..8b93d2677b 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/TmfVirtualTable.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TmfVirtualTable.java @@ -13,7 +13,7 @@ * Xavier Raynaud - Improvements ******************************************************************************/ -package org.eclipse.linuxtools.tmf.ui.widgets; +package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.TableEditor; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/TooltipProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TooltipProvider.java similarity index 91% rename from org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/TooltipProvider.java rename to org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TooltipProvider.java index 28d792019a..39734c8f24 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/TooltipProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TooltipProvider.java @@ -9,7 +9,7 @@ * Contributors: * Xavier Raynaud - Initial API and implementation ******************************************************************************/ -package org.eclipse.linuxtools.tmf.ui.widgets; +package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable; public interface TooltipProvider { -- 2.34.1