483bbeec06aef7486b6af7d557bf8e160276f7bb
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / dialogs / EnableKernelEventComposite.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 * Marc-Andre Laperle - Add filtering textbox
12 **********************************************************************/
13 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.jface.dialogs.MessageDialog;
19 import org.eclipse.jface.viewers.CheckStateChangedEvent;
20 import org.eclipse.jface.viewers.CheckboxTreeViewer;
21 import org.eclipse.jface.viewers.ICheckStateListener;
22 import org.eclipse.jface.viewers.TreeViewer;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.SelectionAdapter;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.graphics.Image;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Button;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Group;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.Text;
34 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
35 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
36 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.BaseEventComponent;
37 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.KernelProviderComponent;
38 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceControlContentProvider;
39 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceControlLabelProvider;
40 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
41 import org.eclipse.ui.dialogs.FilteredTree;
42 import org.eclipse.ui.dialogs.PatternFilter;
43
44 /**
45 * <p>
46 * A composite for collecting information about kernel events to be enabled.
47 * </p>
48 *
49 * @author Bernd Hufmann
50 */
51 public class EnableKernelEventComposite extends Composite implements IEnableKernelEvents {
52
53 // ------------------------------------------------------------------------
54 // Constants
55 // ------------------------------------------------------------------------
56 private enum KernelGroupEnum { TRACEPOINTS, SYSCALLS, PROBE, FUNCTION }
57
58 // ------------------------------------------------------------------------
59 // Attributes
60 // ------------------------------------------------------------------------
61
62 /**
63 * A button to enable/disable the tracepoints group
64 */
65 private Button fTracepointsActivateButton;
66 /**
67 * A tree viewer for displaying and selection of available tracepoints.
68 */
69 private CheckboxTreeViewer fTracepointsViewer;
70 /**
71 * A button to enable/disable the syscalls group
72 */
73 private Button fSysCallsActivateButton;
74 /**
75 * A button to enable or disable the dynamic probe group.
76 */
77 private Button fProbeActivateButton;
78 /**
79 * The text field for the event name for the dynamic probe.
80 */
81 private Text fProbeEventNameText;
82 /**
83 * The text field for the dynamic probe.
84 */
85 private Text fProbeText;
86 /**
87 * A button to enable or disable the dynamic function probe group.
88 */
89 private Button fFunctionActivateButton;
90 /**
91 * The text field for the event name for the dynamic probe.
92 */
93 private Text fFunctionEventNameText;
94 /**
95 * The text field for the dynamic function entry/return probe.
96 */
97 private Text fFunctionText;
98 /**
99 * The referenced trace provider group containing the kernel provider
100 * component which contains a list of available tracepoints.
101 */
102 private final TraceProviderGroup fProviderGroup;
103 /**
104 * The flag indicating that tracepoints are selected.
105 */
106 private boolean fIsTracepoints;
107 /**
108 * The flag indicating that all tracepoints are selected.
109 */
110 private boolean fIsAllTracepoints;
111 /**
112 * The flag indicating that syscalls are selected.
113 */
114 private boolean fIsSysCalls;
115 /**
116 * The list of tracepoints to be enabled.
117 */
118 private List<String> fSelectedEvents;
119 /**
120 * The flag indicating that dynamic probe is selected.
121 */
122 private boolean fIsDynamicProbe;
123 /**
124 * The event name of the dynamic probe.
125 */
126 private String fProbeEventName;
127 /**
128 * The dynamic probe.
129 */
130 private String fProbeString;
131 /**
132 * The flag indicating that the dynamic function probe is selected.
133 */
134 private boolean fIsDynamicFunctionProbe;
135 /**
136 * The event name of the dynamic function entry/return probe.
137 */
138 private String fFunctionEventName;
139 /**
140 * The dynamic function entry/return probe.
141 */
142 private String fFunctionString;
143
144 // ------------------------------------------------------------------------
145 // Constructors
146 // ------------------------------------------------------------------------
147
148 /**
149 * Constructor
150 *
151 * @param parent
152 * The parent composite
153 * @param style
154 * The index of the style for this event composite
155 * @param providerGroup
156 * The trace provider group
157 */
158 public EnableKernelEventComposite(Composite parent, int style, TraceProviderGroup providerGroup) {
159 super(parent, style);
160 fProviderGroup = providerGroup;
161 }
162
163 // ------------------------------------------------------------------------
164 // Acessors
165 // ------------------------------------------------------------------------
166
167 @Override
168 public boolean isTracepoints() {
169 return fIsTracepoints;
170 }
171
172 @Override
173 public boolean isAllTracePoints() {
174 return fIsAllTracepoints;
175 }
176
177 @Override
178 public boolean isSysCalls() {
179 return fIsSysCalls;
180 }
181
182 @Override
183 public boolean isAllSysCalls() {
184 return fIsSysCalls;
185 }
186
187 @Override
188 public List<String> getEventNames() {
189 return new ArrayList<>(fSelectedEvents);
190 }
191
192 @Override
193 public boolean isDynamicProbe() {
194 return fIsDynamicProbe;
195 }
196
197 @Override
198 public String getProbeName() {
199 return fProbeString;
200 }
201
202 @Override
203 public String getProbeEventName() {
204 return fProbeEventName;
205 }
206
207 @Override
208 public boolean isDynamicFunctionProbe() {
209 return fIsDynamicFunctionProbe;
210 }
211
212 @Override
213 public String getFunctionEventName() {
214 return fFunctionEventName;
215 }
216
217 @Override
218 public String getFunction() {
219 return fFunctionString;
220 }
221
222 // ------------------------------------------------------------------------
223 // Operations
224 // ------------------------------------------------------------------------
225
226 /**
227 * Creates the composite content
228 */
229 public void createContent() {
230
231 // Tracepoints Group
232 createTracepointsGroup();
233
234 // Syscalls Group
235 createSysCallsGroup();
236
237 // Dynamic Probe Group
238 createDynamicProbeGroup();
239
240 // Dynamic Function Probe Group
241 createDynamicFunctionPropeGroup();
242
243 // Set default enablements
244 setKernelEnablements(KernelGroupEnum.TRACEPOINTS);
245 }
246
247 /**
248 * Validates the kernel composite input data.
249 * @return true if configured data is valid and can be retrieved.
250 */
251 public boolean isValid() {
252 fIsTracepoints = fTracepointsActivateButton.getSelection();
253 fIsSysCalls = fSysCallsActivateButton.getSelection();
254 fIsDynamicProbe = fProbeActivateButton.getSelection();
255 fIsDynamicFunctionProbe = fFunctionActivateButton.getSelection();
256
257 // initialize tracepoint fields
258 fIsAllTracepoints = false;
259 fSelectedEvents = new ArrayList<>();
260
261 if (fIsTracepoints) {
262 Object[] checkedElements = fTracepointsViewer.getCheckedElements();
263 for (int i = 0; i < checkedElements.length; i++) {
264 ITraceControlComponent component = (ITraceControlComponent)checkedElements[i];
265 if (component instanceof BaseEventComponent) {
266 fSelectedEvents.add(component.getName());
267 }
268 }
269 // verify if all events are selected
270 int nbEvents = 0;
271 List<ITraceControlComponent> comps = fProviderGroup.getChildren(KernelProviderComponent.class);
272 for (ITraceControlComponent comp : comps) {
273 nbEvents += comp.getChildren().length;
274 }
275 fIsAllTracepoints = (nbEvents == fSelectedEvents.size());
276 }
277
278 if (fIsDynamicProbe) {
279 String temp = fProbeEventNameText.getText();
280 if (temp.isEmpty() ||
281 fProbeText.getText().matches("\\s*") || //$NON-NLS-1$
282 (!temp.matches("^[\\s]{0,}$") && !temp.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
283 MessageDialog.openError(getShell(),
284 Messages.TraceControl_EnableEventsDialogTitle,
285 Messages.TraceControl_InvalidProbeNameError + " (" + temp + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
286
287 return false;
288 }
289
290 fProbeEventName = temp;
291 // fProbeString will be validated by lttng-tools
292 fProbeString = fProbeText.getText();
293 }
294
295 // initialize function string
296 fFunctionEventName = null;
297 fFunctionString = null;
298 if (fIsDynamicFunctionProbe) {
299 String functionTemp = fFunctionEventNameText.getText();
300 if (functionTemp.isEmpty() ||
301 functionTemp.matches("\\s*") || //$NON-NLS-1$
302 (!functionTemp.matches("^[\\s]{0,}$") && !functionTemp.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
303 MessageDialog.openError(getShell(),
304 Messages.TraceControl_EnableEventsDialogTitle,
305 Messages.TraceControl_InvalidProbeNameError + " (" + functionTemp + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
306
307 return false;
308 }
309
310 fFunctionEventName = functionTemp;
311 // fFunctionString will be validated by lttng-tools
312 fFunctionString = fFunctionText.getText();
313 }
314
315 return true;
316 }
317
318 /**
319 * Creates tracepoints group.
320 */
321 private void createTracepointsGroup() {
322
323 GridLayout layout;
324 GridData data;
325 Group tpMainGroup = new Group(this, SWT.SHADOW_NONE);
326 tpMainGroup.setText(Messages.TraceControl_EnableEventsTracepointGroupName);
327 layout = new GridLayout(2, false);
328 tpMainGroup.setLayout(layout);
329 data = new GridData(GridData.FILL_BOTH);
330 tpMainGroup.setLayoutData(data);
331
332 Composite buttonComposite = new Composite(tpMainGroup, SWT.NONE);
333 layout = new GridLayout(1, true);
334 buttonComposite.setLayout(layout);
335 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
336 buttonComposite.setLayoutData(data);
337
338 fTracepointsActivateButton = new Button(buttonComposite, SWT.RADIO);
339 fTracepointsActivateButton.setText(Messages.TraceControl_EnableGroupSelectionName);
340 data = new GridData(GridData.FILL_HORIZONTAL);
341 fTracepointsActivateButton.setLayoutData(data);
342 fTracepointsActivateButton.addSelectionListener(new SelectionAdapter() {
343 @Override
344 public void widgetSelected(SelectionEvent e) {
345 setKernelEnablements(KernelGroupEnum.TRACEPOINTS);
346 }
347 });
348
349 Group tracepointsGroup = new Group(tpMainGroup, SWT.SHADOW_NONE);
350 layout = new GridLayout(1, true);
351 tracepointsGroup.setLayout(layout);
352 data = new GridData(GridData.FILL_BOTH);
353 tracepointsGroup.setLayoutData(data);
354
355 new FilteredTree(tracepointsGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, new PatternFilter(), true) {
356 @Override
357 protected TreeViewer doCreateTreeViewer(Composite aparent, int style) {
358 fTracepointsViewer = new CheckboxTreeViewer(aparent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
359 fTracepointsViewer.getTree().setToolTipText(Messages.TraceControl_EnableEventsTracepointTreeTooltip);
360
361 fTracepointsViewer.setContentProvider(new KernelContentProvider());
362 fTracepointsViewer.setLabelProvider(new KernelLabelProvider());
363 fTracepointsViewer.addCheckStateListener(new KernelCheckListener());
364 fTracepointsViewer.setInput(fProviderGroup);
365
366 fTracepointsViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
367 return fTracepointsViewer;
368 }
369 };
370 }
371
372 /**
373 * Creates syscalls group.
374 */
375 private void createSysCallsGroup() {
376 GridLayout layout;
377 GridData data;
378 Group sysCallsMainGroup = new Group(this, SWT.SHADOW_NONE);
379 sysCallsMainGroup.setText(Messages.TraceControl_EnableEventsSyscallName);
380 sysCallsMainGroup.setToolTipText(Messages.TraceControl_EnableEventsSyscallTooltip);
381 layout = new GridLayout(2, false);
382 sysCallsMainGroup.setLayout(layout);
383 data = new GridData(GridData.FILL_HORIZONTAL);
384 sysCallsMainGroup.setLayoutData(data);
385
386 Composite buttonComposite = new Composite(sysCallsMainGroup, SWT.NONE);
387 layout = new GridLayout(1, false);
388 buttonComposite.setLayout(layout);
389 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
390 buttonComposite.setLayoutData(data);
391
392 fSysCallsActivateButton = new Button(buttonComposite, SWT.RADIO);
393 fSysCallsActivateButton.setText(Messages.TraceControl_EnableGroupSelectionName);
394 fSysCallsActivateButton.setToolTipText(Messages.TraceControl_EnableEventsSyscallTooltip);
395 fSysCallsActivateButton.setSelection(false);
396 data = new GridData(GridData.FILL_HORIZONTAL);
397 fSysCallsActivateButton.setLayoutData(data);
398 fSysCallsActivateButton.addSelectionListener(new SelectionAdapter() {
399 @Override
400 public void widgetSelected(SelectionEvent e) {
401 setKernelEnablements(KernelGroupEnum.SYSCALLS);
402 }
403 });
404 }
405
406 /**
407 * Creates dynamic probe group.
408 */
409 private void createDynamicProbeGroup() {
410 GridLayout layout;
411 GridData data;
412 Group probeMainGroup = new Group(this, SWT.SHADOW_NONE);
413 probeMainGroup.setText(Messages.TraceControl_EnableEventsProbeGroupName);
414 layout = new GridLayout(2, false);
415 probeMainGroup.setLayout(layout);
416 data = new GridData(GridData.FILL_HORIZONTAL);
417 probeMainGroup.setLayoutData(data);
418
419 Composite buttonComposite = new Composite(probeMainGroup, SWT.NONE);
420 layout = new GridLayout(1, false);
421 buttonComposite.setLayout(layout);
422 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
423 buttonComposite.setLayoutData(data);
424
425 fProbeActivateButton = new Button(buttonComposite, SWT.RADIO);
426 fProbeActivateButton.setText(Messages.TraceControl_EnableGroupSelectionName);
427 fProbeActivateButton.setSelection(false);
428 data = new GridData(GridData.FILL_HORIZONTAL);
429 fProbeActivateButton.setLayoutData(data);
430 fProbeActivateButton.addSelectionListener(new SelectionAdapter() {
431 @Override
432 public void widgetSelected(SelectionEvent e) {
433 setKernelEnablements(KernelGroupEnum.PROBE);
434 }
435 });
436
437 Group probeGroup = new Group(probeMainGroup, SWT.SHADOW_NONE);
438 layout = new GridLayout(4, true);
439 probeGroup.setLayout(layout);
440 probeGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
441
442 Label probeNameLabel = new Label(probeGroup, SWT.LEFT);
443 probeNameLabel.setText(Messages.TraceControl_EnableEventsEventNameLabel);
444 data = new GridData(GridData.FILL_BOTH);
445 data.horizontalSpan = 1;
446 probeNameLabel.setLayoutData(data);
447
448 fProbeEventNameText = new Text(probeGroup, SWT.LEFT);
449 fProbeEventNameText.setToolTipText(Messages.TraceControl_EnableEventsProbeEventNameTooltip);
450
451 data = new GridData(GridData.FILL_BOTH);
452 data.horizontalSpan = 3;
453 fProbeEventNameText.setLayoutData(data);
454
455 Label probeLabel = new Label(probeGroup, SWT.LEFT);
456 probeLabel.setText(Messages.TraceControl_EnableEventsProbeNameLabel);
457 data = new GridData(GridData.FILL_BOTH);
458 data.horizontalSpan = 1;
459 probeLabel.setLayoutData(data);
460
461 fProbeText = new Text(probeGroup, SWT.LEFT);
462 fProbeText.setToolTipText(Messages.TraceControl_EnableEventsProbeNameTooltip);
463 data = new GridData(GridData.FILL_BOTH);
464 data.horizontalSpan = 3;
465 fProbeText.setLayoutData(data);
466 }
467
468 /**
469 * Creates dynamic function entry/return probe group.
470 */
471 private void createDynamicFunctionPropeGroup() {
472 GridLayout layout;
473 GridData data;
474 Group functionMainGroup = new Group(this, SWT.SHADOW_NONE);
475 functionMainGroup.setText(Messages.TraceControl_EnableEventsFucntionGroupName);
476 layout = new GridLayout(2, false);
477 functionMainGroup.setLayout(layout);
478 data = new GridData(GridData.FILL_HORIZONTAL);
479 functionMainGroup.setLayoutData(data);
480
481 Composite buttonComposite = new Composite(functionMainGroup, SWT.NONE);
482 layout = new GridLayout(1, false);
483 buttonComposite.setLayout(layout);
484 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
485 buttonComposite.setLayoutData(data);
486
487 fFunctionActivateButton = new Button(buttonComposite, SWT.RADIO);
488 fFunctionActivateButton.setText(Messages.TraceControl_EnableGroupSelectionName);
489 fFunctionActivateButton.setSelection(false);
490 data = new GridData(GridData.FILL_HORIZONTAL);
491 fFunctionActivateButton.setLayoutData(data);
492 fFunctionActivateButton.addSelectionListener(new SelectionAdapter() {
493 @Override
494 public void widgetSelected(SelectionEvent e) {
495 setKernelEnablements(KernelGroupEnum.FUNCTION);
496 }
497 });
498
499 Group functionGroup = new Group(functionMainGroup, SWT.SHADOW_NONE);
500 layout = new GridLayout(4, true);
501 functionGroup.setLayout(layout);
502 functionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
503
504 Label functionNameLabel = new Label(functionGroup, SWT.LEFT);
505 functionNameLabel.setText(Messages.TraceControl_EnableEventsEventNameLabel);
506 data = new GridData(GridData.FILL_BOTH);
507 data.horizontalSpan = 1;
508 functionNameLabel.setLayoutData(data);
509
510 fFunctionEventNameText = new Text(functionGroup, SWT.LEFT);
511 fFunctionEventNameText.setToolTipText(Messages.TraceControl_EnableEventsFunctionEventNameTooltip);
512 data = new GridData(GridData.FILL_BOTH);
513 data.horizontalSpan = 3;
514 fFunctionEventNameText.setLayoutData(data);
515
516 Label functionLabel = new Label(functionGroup, SWT.LEFT);
517 functionLabel.setText(Messages.TraceControl_EnableEventsFunctionNameLabel);
518 data = new GridData(GridData.FILL_BOTH);
519 data.horizontalSpan = 1;
520 functionLabel.setLayoutData(data);
521
522 fFunctionText = new Text(functionGroup, SWT.LEFT);
523 fFunctionText.setToolTipText(Messages.TraceControl_EnableEventsProbeNameTooltip);
524 data = new GridData(GridData.FILL_BOTH);
525 data.horizontalSpan = 3;
526 fFunctionText.setLayoutData(data);
527 }
528
529 /**
530 * Enable/selects widgets depending on the group specified.
531 * @param group - group to enable.
532 */
533 private void setKernelEnablements(KernelGroupEnum group) {
534 fTracepointsActivateButton.setSelection(group == KernelGroupEnum.TRACEPOINTS);
535 fTracepointsViewer.getTree().setEnabled(group == KernelGroupEnum.TRACEPOINTS);
536
537 fSysCallsActivateButton.setSelection(group == KernelGroupEnum.SYSCALLS);
538
539 fProbeActivateButton.setSelection(group == KernelGroupEnum.PROBE);
540 fProbeEventNameText.setEnabled(group == KernelGroupEnum.PROBE);
541 fProbeText.setEnabled(group == KernelGroupEnum.PROBE);
542
543 fFunctionActivateButton.setSelection(group == KernelGroupEnum.FUNCTION);
544 fFunctionEventNameText.setEnabled(group == KernelGroupEnum.FUNCTION);
545 fFunctionText.setEnabled(group == KernelGroupEnum.FUNCTION);
546 }
547
548 // ------------------------------------------------------------------------
549 // Local classes
550 // ------------------------------------------------------------------------
551 /**
552 * Content provider for the tracepoints tree.
553 */
554 public static final class KernelContentProvider extends TraceControlContentProvider {
555 @Override
556 public Object[] getChildren(Object parentElement) {
557 if (parentElement instanceof TraceProviderGroup) {
558 List<ITraceControlComponent> children = ((ITraceControlComponent)parentElement).getChildren(KernelProviderComponent.class);
559 return children.toArray(new ITraceControlComponent[children.size()]);
560 }
561 if (parentElement instanceof ITraceControlComponent) {
562 return ((ITraceControlComponent)parentElement).getChildren();
563 }
564 return new Object[0];
565 }
566 }
567
568 /**
569 * Content label for the tracepoints tree.
570 */
571 public static final class KernelLabelProvider extends TraceControlLabelProvider {
572 @Override
573 public Image getImage(Object element) {
574 return null;
575 }
576 @Override
577 public String getText(Object element) {
578 if ((element != null) && (element instanceof KernelProviderComponent)) {
579 return Messages.TraceControl_EnableEventsTracepointTreeAllLabel;
580 }
581 return super.getText(element);
582 }
583 }
584
585 /**
586 * Check state listener for the tracepoints tree.
587 */
588 public final class KernelCheckListener implements ICheckStateListener {
589 @Override
590 public void checkStateChanged(CheckStateChangedEvent event) {
591 if (event.getChecked()) {
592 if (event.getElement() instanceof KernelProviderComponent) {
593 fTracepointsViewer.setSubtreeChecked(event.getElement(), true);
594 }
595 } else {
596 if (event.getElement() instanceof KernelProviderComponent) {
597 fTracepointsViewer.setSubtreeChecked(event.getElement(), false);
598 } else {
599 ITraceControlComponent component = (ITraceControlComponent) event.getElement();
600 fTracepointsViewer.setChecked(component.getParent(), false);
601 }
602 }
603 }
604 }
605 }
This page took 0.046555 seconds and 4 git commands to generate.