]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Add options to simulation result saving dialog to allow filtering data based on sever...
authorjkauttio <jkauttio@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 4 Jun 2014 13:40:04 +0000 (13:40 +0000)
committerjkauttio <jkauttio@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 4 Jun 2014 13:40:04 +0000 (13:40 +0000)
fixes #4919

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29587 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryDialog.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java

index 08882f88695bc98e0cca507886b4a6c6c28abc48..44547c0872493b094d11c28805591e0f451c55c6 100644 (file)
@@ -22,8 +22,13 @@ import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.events.ModifyEvent;\r
 import org.eclipse.swt.events.ModifyListener;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Display;\r
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Text;\r
@@ -38,6 +43,15 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3<DataSet> {
 \r
        private String sheetName;\r
        private String sheetLocation;\r
+       \r
+       private GridData filterLayout;\r
+       \r
+       private boolean filterStart = false;\r
+       private boolean startValid = false;\r
+       private double start;\r
+       private boolean filterStep = false;\r
+       private boolean stepValid = false;\r
+       private int step;\r
 \r
        public SaveHistoryDialog(Shell shell,\r
                        Map<DataSet, Pair<String, ImageDescriptor>> parameter, String title) {\r
@@ -58,7 +72,7 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3<DataSet> {
        }\r
 \r
        @Override\r
-       protected Control createExtendedContentArea(Composite parent_) {\r
+       protected Control createExtendedContentArea(final Composite parent_) {\r
 \r
                Composite parent = new Composite(parent_, SWT.NONE);\r
                GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent);\r
@@ -88,6 +102,101 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3<DataSet> {
                        }\r
                });\r
                GridDataFactory.fillDefaults().grab(true, false).applyTo(t2);\r
+               \r
+               // filter options\r
+               Composite filterControls = new Composite(parent, SWT.NONE);\r
+               GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(filterControls);\r
+               GridLayoutFactory.fillDefaults().numColumns(2).applyTo(filterControls);\r
+               \r
+               Button filterButton = new Button(filterControls, SWT.ARROW | SWT.DOWN);\r
+               GridDataFactory.fillDefaults().applyTo(filterButton);\r
+               Label filterLabel = new Label(filterControls, SWT.NONE);\r
+               GridDataFactory.fillDefaults().applyTo(filterLabel);\r
+               \r
+               filterButton.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               filterLayout.exclude = !filterLayout.exclude;\r
+                               parent_.layout();\r
+                       }\r
+               });\r
+               \r
+               filterLabel.setText("show filter options");\r
+               GridDataFactory.fillDefaults().applyTo(filterLabel);\r
+               \r
+               Composite filterOptions = new Composite(parent, SWT.NONE);\r
+               filterLayout = GridDataFactory.fillDefaults().span(2, 1).grab(true, false).exclude(true).create();\r
+               filterOptions.setLayoutData(filterLayout);\r
+               GridLayoutFactory.fillDefaults().numColumns(2).applyTo(filterOptions);\r
+               \r
+               final Button startButton = new Button(filterOptions, SWT.CHECK);\r
+               GridDataFactory.fillDefaults().applyTo(startButton);\r
+               startButton.setText("start time (in terms of simulation time)");\r
+               final Text startInput = new Text(filterOptions, SWT.BORDER);\r
+               GridDataFactory.fillDefaults().applyTo(startInput);\r
+               \r
+               startButton.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               filterStart = startButton.getSelection();\r
+                               startInput.setEnabled(filterStart);\r
+                               startInput.setBackground(Display.getCurrent().getSystemColor(\r
+                                               !filterStart || startValid ? SWT.COLOR_WIDGET_BACKGROUND : SWT.COLOR_YELLOW));\r
+                               validatePage();\r
+                       }\r
+               });\r
+               \r
+               startInput.setEnabled(false);\r
+               startInput.addModifyListener(new ModifyListener() {\r
+                       @Override\r
+                       public void modifyText(ModifyEvent e) {\r
+                               try {\r
+                                       start = Double.parseDouble(startInput.getText());\r
+                                       startValid = true;\r
+                               }\r
+                               catch (Exception ex) {\r
+                                       startValid = false;\r
+                               }\r
+                               startInput.setBackground(Display.getCurrent().getSystemColor(\r
+                                               startValid ? SWT.COLOR_WIDGET_BACKGROUND : SWT.COLOR_YELLOW));\r
+                               validatePage();\r
+                       }\r
+               });\r
+               \r
+               final Button stepButton = new Button(filterOptions, SWT.CHECK);\r
+               GridDataFactory.fillDefaults().applyTo(stepButton);\r
+               stepButton.setText("sample rate (1 = every step, 2 = every other step...)");\r
+               final Text stepInput = new Text(filterOptions, SWT.BORDER);\r
+               GridDataFactory.fillDefaults().applyTo(stepInput);\r
+               \r
+               stepButton.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               filterStep = stepButton.getSelection();\r
+                               stepInput.setEnabled(filterStep);\r
+                               stepInput.setBackground(Display.getCurrent().getSystemColor(\r
+                                               !filterStep || stepValid ? SWT.COLOR_WIDGET_BACKGROUND : SWT.COLOR_YELLOW));\r
+                               validatePage();\r
+                       }\r
+               });\r
+               \r
+               stepInput.setEnabled(false);\r
+               stepInput.addModifyListener(new ModifyListener() {\r
+                       @Override\r
+                       public void modifyText(ModifyEvent e) {\r
+                               try {\r
+                                       step = Integer.parseInt(stepInput.getText());\r
+                                       stepValid = true;\r
+                               }\r
+                               catch (Exception ex) {\r
+                                       stepValid = false;\r
+                               }\r
+                               stepInput.setBackground(Display.getCurrent().getSystemColor(\r
+                                               stepValid ? SWT.COLOR_WIDGET_BACKGROUND : SWT.COLOR_YELLOW));\r
+                               validatePage();\r
+                       }\r
+               });\r
+               \r
                validatePage();\r
                return super.createExtendedContentArea(parent);\r
        }\r
