6: Add Load/Save state functionality

Task-Url: https://github.com/eyck/txviewer/issues/issue/6
This commit is contained in:
Eyck Jentzsch 2015-11-30 22:16:29 +01:00
parent 31ed3e4858
commit ff4cb91aed
7 changed files with 159 additions and 46 deletions

View File

@ -20,6 +20,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.NoSuchElementException;
import java.util.TreeMap;
import org.eclipse.core.runtime.ListenerList;
@ -772,6 +773,7 @@ public class WaveformViewer implements IWaveformViewer {
protected void paintNames(GC gc, Rectangle rect) {
if (streams.size() > 0) {
try {
Integer firstKey = trackVerticalOffset.floorKey(rect.y);
if (firstKey == null)
firstKey = trackVerticalOffset.firstKey();
@ -792,11 +794,13 @@ public class WaveformViewer implements IWaveformViewer {
drawTextFormat(gc, subArea, entry.getKey(), w.getFullName(), entry.getValue().selected);
}
}
}catch(NoSuchElementException e){}
}
}
protected void paintValues(GC gc, Rectangle rect) {
if (streams.size() > 0) {
try {
Integer firstKey = trackVerticalOffset.floorKey(rect.y);
if (firstKey == null)
firstKey = trackVerticalOffset.firstKey();
@ -818,6 +822,7 @@ public class WaveformViewer implements IWaveformViewer {
drawValue(gc, subArea, entry.getKey(), actualValues.get(w), entry.getValue().selected);
}
}
}catch(NoSuchElementException e){}
}
}

View File

@ -34,8 +34,13 @@
</children>
<mainMenu xmi:id="_95PfyXNmEeWBq8z1Dv39LA" elementId="menu:org.eclipse.ui.main.menu">
<children xsi:type="menu:Menu" xmi:id="_95QGwHNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.menu.file" label="File">
<children xsi:type="menu:HandledMenuItem" xmi:id="_VJG3YHgvEeWwZ-9vrAR2UQ" elementId="" label="Open" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/folder_database.png" command="_95PfwHNmEeWBq8z1Dv39LA"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_95QGwnNmEeWBq8z1Dv39LA" label="Save" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/save_edit.png" command="_95Pfw3NmEeWBq8z1Dv39LA"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_VJG3YHgvEeWwZ-9vrAR2UQ" elementId="" label="Open Database" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/folder_database.png" command="_95PfwHNmEeWBq8z1Dv39LA"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_e7MOYJedEeW09eyIbHsdvg" elementId="" label="Load settings" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/folder_page.png" command="_7-AIMJebEeW09eyIbHsdvg">
<parameters xmi:id="_4vtYgJehEeW09eyIbHsdvg" elementId="com.minres.scviewer.e4.application.parameter.30" name="com.minres.scviewer.e4.application.commandparameter.loadStore" value="load"/>
</children>
<children xsi:type="menu:HandledMenuItem" xmi:id="_95QGwnNmEeWBq8z1Dv39LA" label="Save settings" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/script_save.png" command="_7-AIMJebEeW09eyIbHsdvg">
<parameters xmi:id="_61QIsJehEeW09eyIbHsdvg" elementId="com.minres.scviewer.e4.application.parameter.31" name="com.minres.scviewer.e4.application.commandparameter.loadStore" value="store"/>
</children>
<children xsi:type="menu:HandledMenuItem" xmi:id="_95QGw3NmEeWBq8z1Dv39LA" label="Quit" command="_95PfvHNmEeWBq8z1Dv39LA"/>
</children>
<children xsi:type="menu:Menu" xmi:id="_ZyHC0HgvEeWwZ-9vrAR2UQ" elementId="" label="Edit">
@ -77,6 +82,9 @@
<trimBars xmi:id="_95QGy3NmEeWBq8z1Dv39LA" elementId="org.eclipse.ui.main.toolbar">
<children xsi:type="menu:ToolBar" xmi:id="_95QGzHNmEeWBq8z1Dv39LA" elementId="toolbar:org.eclipse.ui.main.toolbar">
<children xsi:type="menu:HandledToolItem" xmi:id="_95QGzXNmEeWBq8z1Dv39LA" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/folder_database.png" tooltip="Open new database" command="_95PfwHNmEeWBq8z1Dv39LA"/>
<children xsi:type="menu:HandledToolItem" xmi:id="_o9UBUJeiEeW09eyIbHsdvg" elementId="com.minres.scviewer.e4.application.handledtoolitem.loadsettings" label="Load settings" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/folder_page.png" command="_7-AIMJebEeW09eyIbHsdvg">
<parameters xmi:id="_tQZAEJeiEeW09eyIbHsdvg" elementId="com.minres.scviewer.e4.application.parameter.32" name="com.minres.scviewer.e4.application.commandparameter.loadStore" value="load"/>
</children>
<children xsi:type="menu:HandledToolItem" xmi:id="_95QGznNmEeWBq8z1Dv39LA" toBeRendered="false" visible="false" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/save_edit.png" command="_95Pfw3NmEeWBq8z1Dv39LA"/>
</children>
<children xsi:type="menu:ToolBar" xmi:id="_VUv_AHckEeWwZ-9vrAR2UQ" elementId="com.minres.scviewer.e4.application.toolbar.0">
@ -145,6 +153,7 @@
<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"/>
<handlers xmi:id="_UUnX8IoNEeWxJ_wPkM6yGQ" elementId="com.minres.scviewer.e4.application.handler.set_them" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.ThemeSetHandler" command="_KlGlsIoNEeWxJ_wPkM6yGQ"/>
<handlers xmi:id="_V4EscIuGEeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.handler.setreleationtype" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.SetRelationTypeHandler" command="_E9lUgIt2EeWid7xO48ZBXw"/>
<handlers xmi:id="__99WoJebEeW09eyIbHsdvg" elementId="com.minres.scviewer.e4.application.handler.loadStoreSettings" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.LoadStoreSettingsHandler" command="_7-AIMJebEeW09eyIbHsdvg"/>
<bindingTables xmi:id="_95PfvnNmEeWBq8z1Dv39LA" bindingContext="_95PfuXNmEeWBq8z1Dv39LA">
<bindings xmi:id="_95Pfv3NmEeWBq8z1Dv39LA" keySequence="M1+Q" command="_95PfvHNmEeWBq8z1Dv39LA"/>
<bindings xmi:id="_95PfwnNmEeWBq8z1Dv39LA" keySequence="M1+O" command="_95PfwHNmEeWBq8z1Dv39LA"/>
@ -226,6 +235,9 @@
<commands xmi:id="_E9lUgIt2EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.command.setrelationtype" commandName="SetRelationType">
<parameters xmi:id="_xnW7IIt_EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.commandparameter.relationName" name="relationName" optional="false"/>
</commands>
<commands xmi:id="_7-AIMJebEeW09eyIbHsdvg" elementId="com.minres.scviewer.e4.application.command.loadStoreSettings" commandName="loadStoreSettings">
<parameters xmi:id="_wxY3EJehEeW09eyIbHsdvg" elementId="com.minres.scviewer.e4.application.commandparameter.loadStore" name="loadStore"/>
</commands>
<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"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 804 B

