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