From: jkauttio Date: Wed, 4 Jun 2014 13:40:04 +0000 (+0000) Subject: Add options to simulation result saving dialog to allow filtering data based on sever... X-Git-Tag: 1.8.1~39 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f96c3b27b256cef578040c0c87742e2e3eab6d40;p=simantics%2Fsysdyn.git Add options to simulation result saving dialog to allow filtering data based on several criteria (the filtering process could be improved as the implementation is currently very simple and thus inefficient and inaccurate in some cases) fixes #4919 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29587 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryDialog.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryDialog.java index 08882f88..44547c08 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryDialog.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryDialog.java @@ -22,8 +22,13 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; @@ -38,6 +43,15 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3 { private String sheetName; private String sheetLocation; + + private GridData filterLayout; + + private boolean filterStart = false; + private boolean startValid = false; + private double start; + private boolean filterStep = false; + private boolean stepValid = false; + private int step; public SaveHistoryDialog(Shell shell, Map> parameter, String title) { @@ -58,7 +72,7 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3 { } @Override - protected Control createExtendedContentArea(Composite parent_) { + protected Control createExtendedContentArea(final Composite parent_) { Composite parent = new Composite(parent_, SWT.NONE); GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent); @@ -88,6 +102,101 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3 { } }); GridDataFactory.fillDefaults().grab(true, false).applyTo(t2); + + // filter options + Composite filterControls = new Composite(parent, SWT.NONE); + GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(filterControls); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(filterControls); + + Button filterButton = new Button(filterControls, SWT.ARROW | SWT.DOWN); + GridDataFactory.fillDefaults().applyTo(filterButton); + Label filterLabel = new Label(filterControls, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(filterLabel); + + filterButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + filterLayout.exclude = !filterLayout.exclude; + parent_.layout(); + } + }); + + filterLabel.setText("show filter options"); + GridDataFactory.fillDefaults().applyTo(filterLabel); + + Composite filterOptions = new Composite(parent, SWT.NONE); + filterLayout = GridDataFactory.fillDefaults().span(2, 1).grab(true, false).exclude(true).create(); + filterOptions.setLayoutData(filterLayout); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(filterOptions); + + final Button startButton = new Button(filterOptions, SWT.CHECK); + GridDataFactory.fillDefaults().applyTo(startButton); + startButton.setText("start time (in terms of simulation time)"); + final Text startInput = new Text(filterOptions, SWT.BORDER); + GridDataFactory.fillDefaults().applyTo(startInput); + + startButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + filterStart = startButton.getSelection(); + startInput.setEnabled(filterStart); + startInput.setBackground(Display.getCurrent().getSystemColor( + !filterStart || startValid ? SWT.COLOR_WIDGET_BACKGROUND : SWT.COLOR_YELLOW)); + validatePage(); + } + }); + + startInput.setEnabled(false); + startInput.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + try { + start = Double.parseDouble(startInput.getText()); + startValid = true; + } + catch (Exception ex) { + startValid = false; + } + startInput.setBackground(Display.getCurrent().getSystemColor( + startValid ? SWT.COLOR_WIDGET_BACKGROUND : SWT.COLOR_YELLOW)); + validatePage(); + } + }); + + final Button stepButton = new Button(filterOptions, SWT.CHECK); + GridDataFactory.fillDefaults().applyTo(stepButton); + stepButton.setText("sample rate (1 = every step, 2 = every other step...)"); + final Text stepInput = new Text(filterOptions, SWT.BORDER); + GridDataFactory.fillDefaults().applyTo(stepInput); + + stepButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + filterStep = stepButton.getSelection(); + stepInput.setEnabled(filterStep); + stepInput.setBackground(Display.getCurrent().getSystemColor( + !filterStep || stepValid ? SWT.COLOR_WIDGET_BACKGROUND : SWT.COLOR_YELLOW)); + validatePage(); + } + }); + + stepInput.setEnabled(false); + stepInput.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + try { + step = Integer.parseInt(stepInput.getText()); + stepValid = true; + } + catch (Exception ex) { + stepValid = false; + } + stepInput.setBackground(Display.getCurrent().getSystemColor( + stepValid ? SWT.COLOR_WIDGET_BACKGROUND : SWT.COLOR_YELLOW)); + validatePage(); + } + }); + validatePage(); return super.createExtendedContentArea(parent); } @@ -117,6 +226,12 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3 { return; } + error = validateFilter(); + if (error != null) { + updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, error)); + return; + } + updateStatus(new Status(Status.OK, Activator.PLUGIN_ID, "")); } @@ -137,6 +252,18 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3 { return e.getMessage(); } } + + protected String validateFilter() { + if (filterStart && !startValid) { + return "Invalid start time in filter"; + } + else if (filterStep && !stepValid) { + return "Invalid sample rate in filter"; + } + else { + return null; + } + } public String getSheetName() { return sheetName; @@ -146,4 +273,20 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3 { return sheetLocation; } + public boolean filterStart() { + return filterStart; + } + + public double getStart() { + return start; + } + + public boolean filterStep() { + return filterStep; + } + + public int getStep() { + return step; + } + } \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java index 054beef5..f4a103c0 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java @@ -78,6 +78,12 @@ public class SaveHistoryHandler extends AbstractHandler { final Object[] result = dialog.getResult(); final String sheetName = dialog.getSheetName(); final String sheetLocation = dialog.getSheetLocation(); + + final boolean filterStart = dialog.filterStart(); + final double start = dialog.getStart(); + final boolean filterStep = dialog.filterStep(); + final int step = dialog.getStep(); + Simantics.getSession().syncRequest(new WriteRequest() { public void writeCell(WriteGraph graph, Variable sheet, String cellName, String value) throws DatabaseException { @@ -108,20 +114,29 @@ public class SaveHistoryHandler extends AbstractHandler { Range base = SpreadsheetUtils.decodeCellAbsolute(sheetLocation); + int row = base.startRow; DataSet first = (DataSet)result[0]; - writeCell(graph, sheet, sheetLocation, "times"); + writeCell(graph, sheet, SpreadsheetUtils.cellName(row++, base.startColumn), "time"); for(int i=0;i