1 /**********************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.tmf
.remote
.core
.preferences
;
14 import java
.util
.HashMap
;
17 import org
.eclipse
.core
.runtime
.preferences
.DefaultScope
;
18 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
19 import org
.eclipse
.core
.runtime
.preferences
.InstanceScope
;
20 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.core
.Activator
;
23 * Singleton class to access the remote control preferences of Trace Compasss.
25 * @author Bernd Hufmann
27 public final class TmfRemotePreferences
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 * The command time-out preference
35 public static final String TRACE_CONTROL_COMMAND_TIMEOUT_PREF
= "trace.control.command.timeout"; //$NON-NLS-1$
37 * Default timeout value used for executing commands, in seconds
39 public static final int TRACE_CONTROL_DEFAULT_TIMEOUT_VALUE
= 15;
41 * Minimum timeout value used for executing commands, in seconds
43 public static final int TRACE_CONTROL_MIN_TIMEOUT_VALUE
= 5;
45 * Maximum timeout value used for executing commands, in seconds
47 public static final int TRACE_CONTROL_MAX_TIMEOUT_VALUE
= 600;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * Initialize the default preferences and the singleton
56 public static void init() {
57 IEclipsePreferences defaultPreferences
= DefaultScope
.INSTANCE
.getNode(Activator
.PLUGIN_ID
);
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
));
64 private static void prefToMap(IEclipsePreferences node
, Map
<String
, String
> prefsMap
, String key
, String defaultValue
) {
65 prefsMap
.put(key
, node
.get(key
, defaultValue
));
69 * Get the default preferences map
71 * @return a collection containing the default preferences
73 public static Map
<String
, String
> getDefaultPreferenceMap() {
74 return getPreferenceMap(true);
78 * Get the current preferences map
80 * @return a collection containing the current preferences
82 public static Map
<String
, String
> getPreferenceMap() {
83 return getPreferenceMap(false);
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
));
94 * @return command timeout value
96 public static int getCommandTimeout() {
97 return Integer
.parseInt(getPreferenceMap().get(TRACE_CONTROL_COMMAND_TIMEOUT_PREF
));