ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TmfExperimentFolder.java
CommitLineData
12c155f5 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2010, 2014 Ericsson
9a47bdf1 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
9a47bdf1 8 *
12c155f5
FC
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
339d539c 11 * Patrick Tasse - Add support for folder elements
12c155f5
FC
12 *******************************************************************************/
13
14package org.eclipse.linuxtools.tmf.ui.project.model;
15
a6e37e4c 16import java.util.ArrayList;
5a5c2fc7 17import java.util.Arrays;
f537c959 18import java.util.HashMap;
a6e37e4c 19import java.util.List;
f537c959 20import java.util.Map;
5a5c2fc7 21
12c155f5 22import org.eclipse.core.resources.IFolder;
f537c959
PT
23import org.eclipse.core.resources.IResource;
24import org.eclipse.core.runtime.CoreException;
080600d9 25import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
12c155f5
FC
26import org.eclipse.ui.views.properties.IPropertyDescriptor;
27import org.eclipse.ui.views.properties.IPropertySource2;
12c155f5
FC
28
29/**
339d539c
PT
30 * Implementation of model element representing the unique "Experiments" folder
31 * in the project.
12c155f5 32 * <p>
339d539c 33 *
b544077e
BH
34 * @version 1.0
35 * @author Francois Chouinard
9a47bdf1 36 *
12c155f5
FC
37 */
38public class TmfExperimentFolder extends TmfProjectModelElement implements IPropertySource2 {
39
40 // ------------------------------------------------------------------------
41 // Constants
42 // ------------------------------------------------------------------------
11252342 43
b544077e
BH
44 /**
45 * The name of the experiment folder.
46 */
12c155f5
FC
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
253d5be1
BH
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);
12c155f5
FC
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
b544077e 71 /**
9a47bdf1 72 * Constructor.
b544077e
BH
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 */
12c155f5
FC
78 public TmfExperimentFolder(String name, IFolder folder, TmfProjectElement parent) {
79 super(name, folder, parent);
80 parent.addChild(this);
81 }
82
83 // ------------------------------------------------------------------------
84 // TmfProjectModelElement
85 // ------------------------------------------------------------------------
11252342 86
12c155f5
FC
87 @Override
88 public IFolder getResource() {
89 return (IFolder) fResource;
90 }
9a47bdf1 91
12c155f5 92 @Override
f537c959
PT
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 }
12c155f5
FC
124 }
125
b544077e 126 // ------------------------------------------------------------------------
a6e37e4c
PT
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 * @since 3.0
134 */
135 public List<TmfExperimentElement> getExperiments() {
136 List<ITmfProjectModelElement> children = getChildren();
137 List<TmfExperimentElement> traces = new ArrayList<>();
138 for (ITmfProjectModelElement child : children) {
139 if (child instanceof TmfExperimentElement) {
140 traces.add((TmfExperimentElement) child);
141 }
142 }
143 return traces;
144 }
145
146 // ------------------------------------------------------------------------
be222f56
PT
147 // IPropertySource2
148 // ------------------------------------------------------------------------
11252342 149
be222f56
PT
150 @Override
151 public Object getEditableValue() {
152 return null;
153 }
11252342 154
be222f56
PT
155 @Override
156 public IPropertyDescriptor[] getPropertyDescriptors() {
77fdc5df 157 return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
be222f56 158 }
9a47bdf1 159
be222f56
PT
160 @Override
161 public Object getPropertyValue(Object id) {
162
9a47bdf1 163 if (sfName.equals(id)) {
be222f56 164 return getName();
9a47bdf1 165 }
be222f56 166
9a47bdf1 167 if (sfPath.equals(id)) {
be222f56 168 return getPath().toString();
9a47bdf1 169 }
be222f56 170
9a47bdf1 171 if (sfLocation.equals(id)) {
be222f56 172 return getLocation().toString();
9a47bdf1 173 }
be222f56
PT
174
175 return null;
176 }
11252342 177
be222f56
PT
178 @Override
179 public void resetPropertyValue(Object id) {
180 }
11252342 181
be222f56
PT
182 @Override
183 public void setPropertyValue(Object id, Object value) {
184 }
11252342 185
be222f56
PT
186 @Override
187 public boolean isPropertyResettable(Object id) {
188 return false;
189 }
11252342 190
be222f56
PT
191 @Override
192 public boolean isPropertySet(Object id) {
193 return false;
194 }
195
196}
This page took 0.062648 seconds and 5 git commands to generate.