/*******************************************************************************
- * 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
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
+ * Semantum Oy - #501
*******************************************************************************/
package org.simantics.charts.editor;
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;
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 {
ErrorLogger.defaultLogError(e.getCause());
} catch (InterruptedException e) {
ErrorLogger.defaultLogError(e);
+ } finally {
+ csvnode.setValue(CSVPreferences.P_CSV_START_TIME, oldStartTime);
}
return null;
// 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;
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) {
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;
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",
return true;
}
try {
+ @SuppressWarnings("unused")
double number = Double.parseDouble(text);
- return number>0;
+ return true;
} catch (NumberFormatException e1) {
return false;
}
};
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() {
};
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);
addField(fDoubleDigitsEditor);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(significantDigitsGroup);
+
+ updateSampling(getPreferenceStore().getBoolean(CSVPreferences.P_CSV_RESAMPLE));
}
/**
} else if (source == fColumnSeparatorEditor) {
columnSeparatorValue = (String) event.getNewValue();
validate = true;
+ } else if (source == fResamplingEditor) {
+ updateSampling();
}
if (validate) {
if (decimalSeparatorValue.equals(columnSeparatorValue)) {
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);
+ }
+
}
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.