- added preference dialog

- added preference handling
- added file monitor to automatically reload changed database
This commit is contained in:
2015-11-12 23:35:13 +01:00
parent c1d84ceb01
commit 5680af1b45
34 changed files with 796 additions and 167 deletions

View File

@ -70,6 +70,9 @@
</children>
</children>
</children>
<children xsi:type="menu:Menu" xmi:id="_JTXBgIl_EeWxJ_wPkM6yGQ" elementId="com.minres.scviewer.e4.application.menu.window" label="Window">
<children xsi:type="menu:HandledMenuItem" xmi:id="_JTXBgYl_EeWxJ_wPkM6yGQ" elementId="" label="Preferences" command="_AxH6sIl_EeWxJ_wPkM6yGQ"/>
</children>
<children xsi:type="menu:Menu" xmi:id="_95QGxHNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.menu.help" label="Help">
<children xsi:type="menu:HandledMenuItem" xmi:id="_95QGxXNmEeWBq8z1Dv39LA" label="About" command="_95PfxnNmEeWBq8z1Dv39LA"/>
</children>
@ -117,13 +120,13 @@
</children>
</trimBars>
<trimBars xmi:id="_JHMt8HS8EeWBq8z1Dv39LA" elementId="org.eclipse.ui.trim.status" side="Bottom">
<children xsi:type="menu:ToolControl" xmi:id="_YsBi8HfLEeWwZ-9vrAR2UQ" elementId="org.eclipse.ui.StatusLine" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.internal.WaveStatusBarControl">
<children xsi:type="menu:ToolControl" xmi:id="_YsBi8HfLEeWwZ-9vrAR2UQ" elementId="org.eclipse.ui.StatusLine" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.internal.status.WaveStatusBarControl">
<tags>stretch</tags>
</children>
<children xsi:type="menu:ToolControl" xmi:id="_VZzJMHdHEeWwZ-9vrAR2UQ" elementId="org.eclipse.ui.HeapStatus" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.internal.StatusBarControl">
<children xsi:type="menu:ToolControl" xmi:id="_VZzJMHdHEeWwZ-9vrAR2UQ" elementId="org.eclipse.ui.HeapStatus" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.internal.status.StatusBarControl">
<tags>Draggable</tags>
</children>
<children xsi:type="menu:ToolControl" xmi:id="_y0ZS0HfzEeWwZ-9vrAR2UQ" elementId="org.eclipse.ui.ProgressBar" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.internal.StatusBarControl">
<children xsi:type="menu:ToolControl" xmi:id="_y0ZS0HfzEeWwZ-9vrAR2UQ" elementId="org.eclipse.ui.ProgressBar" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.internal.status.StatusBarControl">
<tags>Draggable</tags>
</children>
</trimBars>
@ -133,6 +136,7 @@
<handlers xmi:id="_95PfxHNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.handler.saveCommand" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.SaveHandler" command="_95Pfw3NmEeWBq8z1Dv39LA"/>
<handlers xmi:id="_95Pfx3NmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.handler.aboutCommand" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.AboutHandler" command="_95PfxnNmEeWBq8z1Dv39LA"/>
<handlers xmi:id="_3ZZhsHXHEeWwZ-9vrAR2UQ" elementId="com.minres.scviewer.e4.application.handler.selectallCommand" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.SelectAllHandler" command="_bV-TMHXHEeWwZ-9vrAR2UQ"/>
<handlers xmi:id="_CTcpEIl_EeWxJ_wPkM6yGQ" elementId="com.minres.scviewer.e4.application.handler.preferences" contributionURI="bundleclass://com.opcoach.e4.preferences/com.opcoach.e4.preferences.handlers.E4PreferencesHandler" command="_AxH6sIl_EeWxJ_wPkM6yGQ"/>
<bindingTables xmi:id="_95PfvnNmEeWBq8z1Dv39LA" bindingContext="_95PfuXNmEeWBq8z1Dv39LA">
<bindings xmi:id="_95Pfv3NmEeWBq8z1Dv39LA" keySequence="M1+Q" command="_95PfvHNmEeWBq8z1Dv39LA"/>
<bindings xmi:id="_95PfwnNmEeWBq8z1Dv39LA" keySequence="M1+O" command="_95PfwHNmEeWBq8z1Dv39LA"/>
@ -207,6 +211,7 @@
<parameters xmi:id="_6KsZcHr9EeWVM_sKoXvptg" elementId="com.minres.scviewer.e4.application.command.addwaveform.where" name="where" optional="false"/>
<parameters xmi:id="_7T1TcHwIEeWv0Y5uF2QN5w" elementId="com.minres.scviewer.e4.application.command.addwaveform.all" name="all" typeId="" optional="false"/>
</commands>
<commands xmi:id="_AxH6sIl_EeWxJ_wPkM6yGQ" elementId="org.eclipse.ui.window.preferences" commandName="Preferences"/>
<addons xmi:id="_95PfsnNmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
<addons xmi:id="_95Pfs3NmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
<addons xmi:id="_95PftHNmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
@ -214,4 +219,5 @@
<addons xmi:id="_95PftnNmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
<addons xmi:id="_95Pft3NmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
<addons xmi:id="_95PfuHNmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
<addons xmi:id="_zSk-cIkcEeWxJ_wPkM6yGQ" elementId="org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon"/>
</application:Application>

