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