tmf: remove deprecated methods from tmf
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / project / model / TraceTypePreferences.java
1 /**********************************************************************
2 * Copyright (c) 2017 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 package org.eclipse.tracecompass.tmf.core.project.model;
10
11 import java.util.List;
12
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;
18
19 import com.google.common.base.Joiner;
20 import com.google.common.base.Splitter;
21 import com.google.common.collect.Lists;
22
23 /**
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.
26 *
27 * @author Jean-Christian Kouame
28 * @since 3.0
29 */
30 public final class TraceTypePreferences {
31
32 private static final String SEPARATOR = "::"; //$NON-NLS-1$
33 /**
34 * The key for trace type preferences
35 */
36 public static final String TRACE_TYPE_PREFERENCE_KEY = "org.eclipse.tracecompass.tmf.core.prefs.traceType"; //$NON-NLS-1$
37
38 /**
39 * Initialize the trace type preferences
40 */
41 public static void init() {
42 IEclipsePreferences configurationPreferences = getEclipsePreference();
43 try {
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$
48 }
49
50 }
51
52 private static String getDefaultValue() {
53 return Joiner.on(SEPARATOR).join(new @NonNull String[] {});
54 }
55
56 /**
57 * Update the trace type preference value. The value stored is the list of
58 * disabled trace types.
59 *
60 * @param disabled
61 * The list of disabled trace type ids in the preference page
62 */
63 public static void setPreferenceValue(List<@NonNull String> disabled) {
64 try {
65 IEclipsePreferences configurationPreferences = getEclipsePreference();
66
67 TmfTraceType.getTraceTypeHelpers().forEach(helper -> {
68 if (!helper.isExperimentType()) {
69 helper.setEnabled(!disabled.contains(helper.getTraceTypeId()));
70 }
71 });
72
73 String value = Joiner.on(SEPARATOR).join(disabled);
74
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$
79 }
80 }
81
82 private static IEclipsePreferences getEclipsePreference() {
83 IEclipsePreferences configurationPreferences = ConfigurationScope.INSTANCE.getNode(Activator.PLUGIN_ID);
84 return configurationPreferences;
85 }
86
87 /**
88 * Get the preference value for the trace types
89 *
90 * @return The list of disabled trace types
91 */
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);
97 }
98 }
This page took 0.034315 seconds and 5 git commands to generate.