1 /**********************************************************************
2 * Copyright (c) 2017 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
8 **********************************************************************/
9 package org
.eclipse
.tracecompass
.tmf
.core
.project
.model
;
11 import java
.util
.List
;
13 import org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
;
14 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.Activator
;
17 import org
.osgi
.service
.prefs
.BackingStoreException
;
19 import com
.google
.common
.base
.Joiner
;
20 import com
.google
.common
.base
.Splitter
;
21 import com
.google
.common
.collect
.Lists
;
24 * Singleton class to access the trace type preferences of Trace Compass. The
25 * trace type preferences is a blacklist preference of disabled trace types.
27 * @author Jean-Christian Kouame
30 public final class TraceTypePreferences
{
32 private static final String SEPARATOR
= "::"; //$NON-NLS-1$
34 * The key for trace type preferences
36 public static final String TRACE_TYPE_PREFERENCE_KEY
= "org.eclipse.tracecompass.tmf.core.prefs.traceType"; //$NON-NLS-1$
39 * Initialize the trace type preferences
41 public static void init() {
42 IEclipsePreferences configurationPreferences
= getEclipsePreference();
44 configurationPreferences
.put(TRACE_TYPE_PREFERENCE_KEY
, configurationPreferences
.get(TRACE_TYPE_PREFERENCE_KEY
, getDefaultValue()));
45 configurationPreferences
.flush();
46 } catch (BackingStoreException e
) {
47 Activator
.logError("Failed to initialize trace type preferences", e
); //$NON-NLS-1$
52 private static String
getDefaultValue() {
53 return Joiner
.on(SEPARATOR
).join(new @NonNull String
[] {});
57 * Update the trace type preference value. The value stored is the list of
58 * disabled trace types.
61 * The list of disabled trace type ids in the preference page
63 public static void setPreferenceValue(List
<@NonNull String
> disabled
) {
65 IEclipsePreferences configurationPreferences
= getEclipsePreference();
67 TmfTraceType
.getTraceTypeHelpers().forEach(helper
-> {
68 if (!helper
.isExperimentType()) {
69 helper
.setEnabled(!disabled
.contains(helper
.getTraceTypeId()));
73 String value
= Joiner
.on(SEPARATOR
).join(disabled
);
75 configurationPreferences
.put(TraceTypePreferences
.TRACE_TYPE_PREFERENCE_KEY
, value
);
76 configurationPreferences
.flush();
77 } catch (BackingStoreException e
) {
78 Activator
.logError("Failed to set the trace type preferences", e
); //$NON-NLS-1$
82 private static IEclipsePreferences
getEclipsePreference() {
83 IEclipsePreferences configurationPreferences
= ConfigurationScope
.INSTANCE
.getNode(Activator
.PLUGIN_ID
);
84 return configurationPreferences
;
88 * Get the preference value for the trace types
90 * @return The list of disabled trace types
92 public static List
<String
> getPreferenceValue() {
93 IEclipsePreferences configurationPreferences
= getEclipsePreference();
94 String joined
= configurationPreferences
.get(TraceTypePreferences
.TRACE_TYPE_PREFERENCE_KEY
, getDefaultValue());
95 Iterable
<String
> disabled
= Splitter
.on(SEPARATOR
).split(joined
);
96 return Lists
.newArrayList(disabled
);