-/*******************************************************************************\r
- * Copyright (c) 2007, 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.modeling.ui.preferences;\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.BooleanFieldEditor;\r
-import org.eclipse.jface.preference.ComboFieldEditor;\r
-import org.eclipse.jface.preference.FieldEditor;\r
-import org.eclipse.jface.preference.FieldEditorPreferencePage;\r
-import org.eclipse.jface.preference.IPreferenceStore;\r
-import org.eclipse.jface.preference.IntegerFieldEditor;\r
-import org.eclipse.jface.preference.StringFieldEditor;\r
-import org.eclipse.jface.util.PropertyChangeEvent;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Group;\r
-import org.eclipse.ui.IWorkbench;\r
-import org.eclipse.ui.IWorkbenchPreferencePage;\r
-import org.eclipse.ui.preferences.ScopedPreferenceStore;\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.modeling.preferences.CSVPreferences;\r
-\r
-public class CSVPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {\r
-\r
- private ComboFieldEditor fDecimalSeparatorEditor = null;\r
- private ComboFieldEditor fColumnSeparatorEditor = null;\r
- private StringFieldEditor fExtensionEditor = null;\r
- private BooleanFieldEditor fResamplingEditor = null;\r
- private ComboFieldEditor fSamplingModeEditor = null;\r
- private StringFieldEditor fStartEditor = null;\r
- private StringFieldEditor fStepEditor = null;\r
- private IntegerFieldEditor fTimeDigitsEditor = null;\r
- private IntegerFieldEditor fFloatDigitsEditor = null;\r
- private IntegerFieldEditor fDoubleDigitsEditor = null;\r
-\r
- private String decimalSeparatorValue;\r
- private String columnSeparatorValue;\r
-\r
- public CSVPreferencePage() {\r
- super(GRID);\r
- setDescription("CSV import and export preferences");\r
- IPreferenceStore pf = new ScopedPreferenceStore(InstanceScope.INSTANCE, CSVPreferences.P_NODE);\r
- setPreferenceStore( pf ); \r
- }\r
-\r
- @Override\r
- public void createControl(Composite parent) {\r
- super.createControl(parent);\r
- }\r
-\r
- @Override\r
- public void init(IWorkbench workbench) {\r
- }\r
-\r
- @Override\r
- protected void initialize() {\r
- super.initialize();\r
-\r
- if (decimalSeparatorValue.equals(columnSeparatorValue)) {\r
- setErrorMessage("Column and decimal separators must not be the same.");\r
- checkState();\r
- updateApplyButton();\r
- }\r
- }\r
-\r
- @Override\r
- protected void createFieldEditors() {\r
- decimalSeparatorValue = getPreferenceStore().getString(CSVPreferences.P_CSV_DECIMAL_SEPARATOR);\r
- columnSeparatorValue = getPreferenceStore().getString(CSVPreferences.P_CSV_COLUMN_SEPARATOR);\r
-\r
- String[][] decimalSeparators = new String[DecimalSeparator.values().length][];\r
- int i = 0;\r
- for (DecimalSeparator ds : DecimalSeparator.values())\r
- decimalSeparators[i++] = new String[] { ds.label, ds.preference };\r
- String[][] columnSeparators = new String[ColumnSeparator.values().length][];\r
- i = 0;\r
- for (ColumnSeparator cs : ColumnSeparator.values())\r
- columnSeparators[i++] = new String[] { cs.label, cs.preference };\r
-\r
- fDecimalSeparatorEditor = new ComboFieldEditor(CSVPreferences.P_CSV_DECIMAL_SEPARATOR, "Decimal separator", decimalSeparators, getFieldEditorParent()) {\r
- @Override\r
- public boolean isValid() {\r
- return !decimalSeparatorValue.equals(columnSeparatorValue);\r
- }\r
- };\r
- addField(fDecimalSeparatorEditor);\r
-\r
- fColumnSeparatorEditor = new ComboFieldEditor(CSVPreferences.P_CSV_COLUMN_SEPARATOR, "Column separator", columnSeparators, getFieldEditorParent()) {\r
- @Override\r
- public boolean isValid() {\r
- return !decimalSeparatorValue.equals(columnSeparatorValue);\r
- }\r
- };\r
-\r
- addField(fColumnSeparatorEditor);\r
-\r
- fExtensionEditor = new StringFieldEditor(CSVPreferences.P_CSV_FILE_EXTENSION, "File extension", getFieldEditorParent());\r
- addField(fExtensionEditor);\r
- \r
- fResamplingEditor = new BooleanFieldEditor(CSVPreferences.P_CSV_RESAMPLE, "Resampling", getFieldEditorParent());\r
- addField(fResamplingEditor);\r
-\r
- fSamplingModeEditor = new ComboFieldEditor(CSVPreferences.P_CSV_SAMPLING_MODE, "Sampling mode",\r
- new String[][] {\r
- {ExportInterpolation.LINEAR_INTERPOLATION.label, ExportInterpolation.LINEAR_INTERPOLATION.preference},\r
- {ExportInterpolation.PREVIOUS_SAMPLE.label, ExportInterpolation.PREVIOUS_SAMPLE.preference},\r
- }, getFieldEditorParent());\r
- addField(fSamplingModeEditor);\r
-\r
- fStartEditor = new StringFieldEditor(CSVPreferences.P_CSV_START_TIME, "Start time (s)", getFieldEditorParent()) {\r
- protected boolean doCheckState() {\r
- String text = getTextControl().getText();\r
- if (text == null || text.isEmpty()) {\r
- return true;\r
- }\r
- try {\r
- double number = Double.parseDouble(text);\r
- return number>0;\r
- } catch (NumberFormatException e1) {\r
- return false;\r
- }\r
- };\r
- };\r
- fStartEditor.setEmptyStringAllowed(true);\r
- fStartEditor.setErrorMessage("Enter valid start time value (s)");\r
-\r
- fStepEditor = new StringFieldEditor(CSVPreferences.P_CSV_TIME_STEP, "Step size (s)", getFieldEditorParent()) {\r
- protected boolean doCheckState() {\r
- String text = getTextControl().getText();\r
- if (text == null || text.isEmpty()) {\r
- return true;\r
- }\r
- try {\r
- double number = Double.parseDouble(text);\r
- return number>0;\r
- } catch (NumberFormatException e1) {\r
- return false;\r
- }\r
- };\r
- };\r
- fStepEditor.setEmptyStringAllowed(true);\r
- fStepEditor.setErrorMessage("Enter valid time step value (s)");\r
- addField(fStepEditor);\r
-\r
- Group significantDigitsGroup = new Group(getFieldEditorParent(), SWT.NONE);\r
- significantDigitsGroup.setText("Significant digits");\r
- significantDigitsGroup.setToolTipText("Control the Amount of Significant Digits in Exported Numbers");\r
- GridDataFactory.fillDefaults().indent(0, 5).span(2, 1).applyTo(significantDigitsGroup);\r
-\r
- fTimeDigitsEditor = new IntegerFieldEditor(CSVPreferences.P_CSV_TIME_DIGITS, "Time stamps", significantDigitsGroup, 2);\r
- fTimeDigitsEditor.setValidRange(1, 15);\r
- addField(fTimeDigitsEditor);\r
- fFloatDigitsEditor = new IntegerFieldEditor(CSVPreferences.P_CSV_FLOAT_DIGITS, "Single precision floating point", significantDigitsGroup, 1);\r
- fFloatDigitsEditor.setValidRange(1, 7);\r
- addField(fFloatDigitsEditor);\r
- fDoubleDigitsEditor = new IntegerFieldEditor(CSVPreferences.P_CSV_DOUBLE_DIGITS, "Double precision floating point", significantDigitsGroup, 2);\r
- fDoubleDigitsEditor.setValidRange(1, 15);\r
- addField(fDoubleDigitsEditor);\r
-\r
- GridLayoutFactory.swtDefaults().numColumns(2).applyTo(significantDigitsGroup);\r
- }\r
-\r
- /**\r
- * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)\r
- */\r
- @Override\r
- public void propertyChange(PropertyChangeEvent event) {\r
- if (event.getProperty().equals(FieldEditor.VALUE)) {\r
- Object source = event.getSource();\r
- boolean validate = false;\r
- if (source == fDecimalSeparatorEditor) {\r
- decimalSeparatorValue = (String) event.getNewValue();\r
- validate = true;\r
- } else if (source == fColumnSeparatorEditor) {\r
- columnSeparatorValue = (String) event.getNewValue();\r
- validate = true;\r
- }\r
- if (validate) {\r
- if (decimalSeparatorValue.equals(columnSeparatorValue)) {\r
- setErrorMessage("Column and decimal separators must not be the same.");\r
- } else {\r
- setErrorMessage(null);\r
- }\r
- checkState();\r
- updateApplyButton();\r
- }\r
- }\r
- super.propertyChange(event);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 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.modeling.ui.preferences;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.IntegerFieldEditor;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+import org.simantics.history.csv.ColumnSeparator;
+import org.simantics.history.csv.DecimalSeparator;
+import org.simantics.history.csv.ExportInterpolation;
+import org.simantics.modeling.preferences.CSVPreferences;
+
+public class CSVPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ private ComboFieldEditor fDecimalSeparatorEditor = null;
+ private ComboFieldEditor fColumnSeparatorEditor = null;
+ private StringFieldEditor fExtensionEditor = null;
+ private BooleanFieldEditor fResamplingEditor = null;
+ private ComboFieldEditor fSamplingModeEditor = null;
+ private StringFieldEditor fStartEditor = null;
+ private StringFieldEditor fStepEditor = null;
+ private IntegerFieldEditor fTimeDigitsEditor = null;
+ private IntegerFieldEditor fFloatDigitsEditor = null;
+ private IntegerFieldEditor fDoubleDigitsEditor = null;
+
+ private String decimalSeparatorValue;
+ private String columnSeparatorValue;
+
+ public CSVPreferencePage() {
+ super(GRID);
+ setDescription("CSV import and export preferences");
+ IPreferenceStore pf = new ScopedPreferenceStore(InstanceScope.INSTANCE, CSVPreferences.P_NODE);
+ setPreferenceStore( pf );
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+
+ if (decimalSeparatorValue.equals(columnSeparatorValue)) {
+ setErrorMessage("Column and decimal separators must not be the same.");
+ checkState();
+ updateApplyButton();
+ }
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ decimalSeparatorValue = getPreferenceStore().getString(CSVPreferences.P_CSV_DECIMAL_SEPARATOR);
+ columnSeparatorValue = getPreferenceStore().getString(CSVPreferences.P_CSV_COLUMN_SEPARATOR);
+
+ String[][] decimalSeparators = new String[DecimalSeparator.values().length][];
+ int i = 0;
+ for (DecimalSeparator ds : DecimalSeparator.values())
+ decimalSeparators[i++] = new String[] { ds.label, ds.preference };
+ String[][] columnSeparators = new String[ColumnSeparator.values().length][];
+ i = 0;
+ for (ColumnSeparator cs : ColumnSeparator.values())
+ columnSeparators[i++] = new String[] { cs.label, cs.preference };
+
+ fDecimalSeparatorEditor = new ComboFieldEditor(CSVPreferences.P_CSV_DECIMAL_SEPARATOR, "Decimal separator", decimalSeparators, getFieldEditorParent()) {
+ @Override
+ public boolean isValid() {
+ return !decimalSeparatorValue.equals(columnSeparatorValue);
+ }
+ };
+ addField(fDecimalSeparatorEditor);
+
+ fColumnSeparatorEditor = new ComboFieldEditor(CSVPreferences.P_CSV_COLUMN_SEPARATOR, "Column separator", columnSeparators, getFieldEditorParent()) {
+ @Override
+ public boolean isValid() {
+ return !decimalSeparatorValue.equals(columnSeparatorValue);
+ }
+ };
+
+ addField(fColumnSeparatorEditor);
+
+ fExtensionEditor = new StringFieldEditor(CSVPreferences.P_CSV_FILE_EXTENSION, "File extension", getFieldEditorParent());
+ addField(fExtensionEditor);
+
+ fResamplingEditor = new BooleanFieldEditor(CSVPreferences.P_CSV_RESAMPLE, "Resampling", getFieldEditorParent());
+ addField(fResamplingEditor);
+
+ fSamplingModeEditor = new ComboFieldEditor(CSVPreferences.P_CSV_SAMPLING_MODE, "Sampling mode",
+ new String[][] {
+ {ExportInterpolation.LINEAR_INTERPOLATION.label, ExportInterpolation.LINEAR_INTERPOLATION.preference},
+ {ExportInterpolation.PREVIOUS_SAMPLE.label, ExportInterpolation.PREVIOUS_SAMPLE.preference},
+ }, getFieldEditorParent());
+ addField(fSamplingModeEditor);
+
+ fStartEditor = new StringFieldEditor(CSVPreferences.P_CSV_START_TIME, "Start time (s)", getFieldEditorParent()) {
+ protected boolean doCheckState() {
+ String text = getTextControl().getText();
+ if (text == null || text.isEmpty()) {
+ return true;
+ }
+ try {
+ double number = Double.parseDouble(text);
+ return number>0;
+ } catch (NumberFormatException e1) {
+ return false;
+ }
+ };
+ };
+ fStartEditor.setEmptyStringAllowed(true);
+ fStartEditor.setErrorMessage("Enter valid start time value (s)");
+
+ fStepEditor = new StringFieldEditor(CSVPreferences.P_CSV_TIME_STEP, "Step size (s)", getFieldEditorParent()) {
+ protected boolean doCheckState() {
+ String text = getTextControl().getText();
+ if (text == null || text.isEmpty()) {
+ return true;
+ }
+ try {
+ double number = Double.parseDouble(text);
+ return number>0;
+ } catch (NumberFormatException e1) {
+ return false;
+ }
+ };
+ };
+ fStepEditor.setEmptyStringAllowed(true);
+ fStepEditor.setErrorMessage("Enter valid time step value (s)");
+ addField(fStepEditor);
+
+ Group significantDigitsGroup = new Group(getFieldEditorParent(), SWT.NONE);
+ significantDigitsGroup.setText("Significant digits");
+ significantDigitsGroup.setToolTipText("Control the Amount of Significant Digits in Exported Numbers");
+ GridDataFactory.fillDefaults().indent(0, 5).span(2, 1).applyTo(significantDigitsGroup);
+
+ fTimeDigitsEditor = new IntegerFieldEditor(CSVPreferences.P_CSV_TIME_DIGITS, "Time stamps", significantDigitsGroup, 2);
+ fTimeDigitsEditor.setValidRange(1, 15);
+ addField(fTimeDigitsEditor);
+ fFloatDigitsEditor = new IntegerFieldEditor(CSVPreferences.P_CSV_FLOAT_DIGITS, "Single precision floating point", significantDigitsGroup, 1);
+ fFloatDigitsEditor.setValidRange(1, 7);
+ addField(fFloatDigitsEditor);
+ fDoubleDigitsEditor = new IntegerFieldEditor(CSVPreferences.P_CSV_DOUBLE_DIGITS, "Double precision floating point", significantDigitsGroup, 2);
+ fDoubleDigitsEditor.setValidRange(1, 15);
+ addField(fDoubleDigitsEditor);
+
+ GridLayoutFactory.swtDefaults().numColumns(2).applyTo(significantDigitsGroup);
+ }
+
+ /**
+ * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event.getProperty().equals(FieldEditor.VALUE)) {
+ Object source = event.getSource();
+ boolean validate = false;
+ if (source == fDecimalSeparatorEditor) {
+ decimalSeparatorValue = (String) event.getNewValue();
+ validate = true;
+ } else if (source == fColumnSeparatorEditor) {
+ columnSeparatorValue = (String) event.getNewValue();
+ validate = true;
+ }
+ if (validate) {
+ if (decimalSeparatorValue.equals(columnSeparatorValue)) {
+ setErrorMessage("Column and decimal separators must not be the same.");
+ } else {
+ setErrorMessage(null);
+ }
+ checkState();
+ updateApplyButton();
+ }
+ }
+ super.propertyChange(event);
+ }
+
+}