1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.issues.preferences;
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;
22 * @author Tuukka Lehtonen
24 public final class IssuePreferenceUtil {
26 public static final String PLUGIN_ID = "org.simantics.issues";
28 public static IssuePreferences getDefaultPreferences() {
29 return getPreferences(DefaultScope.INSTANCE);
35 public static IssuePreferences getPreferences() {
36 return getPreferences(InstanceScope.INSTANCE);
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);
51 * @throws BackingStoreException
53 public static void setPreferences(IssuePreferences commons) {
54 _setPreferences(InstanceScope.INSTANCE, commons);
59 * @throws BackingStoreException
61 public static void flushPreferences(IssuePreferences commons) throws BackingStoreException {
62 Preferences p = _setPreferences(InstanceScope.INSTANCE, commons);
68 * @throws BackingStoreException
70 public static void setPreferences(IScopeContext context, IssuePreferences prefs) {
71 _setPreferences(context, prefs);
76 * @throws BackingStoreException
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);