1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
;
14 import java
.util
.ArrayList
;
15 import java
.util
.List
;
17 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
18 import org
.eclipse
.jface
.viewers
.CheckStateChangedEvent
;
19 import org
.eclipse
.jface
.viewers
.CheckboxTreeViewer
;
20 import org
.eclipse
.jface
.viewers
.ICheckStateListener
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.BaseEventComponent
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceControlContentProvider
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceControlLabelProvider
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceProviderGroup
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.events
.SelectionAdapter
;
30 import org
.eclipse
.swt
.events
.SelectionEvent
;
31 import org
.eclipse
.swt
.graphics
.Image
;
32 import org
.eclipse
.swt
.layout
.GridData
;
33 import org
.eclipse
.swt
.layout
.GridLayout
;
34 import org
.eclipse
.swt
.widgets
.Button
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.swt
.widgets
.Group
;
37 import org
.eclipse
.swt
.widgets
.Label
;
38 import org
.eclipse
.swt
.widgets
.Text
;
41 * <b><u>EnableKernelEventsComposite</u></b>
43 * A composite for collecting information about kernel events to be enabled.
46 public class EnableKernelEventComposite
extends Composite
implements IEnableKernelEvents
{
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
51 private enum KernelGroupEnum
{ TRACEPOINTS
, SYSCALLS
, PROBE
, FUNCTION
};
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * A button to enable/disable the tracepoints group
60 private Button fTracepointsActivateButton
;
62 * A tree viewer for displaying and selection of available tracepoints.
64 private CheckboxTreeViewer fTracepointsViewer
;
66 * A button to enable/disable the syscalls group
68 private Button fSysCallsActivateButton
;
70 * A button to enable or disable the dynamic probe group.
72 private Button fProbeActivateButton
;
74 * The text field for the event name for the dynamic probe.
76 private Text fProbeEventNameText
;
78 * The text field for the dynamic probe.
80 private Text fProbeText
;
82 * A button to enable or disable the dynamic function probe group.
84 private Button fFunctionActivateButton
;
86 * The text field for the event name for the dynamic probe.
88 private Text fFunctionEventNameText
;
90 * The text field for the dynamic function entry/return probe.
92 private Text fFunctionText
;
94 * The referenced trace provider group containing the kernel provider
95 * component which contains a list of available tracepoints.
97 private TraceProviderGroup fProviderGroup
;
99 * The flag indicating that tracepoints are selected.
101 private boolean fIsTracepoints
;
103 * The flag indicating that all tracepoints are selected.
105 private boolean fIsAllTracepoints
;
107 * The flag indicating that syscalls are selected.
109 private boolean fIsSysCalls
;
111 * The list of tracepoints to be enabled.
113 private List
<String
> fSelectedEvents
;
115 * The flag indicating that dynamic probe is selected.
117 private boolean fIsDynamicProbe
;
119 * The event name of the dynamic probe.
121 private String fProbeEventName
;
125 private String fProbeString
;
127 * The flag indicating that the dynamic function probe is selected.
129 private boolean fIsDynamicFunctionProbe
;
131 * The event name of the dynamic function entry/return probe.
133 private String fFunctionEventName
;
135 * The dynamic function entry/return probe.
137 private String fFunctionString
;
139 // ------------------------------------------------------------------------
141 // ------------------------------------------------------------------------
143 public EnableKernelEventComposite(Composite parent
, int style
, TraceProviderGroup providerGroup
) {
144 super(parent
, style
);
145 fProviderGroup
= providerGroup
;
148 // ------------------------------------------------------------------------
150 // ------------------------------------------------------------------------
153 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isTracpoints()
156 public boolean isTracepoints() {
157 return fIsTracepoints
;
161 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isAllTracePoints()
164 public boolean isAllTracePoints() {
165 return fIsAllTracepoints
;
170 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isSysCalls()
173 public boolean isSysCalls() {
178 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isAllSysCalls()
181 public boolean isAllSysCalls() {
186 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getEventNames()
189 public List
<String
> getEventNames() {
190 return new ArrayList
<String
>(fSelectedEvents
);
194 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isDynamicProbe()
197 public boolean isDynamicProbe() {
198 return fIsDynamicProbe
;
202 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getProbeName()
205 public String
getProbeName() {
210 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getProbeEventName()
213 public String
getProbeEventName() {
214 return fProbeEventName
;
219 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isDynamicFunctionProbe()
222 public boolean isDynamicFunctionProbe() {
223 return fIsDynamicFunctionProbe
;
227 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getFunctionEventName()
230 public String
getFunctionEventName() {
231 return fFunctionEventName
;
235 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getFunction()
238 public String
getFunction() {
239 return fFunctionString
;
242 // ------------------------------------------------------------------------
244 // ------------------------------------------------------------------------
246 * Creates the composite content
248 public void createContent() {
251 createTracepointsGroup();
254 createSysCallsGroup();
256 // Dynamic Probe Group
257 createDynamicProbeGroup();
259 // Dynamic Function Probe Group
260 createDynamicFunctionPropeGroup();
262 // Set default enablements
263 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
267 * Validates the kernel composite input data.
268 * @return true if configured data is valid and can be retrieved.
270 public boolean isValid() {
271 fIsTracepoints
= fTracepointsActivateButton
.getSelection();
272 fIsSysCalls
= fSysCallsActivateButton
.getSelection();
273 fIsDynamicProbe
= fProbeActivateButton
.getSelection();
274 fIsDynamicFunctionProbe
= fFunctionActivateButton
.getSelection();
276 // initialize tracepoint fields
277 fIsAllTracepoints
= false;
278 fSelectedEvents
= new ArrayList
<String
>();
280 if (fIsTracepoints
) {
281 List
<ITraceControlComponent
> comps
= fProviderGroup
.getChildren(KernelProviderComponent
.class);
282 fIsAllTracepoints
= fTracepointsViewer
.getChecked(comps
.get(0));
284 Object
[] checkedElements
= fTracepointsViewer
.getCheckedElements();
285 for (int i
= 0; i
< checkedElements
.length
; i
++) {
286 ITraceControlComponent component
= (ITraceControlComponent
)checkedElements
[i
];
287 if (component
instanceof BaseEventComponent
) {
288 fSelectedEvents
.add(component
.getName());
293 if (fIsDynamicProbe
) {
294 String temp
= fProbeEventNameText
.getText();
295 if (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
296 MessageDialog
.openError(getShell(),
297 Messages
.TraceControl_EnableEventsDialogTitle
,
298 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
303 if(!fProbeText
.getText().matches("\\s*")) { //$NON-NLS-1$
304 fProbeEventName
= temp
;
305 // fProbeString will be validated by lttng-tools
306 fProbeString
= fProbeText
.getText();
310 // initialize function string
311 fFunctionEventName
= null;
312 fFunctionString
= null;
313 if (fIsDynamicFunctionProbe
) {
314 String functionTemp
= fFunctionEventNameText
.getText();
315 if (!functionTemp
.matches("^[\\s]{0,}$") && !functionTemp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
316 MessageDialog
.openError(getShell(),
317 Messages
.TraceControl_EnableEventsDialogTitle
,
318 Messages
.TraceControl_InvalidProbeNameError
+ " (" + functionTemp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
323 if(!fFunctionText
.getText().matches("\\s*")) { //$NON-NLS-1$
324 fFunctionEventName
= functionTemp
;
325 // fFunctionString will be validated by lttng-tools
326 fFunctionString
= fFunctionText
.getText();
334 * Creates tracepoints group.
336 private void createTracepointsGroup() {
340 Group tpMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
341 tpMainGroup
.setText(Messages
.TraceControl_EnableEventsTracepointGroupName
);
342 layout
= new GridLayout(2, false);
343 tpMainGroup
.setLayout(layout
);
344 data
= new GridData(GridData
.FILL_BOTH
);
345 tpMainGroup
.setLayoutData(data
);
347 Composite buttonComposite
= new Composite(tpMainGroup
, SWT
.NONE
);
348 layout
= new GridLayout(1, true);
349 buttonComposite
.setLayout(layout
);
350 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
351 buttonComposite
.setLayoutData(data
);
353 fTracepointsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
354 fTracepointsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
355 data
= new GridData(GridData
.FILL_HORIZONTAL
);
356 fTracepointsActivateButton
.setLayoutData(data
);
357 fTracepointsActivateButton
.addSelectionListener(new SelectionAdapter() {
359 public void widgetSelected(SelectionEvent e
) {
360 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
364 Group tracepointsGroup
= new Group(tpMainGroup
, SWT
.SHADOW_NONE
);
365 layout
= new GridLayout(1, true);
366 tracepointsGroup
.setLayout(layout
);
367 data
= new GridData(GridData
.FILL_BOTH
);
368 tracepointsGroup
.setLayoutData(data
);
370 fTracepointsViewer
= new CheckboxTreeViewer(tracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
371 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
373 fTracepointsViewer
.setContentProvider(new KernelContentProvider());
374 fTracepointsViewer
.setLabelProvider(new KernelLabelProvider());
375 fTracepointsViewer
.addCheckStateListener(new KernelCheckListener());
376 fTracepointsViewer
.setInput(fProviderGroup
);
378 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
382 * Creates syscalls group.
384 private void createSysCallsGroup() {
387 Group sysCallsMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
388 sysCallsMainGroup
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
389 sysCallsMainGroup
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
390 layout
= new GridLayout(2, false);
391 sysCallsMainGroup
.setLayout(layout
);
392 data
= new GridData(GridData
.FILL_HORIZONTAL
);
393 sysCallsMainGroup
.setLayoutData(data
);
395 Composite buttonComposite
= new Composite(sysCallsMainGroup
, SWT
.NONE
);
396 layout
= new GridLayout(1, false);
397 buttonComposite
.setLayout(layout
);
398 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
399 buttonComposite
.setLayoutData(data
);
401 fSysCallsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
402 fSysCallsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
403 fSysCallsActivateButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
404 fSysCallsActivateButton
.setSelection(false);
405 data
= new GridData(GridData
.FILL_HORIZONTAL
);
406 fSysCallsActivateButton
.setLayoutData(data
);
407 fSysCallsActivateButton
.addSelectionListener(new SelectionAdapter() {
409 public void widgetSelected(SelectionEvent e
) {
410 setKernelEnablements(KernelGroupEnum
.SYSCALLS
);
416 * Creates dynamic probe group.
418 private void createDynamicProbeGroup() {
421 Group probeMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
422 probeMainGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
423 layout
= new GridLayout(2, false);
424 probeMainGroup
.setLayout(layout
);
425 data
= new GridData(GridData
.FILL_HORIZONTAL
);
426 probeMainGroup
.setLayoutData(data
);
428 Composite buttonComposite
= new Composite(probeMainGroup
, SWT
.NONE
);
429 layout
= new GridLayout(1, false);
430 buttonComposite
.setLayout(layout
);
431 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
432 buttonComposite
.setLayoutData(data
);
434 fProbeActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
435 fProbeActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
436 fProbeActivateButton
.setSelection(false);
437 data
= new GridData(GridData
.FILL_HORIZONTAL
);
438 fProbeActivateButton
.setLayoutData(data
);
439 fProbeActivateButton
.addSelectionListener(new SelectionAdapter() {
441 public void widgetSelected(SelectionEvent e
) {
442 setKernelEnablements(KernelGroupEnum
.PROBE
);
446 Group probeGroup
= new Group(probeMainGroup
, SWT
.SHADOW_NONE
);
447 layout
= new GridLayout(4, true);
448 probeGroup
.setLayout(layout
);
449 probeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
451 Label probeNameLabel
= new Label(probeGroup
, SWT
.LEFT
);
452 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
453 data
= new GridData(GridData
.FILL_BOTH
);
454 data
.horizontalSpan
= 1;
455 probeNameLabel
.setLayoutData(data
);
457 fProbeEventNameText
= new Text(probeGroup
, SWT
.LEFT
);
458 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
460 data
= new GridData(GridData
.FILL_BOTH
);
461 data
.horizontalSpan
= 3;
462 fProbeEventNameText
.setLayoutData(data
);
464 Label probeLabel
= new Label(probeGroup
, SWT
.LEFT
);
465 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
466 data
= new GridData(GridData
.FILL_BOTH
);
467 data
.horizontalSpan
= 1;
468 probeLabel
.setLayoutData(data
);
470 fProbeText
= new Text(probeGroup
, SWT
.LEFT
);
471 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
472 data
= new GridData(GridData
.FILL_BOTH
);
473 data
.horizontalSpan
= 3;
474 fProbeText
.setLayoutData(data
);
478 * Creates dynamic function entry/return probe group.
480 private void createDynamicFunctionPropeGroup() {
483 Group functionMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
484 functionMainGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
485 layout
= new GridLayout(2, false);
486 functionMainGroup
.setLayout(layout
);
487 data
= new GridData(GridData
.FILL_HORIZONTAL
);
488 functionMainGroup
.setLayoutData(data
);
490 Composite buttonComposite
= new Composite(functionMainGroup
, SWT
.NONE
);
491 layout
= new GridLayout(1, false);
492 buttonComposite
.setLayout(layout
);
493 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
494 buttonComposite
.setLayoutData(data
);
496 fFunctionActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
497 fFunctionActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
498 fFunctionActivateButton
.setSelection(false);
499 data
= new GridData(GridData
.FILL_HORIZONTAL
);
500 fFunctionActivateButton
.setLayoutData(data
);
501 fFunctionActivateButton
.addSelectionListener(new SelectionAdapter() {
503 public void widgetSelected(SelectionEvent e
) {
504 setKernelEnablements(KernelGroupEnum
.FUNCTION
);
508 Group functionGroup
= new Group(functionMainGroup
, SWT
.SHADOW_NONE
);
509 layout
= new GridLayout(4, true);
510 functionGroup
.setLayout(layout
);
511 functionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
513 Label functionNameLabel
= new Label(functionGroup
, SWT
.LEFT
);
514 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
515 data
= new GridData(GridData
.FILL_BOTH
);
516 data
.horizontalSpan
= 1;
517 functionNameLabel
.setLayoutData(data
);
519 fFunctionEventNameText
= new Text(functionGroup
, SWT
.LEFT
);
520 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
521 data
= new GridData(GridData
.FILL_BOTH
);
522 data
.horizontalSpan
= 3;
523 fFunctionEventNameText
.setLayoutData(data
);
525 Label functionLabel
= new Label(functionGroup
, SWT
.LEFT
);
526 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
527 data
= new GridData(GridData
.FILL_BOTH
);
528 data
.horizontalSpan
= 1;
529 functionLabel
.setLayoutData(data
);
531 fFunctionText
= new Text(functionGroup
, SWT
.LEFT
);
532 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
533 data
= new GridData(GridData
.FILL_BOTH
);
534 data
.horizontalSpan
= 3;
535 fFunctionText
.setLayoutData(data
);
539 * Enable/selects widgets depending on the group specified.
540 * @param group - group to enable.
542 private void setKernelEnablements(KernelGroupEnum group
) {
543 fTracepointsActivateButton
.setSelection(group
== KernelGroupEnum
.TRACEPOINTS
);
544 fTracepointsViewer
.getTree().setEnabled(group
== KernelGroupEnum
.TRACEPOINTS
);
546 fSysCallsActivateButton
.setSelection(group
== KernelGroupEnum
.SYSCALLS
);
548 fProbeActivateButton
.setSelection(group
== KernelGroupEnum
.PROBE
);
549 fProbeEventNameText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
550 fProbeText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
552 fFunctionActivateButton
.setSelection(group
== KernelGroupEnum
.FUNCTION
);
553 fFunctionEventNameText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
554 fFunctionText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
557 // ------------------------------------------------------------------------
559 // ------------------------------------------------------------------------
561 * Content provider for the tracepoints tree.
563 final static public class KernelContentProvider
extends TraceControlContentProvider
{
565 public Object
[] getChildren(Object parentElement
) {
566 if (parentElement
instanceof TraceProviderGroup
) {
567 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
568 return (ITraceControlComponent
[]) children
.toArray(new ITraceControlComponent
[children
.size()]);
570 if (parentElement
instanceof ITraceControlComponent
) {
571 return ((ITraceControlComponent
)parentElement
).getChildren();
573 return new Object
[0];
578 * Content label for the tracepoints tree.
580 final static public class KernelLabelProvider
extends TraceControlLabelProvider
{
582 public Image
getImage(Object element
) {
586 public String
getText(Object element
) {
587 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
588 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
590 return super.getText(element
);
595 * Check state listener for the tracepoints tree.
597 final public class KernelCheckListener
implements ICheckStateListener
{
599 public void checkStateChanged(CheckStateChangedEvent event
) {
600 if (event
.getChecked()) {
601 if (event
.getElement() instanceof KernelProviderComponent
) {
602 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
605 if (event
.getElement() instanceof KernelProviderComponent
) {
606 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
608 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
609 fTracepointsViewer
.setChecked(component
.getParent(), false);