View File

@ -0,0 +1,57 @@
/*******************************************************************************
* 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;
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import com.minres.scviewer.e4.application.parts.WaveformViewer;
public class LoadStoreSettingsHandler {
static final String PARAMETER_ID="com.minres.scviewer.e4.application.commandparameter.loadStore";
@CanExecute
public boolean canExecute(EPartService partService) {
MPart part = partService.getActivePart();
if(part==null) return false;
return (part.getObject() instanceof WaveformViewer);
}
@Execute
public void execute(@Named(PARAMETER_ID) String param, Shell shell, MApplication app, EModelService modelService,
EPartService partService){
boolean load = "load".equals(param);
FileDialog dialog = new FileDialog(shell, load?SWT.OPEN:SWT.SAVE);
dialog.setFilterExtensions (new String []{"*.scview"});
if(!load) dialog.setFileName("SCViewer.scview");
String res = dialog.open();
MPart part = partService.getActivePart();
if(res!=null && part!=null){
Object obj = part.getObject();
if(obj instanceof WaveformViewer){
if(load)
((WaveformViewer)obj).loadState(res);
else
((WaveformViewer)obj).saveState(res);
}
}
}
}

View File

@ -27,8 +27,9 @@ public class OpenHandler {
@Execute
public void execute(Shell shell, MApplication app, EModelService modelService, EPartService partService){
FileDialog dialog = new FileDialog(shell, SWT.MULTI);
dialog.setFilterExtensions (new String []{"vcd", "txdb", "txlog"});
FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
// dialog.setFilterExtensions (new String []{"vcd", "txdb", "txlog"});
dialog.setFilterExtensions (new String []{"*.vcd;*.txdb;*.txlog"});
dialog.open();
String path = dialog.getFilterPath();
for(String fileName: dialog.getFileNames()){
@ -36,8 +37,7 @@ public class OpenHandler {
if(file.exists()){
// MPart part = MBasicFactory.INSTANCE.createPart();
// part.setLabel(fileName);
// part.setContributionURI("bundleclass://com.minres.scviewer.e4.application/"+
// WaveformViewerPart.class.getName());
// part.setContributionURI("bundleclass://com.minres.scviewer.e4.application/"+ WaveformViewerPart.class.getName());
MPart part = partService .createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer");
part.setLabel(file.getName());

View File

@ -13,12 +13,17 @@ package com.minres.scviewer.e4.application.parts;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -426,6 +431,40 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
saveWaveformViewerState(persistedState);
}
public void saveState(String fileName){
Map<String, String> persistedState = new HashMap<>();
persistedState.put(DATABASE_FILE + "S", Integer.toString(filesToLoad.size()));
Integer index = 0;
for (File file : filesToLoad) {
persistedState.put(DATABASE_FILE + index, file.getAbsolutePath());
index++;
}
saveWaveformViewerState(persistedState);
Properties props = new Properties();
props.putAll(persistedState);
try {
FileOutputStream out = new FileOutputStream(fileName);
props.store(out, "Written by SCViewer");
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void loadState(String fileName){
Properties props = new Properties();
try {
FileInputStream in = new FileInputStream(fileName);
props.load(in);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
HashMap<String, String> propMap = new HashMap<String, String>((Map) props);
restoreWaveformViewerState(propMap);
}
/**
* Save waveform viewer state.
*