From 5680af1b456246a287ed2623e0277487f66429ad Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Thu, 12 Nov 2015 23:35:13 +0100 Subject: [PATCH] - added preference dialog - added preference handling - added file monitor to automatically reload changed database --- .../META-INF/MANIFEST.MF | 6 +- .../database/swt/DatabaseUiPlugin.java | 27 +++ .../database/swt/internal/CursorPainter.java | 11 +- .../database/swt/internal/SignalPainter.java | 27 ++- .../database/swt/internal/StreamPainter.java | 18 +- .../swt/internal/TrackAreaPainter.java | 4 +- .../database/swt/internal/WaveformCanvas.java | 57 +++---- .../database/swt/internal/WaveformViewer.java | 53 +++--- .../minres/scviewer/database/ui/ICursor.java | 19 +++ .../scviewer/database/ui/IWaveformViewer.java | 61 ++++--- .../scviewer/database/ui/WaveformColors.java | 20 +++ .../Application.e4xmi | 12 +- .../META-INF/MANIFEST.MF | 5 +- com.minres.scviewer.e4.application/plugin.xml | 20 +++ .../handlers/AddWaveformHandler.java | 10 ++ .../internal/{ => status}/HeapStatus.java | 2 +- .../{ => status}/IHeapStatusConstants.java | 2 +- .../{ => status}/StatusBarControl.java | 2 +- .../internal/{ => status}/TrimUtil.java | 2 +- .../{ => status}/WaveStatusBarControl.java | 2 +- .../internal/util/FileMonitor.java | 143 ++++++++++++++++ .../internal/util/IFileChangeListener.java | 31 ++++ .../internal/util/IModificationChecker.java | 17 ++ .../e4/application/parts/PartListener.java | 31 ++++ .../application/parts/TransactionDetails.java | 19 ++- .../application/parts/WaveformListPart.java | 4 +- .../application/parts/WaveformViewerPart.java | 161 +++++++++++++++--- .../preferences/DefaultValuesInitializer.java | 60 +++++++ .../preferences/PreferenceConstants.java | 37 ++++ .../preferences/SCViewerPreferencesPage.java | 31 ++++ .../preferences/WaveformPreferencesPage.java | 34 ++++ .../provider/TxDbContentProvider.java | 27 ++- .../org/eclipse/wb/swt/ResourceManager.java | 4 +- .../SCViewer.launch | 4 +- 34 files changed, 796 insertions(+), 167 deletions(-) create mode 100644 com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/DatabaseUiPlugin.java create mode 100644 com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/ICursor.java create mode 100644 com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/WaveformColors.java rename com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/{ => status}/HeapStatus.java (99%) rename com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/{ => status}/IHeapStatusConstants.java (94%) rename com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/{ => status}/StatusBarControl.java (99%) rename com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/{ => status}/TrimUtil.java (96%) rename com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/{ => status}/WaveStatusBarControl.java (98%) create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/util/FileMonitor.java create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/util/IFileChangeListener.java create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/util/IModificationChecker.java create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/PartListener.java create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/DefaultValuesInitializer.java create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/PreferenceConstants.java create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/SCViewerPreferencesPage.java create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/WaveformPreferencesPage.java diff --git a/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF b/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF index c273f02..2abd6cc 100644 --- a/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF +++ b/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF @@ -10,6 +10,10 @@ Require-Bundle: org.eclipse.swt;bundle-version="3.103.1", com.google.guava;bundle-version="15.0.0", org.eclipse.jface, org.eclipse.equinox.registry, - com.minres.scviewer.database.ui + com.minres.scviewer.database.ui, + org.eclipse.core.runtime, + org.eclipse.osgi Export-Package: com.minres.scviewer.database.swt Bundle-ClassPath: . +Bundle-ActivationPolicy: lazy +Bundle-Activator: com.minres.scviewer.database.swt.DatabaseUiPlugin diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/DatabaseUiPlugin.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/DatabaseUiPlugin.java new file mode 100644 index 0000000..84ed5cc --- /dev/null +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/DatabaseUiPlugin.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.database.swt; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; + +public class DatabaseUiPlugin extends Plugin { + + public void start(BundleContext context) throws Exception { + getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Starting org.eclipse.e4.core bundle...")); + } + + public void stop(BundleContext context) throws Exception { + getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Stopping org.eclipse.e4.core bundle...")); + } +} \ No newline at end of file diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/CursorPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/CursorPainter.java index a2b8f7f..ac0e528 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/CursorPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/CursorPainter.java @@ -14,7 +14,10 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; -public class CursorPainter implements IPainter { +import com.minres.scviewer.database.ui.ICursor; +import com.minres.scviewer.database.ui.WaveformColors; + +public class CursorPainter implements IPainter, ICursor { /** * @@ -58,9 +61,9 @@ public class CursorPainter implements IPainter { long scaleFactor=waveCanvas.getScaleFactor(); int x = (int) (time/scaleFactor); int top = id<0?area.y:area.y+15; - Color drawColor=waveCanvas.colors[id<0?WaveformCanvas.Colors.CURSOR.ordinal():WaveformCanvas.Colors.MARKER.ordinal()]; - Color dragColor = waveCanvas.colors[WaveformCanvas.Colors.CURSOR_DRAG.ordinal()]; - Color textColor=waveCanvas.colors[id<0?WaveformCanvas.Colors.CURSOR_TEXT.ordinal():WaveformCanvas.Colors.MARKER_TEXT.ordinal()]; + Color drawColor=waveCanvas.colors[id<0?WaveformColors.CURSOR.ordinal():WaveformColors.MARKER.ordinal()]; + Color dragColor = waveCanvas.colors[WaveformColors.CURSOR_DRAG.ordinal()]; + Color textColor=waveCanvas.colors[id<0?WaveformColors.CURSOR_TEXT.ordinal():WaveformColors.MARKER_TEXT.ordinal()]; if(x>=area.x && x<=(area.x+area.width)){ gc.setForeground(isDragging?dragColor:drawColor); gc.drawLine(x, top, x, area.y+area.height); diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/SignalPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/SignalPainter.java index 4672e84..cde35ea 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/SignalPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/SignalPainter.java @@ -20,10 +20,10 @@ import org.eclipse.swt.graphics.Rectangle; import com.minres.scviewer.database.ISignal; import com.minres.scviewer.database.ISignalChange; -import com.minres.scviewer.database.ui.TrackEntry; import com.minres.scviewer.database.ISignalChangeMulti; import com.minres.scviewer.database.ISignalChangeSingle; -import com.minres.scviewer.database.IWaveform; +import com.minres.scviewer.database.ui.TrackEntry; +import com.minres.scviewer.database.ui.WaveformColors; public class SignalPainter extends TrackPainter { @@ -33,7 +33,6 @@ public class SignalPainter extends TrackPainter { private final WaveformCanvas waveCanvas; private ISignal signal; - @SuppressWarnings("unchecked") public SignalPainter(WaveformCanvas txDisplay, boolean even, TrackEntry trackEntry) { super(trackEntry, even); this.waveCanvas = txDisplay; @@ -42,9 +41,9 @@ public class SignalPainter extends TrackPainter { public void paintArea(GC gc, Rectangle area) { if(trackEntry.selected) - gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TRACK_BG_HIGHLITE.ordinal()]); + gc.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()]); else - gc.setBackground(this.waveCanvas.colors[even?WaveformCanvas.Colors.TRACK_BG_EVEN.ordinal():WaveformCanvas.Colors.TRACK_BG_ODD.ordinal()]); + gc.setBackground(this.waveCanvas.colors[even?WaveformColors.TRACK_BG_EVEN.ordinal():WaveformColors.TRACK_BG_ODD.ordinal()]); gc.setFillRule(SWT.FILL_EVEN_ODD); gc.fillRectangle(area); Entry firstChange=signal.getEvents().floorEntry(area.x*this.waveCanvas.getScaleFactor()); @@ -55,7 +54,7 @@ public class SignalPainter extends TrackPainter { } else if(lastTx==null){ lastTx=signal.getEvents().lastEntry(); } - gc.setForeground(this.waveCanvas.colors[WaveformCanvas.Colors.LINE.ordinal()]); + gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]); gc.setLineStyle(SWT.LINE_SOLID); gc.setLineWidth(1); Entry left=firstChange; @@ -66,18 +65,18 @@ public class SignalPainter extends TrackPainter { int xBegin= (int)(left.getKey()/this.waveCanvas.getScaleFactor()); if(xEnd>xBegin){ int yOffset = this.waveCanvas.getTrackHeight()/2; - Color color = this.waveCanvas.colors[WaveformCanvas.Colors.SIGNALX.ordinal()]; + Color color = this.waveCanvas.colors[WaveformColors.SIGNALX.ordinal()]; switch(((ISignalChangeSingle) left.getValue()).getValue()){ case '1': - color=this.waveCanvas.colors[WaveformCanvas.Colors.SIGNAL1.ordinal()]; + color=this.waveCanvas.colors[WaveformColors.SIGNAL1.ordinal()]; yOffset = this.waveCanvas.getTrackHeight()/5; break; case '0': - color=this.waveCanvas.colors[WaveformCanvas.Colors.SIGNAL0.ordinal()]; + color=this.waveCanvas.colors[WaveformColors.SIGNAL0.ordinal()]; yOffset = 4*this.waveCanvas.getTrackHeight()/5; break; case 'Z': - color=this.waveCanvas.colors[WaveformCanvas.Colors.SIGNALZ.ordinal()]; + color=this.waveCanvas.colors[WaveformColors.SIGNALZ.ordinal()]; break; default: } @@ -104,12 +103,12 @@ public class SignalPainter extends TrackPainter { int yOffsetT = this.waveCanvas.getTrackHeight()/5+area.y; int yOffsetM = this.waveCanvas.getTrackHeight()/2+area.y; int yOffsetB = 4*this.waveCanvas.getTrackHeight()/5+area.y; - Color colorBorder = this.waveCanvas.colors[WaveformCanvas.Colors.SIGNAL0.ordinal()]; + Color colorBorder = this.waveCanvas.colors[WaveformColors.SIGNAL0.ordinal()]; ISignalChangeMulti last = (ISignalChangeMulti) left.getValue(); if(last.getValue().toString().contains("X")){ - colorBorder=this.waveCanvas.colors[WaveformCanvas.Colors.SIGNALX.ordinal()]; + colorBorder=this.waveCanvas.colors[WaveformColors.SIGNALX.ordinal()]; }else if(last.getValue().toString().contains("Z")){ - colorBorder=this.waveCanvas.colors[WaveformCanvas.Colors.SIGNALZ.ordinal()]; + colorBorder=this.waveCanvas.colors[WaveformColors.SIGNALZ.ordinal()]; } int beginTime= (int)(left.getKey()/this.waveCanvas.getScaleFactor()); int endTime= (int)(right.getKey()/this.waveCanvas.getScaleFactor()); @@ -123,7 +122,7 @@ public class SignalPainter extends TrackPainter { }; gc.setForeground(colorBorder); gc.drawPolygon(points); - gc.setForeground(this.waveCanvas.colors[WaveformCanvas.Colors.SIGNAL_TEXT.ordinal()]); + gc.setForeground(this.waveCanvas.colors[WaveformColors.SIGNAL_TEXT.ordinal()]); int size = gc.getDevice().getDPI().y * gc.getFont().getFontData()[0].getHeight()/72; if(beginTime stream; private int txBase, txHeight; - private int totalHeight; private boolean even; private TreeSet seenTx; - @SuppressWarnings("unchecked") public StreamPainter(WaveformCanvas waveCanvas, boolean even, TrackEntry trackEntry) { super(trackEntry, even); this.waveCanvas = waveCanvas; @@ -54,9 +52,9 @@ public class StreamPainter extends TrackPainter{ txBase=trackHeight/5; txHeight=trackHeight*3/5; if(trackEntry.selected) - gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TRACK_BG_HIGHLITE.ordinal()]); + gc.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()]); else - gc.setBackground(this.waveCanvas.colors[even?WaveformCanvas.Colors.TRACK_BG_EVEN.ordinal():WaveformCanvas.Colors.TRACK_BG_ODD.ordinal()]); + gc.setBackground(this.waveCanvas.colors[even?WaveformColors.TRACK_BG_EVEN.ordinal():WaveformColors.TRACK_BG_ODD.ordinal()]); gc.setFillRule(SWT.FILL_EVEN_ODD); gc.fillRectangle(area); Entry firstTx=stream.getEvents().floorEntry(area.x*waveCanvas.getScaleFactor()); @@ -66,7 +64,7 @@ public class StreamPainter extends TrackPainter{ gc.setFillRule(SWT.FILL_EVEN_ODD); gc.setLineStyle(SWT.LINE_SOLID); gc.setLineWidth(1); - gc.setForeground(this.waveCanvas.colors[WaveformCanvas.Colors.LINE.ordinal()]); + gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]); for(int y1=area.y+trackHeight/2; y1 entries = stream.getEvents().subMap(firstTx.getKey(), true, lastTx.getKey(), true); boolean highlighed=false; - gc.setForeground(this.waveCanvas.colors[WaveformCanvas.Colors.LINE.ordinal()]); - gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TX_BG.ordinal()]); + gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]); + gc.setBackground(this.waveCanvas.colors[WaveformColors.TX_BG.ordinal()]); for(Entry entry: entries.entrySet()) for(ITxEvent txEvent:(Collection)entry.getValue()){ if(txEvent.getType()==ITxEvent.Type.BEGIN) @@ -93,8 +91,8 @@ public class StreamPainter extends TrackPainter{ drawTx(gc, area, tx); } if(highlighed){ - gc.setForeground(this.waveCanvas.colors[WaveformCanvas.Colors.LINE_HIGHLITE.ordinal()]); - gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TX_BG_HIGHLITE.ordinal()]); + gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE_HIGHLITE.ordinal()]); + gc.setBackground(this.waveCanvas.colors[WaveformColors.TX_BG_HIGHLITE.ordinal()]); drawTx(gc, area, waveCanvas.currentSelection); } } diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/TrackAreaPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/TrackAreaPainter.java index 5a9887c..ed7fc13 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/TrackAreaPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/TrackAreaPainter.java @@ -17,6 +17,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; +import com.minres.scviewer.database.ui.WaveformColors; + public class TrackAreaPainter implements IPainter { /** @@ -35,7 +37,7 @@ public class TrackAreaPainter implements IPainter { public void paintArea(GC gc, Rectangle a) { Rectangle area = new Rectangle(a.x, a.y+waveCanvas.rulerHeight, a.width, a.height-waveCanvas.rulerHeight); - gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TRACK_BG_EVEN.ordinal()]); + gc.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_EVEN.ordinal()]); gc.setFillRule(SWT.FILL_EVEN_ODD); gc.fillRectangle(area); if(trackVerticalOffset.size()>0){ diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java index 7fcb094..19b2540 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java @@ -40,18 +40,11 @@ import com.google.common.collect.Lists; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformEvent; +import com.minres.scviewer.database.ui.WaveformColors; public class WaveformCanvas extends Canvas { - public enum Colors { - LINE, LINE_HIGHLITE, - TRACK_BG_EVEN, TRACK_BG_ODD, TRACK_BG_HIGHLITE, - TX_BG, TX_BG_HIGHLITE, TX_BORDER, - SIGNAL0, SIGNAL1, SIGNALZ, SIGNALX, SIGNAL_TEXT, - CURSOR, CURSOR_DRAG, CURSOR_TEXT, - MARKER, MARKER_TEXT - } - - Color[] colors = new Color[Colors.values().length]; + + Color[] colors = new Color[WaveformColors.values().length]; private int trackHeight = 50; @@ -134,34 +127,34 @@ public class WaveformCanvas extends Canvas { cursorPainters.add(cursorPainter); } - private void initColors(HashMap colourMap) { + public void initColors(HashMap colourMap) { Display d = getDisplay(); if (colourMap != null) { - for (Colors c : Colors.values()) { + for (WaveformColors c : WaveformColors.values()) { if (colourMap.containsKey(c)) { - colors[c.ordinal()].dispose(); colors[c.ordinal()] = new Color(d, colourMap.get(c)); } } + redraw(); } else { - colors[Colors.LINE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED); - colors[Colors.LINE_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_CYAN); - colors[Colors.TRACK_BG_EVEN.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_BLACK); - colors[Colors.TRACK_BG_ODD.ordinal()] = SWTResourceManager.getColor(40, 40, 40); - colors[Colors.TRACK_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(40, 40, 80); - colors[Colors.TX_BG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GREEN); - colors[Colors.TX_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); - colors[Colors.TX_BORDER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED); - colors[Colors.SIGNAL0.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); - colors[Colors.SIGNAL1.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); - colors[Colors.SIGNALZ.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GRAY); - colors[Colors.SIGNALX.ordinal()] = SWTResourceManager.getColor(255, 128, 182); - colors[Colors.SIGNAL_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); - colors[Colors.CURSOR.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED); - colors[Colors.CURSOR_DRAG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GRAY); - colors[Colors.CURSOR_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); - colors[Colors.MARKER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY); - colors[Colors.MARKER_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); + colors[WaveformColors.LINE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED); + colors[WaveformColors.LINE_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_CYAN); + colors[WaveformColors.TRACK_BG_EVEN.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_BLACK); + colors[WaveformColors.TRACK_BG_ODD.ordinal()] = SWTResourceManager.getColor(40, 40, 40); + colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(40, 40, 80); + colors[WaveformColors.TX_BG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GREEN); + colors[WaveformColors.TX_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); + colors[WaveformColors.TX_BORDER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED); + colors[WaveformColors.SIGNAL0.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); + colors[WaveformColors.SIGNAL1.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); + colors[WaveformColors.SIGNALZ.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GRAY); + colors[WaveformColors.SIGNALX.ordinal()] = SWTResourceManager.getColor(255, 128, 182); + colors[WaveformColors.SIGNAL_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); + colors[WaveformColors.CURSOR.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED); + colors[WaveformColors.CURSOR_DRAG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GRAY); + colors[WaveformColors.CURSOR_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); + colors[WaveformColors.MARKER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY); + colors[WaveformColors.MARKER_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); } } @@ -274,7 +267,7 @@ public class WaveformCanvas extends Canvas { */ public void dispose() { transform.dispose(); - for (Colors c : Colors.values()) + for (WaveformColors c : WaveformColors.values()) colors[c.ordinal()].dispose(); super.dispose(); } diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java index c6d2f15..f34d6e8 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java @@ -15,6 +15,7 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map.Entry; import java.util.NavigableMap; @@ -49,6 +50,7 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.TextLayout; import org.eclipse.swt.layout.FillLayout; @@ -75,8 +77,10 @@ import com.minres.scviewer.database.ITxStream; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformEvent; import com.minres.scviewer.database.ui.GotoDirection; +import com.minres.scviewer.database.ui.ICursor; import com.minres.scviewer.database.ui.IWaveformViewer; import com.minres.scviewer.database.ui.TrackEntry; +import com.minres.scviewer.database.ui.WaveformColors; public class WaveformViewer implements IWaveformViewer { @@ -84,8 +88,6 @@ public class WaveformViewer implements IWaveformViewer { private PropertyChangeSupport pcs; - private static final String SELECTION = "selection"; - private ITx currentTxSelection; private TrackEntry currentWaveformSelection; @@ -120,7 +122,7 @@ public class WaveformViewer implements IWaveformViewer { if ((e.button == 1 || e.button == 3)) { Entry entry = trackVerticalOffset.floorEntry(e.y); if (entry != null) - setSelection(new StructuredSelection(entry.getValue().waveform)); + setSelection(new StructuredSelection(entry.getValue())); } if (e.button == 3) { Menu topMenu= top.getMenu(); @@ -368,11 +370,15 @@ public class WaveformViewer implements IWaveformViewer { @Override public void propertyChange(PropertyChangeEvent pce) { if ("size".equals(pce.getPropertyName()) || "content".equals(pce.getPropertyName())) { - updateTracklist(); + waveformCanvas.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + updateTracklist(); + } + }); } } - @SuppressWarnings("unchecked") protected void updateTracklist() { trackVerticalHeight = 0; int nameMaxWidth = 0; @@ -556,7 +562,6 @@ public class WaveformViewer implements IWaveformViewer { * @see com.minres.scviewer.database.swt.IWaveformPanel#setSelection(org.eclipse.jface.viewers.ISelection, boolean) */ @Override - @SuppressWarnings("unchecked") public void setSelection(ISelection selection, boolean addIfNeeded) { boolean selectionChanged = false; if(currentWaveformSelection!=null) currentWaveformSelection.selected=false; @@ -573,9 +578,9 @@ public class WaveformViewer implements IWaveformViewer { if(trackEntry==null && addIfNeeded){ trackEntry=new TrackEntry(txSel.getStream()); streams.add(trackEntry); - currentWaveformSelection = trackEntry; } currentTxSelection = txSel; + if(trackEntry!=null) currentWaveformSelection = trackEntry; selectionChanged = true; } else if (sel instanceof TrackEntry && currentWaveformSelection != sel) { currentWaveformSelection = (TrackEntry) sel; @@ -615,7 +620,6 @@ public class WaveformViewer implements IWaveformViewer { * @see com.minres.scviewer.database.swt.IWaveformPanel#moveSelection(com.minres.scviewer.database.swt.GotoDirection) */ @Override - @SuppressWarnings("unchecked") public void moveSelection(GotoDirection direction) { if (currentWaveformSelection.isStream()) { ITxStream stream = currentWaveformSelection.getStream(); @@ -875,9 +879,16 @@ public class WaveformViewer implements IWaveformViewer { * @see com.minres.scviewer.database.swt.IWaveformPanel#getActMarkerTime() */ @Override - public long getActMarkerTime(){ + public long getSelectedMarkerTime(){ return getMarkerTime(selectedMarker); } + + @Override + public List getCursorList(){ + List cursors = new LinkedList<>(); + for(CursorPainter painter:waveformCanvas.getCursorPainters()) cursors.add(painter); + return Collections.unmodifiableList(cursors); + } /* (non-Javadoc) * @see com.minres.scviewer.database.swt.IWaveformPanel#getMarkerTime(int) @@ -894,12 +905,8 @@ public class WaveformViewer implements IWaveformViewer { dragSource.addDragListener(new DragSourceAdapter() { public void dragStart(DragSourceEvent event) { if (event.y < trackVerticalHeight) { - // event.data = - // trackVerticalOffset.floorEntry(event.y).getValue().getFullName(); event.doit = true; LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(currentWaveformSelection)); - // System.out.println("dragStart at location "+new - // Point(event.x, event.y)); } } @@ -917,7 +924,6 @@ public class WaveformViewer implements IWaveformViewer { dropTarget.setTransfer(types); dropTarget.addDropListener(new DropTargetAdapter() { - @SuppressWarnings("unchecked") public void drop(DropTargetEvent event) { if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)){ ISelection sel = LocalSelectionTransfer.getTransfer().getSelection(); @@ -926,18 +932,17 @@ public class WaveformViewer implements IWaveformViewer { DropTarget tgt = (DropTarget) event.widget; Point dropPoint = ((Canvas) tgt.getControl()).toControl(event.x, event.y); Object target = trackVerticalOffset.floorEntry(dropPoint.y).getValue(); - if(source instanceof IWaveform && target instanceof IWaveform){ - IWaveform srcWave=(IWaveform) source; + if(source instanceof TrackEntry && target instanceof TrackEntry){ + TrackEntry srcWave=(TrackEntry) source; int srcIdx=streams.indexOf(srcWave); - streams.remove(getEntryForStream((IWaveform)source)); + streams.remove(srcWave); int tgtIdx=streams.indexOf(target); if(srcIdx<=tgtIdx) tgtIdx++; - TrackEntry entry = new TrackEntry(srcWave); if(tgtIdx>=streams.size()) - streams.add(entry); + streams.add(srcWave); else - streams.add(tgtIdx, entry); - currentWaveformSelection=entry; + streams.add(tgtIdx, srcWave); + currentWaveformSelection=srcWave; updateTracklist(); } else if(source instanceof CursorPainter){ ((CursorPainter)source).setTime(0); @@ -969,7 +974,6 @@ public class WaveformViewer implements IWaveformViewer { dragSource.setTransfer(types); dragSource.addDragListener(new DragSourceAdapter() { public void dragStart(DragSourceEvent event) { - System.out.println("dragStart"); event.doit = false; List clicked = waveformCanvas.getClicked(new Point(event.x, event.y)); for(Object o:clicked){ @@ -1115,4 +1119,9 @@ public class WaveformViewer implements IWaveformViewer { } return res; } + + @Override + public void setColors(HashMap colourMap) { + waveformCanvas.initColors(colourMap); + } } diff --git a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/ICursor.java b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/ICursor.java new file mode 100644 index 0000000..4f51d1d --- /dev/null +++ b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/ICursor.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.database.ui; + +public interface ICursor { + + public long getTime(); + + public void setTime(long time); + +} diff --git a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/IWaveformViewer.java b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/IWaveformViewer.java index e3f7f00..cde0a8c 100644 --- a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/IWaveformViewer.java +++ b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/IWaveformViewer.java @@ -11,11 +11,13 @@ package com.minres.scviewer.database.ui; import java.beans.PropertyChangeListener; +import java.util.HashMap; import java.util.List; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Control; import com.minres.scviewer.database.IWaveform; @@ -25,62 +27,65 @@ public interface IWaveformViewer extends PropertyChangeListener, ISelectionProvi String CURSOR_PROPERTY = "cursor_time"; String MARKER_PROPERTY = "marker_time"; - void addSelectionChangedListener(ISelectionChangedListener listener); + public void addSelectionChangedListener(ISelectionChangedListener listener); - void removeSelectionChangedListener(ISelectionChangedListener listener); + public void removeSelectionChangedListener(ISelectionChangedListener listener); - Control getControl(); + public Control getControl(); - Control getNameControl(); + public Control getNameControl(); - Control getValueControl(); + public Control getValueControl(); - Control getWaveformControl(); + public Control getWaveformControl(); - ISelection getSelection(); + public ISelection getSelection(); - void setSelection(ISelection selection); + public void setSelection(ISelection selection); - void setSelection(ISelection selection, boolean addIfNeeded); + public void setSelection(ISelection selection, boolean addIfNeeded); - void moveSelection(GotoDirection direction); + public void moveSelection(GotoDirection direction); - void moveCursor(GotoDirection direction); + public void moveCursor(GotoDirection direction); - List getStreamList(); + public List getStreamList(); public TrackEntry getEntryForStream(IWaveform source); - void moveSelected(int i); + public void moveSelected(int i); - long getMaxTime(); + public long getMaxTime(); - void setMaxTime(long maxTime); + public void setMaxTime(long maxTime); - void setZoomLevel(int scale); + public void setZoomLevel(int scale); - int getZoomLevel(); + public int getZoomLevel(); - void setCursorTime(long time); + public void setCursorTime(long time); - void setMarkerTime(long time, int index); + public void setMarkerTime(long time, int index); - long getCursorTime(); + public long getCursorTime(); - long getActMarkerTime(); + public long getSelectedMarkerTime(); - long getMarkerTime(int index); + public long getMarkerTime(int index); - void addPropertyChangeListener(PropertyChangeListener listener); + public void addPropertyChangeListener(PropertyChangeListener listener); - void addPropertyChangeListener(String propertyName, PropertyChangeListener listener); + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener); - void removePropertyChangeListener(PropertyChangeListener listener); + public void removePropertyChangeListener(PropertyChangeListener listener); - void removePropertyChangeListener(String propertyName, PropertyChangeListener listener); + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener); - String getScaledTime(long time); + public String getScaledTime(long time); - String[] getZoomLevels(); + public String[] getZoomLevels(); + public List getCursorList(); + + public void setColors(HashMap colourMap); } \ No newline at end of file diff --git a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/WaveformColors.java b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/WaveformColors.java new file mode 100644 index 0000000..ec3663a --- /dev/null +++ b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/WaveformColors.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.database.ui; + +public enum WaveformColors { + LINE, LINE_HIGHLITE, + TRACK_BG_EVEN, TRACK_BG_ODD, TRACK_BG_HIGHLITE, + TX_BG, TX_BG_HIGHLITE, TX_BORDER, + SIGNAL0, SIGNAL1, SIGNALZ, SIGNALX, SIGNAL_TEXT, + CURSOR, CURSOR_DRAG, CURSOR_TEXT, + MARKER, MARKER_TEXT +} \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/Application.e4xmi b/com.minres.scviewer.e4.application/Application.e4xmi index 10cf343..1d3f058 100644 --- a/com.minres.scviewer.e4.application/Application.e4xmi +++ b/com.minres.scviewer.e4.application/Application.e4xmi @@ -70,6 +70,9 @@ + + + @@ -117,13 +120,13 @@ - + stretch - + Draggable - + Draggable @@ -133,6 +136,7 @@ + @@ -207,6 +211,7 @@ + @@ -214,4 +219,5 @@ + diff --git a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF index 2b30b1d..5ffb45e 100644 --- a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF +++ b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF @@ -15,6 +15,7 @@ Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.e4.ui.di;bundle-version="1.1.0", org.eclipse.e4.core.contexts;bundle-version="1.4.0", com.minres.scviewer.database.ui.swt;bundle-version="1.0.0", + com.minres.scviewer.database.ui, com.minres.scviewer.database;bundle-version="1.0.0", org.eclipse.equinox.ds;bundle-version="1.4.300", org.eclipse.equinox.util;bundle-version="1.0.500", @@ -27,7 +28,9 @@ Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.equinox.preferences, org.eclipse.core.expressions, org.eclipse.e4.core.commands;bundle-version="0.11.0", - com.minres.scviewer.database.ui + org.eclipse.e4.ui.workbench.addons.swt, + com.opcoach.e4.preferences, + org.eclipse.e4.core.di.extensions Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: com.minres.scviewer.database, javax.inject;version="1.0.0" diff --git a/com.minres.scviewer.e4.application/plugin.xml b/com.minres.scviewer.e4.application/plugin.xml index 3ba19b3..3d6f766 100644 --- a/com.minres.scviewer.e4.application/plugin.xml +++ b/com.minres.scviewer.e4.application/plugin.xml @@ -64,5 +64,25 @@ + + + + + + + + + + diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java index 01aa29f..b3aaf47 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ package com.minres.scviewer.e4.application.handlers; diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/HeapStatus.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/HeapStatus.java similarity index 99% rename from com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/HeapStatus.java rename to com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/HeapStatus.java index a1c6d72..26d189f 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/HeapStatus.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/HeapStatus.java @@ -8,7 +8,7 @@ * Contributors: * MINRES Technologies GmbH - initial API and implementation *******************************************************************************/ -package com.minres.scviewer.e4.application.internal; +package com.minres.scviewer.e4.application.internal.status; import java.lang.reflect.Method; import org.eclipse.core.runtime.preferences.IEclipsePreferences; diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/IHeapStatusConstants.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/IHeapStatusConstants.java similarity index 94% rename from com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/IHeapStatusConstants.java rename to com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/IHeapStatusConstants.java index 910be51..b79fb51 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/IHeapStatusConstants.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/IHeapStatusConstants.java @@ -8,7 +8,7 @@ * Contributors: * MINRES Technologies GmbH - initial API and implementation *******************************************************************************/ -package com.minres.scviewer.e4.application.internal; +package com.minres.scviewer.e4.application.internal.status; /** * Preference constants for the heap status. * diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/StatusBarControl.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/StatusBarControl.java similarity index 99% rename from com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/StatusBarControl.java rename to com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/StatusBarControl.java index b85caf7..85f9a21 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/StatusBarControl.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/StatusBarControl.java @@ -8,7 +8,7 @@ * Contributors: * MINRES Technologies GmbH - initial API and implementation *******************************************************************************/ -package com.minres.scviewer.e4.application.internal; +package com.minres.scviewer.e4.application.internal.status; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/TrimUtil.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/TrimUtil.java similarity index 96% rename from com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/TrimUtil.java rename to com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/TrimUtil.java index ed0178f..14d5b20 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/TrimUtil.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/TrimUtil.java @@ -8,7 +8,7 @@ * Contributors: * MINRES Technologies GmbH - initial API and implementation *******************************************************************************/ -package com.minres.scviewer.e4.application.internal; +package com.minres.scviewer.e4.application.internal.status; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/WaveStatusBarControl.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/WaveStatusBarControl.java similarity index 98% rename from com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/WaveStatusBarControl.java rename to com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/WaveStatusBarControl.java index 0e65bc2..5a44cc8 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/WaveStatusBarControl.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/WaveStatusBarControl.java @@ -8,7 +8,7 @@ * Contributors: * MINRES Technologies GmbH - initial API and implementation *******************************************************************************/ -package com.minres.scviewer.e4.application.internal; +package com.minres.scviewer.e4.application.internal.status; import javax.inject.Inject; import javax.inject.Named; diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/util/FileMonitor.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/util/FileMonitor.java new file mode 100644 index 0000000..5c42523 --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/util/FileMonitor.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.e4.application.internal.util; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Hashtable; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +/** + * Class monitoring a {@link File} for changes. + * + * @author Pascal Essiembre + */ +public class FileMonitor { + + private Timer timer; + + private Hashtable timerEntries; + + /** + * Constructor. + */ + public FileMonitor() { + // Create timer, run timer thread as daemon. + timer = new Timer(true); + timerEntries = new Hashtable(); + } + + /** + * Adds a monitored file with a FileChangeListener. + * + * @param listener + * listener to notify when the file changed. + * @param fileName + * name of the file to monitor. + * @param period + * polling period in milliseconds. + */ + public IModificationChecker addFileChangeListener(IFileChangeListener listener, File file, long period) { + return addFileChangeListener(listener, Arrays.asList(new File[]{file}), period); + } + + /** + * Adds a monitored file with a FileChangeListener. + * List filesToLoad + * @param listener + * listener to notify when the file changed. + * @param fileName + * name of the file to monitor. + * @param period + * polling period in milliseconds. + */ + public IModificationChecker addFileChangeListener(IFileChangeListener listener, List files, long period) { + removeFileChangeListener(listener); + FileSetMonitorTask task = new FileSetMonitorTask(listener, files, period); + timerEntries.put(Integer.toHexString(listener.hashCode()), task); + timer.schedule(task, period, period); + return task; + } + + /** + * Remove the listener from the notification list. + * + * @param listener + * the listener to be removed. + */ + public void removeFileChangeListener(IFileChangeListener listener) { + FileSetMonitorTask task = timerEntries.remove(Integer.toHexString(listener.hashCode())); + if (task != null) task.cancel(); + } + + /** + * Fires notification that a file changed. + * + * @param listener + * file change listener + * @param file + * the file that changed + */ + protected void fireFileChangeEvent(IFileChangeListener listener, List file) { + listener.fileChanged(file); + } + + /** + * File monitoring task. + */ + class FileSetMonitorTask extends TimerTask implements IModificationChecker{ + + IFileChangeListener listener; + + private List monitoredFiles; + + private List lastModifiedTimes; + + public final long period; + + public FileSetMonitorTask(IFileChangeListener listener, List monitoredFiles, long period) { + this.period=period; + this.monitoredFiles = monitoredFiles; + this.listener = listener; + lastModifiedTimes= new ArrayList<>(); + for(File monitoredFile:monitoredFiles){ + Long lmt = 0L; + try { + lmt=monitoredFile.lastModified(); + } catch(Exception e){} + lastModifiedTimes.add(lmt); + } + } + + public void run() { + check(); + } + + public void check() { + boolean res = false; + for(int i=0; i file); +} \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/util/IModificationChecker.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/util/IModificationChecker.java new file mode 100644 index 0000000..8da175a --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/util/IModificationChecker.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.e4.application.internal.util; + +public interface IModificationChecker { + + public void check(); + +} diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/PartListener.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/PartListener.java new file mode 100644 index 0000000..e12f76e --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/PartListener.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.e4.application.parts; + +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.workbench.modeling.IPartListener; + +public class PartListener implements IPartListener { + @Override + public void partBroughtToTop(MPart part) {} + + @Override + public void partActivated(MPart part) {} + + @Override + public void partDeactivated(MPart part) {} + + @Override + public void partHidden(MPart part) {} + + @Override + public void partVisible(MPart part) {} +} \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java index a6e89c3..e6b89c6 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java @@ -321,7 +321,7 @@ public class TransactionDetails { } } - enum Type {TIMES, PROPS, IN_REL, OUT_REL} + enum Type {PROPS, ATTRS, IN_REL, OUT_REL} class TreeNode{ public Type type; @@ -334,8 +334,8 @@ public class TransactionDetails { public String toString(){ switch(type){ - case TIMES: return "Times"; - case PROPS: return "Attributes"; + case PROPS: return "Properties"; + case ATTRS: return "Attributes"; case IN_REL: return "Incoming relations"; case OUT_REL: return "Outgoing relations"; } @@ -355,8 +355,8 @@ public class TransactionDetails { @Override public Object[] getElements(Object element) { return new Object[]{ - new TreeNode((ITx)element, Type.TIMES), new TreeNode((ITx)element, Type.PROPS), + new TreeNode((ITx)element, Type.ATTRS), new TreeNode((ITx)element, Type.IN_REL), new TreeNode((ITx)element, Type.OUT_REL) }; @@ -366,11 +366,14 @@ public class TransactionDetails { public Object[] getChildren(Object element) { if(element instanceof TreeNode){ TreeNode propertyHolder=(TreeNode) element; - if(propertyHolder.type == Type.TIMES) + if(propertyHolder.type == Type.PROPS){ return new Object[][]{ - {"Start time", "", timeToString(propertyHolder.element.getBeginTime())}, - {"End time", "", timeToString(propertyHolder.element.getEndTime())}}; - else if(propertyHolder.type == Type.PROPS) + {"Name", "String", propertyHolder.element.getStream().getFullName()}, + {"Type", "String", propertyHolder.element.getGenerator().getName()}, + {"Start time", "Time", timeToString(propertyHolder.element.getBeginTime())}, + {"End time", "Time", timeToString(propertyHolder.element.getEndTime())} + }; + }else if(propertyHolder.type == Type.ATTRS) return propertyHolder.element.getAttributes().toArray(); else if(propertyHolder.type == Type.IN_REL){ Vector res = new Vector<>(); diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformListPart.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformListPart.java index fb5e56c..912ee3a 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformListPart.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformListPart.java @@ -104,7 +104,7 @@ public class WaveformListPart implements ISelectionChangedListener { attributeFilter = new WaveformAttributeFilter(); txTableViewer = new TableViewer(parent); - txTableViewer.setContentProvider(new TxDbContentProvider()); + txTableViewer.setContentProvider(new TxDbContentProvider(true)); txTableViewer.setLabelProvider(new TxDbLabelProvider()); txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); txTableViewer.addSelectionChangedListener(this); @@ -240,7 +240,7 @@ public class WaveformListPart implements ISelectionChangedListener { if(part!=null && part.getObject() != this && selection!=null){ if( selection instanceof IStructuredSelection) { Object object= ((IStructuredSelection)selection).getFirstElement(); - if(object instanceof IHierNode&& !(object instanceof IWaveform)) + if(object instanceof IHierNode&& ((IHierNode)object).getChildNodes().size()!=0) txTableViewer.setInput(object); otherSelectionCount = (object instanceof IWaveform || object instanceof ITx)?1:0; } diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewerPart.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewerPart.java index 10af6be..590a99f 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewerPart.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewerPart.java @@ -15,6 +15,7 @@ import java.beans.PropertyChangeListener; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -32,43 +33,60 @@ import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.di.extensions.Preference; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.ui.di.Focus; import org.eclipse.e4.ui.di.PersistState; import org.eclipse.e4.ui.di.UIEventTopic; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.services.EMenuService; +import org.eclipse.e4.ui.workbench.modeling.EPartService; import org.eclipse.e4.ui.workbench.modeling.ESelectionService; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.resource.StringConverter; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import com.minres.scviewer.database.ITx; -import com.minres.scviewer.database.ITxEvent; -import com.minres.scviewer.database.ITxStream; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDbFactory; import com.minres.scviewer.database.IWaveformEvent; import com.minres.scviewer.database.swt.WaveformViewerFactory; import com.minres.scviewer.database.ui.GotoDirection; +import com.minres.scviewer.database.ui.ICursor; import com.minres.scviewer.database.ui.IWaveformViewer; import com.minres.scviewer.database.ui.TrackEntry; -import com.minres.scviewer.e4.application.internal.WaveStatusBarControl; +import com.minres.scviewer.database.ui.WaveformColors; +import com.minres.scviewer.e4.application.internal.status.WaveStatusBarControl; +import com.minres.scviewer.e4.application.internal.util.FileMonitor; +import com.minres.scviewer.e4.application.internal.util.IFileChangeListener; +import com.minres.scviewer.e4.application.internal.util.IModificationChecker; +import com.minres.scviewer.e4.application.preferences.DefaultValuesInitializer; +import com.minres.scviewer.e4.application.preferences.PreferenceConstants; -public class WaveformViewerPart { +@SuppressWarnings("restriction") +public class WaveformViewerPart implements IFileChangeListener, IPreferenceChangeListener { public static final String ACTIVE_WAVEFORMVIEW="Active_Waveform_View"; - + public static final String ADD_WAVEFORM="AddWaveform"; protected static final String DATABASE_FILE = "DATABASE_FILE"; - protected static final String SHOWN_WAVEFORM = "SHOWN_WAVEFORM"; + protected static final String SHOWN_CURSOR = "SHOWN_CURSOR"; + protected static final String ZOOM_LEVEL = "ZOOM_LEVEL"; + + protected static final long FILE_CHECK_INTERVAL=60000; private String[] zoomLevel; @@ -86,17 +104,29 @@ public class WaveformViewerPart { @Inject ESelectionService selectionService; + @Inject EPartService ePartService; + + @Inject @Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE) IEclipsePreferences prefs; + private IWaveformDb database; + private boolean checkForUpdates; + + private MPart myPart; + private Composite myParent; ArrayList filesToLoad; Map persistedState; + FileMonitor fileMonitor = new FileMonitor(); + + IModificationChecker fileChecker; @PostConstruct public void createComposite(MPart part, Composite parent, IWaveformDbFactory dbFactory) { + myPart=part; myParent=parent; database=dbFactory.getDatabase(); database.addPropertyChangeListener(new PropertyChangeListener() { @@ -119,7 +149,7 @@ public class WaveformViewerPart { public void propertyChange(PropertyChangeEvent evt) { Long time = (Long) evt.getNewValue(); eventBroker.post(WaveStatusBarControl.CURSOR_TIME, waveformPane.getScaledTime(time)); - long marker=waveformPane.getActMarkerTime(); + long marker=waveformPane.getSelectedMarkerTime(); eventBroker.post(WaveStatusBarControl.MARKER_DIFF, waveformPane.getScaledTime(time-marker)); } @@ -141,6 +171,8 @@ public class WaveformViewerPart { } }); zoomLevel=waveformPane.getZoomLevels(); + setupColors(); + checkForUpdates=prefs.getBoolean(PreferenceConstants.DATABASE_RELOAD, true); filesToLoad=new ArrayList(); persistedState = part.getPersistedState(); Integer files = persistedState.containsKey(DATABASE_FILE+"S")?Integer.parseInt(persistedState.get(DATABASE_FILE+"S")):0; @@ -148,14 +180,51 @@ public class WaveformViewerPart { filesToLoad.add(new File(persistedState.get(DATABASE_FILE+i))); } if(filesToLoad.size()>0) - loadDatabase(); + loadDatabase(persistedState); eventBroker.post(WaveStatusBarControl.ZOOM_LEVEL, zoomLevel[waveformPane.getZoomLevel()]); menuService.registerContextMenu(waveformPane.getNameControl(), "com.minres.scviewer.e4.application.popupmenu.namecontext"); menuService.registerContextMenu(waveformPane.getValueControl(), "com.minres.scviewer.e4.application.popupmenu.namecontext"); menuService.registerContextMenu(waveformPane.getWaveformControl(), "com.minres.scviewer.e4.application.popupmenu.wavecontext"); + ePartService.addPartListener(new PartListener(){ + @Override + public void partActivated(MPart part) { + if (part == myPart) { + if(fileChecker!=null) fileChecker.check(); + updateAll(); + } + } + }); + prefs.addPreferenceChangeListener(this); } - protected void loadDatabase() { + @Override + public void preferenceChange(PreferenceChangeEvent event) { + if(PreferenceConstants.DATABASE_RELOAD.equals(event.getKey())){ + checkForUpdates = (Boolean) event.getNewValue(); + fileChecker=null; + if(checkForUpdates) + fileChecker=fileMonitor.addFileChangeListener(WaveformViewerPart.this,filesToLoad, FILE_CHECK_INTERVAL); + else + fileMonitor.removeFileChangeListener(this); + } else { + setupColors(); + } + } + + protected void setupColors() { + DefaultValuesInitializer initializer = new DefaultValuesInitializer(); + HashMap colorPref=new HashMap<>(); + for (WaveformColors c : WaveformColors.values()) { + String prefValue=prefs.get(c.name() + "_COLOR", + StringConverter.asString(initializer.colors[c.ordinal()].getRGB())); + RGB rgb = StringConverter.asRGB(prefValue); + colorPref.put(c, rgb); + } + waveformPane.setColors(colorPref); + } + + protected void loadDatabase(final Map state) { + fileMonitor.removeFileChangeListener(this); Job job = new Job(" My Job") { @Override protected IStatus run( IProgressMonitor monitor) { @@ -189,7 +258,10 @@ public class WaveformViewerPart { @Override public void run() { waveformPane.setMaxTime(database.getMaxTime()); - restoreState(); + if(state!=null) restoreWaveformViewerState(state); + fileChecker=null; + if(checkForUpdates) fileChecker=fileMonitor.addFileChangeListener( + WaveformViewerPart.this,filesToLoad, FILE_CHECK_INTERVAL); } }); } @@ -197,6 +269,23 @@ public class WaveformViewerPart { job.schedule(0); } + @Override + public void fileChanged(List file) { + final Display display = myParent.getDisplay(); + display.asyncExec(new Runnable() { + @Override + public void run() { + if(MessageDialog.openQuestion(display.getActiveShell(), "Database re-load", "Would you like to reload the database?")){ + Map state = new HashMap<>(); + saveWaveformViewerState(state); + waveformPane.getStreamList().clear(); + database.clear(); + if(filesToLoad.size()>0) loadDatabase(state); + } + } + }); + } + @Inject @Optional public void setPartInput( @Named( "input" ) Object partInput ) { @@ -222,16 +311,16 @@ public class WaveformViewerPart { } } if(filesToLoad.size()>0) - loadDatabase(); + loadDatabase(persistedState); } } @Focus public void setFocus() { myParent.setFocus(); - updateAll(); } + @PersistState public void saveState(MPart part) { // save changes @@ -242,30 +331,57 @@ public class WaveformViewerPart { persistedState.put(DATABASE_FILE+index, file.getAbsolutePath()); index++; } + saveWaveformViewerState(persistedState); + } + + protected void saveWaveformViewerState(Map persistedState) { + Integer index; persistedState.put(SHOWN_WAVEFORM+"S", Integer.toString(waveformPane.getStreamList().size())); index=0; for(TrackEntry trackEntry:waveformPane.getStreamList()){ persistedState.put(SHOWN_WAVEFORM+index, trackEntry.waveform.getFullName()); index++; } + List cursors = waveformPane.getCursorList(); + persistedState.put(SHOWN_CURSOR+"S", Integer.toString(cursors.size())); + index=0; + for(ICursor cursor:cursors){ + persistedState.put(SHOWN_CURSOR+index, Long.toString(cursor.getTime())); + index++; + } + persistedState.put(ZOOM_LEVEL, Integer.toString(waveformPane.getZoomLevel())); } - protected void restoreState() { + protected void restoreWaveformViewerState(Map state) { updateAll(); - Integer waves = persistedState.containsKey(SHOWN_WAVEFORM+"S")?Integer.parseInt(persistedState.get(SHOWN_WAVEFORM+"S")):0; + Integer waves = state.containsKey(SHOWN_WAVEFORM+"S")?Integer.parseInt(state.get(SHOWN_WAVEFORM+"S")):0; List res = new LinkedList<>(); for(int i=0; i waveform = database.getStreamByName(persistedState.get(SHOWN_WAVEFORM+i)); + IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM+i)); if(waveform!=null) res.add(new TrackEntry(waveform)); } if(res.size()>0) waveformPane.getStreamList().addAll(res); + Integer cursorLength = state.containsKey(SHOWN_CURSOR+"S")?Integer.parseInt(state.get(SHOWN_CURSOR+"S")):0; + List cursors = waveformPane.getCursorList(); + if(cursorLength==cursors.size()){ + for(int i=0; i waveform, - @Optional @Named( IServiceConstants.ACTIVE_PART) MPart part) { - if (txDisplay!= null && part.getObject()!=this) { - txDisplay.setSelection(waveform==null?new StructuredSelection():new StructuredSelection(waveform)); - } - } - */ + protected boolean askIfToLoad(File txFile) { if(txFile.exists() && MessageDialog.openQuestion(myParent.getDisplay().getActiveShell(), "Database open", @@ -394,4 +502,5 @@ public class WaveformViewerPart { public String getScaledTime(Long time) { return waveformPane.getScaledTime(time); } -} + +} \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/DefaultValuesInitializer.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/DefaultValuesInitializer.java new file mode 100644 index 0000000..4a0f3a1 --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/DefaultValuesInitializer.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.e4.application.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.StringConverter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.wb.swt.SWTResourceManager; + +import com.minres.scviewer.database.ui.WaveformColors; +import com.opcoach.e4.preferences.ScopedPreferenceStore; + +public class DefaultValuesInitializer extends AbstractPreferenceInitializer { + + public final Color[] colors = new Color[WaveformColors.values().length]; + + public DefaultValuesInitializer() { + colors[WaveformColors.LINE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED); + colors[WaveformColors.LINE_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_CYAN); + colors[WaveformColors.TRACK_BG_EVEN.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_BLACK); + colors[WaveformColors.TRACK_BG_ODD.ordinal()] = SWTResourceManager.getColor(40, 40, 40); + colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(40, 40, 80); + colors[WaveformColors.TX_BG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GREEN); + colors[WaveformColors.TX_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); + colors[WaveformColors.TX_BORDER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED); + colors[WaveformColors.SIGNAL0.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); + colors[WaveformColors.SIGNAL1.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); + colors[WaveformColors.SIGNALZ.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GRAY); + colors[WaveformColors.SIGNALX.ordinal()] = SWTResourceManager.getColor(255, 128, 182); + colors[WaveformColors.SIGNAL_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); + colors[WaveformColors.CURSOR.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED); + colors[WaveformColors.CURSOR_DRAG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GRAY); + colors[WaveformColors.CURSOR_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); + colors[WaveformColors.MARKER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY); + colors[WaveformColors.MARKER_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); + + } + + @Override + public void initializeDefaultPreferences() { + IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE); + + store.setDefault(PreferenceConstants.DATABASE_RELOAD, true); + for (WaveformColors c : WaveformColors.values()) { + store.setDefault(c.name()+"_COLOR", StringConverter.asString(colors[c.ordinal()].getRGB())); + } + } + +} diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/PreferenceConstants.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/PreferenceConstants.java new file mode 100644 index 0000000..92c42dc --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/PreferenceConstants.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.e4.application.preferences; + +public class PreferenceConstants { + + public static final String PREFERENCES_SCOPE="com.minres.scviewer.e4.application"; + public static final String DATABASE_RELOAD="databaseReload"; + public static final String LINE_COLOR="LINE_COLOR"; + public static final String LINE_HIGHLITE_COLOR="LINE_HIGHLITE_COLOR"; + public static final String TRACK_BG_EVEN_COLOR="TRACK_BG_EVEN_COLOR"; + public static final String TRACK_BG_ODD_COLOR="TRACK_BG_ODD_COLOR"; + public static final String TRACK_BG_HIGHLITE_COLOR="TRACK_BG_HIGHLITE_COLOR"; + public static final String TX_BG_COLOR="TX_BG_COLOR"; + public static final String TX_BG_HIGHLITE_COLOR="TX_BG_HIGHLITE_COLOR"; + public static final String TX_BORDER_COLOR="TX_BORDER_COLOR"; + public static final String SIGNAL0_COLOR="SIGNAL0_COLOR"; + public static final String SIGNAL1_COLOR="SIGNAL1_COLOR"; + public static final String SIGNALZ_COLOR="SIGNALZ_COLOR"; + public static final String SIGNALX_COLOR="SIGNALX_COLOR"; + public static final String SIGNAL_TEXT_COLOR="SIGNAL_TEXT_COLOR"; + public static final String CURSOR_COLOR="CURSOR_COLOR"; + public static final String CURSOR_DRAG_COLOR="CURSOR_DRAG_COLOR"; + public static final String CURSOR_TEXT_COLOR="CURSOR_TEXT_COLOR"; + public static final String MARKER_COLOR="MARKER_COLOR"; + public static final String MARKER_TEXT_COLOR="MARKER_TEXT_COLOR"; + + +} diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/SCViewerPreferencesPage.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/SCViewerPreferencesPage.java new file mode 100644 index 0000000..c175829 --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/SCViewerPreferencesPage.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.e4.application.preferences; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; + +/** A sample preference page to show how it works */ +public class SCViewerPreferencesPage extends FieldEditorPreferencePage { + + public SCViewerPreferencesPage() { + super(GRID); + } + + @Override + protected void createFieldEditors() { + + addField(new BooleanFieldEditor(PreferenceConstants.DATABASE_RELOAD, "Check for changed database", + getFieldEditorParent())); + + } + +} diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/WaveformPreferencesPage.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/WaveformPreferencesPage.java new file mode 100644 index 0000000..207a25b --- /dev/null +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/preferences/WaveformPreferencesPage.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2015 MINRES Technologies GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.e4.application.preferences; + +import org.eclipse.jface.preference.ColorFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; + +import com.minres.scviewer.database.ui.WaveformColors; + +/** A sample preference page to show how it works */ +public class WaveformPreferencesPage extends FieldEditorPreferencePage { + + public WaveformPreferencesPage() { + super(GRID); + } + + @Override + protected void createFieldEditors() { + + for (WaveformColors c : WaveformColors.values()) { + addField(new ColorFieldEditor(c.name() + "_COLOR", "Color for " + c.name().toLowerCase(), + getFieldEditorParent())); + } + } + +} diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/provider/TxDbContentProvider.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/provider/TxDbContentProvider.java index 36410b9..62ccd8a 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/provider/TxDbContentProvider.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/provider/TxDbContentProvider.java @@ -10,6 +10,7 @@ *******************************************************************************/ package com.minres.scviewer.e4.application.provider; +import java.util.Collection; import java.util.List; import org.eclipse.jface.viewers.ITreeContentProvider; @@ -23,25 +24,40 @@ import com.minres.scviewer.database.IWaveform; public class TxDbContentProvider implements ITreeContentProvider { // private List nodes; - private boolean showNodes=false; + private boolean showNodes; + + public TxDbContentProvider() { + super(); + this.showNodes = false; + } + + public TxDbContentProvider(boolean showNodes) { + super(); + this.showNodes = showNodes; + } @Override public void dispose() { } @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - showNodes=!(newInput instanceof IHierNode); +// showNodes=!(newInput instanceof IHierNode); } @Override public Object[] getElements(Object inputElement) { if(inputElement instanceof IHierNode){ - return Collections2.filter(((IHierNode)inputElement).getChildNodes(), new Predicate(){ + Collection res = Collections2.filter(((IHierNode)inputElement).getChildNodes(), new Predicate(){ @Override public boolean apply(IHierNode arg0) { - return (arg0 instanceof IWaveform)!=showNodes; + if(showNodes){ + return arg0 instanceof IWaveform; + } else{ + return arg0.getChildNodes().size()!=0; + } } - }).toArray(); + }); + return res.toArray(); }else if(inputElement instanceof List) return ((List)inputElement).toArray(); else @@ -60,7 +76,6 @@ public class TxDbContentProvider implements ITreeContentProvider { @Override public boolean hasChildren(Object element) { - // Object[] obj = getChildren(element); Object[] obj = getElements(element); return obj == null ? false : obj.length > 0; } diff --git a/com.minres.scviewer.e4.application/src/org/eclipse/wb/swt/ResourceManager.java b/com.minres.scviewer.e4.application/src/org/eclipse/wb/swt/ResourceManager.java index 4bfbc6b..f42c09f 100644 --- a/com.minres.scviewer.e4.application/src/org/eclipse/wb/swt/ResourceManager.java +++ b/com.minres.scviewer.e4.application/src/org/eclipse/wb/swt/ResourceManager.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2015 MINRES Technologies GmbH and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Google, Inc. - initial API and implementation + * MINRES Technologies GmbH - initial API and implementation *******************************************************************************/ package org.eclipse.wb.swt; diff --git a/com.minres.scviewer.e4.product/SCViewer.launch b/com.minres.scviewer.e4.product/SCViewer.launch index c5fab17..42c4138 100644 --- a/com.minres.scviewer.e4.product/SCViewer.launch +++ b/com.minres.scviewer.e4.product/SCViewer.launch @@ -16,14 +16,14 @@ - + - +