From: Tuukka Lehtonen Date: Thu, 19 Mar 2020 23:45:59 +0000 (+0200) Subject: Improved Copy Visible Data usability in time series chart editor X-Git-Tag: v1.43.0~53 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F33%2F4033%2F1;p=simantics%2Fplatform.git Improved Copy Visible Data usability in time series chart editor The action now first opens a preference dialog with only the CSV export preferences shown which allows the user to know what settings are being used to copy the data before actually copying, and also cancel the copy. The preference page also shows which options are not used if resampling is not enabled. gitlab #501 Change-Id: If998d322f4286841c2c6bd3cbad479b8032b19ae --- diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/editor/ChartCopyHandler.java b/bundles/org.simantics.charts/src/org/simantics/charts/editor/ChartCopyHandler.java index 65108d6f7..183000045 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/editor/ChartCopyHandler.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/editor/ChartCopyHandler.java @@ -1,6 +1,6 @@ /******************************************************************************* - * Copyright (c) 2011 Association for Decentralized Information Management in - * Industry THTH ry. + * Copyright (c) 2011,2020 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 @@ -8,6 +8,7 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - #501 *******************************************************************************/ package org.simantics.charts.editor; @@ -33,11 +34,14 @@ import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.simantics.charts.ui.CSVProgressMonitor; @@ -74,8 +78,28 @@ public class ChartCopyHandler extends AbstractHandler { IStatusLineManager status = editor.getEditorSite().getActionBars().getStatusLineManager(); final Shell shell = HandlerUtil.getActiveShell(event); - final AtomicBoolean result = new AtomicBoolean(false); + // Find a good value to use for START_TIME based on the current horizontal ruler + // time range and the data start time. + IPreferenceStore csvnode = new ScopedPreferenceStore( InstanceScope.INSTANCE, CSVPreferences.P_NODE ); + double oldStartTime = csvnode.getDouble(CSVPreferences.P_CSV_START_TIME); + double timeStep = csvnode.getDouble(CSVPreferences.P_CSV_TIME_STEP); + double visibleChartMinTime = trendNode.horizRuler.from; + double dataStartTime = trendNode.horizRuler.getItemFromTime(); + // Find the first sample time that contains data if startTime < _from + double n = Math.max(0, Math.ceil((visibleChartMinTime-dataStartTime) / timeStep)); + double temporaryStartTime = dataStartTime + n*timeStep; + csvnode.setValue(CSVPreferences.P_CSV_START_TIME, temporaryStartTime); + try { + PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn( + shell, "org.simantics.modeling.csv.preferences", + new String[] { "org.simantics.modeling.csv.preferences" }, + null); + dialog.setMessage("Select Used CSV Export Settings"); + if (dialog.open() != Window.OK) + return null; + + AtomicBoolean result = new AtomicBoolean(false); PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { @@ -92,6 +116,8 @@ public class ChartCopyHandler extends AbstractHandler { ErrorLogger.defaultLogError(e.getCause()); } catch (InterruptedException e) { ErrorLogger.defaultLogError(e); + } finally { + csvnode.setValue(CSVPreferences.P_CSV_START_TIME, oldStartTime); } return null; diff --git a/bundles/org.simantics.history/src/org/simantics/history/csv/CSVFormatter.java b/bundles/org.simantics.history/src/org/simantics/history/csv/CSVFormatter.java index 4e405e2ac..6cc7a2a6f 100644 --- a/bundles/org.simantics.history/src/org/simantics/history/csv/CSVFormatter.java +++ b/bundles/org.simantics.history/src/org/simantics/history/csv/CSVFormatter.java @@ -308,7 +308,7 @@ public class CSVFormatter { // Sampling based on given startTime and timeStep if(timeStep > 0) { - // Find the first sample time that contains data + // Find the first sample time that contains data if startTime < _from double n = Math.max(0, Math.ceil((_from-startTime) / timeStep)); time = startTime + n*timeStep; @@ -587,7 +587,7 @@ public class CSVFormatter { private Formatter evaluateFormatter(Format format, DecimalSeparator target) { // Probe decimal separator String onePointTwo = format.format(1.2); - System.out.println("formatted zeroPointOne: " + onePointTwo); + //System.out.println("formatted zeroPointOne: " + onePointTwo); DecimalSeparator formatSeparator; if (onePointTwo.indexOf('.') != -1) { diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/preferences/CSVPreferencePage.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/preferences/CSVPreferencePage.java index aadd9395a..7a2e7a6eb 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/preferences/CSVPreferencePage.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/preferences/CSVPreferencePage.java @@ -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); + } + } diff --git a/bundles/org.simantics.trend/src/org/simantics/trend/impl/HorizRuler.java b/bundles/org.simantics.trend/src/org/simantics/trend/impl/HorizRuler.java index a70949d5e..708a32efc 100644 --- a/bundles/org.simantics.trend/src/org/simantics/trend/impl/HorizRuler.java +++ b/bundles/org.simantics.trend/src/org/simantics/trend/impl/HorizRuler.java @@ -284,6 +284,14 @@ public class HorizRuler extends TrendGraphicalNode { return (end-from) / getWidth(); } + /** + * @return the current starting sample time calculated from all visible chart + * items. + */ + public double getItemFromTime() { + return iFrom; + } + /** * @return the current ending sample time calculated from all visible chart * items.