@@ -117,6 +226,12 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3<DataSet> {
                        return;\r
                }\r
                \r
+               error = validateFilter();\r
+               if (error != null) {\r
+                       updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, error));\r
+                       return;\r
+               }\r
+               \r
                updateStatus(new Status(Status.OK, Activator.PLUGIN_ID, ""));\r
                \r
        }\r
@@ -137,6 +252,18 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3<DataSet> {
                        return e.getMessage();\r
                }\r
        }\r
+       \r
+       protected String validateFilter() {\r
+               if (filterStart && !startValid) {\r
+                       return "Invalid start time in filter";\r
+               }\r
+               else if (filterStep && !stepValid) {\r
+                       return "Invalid sample rate in filter";\r
+               }\r
+               else {\r
+                       return null;\r
+               }\r
+       }\r
 \r
        public String getSheetName() {\r
                return sheetName;\r
@@ -146,4 +273,20 @@ public class SaveHistoryDialog extends ResourceSelectionDialog3<DataSet> {
                return sheetLocation;\r
        }\r
        \r
+       public boolean filterStart() {\r
+               return filterStart;\r
+       }\r
+       \r
+       public double getStart() {\r
+               return start;\r
+       }\r
+       \r
+       public boolean filterStep() {\r
+               return filterStep;\r
+       }\r
+       \r
+       public int getStep() {\r
+               return step;\r
+       }\r
+       \r
 }
\ No newline at end of file
index 054beef53b59ff5c390f6947ac2afff0d1f69695..f4a103c01add0d117ca383f0a0988ff1275954f3 100644 (file)
@@ -78,6 +78,12 @@ public class SaveHistoryHandler extends AbstractHandler {
                     final Object[] result = dialog.getResult();\r
                     final String sheetName = dialog.getSheetName();\r
                     final String sheetLocation = dialog.getSheetLocation();\r
+                    \r
+                    final boolean filterStart = dialog.filterStart();\r
+                    final double start = dialog.getStart();\r
+                    final boolean filterStep = dialog.filterStep();\r
+                    final int step = dialog.getStep();\r
+                    \r
                     Simantics.getSession().syncRequest(new WriteRequest() {\r
 \r
                        public void writeCell(WriteGraph graph, Variable sheet, String cellName, String value) throws DatabaseException {\r
@@ -108,20 +114,29 @@ public class SaveHistoryHandler extends AbstractHandler {
                                \r
                                Range base = SpreadsheetUtils.decodeCellAbsolute(sheetLocation);\r
                                \r
+                               int row = base.startRow;\r
                                DataSet first = (DataSet)result[0];\r
-                               writeCell(graph, sheet, sheetLocation, "times");\r
+                               writeCell(graph, sheet, SpreadsheetUtils.cellName(row++, base.startColumn), "time");\r
                                for(int i=0;i<first.times.length;i++) {\r
-                                       String loc = SpreadsheetUtils.cellName(base.startRow+1+i, base.startColumn);\r
-                                       writeCell(graph, sheet, loc, "" + first.times[i]);      \r
+                                       if (filterStep && i % step != 0)\r
+                                               continue;\r
+                                       if (filterStart && first.times[i] < start)\r
+                                               continue;\r
+                                       String loc = SpreadsheetUtils.cellName(row++, base.startColumn);\r
+                                       writeCell(graph, sheet, loc, Double.toString(first.times[i]));\r
                                }\r
                                \r
                                for(int j=0;j<result.length;j++) {\r
-\r
+                                       row = base.startRow;\r
                                        first = (DataSet)result[j];\r
-                                       writeCell(graph, sheet, SpreadsheetUtils.cellName(base.startRow, base.startColumn+1+j), first.name);\r
+                                       writeCell(graph, sheet, SpreadsheetUtils.cellName(row++, base.startColumn+1+j), first.name);\r
                                        for(int i=0;i<first.values.length;i++) {\r
-                                               String loc = SpreadsheetUtils.cellName(base.startRow+1+i, base.startColumn+1+j);\r
-                                               writeCell(graph, sheet, loc, "" + first.values[i]);     \r
+                                               if (filterStep && i % step != 0)\r
+                                                       continue;\r
+                                               if (filterStart && first.times[i] < start)\r
+                                                       continue;\r
+                                               String loc = SpreadsheetUtils.cellName(row++, base.startColumn+1+j);\r
+                                               writeCell(graph, sheet, loc, Double.toString(first.values[i])); \r
                                        }\r
 \r
                                }\r