]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.workbench/src/org/simantics/workbench/internal/preferences/AutosavePreferencePage.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.workbench / src / org / simantics / workbench / internal / preferences / AutosavePreferencePage.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.workbench.internal.preferences;\r
13 \r
14 import org.eclipse.core.runtime.preferences.InstanceScope;\r
15 import org.eclipse.jface.preference.BooleanFieldEditor;\r
16 import org.eclipse.jface.preference.FieldEditorPreferencePage;\r
17 import org.eclipse.jface.preference.IPreferenceStore;\r
18 import org.eclipse.jface.preference.IntegerFieldEditor;\r
19 import org.eclipse.ui.IWorkbench;\r
20 import org.eclipse.ui.IWorkbenchPreferencePage;\r
21 import org.eclipse.ui.preferences.ScopedPreferenceStore;\r
22 import org.simantics.AutosavePreferences;\r
23 import org.simantics.AutosaveVirtualGraphs;\r
24 \r
25 /**\r
26  * @author Tuukka Lehtonen <tuukka.lehtonen@semantum.fi>\r
27  */\r
28 public class AutosavePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {\r
29 \r
30     public AutosavePreferencePage() {\r
31         super(GRID);\r
32 \r
33         IPreferenceStore pf = new ScopedPreferenceStore(InstanceScope.INSTANCE, AutosavePreferences.P_NODE);\r
34         setPreferenceStore( pf );\r
35     }\r
36 \r
37     @Override\r
38     protected void createFieldEditors() {\r
39         BooleanFieldEditor autosaveEnabled = new BooleanFieldEditor(\r
40                 AutosavePreferences.P_VG_AUTOSAVE_ENABLED,\r
41                 "Virtual Graph autosave enabled",\r
42                 getFieldEditorParent());\r
43         addField(autosaveEnabled);\r
44 \r
45         IntegerFieldEditor autosaveInterval = new IntegerFieldEditor(\r
46                 AutosavePreferences.P_VG_AUTOSAVE_INTERVAL, \r
47                 "Virtual Graph autosave interval (seconds)", \r
48                 getFieldEditorParent());\r
49         autosaveInterval.setValidRange(1, Integer.MAX_VALUE);\r
50         autosaveInterval.setErrorMessage("Autosave interval must be positive");\r
51         addField(autosaveInterval);\r
52     }\r
53 \r
54     @Override\r
55     public boolean performOk() {\r
56         if(super.performOk()) {\r
57             AutosaveVirtualGraphs.saveVirtualGraphsPeriodically();\r
58             return true;\r
59         }\r
60         else\r
61             return false;\r
62     }\r
63 \r
64     @Override\r
65     public void init(IWorkbench workbench) {\r
66     }\r
67 \r
68 }\r