tmf/lttng: Update 2014 copyrights
[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
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.ui.project.model;
14
a6e37e4c 15import java.util.ArrayList;
5a5c2fc7 16import java.util.Arrays;
f537c959 17import java.util.HashMap;
a6e37e4c 18import java.util.List;
f537c959 19import java.util.Map;
5a5c2fc7 20
12c155f5 21import org.eclipse.core.resources.IFolder;
f537c959
PT
22import org.eclipse.core.resources.IResource;
23import org.eclipse.core.runtime.CoreException;
080600d9 24import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
12c155f5
FC
25import org.eclipse.ui.views.properties.IPropertyDescriptor;
26import org.eclipse.ui.views.properties.IPropertySource2;
12c155f5
FC
27
28/**
b544077e 29 * Implementation of the model element for the experiment folder.
12c155f5 30 * <p>
b544077e
BH
31 * @version 1.0
32 * @author Francois Chouinard
9a47bdf1 33 *
12c155f5
FC
34 */
35public class TmfExperimentFolder extends TmfProjectModelElement implements IPropertySource2 {
36
37 // ------------------------------------------------------------------------
38 // Constants
39 // ------------------------------------------------------------------------
11252342 40
b544077e
BH
41 /**
42 * The name of the experiment folder.
43 */
12c155f5
FC
44 public static final String EXPER_FOLDER_NAME = "Experiments"; //$NON-NLS-1$
45
46 // Property View stuff
47 private static final String sfInfoCategory = "Info"; //$NON-NLS-1$
48 private static final String sfName = "name"; //$NON-NLS-1$
49 private static final String sfPath = "path"; //$NON-NLS-1$
50 private static final String sfLocation = "location"; //$NON-NLS-1$
51
253d5be1
BH
52 private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor = new ReadOnlyTextPropertyDescriptor(sfName, sfName);
53 private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor = new ReadOnlyTextPropertyDescriptor(sfPath, sfPath);
54 private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfLocation, sfLocation);
12c155f5
FC
55
56 private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor };
57
58 static {
59 sfNameDescriptor.setCategory(sfInfoCategory);
60 sfPathDescriptor.setCategory(sfInfoCategory);
61 sfLocationDescriptor.setCategory(sfInfoCategory);
62 }
63
64 // ------------------------------------------------------------------------
65 // Constructors
66 // ------------------------------------------------------------------------
67
b544077e 68 /**
9a47bdf1 69 * Constructor.
b544077e
BH
70 * Creates a TmfExperimentFolder model element.
71 * @param name The name of the folder
72 * @param folder The folder reference
73 * @param parent The parent (project element)
74 */
12c155f5
FC
75 public TmfExperimentFolder(String name, IFolder folder, TmfProjectElement parent) {
76 super(name, folder, parent);
77 parent.addChild(this);
78 }
79
80 // ------------------------------------------------------------------------
81 // TmfProjectModelElement
82 // ------------------------------------------------------------------------
11252342 83
12c155f5
FC
84 @Override
85 public IFolder getResource() {
86 return (IFolder) fResource;
87 }
9a47bdf1 88
12c155f5
FC
89 @Override
90 public TmfProjectElement getProject() {
91 return (TmfProjectElement) getParent();
92 }
9a47bdf1 93
12c155f5 94 @Override
f537c959
PT
95 void refreshChildren() {
96 IFolder folder = getResource();
97
98 // Get the children from the model
99 Map<String, ITmfProjectModelElement> childrenMap = new HashMap<>();
100 for (ITmfProjectModelElement element : getChildren()) {
101 childrenMap.put(element.getResource().getName(), element);
102 }
103
104 try {
105 IResource[] members = folder.members();
106 for (IResource resource : members) {
107 if (resource instanceof IFolder) {
108 IFolder expFolder = (IFolder) resource;
109 String name = resource.getName();
110 ITmfProjectModelElement element = childrenMap.get(name);
111 if (element instanceof TmfExperimentElement) {
112 childrenMap.remove(name);
113 } else {
114 element = new TmfExperimentElement(name, expFolder, this);
115 }
116 ((TmfExperimentElement) element).refreshChildren();
117 }
118 }
119 } catch (CoreException e) {
120 }
121
122 // Cleanup dangling children from the model
123 for (ITmfProjectModelElement danglingChild : childrenMap.values()) {
124 removeChild(danglingChild);
125 }
12c155f5
FC
126 }
127
b544077e 128 // ------------------------------------------------------------------------
a6e37e4c
PT
129 // Operations
130 // ------------------------------------------------------------------------
131
132 /**
133 * Returns a list of experiment model elements under the experiments folder.
134 * @return list of experiment model elements
135 * @since 3.0
136 */
137 public List<TmfExperimentElement> getExperiments() {
138 List<ITmfProjectModelElement> children = getChildren();
139 List<TmfExperimentElement> traces = new ArrayList<>();
140 for (ITmfProjectModelElement child : children) {
141 if (child instanceof TmfExperimentElement) {
142 traces.add((TmfExperimentElement) child);
143 }
144 }
145 return traces;
146 }
147
148 // ------------------------------------------------------------------------
be222f56
PT
149 // IPropertySource2
150 // ------------------------------------------------------------------------
11252342 151
be222f56
PT
152 @Override
153 public Object getEditableValue() {
154 return null;
155 }
11252342 156
be222f56
PT
157 @Override
158 public IPropertyDescriptor[] getPropertyDescriptors() {
77fdc5df 159 return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
be222f56 160 }
9a47bdf1 161
be222f56
PT
162 @Override
163 public Object getPropertyValue(Object id) {
164
9a47bdf1 165 if (sfName.equals(id)) {
be222f56 166 return getName();
9a47bdf1 167 }
be222f56 168
9a47bdf1 169 if (sfPath.equals(id)) {
be222f56 170 return getPath().toString();
9a47bdf1 171 }
be222f56 172
9a47bdf1 173 if (sfLocation.equals(id)) {
be222f56 174 return getLocation().toString();
9a47bdf1 175 }
be222f56
PT
176
177 return null;
178 }
11252342 179
be222f56
PT
180 @Override
181 public void resetPropertyValue(Object id) {
182 }
11252342 183
be222f56
PT
184 @Override
185 public void setPropertyValue(Object id, Object value) {
186 }
11252342 187
be222f56
PT
188 @Override
189 public boolean isPropertyResettable(Object id) {
190 return false;
191 }
11252342 192
be222f56
PT
193 @Override
194 public boolean isPropertySet(Object id) {
195 return false;
196 }
197
198}
This page took 0.055341 seconds and 5 git commands to generate.