1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
;
15 import java
.io
.ByteArrayInputStream
;
16 import java
.io
.InputStream
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Arrays
;
19 import java
.util
.List
;
21 import org
.eclipse
.core
.resources
.IFile
;
22 import org
.eclipse
.core
.resources
.IFolder
;
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
;
27 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
28 import org
.eclipse
.ui
.views
.properties
.IPropertySource2
;
29 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
32 * Implementation of TMF Experiment Model Element.
35 * @author Francois Chouinard
38 public class TmfExperimentElement
extends TmfProjectModelElement
implements IPropertySource2
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
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$
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
,
55 private static final IPropertyDescriptor
[] sfDescriptors
= { sfNameDescriptor
, sfPathDescriptor
,
56 sfLocationDescriptor
};
59 sfNameDescriptor
.setCategory(sfInfoCategory
);
60 sfPathDescriptor
.setCategory(sfInfoCategory
);
61 sfLocationDescriptor
.setCategory(sfInfoCategory
);
64 private static final String BOOKMARKS_HIDDEN_FILE
= ".bookmarks"; //$NON-NLS-1$
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
71 * @param name The name of the experiment
72 * @param folder The folder reference
73 * @param parent The experiment folder reference.
75 public TmfExperimentElement(String name
, IFolder folder
, TmfExperimentFolder parent
) {
76 super(name
, folder
, parent
);
77 parent
.addChild(this);
80 // ------------------------------------------------------------------------
81 // TmfProjectModelElement
82 // ------------------------------------------------------------------------
86 * @see org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectModelElement#getResource()
89 public IFolder
getResource() {
90 return (IFolder
) fResource
;
95 * @see org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement#getProject()
98 public TmfProjectElement
getProject() {
99 return (TmfProjectElement
) getParent().getParent();
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
106 * Returns a list of TmfTraceElements contained in this experiment.
107 * @return a list of TmfTraceElements
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
);
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.
123 * @return the bookmarks file
124 * @throws CoreException if the bookmarks file cannot be created
127 public IFile
createBookmarksFile() throws CoreException
{
128 IFile file
= getBookmarksFile();
129 if (!file
.exists()) {
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);
135 bookmarksFile
.setHidden(true);
136 file
.createLink(bookmarksFile
.getLocation(), IResource
.REPLACE
, null);
137 file
.setHidden(true);
138 file
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, TmfExperiment
.class.getCanonicalName());
144 * Returns the file resource used to store bookmarks.
145 * The file may not exist.
146 * @return the bookmarks file
149 public IFile
getBookmarksFile() {
150 final IFolder folder
= (IFolder
) fResource
;
151 IFile file
= folder
.getFile(getName() + '_');
155 // ------------------------------------------------------------------------
157 // ------------------------------------------------------------------------
161 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
164 public Object
getEditableValue() {
170 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
173 public IPropertyDescriptor
[] getPropertyDescriptors() {
174 return Arrays
.copyOf(sfDescriptors
, sfDescriptors
.length
);
179 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
182 public Object
getPropertyValue(Object id
) {
184 if (sfName
.equals(id
)) {
188 if (sfPath
.equals(id
)) {
189 return getPath().toString();
192 if (sfLocation
.equals(id
)) {
193 return getLocation().toString();
201 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
204 public void resetPropertyValue(Object id
) {
209 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
212 public void setPropertyValue(Object id
, Object value
) {
217 * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertyResettable(java.lang.Object)
220 public boolean isPropertyResettable(Object id
) {
226 * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertySet(java.lang.Object)
229 public boolean isPropertySet(Object id
) {