View File

@ -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"

View File

@ -64,5 +64,25 @@
</with>
</definition>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="com.minres.scviewer.e4.application.preferences.DefaultValuesInitializer">
</initializer>
</extension>
<extension
point="com.opcoach.e4.preferences.e4PreferencePages">
<page
class="com.minres.scviewer.e4.application.preferences.SCViewerPreferencesPage"
id="com.minres.scviewer.e4.application.preferences.scviewer"
name="SCViewer Page">
</page>
<page
class="com.minres.scviewer.e4.application.preferences.WaveformPreferencesPage"
id="com.minres.scviewer.e4.application.preferences.waveform"
name="Waveform view"
category="com.minres.scviewer.e4.application.preferences.scviewer">
</page>
</extension>
</plugin>

View File

@ -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;

View File

@ -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;

View File

@ -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.
*

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<String, FileSetMonitorTask> timerEntries;
/**
* Constructor.
*/
public FileMonitor() {
// Create timer, run timer thread as daemon.
timer = new Timer(true);
timerEntries = new Hashtable<String, FileSetMonitorTask>();
}
/**
* 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<File> 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<File> 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> file) {
listener.fileChanged(file);
}
/**
* File monitoring task.
*/
class FileSetMonitorTask extends TimerTask implements IModificationChecker{
IFileChangeListener listener;
private List<File> monitoredFiles;
private List<Long> lastModifiedTimes;
public final long period;
public FileSetMonitorTask(IFileChangeListener listener, List<File> 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<monitoredFiles.size(); ++i){
File file = monitoredFiles.get(i);
Long lmt = 0L;
try {
lmt=file.lastModified();
} catch(Exception e){}
if (!lmt.equals(lastModifiedTimes.get(i)))
res |= true;
lastModifiedTimes.set(i, lmt);
}
if(res)
fireFileChangeEvent(this.listener, monitoredFiles);
}
}
}

View File

@ -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.internal.util;
import java.io.File;
import java.util.List;
/**
* Listener interested in {@link File} changes.
*
* @author Pascal Essiembre
*/
public interface IFileChangeListener {
/**
* Invoked when a file changes.
*
* @param fileName
* name of changed file.
*/
public void fileChanged(List<File> file);
}

View File

@ -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();
}

View File

@ -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) {}
}

View File

@ -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<Object[] > res = new Vector<>();

View File

@ -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;
}

View File

@ -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<File> filesToLoad;
Map<String, String> 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<File>();
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<WaveformColors, RGB> 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<String, String> 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> 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<String, String> 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<String, String> 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<ICursor> 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<String, String> 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<TrackEntry> res = new LinkedList<>();
for(int i=0; i<waves;i++){
IWaveform<? extends IWaveformEvent> waveform = database.getStreamByName(persistedState.get(SHOWN_WAVEFORM+i));
IWaveform<? extends IWaveformEvent> 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<ICursor> cursors = waveformPane.getCursorList();
if(cursorLength==cursors.size()){
for(int i=0; i<cursorLength;i++){
Long time = Long.parseLong(state.get(SHOWN_CURSOR+i));
cursors.get(i).setTime(time);
}
}
if(state.containsKey(ZOOM_LEVEL)){
try {
Integer scale = Integer.parseInt(state.get(ZOOM_LEVEL));
waveformPane.setZoomLevel(scale);
} catch(NumberFormatException e){}
}
}
private void updateAll() {
eventBroker.post(ACTIVE_WAVEFORMVIEW, this);
eventBroker.post(WaveStatusBarControl.ZOOM_LEVEL, zoomLevel[waveformPane.getZoomLevel()]);
long cursor=waveformPane.getCursorTime();
long marker=waveformPane.getActMarkerTime();
long marker=waveformPane.getSelectedMarkerTime();
eventBroker.post(WaveStatusBarControl.CURSOR_TIME, waveformPane.getScaledTime(cursor));
eventBroker.post(WaveStatusBarControl.MARKER_TIME, waveformPane.getScaledTime(marker));
eventBroker.post(WaveStatusBarControl.MARKER_DIFF, waveformPane.getScaledTime(cursor-marker));
@ -281,15 +397,7 @@ public class WaveformViewerPart {
}
}
/*
@Inject
public void setWaveform(@Optional @Named( IServiceConstants.ACTIVE_SELECTION) IWaveform<?> 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);
}
}
}

View File

@ -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()));
}
}
}

View File

@ -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";
}

View File

@ -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()));
}
}

View File

@ -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()));
}
}
}

View File

@ -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<HierNode> 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<IHierNode>(){
Collection<IHierNode> res = Collections2.filter(((IHierNode)inputElement).getChildNodes(), new Predicate<IHierNode>(){
@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;
}

View File

@ -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;