Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
b544077e | 2 | * Copyright (c) 2011, 2012 Ericsson |
013a5f1c | 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 | |
013a5f1c | 8 | * |
12c155f5 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
14 | ||
15 | import java.util.ArrayList; | |
5a5c2fc7 | 16 | import java.util.Arrays; |
12c155f5 FC |
17 | import java.util.List; |
18 | ||
19 | import org.eclipse.core.resources.IFolder; | |
20 | import org.eclipse.ui.views.properties.IPropertyDescriptor; | |
21 | import org.eclipse.ui.views.properties.IPropertySource2; | |
22 | import org.eclipse.ui.views.properties.TextPropertyDescriptor; | |
23 | ||
24 | /** | |
b544077e | 25 | * Implementation of trace folder model element representing the trace folder in the project. |
12c155f5 | 26 | * <p> |
b544077e BH |
27 | * @version 1.0 |
28 | * @author Francois Chouinard | |
12c155f5 FC |
29 | */ |
30 | public class TmfTraceFolder extends TmfProjectModelElement implements IPropertySource2 { | |
31 | ||
32 | // ------------------------------------------------------------------------ | |
33 | // Constants | |
34 | // ------------------------------------------------------------------------ | |
b544077e | 35 | /** |
013a5f1c | 36 | * The name of the trace folder |
b544077e | 37 | */ |
12c155f5 FC |
38 | public static final String TRACE_FOLDER_NAME = "Traces"; //$NON-NLS-1$ |
39 | ||
40 | // Property View stuff | |
41 | private static final String sfInfoCategory = "Info"; //$NON-NLS-1$ | |
42 | private static final String sfName = "name"; //$NON-NLS-1$ | |
43 | private static final String sfPath = "path"; //$NON-NLS-1$ | |
44 | private static final String sfLocation = "location"; //$NON-NLS-1$ | |
45 | ||
46 | private static final TextPropertyDescriptor sfNameDescriptor = new TextPropertyDescriptor(sfName, sfName); | |
47 | private static final TextPropertyDescriptor sfPathDescriptor = new TextPropertyDescriptor(sfPath, sfPath); | |
48 | private static final TextPropertyDescriptor sfLocationDescriptor = new TextPropertyDescriptor(sfLocation, | |
49 | sfLocation); | |
50 | ||
51 | private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, | |
52 | sfLocationDescriptor }; | |
53 | ||
54 | static { | |
55 | sfNameDescriptor.setCategory(sfInfoCategory); | |
56 | sfPathDescriptor.setCategory(sfInfoCategory); | |
57 | sfLocationDescriptor.setCategory(sfInfoCategory); | |
58 | } | |
59 | ||
60 | // ------------------------------------------------------------------------ | |
61 | // Constructor | |
62 | // ------------------------------------------------------------------------ | |
b544077e | 63 | /** |
013a5f1c | 64 | * Constructor. |
b544077e BH |
65 | * Creates trace folder model element under the project. |
66 | * @param name The name of trace folder. | |
013a5f1c | 67 | * @param resource The folder resource. |
b544077e BH |
68 | * @param parent The parent element (project). |
69 | */ | |
12c155f5 FC |
70 | public TmfTraceFolder(String name, IFolder resource, TmfProjectElement parent) { |
71 | super(name, resource, parent); | |
72 | parent.addChild(this); | |
73 | } | |
74 | ||
75 | // ------------------------------------------------------------------------ | |
76 | // TmfProjectModelElement | |
77 | // ------------------------------------------------------------------------ | |
013a5f1c | 78 | |
b544077e BH |
79 | /* |
80 | * (non-Javadoc) | |
81 | * @see org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectModelElement#getResource() | |
82 | */ | |
12c155f5 FC |
83 | @Override |
84 | public IFolder getResource() { | |
85 | return (IFolder) fResource; | |
86 | } | |
87 | ||
b544077e BH |
88 | /* |
89 | * (non-Javadoc) | |
90 | * @see org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement#getProject() | |
91 | */ | |
12c155f5 FC |
92 | @Override |
93 | public TmfProjectElement getProject() { | |
94 | return (TmfProjectElement) getParent(); | |
95 | } | |
96 | ||
b544077e BH |
97 | /* |
98 | * (non-Javadoc) | |
99 | * @see org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectModelElement#refresh() | |
100 | */ | |
12c155f5 FC |
101 | @Override |
102 | public void refresh() { | |
103 | TmfProjectElement project = (TmfProjectElement) getParent(); | |
104 | project.refresh(); | |
105 | } | |
106 | ||
107 | // ------------------------------------------------------------------------ | |
108 | // Operations | |
109 | // ------------------------------------------------------------------------ | |
b544077e BH |
110 | /** |
111 | * Returns a list of trace model elements under the traces folder. | |
112 | * @return list of trace model elements | |
113 | */ | |
12c155f5 FC |
114 | public List<TmfTraceElement> getTraces() { |
115 | List<ITmfProjectModelElement> children = getChildren(); | |
116 | List<TmfTraceElement> traces = new ArrayList<TmfTraceElement>(); | |
117 | for (ITmfProjectModelElement child : children) { | |
118 | if (child instanceof TmfTraceElement) { | |
119 | traces.add((TmfTraceElement) child); | |
120 | } | |
121 | } | |
122 | return traces; | |
123 | } | |
124 | ||
125 | // ------------------------------------------------------------------------ | |
126 | // IPropertySource2 | |
127 | // ------------------------------------------------------------------------ | |
128 | ||
b544077e BH |
129 | /* |
130 | * (non-Javadoc) | |
131 | * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue() | |
132 | */ | |
12c155f5 FC |
133 | @Override |
134 | public Object getEditableValue() { | |
135 | return null; | |
136 | } | |
137 | ||
b544077e BH |
138 | /* |
139 | * (non-Javadoc) | |
140 | * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() | |
141 | */ | |
12c155f5 FC |
142 | @Override |
143 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
5a5c2fc7 | 144 | return (sfDescriptors != null) ? Arrays.copyOf(sfDescriptors, sfDescriptors.length) : null; |
12c155f5 FC |
145 | } |
146 | ||
b544077e BH |
147 | /* |
148 | * (non-Javadoc) | |
149 | * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) | |
150 | */ | |
12c155f5 FC |
151 | @Override |
152 | public Object getPropertyValue(Object id) { | |
153 | ||
013a5f1c | 154 | if (sfName.equals(id)) { |
12c155f5 | 155 | return getName(); |
013a5f1c | 156 | } |
12c155f5 | 157 | |
013a5f1c | 158 | if (sfPath.equals(id)) { |
12c155f5 | 159 | return getPath().toString(); |
013a5f1c | 160 | } |
12c155f5 | 161 | |
013a5f1c | 162 | if (sfLocation.equals(id)) { |
12c155f5 | 163 | return getLocation().toString(); |
013a5f1c | 164 | } |
12c155f5 FC |
165 | |
166 | return null; | |
167 | } | |
168 | ||
b544077e BH |
169 | /* |
170 | * (non-Javadoc) | |
171 | * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object) | |
172 | */ | |
12c155f5 FC |
173 | @Override |
174 | public void resetPropertyValue(Object id) { | |
175 | } | |
176 | ||
b544077e BH |
177 | /* |
178 | * (non-Javadoc) | |
179 | * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object) | |
180 | */ | |
12c155f5 FC |
181 | @Override |
182 | public void setPropertyValue(Object id, Object value) { | |
183 | } | |
184 | ||
b544077e BH |
185 | /* |
186 | * (non-Javadoc) | |
187 | * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertyResettable(java.lang.Object) | |
188 | */ | |
12c155f5 FC |
189 | @Override |
190 | public boolean isPropertyResettable(Object id) { | |
191 | return false; | |
192 | } | |
193 | ||
b544077e BH |
194 | /* |
195 | * (non-Javadoc) | |
196 | * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertySet(java.lang.Object) | |
197 | */ | |
12c155f5 FC |
198 | @Override |
199 | public boolean isPropertySet(Object id) { | |
200 | return false; | |
201 | } | |
202 | ||
203 | } |