From f8177ba26149e360cedec85af30fb2d22cb735f6 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Tue, 30 Oct 2012 11:06:32 -0400 Subject: [PATCH] Implement TmfTimestampFormat Change-Id: I29d4f815679503c82a14ac74e8395f9aa3dc0cbf Signed-off-by: Francois Chouinard Reviewed-on: https://git.eclipse.org/r/8419 Tested-by: Hudson CI IP-Clean: Alexandre Montplaisir --- .../META-INF/MANIFEST.MF | 2 +- .../ctf/core/tests/AllCtfCoreTests.java | 4 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 4 +- .../META-INF/MANIFEST.MF | 6 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 18 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 12 +- .../META-INF/MANIFEST.MF | 8 +- .../tests/event/TmfSimpleTimestampTest.java | 17 +- .../core/tests/event/TmfTimestampTest.java | 29 +- .../META-INF/MANIFEST.MF | 4 +- .../tmf/core/ctfadaptor/CtfTmfTimestamp.java | 127 +--- .../tmf/core/event/ITmfTimestamp.java | 55 +- .../tmf/core/event/TmfSimpleTimestamp.java | 20 +- .../tmf/core/event/TmfTimestamp.java | 61 +- .../tmf/core/event/TmfTimestampFormat.java | 616 ++++++++++++++++++ .../TmfTimestampFormatUpdateSignal.java | 31 + .../META-INF/MANIFEST.MF | 14 +- .../META-INF/MANIFEST.MF | 16 +- .../plugin.properties | 1 + org.eclipse.linuxtools.tmf.ui/plugin.xml | 6 + .../linuxtools/internal/tmf/ui/Activator.java | 46 +- .../tmf/ui/properties/TmfTimePreferences.java | 232 +++++++ .../ui/properties/TmfTimestampFormatPage.java | 325 +++++++++ .../tmf/ui/viewers/events/TmfEventsTable.java | 11 + .../tmf/ui/views/events/TmfEventsView.java | 13 + .../views/histogram/FullTraceHistogram.java | 39 +- .../tmf/ui/views/histogram/Histogram.java | 112 +++- .../HistogramCurrentTimeControl.java | 96 ++- .../views/histogram/HistogramDataModel.java | 20 +- .../views/histogram/HistogramTextControl.java | 112 ++-- .../histogram/HistogramTimeRangeControl.java | 82 ++- .../ui/views/histogram/HistogramUtils.java | 145 ----- .../tmf/ui/views/histogram/HistogramView.java | 91 +-- .../views/histogram/TimeRangeHistogram.java | 21 +- .../ui/views/histogram/messages.properties | 4 +- 41 files changed, 1794 insertions(+), 618 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampFormat.java create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfTimestampFormatUpdateSignal.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/properties/TmfTimePreferences.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/properties/TmfTimestampFormatPage.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramUtils.java diff --git a/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF index 1880b6eea9..9e756b3edd 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF @@ -7,4 +7,4 @@ Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.linuxtools.ctf.core.tests Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Fragment-Host: org.eclipse.linuxtools.ctf.core -Require-Bundle: org.junit4;bundle-version="4.8.1" +Require-Bundle: org.junit4;bundle-version="4.8.0" diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java index 66f8400926..34bc3dc329 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java @@ -8,7 +8,7 @@ import org.junit.runners.Suite; * The class TestAll builds a suite that can be used to run all of * the tests within its package as well as within any subpackages of its * package. - * + * * @author ematkho * @version $Revision: 1.0 $ */ @@ -24,7 +24,7 @@ public class AllCtfCoreTests { /** * Launch the test. - * + * * @param args * the command line arguments */ diff --git a/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF index f89927e819..f37eef0812 100644 --- a/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF @@ -8,7 +8,7 @@ Bundle-SymbolicName: org.eclipse.linuxtools.ctf.core;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.ctf.core.Activator Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0", +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", org.eclipse.linuxtools.ctf.parser;bundle-version="1.0.0" Export-Package: org.eclipse.linuxtools.ctf.core.event, org.eclipse.linuxtools.ctf.core.event.types, diff --git a/org.eclipse.linuxtools.lttng.help/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng.help/META-INF/MANIFEST.MF index 27e369307d..a4cabb0a06 100644 --- a/org.eclipse.linuxtools.lttng.help/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng.help/META-INF/MANIFEST.MF @@ -5,4 +5,4 @@ Bundle-Vendor: %Bundle-Vendor Bundle-Version: 2.0.0.qualifier Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.linuxtools.lttng.help; singleton:=true -Require-Bundle: org.eclipse.help;bundle-version="3.5.100" +Require-Bundle: org.eclipse.help;bundle-version="3.6.0" diff --git a/org.eclipse.linuxtools.lttng2.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.core.tests/META-INF/MANIFEST.MF index b341a8f3bb..9f1d9d9b20 100644 --- a/org.eclipse.linuxtools.lttng2.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.core.tests/META-INF/MANIFEST.MF @@ -8,4 +8,4 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.core.tests Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Fragment-Host: org.eclipse.linuxtools.lttng2.core -Require-Bundle: org.junit;bundle-version="3.8.2" +Require-Bundle: org.junit;bundle-version="4.8.0" diff --git a/org.eclipse.linuxtools.lttng2.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.core/META-INF/MANIFEST.MF index 6af7b3d796..dded32f022 100644 --- a/org.eclipse.linuxtools.lttng2.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.core/META-INF/MANIFEST.MF @@ -8,6 +8,6 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.core;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.lttng2.core.Activator Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0" +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0" Export-Package: org.eclipse.linuxtools.internal.lttng2.core.control.model;x-friends:="org.eclipse.linuxtools.lttng2.ui", org.eclipse.linuxtools.internal.lttng2.core.control.model.impl;x-friends:="org.eclipse.linuxtools.lttng2.ui" diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.kernel.core.tests/META-INF/MANIFEST.MF index 2832300575..0aa82b5575 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/META-INF/MANIFEST.MF @@ -8,5 +8,5 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.kernel.core.tests Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Fragment-Host: org.eclipse.linuxtools.lttng2.kernel.core -Require-Bundle: org.junit;bundle-version="3.8.2", - org.eclipse.linuxtools.tmf.core;bundle-version="1.0.0" +Require-Bundle: org.junit;bundle-version="4.8.0", + org.eclipse.linuxtools.tmf.core;bundle-version="2.0.0" diff --git a/org.eclipse.linuxtools.lttng2.kernel.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.kernel.core/META-INF/MANIFEST.MF index 531629130e..7b32fb234b 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.kernel.core/META-INF/MANIFEST.MF @@ -8,10 +8,10 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.kernel.core;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.lttng2.kernel.core.Activator Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0", - org.eclipse.core.resources;bundle-version="3.7.0", +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", + org.eclipse.core.resources;bundle-version="3.8.0", org.eclipse.linuxtools.ctf.core;bundle-version="1.0.0", - org.eclipse.linuxtools.tmf.core;bundle-version="1.0.0" + org.eclipse.linuxtools.tmf.core;bundle-version="2.0.0" Export-Package: org.eclipse.linuxtools.internal.lttng2.kernel.core;x-friends:="org.eclipse.linuxtools.lttng2.kernel.ui", org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider;x-internal:=true, org.eclipse.linuxtools.lttng2.kernel.core.trace diff --git a/org.eclipse.linuxtools.lttng2.kernel.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.kernel.ui.tests/META-INF/MANIFEST.MF index 293c515d69..9d873476de 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.ui.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.kernel.ui.tests/META-INF/MANIFEST.MF @@ -8,4 +8,4 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.kernel.ui.tests Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Fragment-Host: org.eclipse.linuxtools.lttng2.kernel.ui -Require-Bundle: org.junit;bundle-version="3.8.2" +Require-Bundle: org.junit;bundle-version="4.8.0" diff --git a/org.eclipse.linuxtools.lttng2.kernel.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.kernel.ui/META-INF/MANIFEST.MF index 0fe8090e9b..4e3ebdaef3 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.kernel.ui/META-INF/MANIFEST.MF @@ -8,12 +8,12 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.kernel.ui;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.lttng2.kernel.ui.Activator Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.ui;bundle-version="3.7.0", - org.eclipse.ui.ide;bundle-version="3.7.0", - org.eclipse.core.resources;bundle-version="3.7.0", - org.eclipse.core.runtime;bundle-version="3.7.0", - org.eclipse.linuxtools.tmf.core;bundle-version="1.1.0", - org.eclipse.linuxtools.tmf.ui;bundle-version="1.0.0", - org.eclipse.linuxtools.lttng2.core;bundle-version="1.0.0", - org.eclipse.linuxtools.lttng2.ui;bundle-version="1.0.0", - org.eclipse.linuxtools.lttng2.kernel.core;bundle-version="1.0.0" +Require-Bundle: org.eclipse.ui;bundle-version="3.8.0", + org.eclipse.ui.ide;bundle-version="3.8.0", + org.eclipse.core.resources;bundle-version="3.8.0", + org.eclipse.core.runtime;bundle-version="3.8.0", + org.eclipse.linuxtools.tmf.core;bundle-version="2.0.0", + org.eclipse.linuxtools.tmf.ui;bundle-version="2.0.0", + org.eclipse.linuxtools.lttng2.core;bundle-version="2.0.0", + org.eclipse.linuxtools.lttng2.ui;bundle-version="2.0.0", + org.eclipse.linuxtools.lttng2.kernel.core;bundle-version="2.0.0" diff --git a/org.eclipse.linuxtools.lttng2.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.ui.tests/META-INF/MANIFEST.MF index a01f68f2a0..00a15a0442 100644 --- a/org.eclipse.linuxtools.lttng2.ui.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.ui.tests/META-INF/MANIFEST.MF @@ -8,4 +8,4 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.ui.tests Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Fragment-Host: org.eclipse.linuxtools.lttng2.ui -Require-Bundle: org.junit;bundle-version="3.8.2" +Require-Bundle: org.junit;bundle-version="4.8.0" diff --git a/org.eclipse.linuxtools.lttng2.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.ui/META-INF/MANIFEST.MF index f70a7ef048..5b49a9a3a3 100644 --- a/org.eclipse.linuxtools.lttng2.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.ui/META-INF/MANIFEST.MF @@ -8,12 +8,12 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.ui;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.lttng2.ui.Activator Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.ui;bundle-version="3.7.0", - org.eclipse.ui.ide;bundle-version="3.7.0", - org.eclipse.core.resources;bundle-version="3.7.100", - org.eclipse.core.runtime;bundle-version="3.7.0", - org.eclipse.linuxtools.lttng2.core;bundle-version="1.0.0", - org.eclipse.linuxtools.tmf.core;bundle-version="1.0.0", +Require-Bundle: org.eclipse.ui;bundle-version="3.8.0", + org.eclipse.ui.ide;bundle-version="3.8.0", + org.eclipse.core.resources;bundle-version="3.8.0", + org.eclipse.core.runtime;bundle-version="3.8.0", + org.eclipse.linuxtools.lttng2.core;bundle-version="2.0.0", + org.eclipse.linuxtools.tmf.core;bundle-version="2.0.0", org.eclipse.linuxtools.tmf.ui;bundle-version="1.0.0" Export-Package: org.eclipse.linuxtools.internal.lttng2.ui.views.control;x-friends:="org.eclipse.linuxtools.lttng2.kernel.ui", org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;x-internal:=true, diff --git a/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF index aafe400b60..dd789fa8c8 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF @@ -8,9 +8,9 @@ Bundle-SymbolicName: org.eclipse.linuxtools.tmf.core.tests;singleton:=true Bundle-Activator: org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.junit;bundle-version="3.8.2", - org.eclipse.core.runtime;bundle-version="3.7.0", - org.eclipse.core.resources;bundle-version="3.7.100", - org.eclipse.linuxtools.tmf.core;bundle-version="1.0.0", +Require-Bundle: org.junit;bundle-version="4.8.0", + org.eclipse.core.runtime;bundle-version="3.8.0", + org.eclipse.core.resources;bundle-version="3.8.0", + org.eclipse.linuxtools.tmf.core;bundle-version="2.0.0", org.eclipse.linuxtools.ctf.core;bundle-version="1.0.0" Export-Package: org.eclipse.linuxtools.tmf.tests.stubs.trace;x-friends:="org.eclipse.linuxtools.tmf.ui.tests" diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java index dd87ab0198..292f227606 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java @@ -94,8 +94,7 @@ public class TmfSimpleTimestampTest extends TestCase { * */ public void testCopyBadTimestamp() { - final ITmfTimestamp ts0a = new TmfTimestamp(0, 1, 0); - final ITmfTimestamp ts0b = new TmfTimestamp(0, 0, 1); + final ITmfTimestamp ts0a = new TmfTimestamp(0, 100, 0); try { new TmfSimpleTimestamp(null); @@ -106,13 +105,7 @@ public class TmfSimpleTimestampTest extends TestCase { try { new TmfSimpleTimestamp(ts0a); fail("TmfSimpleTimestamp: bad scale"); - } catch (final IllegalArgumentException e) { - } - - try { - new TmfSimpleTimestamp(ts0b); - fail("TmfSimpleTimestamp: bad precision"); - } catch (final IllegalArgumentException e) { + } catch (final ArithmeticException e) { } } @@ -236,9 +229,9 @@ public class TmfSimpleTimestampTest extends TestCase { * */ public void testToString() { - assertEquals("toString", "TmfSimpleTimestamp [fValue=0]", ts0.toString()); - assertEquals("toString", "TmfSimpleTimestamp [fValue=12345]", ts1.toString()); - assertEquals("toString", "TmfSimpleTimestamp [fValue=-1234]", ts2.toString()); + assertEquals("toString", "00:00:00.000_000_000", ts0.toString()); + assertEquals("toString", "03:25:45.000_000_000", ts1.toString()); + assertEquals("toString", "23:39:26.000_000_000", ts2.toString()); } // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java index 73d28a3fa1..44acb134c7 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java @@ -17,6 +17,7 @@ import junit.framework.TestCase; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; /** * Test suite for the TmfTimestamp class. @@ -29,9 +30,9 @@ public class TmfTimestampTest extends TestCase { // ------------------------------------------------------------------------ private final ITmfTimestamp ts0 = new TmfTimestamp(); - private final ITmfTimestamp ts1 = new TmfTimestamp(12345); + private final ITmfTimestamp ts1 = new TmfTimestamp(12345, 0); private final ITmfTimestamp ts2 = new TmfTimestamp(12345, -1); - private final ITmfTimestamp ts3 = new TmfTimestamp(12345, 2, 5); + private final ITmfTimestamp ts3 = new TmfTimestamp(12345, 2, 5); // ------------------------------------------------------------------------ // Housekeping @@ -291,13 +292,23 @@ public class TmfTimestampTest extends TestCase { /** * */ - public void testToString() { - assertEquals("toString", "TmfTimestamp [fValue=0, fScale=0, fPrecision=0]", ts0.toString()); - assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=0, fPrecision=0]", ts1.toString()); - assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=-1, fPrecision=0]", ts2.toString()); - assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=2, fPrecision=5]", ts3.toString()); + public void testToStringDefault() { + assertEquals("toString", "00:00:00.000_000_000", ts0.toString()); + assertEquals("toString", "03:25:45.000_000_000", ts1.toString()); + assertEquals("toString", "00:20:34.500_000_000", ts2.toString()); + assertEquals("toString", "06:55:00.000_000_000", ts3.toString()); } + /** + * + */ + public void testToStringInterval() { + assertEquals("toString", "000.000_000_000", ts0.toString(TmfTimestampFormat.getDefaulIntervalFormat())); + assertEquals("toString", "12345.000_000_000", ts1.toString(TmfTimestampFormat.getDefaulIntervalFormat())); + assertEquals("toString", "1234.500_000_000", ts2.toString(TmfTimestampFormat.getDefaulIntervalFormat())); + assertEquals("toString", "1234500.000_000_000", ts3.toString(TmfTimestampFormat.getDefaulIntervalFormat())); + } + // ------------------------------------------------------------------------ // normalize // ------------------------------------------------------------------------ @@ -331,7 +342,7 @@ public class TmfTimestampTest extends TestCase { * */ public void testNormalizeOffsetLowerLimits() { - final ITmfTimestamp ref = new TmfTimestamp(Long.MIN_VALUE + 5); + final ITmfTimestamp ref = new TmfTimestamp(Long.MIN_VALUE + 5, 0); ITmfTimestamp ts = ref.normalize(-4, 0); assertEquals("getValue", Long.MIN_VALUE + 1, ts.getValue()); @@ -353,7 +364,7 @@ public class TmfTimestampTest extends TestCase { * */ public void testNormalizeOffsetUpperLimits() { - final ITmfTimestamp ref = new TmfTimestamp(Long.MAX_VALUE - 5); + final ITmfTimestamp ref = new TmfTimestamp(Long.MAX_VALUE - 5, 0); ITmfTimestamp ts = ref.normalize(4, 0); assertEquals("getValue", Long.MAX_VALUE - 1, ts.getValue()); diff --git a/org.eclipse.linuxtools.tmf.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.core/META-INF/MANIFEST.MF index eab00f4dbe..68ef90d5a0 100644 --- a/org.eclipse.linuxtools.tmf.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.core/META-INF/MANIFEST.MF @@ -8,8 +8,8 @@ Bundle-SymbolicName: org.eclipse.linuxtools.tmf.core;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.tmf.core.Activator Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0", - org.eclipse.core.resources;bundle-version="3.7.100", +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", + org.eclipse.core.resources;bundle-version="3.8.0", org.eclipse.ui.views;bundle-version="3.6.100", org.eclipse.linuxtools.ctf.core;bundle-version="1.0.0" Export-Package: org.eclipse.linuxtools.internal.tmf.core;x-friends:="org.eclipse.linuxtools.tmf.core.tests", diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java index ab3c04f2cb..644e217951 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java @@ -11,17 +11,13 @@ package org.eclipse.linuxtools.tmf.core.ctfadaptor; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; /** * The CTF adapter for the TMF timestamp * - * @version 1.0 + * @version 1.1 * @author Matthew khouzam */ public class CtfTmfTimestamp extends TmfTimestamp { @@ -54,7 +50,7 @@ public class CtfTmfTimestamp extends TmfTimestamp { * @param timestamp long */ public CtfTmfTimestamp(long timestamp) { - setValue(timestamp, -9, 0); + setValue(timestamp, ITmfTimestamp.NANOSECOND_SCALE, 0); type = TimestampType.DAY; } @@ -74,125 +70,6 @@ public class CtfTmfTimestamp extends TmfTimestamp { return type; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse - * .linuxtools.tmf.core.event.ITmfTimestamp) - */ - /** - * Method getDelta. - * @param ts ITmfTimestamp - * @return ITmfTimestamp - * @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#getDelta(ITmfTimestamp) - */ - @Override - public ITmfTimestamp getDelta(ITmfTimestamp ts) { - TmfTimestamp parent = (TmfTimestamp) super.getDelta(ts); - long value = parent.getValue(); - long exp = parent.getScale(); - long diff = exp + 9; - for (int i = 0; i < diff; i++) { - value *= 10; - } - CtfTmfTimestamp retVal = new CtfTmfTimestamp(value); - if (value > 100000000) { - retVal.type = TimestampType.SECONDS; - } else { - retVal.type = TimestampType.NANOS; - } - return retVal; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - switch (type) { - case DAY: { - return dateToString(); - } - case FULL_DATE: { - return toFullDateString(); - } - case NANOS: { - return nanoToString(); - } - case SECONDS:{ - return secondsToString(); - } - default: - break; - } - return super.toString(); - } - - /** - * Method secondsToString. - * @return String - */ - private String secondsToString() { - double timestamp = getValue(); - timestamp /= 1000000000; - StringBuilder retVal = new StringBuilder(); - retVal.append(timestamp); - retVal.append(" s"); //$NON-NLS-1$ - return retVal.toString(); - } - - /** - * Method nanoToString. - * @return String - */ - private String nanoToString() { - final long timestamp = getValue(); - StringBuilder retVal = new StringBuilder(); - String time = Long.toString(timestamp); - for (int i = 0; i < time.length(); i++) { - int pos = time.length() - i - 1; - retVal.append(time.charAt(i)); - if (pos % 3 == 0) { - retVal.append(' '); - } - } - retVal.append("ns"); //$NON-NLS-1$ - return retVal.toString(); - } - - /** - * Method dateToString. - * @return String - */ - private String dateToString() { - final long timestamp = getValue(); - final Date d = new Date(timestamp / 1000000); - final DateFormat df = new SimpleDateFormat("HH:mm:ss."); //$NON-NLS-1$ - final long nanos = (timestamp % 1000000000); - StringBuilder output = new StringBuilder(); - output.append(df.format(d)); - output.append(String.format("%09d", nanos)); //$NON-NLS-1$ - return output.toString(); - } - - /** - * Method toFullDateString. - * @return String - */ - private String toFullDateString() { - final long timestamp = getValue(); - final Date d = new Date(timestamp / 1000000); - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$ - final long nanos = (timestamp % 1000000000); - StringBuilder output = new StringBuilder(); - output.append(df.format(d)); - output.append(String.format("%09d", nanos)); //$NON-NLS-1$ - return output.toString(); - } - /* (non-Javadoc) * @see java.lang.Object#hashCode() */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java index d51fd59030..f9689a505d 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java @@ -1,11 +1,11 @@ /******************************************************************************* * 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: * Francois Chouinard - Initial API and implementation *******************************************************************************/ @@ -27,15 +27,43 @@ package org.eclipse.linuxtools.tmf.core.event; *
  • [precision] indicates the error on the value (useful for comparing * timestamps in different scales). Default: 0. * - * - * @version 1.0 + * + * @version 2.0 * @author Francois Chouinard - * + * * @see ITmfEvent * @see TmfTimeRange */ public interface ITmfTimestamp extends Comparable { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /** + * The millisecond scale factor (10e0) + * @since 2.0 + */ + public int SECOND_SCALE = 0; + + /** + * The millisecond scale factor (10e-3) + * @since 2.0 + */ + public int MILLISECOND_SCALE = -3; + + /** + * The microsecond scale factor (10e-6) + * @since 2.0 + */ + public int MICROSECOND_SCALE = -6; + + /** + * The nanosecond scale factor (10e-9) + * @since 2.0 + */ + public int NANOSECOND_SCALE = -9; + // ------------------------------------------------------------------------ // Getters // ------------------------------------------------------------------------ @@ -60,8 +88,8 @@ public interface ITmfTimestamp extends Comparable { // ------------------------------------------------------------------------ /** - * Normalize (adjust scale and offset) of the timerstamp - * + * Normalize (adjust scale and offset) of the timestamp + * * @param offset the offset to apply to the timestamp value (after scaling) * @param scale the new timestamp scale * @return a new 'adjusted' ITmfTimestamp @@ -70,7 +98,7 @@ public interface ITmfTimestamp extends Comparable { /** * Compares [this] and [ts] within timestamp precision - * + * * @param ts the other timestamp * @param withinPrecision consider the precision when testing for equality * @return -1, 0 or 1 (less than, equals, greater than) @@ -79,7 +107,7 @@ public interface ITmfTimestamp extends Comparable { /** * Returns the difference between [this] and [ts] as a timestamp - * + * * @param ts the other timestamp * @return the time difference (this - other) as an ITmfTimestamp */ @@ -100,4 +128,13 @@ public interface ITmfTimestamp extends Comparable { @Override int compareTo(ITmfTimestamp ts); + /** + * Format the timestamp as per the format provided + * + * @param format the timestamp formatter + * @return the formatted timestamp + * @since 2.0 + */ + public String toString(final TmfTimestampFormat format); + } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java index 99ffd37b43..1922e59db9 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Standardize on the default toString() *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.event; @@ -15,7 +16,7 @@ package org.eclipse.linuxtools.tmf.core.event; /** * A simplified timestamp where scale and precision are set to 0. * - * @version 1.0 + * @version 1.1 * @author Francois Chouinard */ public class TmfSimpleTimestamp extends TmfTimestamp { @@ -43,13 +44,15 @@ public class TmfSimpleTimestamp extends TmfTimestamp { /** * Copy constructor * - * @param timestamp the timestamp to copy + * @param timestamp the timestamp to copy or scale to 0 + * @throws IllegalArgumentException if timestamp is null + * @throws ArithmeticException if timestamp can't be scaled to 0 */ public TmfSimpleTimestamp(final ITmfTimestamp timestamp) { - if (timestamp == null || timestamp.getScale() != 0 || timestamp.getPrecision() != 0) { + if (timestamp == null) { throw new IllegalArgumentException(); } - setValue(timestamp.getValue(), 0, 0); + setValue(timestamp.normalize(0, 0).getValue(), 0, 0); } // ------------------------------------------------------------------------ @@ -133,13 +136,4 @@ public class TmfSimpleTimestamp extends TmfTimestamp { return compareTo(ts, false) == 0; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#toString() - */ - @Override - @SuppressWarnings("nls") - public String toString() { - return "TmfSimpleTimestamp [fValue=" + getValue() + "]"; - } - } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java index 118f8bbc25..f23b918790 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java @@ -1,25 +1,26 @@ /******************************************************************************* * 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: * Francois Chouinard - Initial API and implementation * Thomas Gatterweh - Updated scaling / synchronization * Francois Chouinard - Refactoring to align with TMF Event Model 1.0 + * Francois Chouinard - Implement augmented interface *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.event; - /** * A generic timestamp implementation. The timestamp is represented by the - * tuple { value, scale, precision }. - * - * @version 1.0 + * tuple { value, scale, precision }. By default, timestamps are in the + * nanosecond scale. + * + * @version 1.1 * @author Francois Chouinard */ public class TmfTimestamp implements ITmfTimestamp, Cloneable { @@ -40,6 +41,18 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable { public static final ITmfTimestamp BIG_CRUNCH = new TmfTimestamp(Long.MAX_VALUE, Integer.MAX_VALUE, 0); + /** + * A more practical definition of "beginning of time" + * @since 2.0 + */ + public static final ITmfTimestamp PROJECT_IS_FUNDED = BIG_BANG; + + /** + * A more practical definition of "end of time" + * @since 2.0 + */ + public static final ITmfTimestamp PROJECT_IS_CANCELLED = BIG_CRUNCH; + /** * Zero */ @@ -51,7 +64,7 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable { // ------------------------------------------------------------------------ /** - * The timestamp raw value (mantissa) + * The timestamp raw value (mantissa) in nanoseconds */ private long fValue; @@ -73,7 +86,7 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable { * Default constructor */ public TmfTimestamp() { - this(0, 0, 0); + this(0, ITmfTimestamp.SECOND_SCALE, 0); } /** @@ -82,12 +95,12 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable { * @param value the timestamp value */ public TmfTimestamp(final long value) { - this(value, 0, 0); + this(value, ITmfTimestamp.SECOND_SCALE, 0); } /** * Simple constructor (precision = 0) - * + * * @param value the timestamp value * @param scale the timestamp scale */ @@ -97,7 +110,7 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable { /** * Full constructor - * + * * @param value the timestamp value * @param scale the timestamp scale * @param precision the timestamp precision @@ -110,7 +123,7 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable { /** * Copy constructor - * + * * @param timestamp the timestamp to copy */ public TmfTimestamp(final ITmfTimestamp timestamp) { @@ -195,8 +208,8 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable { if (fScale == scale && offset == 0) { return new TmfTimestamp(this); } - - // In case of big bang and big crunch just return this (no need to normalize) + + // In case of big bang and big crunch just return this (no need to normalize) if (this.equals(BIG_BANG) || this.equals(BIG_CRUNCH)) { return this; } @@ -358,9 +371,25 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable { * @see java.lang.Object#toString() */ @Override - @SuppressWarnings("nls") public String toString() { - return "TmfTimestamp [fValue=" + fValue + ", fScale=" + fScale + ", fPrecision=" + fPrecision + "]"; + return toString(TmfTimestampFormat.getDefaulTimeFormat()); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#toString(org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat) + */ + /** + * @since 2.0 + */ + @Override + public String toString(final TmfTimestampFormat format) { + try { + ITmfTimestamp ts = normalize(0, ITmfTimestamp.NANOSECOND_SCALE); + return format.format(ts.getValue()); + } + catch (ArithmeticException e) { + return format.format(0); + } } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampFormat.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampFormat.java new file mode 100644 index 0000000000..1e271e376d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampFormat.java @@ -0,0 +1,616 @@ +/******************************************************************************* + * 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: + * Francois Chouinard - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.event; + +import java.text.DecimalFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; +import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; + +/** + * A formatting and parsing facility that can handle timestamps that span the + * epoch with a precision down to the nanosecond. It can be understood as a + * simplified and more constrained version of SimpleDateFormat as it limits the + * number of allowed pattern characters and the acceptable timestamp formats. + *

    + * The timestamp representation is broken down into a number of optional + * components that can be assembled into a fairly simple way. + * + *

    Date Pattern

    + *
    + * + * + * + * + * + *
    Format + * Description + * Value Range + * Example + *
    yyyy + * Year + * 1970-... + * 2012 + *
    MM + * Month in year + * 01-12 + * 09 + *
    dd + * Day in month + * 01-31 + * 22 + *
    + *
    + * + *

    Time Pattern

    + *
    + * + * + * + * + * + * + *
    Format + * Description + * Value Range + * Example + *
    HH + * Hour in day + * 00-23 + * 07 + *
    mm + * Minute in hour + * 00-59 + * 35 + *
    ss + * Second in minute + * 00-59 + * 41 + *
    T + * The seconds since the epoch + * 00-... + * 1332170682 + *
    + *
    + * + *

    Sub-Seconds Pattern

    + *
    + * + * + * + * + * + *
    Format + * Description + * Value Range + * Example + *
    SSS + * Millisecond in second + * 000-999 + * 123 + *
    CCC + * Microseconds in ms + * 000-999 + * 456 + *
    NNN + * Nanosecond in µs + * 000-999 + * 789 + *
    + *
    + * + * Note: If "T" is used, no other Date or Time pattern + * can be used. Also, "T" should be used for time intervals. + *

    + * Note: Each sub-field can be separated by a single, + * optional character delimiter. However, the between Date/Time and the + * Sub-seconds pattern is mandatory (if there is a fractional part) and + * has to be separated from Date/time by "." (period). + *

    + * The recognized delimiters are: + *

      + *
    • Space (" ") + *
    • Period (".") + *
    • Comma (",") + *
    • Dash ("-") + *
    • Underline ("_") + *
    • Colon (":") + *
    • Semicolon (";") + *
    • Slash ("/") + *
    • Double-quote (""") + *
    + * + *

    Examples

    + * The following examples show how timestamp patterns are interpreted in + * the U.S. locale. The given timestamp is 1332170682539677389L, the number + * of nanoseconds since 1970/01/01. + * + *
    + * + * + * + * + * + * + * + * + *
    Date and Time Pattern + * Result + *
    "yyyy-MM-dd HH:mm:ss.SSS.CCC.NNN" + * 2012-03-19 11:24:42.539.677.389 + *
    "yyyy-MM-dd HH:mm:ss.SSS.CCC" + * 2012-03-19 11:24:42.539.677 + *
    "yyyy-D HH:mm:ss.SSS.CCC" + * 2012-79 11:24:42.539.677 + *
    "ss.SSSCCCNNN" + * 42.539677389 + *
    "T.SSS CCC NNN" + * 1332170682.539 677 389 + *
    "T" + * 1332170682 + *
    + *
    + *

    + * @version 1.0 + * @since 2.0 + * @author Francois Chouinard + */ +public class TmfTimestampFormat extends SimpleDateFormat { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /** + * This class' serialization ID + */ + private static final long serialVersionUID = 2835829763122454020L; + + /** + * The default timestamp pattern + */ + public static final String DEFAULT_TIME_PATTERN = "HH:mm:ss.SSS_CCC_NNN"; //$NON-NLS-1$ + + /** + * The LTTng 0.x legacy timestamp format + */ + public static final String DEFAULT_INTERVAL_PATTERN = "TTT.SSS_CCC_NNN"; //$NON-NLS-1$ + + // Fractions of seconds supported patterns + private static final String DOT_RE = "\\."; //$NON-NLS-1$ + private static final String SEP_RE = "[ \\.,-_:;/\\\"]?"; //$NON-NLS-1$ + private static final String DGTS_3_RE = "(\\d{3})"; //$NON-NLS-1$ + private static final String DGTS_13_RE = "(\\d{1,3})"; //$NON-NLS-1$ + + private static final String MILLISEC_RE = DOT_RE + DGTS_13_RE; + private static final String MICROSEC_RE = DOT_RE + DGTS_3_RE + SEP_RE + DGTS_13_RE; + private static final String NANOSEC_RE = DOT_RE + DGTS_3_RE + SEP_RE + DGTS_3_RE + SEP_RE + DGTS_13_RE; + + private static final Pattern MILLISEC_PAT = Pattern.compile(MILLISEC_RE); + private static final Pattern MICROSEC_PAT = Pattern.compile(MICROSEC_RE); + private static final Pattern NANOSEC_PAT = Pattern.compile(NANOSEC_RE); + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // The default timestamp pattern + private static String fDefaultTimePattern = null; + private static TmfTimestampFormat fDefaultTimeFormat = null; + + // The default time interval format + private static String fDefaultIntervalPattern = null; + private static TmfTimestampFormat fDefaultIntervalFormat = null; + + // The timestamp pattern + private String fPattern; + + // The timestamp pattern + private List fSupplPatterns = new ArrayList(); + + /** + * The supplementary pattern letters. Can be redefined by sub-classes + * to either override existing letters or augment the letter set. + * If so, the format() method must provide the (re-)implementation of the + * pattern. + */ + protected String fSupplPatternLetters = "TSCN"; //$NON-NLS-1$ + + /** + * The bracketing symbols used to mitigate the risk of a format string + * that contains escaped sequences that would conflict with our format + * extension. + */ + protected String fOpenBracket = "[&"; //$NON-NLS-1$ + protected String fCloseBracket = "&]"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * The default constructor (uses the default pattern) + */ + public TmfTimestampFormat() { + this(fDefaultTimePattern); + } + + /** + * The normal constructor + * + * @param pattern the format pattern + */ + public TmfTimestampFormat(String pattern) { + calendar.setTimeZone(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$ + applyPattern(pattern); + } + + /** + * The copy constructor + * + * @param other the other format pattern + */ + public TmfTimestampFormat(TmfTimestampFormat other) { + this(other.fPattern); + } + + // ------------------------------------------------------------------------ + // Getters/setters + // ------------------------------------------------------------------------ + + /** + * @param pattern the new default time pattern + */ + public static void setDefaultTimeFormat(final String pattern) { + fDefaultTimePattern = pattern; + fDefaultTimeFormat = new TmfTimestampFormat(fDefaultTimePattern); + TmfSignalManager.dispatchSignal(new TmfTimestampFormatUpdateSignal(null)); + } + + /** + * @return the default time format pattern + */ + public static TmfTimestampFormat getDefaulTimeFormat() { + if (fDefaultTimeFormat == null) { + fDefaultTimeFormat = new TmfTimestampFormat(DEFAULT_TIME_PATTERN); + } + return fDefaultTimeFormat; + } + + /** + * @param pattern the new default interval pattern + */ + public static void setDefaultIntervalFormat(final String pattern) { + fDefaultIntervalPattern = pattern; + fDefaultIntervalFormat = new TmfTimestampFormat(fDefaultIntervalPattern); + TmfSignalManager.dispatchSignal(new TmfTimestampFormatUpdateSignal(null)); + } + + /** + * @return the default interval format pattern + */ + public static TmfTimestampFormat getDefaulIntervalFormat() { + if (fDefaultIntervalFormat == null) { + fDefaultIntervalFormat = new TmfTimestampFormat(DEFAULT_INTERVAL_PATTERN); + } + return fDefaultIntervalFormat; + } + + /* (non-Javadoc) + * @see java.text.SimpleDateFormat#applyPattern(java.lang.String) + */ + @Override + public void applyPattern(String pattern) { + fPattern = pattern; + String quotedPattern = quoteSpecificTags(pattern); + super.applyPattern(quotedPattern); + } + + /* (non-Javadoc) + * @see java.text.SimpleDateFormat#toPattern() + */ + @Override + public String toPattern() { + return fPattern; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Format the timestamp according to its pattern. + * + * @param value the timestamp value to format (in ns) + * @return the formatted timestamp + */ + public String format(long value) { + + // Split the timestamp value into its sub-components + long sec = value / 1000000000; // seconds + long ms = value % 1000000000 / 1000000; // milliseconds + long cs = value % 1000000 / 1000; // microseconds + long ns = value % 1000; // nanoseconds + + // Let the base class fill the stuff it knows about + StringBuffer result = new StringBuffer(super.format(sec * 1000 + ms)); + + // In the case where there is no separation between 2 supplementary + // fields, the pattern will have the form "..'[pat-1]''[pat-2]'.." and + // the base class format() will interpret the 2 adjacent quotes as a + // wanted character in the result string as ("..[pat-1]'[pat-2].."). + // Remove these extra quotes before filling the supplementary fields. + int loc = result.indexOf(fCloseBracket + "'" + fOpenBracket); //$NON-NLS-1$ + while (loc != -1) { + result.deleteCharAt(loc + fCloseBracket.length()); + loc = result.indexOf(fCloseBracket + "'" + fOpenBracket); //$NON-NLS-1$ + } + + // Fill in our extensions + for (String pattern : fSupplPatterns) { + int length = pattern.length(); + + // Prepare the format buffer + StringBuffer fmt = new StringBuffer(length); + for (int i = 0; i < length; i++) { + fmt.append("0"); //$NON-NLS-1$ + } + DecimalFormat dfmt = new DecimalFormat(fmt.toString()); + String fmtVal = ""; //$NON-NLS-1$; + + // Format the proper value as per the pattern + switch (pattern.charAt(0)) { + case 'T': + fmtVal = dfmt.format(sec); + break; + case 'S': + fmtVal = dfmt.format(ms); + break; + case 'C': + fmtVal = dfmt.format(cs); + break; + case 'N': + fmtVal = dfmt.format(ns); + break; + default: + break; + } + + // Substitute the placeholder with the formatted value + String ph = new StringBuffer(fOpenBracket + pattern + fCloseBracket).toString(); + loc = result.indexOf(ph); + result.replace(loc, loc + length + fOpenBracket.length() + fCloseBracket.length(), fmtVal); + } + + return result.toString(); + } + + /** + * Parse a string according to the format pattern + * + * @param string the source string + * @param ref the reference (base) time + * @return the parsed value + * @throws ParseException if the string has an invalid format + */ + public long parseValue(final String string, final long ref) throws ParseException { + + // Trivial case + if (string == null || string.length() == 0) { + return 0; + } + + // The timestamp sub-components + long seconds = -1; + long millisec = 0; + long microsec = 0; + long nanosec = 0; + + // Since we are processing the fractional part, substitute it with + // its pattern so the base parser doesn't complain + StringBuilder sb = new StringBuilder(string); + int dot = string.indexOf('.'); + if (dot == -1) { + sb.append('.'); + dot = string.length(); + } + sb = new StringBuilder(string.substring(0, dot)); + String basePattern = super.toPattern(); + int dot2 = basePattern.indexOf('.'); + if (dot2 != -1) { + sb.append(basePattern.substring(dot2)); + } + + // Fill in our extensions + for (String pattern : fSupplPatterns) { + String pat = fOpenBracket + pattern + fCloseBracket; + Matcher matcher; + + // Extract the substring corresponding to the extra pattern letters + // and replace with the pattern so the base parser can do its job. + switch (pattern.charAt(0)) { + case 'T': + // Remove everything up to the first "." and compute the + // number of seconds since the epoch. If there is no period, + // assume an integer value and return immediately + if (dot < 1) { + return new DecimalFormat("0").parse(string).longValue() * 1000000000; //$NON-NLS-1$ + } + seconds = new DecimalFormat("0").parse(string.substring(0, dot)).longValue(); //$NON-NLS-1$ + sb.delete(0, dot); + sb.insert(0, pat); + break; + case 'S': + matcher = MILLISEC_PAT.matcher(string.substring(dot)); + if (matcher.find()) { + millisec = new Long(matcher.group(1)); + for (int l = matcher.group(1).length(); l < 3; l++) { + millisec *= 10; + } + } + stripQuotes(sb, pattern); + break; + case 'C': + matcher = MICROSEC_PAT.matcher(string.substring(dot)); + if (matcher.find()) { + microsec = new Long(matcher.group(2)); + for (int l = matcher.group(2).length(); l < 3; l++) { + microsec *= 10; + } + } + stripQuotes(sb, pattern); + break; + case 'N': + matcher = NANOSEC_PAT.matcher(string.substring(dot)); + if (matcher.find()) { + nanosec = new Long(matcher.group(3)); + for (int l = matcher.group(3).length(); l < 3; l++) { + nanosec *= 10; + } + } + stripQuotes(sb, pattern); + break; + default: + break; + } + } + + // If there was no "T" (thus not an interval), parse as a date + if (seconds == -1) { + Date baseDate = super.parse(sb.toString()); + + Calendar refTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$ + refTime.setTimeInMillis(ref / 1000000); + Calendar newTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$ + newTime.setTimeInMillis(baseDate.getTime()); + + int[] fields = new int[] { Calendar.YEAR, Calendar.DAY_OF_YEAR, Calendar.MONTH, Calendar.DATE, Calendar.HOUR, Calendar.MINUTE, Calendar.SECOND }; + for (int field : fields) { + int value = newTime.get(field); + // Do some adjustments... + if (field == Calendar.YEAR) { + value -= 1970; + } else if (field == Calendar.DATE || field == Calendar.DAY_OF_YEAR) { + value -= 1; + } + // ... and fill-in the empty fields + if (value == 0) { + newTime.set(field, refTime.get(field)); + } else if (field == Calendar.DAY_OF_YEAR) { + newTime.set(field, value); + } else { + break; // Get out as soon as we have a significant value + } + } + seconds = newTime.getTimeInMillis() / 1000; + } + + // Compute the value in ns + return seconds * 1000000000 + millisec * 1000000 + microsec * 1000 + nanosec; + } + + /** + * Parse a string according to the format pattern + * + * @param string the source string + * @return the parsed value + * @throws ParseException if the string has an invalid format + */ + public long parseValue(final String string) throws ParseException { + long result = parseValue(string, 0); + return result; + + } + + // ------------------------------------------------------------------------ + // Helper functions + // ------------------------------------------------------------------------ + + /** + * Copy the pattern but quote (bracket with "[&" and "&]") the + * TmfTimestampFormat specific tags so these fields are treated as + * comments by the base class. + * + * It also keeps track of the corresponding quoted fields so they can be + * properly populated later on (by format()). + * + * @param pattern the 'extended' pattern + * @return the quoted and bracketed pattern + */ + private String quoteSpecificTags(final String pattern) { + + StringBuffer result = new StringBuffer(); + + int length = pattern.length(); + boolean inQuote = false; + + for (int i = 0; i < length; i++) { + char c = pattern.charAt(i); + result.append(c); + if (c == '\'') { + // '' is treated as a single quote regardless of being + // in a quoted section. + if ((i + 1) < length) { + c = pattern.charAt(i + 1); + if (c == '\'') { + i++; + result.append(c); + continue; + } + } + inQuote = !inQuote; + continue; + } + if (!inQuote) { + if (fSupplPatternLetters.indexOf(c) != -1) { + StringBuilder pat = new StringBuilder(); + pat.append(c); + result.insert(result.length() - 1, "'" + fOpenBracket); //$NON-NLS-1$ + while ((i + 1) < length && pattern.charAt(i + 1) == c) { + result.append(c); + pat.append(c); + i++; + } + result.append(fCloseBracket + "'"); //$NON-NLS-1$ + fSupplPatterns.add(pat.toString()); + } + } + } + return result.toString(); + } + + /** + * Remove the quotes from the pattern + * + * @param sb + * @param pattern + */ + private void stripQuotes(StringBuilder sb, String pattern) { + String pt = "'" + fOpenBracket + pattern + fCloseBracket + "'"; //$NON-NLS-1$//$NON-NLS-2$ + int l = sb.indexOf(pt); + if (l != -1) { + sb.delete(l + pt.length() - 1, l + pt.length()); + sb.delete(l, l + 1); + } + } + +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfTimestampFormatUpdateSignal.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfTimestampFormatUpdateSignal.java new file mode 100644 index 0000000000..2b25fd0aab --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfTimestampFormatUpdateSignal.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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: + * Francois Chouinard - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.signal; + +/** + * The default timestamp/interval format was modified + * + * @author Francois Chouinard + * @version 1.0 + * @since 2.0 + */ +public class TmfTimestampFormatUpdateSignal extends TmfSignal { + + /** + * @param source the signal source + */ + public TmfTimestampFormatUpdateSignal(Object source) { + super(source); + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF index f71cfb087b..b2c1297886 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF @@ -7,10 +7,10 @@ Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.linuxtools.tmf.ui.tests;singleton:=true Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.junit;bundle-version="3.8.2", - org.eclipse.ui;bundle-version="3.7.0", - org.eclipse.core.runtime;bundle-version="3.7.0", - org.eclipse.core.resources;bundle-version="3.7.100", - org.eclipse.linuxtools.tmf.core;bundle-version="1.0.0", - org.eclipse.linuxtools.tmf.ui;bundle-version="1.0.0", - org.eclipse.linuxtools.tmf.core.tests;bundle-version="1.0.0" +Require-Bundle: org.junit;bundle-version="4.8.0", + org.eclipse.ui;bundle-version="3.8.0", + org.eclipse.core.runtime;bundle-version="3.8.0", + org.eclipse.core.resources;bundle-version="3.8.0", + org.eclipse.linuxtools.tmf.core;bundle-version="2.0.0", + org.eclipse.linuxtools.tmf.ui;bundle-version="2.0.0", + org.eclipse.linuxtools.tmf.core.tests;bundle-version="2.0.0" diff --git a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF index 735195e1f1..a808e1e704 100644 --- a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF @@ -8,14 +8,14 @@ Bundle-SymbolicName: org.eclipse.linuxtools.tmf.ui;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.tmf.ui.Activator Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.core.expressions, - org.eclipse.core.resources;bundle-version="3.7.100", - org.eclipse.core.runtime;bundle-version="3.7.0", - org.eclipse.linuxtools.tmf.core;bundle-version="1.0.0", - org.eclipse.ui;bundle-version="3.7.0", - org.eclipse.ui.ide;bundle-version="3.7.0", - org.eclipse.ui.navigator;bundle-version="3.5.100", - org.eclipse.ui.navigator.resources;bundle-version="3.4.300" +Require-Bundle: org.eclipse.core.expressions;bundle-version="3.4.400", + org.eclipse.core.resources;bundle-version="3.8.0", + org.eclipse.core.runtime;bundle-version="3.8.0", + org.eclipse.linuxtools.tmf.core;bundle-version="2.0.0", + org.eclipse.ui;bundle-version="3.8.0", + org.eclipse.ui.ide;bundle-version="3.8.0", + org.eclipse.ui.navigator;bundle-version="3.5.200", + org.eclipse.ui.navigator.resources;bundle-version="3.4.400" Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.linuxtools.tmf.ui.tests", org.eclipse.linuxtools.internal.tmf.ui.commands;x-internal:=true, org.eclipse.linuxtools.internal.tmf.ui.dialogs;x-internal:=true, diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.properties b/org.eclipse.linuxtools.tmf.ui/plugin.properties index 52a383a4cd..e97c34a4d4 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.properties +++ b/org.eclipse.linuxtools.tmf.ui/plugin.properties @@ -29,6 +29,7 @@ project.import.wizard.name = Trace Import # Preference page preference.page.trace.name = Tracing preference.page.uml2sd.name = UML2 Sequence Diagram +preferences.page.timestamp.format = Time Format ##Commands and Menus diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.xml b/org.eclipse.linuxtools.tmf.ui/plugin.xml index 01633367d0..ab4d7cb590 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui/plugin.xml @@ -1182,6 +1182,12 @@ id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewerPage" name="%preference.page.uml2sd.name"> + + diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Activator.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Activator.java index 7045eff6d4..97b9436865 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Activator.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Activator.java @@ -1,11 +1,11 @@ /******************************************************************************* * 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: * Francois Chouinard - Initial API and implementation *******************************************************************************/ @@ -17,6 +17,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.linuxtools.tmf.ui.properties.TmfTimePreferences; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -31,7 +32,7 @@ public class Activator extends AbstractUIPlugin { // ------------------------------------------------------------------------ /** - * The plug-in ID + * The plug-in ID */ public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf.ui"; //$NON-NLS-1$ @@ -77,6 +78,7 @@ public class Activator extends AbstractUIPlugin { plugin = this; TmfUiTracer.init(); TmfTraceElement.init(); + TmfTimePreferences.init(); } /* @@ -96,31 +98,31 @@ public class Activator extends AbstractUIPlugin { /** * Gets an image object using given path within plug-in. - * + * * @param path path to image file - * + * * @return image object */ public Image getImageFromPath(String path){ return getImageDescripterFromPath(path).createImage(); } - + /** * Gets an image descriptor using given path within plug-in. - * - * @param path path to image file - * + * + * @param path path to image file + * * @return image descriptor object */ public ImageDescriptor getImageDescripterFromPath(String path){ return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); } - + /** * Gets a image object from the image registry based on the given path. - * If the image is not in the registry it will be registered. - * - * @param path to the image file + * If the image is not in the registry it will be registered. + * + * @param path to the image file * @return image object */ public Image getImageFromImageRegistry(String path) { @@ -148,16 +150,16 @@ public class Activator extends AbstractUIPlugin { /** * Logs a message with severity INFO in the runtime log of the plug-in. - * + * * @param message A message to log */ public void logInfo(String message) { getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); } - + /** * Logs a message and exception with severity INFO in the runtime log of the plug-in. - * + * * @param message A message to log * @param exception A exception to log */ @@ -167,16 +169,16 @@ public class Activator extends AbstractUIPlugin { /** * Logs a message and exception with severity WARNING in the runtime log of the plug-in. - * + * * @param message A message to log */ public void logWarning(String message) { getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message)); } - + /** * Logs a message and exception with severity WARNING in the runtime log of the plug-in. - * + * * @param message A message to log * @param exception A exception to log */ @@ -186,16 +188,16 @@ public class Activator extends AbstractUIPlugin { /** * Logs a message and exception with severity ERROR in the runtime log of the plug-in. - * + * * @param message A message to log */ public void logError(String message) { getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); } - + /** * Logs a message and exception with severity ERROR in the runtime log of the plug-in. - * + * * @param message A message to log * @param exception A exception to log */ diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/properties/TmfTimePreferences.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/properties/TmfTimePreferences.java new file mode 100644 index 0000000000..15c6ca857f --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/properties/TmfTimePreferences.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * 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: + * Francois Chouinard - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.properties; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; + +/** + * TMF Time format preferences + * + * @version 1.0 + * @author Francois Chouinard + */ +@SuppressWarnings("javadoc") +public class TmfTimePreferences { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + public static final String DEFAULT_TIME_PATTERN = "HH:mm:ss.SSS_CCC_NNN"; //$NON-NLS-1$ + + static final String TIME_FORMAT_PREF = "org.eclipse.linuxtools.tmf.ui.prefs.time.format"; //$NON-NLS-1$ + static final String DATIME = TIME_FORMAT_PREF + ".datime"; //$NON-NLS-1$ + static final String SUBSEC = TIME_FORMAT_PREF + ".subsec"; //$NON-NLS-1$ + + static final String DATE_DELIMITER = TIME_FORMAT_PREF + ".date.delimiter"; //$NON-NLS-1$ + static final String TIME_DELIMITER = TIME_FORMAT_PREF + ".time.delimiter"; //$NON-NLS-1$ + static final String SSEC_DELIMITER = TIME_FORMAT_PREF + ".ssec.delimiter"; //$NON-NLS-1$ + + static final String DATE_YEAR_FMT = "yyyy-MM-dd HH:mm:ss"; //$NON-NLS-1$ + static final String DATE_YEAR2_FMT = "yy-MM-dd HH:mm:ss"; //$NON-NLS-1$ + static final String DATE_MONTH_FMT = "MM-dd HH:mm:ss"; //$NON-NLS-1$ + static final String DATE_DAY_FMT = "dd HH:mm:ss"; //$NON-NLS-1$ + static final String DATE_JDAY_FMT = "DDD HH:mm:ss"; //$NON-NLS-1$ + static final String DATE_NO_FMT = "HH:mm:ss"; //$NON-NLS-1$ + + static final String TIME_HOUR_FMT = "HH:mm:ss"; //$NON-NLS-1$ + static final String TIME_MINUTE_FMT = "mm:ss"; //$NON-NLS-1$ + static final String TIME_SECOND_FMT = "ss"; //$NON-NLS-1$ + static final String TIME_ELAPSED_FMT = "TTT"; //$NON-NLS-1$ + static final String TIME_NO_FMT = ""; //$NON-NLS-1$ + + static final String SUBSEC_MILLI_FMT = "SSS"; //$NON-NLS-1$ + static final String SUBSEC_MICRO_FMT = "SSS_CCC"; //$NON-NLS-1$ + static final String SUBSEC_NANO_FMT = "SSS_CCC_NNN"; //$NON-NLS-1$ + static final String SUBSEC_NO_FMT = ""; //$NON-NLS-1$ + + static final String DELIMITER_NONE = ""; //$NON-NLS-1$ + static final String DELIMITER_SPACE = " "; //$NON-NLS-1$ + static final String DELIMITER_PERIOD = "."; //$NON-NLS-1$ + static final String DELIMITER_COMMA = ","; //$NON-NLS-1$ + static final String DELIMITER_DASH = "-"; //$NON-NLS-1$ + static final String DELIMITER_UNDERLINE = "_"; //$NON-NLS-1$ + static final String DELIMITER_COLON = ":"; //$NON-NLS-1$ + static final String DELIMITER_SEMICOLON = ";"; //$NON-NLS-1$ + static final String DELIMITER_SLASH = "/"; //$NON-NLS-1$ + static final String DELIMITER_DQUOT = "\""; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private static TmfTimePreferences fPreferences; + + private static IPreferenceStore fPreferenceStore; + private static String fTimestampPattern; + private static String fIntervalPattern; + + private String fDatimeFormat; + private String fDateFormat; + private String fTimeFormat; + private String fSSecFormat; + + private String fDateFieldSep = "-"; //$NON-NLS-1$ + private String fTimeFieldSep = ":"; //$NON-NLS-1$ + private String fSSecFieldSep = " "; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Constructor + // ------------------------------------------------------------------------ + + public static void init() { + fPreferenceStore = Activator.getDefault().getPreferenceStore(); + fPreferenceStore.setDefault(TmfTimePreferences.DATIME, TIME_HOUR_FMT); + fPreferenceStore.setDefault(TmfTimePreferences.SUBSEC, SUBSEC_NANO_FMT); + fPreferenceStore.setDefault(TmfTimePreferences.DATE_DELIMITER, DELIMITER_DASH); + fPreferenceStore.setDefault(TmfTimePreferences.TIME_DELIMITER, DELIMITER_COLON); + fPreferenceStore.setDefault(TmfTimePreferences.SSEC_DELIMITER, DELIMITER_UNDERLINE); + + // Create the singleton and initialize format preferences + getInstance(); + } + + public static synchronized IPreferenceStore getPreferenceStore() { + if (fPreferenceStore == null) { + init(); + } + return fPreferenceStore; + } + + public static synchronized TmfTimePreferences getInstance() { + if (fPreferences == null) { + fPreferences = new TmfTimePreferences(); + } + return fPreferences; + } + + /** + * Local constructor + */ + private TmfTimePreferences() { + initPatterns(); + setTimePattern(fTimestampPattern); + } + + // ------------------------------------------------------------------------ + // Getters/Setters + // ------------------------------------------------------------------------ + + /** + * @return the timestamp pattern + */ + public static String getTimePattern() { + return fTimestampPattern; + } + + /** + * Sets the timestamp pattern and updates TmfTimestampFormat + * + * @param timePattern the new timestamp pattern + */ + static void setTimePattern(String timePattern) { + fTimestampPattern = timePattern; + TmfTimestampFormat.setDefaultTimeFormat(fTimestampPattern); + TmfTimestampFormat.setDefaultIntervalFormat(fIntervalPattern); + } + + /** + * Update the Date field separator + * @param pattern the Date field separator + */ + void setDateFieldSep(String pattern) { + fDateFieldSep = pattern; + } + + /** + * Update the Time field separator + * @param pattern the Time field separator + */ + void setTimeFieldSep(String pattern) { + fTimeFieldSep = pattern; + } + + /** + * Update the Subseconds field separator + * @param pattern the Subseconds field separator + */ + void setSSecFieldSep(String pattern) { + fSSecFieldSep = pattern; + } + + /** + * Update the Date/Time format + * @param pattern the Date/Time format + */ + void setDateTimeFormat(String pattern) { + fDatimeFormat = pattern; + if (fDatimeFormat == null) { + fDatimeFormat = DEFAULT_TIME_PATTERN; + } + int index = fDatimeFormat.indexOf(' '); + if (index != -1) { + fDateFormat = fDatimeFormat.substring(0, fDatimeFormat.indexOf(' ') + 1); + fTimeFormat = fDatimeFormat.substring(fDateFormat.length()); + } else { + fDateFormat = ""; //$NON-NLS-1$ + fTimeFormat = fDatimeFormat; + } + } + + /** + * Update the Subseconds format + * @param pattern the Subseconds format + */ + void setSSecFormat(String pattern) { + fSSecFormat = pattern; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + void initPatterns() { + setDateTimeFormat(fPreferenceStore.getString(DATIME)); + fSSecFormat = fPreferenceStore.getString(SUBSEC); + fDateFieldSep = fPreferenceStore.getString(DATE_DELIMITER); + fTimeFieldSep = fPreferenceStore.getString(TIME_DELIMITER); + fSSecFieldSep = fPreferenceStore.getString(SSEC_DELIMITER); + updatePatterns(); + } + + void updatePatterns() { + String dateFmt = fDateFormat.replaceAll("-", fDateFieldSep); //$NON-NLS-1$ + String timeFmt = fTimeFormat.replaceAll(":", fTimeFieldSep); //$NON-NLS-1$ + String ssecFmt = fSSecFormat.replaceAll("_", fSSecFieldSep); //$NON-NLS-1$ + + fTimestampPattern = dateFmt + timeFmt + "." + ssecFmt; //$NON-NLS-1$ + fIntervalPattern = "TTT." + ssecFmt; //$NON-NLS-1$ + } + + void setDefaults() { + setDateTimeFormat(TmfTimePreferences.TIME_HOUR_FMT); + setSSecFormat(TmfTimePreferences.SUBSEC_NANO_FMT); + setDateFieldSep(TmfTimePreferences.DELIMITER_DASH); + setTimeFieldSep(TmfTimePreferences.DELIMITER_COLON); + setSSecFieldSep(TmfTimePreferences.DELIMITER_UNDERLINE); + updatePatterns(); + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/properties/TmfTimestampFormatPage.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/properties/TmfTimestampFormatPage.java new file mode 100644 index 0000000000..29691a5399 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/properties/TmfTimestampFormatPage.java @@ -0,0 +1,325 @@ +/******************************************************************************* + * 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: + * Francois Chouinard - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.properties; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.preference.RadioGroupFieldEditor; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +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.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * The TMF timestamp format configuration page. This page is used to select + * the global timestamp and interval time formats (for display and parsing). + * The user can either pick a pre-defined format or enter his/her own. + * + * @version 1.0 + * @author Francois Chouinard + */ +public class TmfTimestampFormatPage extends PreferencePage implements IWorkbenchPreferencePage, SelectionListener, IPropertyChangeListener { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + // Date and Time formats + private static final String[][] fDateTimeFormats = new String[][] { + { TmfTimePreferences.DATE_YEAR_FMT, TmfTimePreferences.DATE_YEAR_FMT }, + { TmfTimePreferences.DATE_YEAR2_FMT, TmfTimePreferences.DATE_YEAR2_FMT }, + { TmfTimePreferences.DATE_MONTH_FMT, TmfTimePreferences.DATE_MONTH_FMT }, + { TmfTimePreferences.DATE_DAY_FMT, TmfTimePreferences.DATE_DAY_FMT }, + { TmfTimePreferences.DATE_JDAY_FMT, TmfTimePreferences.DATE_JDAY_FMT }, + { TmfTimePreferences.TIME_HOUR_FMT, TmfTimePreferences.TIME_HOUR_FMT }, + { TmfTimePreferences.TIME_MINUTE_FMT, TmfTimePreferences.TIME_MINUTE_FMT }, + { TmfTimePreferences.TIME_SECOND_FMT, TmfTimePreferences.TIME_SECOND_FMT }, + { TmfTimePreferences.TIME_ELAPSED_FMT + " (secs in epoch)", TmfTimePreferences.TIME_ELAPSED_FMT }, //$NON-NLS-1$ + { "(none)", TmfTimePreferences.TIME_NO_FMT }, //$NON-NLS-1$ + }; + + // Sub-second formats + private static final String[][] fSubSecondFormats = new String[][] { + { TmfTimePreferences.SUBSEC_MILLI_FMT + " (ms)", TmfTimePreferences.SUBSEC_MILLI_FMT }, //$NON-NLS-1$ + { TmfTimePreferences.SUBSEC_MICRO_FMT + " (µs)", TmfTimePreferences.SUBSEC_MICRO_FMT }, //$NON-NLS-1$ + { TmfTimePreferences.SUBSEC_NANO_FMT + " (ns)", TmfTimePreferences.SUBSEC_NANO_FMT }, //$NON-NLS-1$ + }; + + // Date and Time delimiters + private static final String[][] fDateTimeDelimiters = new String[][] { + { "(none)", TmfTimePreferences.DELIMITER_NONE }, //$NON-NLS-1$ + { " (space)", TmfTimePreferences.DELIMITER_SPACE }, //$NON-NLS-1$ + { ", (comma)", TmfTimePreferences.DELIMITER_COMMA }, //$NON-NLS-1$ + { "- (dash)", TmfTimePreferences.DELIMITER_DASH }, //$NON-NLS-1$ + { "_ (underline)", TmfTimePreferences.DELIMITER_UNDERLINE }, //$NON-NLS-1$ + { ": (colon)", TmfTimePreferences.DELIMITER_COLON }, //$NON-NLS-1$ + { "; (semicolon)", TmfTimePreferences.DELIMITER_SEMICOLON }, //$NON-NLS-1$ + { "/ (slash)", TmfTimePreferences.DELIMITER_SLASH }, //$NON-NLS-1$ + { "\" (dbl-quote)", TmfTimePreferences.DELIMITER_DQUOT }, //$NON-NLS-1$ + }; + + // Sub-Second delimiters + private static final String[][] fSubSecondDelimiters = new String[][] { + { "(none)", TmfTimePreferences.DELIMITER_NONE }, //$NON-NLS-1$ + { " (space)", TmfTimePreferences.DELIMITER_SPACE }, //$NON-NLS-1$ + { ", (comma)", TmfTimePreferences.DELIMITER_COMMA }, //$NON-NLS-1$ + { "- (dash)", TmfTimePreferences.DELIMITER_DASH }, //$NON-NLS-1$ + { "_ (underline)", TmfTimePreferences.DELIMITER_UNDERLINE }, //$NON-NLS-1$ + { ": (colon)", TmfTimePreferences.DELIMITER_COLON }, //$NON-NLS-1$ + { "; (semicolon)", TmfTimePreferences.DELIMITER_SEMICOLON }, //$NON-NLS-1$ + { "/ (slash)", TmfTimePreferences.DELIMITER_SLASH }, //$NON-NLS-1$ + { "\" (dbl-quote)", TmfTimePreferences.DELIMITER_DQUOT }, //$NON-NLS-1$ + { ". (period)", TmfTimePreferences.DELIMITER_PERIOD }, //$NON-NLS-1$ + }; + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // General stuff + private Composite fPage; + private IPreferenceStore fPreferenceStore; + private TmfTimePreferences fTimePreference; + + // Example section + private Composite fExampleSection; + private Text fPatternDisplay; + private Text fExampleDisplay; + private String fTimePattern; + + // Date/Time format section + private RadioGroupFieldEditor fDateTimeFields; + private RadioGroupFieldEditor fSSecFields; + + // Delimiters section + private RadioGroupFieldEditor fDateFieldDelim; + private RadioGroupFieldEditor fTimeFieldDelim; + private RadioGroupFieldEditor fSSecFieldDelim; + + // IPropertyChangeListener data + private String fProperty; + private String fChangedProperty; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * The default constructor + */ + public TmfTimestampFormatPage() { + fPreferenceStore = TmfTimePreferences.getPreferenceStore(); + fTimePreference = TmfTimePreferences.getInstance(); + } + + // ------------------------------------------------------------------------ + // IWorkbenchPreferencePage + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + */ + @Override + public void init(IWorkbench workbench) { + } + + // ------------------------------------------------------------------------ + // PreferencePage + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createContents(Composite parent) { + + // Overall preference page layout + parent.setLayout(new GridLayout()); + fPage = new Composite(parent, SWT.NONE); + fPage.setLayout(new GridLayout()); + fPage.setLayoutData(new GridData( + GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL)); + + // Example section + fExampleSection = new Composite(fPage, SWT.NONE); + fExampleSection.setLayout(new GridLayout(2, false)); + fExampleSection.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Label patternLabel = new Label(fExampleSection, SWT.HORIZONTAL); + patternLabel.setText("Current Format: "); //$NON-NLS-1$ + fPatternDisplay = new Text(fExampleSection, SWT.BORDER | SWT.READ_ONLY); + fPatternDisplay.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label exampleLabel = new Label(fExampleSection, SWT.NONE); + exampleLabel.setText("Sample Display: "); //$NON-NLS-1$ + fExampleDisplay = new Text(fExampleSection, SWT.BORDER | SWT.READ_ONLY); + fExampleDisplay.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label separator = new Label(fPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE); + separator.setLayoutData( + new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); + + // Date and Time section + fDateTimeFields = new RadioGroupFieldEditor( + TmfTimePreferences.DATIME, "Date and Time format", 3, fDateTimeFormats, fPage, true); //$NON-NLS-1$ + fDateTimeFields.setPreferenceStore(fPreferenceStore); + fDateTimeFields.load(); + fDateTimeFields.setPropertyChangeListener(this); + + // Sub-second section + fSSecFields = new RadioGroupFieldEditor( + TmfTimePreferences.SUBSEC, "Sub-second format", 3, fSubSecondFormats, fPage, true); //$NON-NLS-1$ + fSSecFields.setPreferenceStore(fPreferenceStore); + fSSecFields.load(); + fSSecFields.setPropertyChangeListener(this); + + // Separators section + fDateFieldDelim = new RadioGroupFieldEditor( + TmfTimePreferences.DATE_DELIMITER, "Date delimiter", 5, fDateTimeDelimiters, fPage, true); //$NON-NLS-1$ + fDateFieldDelim.setPreferenceStore(fPreferenceStore); + fDateFieldDelim.load(); + fDateFieldDelim.setPropertyChangeListener(this); + + fTimeFieldDelim = new RadioGroupFieldEditor( + TmfTimePreferences.TIME_DELIMITER, "Time delimiter", 5, fDateTimeDelimiters, fPage, true); //$NON-NLS-1$ + fTimeFieldDelim.setPreferenceStore(fPreferenceStore); + fTimeFieldDelim.load(); + fTimeFieldDelim.setPropertyChangeListener(this); + + fSSecFieldDelim = new RadioGroupFieldEditor( + TmfTimePreferences.SSEC_DELIMITER, "Sub-Second Delimiter", 5, fSubSecondDelimiters, fPage, true); //$NON-NLS-1$ + fSSecFieldDelim.setPreferenceStore(fPreferenceStore); + fSSecFieldDelim.load(); + fSSecFieldDelim.setPropertyChangeListener(this); + + fTimePreference.initPatterns(); + refresh(); + return fPage; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performDefaults() + */ + @Override + protected void performDefaults() { + fDateTimeFields.loadDefault(); + fSSecFields.loadDefault(); + fDateFieldDelim.loadDefault(); + fTimeFieldDelim.loadDefault(); + fSSecFieldDelim.loadDefault(); + + fTimePreference.setDefaults(); + fTimePattern = TmfTimePreferences.getTimePattern(); + displayExample(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performApply() + */ + @Override + protected void performApply() { + fDateTimeFields.store(); + fSSecFields.store(); + fDateFieldDelim.store(); + fTimeFieldDelim.store(); + fSSecFieldDelim.store(); + + TmfTimePreferences.setTimePattern(fTimePattern); + displayExample(); + } + + // ------------------------------------------------------------------------ + // SelectionListener + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + public void widgetSelected(SelectionEvent e) { + } + + /* (non-Javadoc) + * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + + // ------------------------------------------------------------------------ + // IPropertyChangeListener + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + @Override + public void propertyChange(PropertyChangeEvent event) { + Object source = event.getSource(); + Object value = event.getNewValue(); + if (source instanceof RadioGroupFieldEditor && value instanceof String && + !(value.equals(fChangedProperty) && source == fProperty)) + { + fProperty = ((RadioGroupFieldEditor) source).getPreferenceName(); + fChangedProperty = (String) value; + refresh(); + } + } + + // ------------------------------------------------------------------------ + // Helper functions + // ------------------------------------------------------------------------ + + private void refresh() { + updatePatterns(); + displayExample(); + } + + void updatePatterns() { + if (TmfTimePreferences.DATIME.equals(fProperty)) { + fTimePreference.setDateTimeFormat(fChangedProperty); + } else if (TmfTimePreferences.SUBSEC.equals(fProperty)) { + fTimePreference.setSSecFormat(fChangedProperty); + } else if (TmfTimePreferences.DATE_DELIMITER.equals(fProperty)) { + fTimePreference.setDateFieldSep(fChangedProperty); + } else if (TmfTimePreferences.TIME_DELIMITER.equals(fProperty)) { + fTimePreference.setTimeFieldSep(fChangedProperty); + } else if (TmfTimePreferences.SSEC_DELIMITER.equals(fProperty)) { + fTimePreference.setSSecFieldSep(fChangedProperty); + } + fTimePreference.updatePatterns(); + fTimePattern = TmfTimePreferences.getTimePattern(); + } + + private void displayExample() { + long ts = 1332170682500677380L; + fPatternDisplay.setText(fTimePattern); + fPatternDisplay.redraw(); + + fExampleDisplay.setText(new TmfTimestampFormat(fTimePattern).format(ts)); + fExampleDisplay.redraw(); + } + +} 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 3278d48b6f..b7f19527da 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 @@ -688,10 +688,13 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, fRawViewer.setMenu(menu); } + + @SuppressWarnings("unused") protected void appendToTablePopupMenu(final MenuManager tablePopupMenu, final TableItem selectedItem) { // override to append more actions } + @SuppressWarnings("unused") protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu) { // override to append more actions } @@ -1988,4 +1991,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, mb.open(); } + /** + * @since 2.0 + */ + public void refresh() { + fCache.clear(); + fTable.refresh(); + fTable.redraw(); + } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java index e71de7738f..144e64c4fe 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java @@ -42,6 +42,7 @@ import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; +import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType; @@ -426,4 +427,16 @@ public class TmfEventsView extends TmfView implements IResourceChangeListener, I } } } + + /** + * Update the display to use the updated timestamp format + * + * @param signal the incoming signal + * @since 2.0 + */ + @TmfSignalHandler + public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) { + fEventsTable.refresh(); + } + } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/FullTraceHistogram.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/FullTraceHistogram.java index 52b9f3990c..2819c885a4 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/FullTraceHistogram.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/FullTraceHistogram.java @@ -27,8 +27,8 @@ import org.eclipse.swt.widgets.Display; * A histogram widget that displays the event distribution of a whole trace. *

    * It also features a selected range window that can be dragged and zoomed. - * - * @version 1.0 + * + * @version 1.1 * @author Francois Chouinard */ public class FullTraceHistogram extends Histogram implements MouseMoveListener { @@ -46,7 +46,7 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener { private final HistogramZoom fZoom; - private long fRangeStartTime; + private long fRangeStartTime = 0L; private long fRangeDuration; // ------------------------------------------------------------------------ @@ -54,9 +54,9 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener { // ------------------------------------------------------------------------ /** - * Standard Constructor. - * - * @param view A reference to the parent histogram view + * Full Constructor + * + * @param view A reference to the parent histogram view * @param parent A reference to the parent composite */ public FullTraceHistogram(HistogramView view, Composite parent) { @@ -76,8 +76,8 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener { // ------------------------------------------------------------------------ /** - * Sets the time range of the full histogram. - * + * Sets the time range of the full histogram. + * * @param startTime A start time * @param endTime A end time */ @@ -87,9 +87,9 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener { /** * Sets the selected time range. - * - * @param startTime A start time - * @param duration A window duration + * + * @param startTime The histogram start time + * @param duration The histogram duration */ public void setTimeRange(long startTime, long duration) { fRangeStartTime = startTime; @@ -98,6 +98,9 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener { fDataModel.complete(); } + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.views.histogram.Histogram#updateTimeRange(long, long) + */ @Override public void updateTimeRange(long startTime, long endTime) { ((HistogramView) fParentView).updateTimeRange(startTime, endTime); @@ -115,7 +118,7 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener { fMouseDown = true; fStartPosition = event.x; } - + @Override public void mouseUp(MouseEvent event) { if (fMouseDown) { @@ -125,13 +128,13 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener { super.mouseDown(event); return; } - + ((HistogramView) fParentView).updateTimeRange(fRangeStartTime, fRangeStartTime + fZoom.getDuration()); } } - - + + // ------------------------------------------------------------------------ // MouseMoveListener // ------------------------------------------------------------------------ @@ -171,7 +174,7 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener { GC rangeWindowGC = new GC(rangeRectangleImage); if ((fScaledData != null) && (fRangeStartTime != 0)) { - drawTimeRangeWindow(rangeWindowGC, rangeRectangleImage); + drawTimeRangeWindow(rangeWindowGC); } // Draws the buffer image onto the canvas. @@ -181,10 +184,10 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener { rangeRectangleImage.dispose(); } - private void drawTimeRangeWindow(GC imageGC, Image image) { + private void drawTimeRangeWindow(GC imageGC) { // Map times to histogram coordinates - long bucketSpan = Math.max(fScaledData.fBucketDuration,1); + long bucketSpan = Math.max(fScaledData.fBucketDuration, 1); int rangeWidth = (int) (fRangeDuration / bucketSpan); int left = (int) ((fRangeStartTime - fDataModel.getFirstBucketTime()) / bucketSpan); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java index 5b26514a32..16c0e3e0a5 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java @@ -9,11 +9,17 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Bernd Hufmann - Changed to updated histogram data model - * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Reformat histogram labels on format change *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.views.histogram; +import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; +import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; import org.eclipse.linuxtools.tmf.ui.views.TmfView; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlEvent; @@ -30,6 +36,8 @@ import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; 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.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -72,7 +80,7 @@ import org.eclipse.swt.widgets.Text; *

  • number of events in that time range * * - * @version 1.0 + * @version 1.1 * @author Francois Chouinard */ public abstract class Histogram implements ControlListener, PaintListener, KeyListener, MouseListener, MouseTrackListener, IHistogramModelListener { @@ -87,27 +95,18 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi private final Color fLastEventColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED); private final Color fHistoBarColor = new Color(Display.getDefault(), 74, 112, 139); - // Timestamp scale (nanosecond) - /** - * The time scale of the histogram (nano seconds) - */ - public static final byte TIME_SCALE = -9; - - /** - * The histogram bar width (number of pixels). - */ - public static final int HISTOGRAM_BAR_WIDTH = 1; - // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ - // Owner view /** * The parent TMF view. */ protected TmfView fParentView; + private Composite fParent; + private Font fFont; + // Histogram text fields private Text fMaxNbEventsText; private Text fMinNbEventsText; @@ -118,29 +117,35 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi * Histogram drawing area */ protected Canvas fCanvas; + /** * The histogram data model. */ protected final HistogramDataModel fDataModel; + /** * The histogram data model scaled to current resolution and screen width. */ protected HistogramScaledData fScaledData; - protected long fCurrentEventTime = 0; + /** + * The current event value + */ + protected long fCurrentEventTime = 0L; // ------------------------------------------------------------------------ // Construction // ------------------------------------------------------------------------ /** - * Standard constructor. + * Full constructor. * * @param view A reference to the parent TMF view. * @param parent A parent composite */ public Histogram(final TmfView view, final Composite parent) { fParentView = view; + fParent = parent; createWidget(parent); fDataModel = new HistogramDataModel(); @@ -152,12 +157,16 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi fCanvas.addKeyListener(this); fCanvas.addMouseListener(this); fCanvas.addMouseTrackListener(this); + + TmfSignalManager.register(this); } /** - * Dispose resources and deregisters listeners. + * Dispose resources and unregisters listeners. */ public void dispose() { + TmfSignalManager.deregister(this); + fHistoBarColor.dispose(); fDataModel.removeHistogramListener(this); } @@ -165,7 +174,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi private void createWidget(final Composite parent) { final Color labelColor = parent.getBackground(); - final Font fFont = adjustFont(parent); + fFont = adjustFont(parent); final int initalWidth = 10; @@ -244,7 +253,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi fTimeRangeStartText = new Text(composite, SWT.READ_ONLY); fTimeRangeStartText.setFont(fFont); fTimeRangeStartText.setBackground(labelColor); - fTimeRangeStartText.setText(HistogramUtils.nanosecondsToString(0)); + fTimeRangeStartText.setText(TmfTimestamp.ZERO.toString()); fTimeRangeStartText.setLayoutData(gridData); // Window range end time @@ -254,7 +263,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi fTimeRangeEndText = new Text(composite, SWT.READ_ONLY); fTimeRangeEndText.setFont(fFont); fTimeRangeEndText.setBackground(labelColor); - fTimeRangeEndText.setText(HistogramUtils.nanosecondsToString(0)); + fTimeRangeEndText.setText(TmfTimestamp.ZERO.toString()); fTimeRangeEndText.setLayoutData(gridData); } @@ -271,7 +280,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // ------------------------------------------------------------------------ /** - * Returns the start time (equal first bucket time). + * Returns the start time (equal first bucket time) * @return the start time. */ public long getStartTime() { @@ -449,13 +458,13 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi return; } fDataModel.setCurrentEvent(fCurrentEventTime); - fScaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, HISTOGRAM_BAR_WIDTH); + fScaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, 1); synchronized(fScaledData) { if (fScaledData != null) { fCanvas.redraw(); // Display histogram and update X-,Y-axis labels - fTimeRangeStartText.setText(HistogramUtils.nanosecondsToString(fDataModel.getFirstBucketTime())); - fTimeRangeEndText.setText(HistogramUtils.nanosecondsToString(fDataModel.getEndTime())); + fTimeRangeStartText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime())); + fTimeRangeEndText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime())); fMaxNbEventsText.setText(Long.toString(fScaledData.fMaxValue)); // The Y-axis area might need to be re-sized fMaxNbEventsText.getParent().layout(); @@ -627,9 +636,9 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi final StringBuffer buffer = new StringBuffer(); buffer.append("Range = ["); //$NON-NLS-1$ - buffer.append(HistogramUtils.nanosecondsToString(startTime)); + buffer.append(new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE).toString()); buffer.append(","); //$NON-NLS-1$ - buffer.append(HistogramUtils.nanosecondsToString(endTime)); + buffer.append(new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE).toString()); buffer.append(")\n"); //$NON-NLS-1$ buffer.append("Event count = "); //$NON-NLS-1$ buffer.append(nbEvents); @@ -649,4 +658,55 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi public void controlResized(final ControlEvent event) { fDataModel.complete(); } + + // ------------------------------------------------------------------------ + // Signal Handlers + // ------------------------------------------------------------------------ + + /** + * Format the timestamp and update the display + * + * @param signal the incoming signal + * @since 2.0 + */ + @TmfSignalHandler + public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) { + Point size = fTimeRangeStartText.getSize(); + String newTS = TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime()); + size.x = getTextSize(newTS); + fTimeRangeStartText.setSize(size); + fTimeRangeStartText.setText(newTS); + + newTS = TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime()); + Rectangle rect = fTimeRangeEndText.getBounds(); + int newWidth = getTextSize(newTS); + rect.x += rect.width - newWidth; + rect.width = newWidth; + fTimeRangeEndText.setBounds(rect); + fTimeRangeEndText.setText(newTS); + } + + /** + * Compute the width of a String. + * + * @param text the Text to measure + * @return The result size + * @since 2.0 + */ + private int getTextSize(final String text) { + GC controlGC = new GC(fParent); + controlGC.setFont(fFont); + + int textSize = 0; + for (int pos = 0; pos < text.length(); pos++) { + textSize += controlGC.getAdvanceWidth(text.charAt(pos)); + } + // Add an extra space + textSize += controlGC.getAdvanceWidth(' '); + + controlGC.dispose(); + + return textSize; + } + } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramCurrentTimeControl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramCurrentTimeControl.java index f995664cad..018d5d93f0 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramCurrentTimeControl.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramCurrentTimeControl.java @@ -9,50 +9,64 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Moved from LTTng to TMF + * Francois Chouinard - Simplified constructor, handle interval format change *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.views.histogram; +import java.text.ParseException; + +import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; +import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; +import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; import org.eclipse.swt.widgets.Composite; /** * This control provides a group containing a text control. * - * @version 1.0 + * @version 1.1 * @author Francois Chouinard */ public class HistogramCurrentTimeControl extends HistogramTextControl { + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private long fExperimentStartTime; + // ------------------------------------------------------------------------ // Construction // ------------------------------------------------------------------------ /** - * Constructor with default group and text value. + * Standard constructor * * @param parentView A parent histogram view * @param parent A parent composite to draw in - * @param textStyle A test style - * @param groupStyle A group style + * @param groupLabel A group value + * @param value A value + * @since 2.0 */ - public HistogramCurrentTimeControl(HistogramView parentView, Composite parent, int textStyle, int groupStyle) { - this(parentView, parent, textStyle, groupStyle, "", HistogramUtils.nanosecondsToString(0L)); //$NON-NLS-1$ + public HistogramCurrentTimeControl(HistogramView parentView, Composite parent, + String groupLabel, long value) + { + super(parentView, parent, groupLabel, value); + TmfSignalManager.register(this); } - /** - * - * Constructor - * @param parentView A parent histogram view - * @param parent A parent composite to draw in - * @param textStyle A test style - * @param groupStyle A group style - * @param groupValue A group value - * @param textValue A text value + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramTextControl#dispose() */ - public HistogramCurrentTimeControl(HistogramView parentView, Composite parent, int textStyle, int groupStyle, String groupValue, String textValue) { - super(parentView, parent, textStyle, groupStyle, groupValue, textValue); + @Override + public void dispose() { + TmfSignalManager.deregister(this); } // ------------------------------------------------------------------------ @@ -61,16 +75,20 @@ public class HistogramCurrentTimeControl extends HistogramTextControl { @Override protected void updateValue() { - String stringValue = fTextValue.getText(); - long value = HistogramUtils.stringToNanoseconds(stringValue); + String string = fTextValue.getText(); + long value = 0; + try { + value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, fExperimentStartTime); + } catch (ParseException e) { + } if (getValue() != value) { // Make sure that the new time is within range TmfExperiment exp = TmfExperiment.getCurrentExperiment(); if (exp != null) { TmfTimeRange range = exp.getTimeRange(); - long startTime = range.getStartTime().normalize(0, -9).getValue(); - long endTime = range.getEndTime().normalize(0, -9).getValue(); + long startTime = range.getStartTime().getValue(); + long endTime = range.getEndTime().getValue(); if (value < startTime) { value = startTime; } else if (value > endTime) { @@ -84,4 +102,40 @@ public class HistogramCurrentTimeControl extends HistogramTextControl { } } + @Override + public void setValue(long time) { + super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString()); + } + + // ------------------------------------------------------------------------ + // Signal Handlers + // ------------------------------------------------------------------------ + + /** + * Update the initial time value + * + * @param signal the time range signal + * @since 2.0 + */ + @TmfSignalHandler + public void experimentRangeUpdated(final TmfExperimentUpdatedSignal signal) { + fExperimentStartTime = signal.getExperiment().getTimeRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + } + + // ------------------------------------------------------------------------ + // Signal Handlers + // ------------------------------------------------------------------------ + + /** + * Format the timestamp and update the display. Compute the new text size, + * adjust the text and group widgets and then refresh the view layout. + * + * @param signal the incoming signal + * @since 2.0 + */ + @TmfSignalHandler + public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) { + setValue(getValue()); + } + } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java index 0e10f58739..30ad107c99 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.ListenerList; /** * Histogram-independent data model. - * + * * It has the following characteristics: *
      *
    • The basetime is the timestamp of the first event @@ -57,7 +57,7 @@ import org.eclipse.core.runtime.ListenerList; * respect to to the number of pixels in the actual histogram, we should achieve * a nice result when visualizing the histogram. *

      - * + * * @version 1.0 * @author Francois Chouinard */ @@ -73,7 +73,7 @@ public class HistogramDataModel implements IHistogramDataModel { public static final int DEFAULT_NUMBER_OF_BUCKETS = 16 * 1000; /** - * Number of events after which listeners will be notified. + * Number of events after which listeners will be notified. */ public static final int REFRESH_FREQUENCY = DEFAULT_NUMBER_OF_BUCKETS; @@ -195,7 +195,7 @@ public class HistogramDataModel implements IHistogramDataModel { } /** - * Returns the time of the current event in the model. + * Returns the time of the current event in the model. * @return the time of the current event. */ public long getCurrentEventTime() { @@ -230,7 +230,7 @@ public class HistogramDataModel implements IHistogramDataModel { fModelListeners.remove(listener); } - // Notify listeners (always) + // Notify listeners (always) private void fireModelUpdateNotification() { fireModelUpdateNotification(0); } @@ -271,13 +271,13 @@ public class HistogramDataModel implements IHistogramDataModel { fLastEventTime = 0; fCurrentEventTime = 0; fLastBucket = 0; - fBucketDuration = 1; // 1ns + fBucketDuration = 1; updateEndTime(); fireModelUpdateNotification(); } /** - * Sets the current event time (no notification of listeners) + * Sets the current event time (no notification of listeners) * * @param timestamp A time stamp to set. */ @@ -286,7 +286,7 @@ public class HistogramDataModel implements IHistogramDataModel { } /** - * Sets the current event time with notification of listeners + * Sets the current event time with notification of listeners * * @param timestamp A time stamp to set. */ @@ -300,7 +300,7 @@ public class HistogramDataModel implements IHistogramDataModel { * * @param eventCount The current event Count (for notification purposes) * @param timestamp The timestamp of the event to count - * + * */ @Override public void countEvent(long eventCount, long timestamp) { @@ -369,7 +369,7 @@ public class HistogramDataModel implements IHistogramDataModel { * @param height A height of the histogram canvas * @param barWidth A width (in pixel) of a histogram bar * @return the result array of size [width] and where the highest value doesn't exceed [height] - * + * * @see org.eclipse.linuxtools.tmf.ui.views.histogram.IHistogramDataModel#scaleTo(int, int, int) */ @Override diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramTextControl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramTextControl.java index 6fd482ff94..3b77e26abc 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramTextControl.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramTextControl.java @@ -1,19 +1,21 @@ /******************************************************************************* * Copyright (c) 2009, 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: * Wiliam Bourque - Adapted from SpinnerGroup (in TimeFrameView) * Francois Chouinard - Cleanup and refactoring * Francois Chouinard - Moved from LTTng to TMF - *******************************************************************************/ + * Francois Chouinard - Better handling of control display, support for signals + *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.views.histogram; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; @@ -30,8 +32,8 @@ import org.eclipse.swt.widgets.Text; /** * This control provides a group containing a text control. - * - * @version 1.0 + * + * @version 1.1 * @author Francois Chouinard */ public abstract class HistogramTextControl implements FocusListener, KeyListener { @@ -44,45 +46,34 @@ public abstract class HistogramTextControl implements FocusListener, KeyListener * The parent histogram view. */ protected final HistogramView fParentView; - private final Composite fParent; - // Controls + // Controls data + private final Composite fParent; + private Font fFont; private final Group fGroup; + /** * The text value field. */ protected final Text fTextValue; + private long fValue; // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ - /** - * Constructor default values - * - * @param parentView The parent histogram view. - * @param parent The parent composite - * @param textStyle The text style bits. - * @param groupStyle The group style bits. - * - */ - public HistogramTextControl(HistogramView parentView, Composite parent, int textStyle, int groupStyle) { - this(parentView, parent, textStyle, groupStyle, "", HistogramUtils.nanosecondsToString(0L)); //$NON-NLS-1$ - } - /** * Constructor with given group and text values. - * + * * @param parentView The parent histogram view. * @param parent The parent composite - * @param textStyle The text style bits. - * @param groupStyle The group style bits. - * @param groupValue A group value - * @param textValue A text value + * @param label The text label + * @param value The initial value + * @since 2.0 */ - public HistogramTextControl(HistogramView parentView, Composite parent, int textStyle, int groupStyle, String groupValue, String textValue) { - + public HistogramTextControl(HistogramView parentView, Composite parent, String label, long value) + { fParentView = parentView; fParent = parent; @@ -93,15 +84,7 @@ public abstract class HistogramTextControl implements FocusListener, KeyListener final int fontSizeAdjustment = -1; final Font font = parent.getFont(); final FontData fontData = font.getFontData()[0]; - final Font adjustedFont = new Font(font.getDevice(), fontData.getName(), fontData.getHeight() + fontSizeAdjustment, fontData.getStyle()); - - // -------------------------------------------------------------------- - // Pre-compute the size of the control - // -------------------------------------------------------------------- - - final String longestStringValue = "." + Long.MAX_VALUE; //$NON-NLS-1$ - final int maxChars = longestStringValue.length(); - final int textBoxSize = HistogramUtils.getTextSizeInControl(parent, longestStringValue); + fFont = new Font(font.getDevice(), fontData.getName(), fontData.getHeight() + fontSizeAdjustment, fontData.getStyle()); // -------------------------------------------------------------------- // Create the group @@ -112,23 +95,20 @@ public abstract class HistogramTextControl implements FocusListener, KeyListener GridData gridData; // Group control - gridLayout = new GridLayout(1, false); + gridLayout = new GridLayout(1, true); gridLayout.horizontalSpacing = 0; gridLayout.verticalSpacing = 0; - fGroup = new Group(fParent, groupStyle); - fGroup.setText(groupValue); - fGroup.setFont(adjustedFont); + fGroup = new Group(fParent, SWT.DEFAULT); + fGroup.setText(label); + fGroup.setFont(fFont); fGroup.setLayout(gridLayout); // Group control gridData = new GridData(SWT.LEFT, SWT.CENTER, true, false); gridData.horizontalIndent = 0; gridData.verticalIndent = 0; - gridData.minimumWidth = textBoxSize; - fTextValue = new Text(fGroup, textStyle); - fTextValue.setTextLimit(maxChars); - fTextValue.setText(textValue); - fTextValue.setFont(adjustedFont); + fTextValue = new Text(fGroup, SWT.BORDER); + fTextValue.setFont(fFont); fTextValue.setLayoutData(gridData); // -------------------------------------------------------------------- @@ -137,6 +117,16 @@ public abstract class HistogramTextControl implements FocusListener, KeyListener fTextValue.addFocusListener(this); fTextValue.addKeyListener(this); + + TmfSignalManager.register(this); + } + + /** + * Dispose of the widget + * @since 2.0 + */ + public void dispose() { + TmfSignalManager.deregister(this); } // ------------------------------------------------------------------------ @@ -145,7 +135,7 @@ public abstract class HistogramTextControl implements FocusListener, KeyListener /** * Returns if widget isDisposed or not - * @return true if widget is disposed else false + * @return true if widget is disposed else false */ public boolean isDisposed() { return fGroup.isDisposed(); @@ -169,40 +159,40 @@ public abstract class HistogramTextControl implements FocusListener, KeyListener } /** - * Sets the value converted to nano-seconds in the text field. - * @param timeString the time string (input) - */ - public void setValue(String timeString) { - long timeValue = HistogramUtils.stringToNanoseconds(timeString); - setValue(timeValue); - } - - /** - * The time value in nano-seconds to set in the text field. + * The time value in to set in the text field. + * * @param time the time to set + * @param displayTime the display value + * @since 2.0 */ - public void setValue(final long time) { + protected void setValue(final long time, final String displayTime) { // If this is the UI thread, process now Display display = Display.getCurrent(); if (display != null) { fValue = time; - fTextValue.setText(HistogramUtils.nanosecondsToString(time)); + fTextValue.setText(displayTime); + fParent.getParent().layout(); return; } - // Call "recursively" from the UI thread + // Call self from the UI thread if (!isDisposed()) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { if (!isDisposed()) { - setValue(time); + setValue(time, displayTime); } } }); } } - + + /** + * @param time the time value to display + */ + public abstract void setValue(long time); + /** * Returns the time value. * @return time value. diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramTimeRangeControl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramTimeRangeControl.java index 2b436bbefd..5a8c5cedfe 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramTimeRangeControl.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramTimeRangeControl.java @@ -1,24 +1,33 @@ /******************************************************************************* * Copyright (c) 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: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Moved from LTTng to TMF + * Francois Chouinard - Simplified constructor, handle interval format change *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.views.histogram; +import java.text.ParseException; + +import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; +import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; import org.eclipse.swt.widgets.Composite; /** * This control provides a group containing a text control. - * - * @version 1.0 + * + * @version 2.0 * @author Francois Chouinard */ public class HistogramTimeRangeControl extends HistogramTextControl { @@ -26,29 +35,29 @@ public class HistogramTimeRangeControl extends HistogramTextControl { // ------------------------------------------------------------------------ // Construction // ------------------------------------------------------------------------ + /** - * Constructor default values + * Constructor with given group and text values. + * * @param parentView The parent histogram view. * @param parent The parent composite - * @param textStyle The text style bits. - * @param groupStyle The group style bits. + * @param groupLabel A group value + * @param value A text value + * @since 2.0 */ - public HistogramTimeRangeControl(HistogramView parentView, Composite parent, int textStyle, int groupStyle) { - this(parentView, parent, textStyle, groupStyle, "", HistogramUtils.nanosecondsToString(0L)); //$NON-NLS-1$ + public HistogramTimeRangeControl(HistogramView parentView, Composite parent, + String groupLabel, long value) + { + super(parentView, parent, groupLabel, value); + TmfSignalManager.register(this); } - /** - * Constructor with given group and text values. - * - * @param parentView The parent histogram view. - * @param parent The parent composite - * @param textStyle The text style bits. - * @param groupStyle The group style bits. - * @param groupValue A group value - * @param textValue A text value + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramTextControl#dispose() */ - public HistogramTimeRangeControl(HistogramView parentView, Composite parent, int textStyle, int groupStyle, String groupValue, String textValue) { - super(parentView, parent, textStyle, groupStyle, groupValue, textValue); + @Override + public void dispose() { + TmfSignalManager.deregister(this); } // ------------------------------------------------------------------------ @@ -61,12 +70,35 @@ public class HistogramTimeRangeControl extends HistogramTextControl { */ @Override protected void updateValue() { - String stringValue = fTextValue.getText(); - long value = HistogramUtils.stringToNanoseconds(stringValue); - - if (getValue() != value) { - fParentView.updateTimeRange(value); + String string = fTextValue.getText(); + long value = getValue(); + try { + value = TmfTimestampFormat.getDefaulIntervalFormat().parseValue(string); + } catch (ParseException e) { } + fParentView.updateTimeRange(value); + } + + @Override + public void setValue(long time) { + ITmfTimestamp ts = new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE); + super.setValue(time, ts.toString(TmfTimestampFormat.getDefaulIntervalFormat())); + } + + // ------------------------------------------------------------------------ + // Signal Handlers + // ------------------------------------------------------------------------ + + /** + * Format the interval and update the display. Compute the new text size, + * adjust the text and group widgets and then refresh the view layout. + * + * @param signal the incoming signal + * @since 2.0 + */ + @TmfSignalHandler + public void intervalFormatUpdated(TmfTimestampFormatUpdateSignal signal) { + setValue(getValue()); } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramUtils.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramUtils.java deleted file mode 100644 index f0516fda75..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramUtils.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 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: - * William Bourque - Initial API and implementation - * Francois Chouinard - Cleanup and refactoring - * Francois Chouinard - Moved from LTTng to TMF - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.views.histogram; - -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.widgets.Composite; - -/** - * Bunch of conversion utilities. - * - * @version 1.0 - * @author Francois Chouinard - *

      - */ -public abstract class HistogramUtils { - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * Format a long representing nanoseconds into a string of the form - * "[seconds].[nanoseconds]" with the appropriate zero-padding. - *

      - * - * @param ns - * the timestamp in nanoseconds - * @return the formatted string - */ - public static String nanosecondsToString(long ns) { - ns = Math.abs(ns); - String time = Long.toString(ns); - - int length = time.length(); - if (time.length() > 9) { - // Just insert the decimal dot - time = time.substring(0, length - 9) - + "." + time.substring(length - 9); //$NON-NLS-1$ - return time; - } - - // Zero-pad the value - for (int i = length; i < 9; i++) { - time = "0" + time; //$NON-NLS-1$ - } - time = "0." + time; //$NON-NLS-1$ - return time; - } - - /** - * Convert a string representing a time to the corresponding long. - *

      - * - * @param time - * the string to convert - * @return the corresponding nanoseconds value - */ - public static long stringToNanoseconds(String time) { - - long result = 0L; - StringBuffer buffer = new StringBuffer(time); - - try { - int dot = buffer.indexOf("."); //$NON-NLS-1$ - - // if no . was found, assume ns - if (dot == -1) { - // nanoseconds are the base unit. - if (time.length() > 9) { - long nanos = Long - .parseLong(time.substring(time.length() - 9)); - long secs = Long.parseLong(time.substring(0, - time.length() - 9)); - result = (secs * 1000000000) + nanos; - } else { - result = Long.parseLong(time); - } - - } else { - // Zero-pad the string for nanoseconds - for (int i = buffer.length() - dot - 1; i < 9; i++) { - buffer.append("0"); //$NON-NLS-1$ - } - - // Remove the extra decimals if present - int nbDecimals = buffer.substring(dot + 1).length(); - if (nbDecimals > 9) { - buffer.delete(buffer.substring(0, dot + 1 + 9).length(), - buffer.length()); - } - - // Do the conversion - long seconds = (dot > 0) ? Long.parseLong(buffer.substring(0, - dot)) : 0; - seconds = Math.abs(seconds); - long nanosecs = Long.parseLong(buffer.substring(dot + 1)); - result = (seconds * 1000000000) + nanosecs; - } - } catch (NumberFormatException e) { - // TODO: Find something interesting to say - } - - return result; - } - - /** - * Calculate the width of a String. - *

      - * - * @param parent - * The control used as reference - * @param text - * The Text to measure - * - * @return The result size - */ - public static int getTextSizeInControl(Composite parent, String text) { - - GC controlGC = new GC(parent); - - int textSize = 0; - for (int pos = 0; pos < text.length(); pos++) { - textSize += controlGC.getAdvanceWidth(text.charAt(pos)); - } - // Add an extra space - textSize += controlGC.getAdvanceWidth(' '); - - controlGC.dispose(); - - return textSize; - } - -} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java index 927ab951f0..958e1ce027 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java @@ -50,7 +50,7 @@ import org.eclipse.swt.widgets.Composite; *

    * The histograms x-axis show their respective time range. * - * @version 1.0 + * @version 2.0 * @author Francois Chouinard */ public class HistogramView extends TmfView { @@ -69,9 +69,6 @@ public class HistogramView extends TmfView { */ public static final long INITIAL_WINDOW_SPAN = (1L * 100 * 1000 * 1000); // .1sec - // Time scale - private final byte TIME_SCALE = Histogram.TIME_SCALE; - // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ @@ -82,7 +79,7 @@ public class HistogramView extends TmfView { // The current experiment private TmfExperiment fCurrentExperiment; - // Current timestamp/time window + // Current timestamp/time window - everything in the TIME_SCALE private long fExperimentStartTime; private long fExperimentEndTime; private long fWindowStartTime; @@ -123,6 +120,8 @@ public class HistogramView extends TmfView { } fFullTraceHistogram.dispose(); fTimeRangeHistogram.dispose(); + fCurrentEventTimeControl.dispose(); + fTimeSpanControl.dispose(); super.dispose(); } @@ -170,7 +169,7 @@ public class HistogramView extends TmfView { gridLayout.marginWidth = 0; gridLayout.horizontalSpacing = 5; gridLayout.verticalSpacing = 0; - gridLayout.makeColumnsEqualWidth = true; + gridLayout.makeColumnsEqualWidth = false; gridLayout.marginLeft = 5; gridLayout.marginRight = 5; controlsComposite.setLayout(gridLayout); @@ -179,17 +178,17 @@ public class HistogramView extends TmfView { gridData = new GridData(); gridData.horizontalAlignment = SWT.CENTER; gridData.verticalAlignment = SWT.CENTER; - fCurrentEventTimeControl = new HistogramCurrentTimeControl(this, controlsComposite, SWT.BORDER, SWT.NONE, - currentEventLabel, HistogramUtils.nanosecondsToString(0L)); + fCurrentEventTimeControl = new HistogramCurrentTimeControl(this, controlsComposite, currentEventLabel, 0L); fCurrentEventTimeControl.setLayoutData(gridData); + fCurrentEventTimeControl.setValue(0L); // Window span time control gridData = new GridData(); gridData.horizontalAlignment = SWT.CENTER; gridData.verticalAlignment = SWT.CENTER; - fTimeSpanControl = new HistogramTimeRangeControl(this, controlsComposite, SWT.BORDER, SWT.NONE, - windowSpanLabel, HistogramUtils.nanosecondsToString(0L)); + fTimeSpanControl = new HistogramTimeRangeControl(this, controlsComposite, windowSpanLabel, 0L); fTimeSpanControl.setLayoutData(gridData); + fTimeSpanControl.setValue(0L); // -------------------------------------------------------------------- // Time range histogram @@ -261,6 +260,10 @@ public class HistogramView extends TmfView { fParent.redraw(); } + void refresh() { + fParent.layout(true); + } + // ------------------------------------------------------------------------ // Accessors // ------------------------------------------------------------------------ @@ -271,8 +274,9 @@ public class HistogramView extends TmfView { * @return the time range of current selected window. */ public TmfTimeRange getTimeRange() { - return new TmfTimeRange(new TmfTimestamp(fWindowStartTime, TIME_SCALE), new TmfTimestamp(fWindowEndTime, - TIME_SCALE)); + return new TmfTimeRange( + new TmfTimestamp(fWindowStartTime, ITmfTimestamp.NANOSECOND_SCALE), + new TmfTimestamp(fWindowEndTime, ITmfTimestamp.NANOSECOND_SCALE)); } // ------------------------------------------------------------------------ @@ -283,9 +287,9 @@ public class HistogramView extends TmfView { * Broadcast TmfSignal about new current time value. * @param newTime the new current time. */ - public void updateCurrentEventTime(long newTime) { + void updateCurrentEventTime(long newTime) { if (fCurrentExperiment != null) { - TmfTimeRange timeRange = new TmfTimeRange(new TmfTimestamp(newTime, TIME_SCALE), TmfTimestamp.BIG_CRUNCH); + TmfTimeRange timeRange = new TmfTimeRange(new TmfTimestamp(newTime, ITmfTimestamp.NANOSECOND_SCALE), TmfTimestamp.BIG_CRUNCH); HistogramRequest request = new HistogramRequest(fTimeRangeHistogram.getDataModel(), timeRange, 0, 1, 0, ExecutionType.FOREGROUND) { @Override public void handleData(ITmfEvent event) { @@ -304,13 +308,13 @@ public class HistogramView extends TmfView { * @param startTime the new start time * @param endTime the new end time */ - public void updateTimeRange(long startTime, long endTime) { + void updateTimeRange(long startTime, long endTime) { if (fCurrentExperiment != null) { // Build the new time range; keep the current time - TmfTimeRange timeRange = new TmfTimeRange(new TmfTimestamp(startTime, TIME_SCALE), new TmfTimestamp( - endTime, TIME_SCALE)); - TmfTimestamp currentTime = new TmfTimestamp(fCurrentTimestamp, TIME_SCALE); - + TmfTimeRange timeRange = new TmfTimeRange( + new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE), + new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE)); + ITmfTimestamp currentTime = new TmfTimestamp(fCurrentTimestamp, ITmfTimestamp.NANOSECOND_SCALE); fTimeSpanControl.setValue(endTime - startTime); // Send the FW signal @@ -337,10 +341,6 @@ public class HistogramView extends TmfView { } long endTime = startTime + duration; - if( endTime < startTime ) { - endTime = fExperimentEndTime; - startTime = fExperimentStartTime; - } if (endTime > fExperimentEndTime) { endTime = fExperimentEndTime; if ((endTime - duration) > fExperimentStartTime) { @@ -390,17 +390,18 @@ public class HistogramView extends TmfView { // Initialize the internal data fCurrentExperiment = null; - fExperimentStartTime = 0; - fExperimentEndTime = 0; - fWindowStartTime = 0; - fWindowEndTime = 0; + fExperimentStartTime = 0L; + fExperimentEndTime = 0L; + fWindowStartTime = 0L; + fWindowEndTime = 0L; fWindowSpan = INITIAL_WINDOW_SPAN; - fCurrentTimestamp = 0; + fCurrentTimestamp = 0L; // Clear the UI widgets fFullTraceHistogram.clear(); fTimeRangeHistogram.clear(); - fCurrentEventTimeControl.setValue(0); + fCurrentEventTimeControl.setValue(0L); + fTimeSpanControl.setValue(0); } @@ -421,8 +422,8 @@ public class HistogramView extends TmfView { boolean drawTimeRangeHistogram = fExperimentStartTime == 0; TmfTimeRange fullRange = signal.getRange(); - fExperimentStartTime = fullRange.getStartTime().normalize(0, -9).getValue(); - fExperimentEndTime = fullRange.getEndTime().normalize(0, -9).getValue(); + fExperimentStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + fExperimentEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); fFullTraceHistogram.setFullRange(fExperimentStartTime, fExperimentEndTime); fTimeRangeHistogram.setFullRange(fExperimentStartTime, fExperimentEndTime); @@ -448,8 +449,8 @@ public class HistogramView extends TmfView { return; } TmfTimeRange fullRange = signal.getExperiment().getTimeRange(); - fExperimentStartTime = fullRange.getStartTime().normalize(0, -9).getValue(); - fExperimentEndTime = fullRange.getEndTime().normalize(0, -9).getValue(); + fExperimentStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + fExperimentEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); fFullTraceHistogram.setFullRange(fExperimentStartTime, fExperimentEndTime); fTimeRangeHistogram.setFullRange(fExperimentStartTime, fExperimentEndTime); @@ -467,8 +468,8 @@ public class HistogramView extends TmfView { assert (signal != null); // Update the selected event time - ITmfTimestamp currentTime = signal.getCurrentTime(); - fCurrentTimestamp = currentTime.normalize(0, -9).getValue(); + ITmfTimestamp currentTime = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); + fCurrentTimestamp = currentTime.getValue(); // Notify the relevant widgets fFullTraceHistogram.setCurrentEvent(fCurrentTimestamp); @@ -487,13 +488,14 @@ public class HistogramView extends TmfView { if (fCurrentExperiment != null) { // Update the time range - fWindowStartTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue(); - fWindowEndTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue(); + fWindowStartTime = signal.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + fWindowEndTime = signal.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); fWindowSpan = fWindowEndTime - fWindowStartTime; // Notify the relevant widgets sendTimeRangeRequest(fWindowStartTime, fWindowEndTime); fFullTraceHistogram.setTimeRange(fWindowStartTime, fWindowSpan); + fTimeSpanControl.setValue(fWindowSpan); } } @@ -520,6 +522,7 @@ public class HistogramView extends TmfView { fWindowEndTime = fWindowStartTime + fWindowSpan; fCurrentEventTimeControl.setValue(fExperimentStartTime); + fTimeSpanControl.setValue(fWindowSpan); if (!fullRange.equals(TmfTimeRange.NULL_RANGE)) { @@ -529,14 +532,14 @@ public class HistogramView extends TmfView { } private TmfTimeRange updateExperimentTimeRange() { - fExperimentStartTime = 0; - fExperimentEndTime = 0; - fCurrentTimestamp = 0; + fExperimentStartTime = 0L; + fExperimentEndTime = 0L; + fCurrentTimestamp = 0L; TmfTimeRange timeRange = fCurrentExperiment.getTimeRange(); if (!timeRange.equals(TmfTimeRange.NULL_RANGE)) { - fExperimentStartTime = timeRange.getStartTime().normalize(0, -9).getValue(); - fExperimentEndTime = timeRange.getEndTime().normalize(0, -9).getValue(); + fExperimentStartTime = timeRange.getStartTime().getValue(); + fExperimentEndTime = timeRange.getEndTime().getValue(); fCurrentTimestamp = fExperimentStartTime; } return timeRange; @@ -546,8 +549,8 @@ public class HistogramView extends TmfView { if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { fTimeRangeRequest.cancel(); } - TmfTimestamp startTS = new TmfTimestamp(startTime, TIME_SCALE); - TmfTimestamp endTS = new TmfTimestamp(endTime, TIME_SCALE); + TmfTimestamp startTS = new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE); + TmfTimestamp endTS = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE); TmfTimeRange timeRange = new TmfTimeRange(startTS, endTS); fTimeRangeHistogram.clear(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java index 2fe8217058..1b0a456282 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java @@ -1,14 +1,14 @@ /******************************************************************************* * Copyright (c) 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: * Francois Chouinard - Initial API and implementation - * Bernd Hufmann - Changed to updated histogram data model + * Bernd Hufmann - Changed to updated histogram data model * Francois Chouinard - Moved from LTTng to TMF *******************************************************************************/ @@ -18,14 +18,14 @@ import org.eclipse.swt.widgets.Composite; /** *

    - * A basic histogram widget that displays the event distribution of a specific time range of a trace. + * A basic histogram widget that displays the event distribution of a specific time range of a trace. * It has the following additional features: *

      *
    • zoom in: mouse wheel up (or forward) *
    • zoom out: mouse wheel down (or backward) *
    - * - * @version 1.0 + * + * @version 1.1 * @author Francois Chouinard */ public class TimeRangeHistogram extends Histogram { @@ -40,7 +40,7 @@ public class TimeRangeHistogram extends Histogram { // Constructor // ------------------------------------------------------------------------ /** - * Constructor + * Constructor * @param view The parent histogram view * @param parent The parent composite */ @@ -68,14 +68,15 @@ public class TimeRangeHistogram extends Histogram { */ @Override public synchronized void clear() { - if (fZoom != null) + if (fZoom != null) { fZoom.stop(); + } super.clear(); } /** * Sets the time range of the histogram - * @param startTime The start time + * @param startTime The start time * @param duration The duration of the time range */ public synchronized void setTimeRange(long startTime, long duration) { @@ -84,7 +85,7 @@ public class TimeRangeHistogram extends Histogram { /** * Sets the full time range of the whole trace. - * @param startTime The start time + * @param startTime The start time * @param endTime The end time */ public void setFullRange(long startTime, long endTime) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/messages.properties index 2078673bfe..557d13042e 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/messages.properties @@ -1,2 +1,2 @@ -HistogramView_currentEventLabel=Current Event (sec) -HistogramView_windowSpanLabel=Window Span (sec) +HistogramView_currentEventLabel=Current Event +HistogramView_windowSpanLabel=Window Span -- 2.34.1