Remove all existing @since annotations
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / project / model / TmfExperimentFolder.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 * Patrick Tasse - Add support for folder elements
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.ui.project.model;
15
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
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;
28
29 /**
30 * Implementation of model element representing the unique "Experiments" folder
31 * in the project.
32 * <p>
33 *
34 * @version 1.0
35 * @author Francois Chouinard
36 *
37 */
38 public class TmfExperimentFolder extends TmfProjectModelElement implements IPropertySource2 {
39
40 // ------------------------------------------------------------------------
41 // Constants
42 // ------------------------------------------------------------------------
43
44 /**
45 * The name of the experiment folder.
46 */
47 public static final String EXPER_FOLDER_NAME = "Experiments"; //$NON-NLS-1$
48
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$
54
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);
58
59 private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor };
60
61 static {
62 sfNameDescriptor.setCategory(sfInfoCategory);
63 sfPathDescriptor.setCategory(sfInfoCategory);
64 sfLocationDescriptor.setCategory(sfInfoCategory);
65 }
66
67 // ------------------------------------------------------------------------
68 // Constructors
69 // ------------------------------------------------------------------------
70
71 /**
72 * Constructor.
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)
77 */
78 public TmfExperimentFolder(String name, IFolder folder, TmfProjectElement parent) {
79 super(name, folder, parent);
80 parent.addChild(this);
81 }
82
83 // ------------------------------------------------------------------------
84 // TmfProjectModelElement
85 // ------------------------------------------------------------------------
86
87 @Override
88 public IFolder getResource() {
89 return (IFolder) fResource;
90 }
91
92 @Override
93 void refreshChildren() {
94 IFolder folder = getResource();
95
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);
100 }
101
102 try {
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);
111 } else {
112 element = new TmfExperimentElement(name, expFolder, this);
113 }
114 ((TmfExperimentElement) element).refreshChildren();
115 }
116 }
117 } catch (CoreException e) {
118 }
119
120 // Cleanup dangling children from the model
121 for (ITmfProjectModelElement danglingChild : childrenMap.values()) {
122 removeChild(danglingChild);
123 }
124 }
125
126 // ------------------------------------------------------------------------
127 // Operations
128 // ------------------------------------------------------------------------
129
130 /**
131 * Returns a list of experiment model elements under the experiments folder.
132 * @return list of experiment model elements
133 */
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);
140 }
141 }
142 return traces;
143 }
144
145 // ------------------------------------------------------------------------
146 // IPropertySource2
147 // ------------------------------------------------------------------------
148
149 @Override
150 public Object getEditableValue() {
151 return null;
152 }
153
154 @Override
155 public IPropertyDescriptor[] getPropertyDescriptors() {
156 return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
157 }
158
159 @Override
160 public Object getPropertyValue(Object id) {
161
162 if (sfName.equals(id)) {
163 return getName();
164 }
165
166 if (sfPath.equals(id)) {
167 return getPath().toString();
168 }
169
170 if (sfLocation.equals(id)) {
171 return getLocation().toString();
172 }
173
174 return null;
175 }
176
177 @Override
178 public void resetPropertyValue(Object id) {
179 }
180
181 @Override
182 public void setPropertyValue(Object id, Object value) {
183 }
184
185 @Override
186 public boolean isPropertyResettable(Object id) {
187 return false;
188 }
189
190 @Override
191 public boolean isPropertySet(Object id) {
192 return false;
193 }
194
195 }
This page took 0.034085 seconds and 5 git commands to generate.