/*******************************************************************************
- * 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;