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 | *******************************************************************************/ | |
14 | package org.eclipse.linuxtools.lttng.ui.tracecontrol.model; | |
15 | ||
16 | import org.eclipse.core.runtime.IAdaptable; | |
17 | import org.eclipse.core.runtime.IProgressMonitor; | |
18 | import org.eclipse.jface.resource.ImageDescriptor; | |
19 | import org.eclipse.jface.viewers.IStructuredSelection; | |
6c13869b | 20 | import org.eclipse.linuxtools.lttng.core.tracecontrol.model.TargetResource; |
e8d771d5 | 21 | import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; |
e8d771d5 | 22 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages; |
1b70b6dc | 23 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.TraceControlConstants; |
e8d771d5 BH |
24 | import org.eclipse.rse.ui.SystemMenuManager; |
25 | import org.eclipse.rse.ui.view.AbstractSystemViewAdapter; | |
26 | import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter; | |
27 | import org.eclipse.swt.widgets.Shell; | |
28 | import org.eclipse.ui.views.properties.IPropertyDescriptor; | |
29 | ||
30 | /** | |
31 | * <b><u>TargetResourceAdapter</u></b> | |
32 | * <p> | |
33 | * This is the adapter which enables us to work with our remote target resources. | |
34 | * </p> | |
35 | */ | |
36 | public class TargetResourceAdapter extends AbstractSystemViewAdapter implements ISystemRemoteElementAdapter { | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
39 | // Attributes | |
40 | // ------------------------------------------------------------------------ | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Constructors | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
46 | /** | |
47 | * Constructor | |
48 | */ | |
49 | public TargetResourceAdapter() { | |
50 | super(); | |
51 | } | |
52 | ||
53 | // ------------------------------------------------------------------------ | |
54 | // Operations | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
57 | /* | |
58 | * (non-Javadoc) | |
59 | * @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) | |
60 | */ | |
61 | @Override | |
62 | public void addActions(SystemMenuManager menu, IStructuredSelection selection, Shell parent, String menuGroup) { | |
63 | } | |
64 | ||
65 | /* | |
66 | * (non-Javadoc) | |
67 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#getImageDescriptor(java.lang.Object) | |
68 | */ | |
69 | @Override | |
70 | public ImageDescriptor getImageDescriptor(Object object) { | |
71 | return LTTngUiPlugin.getDefault().getImageDescriptor(LTTngUiPlugin.ICON_ID_TARGET); | |
72 | } | |
73 | ||
74 | /* | |
75 | * (non-Javadoc) | |
76 | * @see org.eclipse.rse.ui.view.ISystemViewElementAdapter#getText(java.lang.Object) | |
77 | */ | |
78 | @Override | |
79 | public String getText(Object element) { | |
80 | return ((TargetResource) element).getName(); | |
81 | } | |
82 | ||
83 | /* | |
84 | * (non-Javadoc) | |
85 | * @see org.eclipse.rse.core.subsystems.IRemoteObjectIdentifier#getAbsoluteName(java.lang.Object) | |
86 | */ | |
87 | @Override | |
88 | public String getAbsoluteName(Object object) { | |
89 | TargetResource tar = (TargetResource) object; | |
90 | return tar.getName(); | |
91 | } | |
92 | ||
93 | /* | |
94 | * (non-Javadoc) | |
95 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#getType(java.lang.Object) | |
96 | */ | |
97 | @Override | |
98 | public String getType(Object element) { | |
99 | return Messages.Lttng_Resource_Target; | |
100 | } | |
101 | ||
102 | /* | |
103 | * (non-Javadoc) | |
104 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#getParent(java.lang.Object) | |
105 | */ | |
106 | @Override | |
107 | public Object getParent(Object object) { | |
108 | return ((TargetResource) object).getParent(); // not really used, which is good because it is ambiguous | |
109 | } | |
110 | ||
111 | /* | |
112 | * (non-Javadoc) | |
113 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#getChildren(org.eclipse.core.runtime.IAdaptable, org.eclipse.core.runtime.IProgressMonitor) | |
114 | */ | |
115 | @Override | |
116 | public Object[] getChildren(IAdaptable element, IProgressMonitor monitor) { | |
117 | return ((TargetResource) element).getTraces(); | |
118 | } | |
119 | ||
120 | /* | |
121 | * (non-Javadoc) | |
122 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#internalGetPropertyDescriptors() | |
123 | */ | |
124 | @Override | |
125 | protected IPropertyDescriptor[] internalGetPropertyDescriptors() { | |
126 | return null; | |
127 | } | |
128 | ||
129 | /* | |
130 | * (non-Javadoc) | |
131 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#internalGetPropertyValue(java.lang.Object) | |
132 | */ | |
133 | @Override | |
134 | protected Object internalGetPropertyValue(Object key) { | |
135 | return null; | |
136 | } | |
137 | ||
138 | // -------------------------------------- | |
139 | // ISystemRemoteElementAdapter methods... | |
140 | // -------------------------------------- | |
141 | ||
142 | /* | |
143 | * (non-Javadoc) | |
144 | * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#getAbsoluteParentName(java.lang.Object) | |
145 | */ | |
146 | @Override | |
147 | public String getAbsoluteParentName(Object element) { | |
148 | return Messages.Lttng_Resource_Root; // not really applicable as we have no unique hierarchy | |
149 | } | |
150 | ||
151 | /* | |
152 | * (non-Javadoc) | |
153 | * @see org.eclipse.rse.core.subsystems.ISystemRemoteObjectMatchProvider#getSubSystemConfigurationId(java.lang.Object) | |
154 | */ | |
155 | @Override | |
156 | public String getSubSystemConfigurationId(Object element) { | |
157 | return "org.eclipse.linuxtools.lttng.ui.tracecontrol.subsystems.factory"; // as declared in extension in plugin.xml //$NON-NLS-1$ | |
158 | } | |
159 | ||
160 | /* | |
161 | * (non-Javadoc) | |
162 | * @see org.eclipse.rse.core.subsystems.ISystemRemoteObjectMatchProvider#getRemoteTypeCategory(java.lang.Object) | |
163 | */ | |
164 | @Override | |
165 | public String getRemoteTypeCategory(Object element) { | |
166 | return TraceControlConstants.Rse_Target_Resource_Remote_Type_Category; // Course grained. Same for all our remote resources. | |
167 | } | |
168 | ||
169 | /* | |
170 | * (non-Javadoc) | |
171 | * @see org.eclipse.rse.core.subsystems.ISystemRemoteObjectMatchProvider#getRemoteType(java.lang.Object) | |
172 | */ | |
173 | @Override | |
174 | public String getRemoteType(Object element) { | |
175 | return TraceControlConstants.Rse_Target_Resource_Remote_Type; // Fine grained. Unique to this resource type. | |
176 | } | |
177 | ||
178 | /* | |
179 | * (non-Javadoc) | |
180 | * @see org.eclipse.rse.core.subsystems.ISystemRemoteObjectMatchProvider#getRemoteSubType(java.lang.Object) | |
181 | */ | |
182 | @Override | |
183 | public String getRemoteSubType(Object element) { | |
184 | return null; // Very fine grained. We don't use it. | |
185 | } | |
186 | ||
187 | /* | |
188 | * (non-Javadoc) | |
189 | * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#refreshRemoteObject(java.lang.Object, java.lang.Object) | |
190 | */ | |
191 | @Override | |
192 | public boolean refreshRemoteObject(Object oldElement, Object newElement) { | |
193 | TargetResource oldDevr = (TargetResource) oldElement; | |
194 | TargetResource newDevr = (TargetResource) newElement; | |
195 | newDevr.setName(oldDevr.getName()); | |
196 | return true; | |
197 | } | |
198 | ||
199 | public boolean supportsUserDefinedActions(Object object) { | |
200 | return true; | |
201 | } | |
202 | ||
203 | /* | |
204 | * (non-Javadoc) | |
205 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#hasChildren(org.eclipse.core.runtime.IAdaptable) | |
206 | */ | |
207 | @Override | |
208 | public boolean hasChildren(IAdaptable element) { | |
209 | return ((((TargetResource) element).getTraces() != null) && (((TargetResource) element).getTraces().length > 0)); | |
210 | } | |
211 | ||
212 | /* | |
213 | * (non-Javadoc) | |
214 | * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#getRemoteParent(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor) | |
215 | */ | |
216 | @Override | |
217 | public Object getRemoteParent(Object element, IProgressMonitor monitor) throws Exception { | |
218 | return null; | |
219 | } | |
220 | ||
221 | /* | |
222 | * (non-Javadoc) | |
223 | * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#getRemoteParentNamesInUse(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor) | |
224 | */ | |
225 | @Override | |
226 | public String[] getRemoteParentNamesInUse(Object element, IProgressMonitor monitor) throws Exception { | |
227 | return null; | |
228 | } | |
229 | ||
230 | /* | |
231 | * (non-Javadoc) | |
232 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showDelete(java.lang.Object) | |
233 | */ | |
234 | @Override | |
235 | public boolean showDelete(Object element) { | |
236 | return false; | |
237 | } | |
238 | ||
239 | /* | |
240 | * (non-Javadoc) | |
241 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showRefresh(java.lang.Object) | |
242 | */ | |
243 | @Override | |
244 | public boolean showRefresh(Object element) { | |
245 | return false; | |
246 | } | |
247 | ||
248 | /* | |
249 | * (non-Javadoc) | |
250 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showRename(java.lang.Object) | |
251 | */ | |
252 | @Override | |
253 | public boolean showRename(Object element) { | |
254 | return false; | |
255 | } | |
256 | ||
257 | /* | |
258 | * (non-Javadoc) | |
259 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#saveExpansionState(java.lang.Object) | |
260 | */ | |
261 | @Override | |
262 | public boolean saveExpansionState(Object element) { | |
263 | return true; | |
264 | } | |
265 | ||
266 | /* | |
267 | * (non-Javadoc) | |
268 | * @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#testAttribute(java.lang.Object, java.lang.String, java.lang.String) | |
269 | */ | |
270 | @Override | |
271 | public boolean testAttribute(Object target, String name, String value) { | |
272 | ||
273 | if (target instanceof TargetResource) { | |
274 | if ((name.compareTo("canCreateNewTrace") == 0) && (((TargetResource)target).getCanCreateNewTrace().compareTo(value) == 0)) { //$NON-NLS-1$ | |
275 | return true; | |
276 | } | |
277 | } | |
278 | ||
279 | return super.testAttribute(target, name, value); | |
280 | } | |
281 | } |