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
\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
}\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
}\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
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
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
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
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
\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