tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.remote.core / src / org / eclipse / tracecompass / internal / tmf / remote / core / preferences / TmfRemotePreferences.java
CommitLineData
ec619615
BH
1/**********************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12package org.eclipse.tracecompass.internal.tmf.remote.core.preferences;
13
14import java.util.HashMap;
15import java.util.Map;
16
17import org.eclipse.core.runtime.preferences.DefaultScope;
18import org.eclipse.core.runtime.preferences.IEclipsePreferences;
19import org.eclipse.core.runtime.preferences.InstanceScope;
20import org.eclipse.tracecompass.internal.tmf.remote.core.Activator;
21
22/**
23 * Singleton class to access the remote control preferences of Trace Compasss.
24 *
25 * @author Bernd Hufmann
26 */
27public final class TmfRemotePreferences {
28
29 // ------------------------------------------------------------------------
30 // Constants
31 // ------------------------------------------------------------------------
32 /**
33 * The command time-out preference
34 */
35 public static final String TRACE_CONTROL_COMMAND_TIMEOUT_PREF = "trace.control.command.timeout"; //$NON-NLS-1$
36 /**
37 * Default timeout value used for executing commands, in seconds
38 */
39 public static final int TRACE_CONTROL_DEFAULT_TIMEOUT_VALUE = 15;
40 /**
41 * Minimum timeout value used for executing commands, in seconds
42 */
43 public static final int TRACE_CONTROL_MIN_TIMEOUT_VALUE = 5;
44 /**
45 * Maximum timeout value used for executing commands, in seconds
46 */
47 public static final int TRACE_CONTROL_MAX_TIMEOUT_VALUE = 600;
48
49 // ------------------------------------------------------------------------
50 // operations
51 // ------------------------------------------------------------------------
52
53 /**
54 * Initialize the default preferences and the singleton
55 */
56 public static void init() {
57 IEclipsePreferences defaultPreferences = DefaultScope.INSTANCE.getNode(Activator.PLUGIN_ID);
58
59 //Set default User ID if none already stored in preferences
60 defaultPreferences.put(TRACE_CONTROL_COMMAND_TIMEOUT_PREF, String.valueOf(TmfRemotePreferences.TRACE_CONTROL_DEFAULT_TIMEOUT_VALUE));
61
62 }
63
64 private static void prefToMap(IEclipsePreferences node, Map<String, String> prefsMap, String key, String defaultValue) {
65 prefsMap.put(key, node.get(key, defaultValue));
66 }
67
68 /**
69 * Get the default preferences map
70 *
71 * @return a collection containing the default preferences
72 */
73 public static Map<String, String> getDefaultPreferenceMap() {
74 return getPreferenceMap(true);
75 }
76
77 /**
78 * Get the current preferences map
79 *
80 * @return a collection containing the current preferences
81 */
82 public static Map<String, String> getPreferenceMap() {
83 return getPreferenceMap(false);
84 }
85
86 private static Map<String, String> getPreferenceMap(boolean defaultValues) {
87 Map<String, String> prefsMap = new HashMap<>();
88 IEclipsePreferences prefs = defaultValues ? DefaultScope.INSTANCE.getNode(Activator.PLUGIN_ID) : InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
89 prefToMap(prefs, prefsMap, TRACE_CONTROL_COMMAND_TIMEOUT_PREF, String.valueOf(TmfRemotePreferences.TRACE_CONTROL_DEFAULT_TIMEOUT_VALUE));
90 return prefsMap;
91 }
92
93 /**
94 * @return command timeout value
95 */
96 public static int getCommandTimeout() {
97 return Integer.parseInt(getPreferenceMap().get(TRACE_CONTROL_COMMAND_TIMEOUT_PREF));
98 }
99
100}
This page took 0.037482 seconds and 5 git commands to generate.