]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/preferences/CSVPreferencePage.java
Improved Copy Visible Data usability in time series chart editor
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / preferences / CSVPreferencePage.java
index aadd9395ab2867faf1a4a3f3168558fb14d4146a..7a2e7a6eb3a1fb57b84a619190adf8d2a1b7cc2d 100644 (file)
@@ -23,8 +23,10 @@ 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.graphics.Color;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 import org.eclipse.ui.preferences.ScopedPreferenceStore;
@@ -110,7 +112,8 @@ public class CSVPreferencePage extends FieldEditorPreferencePage implements IWor
            fExtensionEditor = new StringFieldEditor(CSVPreferences.P_CSV_FILE_EXTENSION, "File extension", getFieldEditorParent());
            addField(fExtensionEditor);
            
-           fResamplingEditor = new BooleanFieldEditor(CSVPreferences.P_CSV_RESAMPLE, "Resampling", getFieldEditorParent());
+           fResamplingEditor = new BooleanFieldEditor(CSVPreferences.P_CSV_RESAMPLE, "&Resample", getFieldEditorParent());
+           fResamplingEditor.getDescriptionControl(getFieldEditorParent()).setToolTipText("Resample exported data from raw data");
            addField(fResamplingEditor);
 
            fSamplingModeEditor = new ComboFieldEditor(CSVPreferences.P_CSV_SAMPLING_MODE, "Sampling mode",
@@ -127,8 +130,9 @@ public class CSVPreferencePage extends FieldEditorPreferencePage implements IWor
                        return true;
                    }
                    try {
+                       @SuppressWarnings("unused")
                        double number = Double.parseDouble(text);
-                       return number>0;
+                       return true;
                    } catch (NumberFormatException e1) {
                        return false;
                    }
@@ -136,6 +140,8 @@ public class CSVPreferencePage extends FieldEditorPreferencePage implements IWor
            };
            fStartEditor.setEmptyStringAllowed(true);
            fStartEditor.setErrorMessage("Enter valid start time value (s)");
+           fStartEditor.getTextControl(getFieldEditorParent()).setToolTipText("Time to start resampling from");
+           addField(fStartEditor);
 
            fStepEditor = new StringFieldEditor(CSVPreferences.P_CSV_TIME_STEP, "Step size (s)", getFieldEditorParent()) {
                protected boolean doCheckState() {
@@ -153,6 +159,7 @@ public class CSVPreferencePage extends FieldEditorPreferencePage implements IWor
            };
            fStepEditor.setEmptyStringAllowed(true);
            fStepEditor.setErrorMessage("Enter valid time step value (s)");
+           fStepEditor.getTextControl(getFieldEditorParent()).setToolTipText("Time step to use when resampling");
            addField(fStepEditor);
 
            Group significantDigitsGroup = new Group(getFieldEditorParent(), SWT.NONE);
@@ -171,6 +178,8 @@ public class CSVPreferencePage extends FieldEditorPreferencePage implements IWor
            addField(fDoubleDigitsEditor);
 
            GridLayoutFactory.swtDefaults().numColumns(2).applyTo(significantDigitsGroup);
+
+           updateSampling(getPreferenceStore().getBoolean(CSVPreferences.P_CSV_RESAMPLE));
        }
 
     /**
@@ -187,6 +196,8 @@ public class CSVPreferencePage extends FieldEditorPreferencePage implements IWor
             } else if (source == fColumnSeparatorEditor) {
                 columnSeparatorValue = (String) event.getNewValue();
                 validate = true;
+            } else if (source == fResamplingEditor) {
+                updateSampling();
             }
             if (validate) {
                 if (decimalSeparatorValue.equals(columnSeparatorValue)) {
@@ -201,4 +212,16 @@ public class CSVPreferencePage extends FieldEditorPreferencePage implements IWor
         super.propertyChange(event);
     }
 
+    private void updateSampling() {
+        updateSampling(fResamplingEditor.getBooleanValue());
+    }
+
+    private void updateSampling(boolean resample) {
+        Label fStartLabel = fStartEditor.getLabelControl(getFieldEditorParent());
+        Label fStepLabel = fStepEditor.getLabelControl(getFieldEditorParent());
+        Color gray = fStartLabel.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
+        fStartLabel.setForeground(resample ? null : gray);
+        fStepLabel.setForeground(resample ? null : gray);
+    }
+
 }