1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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 TmfWithFolderElement
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$
49 private static final String sfFolderSuffix
= "_exp"; //$NON-NLS-1$
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
,
56 private static final IPropertyDescriptor
[] sfDescriptors
= { sfNameDescriptor
, sfPathDescriptor
,
57 sfLocationDescriptor
};
60 sfNameDescriptor
.setCategory(sfInfoCategory
);
61 sfPathDescriptor
.setCategory(sfInfoCategory
);
62 sfLocationDescriptor
.setCategory(sfInfoCategory
);
65 private static final String BOOKMARKS_HIDDEN_FILE
= ".bookmarks"; //$NON-NLS-1$
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 * @param name The name of the experiment
73 * @param folder The folder reference
74 * @param parent The experiment folder reference.
76 public TmfExperimentElement(String name
, IFolder folder
, TmfExperimentFolder parent
) {
77 super(name
, folder
, parent
);
78 parent
.addChild(this);
81 // ------------------------------------------------------------------------
82 // TmfProjectModelElement
83 // ------------------------------------------------------------------------
87 * @see org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectModelElement#getResource()
90 public IFolder
getResource() {
91 return (IFolder
) fResource
;
96 * @see org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement#getProject()
99 public TmfProjectElement
getProject() {
100 return (TmfProjectElement
) getParent().getParent();
103 // ------------------------------------------------------------------------
105 // ------------------------------------------------------------------------
107 * Returns a list of TmfTraceElements contained in this experiment.
108 * @return a list of TmfTraceElements
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
);
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.
124 * @return the bookmarks file
125 * @throws CoreException if the bookmarks file cannot be created
128 public IFile
createBookmarksFile() throws CoreException
{
129 IFile file
= getBookmarksFile();
130 if (!file
.exists()) {
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);
136 bookmarksFile
.setHidden(true);
137 file
.createLink(bookmarksFile
.getLocation(), IResource
.REPLACE
, null);
138 file
.setHidden(true);
139 file
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, TmfExperiment
.class.getCanonicalName());
145 * Returns the file resource used to store bookmarks.
146 * The file may not exist.
147 * @return the bookmarks file
150 public IFile
getBookmarksFile() {
151 final IFolder folder
= (IFolder
) fResource
;
152 IFile file
= folder
.getFile(getName() + '_');
156 // ------------------------------------------------------------------------
158 // ------------------------------------------------------------------------
162 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
165 public Object
getEditableValue() {
171 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
174 public IPropertyDescriptor
[] getPropertyDescriptors() {
175 return Arrays
.copyOf(sfDescriptors
, sfDescriptors
.length
);
180 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
183 public Object
getPropertyValue(Object id
) {
185 if (sfName
.equals(id
)) {
189 if (sfPath
.equals(id
)) {
190 return getPath().toString();
193 if (sfLocation
.equals(id
)) {
194 return getLocation().toString();
202 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
205 public void resetPropertyValue(Object id
) {
210 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
213 public void setPropertyValue(Object id
, Object value
) {
218 * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertyResettable(java.lang.Object)
221 public boolean isPropertyResettable(Object id
) {
227 * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertySet(java.lang.Object)
230 public boolean isPropertySet(Object id
) {
235 * Return the suffix for resource names
236 * @return The folder suffix
239 public String
getSuffix() {
240 return sfFolderSuffix
;