Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2010, 2013 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 | ||
13 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
14 | ||
5a5c2fc7 | 15 | import java.util.Arrays; |
f537c959 PT |
16 | import java.util.HashMap; |
17 | import java.util.Map; | |
5a5c2fc7 | 18 | |
12c155f5 | 19 | import org.eclipse.core.resources.IFolder; |
f537c959 PT |
20 | import org.eclipse.core.resources.IResource; |
21 | import org.eclipse.core.runtime.CoreException; | |
080600d9 | 22 | import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor; |
12c155f5 FC |
23 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
24 | import org.eclipse.ui.views.properties.IPropertySource2; | |
12c155f5 FC |
25 | |
26 | /** | |
b544077e | 27 | * Implementation of the model element for the experiment folder. |
12c155f5 | 28 | * <p> |
b544077e BH |
29 | * @version 1.0 |
30 | * @author Francois Chouinard | |
9a47bdf1 | 31 | * |
12c155f5 FC |
32 | */ |
33 | public class TmfExperimentFolder extends TmfProjectModelElement implements IPropertySource2 { | |
34 | ||
35 | // ------------------------------------------------------------------------ | |
36 | // Constants | |
37 | // ------------------------------------------------------------------------ | |
11252342 | 38 | |
b544077e BH |
39 | /** |
40 | * The name of the experiment folder. | |
41 | */ | |
12c155f5 FC |
42 | public static final String EXPER_FOLDER_NAME = "Experiments"; //$NON-NLS-1$ |
43 | ||
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 | ||
253d5be1 BH |
50 | private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor = new ReadOnlyTextPropertyDescriptor(sfName, sfName); |
51 | private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor = new ReadOnlyTextPropertyDescriptor(sfPath, sfPath); | |
52 | private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfLocation, sfLocation); | |
12c155f5 FC |
53 | |
54 | private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor }; | |
55 | ||
56 | static { | |
57 | sfNameDescriptor.setCategory(sfInfoCategory); | |
58 | sfPathDescriptor.setCategory(sfInfoCategory); | |
59 | sfLocationDescriptor.setCategory(sfInfoCategory); | |
60 | } | |
61 | ||
62 | // ------------------------------------------------------------------------ | |
63 | // Constructors | |
64 | // ------------------------------------------------------------------------ | |
65 | ||
b544077e | 66 | /** |
9a47bdf1 | 67 | * Constructor. |
b544077e BH |
68 | * Creates a TmfExperimentFolder model element. |
69 | * @param name The name of the folder | |
70 | * @param folder The folder reference | |
71 | * @param parent The parent (project element) | |
72 | */ | |
12c155f5 FC |
73 | public TmfExperimentFolder(String name, IFolder folder, TmfProjectElement parent) { |
74 | super(name, folder, parent); | |
75 | parent.addChild(this); | |
76 | } | |
77 | ||
78 | // ------------------------------------------------------------------------ | |
79 | // TmfProjectModelElement | |
80 | // ------------------------------------------------------------------------ | |
11252342 | 81 | |
12c155f5 FC |
82 | @Override |
83 | public IFolder getResource() { | |
84 | return (IFolder) fResource; | |
85 | } | |
9a47bdf1 | 86 | |
12c155f5 FC |
87 | @Override |
88 | public TmfProjectElement getProject() { | |
89 | return (TmfProjectElement) getParent(); | |
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 | // ------------------------------------------------------------------------ |
be222f56 PT |
127 | // IPropertySource2 |
128 | // ------------------------------------------------------------------------ | |
11252342 | 129 | |
be222f56 PT |
130 | @Override |
131 | public Object getEditableValue() { | |
132 | return null; | |
133 | } | |
11252342 | 134 | |
be222f56 PT |
135 | @Override |
136 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
77fdc5df | 137 | return Arrays.copyOf(sfDescriptors, sfDescriptors.length); |
be222f56 | 138 | } |
9a47bdf1 | 139 | |
be222f56 PT |
140 | @Override |
141 | public Object getPropertyValue(Object id) { | |
142 | ||
9a47bdf1 | 143 | if (sfName.equals(id)) { |
be222f56 | 144 | return getName(); |
9a47bdf1 | 145 | } |
be222f56 | 146 | |
9a47bdf1 | 147 | if (sfPath.equals(id)) { |
be222f56 | 148 | return getPath().toString(); |
9a47bdf1 | 149 | } |
be222f56 | 150 | |
9a47bdf1 | 151 | if (sfLocation.equals(id)) { |
be222f56 | 152 | return getLocation().toString(); |
9a47bdf1 | 153 | } |
be222f56 PT |
154 | |
155 | return null; | |
156 | } | |
11252342 | 157 | |
be222f56 PT |
158 | @Override |
159 | public void resetPropertyValue(Object id) { | |
160 | } | |
11252342 | 161 | |
be222f56 PT |
162 | @Override |
163 | public void setPropertyValue(Object id, Object value) { | |
164 | } | |
11252342 | 165 | |
be222f56 PT |
166 | @Override |
167 | public boolean isPropertyResettable(Object id) { | |
168 | return false; | |
169 | } | |
11252342 | 170 | |
be222f56 PT |
171 | @Override |
172 | public boolean isPropertySet(Object id) { | |
173 | return false; | |
174 | } | |
175 | ||
176 | } |