--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2012 Association for Decentralized Information Management\r
+ * in 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
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.workbench.internal.preferences;\r
+\r
+import org.eclipse.core.runtime.preferences.InstanceScope;\r
+import org.eclipse.jface.preference.BooleanFieldEditor;\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.ui.IWorkbench;\r
+import org.eclipse.ui.IWorkbenchPreferencePage;\r
+import org.eclipse.ui.preferences.ScopedPreferenceStore;\r
+import org.simantics.AutosavePreferences;\r
+import org.simantics.AutosaveVirtualGraphs;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen <tuukka.lehtonen@semantum.fi>\r
+ */\r
+public class AutosavePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {\r
+\r
+ public AutosavePreferencePage() {\r
+ super(GRID);\r
+\r
+ IPreferenceStore pf = new ScopedPreferenceStore(InstanceScope.INSTANCE, AutosavePreferences.P_NODE);\r
+ setPreferenceStore( pf );\r
+ }\r
+\r
+ @Override\r
+ protected void createFieldEditors() {\r
+ BooleanFieldEditor autosaveEnabled = new BooleanFieldEditor(\r
+ AutosavePreferences.P_VG_AUTOSAVE_ENABLED,\r
+ "Virtual Graph autosave enabled",\r
+ getFieldEditorParent());\r
+ addField(autosaveEnabled);\r
+\r
+ IntegerFieldEditor autosaveInterval = new IntegerFieldEditor(\r
+ AutosavePreferences.P_VG_AUTOSAVE_INTERVAL, \r
+ "Virtual Graph autosave interval (seconds)", \r
+ getFieldEditorParent());\r
+ autosaveInterval.setValidRange(1, Integer.MAX_VALUE);\r
+ autosaveInterval.setErrorMessage("Autosave interval must be positive");\r
+ addField(autosaveInterval);\r
+ }\r
+\r
+ @Override\r
+ public boolean performOk() {\r
+ if(super.performOk()) {\r
+ AutosaveVirtualGraphs.saveVirtualGraphsPeriodically();\r
+ return true;\r
+ }\r
+ else\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public void init(IWorkbench workbench) {\r
+ }\r
+\r
+}\r