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