Fixed 'Save Settings' #4
This commit is contained in:
parent
79eb8073d8
commit
3a6ed3ce7e
|
@ -38,10 +38,10 @@
|
|||
<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 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">
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_e7MOYJedEeW09eyIbHsdvg" elementId="" label="Load active tab 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">
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_95QGwnNmEeWBq8z1Dv39LA" label="Save active tab 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"/>
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
|
@ -20,6 +22,7 @@ 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.MessageBox;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import com.minres.scviewer.e4.application.Messages;
|
||||
|
@ -38,21 +41,60 @@ public class LoadStoreSettingsHandler {
|
|||
@Execute
|
||||
public void execute(@Named(PARAMETER_ID) String param, Shell shell, MApplication app, EModelService modelService,
|
||||
EPartService partService){
|
||||
|
||||
boolean load = "load".equals(param); //$NON-NLS-1$
|
||||
FileDialog dialog = new FileDialog(shell, load?SWT.OPEN:SWT.SAVE);
|
||||
dialog.setFilterExtensions (new String []{Messages.LoadStoreSettingsHandler_2});
|
||||
if(!load) dialog.setFileName(Messages.LoadStoreSettingsHandler_3);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String fileName = null;
|
||||
MPart part = partService.getActivePart();
|
||||
Object obj = part.getObject();
|
||||
|
||||
// Save active tab settings
|
||||
if(!load) {
|
||||
// 3 possible cases when when saving active tab settings:
|
||||
// - user dismisses the dialog by pressing Cancel
|
||||
// - selected file name does not exist
|
||||
// - user agrees to overwrite existing file
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
// open the File Dialog
|
||||
fileName = dialog.open();
|
||||
if (fileName == null) {
|
||||
// user has cancelled -> quit and return
|
||||
done = true;
|
||||
} else {
|
||||
// user has selected a file -> see if it already exists
|
||||
File file = new File(fileName);
|
||||
if (file.exists()) {
|
||||
// file already exists -> asks for confirmation
|
||||
MessageBox mb = new MessageBox(dialog.getParent(), SWT.ICON_WARNING
|
||||
| SWT.YES | SWT.NO);
|
||||
mb.setText("Confirm overwrite");
|
||||
mb.setMessage(fileName + " already exists. Do you want to overwrite it?");
|
||||
// user clicks Yes -> all done, drop out
|
||||
if(mb.open() == SWT.YES) {
|
||||
((WaveformViewer)obj).saveState(fileName);
|
||||
done = true;
|
||||
} else { // user clicks No -> redisplay the File Dialog
|
||||
done = false;
|
||||
}
|
||||
} else {
|
||||
// file does not exist -> save and drop out
|
||||
((WaveformViewer)obj).saveState(fileName);
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
} // end if(!load)
|
||||
|
||||
else { // load active tab settings
|
||||
String res = dialog.open();
|
||||
if(res != null && part!=null && (obj instanceof WaveformViewer)) {
|
||||
((WaveformViewer)obj).loadState(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -74,6 +74,7 @@ import org.eclipse.swt.widgets.Event;
|
|||
import org.eclipse.swt.widgets.Listener;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.ITxRelation;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
|
@ -127,6 +128,15 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
/** The Constant BASE_LINE_TIME. */
|
||||
protected static final String BASE_LINE_TIME = "BASE_LINE_TIME"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant SELECTED_TX_ID. */
|
||||
protected static final String SELECTED_TX_ID = "SELECTED_TX_ID"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant SELECTED_TRACKENTRY_NAME. */
|
||||
protected static final String SELECTED_TRACKENTRY_NAME = "SELECTED_TRACKENTRY_NAME"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant WAVEFORM_SELECTED. */
|
||||
protected static final String WAVEFORM_SELECTED = ".WAVEFORM_SELECTED"; //$NON-NLS-1$
|
||||
|
||||
/** The Constant FILE_CHECK_INTERVAL. */
|
||||
protected static final long FILE_CHECK_INTERVAL = 60000;
|
||||
|
||||
|
@ -578,6 +588,8 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
}
|
||||
|
||||
public void saveState(String fileName){
|
||||
|
||||
|
||||
Map<String, String> persistedState = new HashMap<>();
|
||||
persistedState.put(DATABASE_FILE + "S", Integer.toString(filesToLoad.size())); //$NON-NLS-1$
|
||||
Integer index = 0;
|
||||
|
@ -588,10 +600,14 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
saveWaveformViewerState(persistedState);
|
||||
Properties props = new Properties();
|
||||
props.putAll(persistedState);
|
||||
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(fileName);
|
||||
props.store(out, "Written by SCViewer"); //$NON-NLS-1$
|
||||
out.close();
|
||||
|
||||
FileOutputStream out = new FileOutputStream(fileName);
|
||||
props.store(out, "Written by SCViewer"); //$NON-NLS-1$
|
||||
out.close();
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -600,6 +616,13 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
public void loadState(String fileName){
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
//clear old streams before loading tab settings
|
||||
if(!waveformPane.getStreamList().isEmpty()) {
|
||||
waveformPane.getStreamList().clear();
|
||||
for (TrackEntry trackEntry : waveformPane.getStreamList()) {
|
||||
trackEntry.selected = false;
|
||||
}
|
||||
}
|
||||
FileInputStream in = new FileInputStream(fileName);
|
||||
props.load(in);
|
||||
in.close();
|
||||
|
@ -619,12 +642,15 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
*/
|
||||
protected void saveWaveformViewerState(Map<String, String> persistedState) {
|
||||
Integer index;
|
||||
boolean isStream = false;
|
||||
persistedState.put(SHOWN_WAVEFORM + "S", Integer.toString(waveformPane.getStreamList().size())); //$NON-NLS-1$
|
||||
index = 0;
|
||||
for (TrackEntry trackEntry : waveformPane.getStreamList()) {
|
||||
if(trackEntry.isStream()) { isStream=true; }
|
||||
persistedState.put(SHOWN_WAVEFORM + index, trackEntry.waveform.getFullName());
|
||||
persistedState.put(SHOWN_WAVEFORM + index + VALUE_DISPLAY, trackEntry.valueDisplay.toString());
|
||||
persistedState.put(SHOWN_WAVEFORM + index + WAVE_DISPLAY, trackEntry.waveDisplay.toString());
|
||||
persistedState.put(SHOWN_WAVEFORM + index + WAVEFORM_SELECTED, String.valueOf(trackEntry.selected).toUpperCase());
|
||||
index++;
|
||||
}
|
||||
List<ICursor> cursors = waveformPane.getCursorList();
|
||||
|
@ -636,6 +662,36 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
}
|
||||
persistedState.put(ZOOM_LEVEL, Integer.toString(waveformPane.getZoomLevel()));
|
||||
persistedState.put(BASE_LINE_TIME, Long.toString(waveformPane.getBaselineTime()));
|
||||
|
||||
// get selected transaction of a stream
|
||||
ISelection selection = waveformPane.getSelection();
|
||||
if (!selection.isEmpty() && isStream) {
|
||||
List<Object> t = getISelection(selection);
|
||||
ITx tx = (ITx) t.get(0);
|
||||
TrackEntry te = (TrackEntry) t.get(1);
|
||||
// get transaction id
|
||||
persistedState.put(SELECTED_TX_ID, Long.toString(tx.getId()));
|
||||
//get TrackEntry name
|
||||
String name = te.getStream().getFullName();
|
||||
persistedState.put(SELECTED_TRACKENTRY_NAME, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Object> getISelection(ISelection selection){
|
||||
List<Object> result = new LinkedList<Object> ();
|
||||
|
||||
if ( selection instanceof IStructuredSelection )
|
||||
{
|
||||
Iterator<?> i = ((IStructuredSelection)selection).iterator();
|
||||
while (i.hasNext()){
|
||||
Object o = i.next ();
|
||||
if (o == null) {
|
||||
continue;
|
||||
}
|
||||
result.add(o);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -650,6 +706,13 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM + i));
|
||||
if (waveform != null) {
|
||||
TrackEntry t = new TrackEntry(waveform);
|
||||
//check if t is selected
|
||||
boolean isSelected = Boolean.valueOf(state.get(SHOWN_WAVEFORM + i + WAVEFORM_SELECTED));
|
||||
if(isSelected) {
|
||||
t.selected = true;
|
||||
} else {
|
||||
t.selected = false;
|
||||
}
|
||||
res.add(t);
|
||||
String v = state.get(SHOWN_WAVEFORM + i + VALUE_DISPLAY);
|
||||
if(v!=null)
|
||||
|
@ -683,6 +746,38 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
if (state.containsKey(SELECTED_TX_ID) && state.containsKey(SELECTED_TRACKENTRY_NAME)) {
|
||||
try {
|
||||
Long txId = Long.parseLong(state.get(SELECTED_TX_ID));
|
||||
String trackentryName = state.get(SELECTED_TRACKENTRY_NAME);
|
||||
|
||||
//get TrackEntry Object based on name and TX Object by id and put into selectionList
|
||||
for(TrackEntry te : res) {
|
||||
if(te.waveform.getFullName().compareTo(trackentryName)==0) {
|
||||
boolean found = false;
|
||||
// TODO: find transaction by time? To avoid 3x for-loop
|
||||
for( List<ITxEvent> lev : te.getStream().getEvents().values() ) {
|
||||
if(lev == null) continue;
|
||||
for(ITxEvent itxe : lev) {
|
||||
if(itxe == null) continue;
|
||||
ITx itx = itxe.getTransaction();
|
||||
if(itx.getId() == txId) {
|
||||
found = true;
|
||||
ArrayList<Object> selectionList = new ArrayList<Object>();
|
||||
selectionList.add(te);
|
||||
selectionList.add(itx);
|
||||
waveformPane.setSelection(new StructuredSelection (selectionList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found) break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
updateAll();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue