Commit | Line | Data |
---|---|---|
e8d771d5 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 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 | * Polytechnique Montréal - Initial API and implementation | |
11 | * Bernd Hufmann - Productification, enhancements and fixes | |
12 | * | |
13 | *******************************************************************************/ | |
638eac44 | 14 | package org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.model; |
e8d771d5 BH |
15 | |
16 | import java.util.Iterator; | |
17 | import java.util.Map; | |
18 | import java.util.Set; | |
19 | ||
20 | import org.eclipse.core.runtime.IAdaptable; | |
21 | import org.eclipse.core.runtime.IProgressMonitor; | |
22 | import org.eclipse.jface.resource.ImageDescriptor; | |
23 | import org.eclipse.jface.viewers.IStructuredSelection; | |
5945cec9 FC |
24 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource; |
25 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource.PropertyInfo; | |
26 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource.TraceState; | |
0977b009 | 27 | import org.eclipse.linuxtools.internal.lttng.ui.Activator; |
638eac44 FC |
28 | import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.Messages; |
29 | import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.TraceControlConstants; | |
e8d771d5 BH |
30 | import org.eclipse.rse.core.subsystems.ISubSystem; |
31 | import org.eclipse.rse.ui.SystemMenuManager; | |
32 | import org.eclipse.rse.ui.view.AbstractSystemViewAdapter; | |
33 | import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter; | |
34 | import org.eclipse.swt.widgets.Shell; | |
35 | import org.eclipse.ui.views.properties.IPropertyDescriptor; | |
36 | import org.eclipse.ui.views.properties.PropertyDescriptor; | |
37 | ||
38 | /** | |
39 | * <b><u>TargetResourceAdapter</u></b> | |
40 | * <p> | |
41 | * This is the adapter which enables us to work with our remote trace resources. | |
42 | * </p> | |
43 | */ | |
44 | public class TraceResourceAdapter extends AbstractSystemViewAdapter implements ISystemRemoteElementAdapter { | |
45 | ||
46 | // ------------------------------------------------------------------------ | |
47 | // Attributes | |
48 | // ------------------------------------------------------------------------ | |
49 | ||
50 | // ------------------------------------------------------------------------ | |
51 | // Constructors | |
52 | // ------------------------------------------------------------------------ | |
53 | ||
54 | /** | |
55 | * Constructor | |
56 | */ | |
57 | public TraceResourceAdapter() { | |
58 | super(); | |
59 | } | |
60 | ||
61 | // ------------------------------------------------------------------------ | |
62 | // Operations | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
65 | /* | |
66 | * (non-Javadoc) | |
67 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#addActions(org.eclipse.rse.ui.SystemMenuManager, org.eclipse.jface.viewers.IStructuredSelection, org.eclipse.swt.widgets.Shell, java.lang.String) | |
68 | */ | |
69 | @Override | |
70 | public void addActions(SystemMenuManager menu, IStructuredSelection selection, Shell parent, String menuGroup) { | |
71 | ||
72 | } | |
73 | ||
74 | /* | |
75 | * (non-Javadoc) | |
76 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#getImageDescriptor(java.lang.Object) | |
77 | */ | |
78 | @Override | |
79 | public ImageDescriptor getImageDescriptor(Object object) { | |
638eac44 | 80 | return Activator.getDefault().getImageDescriptor(Activator.ICON_ID_TRACE); |
e8d771d5 BH |
81 | } |
82 | ||
83 | /* | |
84 | * (non-Javadoc) | |
85 | * @see org.eclipse.rse.ui.view.ISystemViewElementAdapter#getText(java.lang.Object) | |
86 | */ | |
87 | @Override | |
88 | public String getText(Object element) { | |
89 | return ((TraceResource) element).getName(); | |
90 | } | |
91 | ||
92 | /* | |
93 | * (non-Javadoc) | |
94 | * @see org.eclipse.rse.core.subsystems.IRemoteObjectIdentifier#getAbsoluteName(java.lang.Object) | |
95 | */ | |
96 | @Override | |
97 | public String getAbsoluteName(Object object) { | |
98 | TraceResource tar = (TraceResource) object; | |
99 | return tar.getName(); | |
100 | } | |
101 | ||
102 | /* | |
103 | * (non-Javadoc) | |
104 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#getType(java.lang.Object) | |
105 | */ | |
106 | @Override | |
107 | public String getType(Object element) { | |
108 | return Messages.Lttng_Resource_Trace; | |
109 | } | |
110 | ||
111 | /* | |
112 | * (non-Javadoc) | |
113 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#getParent(java.lang.Object) | |
114 | */ | |
115 | @Override | |
116 | public Object getParent(Object object) { | |
117 | return ((TraceResource) object).getParent(); | |
118 | } | |
119 | ||
120 | /* | |
121 | * (non-Javadoc) | |
122 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#getChildren(org.eclipse.core.runtime.IAdaptable, org.eclipse.core.runtime.IProgressMonitor) | |
123 | */ | |
124 | @Override | |
125 | public Object[] getChildren(IAdaptable element, IProgressMonitor monitor) { | |
126 | return null; | |
127 | } | |
128 | ||
129 | /* | |
130 | * (non-Javadoc) | |
131 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#internalGetPropertyDescriptors() | |
132 | */ | |
133 | @Override | |
134 | protected IPropertyDescriptor[] internalGetPropertyDescriptors() { | |
135 | // propertySourceInput holds the currently selected object | |
136 | TraceResource trace = (TraceResource)propertySourceInput; | |
137 | ||
138 | Map<String, PropertyInfo> properties = trace.getPropertyInfo(); | |
139 | ||
140 | PropertyDescriptor[] propertyDescriptors = new PropertyDescriptor[properties.size()]; | |
141 | ||
142 | Set<String> keys = properties.keySet(); | |
143 | int i = 0; | |
144 | for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) { | |
145 | String key = iterator.next(); | |
146 | PropertyInfo info = properties.get(key); | |
147 | propertyDescriptors[i++] = createSimplePropertyDescriptor(key, info.getName(), info.getDescription()); | |
148 | } | |
149 | ||
150 | return propertyDescriptors; | |
151 | } | |
152 | ||
153 | /* | |
154 | * (non-Javadoc) | |
155 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#internalGetPropertyValue(java.lang.Object) | |
156 | */ | |
157 | @Override | |
158 | protected Object internalGetPropertyValue(Object key) { | |
159 | // propertySourceInput holds the currently selected object | |
160 | TraceResource trace = (TraceResource)propertySourceInput; | |
161 | return trace.getProperty((String)key); | |
162 | } | |
163 | ||
164 | /* | |
165 | * (non-Javadoc) | |
166 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showDelete(java.lang.Object) | |
167 | */ | |
168 | @Override | |
169 | public boolean showDelete(Object element) { | |
170 | return false; | |
171 | } | |
172 | ||
173 | /* | |
174 | * (non-Javadoc) | |
175 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showRefresh(java.lang.Object) | |
176 | */ | |
177 | @Override | |
178 | public boolean showRefresh(Object element) { | |
179 | return false; | |
180 | } | |
181 | ||
182 | /* | |
183 | * (non-Javadoc) | |
184 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showRename(java.lang.Object) | |
185 | */ | |
186 | @Override | |
187 | public boolean showRename(Object element) { | |
188 | return false; | |
189 | } | |
190 | ||
191 | /* | |
192 | * (non-Javadoc) | |
193 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#supportsDeferredQueries(org.eclipse.rse.core.subsystems.ISubSystem) | |
194 | */ | |
195 | @Override | |
196 | public boolean supportsDeferredQueries(ISubSystem subSys) { | |
197 | return false; | |
198 | } | |
199 | // -------------------------------------- | |
200 | // ISystemRemoteElementAdapter methods... | |
201 | // -------------------------------------- | |
202 | /* | |
203 | * (non-Javadoc) | |
204 | * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#getAbsoluteParentName(java.lang.Object) | |
205 | */ | |
206 | @Override | |
207 | public String getAbsoluteParentName(Object element) { | |
208 | return Messages.Lttng_Resource_Root; // not really applicable as we have no unique hierarchy | |
209 | } | |
210 | ||
211 | /* | |
212 | * (non-Javadoc) | |
213 | * @see org.eclipse.rse.core.subsystems.ISystemRemoteObjectMatchProvider#getSubSystemConfigurationId(java.lang.Object) | |
214 | */ | |
215 | @Override | |
216 | public String getSubSystemConfigurationId(Object element) { | |
217 | return "org.eclipse.linuxtools.lttng.rse.subsystems.factory"; // as declared in extension in plugin.xml //$NON-NLS-1$ | |
218 | } | |
219 | ||
220 | /* | |
221 | * (non-Javadoc) | |
222 | * @see org.eclipse.rse.core.subsystems.ISystemRemoteObjectMatchProvider#getRemoteTypeCategory(java.lang.Object) | |
223 | */ | |
224 | @Override | |
225 | public String getRemoteTypeCategory(Object element) { | |
226 | return TraceControlConstants.Rse_Trace_Resource_Remote_Type_Category; // Course grained. Same for all our remote resources. | |
227 | } | |
228 | ||
229 | /* | |
230 | * (non-Javadoc) | |
231 | * @see org.eclipse.rse.core.subsystems.ISystemRemoteObjectMatchProvider#getRemoteType(java.lang.Object) | |
232 | */ | |
233 | @Override | |
234 | public String getRemoteType(Object element) { | |
235 | return TraceControlConstants.Rse_Trace_Resource_Remote_Type; // Fine grained. Unique to this resource type. | |
236 | } | |
237 | ||
238 | /* | |
239 | * (non-Javadoc) | |
240 | * @see org.eclipse.rse.core.subsystems.ISystemRemoteObjectMatchProvider#getRemoteSubType(java.lang.Object) | |
241 | */ | |
242 | @Override | |
243 | public String getRemoteSubType(Object element) { | |
244 | return null; // Very fine grained. We don't use it. | |
245 | } | |
246 | ||
247 | /* | |
248 | * (non-Javadoc) | |
249 | * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#refreshRemoteObject(java.lang.Object, java.lang.Object) | |
250 | */ | |
251 | @Override | |
252 | public boolean refreshRemoteObject(Object oldElement, Object newElement) { | |
253 | TraceResource oldDevr = (TraceResource) oldElement; | |
254 | TraceResource newDevr = (TraceResource) newElement; | |
255 | newDevr.setName(oldDevr.getName()); | |
256 | return true; | |
257 | } | |
258 | ||
259 | /* | |
260 | * (non-Javadoc) | |
261 | * | |
262 | * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#supportsUserDefinedActions(java.lang.Object) | |
263 | */ | |
264 | public boolean supportsUserDefinedActions(Object object) { | |
265 | return true; | |
266 | } | |
267 | ||
268 | /* | |
269 | * (non-Javadoc) | |
270 | * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#getRemoteParent(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor) | |
271 | */ | |
272 | @Override | |
273 | public Object getRemoteParent(Object element, IProgressMonitor monitor) throws Exception { | |
274 | return null; // leave as null if this is the root | |
275 | } | |
276 | ||
277 | /* | |
278 | * (non-Javadoc) | |
279 | * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#getRemoteParentNamesInUse(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor) | |
280 | */ | |
281 | @Override | |
282 | public String[] getRemoteParentNamesInUse(Object element, IProgressMonitor monitor) throws Exception { | |
283 | return null; | |
284 | } | |
285 | ||
286 | /* | |
287 | * (non-Javadoc) | |
288 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#hasChildren(org.eclipse.core.runtime.IAdaptable) | |
289 | */ | |
290 | @Override | |
291 | public boolean hasChildren(IAdaptable arg0) { | |
292 | return false; | |
293 | } | |
294 | ||
295 | /* | |
296 | * (non-Javadoc) | |
297 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#testAttribute(java.lang.Object, java.lang.String, java.lang.String) | |
298 | */ | |
299 | @SuppressWarnings("nls") | |
300 | @Override | |
301 | public boolean testAttribute(Object target, String name, String value) { | |
302 | if(target instanceof TraceResource) { | |
303 | TraceResource trace = (TraceResource) target; | |
304 | if (name.equals("canConfigure") && value.equals("yes")) { | |
305 | if (trace.getTraceState() != TraceState.STOPPED) { | |
306 | return true; | |
307 | } | |
308 | } | |
309 | else if (name.equals("canStart") && value.equals("yes")) { | |
310 | if (trace.getTraceState() == TraceState.CONFIGURED|| trace.getTraceState() == TraceState.PAUSED) { | |
311 | return true; | |
312 | } | |
313 | } | |
314 | else if (name.equals("canPause") && value.equals("yes")) { | |
315 | if (trace.getTraceState() == TraceState.STARTED) { | |
316 | return true; | |
317 | } | |
318 | } | |
319 | else if (name.equals("canStop") && value.equals("yes")) { | |
320 | if (trace.getTraceState() == TraceState.CREATED || trace.getTraceState() == TraceState.PAUSED || trace.getTraceState() == TraceState.CONFIGURED) { | |
321 | return true; | |
322 | } | |
323 | } | |
324 | else if (name.equals("canBrowse") && value.equals("yes")) { | |
325 | if ((trace.getTraceConfig() != null) && trace.getTraceConfig().isNetworkTrace() && (trace.getTraceState() == TraceState.STOPPED)) { | |
326 | return true; | |
327 | } | |
328 | } | |
329 | else if (name.equals("canDelete") && value.equals("yes")) { | |
330 | if (trace.getTraceState() == TraceState.STOPPED) { | |
331 | return true; | |
332 | } | |
333 | } | |
334 | else if (name.equals("canImport") && value.equals("yes")) { | |
335 | if (trace.getTraceState() == TraceState.STOPPED) { | |
336 | return true; | |
a79913eb FC |
337 | } else if (trace.getTraceState() != TraceState.CREATED && trace.getTraceConfig().isNetworkTrace()) { |
338 | return true; | |
e8d771d5 BH |
339 | } |
340 | } | |
341 | } | |
342 | return super.testAttribute(target, name, value); | |
343 | } | |
344 | } |