Commit | Line | Data |
---|---|---|
ccc66d01 | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
ccc66d01 BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
ccc66d01 | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
ccc66d01 | 12 | **********************************************************************/ |
8e8c0226 | 13 | package org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs; |
ccc66d01 BH |
14 | |
15 | import java.util.List; | |
16 | ||
17 | import org.eclipse.jface.dialogs.Dialog; | |
18 | import org.eclipse.jface.dialogs.IDialogConstants; | |
8e8c0226 AM |
19 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType; |
20 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel; | |
21 | import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator; | |
22 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages; | |
23 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent; | |
24 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup; | |
ccc66d01 BH |
25 | import org.eclipse.swt.SWT; |
26 | import org.eclipse.swt.events.SelectionAdapter; | |
27 | import org.eclipse.swt.events.SelectionEvent; | |
28 | import org.eclipse.swt.graphics.Point; | |
29 | import org.eclipse.swt.layout.GridData; | |
30 | import org.eclipse.swt.layout.GridLayout; | |
31 | import org.eclipse.swt.widgets.Button; | |
32 | import org.eclipse.swt.widgets.Composite; | |
33 | import org.eclipse.swt.widgets.Control; | |
34 | import org.eclipse.swt.widgets.Group; | |
35 | import org.eclipse.swt.widgets.Shell; | |
36 | ||
37 | /** | |
ccc66d01 BH |
38 | * <p> |
39 | * Dialog box for collecting information events to be enabled. | |
40 | * </p> | |
cfdb727a | 41 | * |
dbd4432d | 42 | * @author Bernd Hufmann |
ccc66d01 BH |
43 | */ |
44 | public class EnableEventsDialog extends Dialog implements IEnableEventsDialog { | |
45 | ||
46 | // ------------------------------------------------------------------------ | |
47 | // Constants | |
48 | // ------------------------------------------------------------------------ | |
cfdb727a | 49 | |
ccc66d01 BH |
50 | /** |
51 | * The icon file for this dialog box. | |
52 | */ | |
cfdb727a | 53 | public static final String ENABLE_EVENT_ICON_FILE = "icons/elcl16/enable_event.gif"; //$NON-NLS-1$ |
ccc66d01 BH |
54 | |
55 | // ------------------------------------------------------------------------ | |
56 | // Attributes | |
57 | // ------------------------------------------------------------------------ | |
58 | /** | |
59 | * The dialog composite. | |
60 | */ | |
61 | private Composite fDialogComposite; | |
62 | /** | |
63 | * The composite with widgets for collecting information about kernel events. | |
64 | */ | |
65 | private EnableKernelEventComposite fKernelComposite; | |
66 | /** | |
cfdb727a | 67 | * The composite with widgets for collecting information about UST events. |
ccc66d01 BH |
68 | */ |
69 | private EnableUstEventsComposite fUstComposite; | |
70 | /** | |
71 | * Radio button for selecting kernel domain. | |
72 | */ | |
73 | private Button fKernelButton; | |
74 | /** | |
75 | * Radio button for selecting UST domain. | |
76 | */ | |
77 | private Button fUstButton; | |
78 | /** | |
cfdb727a | 79 | * The referenced trace provider group containing the kernel provider and UST |
ccc66d01 BH |
80 | * provider component which contains a list of available tracepoints. |
81 | */ | |
82 | private TraceProviderGroup fProviderGroup; | |
83 | /** | |
cfdb727a | 84 | * The parent domain component where the channel node should be added. |
ccc66d01 BH |
85 | * Null in case the domain is not known (i.e. on session level). |
86 | */ | |
87 | private TraceDomainComponent fDomain; | |
88 | /** | |
cfdb727a | 89 | * Output domain information. True in case of Kernel domain. False for UST. |
ccc66d01 BH |
90 | */ |
91 | private boolean fIsKernel; | |
92 | ||
93 | // ------------------------------------------------------------------------ | |
94 | // Constructors | |
95 | // ------------------------------------------------------------------------ | |
96 | /** | |
97 | * Constructor | |
98 | * @param shell - a shell for the display of the dialog | |
ccc66d01 | 99 | */ |
d132bcc7 | 100 | public EnableEventsDialog(Shell shell) { |
ccc66d01 | 101 | super(shell); |
8a396998 | 102 | setShellStyle(SWT.RESIZE | getShellStyle()); |
ccc66d01 | 103 | } |
cfdb727a | 104 | |
ccc66d01 BH |
105 | // ------------------------------------------------------------------------ |
106 | // Accessors | |
107 | // ------------------------------------------------------------------------ | |
cfdb727a | 108 | |
ccc66d01 BH |
109 | @Override |
110 | public boolean isTracepoints() { | |
111 | if (fIsKernel) { | |
112 | return fKernelComposite.isTracepoints(); | |
113 | } | |
114 | return fUstComposite.isTracepoints(); | |
115 | } | |
cfdb727a | 116 | |
ccc66d01 BH |
117 | @Override |
118 | public boolean isAllTracePoints() { | |
119 | if (fIsKernel) { | |
120 | return fKernelComposite.isAllTracePoints(); | |
121 | } | |
122 | return fUstComposite.isAllTracePoints(); | |
123 | } | |
cfdb727a | 124 | |
ccc66d01 BH |
125 | @Override |
126 | public boolean isSysCalls() { | |
127 | if (fIsKernel) { | |
128 | return fKernelComposite.isSysCalls(); | |
129 | } | |
130 | return false; | |
131 | } | |
cfdb727a | 132 | |
ccc66d01 BH |
133 | @Override |
134 | public boolean isAllSysCalls() { | |
135 | if (fIsKernel) { | |
136 | return fKernelComposite.isSysCalls(); | |
137 | } | |
138 | return false; | |
139 | } | |
cfdb727a | 140 | |
ccc66d01 BH |
141 | @Override |
142 | public List<String> getEventNames() { | |
143 | if (fIsKernel) { | |
144 | return fKernelComposite.getEventNames(); | |
145 | } | |
146 | return fUstComposite.getEventNames(); | |
147 | } | |
11252342 | 148 | |
ccc66d01 BH |
149 | @Override |
150 | public boolean isDynamicProbe() { | |
151 | if (fIsKernel) { | |
152 | return fKernelComposite.isDynamicProbe(); | |
153 | } | |
154 | return false; | |
155 | } | |
cfdb727a | 156 | |
ccc66d01 BH |
157 | @Override |
158 | public String getProbeName() { | |
159 | if (fIsKernel) { | |
160 | return fKernelComposite.getProbeName(); | |
161 | } | |
162 | return null; | |
163 | } | |
cfdb727a | 164 | |
ccc66d01 BH |
165 | @Override |
166 | public String getProbeEventName() { | |
167 | if (fIsKernel) { | |
168 | return fKernelComposite.getProbeEventName(); | |
169 | } | |
170 | return null; | |
171 | } | |
cfdb727a | 172 | |
ccc66d01 BH |
173 | @Override |
174 | public boolean isDynamicFunctionProbe() { | |
175 | if (fIsKernel) { | |
176 | return fKernelComposite.isDynamicFunctionProbe(); | |
177 | } | |
178 | return false; | |
179 | } | |
cfdb727a | 180 | |
ccc66d01 BH |
181 | @Override |
182 | public String getFunctionEventName() { | |
183 | if (fIsKernel) { | |
184 | return fKernelComposite.getFunctionEventName(); | |
185 | } | |
186 | return null; | |
187 | } | |
cfdb727a | 188 | |
ccc66d01 BH |
189 | @Override |
190 | public String getFunction() { | |
191 | if (fIsKernel) { | |
192 | return fKernelComposite.getFunction(); | |
193 | } | |
194 | return null; | |
195 | } | |
cfdb727a | 196 | |
ccc66d01 BH |
197 | @Override |
198 | public boolean isWildcard() { | |
199 | if (!fIsKernel) { | |
200 | return fUstComposite.isWildcard(); | |
201 | } | |
202 | return false; | |
203 | } | |
204 | ||
ccc66d01 BH |
205 | @Override |
206 | public String getWildcard() { | |
207 | if (!fIsKernel) { | |
208 | return fUstComposite.getWildcard(); | |
209 | } | |
210 | return null; | |
ccc66d01 BH |
211 | } |
212 | ||
ccc66d01 BH |
213 | @Override |
214 | public boolean isLogLevel() { | |
215 | if (!fIsKernel) { | |
216 | return fUstComposite.isLogLevel(); | |
217 | } | |
218 | return false; | |
ccc66d01 BH |
219 | } |
220 | ||
ccc66d01 BH |
221 | @Override |
222 | public LogLevelType getLogLevelType() { | |
223 | if (!fIsKernel) { | |
224 | return fUstComposite.getLogLevelType(); | |
225 | } | |
226 | return null; | |
ccc66d01 | 227 | } |
cfdb727a | 228 | |
ccc66d01 BH |
229 | @Override |
230 | public TraceLogLevel getLogLevel() { | |
231 | if (!fIsKernel) { | |
232 | return fUstComposite.getLogLevel(); | |
233 | } | |
234 | return null; | |
ccc66d01 BH |
235 | } |
236 | ||
ccc66d01 BH |
237 | @Override |
238 | public String getLogLevelEventName() { | |
239 | if (!fIsKernel) { | |
240 | return fUstComposite.getLogLevelEventName(); | |
241 | } | |
242 | return null; | |
243 | } | |
cfdb727a | 244 | |
ccc66d01 BH |
245 | @Override |
246 | public boolean isKernel() { | |
247 | return fIsKernel; | |
248 | } | |
cfdb727a | 249 | |
d132bcc7 BH |
250 | @Override |
251 | public void setTraceProviderGroup(TraceProviderGroup providerGroup) { | |
252 | fProviderGroup = providerGroup; | |
253 | } | |
254 | ||
d132bcc7 BH |
255 | @Override |
256 | public void setTraceDomainComponent(TraceDomainComponent domain) { | |
257 | fDomain = domain; | |
258 | if (fDomain != null) { | |
259 | fIsKernel = fDomain.isKernel(); | |
260 | } else { | |
a07c7629 | 261 | fIsKernel = fProviderGroup != null ? fProviderGroup.hasKernelProvider() : true; |
d132bcc7 BH |
262 | } |
263 | } | |
ccc66d01 | 264 | |
d4514365 BH |
265 | @Override |
266 | public String getFilterExpression() { | |
267 | if (!fIsKernel) { | |
268 | return fUstComposite.getFilterExpression(); | |
269 | } | |
270 | return null; | |
271 | } | |
272 | ||
ccc66d01 BH |
273 | // ------------------------------------------------------------------------ |
274 | // Operations | |
275 | // ------------------------------------------------------------------------ | |
11252342 | 276 | |
ccc66d01 BH |
277 | @Override |
278 | protected void configureShell(Shell newShell) { | |
279 | super.configureShell(newShell); | |
280 | newShell.setText(Messages.TraceControl_EnableEventsDialogTitle); | |
31a6a4e4 | 281 | newShell.setImage(Activator.getDefault().loadIcon(ENABLE_EVENT_ICON_FILE)); |
ccc66d01 BH |
282 | } |
283 | ||
ccc66d01 BH |
284 | @Override |
285 | protected Control createDialogArea(Composite parent) { | |
cfdb727a | 286 | |
ccc66d01 BH |
287 | // Main dialog panel |
288 | fDialogComposite = new Composite(parent, SWT.NONE); | |
289 | GridLayout layout = new GridLayout(1, true); | |
290 | fDialogComposite.setLayout(layout); | |
291 | fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
292 | ||
293 | // ------------------------------------------------------------------------ | |
cfdb727a | 294 | // Domain Group |
ccc66d01 BH |
295 | // ------------------------------------------------------------------------ |
296 | Group domainGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); | |
297 | domainGroup.setText(Messages.TraceControl_DomainDisplayName); | |
298 | layout = new GridLayout(2, true); | |
cfdb727a AM |
299 | domainGroup.setLayout(layout); |
300 | ||
ccc66d01 BH |
301 | fKernelButton = new Button(domainGroup, SWT.RADIO); |
302 | fKernelButton.setText(Messages.TraceControl_KernelDomainDisplayName); | |
303 | fKernelButton.setSelection(fIsKernel); | |
304 | fUstButton = new Button(domainGroup, SWT.RADIO); | |
305 | fUstButton.setText(Messages.TraceControl_UstDisplayName); | |
306 | fUstButton.setSelection(!fIsKernel); | |
307 | ||
a07c7629 | 308 | if ((fDomain != null) || ((fProviderGroup != null) && (!fProviderGroup.hasKernelProvider()))) { |
ccc66d01 BH |
309 | fKernelButton.setEnabled(false); |
310 | fUstButton.setEnabled(false); | |
311 | } | |
312 | ||
313 | // layout widgets | |
314 | GridData data = new GridData(GridData.FILL_HORIZONTAL); | |
315 | domainGroup.setLayoutData(data); | |
316 | ||
317 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
318 | fKernelButton.setLayoutData(data); | |
319 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
320 | fUstButton.setLayoutData(data); | |
321 | ||
322 | // ------------------------------------------------------------------------ | |
cfdb727a | 323 | // Kernel or UST event data group |
ccc66d01 | 324 | // ------------------------------------------------------------------------ |
d132bcc7 BH |
325 | fUstComposite = null; |
326 | fKernelComposite = null; | |
ccc66d01 BH |
327 | if (fIsKernel) { |
328 | createKernelComposite(); | |
d132bcc7 | 329 | fUstComposite = null; |
ccc66d01 BH |
330 | } else { |
331 | createUstComposite(); | |
332 | } | |
cfdb727a | 333 | |
ccc66d01 BH |
334 | fKernelButton.addSelectionListener(new SelectionAdapter() { |
335 | @Override | |
336 | public void widgetSelected(SelectionEvent e) { | |
337 | if (fKernelButton.getSelection()) { | |
338 | disposeUstComposite(); | |
339 | createKernelComposite(); | |
340 | fDialogComposite.layout(); | |
341 | } | |
342 | } | |
343 | }); | |
344 | ||
345 | fUstButton.addSelectionListener(new SelectionAdapter() { | |
346 | @Override | |
347 | public void widgetSelected(SelectionEvent e) { | |
348 | if (fUstButton.getSelection()) { | |
349 | disposeKernelComposite(); | |
350 | createUstComposite(); | |
351 | fDialogComposite.layout(); | |
352 | } | |
353 | } | |
354 | }); | |
cfdb727a | 355 | |
ccc66d01 | 356 | getShell().setMinimumSize(new Point(500, 650)); |
cfdb727a | 357 | |
ccc66d01 BH |
358 | return fDialogComposite; |
359 | } | |
cfdb727a | 360 | |
ccc66d01 BH |
361 | @Override |
362 | protected void createButtonsForButtonBar(Composite parent) { | |
79c3db85 | 363 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ |
ccc66d01 BH |
364 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
365 | } | |
366 | ||
ccc66d01 BH |
367 | @Override |
368 | protected void okPressed() { | |
c56972bb | 369 | fIsKernel = fKernelButton.getSelection(); |
ccc66d01 BH |
370 | |
371 | // Validate kernel composite in case of kernel domain | |
372 | if (fKernelComposite != null && !fKernelComposite.isValid()) { | |
373 | return; | |
374 | } | |
cfdb727a | 375 | |
ccc66d01 BH |
376 | // Validate UST composite in case of UST domain |
377 | if (fUstComposite != null && !fUstComposite.isValid()) { | |
378 | return; | |
379 | } | |
cfdb727a | 380 | |
ccc66d01 BH |
381 | // validation successful -> call super.okPressed() |
382 | super.okPressed(); | |
383 | } | |
cfdb727a | 384 | |
ccc66d01 BH |
385 | // ------------------------------------------------------------------------ |
386 | // Helper methods | |
387 | // ------------------------------------------------------------------------ | |
11252342 | 388 | |
ccc66d01 BH |
389 | /** |
390 | * Creates the kernel composite (if not existing) | |
391 | */ | |
392 | private void createKernelComposite() { | |
393 | if (fKernelComposite == null) { | |
394 | fKernelComposite = new EnableKernelEventComposite(fDialogComposite, SWT.NONE, fProviderGroup); | |
395 | GridLayout layout = new GridLayout(1, true); | |
396 | fKernelComposite.setLayout(layout); | |
397 | fKernelComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
398 | ||
399 | fKernelComposite.createContent(); | |
400 | } | |
401 | } | |
402 | ||
403 | /** | |
404 | * Disposes the kernel composite (if existing) | |
405 | */ | |
406 | private void disposeKernelComposite() { | |
407 | if (fKernelComposite != null) { | |
408 | fKernelComposite.dispose(); | |
409 | fKernelComposite = null; | |
410 | } | |
411 | } | |
412 | ||
413 | /** | |
414 | * Creates the UST composite (if not existing) | |
415 | */ | |
416 | private void createUstComposite() { | |
cfdb727a | 417 | if (fUstComposite == null) { |
ccc66d01 BH |
418 | fUstComposite = new EnableUstEventsComposite(fDialogComposite, SWT.NONE, fProviderGroup); |
419 | GridLayout layout = new GridLayout(1, true); | |
420 | fUstComposite.setLayout(layout); | |
421 | fUstComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
422 | ||
423 | fUstComposite.createContent(); | |
424 | } | |
425 | } | |
426 | ||
427 | /** | |
428 | * Disposes the UST composite (if existing) | |
429 | */ | |
430 | private void disposeUstComposite() { | |
431 | if (fUstComposite != null) { | |
432 | fUstComposite.dispose(); | |
433 | fUstComposite = null; | |
434 | } | |
435 | } | |
436 | } |