-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.charts.ui;\r
-\r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import org.eclipse.core.runtime.preferences.InstanceScope;\r
-import org.eclipse.jface.layout.GridDataFactory;\r
-import org.eclipse.jface.layout.GridLayoutFactory;\r
-import org.eclipse.jface.preference.IPreferenceStore;\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.CCombo;\r
-import org.eclipse.swt.custom.ScrolledComposite;\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.events.SelectionListener;\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.FileDialog;\r
-import org.eclipse.swt.widgets.Group;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Table;\r
-import org.eclipse.swt.widgets.TableItem;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.eclipse.ui.preferences.ScopedPreferenceStore;\r
-import org.simantics.NameLabelUtil;\r
-import org.simantics.Simantics;\r
-import org.simantics.browsing.ui.common.ColumnKeys;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.parser.StringEscapeUtils;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.NamedResource;\r
-import org.simantics.db.common.request.IsParent;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.SelectionHints;\r
-import org.simantics.history.csv.ColumnSeparator;\r
-import org.simantics.history.csv.DecimalSeparator;\r
-import org.simantics.history.csv.ExportInterpolation;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.modeling.ModelingUtils;\r
-import org.simantics.modeling.preferences.CSVPreferences;\r
-import org.simantics.modeling.ui.modelBrowser2.label.SubscriptionItemLabelRule;\r
-import org.simantics.utils.datastructures.Arrays;\r
-import org.simantics.utils.datastructures.Pair;\r
-import org.simantics.utils.strings.AlphanumComparator;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
-\r
-\r
-/**\r
- * @author Antti Villberg\r
- */\r
-public class CSVExportPage extends WizardPage {\r
-\r
- CSVExportPlan exportModel;\r
- CCombo model;\r
- Table item;\r
- Button selectAllItems;\r
- SelectionAdapter selectAllItemsListener;\r
- CCombo exportLocation;\r
-\r
- CCombo decimalSeparator;\r
- CCombo columnSeparator;\r
- CCombo sampling;\r
- Text timeStep;\r
- Text startTime;\r
- Text timeStamps;\r
- CCombo samplingMode;\r
- Text singlePrecision;\r
- Text doublePrecision;\r
-\r
- Group resampling;\r
-\r
- Collection<Resource> initialSelection;\r
-\r
- List<Pair<NamedResource,List<NamedResource>>> models = new ArrayList<>();\r
-\r
- private Button overwrite;\r
-\r
- ModifyListener m = (e) -> validatePage();\r
-\r
- SelectionListener s = new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- validatePage();\r
- }\r
- };\r
-\r
- protected CSVExportPage(CSVExportPlan model) {\r
- super("Export CSV Data", "Define Export Properties", null);\r
- this.exportModel = model;\r
- }\r
-\r
- @Override\r
- public void createControl(Composite parent) {\r
- ScrolledComposite scroller = new ScrolledComposite(parent, SWT.V_SCROLL);\r
- scroller.setExpandHorizontal(true);\r
- scroller.setExpandVertical(true);\r
-\r
- Composite container = new Composite(scroller, SWT.NONE);\r
- scroller.setContent(container);\r
- GridLayoutFactory.swtDefaults().spacing(20, 10).numColumns(3).applyTo(container);\r
- new Label(container, SWT.NONE).setText("Select a model:");\r
- model = new CCombo(container, SWT.BORDER);\r
- {\r
- model.setEditable(false);\r
- model.setText("");\r
- model.setToolTipText("Selects the Model To Export From");\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(model);\r
- }\r
-\r
- new Label(container, SWT.NONE).setText("Exported items:");\r
- item = new Table(container, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);\r
- {\r
- item.setToolTipText("Selects the Subscription Items");\r
- GridDataFactory.fillDefaults().grab(true, true).span(2, 1).hint(SWT.DEFAULT, 105).applyTo(item);\r
- }\r
- item.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (e.detail == SWT.CHECK) {\r
- TableItem[] selected = item.getSelection();\r
- TableItem it = (TableItem) e.item;\r
- boolean checkedWasSelected = Arrays.contains(selected, it);\r
- if (checkedWasSelected) {\r
- boolean check = it.getChecked();\r
- for (TableItem i : selected)\r
- i.setChecked(check);\r
- }\r
- int checked = countCheckedItems(item);\r
- int totalItems = item.getItemCount();\r
- updateSelectAll(checked > 0, checked < totalItems, false);\r
- validatePage();\r
- }\r
- }\r
- });\r
- new Label(container, 0);\r
- selectAllItems = new Button(container, SWT.CHECK);\r
- {\r
- selectAllItems.setText("&Select All");\r
- selectAllItems.setToolTipText("Select/Deselect All Listed Subscription Items");\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(selectAllItems);\r
- }\r
- selectAllItemsListener = new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- boolean select = selectAllItems.getSelection();\r
- updateSelectAll(select, false, false);\r
- item.setRedraw(false);\r
- for (TableItem it : item.getItems())\r
- it.setChecked(select);\r
- item.setRedraw(true);\r
-\r
- validatePage();\r
- }\r
- };\r
- selectAllItems.addSelectionListener(selectAllItemsListener);\r
-\r
- new Label(container, SWT.NONE).setText("&Output file:");\r
- exportLocation = new CCombo(container, SWT.BORDER);\r
- {\r
- exportLocation.setText("");\r
- GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(exportLocation);\r
- exportLocation.addModifyListener(m);\r
- }\r
- Button browseFileButton = new Button(container, SWT.PUSH);\r
- {\r
- browseFileButton.setText("Browse...");\r
- browseFileButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
- browseFileButton.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);\r
- dialog.setText("Choose Output File");\r
- dialog.setFilterPath(new File(exportLocation.getText()).getParent());\r
- dialog.setFilterExtensions(new String[] { "*.csv" });\r
- dialog.setFilterNames(new String[] { "Comma separated values (*.csv)" });\r
- dialog.setOverwrite(false);\r
- String file = dialog.open();\r
- if (file == null)\r
- return;\r
- exportLocation.setText(file);\r
- validatePage();\r
- }\r
- });\r
- }\r
-\r
- \r
- Label horizRule = new Label(container, SWT.BORDER);\r
- GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 0).grab(true, false).span(3, 1).applyTo(horizRule);\r
-\r
- new Label(container, SWT.NONE).setText("&Decimal separator:");\r
- decimalSeparator = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);\r
- for(DecimalSeparator s : DecimalSeparator.values())\r
- decimalSeparator.add(s.label);\r
- decimalSeparator.select(0);\r
- decimalSeparator.addSelectionListener(s);\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(decimalSeparator);\r
-\r
- new Label(container, SWT.NONE).setText("&Column separator:");\r
- columnSeparator = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);\r
- for(ColumnSeparator s : ColumnSeparator.values())\r
- columnSeparator.add(s.label);\r
- columnSeparator.select(0);\r
- columnSeparator.addSelectionListener(s);\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(columnSeparator);\r
-\r
- new Label(container, SWT.NONE).setText("Sampling:");\r
- sampling = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);\r
- sampling.add("Recorded samples");\r
- sampling.add("Resampled");\r
- sampling.select(0);\r
- sampling.addSelectionListener(s);\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(sampling);\r
-\r
- resampling = new Group(container, SWT.NONE);\r
- resampling.setText("Resampling settings (not used with recorded samples)");\r
- GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(resampling);\r
- GridLayoutFactory.swtDefaults().numColumns(3).applyTo(resampling);\r
-\r
- new Label(resampling, SWT.NONE).setText("&Start time:");\r
- startTime = new Text(resampling, SWT.BORDER);\r
- startTime.addModifyListener(m);\r
- GridDataFactory.fillDefaults().grab(true, false).applyTo(startTime);\r
- new Label(resampling, SWT.NONE).setText(" seconds");\r
-\r
- new Label(resampling, SWT.NONE).setText("&Time step:");\r
- timeStep = new Text(resampling, SWT.BORDER);\r
- timeStep.addModifyListener(m);\r
- GridDataFactory.fillDefaults().grab(true, false).applyTo(timeStep);\r
- new Label(resampling, SWT.NONE).setText(" seconds");\r
- \r
- new Label(resampling, SWT.NONE).setText("Sampling mode:");\r
- samplingMode = new CCombo(resampling, SWT.READ_ONLY | SWT.BORDER);\r
- samplingMode.add("Linear interpolation");\r
- samplingMode.add("Previous sample");\r
- samplingMode.select(0);\r
- samplingMode.addSelectionListener(s);\r
- GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(samplingMode);\r
-\r
- Group digits = new Group(container, SWT.NONE);\r
- digits.setText("Significant digits");\r
- GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(digits);\r
- GridLayoutFactory.swtDefaults().numColumns(2).applyTo(digits);\r
-\r
- new Label(digits, SWT.NONE).setText("&Time stamps:");\r
- timeStamps = new Text(digits, SWT.BORDER);\r
- timeStamps.addModifyListener(m);\r
- GridDataFactory.fillDefaults().grab(true, false).applyTo(timeStamps);\r
- \r
- new Label(digits, SWT.NONE).setText("&Single precision floating point:");\r
- singlePrecision = new Text(digits, SWT.BORDER);\r
- singlePrecision.addModifyListener(m);\r
- GridDataFactory.fillDefaults().grab(true, false).applyTo(singlePrecision);\r
-\r
- new Label(digits, SWT.NONE).setText("&Double precision floating point:");\r
- doublePrecision = new Text(digits, SWT.BORDER);\r
- doublePrecision.addModifyListener(m);\r
- GridDataFactory.fillDefaults().grab(true, false).applyTo(doublePrecision);\r
-\r
- overwrite = new Button(container, SWT.CHECK);\r
- overwrite.setText("&Overwrite existing files without warning");\r
- overwrite.setSelection(exportModel.overwrite);\r
- GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(overwrite);\r
- overwrite.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- validatePage();\r
- }\r
- });\r
-\r
- try {\r
- initializeData();\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
-\r
- model.addSelectionListener(s);\r
-\r
- scroller.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
-\r
- setControl(scroller);\r
- validatePage();\r
- \r
- }\r
-\r
- void updateSelectAll(boolean checked, boolean gray, boolean notify) {\r
- if (checked) {\r
- selectAllItems.setText("Select None");\r
- } else {\r
- selectAllItems.setText("Select All");\r
- }\r
- if (!notify)\r
- selectAllItems.removeSelectionListener(selectAllItemsListener);\r
- selectAllItems.setGrayed(checked && gray);\r
- selectAllItems.setSelection(checked);\r
- if (!notify)\r
- selectAllItems.addSelectionListener(selectAllItemsListener);\r
- }\r
-\r
- protected int countCheckedItems(Table table) {\r
- int ret = 0;\r
- for (TableItem item : table.getItems())\r
- ret += item.getChecked() ? 1 : 0;\r
- return ret;\r
- }\r
-\r
- private void initializeData() throws DatabaseException {\r
-\r
- // Write preferences to formatter\r
- IPreferenceStore csvnode = new ScopedPreferenceStore( InstanceScope.INSTANCE, CSVPreferences.P_NODE );\r
- \r
- Double startTime = csvnode.getDouble(CSVPreferences.P_CSV_START_TIME);\r
- Double timeStep = csvnode.getDouble(CSVPreferences.P_CSV_TIME_STEP);\r
- String decimalSeparator = csvnode.getString(CSVPreferences.P_CSV_DECIMAL_SEPARATOR);\r
- String columnSeparator = StringEscapeUtils.unescape( csvnode.getString(CSVPreferences.P_CSV_COLUMN_SEPARATOR) );\r
- Boolean resample = csvnode.getBoolean(CSVPreferences.P_CSV_RESAMPLE);\r
- String samplingModePreference = csvnode.getString(CSVPreferences.P_CSV_SAMPLING_MODE);\r
- int timeDigits = csvnode.getInt(CSVPreferences.P_CSV_TIME_DIGITS);\r
- int floatDigits = csvnode.getInt(CSVPreferences.P_CSV_FLOAT_DIGITS);\r
- int doubleDigits = csvnode.getInt(CSVPreferences.P_CSV_DOUBLE_DIGITS);\r
- \r
- initialSelection = ISelectionUtils.getPossibleKeys(exportModel.selection, SelectionHints.KEY_MAIN, Resource.class);\r
-\r
- models = exportModel.sessionContext.getSession().syncRequest(new UniqueRead<List<Pair<NamedResource,List<NamedResource>>>>() {\r
-\r
- @Override\r
- public List<Pair<NamedResource,List<NamedResource>>> perform(ReadGraph graph) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- ModelingResources MOD = ModelingResources.getInstance(graph);\r
- List<Pair<NamedResource,List<NamedResource>>> result = new ArrayList<>();\r
- for(Resource model : graph.syncRequest(new org.simantics.db.layer0.request.ProjectModels(Simantics.getProjectResource()))) {\r
- String name = graph.getPossibleRelatedValue(model, L0.HasName, Bindings.STRING);\r
- if(name == null) continue;\r
- name = NameLabelUtil.modalName(graph, model);\r
- List<NamedResource> subs = new ArrayList<>();\r
- for(Resource item : ModelingUtils.searchByType(graph, model, MOD.Subscription_Item)) {\r
- String subscriptionLabel = null;\r
- Resource subscription = graph.getPossibleObject(item, L0.PartOf);\r
- if(subscription != null) {\r
- subscriptionLabel = graph.getPossibleRelatedValue(subscription, L0.HasLabel, Bindings.STRING);\r
- }\r
- SubscriptionItemLabelRule rule = new SubscriptionItemLabelRule();\r
- Map<String,String> map = rule.getLabel(graph, item); \r
- String label = map.get(ColumnKeys.SINGLE);\r
- if(label == null) continue;\r
- if(subscriptionLabel != null) label = subscriptionLabel + "/" + label;\r
- subs.add(new NamedResource(label, item));\r
- }\r
- subs.sort((o1,o2) -> AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getName(), o2.getName()));\r
- result.add(new Pair<>(new NamedResource(name, model), subs));\r
- }\r
- return result;\r
- }\r
- \r
- });\r
- \r
- Set<NamedResource> selected = exportModel.sessionContext.getSession().syncRequest(new UniqueRead<Set<NamedResource>>() {\r
-\r
- @Override\r
- public Set<NamedResource> perform(ReadGraph graph) throws DatabaseException {\r
-\r
- if(initialSelection == null) return Collections.emptySet();\r
-\r
- HashSet<NamedResource> result = new HashSet<>();\r
- \r
- for(Pair<NamedResource,List<NamedResource>> p : models) {\r
- for(NamedResource nr : p.second) {\r
- for(Resource i : initialSelection) {\r
- if(graph.syncRequest(new IsParent(i, nr.getResource()))) result.add(nr);\r
- }\r
- }\r
- }\r
- return result;\r
- }\r
- \r
- });\r
- \r
-\r
- for(int i=0;i<models.size();i++) {\r
- \r
- Pair<NamedResource,List<NamedResource>> p = models.get(i);\r
- model.add(p.first.getName());\r
-\r
- boolean hasInitial = false;\r
- for(NamedResource nr : p.second) {\r
- if(selected.contains(nr)) hasInitial = true;\r
- }\r
- if(hasInitial) {\r
- model.select(i);\r
- item.removeAll();\r
- exportModel.models.clear();\r
- int index = 0;\r
- int firstIndex = 0;\r
- for(NamedResource nr : p.second) {\r
- TableItem ti = new TableItem(item, SWT.NONE);\r
- ti.setText(nr.getName());\r
- ti.setData(nr);\r
- if(selected.contains(nr)) {\r
- exportModel.models.add(nr);\r
- ti.setChecked(true);\r
- if(firstIndex == 0) firstIndex = index;\r
- }\r
- index++;\r
- }\r
- item.setTopIndex(firstIndex);\r
- item.setData(p.first);\r
- }\r
- \r
- }\r
- \r
- this.decimalSeparator.select(DecimalSeparator.fromPreference(decimalSeparator).ordinal());\r
- this.columnSeparator.select(ColumnSeparator.fromPreference(columnSeparator).ordinal());\r
- \r
- if(resample) {\r
- this.sampling.select(1);\r
- } else {\r
- this.sampling.select(0);\r
- }\r
- \r
- this.samplingMode.select(ExportInterpolation.fromPreference(samplingModePreference).index());\r
- \r
- this.startTime.setText("" + startTime);\r
- this.timeStep.setText("" + timeStep);\r
- this.timeStamps.setText("" + timeDigits);\r
- this.singlePrecision.setText("" + floatDigits);\r
- this.doublePrecision.setText("" + doubleDigits);\r
- \r
- for (String path : exportModel.recentLocations) {\r
- exportLocation.add(path);\r
- }\r
- if (exportLocation.getItemCount() > 0)\r
- exportLocation.select(0);\r
- \r
- }\r
-\r
- Integer validInteger(String s) {\r
- try {\r
- return Integer.parseInt(s);\r
- } catch (NumberFormatException e) {\r
- return null;\r
- }\r
- }\r
-\r
- Double validDouble(String s) {\r
- try {\r
- return Double.parseDouble(s);\r
- } catch (NumberFormatException e) {\r
- return null;\r
- }\r
- }\r
- \r
- Pair<NamedResource,List<NamedResource>> getModel(String name) {\r
- for(Pair<NamedResource,List<NamedResource>> data : models) {\r
- if(data.first.getName().equals(name)) return data;\r
- }\r
- return null;\r
- }\r
- \r
- void validatePage() {\r
-\r
- boolean resample = sampling.getText().equals("Resampled"); \r
- \r
- if(resample) {\r
- resampling.setText("Resampling settings");\r
- timeStep.setEnabled(true);\r
- startTime.setEnabled(true);\r
- samplingMode.setEnabled(true);\r
- } else {\r
- resampling.setText("Resampling settings (not used with recorded samples)");\r
- timeStep.setEnabled(false);\r
- startTime.setEnabled(false);\r
- samplingMode.setEnabled(false);\r
- }\r
- \r
- String selectedModel = model.getText();\r
- Pair<NamedResource,List<NamedResource>> p = getModel(selectedModel);\r
- if(p != null) {\r
- \r
- HashSet<NamedResource> checked = new HashSet<>();\r
- \r
- NamedResource existing = (NamedResource)item.getData();\r
- if(!p.first.equals(existing)) {\r
- \r
- item.removeAll();\r
- for(NamedResource nr : p.second) {\r
- TableItem ti = new TableItem(item, SWT.NONE);\r
- ti.setText(nr.getName());\r
- ti.setData(nr);\r
- }\r
- item.setData(p.first);\r
- \r
- }\r
- \r
- for(TableItem ti : item.getItems()) {\r
- if(ti.getChecked()) checked.add((NamedResource)ti.getData());\r
- }\r
- \r
- exportModel.models = checked;\r
- \r
- }\r
-\r
- Double validStartTime = validDouble(startTime.getText());\r
- Double validStepSize = validDouble(timeStep.getText());\r
-\r
- if(resample) {\r
- \r
- if(validStartTime == null) {\r
- setErrorMessage("Start time must be a number.");\r
- setPageComplete(false);\r
- return;\r
- }\r
- \r
- if(validStepSize == null) {\r
- setErrorMessage("Step size must be a number.");\r
- setPageComplete(false);\r
- return;\r
- }\r
- if(validStepSize <= 0) {\r
- setErrorMessage("Step size must be greater than 0.");\r
- setPageComplete(false);\r
- return;\r
- }\r
-\r
- } else {\r
- \r
- if(exportModel.models.size() > 1) {\r
- setErrorMessage("Recorded samples can only be exported for a single subscription item.");\r
- setPageComplete(false);\r
- return;\r
- }\r
-\r
- }\r
- \r
- if(item.getItemCount() == 0) {\r
- setErrorMessage("No subscription items in selected model.");\r
- setPageComplete(false);\r
- return;\r
- }\r
- \r
- if (exportModel.models.isEmpty()) {\r
- setErrorMessage("No items selected for export.");\r
- setPageComplete(false);\r
- return;\r
- }\r
- \r
- String exportLoc = exportLocation.getText();\r
- if (exportLoc.isEmpty()) {\r
- setErrorMessage("Select output file.");\r
- setPageComplete(false);\r
- return;\r
- }\r
- File file = new File(exportLoc);\r
- if (file.isDirectory()) {\r
- setErrorMessage("The output file is a directory.");\r
- setPageComplete(false);\r
- return;\r
- }\r
- File parent = file.getParentFile();\r
- if (parent == null || !parent.isDirectory()) {\r
- setErrorMessage("The output directory does not exist.");\r
- setPageComplete(false);\r
- return;\r
- }\r
-\r
- exportModel.columnSeparator = ColumnSeparator.fromIndex(columnSeparator.getSelectionIndex());\r
- exportModel.decimalSeparator = DecimalSeparator.fromIndex(decimalSeparator.getSelectionIndex());\r
- if (exportModel.columnSeparator.preference.equals(exportModel.decimalSeparator.preference)) {\r
- setErrorMessage("Decimal and column separator cannot be the same character.");\r
- setPageComplete(false);\r
- return;\r
- }\r
-\r
- Integer validTimeDigits = validInteger(timeStamps.getText());\r
-\r
- if(validTimeDigits == null) {\r
- setErrorMessage("Time stamps needs to be an integer number.");\r
- setPageComplete(false);\r
- return;\r
- }\r
-\r
- Integer validSinglePrecision = validInteger(singlePrecision.getText());\r
- if(validSinglePrecision == null) {\r
- setErrorMessage("Single precision needs to be an integer number.");\r
- setPageComplete(false);\r
- return;\r
- }\r
-\r
- Integer validDoublePrecision = validInteger(doublePrecision.getText());\r
- if(validDoublePrecision == null) {\r
- setErrorMessage("Double precision needs to be an integer number.");\r
- setPageComplete(false);\r
- return;\r
- }\r
-\r
- exportModel.exportLocation = file;\r
- exportModel.overwrite = overwrite.getSelection();\r
-\r
- exportModel.startTime = validStartTime;\r
- exportModel.timeStep = validStepSize;\r
-\r
- exportModel.resample = sampling.getSelectionIndex() == 1;\r
- exportModel.samplingMode = ExportInterpolation.fromIndex(samplingMode.getSelectionIndex());\r
- \r
- exportModel.timeDigits = validTimeDigits;\r
- exportModel.floatDigits = validSinglePrecision;\r
- exportModel.doubleDigits = validDoublePrecision;\r
- \r
- setErrorMessage(null);\r
- setMessage("Press Finish to export subscription data.");\r
- setPageComplete(true);\r
- \r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.charts.ui;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+import org.simantics.NameLabelUtil;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.common.ColumnKeys;
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.parser.StringEscapeUtils;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.NamedResource;
+import org.simantics.db.common.request.IsParent;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.SelectionHints;
+import org.simantics.history.csv.ColumnSeparator;
+import org.simantics.history.csv.DecimalSeparator;
+import org.simantics.history.csv.ExportInterpolation;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.ModelingUtils;
+import org.simantics.modeling.preferences.CSVPreferences;
+import org.simantics.modeling.ui.modelBrowser2.label.SubscriptionItemLabelRule;
+import org.simantics.utils.datastructures.Arrays;
+import org.simantics.utils.datastructures.Pair;
+import org.simantics.utils.strings.AlphanumComparator;
+import org.simantics.utils.ui.ISelectionUtils;
+
+
+/**
+ * @author Antti Villberg
+ */
+public class CSVExportPage extends WizardPage {
+
+ CSVExportPlan exportModel;
+ CCombo model;
+ Table item;
+ Button selectAllItems;
+ SelectionAdapter selectAllItemsListener;
+ CCombo exportLocation;
+
+ CCombo decimalSeparator;
+ CCombo columnSeparator;
+ CCombo sampling;
+ Text timeStep;
+ Text startTime;
+ Text timeStamps;
+ CCombo samplingMode;
+ Text singlePrecision;
+ Text doublePrecision;
+
+ Group resampling;
+
+ Collection<Resource> initialSelection;
+
+ List<Pair<NamedResource,List<NamedResource>>> models = new ArrayList<>();
+
+ private Button overwrite;
+
+ ModifyListener m = (e) -> validatePage();
+
+ SelectionListener s = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ validatePage();
+ }
+ };
+
+ protected CSVExportPage(CSVExportPlan model) {
+ super("Export CSV Data", "Define Export Properties", null);
+ this.exportModel = model;
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ ScrolledComposite scroller = new ScrolledComposite(parent, SWT.V_SCROLL);
+ scroller.setExpandHorizontal(true);
+ scroller.setExpandVertical(true);
+
+ Composite container = new Composite(scroller, SWT.NONE);
+ scroller.setContent(container);
+ GridLayoutFactory.swtDefaults().spacing(20, 10).numColumns(3).applyTo(container);
+ new Label(container, SWT.NONE).setText("Select a model:");
+ model = new CCombo(container, SWT.BORDER);
+ {
+ model.setEditable(false);
+ model.setText("");
+ model.setToolTipText("Selects the Model To Export From");
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(model);
+ }
+
+ new Label(container, SWT.NONE).setText("Exported items:");
+ item = new Table(container, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
+ {
+ item.setToolTipText("Selects the Subscription Items");
+ GridDataFactory.fillDefaults().grab(true, true).span(2, 1).hint(SWT.DEFAULT, 105).applyTo(item);
+ }
+ item.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (e.detail == SWT.CHECK) {
+ TableItem[] selected = item.getSelection();
+ TableItem it = (TableItem) e.item;
+ boolean checkedWasSelected = Arrays.contains(selected, it);
+ if (checkedWasSelected) {
+ boolean check = it.getChecked();
+ for (TableItem i : selected)
+ i.setChecked(check);
+ }
+ int checked = countCheckedItems(item);
+ int totalItems = item.getItemCount();
+ updateSelectAll(checked > 0, checked < totalItems, false);
+ validatePage();
+ }
+ }
+ });
+ new Label(container, 0);
+ selectAllItems = new Button(container, SWT.CHECK);
+ {
+ selectAllItems.setText("&Select All");
+ selectAllItems.setToolTipText("Select/Deselect All Listed Subscription Items");
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(selectAllItems);
+ }
+ selectAllItemsListener = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ boolean select = selectAllItems.getSelection();
+ updateSelectAll(select, false, false);
+ item.setRedraw(false);
+ for (TableItem it : item.getItems())
+ it.setChecked(select);
+ item.setRedraw(true);
+
+ validatePage();
+ }
+ };
+ selectAllItems.addSelectionListener(selectAllItemsListener);
+
+ new Label(container, SWT.NONE).setText("&Output file:");
+ exportLocation = new CCombo(container, SWT.BORDER);
+ {
+ exportLocation.setText("");
+ GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(exportLocation);
+ exportLocation.addModifyListener(m);
+ }
+ Button browseFileButton = new Button(container, SWT.PUSH);
+ {
+ browseFileButton.setText("Browse...");
+ browseFileButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ browseFileButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
+ dialog.setText("Choose Output File");
+ dialog.setFilterPath(new File(exportLocation.getText()).getParent());
+ dialog.setFilterExtensions(new String[] { "*.csv" });
+ dialog.setFilterNames(new String[] { "Comma separated values (*.csv)" });
+ dialog.setOverwrite(false);
+ String file = dialog.open();
+ if (file == null)
+ return;
+ exportLocation.setText(file);
+ validatePage();
+ }
+ });
+ }
+
+
+ Label horizRule = new Label(container, SWT.BORDER);
+ GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 0).grab(true, false).span(3, 1).applyTo(horizRule);
+
+ new Label(container, SWT.NONE).setText("&Decimal separator:");
+ decimalSeparator = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
+ for(DecimalSeparator s : DecimalSeparator.values())
+ decimalSeparator.add(s.label);
+ decimalSeparator.select(0);
+ decimalSeparator.addSelectionListener(s);
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(decimalSeparator);
+
+ new Label(container, SWT.NONE).setText("&Column separator:");
+ columnSeparator = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
+ for(ColumnSeparator s : ColumnSeparator.values())
+ columnSeparator.add(s.label);
+ columnSeparator.select(0);
+ columnSeparator.addSelectionListener(s);
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(columnSeparator);
+
+ new Label(container, SWT.NONE).setText("Sampling:");
+ sampling = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
+ sampling.add("Recorded samples");
+ sampling.add("Resampled");
+ sampling.select(0);
+ sampling.addSelectionListener(s);
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(sampling);
+
+ resampling = new Group(container, SWT.NONE);
+ resampling.setText("Resampling settings (not used with recorded samples)");
+ GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(resampling);
+ GridLayoutFactory.swtDefaults().numColumns(3).applyTo(resampling);
+
+ new Label(resampling, SWT.NONE).setText("&Start time:");
+ startTime = new Text(resampling, SWT.BORDER);
+ startTime.addModifyListener(m);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(startTime);
+ new Label(resampling, SWT.NONE).setText(" seconds");
+
+ new Label(resampling, SWT.NONE).setText("&Time step:");
+ timeStep = new Text(resampling, SWT.BORDER);
+ timeStep.addModifyListener(m);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(timeStep);
+ new Label(resampling, SWT.NONE).setText(" seconds");
+
+ new Label(resampling, SWT.NONE).setText("Sampling mode:");
+ samplingMode = new CCombo(resampling, SWT.READ_ONLY | SWT.BORDER);
+ samplingMode.add("Linear interpolation");
+ samplingMode.add("Previous sample");
+ samplingMode.select(0);
+ samplingMode.addSelectionListener(s);
+ GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(samplingMode);
+
+ Group digits = new Group(container, SWT.NONE);
+ digits.setText("Significant digits");
+ GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(digits);
+ GridLayoutFactory.swtDefaults().numColumns(2).applyTo(digits);
+
+ new Label(digits, SWT.NONE).setText("&Time stamps:");
+ timeStamps = new Text(digits, SWT.BORDER);
+ timeStamps.addModifyListener(m);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(timeStamps);
+
+ new Label(digits, SWT.NONE).setText("&Single precision floating point:");
+ singlePrecision = new Text(digits, SWT.BORDER);
+ singlePrecision.addModifyListener(m);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(singlePrecision);
+
+ new Label(digits, SWT.NONE).setText("&Double precision floating point:");
+ doublePrecision = new Text(digits, SWT.BORDER);
+ doublePrecision.addModifyListener(m);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(doublePrecision);
+
+ overwrite = new Button(container, SWT.CHECK);
+ overwrite.setText("&Overwrite existing files without warning");
+ overwrite.setSelection(exportModel.overwrite);
+ GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(overwrite);
+ overwrite.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ validatePage();
+ }
+ });
+
+ try {
+ initializeData();
+ } catch (DatabaseException e) {
+ e.printStackTrace();
+ }
+
+ model.addSelectionListener(s);
+
+ scroller.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+
+ setControl(scroller);
+ validatePage();
+
+ }
+
+ void updateSelectAll(boolean checked, boolean gray, boolean notify) {
+ if (checked) {
+ selectAllItems.setText("Select None");
+ } else {
+ selectAllItems.setText("Select All");
+ }
+ if (!notify)
+ selectAllItems.removeSelectionListener(selectAllItemsListener);
+ selectAllItems.setGrayed(checked && gray);
+ selectAllItems.setSelection(checked);
+ if (!notify)
+ selectAllItems.addSelectionListener(selectAllItemsListener);
+ }
+
+ protected int countCheckedItems(Table table) {
+ int ret = 0;
+ for (TableItem item : table.getItems())
+ ret += item.getChecked() ? 1 : 0;
+ return ret;
+ }
+
+ private void initializeData() throws DatabaseException {
+
+ // Write preferences to formatter
+ IPreferenceStore csvnode = new ScopedPreferenceStore( InstanceScope.INSTANCE, CSVPreferences.P_NODE );
+
+ Double startTime = csvnode.getDouble(CSVPreferences.P_CSV_START_TIME);
+ Double timeStep = csvnode.getDouble(CSVPreferences.P_CSV_TIME_STEP);
+ String decimalSeparator = csvnode.getString(CSVPreferences.P_CSV_DECIMAL_SEPARATOR);
+ String columnSeparator = StringEscapeUtils.unescape( csvnode.getString(CSVPreferences.P_CSV_COLUMN_SEPARATOR) );
+ Boolean resample = csvnode.getBoolean(CSVPreferences.P_CSV_RESAMPLE);
+ String samplingModePreference = csvnode.getString(CSVPreferences.P_CSV_SAMPLING_MODE);
+ int timeDigits = csvnode.getInt(CSVPreferences.P_CSV_TIME_DIGITS);
+ int floatDigits = csvnode.getInt(CSVPreferences.P_CSV_FLOAT_DIGITS);
+ int doubleDigits = csvnode.getInt(CSVPreferences.P_CSV_DOUBLE_DIGITS);
+
+ initialSelection = ISelectionUtils.getPossibleKeys(exportModel.selection, SelectionHints.KEY_MAIN, Resource.class);
+
+ models = exportModel.sessionContext.getSession().syncRequest(new UniqueRead<List<Pair<NamedResource,List<NamedResource>>>>() {
+
+ @Override
+ public List<Pair<NamedResource,List<NamedResource>>> perform(ReadGraph graph) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ List<Pair<NamedResource,List<NamedResource>>> result = new ArrayList<>();
+ for(Resource model : graph.syncRequest(new org.simantics.db.layer0.request.ProjectModels(Simantics.getProjectResource()))) {
+ String name = graph.getPossibleRelatedValue(model, L0.HasName, Bindings.STRING);
+ if(name == null) continue;
+ name = NameLabelUtil.modalName(graph, model);
+ List<NamedResource> subs = new ArrayList<>();
+ for(Resource item : ModelingUtils.searchByType(graph, model, MOD.Subscription_Item)) {
+ String subscriptionLabel = null;
+ Resource subscription = graph.getPossibleObject(item, L0.PartOf);
+ if(subscription != null) {
+ subscriptionLabel = graph.getPossibleRelatedValue(subscription, L0.HasLabel, Bindings.STRING);
+ }
+ SubscriptionItemLabelRule rule = new SubscriptionItemLabelRule();
+ Map<String,String> map = rule.getLabel(graph, item);
+ String label = map.get(ColumnKeys.SINGLE);
+ if(label == null) continue;
+ if(subscriptionLabel != null) label = subscriptionLabel + "/" + label;
+ subs.add(new NamedResource(label, item));
+ }
+ subs.sort((o1,o2) -> AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getName(), o2.getName()));
+ result.add(new Pair<>(new NamedResource(name, model), subs));
+ }
+ return result;
+ }
+
+ });
+
+ Set<NamedResource> selected = exportModel.sessionContext.getSession().syncRequest(new UniqueRead<Set<NamedResource>>() {
+
+ @Override
+ public Set<NamedResource> perform(ReadGraph graph) throws DatabaseException {
+
+ if(initialSelection == null) return Collections.emptySet();
+
+ HashSet<NamedResource> result = new HashSet<>();
+
+ for(Pair<NamedResource,List<NamedResource>> p : models) {
+ for(NamedResource nr : p.second) {
+ for(Resource i : initialSelection) {
+ if(graph.syncRequest(new IsParent(i, nr.getResource()))) result.add(nr);
+ }
+ }
+ }
+ return result;
+ }
+
+ });
+
+
+ for(int i=0;i<models.size();i++) {
+
+ Pair<NamedResource,List<NamedResource>> p = models.get(i);
+ model.add(p.first.getName());
+
+ boolean hasInitial = false;
+ for(NamedResource nr : p.second) {
+ if(selected.contains(nr)) hasInitial = true;
+ }
+ if(hasInitial) {
+ model.select(i);
+ item.removeAll();
+ exportModel.models.clear();
+ int index = 0;
+ int firstIndex = 0;
+ for(NamedResource nr : p.second) {
+ TableItem ti = new TableItem(item, SWT.NONE);
+ ti.setText(nr.getName());
+ ti.setData(nr);
+ if(selected.contains(nr)) {
+ exportModel.models.add(nr);
+ ti.setChecked(true);
+ if(firstIndex == 0) firstIndex = index;
+ }
+ index++;
+ }
+ item.setTopIndex(firstIndex);
+ item.setData(p.first);
+ }
+
+ }
+
+ this.decimalSeparator.select(DecimalSeparator.fromPreference(decimalSeparator).ordinal());
+ this.columnSeparator.select(ColumnSeparator.fromPreference(columnSeparator).ordinal());
+
+ if(resample) {
+ this.sampling.select(1);
+ } else {
+ this.sampling.select(0);
+ }
+
+ this.samplingMode.select(ExportInterpolation.fromPreference(samplingModePreference).index());
+
+ this.startTime.setText("" + startTime);
+ this.timeStep.setText("" + timeStep);
+ this.timeStamps.setText("" + timeDigits);
+ this.singlePrecision.setText("" + floatDigits);
+ this.doublePrecision.setText("" + doubleDigits);
+
+ for (String path : exportModel.recentLocations) {
+ exportLocation.add(path);
+ }
+ if (exportLocation.getItemCount() > 0)
+ exportLocation.select(0);
+
+ }
+
+ Integer validInteger(String s) {
+ try {
+ return Integer.parseInt(s);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ Double validDouble(String s) {
+ try {
+ return Double.parseDouble(s);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ Pair<NamedResource,List<NamedResource>> getModel(String name) {
+ for(Pair<NamedResource,List<NamedResource>> data : models) {
+ if(data.first.getName().equals(name)) return data;
+ }
+ return null;
+ }
+
+ void validatePage() {
+
+ boolean resample = sampling.getText().equals("Resampled");
+
+ if(resample) {
+ resampling.setText("Resampling settings");
+ timeStep.setEnabled(true);
+ startTime.setEnabled(true);
+ samplingMode.setEnabled(true);
+ } else {
+ resampling.setText("Resampling settings (not used with recorded samples)");
+ timeStep.setEnabled(false);
+ startTime.setEnabled(false);
+ samplingMode.setEnabled(false);
+ }
+
+ String selectedModel = model.getText();
+ Pair<NamedResource,List<NamedResource>> p = getModel(selectedModel);
+ if(p != null) {
+
+ HashSet<NamedResource> checked = new HashSet<>();
+
+ NamedResource existing = (NamedResource)item.getData();
+ if(!p.first.equals(existing)) {
+
+ item.removeAll();
+ for(NamedResource nr : p.second) {
+ TableItem ti = new TableItem(item, SWT.NONE);
+ ti.setText(nr.getName());
+ ti.setData(nr);
+ }
+ item.setData(p.first);
+
+ }
+
+ for(TableItem ti : item.getItems()) {
+ if(ti.getChecked()) checked.add((NamedResource)ti.getData());
+ }
+
+ exportModel.models = checked;
+
+ }
+
+ Double validStartTime = validDouble(startTime.getText());
+ Double validStepSize = validDouble(timeStep.getText());
+
+ if(resample) {
+
+ if(validStartTime == null) {
+ setErrorMessage("Start time must be a number.");
+ setPageComplete(false);
+ return;
+ }
+
+ if(validStepSize == null) {
+ setErrorMessage("Step size must be a number.");
+ setPageComplete(false);
+ return;
+ }
+ if(validStepSize <= 0) {
+ setErrorMessage("Step size must be greater than 0.");
+ setPageComplete(false);
+ return;
+ }
+
+ } else {
+
+ if(exportModel.models.size() > 1) {
+ setErrorMessage("Recorded samples can only be exported for a single subscription item.");
+ setPageComplete(false);
+ return;
+ }
+
+ }
+
+ if(item.getItemCount() == 0) {
+ setErrorMessage("No subscription items in selected model.");
+ setPageComplete(false);
+ return;
+ }
+
+ if (exportModel.models.isEmpty()) {
+ setErrorMessage("No items selected for export.");
+ setPageComplete(false);
+ return;
+ }
+
+ String exportLoc = exportLocation.getText();
+ if (exportLoc.isEmpty()) {
+ setErrorMessage("Select output file.");
+ setPageComplete(false);
+ return;
+ }
+ File file = new File(exportLoc);
+ if (file.isDirectory()) {
+ setErrorMessage("The output file is a directory.");
+ setPageComplete(false);
+ return;
+ }
+ File parent = file.getParentFile();
+ if (parent == null || !parent.isDirectory()) {
+ setErrorMessage("The output directory does not exist.");
+ setPageComplete(false);
+ return;
+ }
+
+ exportModel.columnSeparator = ColumnSeparator.fromIndex(columnSeparator.getSelectionIndex());
+ exportModel.decimalSeparator = DecimalSeparator.fromIndex(decimalSeparator.getSelectionIndex());
+ if (exportModel.columnSeparator.preference.equals(exportModel.decimalSeparator.preference)) {
+ setErrorMessage("Decimal and column separator cannot be the same character.");
+ setPageComplete(false);
+ return;
+ }
+
+ Integer validTimeDigits = validInteger(timeStamps.getText());
+
+ if(validTimeDigits == null) {
+ setErrorMessage("Time stamps needs to be an integer number.");
+ setPageComplete(false);
+ return;
+ }
+
+ Integer validSinglePrecision = validInteger(singlePrecision.getText());
+ if(validSinglePrecision == null) {
+ setErrorMessage("Single precision needs to be an integer number.");
+ setPageComplete(false);
+ return;
+ }
+
+ Integer validDoublePrecision = validInteger(doublePrecision.getText());
+ if(validDoublePrecision == null) {
+ setErrorMessage("Double precision needs to be an integer number.");
+ setPageComplete(false);
+ return;
+ }
+
+ exportModel.exportLocation = file;
+ exportModel.overwrite = overwrite.getSelection();
+
+ exportModel.startTime = validStartTime;
+ exportModel.timeStep = validStepSize;
+
+ exportModel.resample = sampling.getSelectionIndex() == 1;
+ exportModel.samplingMode = ExportInterpolation.fromIndex(samplingMode.getSelectionIndex());
+
+ exportModel.timeDigits = validTimeDigits;
+ exportModel.floatDigits = validSinglePrecision;
+ exportModel.doubleDigits = validDoublePrecision;
+
+ setErrorMessage(null);
+ setMessage("Press Finish to export subscription data.");
+ setPageComplete(true);
+
+ }
+
+}