From f6281059b399ca538c5da6c457cdc96c523c0748 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez-Leon Date: Mon, 31 May 2010 19:27:25 +0000 Subject: [PATCH] --- .../.classpath | 8 + org.eclipse.linuxtools.tmf.ui.tests/.project | 28 + .../META-INF/MANIFEST.MF | 14 + .../build.properties | 8 + .../plugin.properties | 3 + .../plugin.xml | 17 + .../tmf/ui/tests/TmfUITestPlugin.java | 77 ++ org.eclipse.linuxtools.tmf.ui.tests/test.xml | 54 ++ .../test/stub/adaption/TsfImplProvider.java | 120 +++ .../test/stub/model/EventImpl.java | 82 ++ .../test/stub/model/TraceImpl.java | 103 +++ .../stub/model/TraceModelImplFactory.java | 235 ++++++ .../test/stub/views/TsfTraceAnalysisView.java | 703 ++++++++++++++++++ 13 files changed, 1452 insertions(+) create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/.classpath create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/.project create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/build.properties create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/plugin.properties create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/plugin.xml create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/TmfUITestPlugin.java create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/test.xml create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/adaption/TsfImplProvider.java create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/EventImpl.java create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/TraceImpl.java create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/TraceModelImplFactory.java create mode 100644 org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/views/TsfTraceAnalysisView.java diff --git a/org.eclipse.linuxtools.tmf.ui.tests/.classpath b/org.eclipse.linuxtools.tmf.ui.tests/.classpath new file mode 100644 index 0000000000..62549a7696 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/org.eclipse.linuxtools.tmf.ui.tests/.project b/org.eclipse.linuxtools.tmf.ui.tests/.project new file mode 100644 index 0000000000..08ccb6ca17 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.tmf.ui.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..84dfbb7b15 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.eclipse.linuxtools.tmf.ui.tests;singleton:=true +Bundle-Version: 0.2.0.qualifier +Bundle-Vendor: %Bundle-Vendor +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.junit, + org.eclipse.linuxtools.tmf;bundle-version="0.2.0", + org.eclipse.linuxtools.tmf.ui;bundle-version="0.2.0", + org.eclipse.core.runtime;bundle-version="3.5.0", + org.eclipse.ui;bundle-version="3.5.0" +Bundle-Localization: plugin +Bundle-Activator: org.eclipse.linuxtools.tmf.ui.tests.TmfUITestPlugin diff --git a/org.eclipse.linuxtools.tmf.ui.tests/build.properties b/org.eclipse.linuxtools.tmf.ui.tests/build.properties new file mode 100644 index 0000000000..e6b9081c6a --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/build.properties @@ -0,0 +1,8 @@ +source.. = src/,\ + widgetStubs/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + test.xml,\ + plugin.xml diff --git a/org.eclipse.linuxtools.tmf.ui.tests/plugin.properties b/org.eclipse.linuxtools.tmf.ui.tests/plugin.properties new file mode 100644 index 0000000000..3d61bbae4c --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/plugin.properties @@ -0,0 +1,3 @@ +#Properties file for org.eclipse.linuxtools.tmf.ui.tests +Bundle-Vendor = Eclipse Linux Tools +Bundle-Name = Tracing and Monitoring Framework (TMF) UI Unit Test Suite \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml b/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml new file mode 100644 index 0000000000..d3ffb0ffcf --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/TmfUITestPlugin.java b/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/TmfUITestPlugin.java new file mode 100644 index 0000000000..746a525819 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/TmfUITestPlugin.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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 (alvsan09@gmail.com) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.tmf.ui.tests; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class TmfUITestPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf.ui.tests"; + + // The shared instance + private static TmfUITestPlugin plugin; + + // ======================================================================== + // Constructor + // ======================================================================== + public TmfUITestPlugin() { + } + + // ======================================================================== + // Methods + // ======================================================================== + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static TmfUITestPlugin getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/org.eclipse.linuxtools.tmf.ui.tests/test.xml b/org.eclipse.linuxtools.tmf.ui.tests/test.xml new file mode 100644 index 0000000000..37506687e3 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/test.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/adaption/TsfImplProvider.java b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/adaption/TsfImplProvider.java new file mode 100644 index 0000000000..8fdf0c5041 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/adaption/TsfImplProvider.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * 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 (alvsan09@gmail.com) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.adaption; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model.EventImpl; +import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model.TraceImpl; + + +public class TsfImplProvider extends TmfTimeAnalysisProvider { + + // ======================================================================== + // Methods + // ======================================================================== + @Override + public StateColor getEventColor(ITimeEvent event) { + if (event instanceof EventImpl) { + EventImpl devent = (EventImpl) event; + switch (devent.getType()) { + case ALARM: + return StateColor.DARK_GREEN; + case ERROR: + return StateColor.DARK_YELLOW; + case EVENT: + return StateColor.MAGENTA3; + case INFORMATION: + return StateColor.PURPLE1; + case TIMEADJUSTMENT: + return StateColor.PINK1; + case WARNING: + return StateColor.AQUAMARINE; + case INFO1: + return StateColor.RED; + case INFO2: + return StateColor.GREEN; + case INFO3: + return StateColor.DARK_BLUE; + case INFO4: + return StateColor.GOLD; + case INFO5: + return StateColor.ORANGE; + case INFO6: + return StateColor.GRAY; + case INFO7: + return StateColor.LIGHT_BLUE; + case INFO8: + return StateColor.CADET_BLUE; + case INFO9: + return StateColor.OLIVE; + } + } + return StateColor.BLACK; + } + + @Override + public String getStateName(StateColor color) { + switch (color) { + case GOLD: + return "ALARM"; + case RED: + return "ERROR"; + case DARK_BLUE: + return "EVENT"; + case GREEN: + return "INFORMATION"; + case GRAY: + return "TIME ADJUSTMENT DKDKDKDKL"; + case ORANGE: + return "WARNING"; + default: + return "UNKNOWN"; + } + } + + @Override + public Map getEventHoverToolTipInfo(ITimeEvent revent) { + Map toolTipEventMsgs = new HashMap(); + if (revent instanceof EventImpl) { + toolTipEventMsgs.put("Test Tip1", "Test Value tip1"); + toolTipEventMsgs.put("Test Tip2", "Test Value tip2"); + } + + return toolTipEventMsgs; + } + + @Override + public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) { + String name = "Unknown"; + name = upper ? name : name; + if (event instanceof EventImpl) { + EventImpl devent = (EventImpl) event; + name = devent.getType().toString(); + } + return name; + } + + @Override + public String getTraceClassName(ITmfTimeAnalysisEntry trace) { + String name = ""; + if (trace instanceof TraceImpl) { + TraceImpl dTrace = (TraceImpl) trace; + name = dTrace.getClassName(); + } + return name; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/EventImpl.java b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/EventImpl.java new file mode 100644 index 0000000000..67669cfffd --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/EventImpl.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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 (alvsan09@gmail.com) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model; + +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.TimeEvent; + +public class EventImpl extends TimeEvent { + // ======================================================================== + // Data + // ======================================================================== + public static enum Type {ERROR, WARNING, TIMEADJUSTMENT, ALARM, EVENT, INFORMATION, UNKNOWN, INFO1, INFO2, INFO3, INFO4, INFO5, INFO6, INFO7, INFO8, INFO9} + + private long time = 0; + private ITmfTimeAnalysisEntry trace = null; + private Type myType = Type.UNKNOWN; + private long duration; + + // ======================================================================== + // Constructor + // ======================================================================== + public EventImpl(long time, ITmfTimeAnalysisEntry trace, Type type) { + this.time = time; + this.trace = trace; + this.myType = type; + this.setDuration(super.getDuration()); + } + + // ======================================================================== + // Methods + // ======================================================================== + public Type getType() { + return myType; + } + + public void setType(Type myType) { + this.myType = myType; + } + + public void setTime(long time) { + this.time = time; + } + + public void setTrace(ITmfTimeAnalysisEntry trace) { + this.trace = trace; + } + + @Override + public long getTime() { + return time; + } + + @Override + public ITmfTimeAnalysisEntry getEntry() { + return trace; + } + + /** + * @param duration the duration to set + */ + public void setDuration(long duration) { + this.duration = duration; + } + + /** + * @return the duration + */ + @Override + public long getDuration() { + return duration; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/TraceImpl.java b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/TraceImpl.java new file mode 100644 index 0000000000..7ffc2d1cf4 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/TraceImpl.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * 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 (alvsan09@gmail.com) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model; + +import java.util.Vector; + +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.TimeEvent; + + +public class TraceImpl implements ITmfTimeAnalysisEntry { + // ======================================================================== + // Data + // ======================================================================== + private int id = 0; + private String name = "traceDefaultName"; + private long startTime = 0; + private long stopTime = 1; + private String groupName = "defaultGroupName"; + private String className = "defaultClassName"; + private Vector traceEvents = new Vector(); + + // ======================================================================== + // Constructor + // ======================================================================== + + public TraceImpl(int id, String name, long sTime, long stopTime, + String groupName, String className) { + this.id = id; + this.name = name; + this.startTime = sTime; + this.stopTime = stopTime; + this.groupName = groupName; + this.className = className; + } + + // ======================================================================== + // Methods + // ======================================================================== + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + 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; + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + public void setStopTime(long stopTime) { + this.stopTime = stopTime; + } + + public String getGroupName() { + return groupName; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public long getStartTime() { + return startTime; + } + + public long getStopTime() { + return stopTime; + } + + @SuppressWarnings("unchecked") + public Vector getTraceEvents() { + return traceEvents; + } + +} 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/timeAnalysis/test/stub/model/TraceModelImplFactory.java new file mode 100644 index 0000000000..e364fce461 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/model/TraceModelImplFactory.java @@ -0,0 +1,235 @@ +/******************************************************************************* + * 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 (alvsan09@gmail.com) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model; + +import java.util.Date; + +public class TraceModelImplFactory { + + // ======================================================================== + // Data + // ======================================================================== + private int count = 0; + private TraceStrings[] traceNames; + private static final long msTons = 1000000; + private Long timeRef = new Date().getTime() * msTons; + + // ======================================================================== + // Constructor + // ======================================================================== + public TraceModelImplFactory() { + traceNames = new TraceStrings[17]; + loadTraceNameStrings(); + } + + // ======================================================================== + // Methods + // ======================================================================== + public TraceImpl[] createTraces() { + 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); + count = i; + createEvents(trace); + traceArr[i] = trace; + } + return traceArr; + } + + /** + * 5000 Events per Trace. + * @param number + * @return + */ + public TraceImpl[] createLargeTraces(int number) { + TraceImpl trace; + TraceImpl[] traceArr = new TraceImpl[number]; + 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); + count = i; + create5000Events(trace); + traceArr[i] = trace; + } + return traceArr; + } + + private void create5000Events(TraceImpl trace) { + EventImpl event; + Long eventTime; + int numEvents = 5000; + long sTime = trace.getStartTime(); + long eTime = trace.getStopTime(); + long duration = (long) ((eTime - sTime)/numEvents); + for (int i = 0; i < numEvents; i++) { + eventTime = sTime + (i * duration); + // eventTime = timeRef + (5 * (count % 4) + (5 * (int) (i/2) )); + // System.out.println("Trace: " + trace.getName() + " EventTime: " + // + eventTime); +// duration = i * msTons + (long) ((i % 4)); + + event = new EventImpl(eventTime, trace, getEventType(i%16)); + event.setDuration(duration); + trace.getTraceEvents().add(event); + } + } + + private void createEvents(TraceImpl trace) { + EventImpl event; + Long eventTime; + int numEvents = 17; + long duration = 0; + for (int i = 0; i < numEvents; i++) { + eventTime = timeRef + msTons * i + (5 * msTons * count) + (5 * i); + duration = msTons + i * msTons + (long) ((i % 4)); +// duration = i + (long) ((i % 4)); + event = new EventImpl(eventTime, trace, getEventType(i)); + event.setDuration(duration); + trace.getTraceEvents().add(event); + } + } + + private EventImpl.Type getEventType(int val) { + if (EventImpl.Type.ALARM.ordinal() == val) + return EventImpl.Type.ALARM; + if (EventImpl.Type.ERROR.ordinal() == val) + return EventImpl.Type.ERROR; + if (EventImpl.Type.EVENT.ordinal() == val) + return EventImpl.Type.EVENT; + if (EventImpl.Type.INFORMATION.ordinal() == val) + return EventImpl.Type.INFORMATION; + if (EventImpl.Type.TIMEADJUSTMENT.ordinal() == val) + return EventImpl.Type.TIMEADJUSTMENT; + if (EventImpl.Type.WARNING.ordinal() == val) + return EventImpl.Type.WARNING; + if (EventImpl.Type.INFO1.ordinal() == val) + return EventImpl.Type.INFO1; + if (EventImpl.Type.INFO2.ordinal() == val) + return EventImpl.Type.INFO2; + if (EventImpl.Type.INFO3.ordinal() == val) + return EventImpl.Type.INFO3; + if (EventImpl.Type.INFO4.ordinal() == val) + return EventImpl.Type.INFO4; + if (EventImpl.Type.INFO5.ordinal() == val) + return EventImpl.Type.INFO5; + if (EventImpl.Type.INFO6.ordinal() == val) + return EventImpl.Type.INFO6; + if (EventImpl.Type.INFO7.ordinal() == val) + return EventImpl.Type.INFO7; + if (EventImpl.Type.INFO8.ordinal() == val) + return EventImpl.Type.INFO8; + if (EventImpl.Type.INFO9.ordinal() == val) + return EventImpl.Type.INFO9; + return EventImpl.Type.UNKNOWN; + } + + private void loadTraceNameStrings() { + 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"; + + } + + // ======================================================================== + // Inner Class + // ======================================================================== + private 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/timeAnalysis/test/stub/views/TsfTraceAnalysisView.java new file mode 100644 index 0000000000..3a43b5a55b --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timeAnalysis/test/stub/views/TsfTraceAnalysisView.java @@ -0,0 +1,703 @@ +/******************************************************************************* + * 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 (alvsan09@gmail.com) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.views; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +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.viewers.TmfViewerFactory; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeSelectionListener; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeScaleSelectionListener; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; +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.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.DrillDownAdapter; +import org.eclipse.ui.part.ViewPart; + +public class TsfTraceAnalysisView extends ViewPart implements + ITmfTimeSelectionListener, ITmfTimeScaleSelectionListener { + + // ======================================================================== + // Data + // ======================================================================== + private TreeViewer viewer; + 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 static SimpleDateFormat stimeformat = new SimpleDateFormat( + "yy/MM/dd HH:mm:ss"); + private TraceModelImplFactory fact; + + // ======================================================================== + // Inner Classes + // ======================================================================== + /* + * The content provider class is responsible for providing objects to the + * view. It can wrap existing objects in adapters or simply return objects + * as-is. These objects may be sensitive to the current input of the view, + * or ignore it and always show the same content (like Task List, for + * example). + */ + + class TreeObject implements IAdaptable { + private String name; + private TreeParent parent; + + public TreeObject(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setParent(TreeParent parent) { + this.parent = parent; + } + + public TreeParent getParent() { + return parent; + } + + @Override + public String toString() { + return getName(); + } + + @SuppressWarnings("rawtypes") + public Object getAdapter(Class key) { + return null; + } + } + + class TreeParent extends TreeObject { + private ArrayList children; + + public TreeParent(String name) { + super(name); + children = new ArrayList(); + } + + public void addChild(TreeObject child) { + children.add(child); + child.setParent(this); + } + + public void removeChild(TreeObject child) { + children.remove(child); + child.setParent(null); + } + + public TreeObject[] getChildren() { + return children.toArray(new TreeObject[children + .size()]); + } + + public boolean hasChildren() { + return children.size() > 0; + } + } + + class ViewContentProvider implements IStructuredContentProvider, + ITreeContentProvider { + private TreeParent invisibleRoot; + + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + public Object[] getElements(Object parent) { + if (parent.equals(getViewSite())) { + if (invisibleRoot == null) + initialize(); + return getChildren(invisibleRoot); + } + return getChildren(parent); + } + + public Object getParent(Object child) { + if (child instanceof TreeObject) { + return ((TreeObject) child).getParent(); + } + return null; + } + + public Object[] getChildren(Object parent) { + if (parent instanceof TreeParent) { + return ((TreeParent) parent).getChildren(); + } + return new Object[0]; + } + + public boolean hasChildren(Object parent) { + if (parent instanceof TreeParent) + return ((TreeParent) parent).hasChildren(); + return false; + } + + /* + * We will set up a dummy model to initialize tree heararchy. In a real + * code, you will connect to a real model and expose its hierarchy. + */ + private void initialize() { + TreeObject to1 = new TreeObject("Leaf 1"); + TreeObject to2 = new TreeObject("Leaf 2"); + TreeObject to3 = new TreeObject("Leaf 3"); + TreeParent p1 = new TreeParent("Parent 1"); + p1.addChild(to1); + p1.addChild(to2); + p1.addChild(to3); + + TreeObject to4 = new TreeObject("Leaf 4"); + TreeParent p2 = new TreeParent("Parent 2"); + p2.addChild(to4); + + TreeParent root = new TreeParent("Root"); + root.addChild(p1); + root.addChild(p2); + + invisibleRoot = new TreeParent(""); + invisibleRoot.addChild(root); + } + } + + class ViewLabelProvider extends LabelProvider { + + @Override + public String getText(Object obj) { + return obj.toString(); + } + + @Override + public Image getImage(Object obj) { + String imageKey = ISharedImages.IMG_OBJ_ELEMENT; + if (obj instanceof TreeParent) + imageKey = ISharedImages.IMG_OBJ_FOLDER; + return PlatformUI.getWorkbench().getSharedImages().getImage( + imageKey); + } + } + + class NameSorter extends ViewerSorter { + } + + // ======================================================================== + // Methods + // ======================================================================== + /** + * This is a callback that will allow us to create the viewer and initialize + * it. + */ + @Override + public void createPartControl(Composite parent) { + 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()); + + viewer = new TreeViewer(sashForm, SWT.MULTI | SWT.H_SCROLL + | SWT.V_SCROLL); + drillDownAdapter = new DrillDownAdapter(viewer); + viewer.setContentProvider(new ViewContentProvider()); + viewer.setLabelProvider(new ViewLabelProvider()); + viewer.setSorter(new NameSorter()); + viewer.setInput(getViewSite()); + + sashForm.setWeights(new int[] { 5, 1 }); + sashForm2.setWeights(new int[] { 1, 1 }); + + fact = new TraceModelImplFactory(); + ITmfTimeAnalysisEntry[] traceArr = fact.createTraces(); + tsfviewer.display(traceArr); + tsfviewer.addWidgetSelectionListner(this); + tsfviewer.addWidgetTimeScaleSelectionListner(this); + tsfviewer.setTimeCalendarFormat(true); + + tsfviewer2.display(traceArr); + tsfviewer2.addWidgetSelectionListner(this); + tsfviewer2.addWidgetTimeScaleSelectionListner(this); + // tsfviewer2.setTimeFormat(ITimeAnalysisViewer.timeFormat.epoch); + + makeActions(); + hookContextMenu(); + hookDoubleClickAction(); + contributeToActionBars(); + } + + private void hookContextMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + TsfTraceAnalysisView.this.fillContextMenu(manager); + } + }); + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, viewer); + } + + private void contributeToActionBars() { + IActionBars bars = getViewSite().getActionBars(); + fillLocalPullDown(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } + + private void fillLocalPullDown(IMenuManager manager) { + manager.add(action1); + manager.add(new Separator()); + manager.add(action2); + } + + private void fillContextMenu(IMenuManager manager) { + manager.add(action1); + manager.add(action2); + manager.add(new Separator()); + drillDownAdapter.addNavigationActions(manager); + // Other plug-ins can contribute there actions here + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + + 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; + if (tsfviewer.isInFocus()) + inFocusViewer = tsfviewer; + else if (tsfviewer2.isInFocus()) + inFocusViewer = tsfviewer2; + return inFocusViewer; + } + + private void makeActions() { + // action1 + action1 = new Action() { + @Override + public void run() { + showMessage("Action 1 executed"); + } + }; + action1.setText("Action 1"); + action1.setToolTipText("Action 1 tooltip"); + action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() + .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + + // action2 + action2 = new Action() { + @Override + public void run() { + showMessage("Action 2 executed"); + } + }; + action2.setText("Action 2"); + action2.setToolTipText("Action 2 tooltip"); + 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(); + if (inFocusViewer != null) { + inFocusViewer.resetStartFinishTime(); + } + + } + }; + resetScale.setText("Reset"); + resetScale.setToolTipText("Reset the Time Scale to Default"); + + // action5 + nextEvent = new Action() { + @Override + public void run() { + ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + if (inFocusViewer != null) { + inFocusViewer.selectNextEvent(); + } + } + }; + nextEvent.setText("NextEv"); + nextEvent.setToolTipText("Next Event"); + + // action6 + prevEvent = new Action() { + @Override + public void run() { + ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + if (inFocusViewer != null) { + inFocusViewer.selectPrevEvent(); + } + } + }; + prevEvent.setText("PrevEv"); + prevEvent.setToolTipText("Previous Event"); + + // action7 + nextTrace = new Action() { + @Override + public void run() { + ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + if (inFocusViewer != null) { + inFocusViewer.selectNextTrace(); + } + } + }; + nextTrace.setText("NextTrace"); + nextTrace.setToolTipText("Select Next Event"); + + // action8 + prevTrace = new Action() { + @Override + public void run() { + ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + if (inFocusViewer != null) { + inFocusViewer.selectPrevTrace(); + } + } + }; + prevTrace.setText("PrevTrace"); + prevTrace.setToolTipText("Select Previous Trace"); + + // action9 + showLegent = new Action() { + @Override + public void run() { + ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + if (inFocusViewer != null) { + inFocusViewer.showLegend(); + } + } + }; + 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(); + if (inFocusViewer != null) { + inFocusViewer.zoomIn(); + } + } + }; + zoomIn.setText("Zoom In"); + zoomIn.setToolTipText("Zoom In"); + + // action10 + zoomOut = new Action() { + @Override + public void run() { + ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); + if (inFocusViewer != null) { + inFocusViewer.zoomOut(); + } + // ISelection selection = inFocusViewer.getSelection(); + // Object sel = null; + // if (selection != null && !selection.isEmpty()) { + // sel = ((IStructuredSelection) selection) + // .getFirstElement(); + // if (sel instanceof EventImpl) { + // EventImpl event = (EventImpl) sel; + // inFocusViewer.selectNextEvent(); + // } + // } + } + }; + 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(); + if (inFocusViewer != null) { + ITmfTimeAnalysisEntry[] traceArr = fact + .createLargeTraces(60); + inFocusViewer.display(traceArr); + } + } + }; + events300K.setText("300K Events"); + events300K.setToolTipText("Add 300K Events"); + + doubleClickAction = new Action() { + @Override + public void run() { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection) selection) + .getFirstElement(); + showMessage("Double-click detected on " + obj.toString()); + } + }; + } + + private void hookDoubleClickAction() { + viewer.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + doubleClickAction.run(); + } + }); + } + + private void showMessage(String message) { + MessageDialog.openInformation(viewer.getControl().getShell(), + "TsfTrace Analysis View", message); + } + + /** + * Passing the focus request to the viewer's control. + */ + @Override + public void setFocus() { + viewer.getControl().setFocus(); + } + + public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event) { + Object source = event.getSource(); + if (source == null || !(source instanceof ITimeAnalysisViewer)) { + return; + } + + ITimeAnalysisViewer rViewer = (ITimeAnalysisViewer) event.getSource(); + ITimeAnalysisViewer synchViewer = null; + // Synchronize viewer selections if Enabled, + // make sure the selection does not go in loops + if (tsfviewer == rViewer) { + synchViewer = tsfviewer2; + } else { + synchViewer = tsfviewer; + } + 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; + date = new Date((long) (selTimens / 1E-6)); + System.out + .println("TsfTmIncubatorListener.tsfTmProcessEvent() Selected Event: \nType: " + + selEvent.getType().toString() + + "\nTime: " + + selEvent.getTime() + + "\nTrace Name: " + + selEvent.getEntry().getName() + + "\nSelection Type: " + + event.getDType().toString() + + "\nSelected Time: " + + selTimens + " " + fDate + " " + ns); + + synchViewer.setSelectedEvent(selEvent, source); + + } else if (selection instanceof TraceImpl) { + TraceImpl selTrace = (TraceImpl) selection; + System.out + .println("TsfTmIncubatorListener.tsfTmProcessEvent() 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); + } else { + System.out + .println("TsfTmIncubatorListener.tsfTmProcessEvent() Unexpected event source received: " + + selection.getClass().getName()); + } + + } + + public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event) { + Object source = event.getSource(); + if (source == null || !(source instanceof ITimeAnalysisViewer)) { + return; + } + + if (event != null && event instanceof TmfTimeScaleSelectionEvent) { + TmfTimeScaleSelectionEvent rEvent = (TmfTimeScaleSelectionEvent) event; + ITimeAnalysisViewer rViewer = (ITimeAnalysisViewer) event + .getSource(); + ITimeAnalysisViewer synchViewer = null; + // Synchronize viewer selections if Enabled, + // make sure the selection does not go in loops + if (tsfviewer == rViewer) { + synchViewer = tsfviewer2; + } else { + synchViewer = tsfviewer; + } + + + synchViewer.setSelectVisTimeWindow(rEvent.getTime0(), rEvent + .getTime1(), source); + } + } + + /** + * Obtains the remainder fraction on unit Seconds of the entered value in + * nanoseconds. e.g. input: 1241207054171080214 ns The number of seconds can + * be obtain by removing the last 9 digits: 1241207054 the fractional + * portion of seconds, expressed in ns is: 171080214 + * + * @param v + * @return + */ + public String formatNs(long v) { + StringBuffer str = new StringBuffer(); + boolean neg = v < 0; + if (neg) { + v = -v; + str.append('-'); + } + + String strVal = String.valueOf(v); + if (v < 1000000000) { + return strVal; + } + + // Extract the last nine digits (e.g. fraction of a S expressed in ns + return strVal.substring(strVal.length() - 9); + } +} \ No newline at end of file -- 2.34.1