Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
b544077e | 2 | * Copyright (c) 2010, 2012 Ericsson |
c4c81d91 | 3 | * |
12c155f5 FC |
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 | |
c4c81d91 | 8 | * |
12c155f5 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
14 | ||
c4c81d91 PT |
15 | import java.io.ByteArrayInputStream; |
16 | import java.io.InputStream; | |
12c155f5 | 17 | import java.util.ArrayList; |
5a5c2fc7 | 18 | import java.util.Arrays; |
12c155f5 FC |
19 | import java.util.List; |
20 | ||
c4c81d91 | 21 | import org.eclipse.core.resources.IFile; |
12c155f5 | 22 | import org.eclipse.core.resources.IFolder; |
c4c81d91 PT |
23 | import org.eclipse.core.resources.IResource; |
24 | import org.eclipse.core.runtime.CoreException; | |
25 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; | |
26 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; | |
12c155f5 FC |
27 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
28 | import org.eclipse.ui.views.properties.IPropertySource2; | |
29 | import org.eclipse.ui.views.properties.TextPropertyDescriptor; | |
30 | ||
31 | /** | |
b544077e | 32 | * Implementation of TMF Experiment Model Element. |
12c155f5 | 33 | * <p> |
b544077e BH |
34 | * @version 1.0 |
35 | * @author Francois Chouinard | |
c4c81d91 | 36 | * |
12c155f5 FC |
37 | */ |
38 | public class TmfExperimentElement extends TmfProjectModelElement implements IPropertySource2 { | |
39 | ||
40 | // ------------------------------------------------------------------------ | |
41 | // Constants | |
42 | // ------------------------------------------------------------------------ | |
43 | ||
44 | // Property View stuff | |
45 | private static final String sfInfoCategory = "Info"; //$NON-NLS-1$ | |
46 | private static final String sfName = "name"; //$NON-NLS-1$ | |
47 | private static final String sfPath = "path"; //$NON-NLS-1$ | |
48 | private static final String sfLocation = "location"; //$NON-NLS-1$ | |
49 | ||
50 | private static final TextPropertyDescriptor sfNameDescriptor = new TextPropertyDescriptor(sfName, sfName); | |
51 | private static final TextPropertyDescriptor sfPathDescriptor = new TextPropertyDescriptor(sfPath, sfPath); | |
52 | private static final TextPropertyDescriptor sfLocationDescriptor = new TextPropertyDescriptor(sfLocation, | |
53 | sfLocation); | |
54 | ||
55 | private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, | |
56 | sfLocationDescriptor }; | |
57 | ||
58 | static { | |
59 | sfNameDescriptor.setCategory(sfInfoCategory); | |
60 | sfPathDescriptor.setCategory(sfInfoCategory); | |
61 | sfLocationDescriptor.setCategory(sfInfoCategory); | |
62 | } | |
63 | ||
c4c81d91 PT |
64 | private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$ |
65 | ||
12c155f5 FC |
66 | // ------------------------------------------------------------------------ |
67 | // Constructors | |
68 | // ------------------------------------------------------------------------ | |
b544077e | 69 | /** |
c4c81d91 | 70 | * Constructor |
b544077e BH |
71 | * @param name The name of the experiment |
72 | * @param folder The folder reference | |
73 | * @param parent The experiment folder reference. | |
74 | */ | |
12c155f5 FC |
75 | public TmfExperimentElement(String name, IFolder folder, TmfExperimentFolder parent) { |
76 | super(name, folder, parent); | |
77 | parent.addChild(this); | |
78 | } | |
79 | ||
80 | // ------------------------------------------------------------------------ | |
81 | // TmfProjectModelElement | |
82 | // ------------------------------------------------------------------------ | |
83 | ||
b544077e BH |
84 | /* |
85 | * (non-Javadoc) | |
86 | * @see org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectModelElement#getResource() | |
87 | */ | |
12c155f5 FC |
88 | @Override |
89 | public IFolder getResource() { | |
90 | return (IFolder) fResource; | |
91 | } | |
92 | ||
b544077e BH |
93 | /* |
94 | * (non-Javadoc) | |
95 | * @see org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement#getProject() | |
96 | */ | |
12c155f5 FC |
97 | @Override |
98 | public TmfProjectElement getProject() { | |
99 | return (TmfProjectElement) getParent().getParent(); | |
100 | } | |
101 | ||
102 | // ------------------------------------------------------------------------ | |
103 | // Operations | |
104 | // ------------------------------------------------------------------------ | |
b544077e BH |
105 | /** |
106 | * Returns a list of TmfTraceElements contained in this experiment. | |
107 | * @return a list of TmfTraceElements | |
108 | */ | |
12c155f5 FC |
109 | public List<TmfTraceElement> getTraces() { |
110 | List<ITmfProjectModelElement> children = getChildren(); | |
111 | List<TmfTraceElement> traces = new ArrayList<TmfTraceElement>(); | |
112 | for (ITmfProjectModelElement child : children) { | |
113 | if (child instanceof TmfTraceElement) { | |
114 | traces.add((TmfTraceElement) child); | |
115 | } | |
116 | } | |
117 | return traces; | |
118 | } | |
119 | ||
c4c81d91 | 120 | /** |
81fe3479 PT |
121 | * Returns the file resource used to store bookmarks after creating it if necessary. |
122 | * The file will be created if it does not exist. | |
c4c81d91 PT |
123 | * @return the bookmarks file |
124 | * @throws CoreException if the bookmarks file cannot be created | |
125 | * @since 2.0 | |
126 | */ | |
81fe3479 PT |
127 | public IFile createBookmarksFile() throws CoreException { |
128 | IFile file = getBookmarksFile(); | |
c4c81d91 | 129 | if (!file.exists()) { |
81fe3479 PT |
130 | final IFile bookmarksFile = getProject().getExperimentsFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE); |
131 | if (!bookmarksFile.exists()) { | |
132 | final InputStream source = new ByteArrayInputStream(new byte[0]); | |
133 | bookmarksFile.create(source, true, null); | |
134 | } | |
135 | bookmarksFile.setHidden(true); | |
c4c81d91 | 136 | file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null); |
81fe3479 PT |
137 | file.setHidden(true); |
138 | file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfExperiment.class.getCanonicalName()); | |
c4c81d91 | 139 | } |
81fe3479 PT |
140 | return file; |
141 | } | |
142 | ||
143 | /** | |
144 | * Returns the file resource used to store bookmarks. | |
145 | * The file may not exist. | |
146 | * @return the bookmarks file | |
147 | * @since 2.0 | |
148 | */ | |
149 | public IFile getBookmarksFile() { | |
150 | final IFolder folder = (IFolder) fResource; | |
151 | IFile file = folder.getFile(getName() + '_'); | |
c4c81d91 PT |
152 | return file; |
153 | } | |
154 | ||
12c155f5 FC |
155 | // ------------------------------------------------------------------------ |
156 | // IPropertySource2 | |
157 | // ------------------------------------------------------------------------ | |
158 | ||
b544077e BH |
159 | /* |
160 | * (non-Javadoc) | |
161 | * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue() | |
162 | */ | |
12c155f5 FC |
163 | @Override |
164 | public Object getEditableValue() { | |
165 | return null; | |
166 | } | |
167 | ||
b544077e BH |
168 | /* |
169 | * (non-Javadoc) | |
170 | * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() | |
171 | */ | |
12c155f5 FC |
172 | @Override |
173 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
77fdc5df | 174 | return Arrays.copyOf(sfDescriptors, sfDescriptors.length); |
12c155f5 FC |
175 | } |
176 | ||
b544077e BH |
177 | /* |
178 | * (non-Javadoc) | |
179 | * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) | |
180 | */ | |
12c155f5 FC |
181 | @Override |
182 | public Object getPropertyValue(Object id) { | |
183 | ||
c4c81d91 | 184 | if (sfName.equals(id)) { |
12c155f5 | 185 | return getName(); |
c4c81d91 | 186 | } |
12c155f5 | 187 | |
c4c81d91 | 188 | if (sfPath.equals(id)) { |
12c155f5 | 189 | return getPath().toString(); |
c4c81d91 | 190 | } |
12c155f5 | 191 | |
c4c81d91 | 192 | if (sfLocation.equals(id)) { |
12c155f5 | 193 | return getLocation().toString(); |
c4c81d91 | 194 | } |
12c155f5 FC |
195 | |
196 | return null; | |
197 | } | |
c4c81d91 | 198 | |
b544077e BH |
199 | /* |
200 | * (non-Javadoc) | |
201 | * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object) | |
202 | */ | |
12c155f5 FC |
203 | @Override |
204 | public void resetPropertyValue(Object id) { | |
205 | } | |
206 | ||
b544077e BH |
207 | /* |
208 | * (non-Javadoc) | |
209 | * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object) | |
210 | */ | |
12c155f5 FC |
211 | @Override |
212 | public void setPropertyValue(Object id, Object value) { | |
213 | } | |
214 | ||
b544077e BH |
215 | /* |
216 | * (non-Javadoc) | |
217 | * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertyResettable(java.lang.Object) | |
218 | */ | |
12c155f5 FC |
219 | @Override |
220 | public boolean isPropertyResettable(Object id) { | |
221 | return false; | |
222 | } | |
223 | ||
b544077e BH |
224 | /* |
225 | * (non-Javadoc) | |
226 | * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertySet(java.lang.Object) | |
227 | */ | |
12c155f5 FC |
228 | @Override |
229 | public boolean isPropertySet(Object id) { | |
230 | return false; | |
231 | } | |
232 | ||
233 | } |