]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues/src/org/simantics/issues/preferences/IssuePreferenceUtil.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.issues / src / org / simantics / issues / preferences / IssuePreferenceUtil.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.issues.preferences;
13
14 import org.eclipse.core.runtime.preferences.DefaultScope;
15 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
16 import org.eclipse.core.runtime.preferences.IScopeContext;
17 import org.eclipse.core.runtime.preferences.InstanceScope;
18 import org.osgi.service.prefs.BackingStoreException;
19 import org.osgi.service.prefs.Preferences;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public final class IssuePreferenceUtil {
25
26     public static final String PLUGIN_ID = "org.simantics.issues";
27
28     public static IssuePreferences getDefaultPreferences() {
29         return getPreferences(DefaultScope.INSTANCE);
30     }
31
32     /**
33      * @return
34      */
35     public static IssuePreferences getPreferences() {
36         return getPreferences(InstanceScope.INSTANCE);
37     }
38
39     /**
40      * @return
41      */
42     public static IssuePreferences getPreferences(IScopeContext context) {
43         Preferences node = context.getNode(PLUGIN_ID);
44         boolean enabled = node.getBoolean(IssuePreferences.P_ISSUES_ENABLED, IssuePreferences.DEFAULT_ISSUES_ENABLED);
45         int maxIssuesToWrite = node.getInt(IssuePreferences.P_MAX_BATCH_ISSUES_TO_WRITE, IssuePreferences.DEFAULT_MAX_BATCH_ISSUES_TO_WRITE);
46         return new IssuePreferences(enabled, maxIssuesToWrite);
47     }
48
49     /**
50      * @return
51      * @throws BackingStoreException
52      */
53     public static void setPreferences(IssuePreferences commons) {
54         _setPreferences(InstanceScope.INSTANCE, commons);
55     }
56
57     /**
58      * @return
59      * @throws BackingStoreException
60      */
61     public static void flushPreferences(IssuePreferences commons) throws BackingStoreException {
62         Preferences p = _setPreferences(InstanceScope.INSTANCE, commons);
63         p.flush();
64     }
65
66     /**
67      * @return
68      * @throws BackingStoreException
69      */
70     public static void setPreferences(IScopeContext context, IssuePreferences prefs) {
71         _setPreferences(context, prefs);
72     }
73
74     /**
75      * @return
76      * @throws BackingStoreException
77      */
78     private static IEclipsePreferences _setPreferences(IScopeContext context, IssuePreferences prefs) {
79         IEclipsePreferences node = context.getNode(PLUGIN_ID);
80         node.putBoolean(IssuePreferences.P_ISSUES_ENABLED, prefs.enabled);
81         node.putInt(IssuePreferences.P_MAX_BATCH_ISSUES_TO_WRITE, prefs.maxBatchIssuesToWrite);
82         return node;
83     }
84
85 }