1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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 * Patrick Tasse - Add support for folder elements
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Arrays
;
18 import java
.util
.HashMap
;
19 import java
.util
.List
;
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
.tracecompass
.tmf
.ui
.properties
.ReadOnlyTextPropertyDescriptor
;
26 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
27 import org
.eclipse
.ui
.views
.properties
.IPropertySource2
;
30 * Implementation of model element representing the unique "Experiments" folder
35 * @author Francois Chouinard
38 public class TmfExperimentFolder
extends TmfProjectModelElement
implements IPropertySource2
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 * The name of the experiment folder.
47 public static final String EXPER_FOLDER_NAME
= "Experiments"; //$NON-NLS-1$
49 // Property View stuff
50 private static final String sfInfoCategory
= "Info"; //$NON-NLS-1$
51 private static final String sfName
= "name"; //$NON-NLS-1$
52 private static final String sfPath
= "path"; //$NON-NLS-1$
53 private static final String sfLocation
= "location"; //$NON-NLS-1$
55 private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor
= new ReadOnlyTextPropertyDescriptor(sfName
, sfName
);
56 private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor
= new ReadOnlyTextPropertyDescriptor(sfPath
, sfPath
);
57 private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor
= new ReadOnlyTextPropertyDescriptor(sfLocation
, sfLocation
);
59 private static final IPropertyDescriptor
[] sfDescriptors
= { sfNameDescriptor
, sfPathDescriptor
, sfLocationDescriptor
};
62 sfNameDescriptor
.setCategory(sfInfoCategory
);
63 sfPathDescriptor
.setCategory(sfInfoCategory
);
64 sfLocationDescriptor
.setCategory(sfInfoCategory
);
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
73 * Creates a TmfExperimentFolder model element.
74 * @param name The name of the folder
75 * @param folder The folder reference
76 * @param parent The parent (project element)
78 public TmfExperimentFolder(String name
, IFolder folder
, TmfProjectElement parent
) {
79 super(name
, folder
, parent
);
80 parent
.addChild(this);
83 // ------------------------------------------------------------------------
84 // TmfProjectModelElement
85 // ------------------------------------------------------------------------
88 public IFolder
getResource() {
89 return (IFolder
) fResource
;
93 void refreshChildren() {
94 IFolder folder
= getResource();
96 // Get the children from the model
97 Map
<String
, ITmfProjectModelElement
> childrenMap
= new HashMap
<>();
98 for (ITmfProjectModelElement element
: getChildren()) {
99 childrenMap
.put(element
.getResource().getName(), element
);
103 IResource
[] members
= folder
.members();
104 for (IResource resource
: members
) {
105 if (resource
instanceof IFolder
) {
106 IFolder expFolder
= (IFolder
) resource
;
107 String name
= resource
.getName();
108 ITmfProjectModelElement element
= childrenMap
.get(name
);
109 if (element
instanceof TmfExperimentElement
) {
110 childrenMap
.remove(name
);
112 element
= new TmfExperimentElement(name
, expFolder
, this);
114 ((TmfExperimentElement
) element
).refreshChildren();
117 } catch (CoreException e
) {
120 // Cleanup dangling children from the model
121 for (ITmfProjectModelElement danglingChild
: childrenMap
.values()) {
122 removeChild(danglingChild
);
126 // ------------------------------------------------------------------------
128 // ------------------------------------------------------------------------
131 * Returns a list of experiment model elements under the experiments folder.
132 * @return list of experiment model elements
134 public List
<TmfExperimentElement
> getExperiments() {
135 List
<ITmfProjectModelElement
> children
= getChildren();
136 List
<TmfExperimentElement
> traces
= new ArrayList
<>();
137 for (ITmfProjectModelElement child
: children
) {
138 if (child
instanceof TmfExperimentElement
) {
139 traces
.add((TmfExperimentElement
) child
);
145 // ------------------------------------------------------------------------
147 // ------------------------------------------------------------------------
150 public Object
getEditableValue() {
155 public IPropertyDescriptor
[] getPropertyDescriptors() {
156 return Arrays
.copyOf(sfDescriptors
, sfDescriptors
.length
);
160 public Object
getPropertyValue(Object id
) {
162 if (sfName
.equals(id
)) {
166 if (sfPath
.equals(id
)) {
167 return getPath().toString();
170 if (sfLocation
.equals(id
)) {
171 return getLocation().toString();
178 public void resetPropertyValue(Object id
) {
182 public void setPropertyValue(Object id
, Object value
) {
186 public boolean isPropertyResettable(Object id
) {
191 public boolean isPropertySet(Object id
) {