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
.lttng
.ui
.views
.control
.dialogs
;
14 import java
.util
.ArrayList
;
15 import java
.util
.List
;
17 import org
.eclipse
.jface
.dialogs
.Dialog
;
18 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.jface
.viewers
.CheckStateChangedEvent
;
21 import org
.eclipse
.jface
.viewers
.CheckboxTreeViewer
;
22 import org
.eclipse
.jface
.viewers
.ICheckStateListener
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.Messages
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.TraceControlContentProvider
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.TraceControlLabelProvider
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceProviderGroup
;
30 import org
.eclipse
.swt
.SWT
;
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
.Control
;
37 import org
.eclipse
.swt
.widgets
.Group
;
38 import org
.eclipse
.swt
.widgets
.Label
;
39 import org
.eclipse
.swt
.widgets
.Shell
;
40 import org
.eclipse
.swt
.widgets
.Text
;
43 * <b><u>EnableKernelEventDialog</u></b>
45 * Dialog box for collecting information kernel events to be enabled.
48 public class EnableKernelEventDialog
extends Dialog
implements IEnableKernelEventsDialog
{
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
54 * The icon file for this dialog box.
56 public static final String ENABLE_EVENT_ICON_FILE
= "icons/elcl16/edit.gif"; //$NON-NLS-1$
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 * The dialog composite.
64 private Composite fDialogComposite
;
66 * The goup for the list of available tracepoints.
68 private Group fTracepointsGroup
;
70 * A tree viewer for diplaying and selection of available tracepoints.
72 private CheckboxTreeViewer fTracepointsViewer
;
74 * The Group for Syscalls selection.
76 private Group fSyscallGroup
;
78 * The button to enable or disable all syscalls
80 private Button fSyscallButton
;
82 * The group for defining a dynamic probe.
84 private Group fProbeGroup
;
86 * The text field for the event name for the dynamic probe.
88 private Text fProbeEventNameText
;
90 * The text field for the dynamic probe.
92 private Text fProbeText
;
94 * The group for defining a dynamic function probe.
96 private Group fFunctionGroup
;
98 * The text field for the event name for the dynamic probe.
100 private Text fFunctionEventNameText
;
102 * The text field for the dynamic function entry/return probe.
104 private Text fFunctionText
;
106 * The referenced kernel provider component which contains a list of available tracepoints.
108 private KernelProviderComponent fKernelProvider
;
110 * The flag indicating that all tracepoints are selected.
112 private boolean fIsAllTracepoints
;
114 * The flag indicating that syscalls are selected.
116 private boolean fIsAllSysCalls
;
118 * The list of tracepoints to be enabled.
120 private List
<String
> fSelectedEvents
;
122 * The event name of the dynamic probe.
124 private String fProbeEventName
;
128 private String fProbeString
;
130 * The event name of the dynamic function entry/return probe.
132 private String fFunctionEventName
;
134 * The dynamic function entry/return probe.
136 private String fFunctionString
;
138 // ------------------------------------------------------------------------
140 // ------------------------------------------------------------------------
144 * @param shell - a shell for the display of the dialog
145 * @param kernelProvider - the kernel provider component
147 public EnableKernelEventDialog(Shell shell
, KernelProviderComponent kernelProvider
) {
149 fKernelProvider
= kernelProvider
;
150 setShellStyle(SWT
.RESIZE
);
153 // ------------------------------------------------------------------------
155 // ------------------------------------------------------------------------
158 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#isAllTracePoints()
161 public boolean isAllTracePoints() {
162 return fIsAllTracepoints
;
166 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#isAllSysCalls()
169 public boolean isAllSysCalls() {
170 return fIsAllSysCalls
;
174 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getEventNames()
177 public List
<String
> getEventNames() {
178 return new ArrayList
<String
>(fSelectedEvents
);
182 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getProbeName()
185 public String
getProbeName() {
190 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getProbeEventName()
193 public String
getProbeEventName() {
194 return fProbeEventName
;
198 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getFunctionEventName()
201 public String
getFunctionEventName() {
202 return fFunctionEventName
;
206 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getFunction()
209 public String
getFunction() {
210 return fFunctionString
;
213 // ------------------------------------------------------------------------
215 // ------------------------------------------------------------------------
218 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
221 protected void configureShell(Shell newShell
) {
222 super.configureShell(newShell
);
223 newShell
.setText(Messages
.TraceControl_EnableKernelEventsDialogTitle
);
224 newShell
.setImage(LTTngUiPlugin
.getDefault().loadIcon(ENABLE_EVENT_ICON_FILE
));
229 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
232 protected Control
createDialogArea(Composite parent
) {
235 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
236 GridLayout layout
= new GridLayout(1, true);
237 fDialogComposite
.setLayout(layout
);
238 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
240 // ------------------------------------------------------------------------
242 // ------------------------------------------------------------------------
243 fTracepointsGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
244 fTracepointsGroup
.setText(Messages
.TraceControl_EnableEventsTracepointGroupName
);
245 layout
= new GridLayout(1, true);
246 fTracepointsGroup
.setLayout(layout
);
247 GridData data
= new GridData(GridData
.FILL_BOTH
);
248 fTracepointsGroup
.setLayoutData(data
);
250 fTracepointsViewer
= new CheckboxTreeViewer(fTracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
251 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
252 fTracepointsViewer
.setContentProvider(new TraceControlContentProvider() {
254 public Object
[] getChildren(Object parentElement
) {
255 if (parentElement
instanceof TraceProviderGroup
) {
256 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
257 return (ITraceControlComponent
[]) children
.toArray(new ITraceControlComponent
[children
.size()]);
259 if (parentElement
instanceof ITraceControlComponent
) {
260 return ((ITraceControlComponent
)parentElement
).getChildren();
262 return new Object
[0];
266 fTracepointsViewer
.setLabelProvider(new TraceControlLabelProvider() {
268 public Image
getImage(Object element
) {
272 public String
getText(Object element
) {
273 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
274 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
276 return super.getText(element
);
280 fTracepointsViewer
.addCheckStateListener(new ICheckStateListener() {
282 public void checkStateChanged(CheckStateChangedEvent event
) {
283 if (event
.getChecked()) {
284 if (event
.getElement() instanceof KernelProviderComponent
) {
285 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
288 if (event
.getElement() instanceof KernelProviderComponent
) {
289 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
291 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
292 fTracepointsViewer
.setChecked(component
.getParent(), false);
298 fTracepointsViewer
.setInput(fKernelProvider
.getParent());
299 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
301 // ------------------------------------------------------------------------
303 // ------------------------------------------------------------------------
304 fSyscallGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
305 layout
= new GridLayout(4, true);
306 fSyscallGroup
.setLayout(layout
);
307 fSyscallGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
309 fSyscallButton
= new Button(fSyscallGroup
, SWT
.CHECK
);
310 fSyscallButton
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
311 fSyscallButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
312 data
= new GridData(GridData
.FILL_BOTH
);
313 data
.horizontalSpan
= 4;
314 fSyscallButton
.setLayoutData(data
);
316 // ------------------------------------------------------------------------
317 // Dynamic Probe Group
318 // ------------------------------------------------------------------------
319 fProbeGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
320 fProbeGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
321 layout
= new GridLayout(4, true);
322 fProbeGroup
.setLayout(layout
);
323 fProbeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
325 Label probeNameLabel
= new Label(fProbeGroup
, SWT
.LEFT
);
326 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsProbeEventNameLabel
);
327 data
= new GridData(GridData
.FILL_BOTH
);
328 data
.horizontalSpan
= 1;
329 probeNameLabel
.setLayoutData(data
);
331 fProbeEventNameText
= new Text(fProbeGroup
, SWT
.LEFT
);
332 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
334 data
= new GridData(GridData
.FILL_BOTH
);
335 data
.horizontalSpan
= 3;
336 fProbeEventNameText
.setLayoutData(data
);
338 Label probeLabel
= new Label(fProbeGroup
, SWT
.LEFT
);
339 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
340 data
= new GridData(GridData
.FILL_BOTH
);
341 data
.horizontalSpan
= 1;
342 probeLabel
.setLayoutData(data
);
344 fProbeText
= new Text(fProbeGroup
, SWT
.LEFT
);
345 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
346 data
= new GridData(GridData
.FILL_BOTH
);
347 data
.horizontalSpan
= 3;
348 fProbeText
.setLayoutData(data
);
350 // ------------------------------------------------------------------------
351 // Dynamic Function Probe Group
352 // ------------------------------------------------------------------------
353 fFunctionGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
354 fFunctionGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
355 layout
= new GridLayout(4, true);
356 fFunctionGroup
.setLayout(layout
);
357 fFunctionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
359 Label functionNameLabel
= new Label(fFunctionGroup
, SWT
.LEFT
);
360 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsProbeEventNameLabel
);
361 data
= new GridData(GridData
.FILL_BOTH
);
362 data
.horizontalSpan
= 1;
363 functionNameLabel
.setLayoutData(data
);
365 fFunctionEventNameText
= new Text(fFunctionGroup
, SWT
.LEFT
);
366 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
367 data
= new GridData(GridData
.FILL_BOTH
);
368 data
.horizontalSpan
= 3;
369 fFunctionEventNameText
.setLayoutData(data
);
371 Label functionLabel
= new Label(fFunctionGroup
, SWT
.LEFT
);
372 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
373 data
= new GridData(GridData
.FILL_BOTH
);
374 data
.horizontalSpan
= 1;
375 functionLabel
.setLayoutData(data
);
377 fFunctionText
= new Text(fFunctionGroup
, SWT
.LEFT
);
378 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
379 data
= new GridData(GridData
.FILL_BOTH
);
380 data
.horizontalSpan
= 3;
381 fFunctionText
.setLayoutData(data
);
383 fDialogComposite
.layout();
385 return fDialogComposite
;
390 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
393 protected void createButtonsForButtonBar(Composite parent
) {
394 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
399 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
402 protected void okPressed() {
403 fIsAllTracepoints
= fTracepointsViewer
.getChecked(fKernelProvider
);
404 fIsAllSysCalls
= fSyscallButton
.getSelection();
406 ITraceControlComponent
[] events
= fKernelProvider
.getChildren();
407 fSelectedEvents
= new ArrayList
<String
>();
408 for (int i
= 0; i
< events
.length
; i
++) {
409 if (fTracepointsViewer
.getChecked(events
[i
])) {
410 fSelectedEvents
.add(events
[i
].getName());
414 // initialize probe string
415 fProbeEventName
= null;
417 String temp
= fProbeEventNameText
.getText();
418 if (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
419 MessageDialog
.openError(getShell(),
420 Messages
.TraceControl_EnableKernelEventsDialogTitle
,
421 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
426 if(!fProbeText
.getText().matches("\\s*")) { //$NON-NLS-1$
427 fProbeEventName
= temp
;
428 // fProbeString will be validated by lttng-tools
429 fProbeString
= fProbeText
.getText();
432 // initialize function string
433 fFunctionEventName
= null;
434 fFunctionString
= null;
436 temp
= fFunctionEventNameText
.getText();
437 if (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
438 MessageDialog
.openError(getShell(),
439 Messages
.TraceControl_EnableKernelEventsDialogTitle
,
440 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
445 if(!fFunctionText
.getText().matches("\\s*")) { //$NON-NLS-1$
446 fFunctionEventName
= temp
;
447 // fFunctionString will be validated by lttng-tools
448 fFunctionString
= fFunctionText
.getText();
451 // validation successful -> call super.okPressed()
457 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
460 protected void buttonPressed(int buttonId
) {
461 super.buttonPressed(buttonId
);
464 // ------------------------------------------------------------------------
466 // ------------------------------------------------------------------------