Commit | Line | Data |
---|---|---|
a3767fd9 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 MontaVista Software | |
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 | * Yufen Kuo (ykuo@mvista.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui; | |
13 | ||
14 | import org.eclipse.core.resources.IProject; | |
15 | import org.eclipse.core.resources.ProjectScope; | |
16 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; | |
17 | ||
18 | public class TraceHelper { | |
19 | /** | |
20 | * Get Trace Library Directory from Project Preference. | |
21 | * | |
22 | * @param project | |
23 | * The <b>project</b> in the workspace. | |
24 | * @return The <b>directory</b> of the trace libraries. null if not defined | |
25 | */ | |
26 | public static String getTraceLibDirFromProject(IProject project) { | |
27 | if (project != null && project.exists()) { | |
28 | return getProjectPreference(project, "traceLibraryPath"); | |
29 | } | |
30 | return null; | |
31 | } | |
32 | ||
33 | /** | |
34 | * Get the project preference with the specified name | |
35 | * | |
36 | * @param project | |
37 | * The <b>project</b> in the workspace. | |
38 | * @param preferenceName | |
39 | * name of the preference. | |
40 | * @return The project preference value. | |
41 | */ | |
42 | public static String getProjectPreference(IProject project, | |
43 | String preferenceName) { | |
44 | if (project.exists()) { | |
45 | IEclipsePreferences prefs = new ProjectScope(project) | |
46 | .getNode("org.eclipse.linuxtools.lttng.jni"); | |
47 | ||
48 | return prefs.get(preferenceName, null); | |
49 | } | |
50 | return null; | |
51 | } | |
52 | ||
53 | /** | |
54 | * Set the project preference with the specified value | |
55 | * | |
56 | * @param project | |
57 | * The <b>project</b> in the workspace. | |
58 | * @param preferenceName | |
59 | * name of the preference. | |
60 | * @param preferenceValue | |
61 | * value of the preference. | |
62 | * @return true if preference is successfully set, false otherwise. | |
63 | */ | |
64 | public static boolean setProjectPreference(IProject project, | |
65 | String preferenceName, String preferenceValue) { | |
66 | if (project.exists()) { | |
67 | IEclipsePreferences prefs = new ProjectScope(project) | |
68 | .getNode("org.eclipse.linuxtools.lttng.jni"); | |
69 | ||
70 | prefs.put(preferenceName, preferenceValue); | |
71 | try { | |
72 | prefs.flush(); | |
73 | return true; | |
74 | } catch (org.osgi.service.prefs.BackingStoreException e) { | |
75 | e.printStackTrace(); | |
76 | } | |
77 | ||
78 | } | |
79 | return false; | |
80 | } | |
81 | /** | |
82 | * Remove the project preference with the specified name | |
83 | * | |
84 | * @param project | |
85 | * The <b>project</b> in the workspace. | |
86 | * @param preferenceName | |
87 | * name of the preference. | |
88 | * @return true if preference name is successfully remove, false otherwise. | |
89 | */ | |
90 | public static boolean removeProjectPreference(IProject project, | |
91 | String preferenceName) { | |
92 | if (project.exists()) { | |
93 | IEclipsePreferences prefs = new ProjectScope(project) | |
94 | .getNode("org.eclipse.linuxtools.lttng.jni"); | |
95 | ||
96 | prefs.remove(preferenceName); | |
97 | try { | |
98 | prefs.flush(); | |
99 | return true; | |
100 | } catch (org.osgi.service.prefs.BackingStoreException e) { | |
101 | e.printStackTrace(); | |
102 | } | |
103 | ||
104 | } | |
105 | return false; | |
106 | } | |
107 | ||
108 | } |