lttng: Rename lttng2 feature/plugins to lttng2.control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / 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.linuxtools.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.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
24 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
25 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.BaseEventComponent;
26 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.KernelProviderComponent;
27 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceControlContentProvider;
28 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceControlLabelProvider;
29 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.events.SelectionAdapter;
32 import org.eclipse.swt.events.SelectionEvent;
33 import org.eclipse.swt.graphics.Image;
34 import org.eclipse.swt.layout.GridData;
35 import org.eclipse.swt.layout.GridLayout;
36 import org.eclipse.swt.widgets.Button;
37 import org.eclipse.swt.widgets.Composite;
38 import org.eclipse.swt.widgets.Group;
39 import org.eclipse.swt.widgets.Label;
40 import org.eclipse.swt.widgets.Text;
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 List<ITraceControlComponent> comps = fProviderGroup.getChildren(KernelProviderComponent.class);
263 fIsAllTracepoints = fTracepointsViewer.getChecked(comps.get(0));
264
265 Object[] checkedElements = fTracepointsViewer.getCheckedElements();
266 for (int i = 0; i < checkedElements.length; i++) {
267 ITraceControlComponent component = (ITraceControlComponent)checkedElements[i];
268 if (component instanceof BaseEventComponent) {
269 fSelectedEvents.add(component.getName());
270 }
271 }
272 }
273
274 if (fIsDynamicProbe) {
275 String temp = fProbeEventNameText.getText();
276 if (temp.isEmpty() ||
277 fProbeText.getText().matches("\\s*") || //$NON-NLS-1$
278 (!temp.matches("^[\\s]{0,}$") && !temp.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
279 MessageDialog.openError(getShell(),
280 Messages.TraceControl_EnableEventsDialogTitle,
281 Messages.TraceControl_InvalidProbeNameError + " (" + temp + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
282
283 return false;
284 }
285
286 fProbeEventName = temp;
287 // fProbeString will be validated by lttng-tools
288 fProbeString = fProbeText.getText();
289 }
290
291 // initialize function string
292 fFunctionEventName = null;
293 fFunctionString = null;
294 if (fIsDynamicFunctionProbe) {
295 String functionTemp = fFunctionEventNameText.getText();
296 if (functionTemp.isEmpty() ||
297 functionTemp.matches("\\s*") || //$NON-NLS-1$
298 (!functionTemp.matches("^[\\s]{0,}$") && !functionTemp.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
299 MessageDialog.openError(getShell(),
300 Messages.TraceControl_EnableEventsDialogTitle,
301 Messages.TraceControl_InvalidProbeNameError + " (" + functionTemp + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
302
303 return false;
304 }
305
306 fFunctionEventName = functionTemp;
307 // fFunctionString will be validated by lttng-tools
308 fFunctionString = fFunctionText.getText();
309 }
310
311 return true;
312 }
313
314 /**
315 * Creates tracepoints group.
316 */
317 private void createTracepointsGroup() {
318
319 GridLayout layout;
320 GridData data;
321 Group tpMainGroup = new Group(this, SWT.SHADOW_NONE);
322 tpMainGroup.setText(Messages.TraceControl_EnableEventsTracepointGroupName);
323 layout = new GridLayout(2, false);
324 tpMainGroup.setLayout(layout);
325 data = new GridData(GridData.FILL_BOTH);
326 tpMainGroup.setLayoutData(data);
327
328 Composite buttonComposite = new Composite(tpMainGroup, SWT.NONE);
329 layout = new GridLayout(1, true);
330 buttonComposite.setLayout(layout);
331 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
332 buttonComposite.setLayoutData(data);
333
334 fTracepointsActivateButton = new Button(buttonComposite, SWT.RADIO);
335 fTracepointsActivateButton.setText(Messages.TraceControl_EnableGroupSelectionName);
336 data = new GridData(GridData.FILL_HORIZONTAL);
337 fTracepointsActivateButton.setLayoutData(data);
338 fTracepointsActivateButton.addSelectionListener(new SelectionAdapter() {
339 @Override
340 public void widgetSelected(SelectionEvent e) {
341 setKernelEnablements(KernelGroupEnum.TRACEPOINTS);
342 }
343 });
344
345 Group tracepointsGroup = new Group(tpMainGroup, SWT.SHADOW_NONE);
346 layout = new GridLayout(1, true);
347 tracepointsGroup.setLayout(layout);
348 data = new GridData(GridData.FILL_BOTH);
349 tracepointsGroup.setLayoutData(data);
350
351 new FilteredTree(tracepointsGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, new PatternFilter(), true) {
352 @Override
353 protected TreeViewer doCreateTreeViewer(Composite aparent, int style) {
354 fTracepointsViewer = new CheckboxTreeViewer(aparent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
355 fTracepointsViewer.getTree().setToolTipText(Messages.TraceControl_EnableEventsTracepointTreeTooltip);
356
357 fTracepointsViewer.setContentProvider(new KernelContentProvider());
358 fTracepointsViewer.setLabelProvider(new KernelLabelProvider());
359 fTracepointsViewer.addCheckStateListener(new KernelCheckListener());
360 fTracepointsViewer.setInput(fProviderGroup);
361
362 fTracepointsViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
363 return fTracepointsViewer;
364 }
365 };
366 }
367
368 /**
369 * Creates syscalls group.
370 */
371 private void createSysCallsGroup() {
372 GridLayout layout;
373 GridData data;
374 Group sysCallsMainGroup = new Group(this, SWT.SHADOW_NONE);
375 sysCallsMainGroup.setText(Messages.TraceControl_EnableEventsSyscallName);
376 sysCallsMainGroup.setToolTipText(Messages.TraceControl_EnableEventsSyscallTooltip);
377 layout = new GridLayout(2, false);
378 sysCallsMainGroup.setLayout(layout);
379 data = new GridData(GridData.FILL_HORIZONTAL);
380 sysCallsMainGroup.setLayoutData(data);
381
382 Composite buttonComposite = new Composite(sysCallsMainGroup, SWT.NONE);
383 layout = new GridLayout(1, false);
384 buttonComposite.setLayout(layout);
385 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
386 buttonComposite.setLayoutData(data);
387
388 fSysCallsActivateButton = new Button(buttonComposite, SWT.RADIO);
389 fSysCallsActivateButton.setText(Messages.TraceControl_EnableGroupSelectionName);
390 fSysCallsActivateButton.setToolTipText(Messages.TraceControl_EnableEventsSyscallTooltip);
391 fSysCallsActivateButton.setSelection(false);
392 data = new GridData(GridData.FILL_HORIZONTAL);
393 fSysCallsActivateButton.setLayoutData(data);
394 fSysCallsActivateButton.addSelectionListener(new SelectionAdapter() {
395 @Override
396 public void widgetSelected(SelectionEvent e) {
397 setKernelEnablements(KernelGroupEnum.SYSCALLS);
398 }
399 });
400 }
401
402 /**
403 * Creates dynamic probe group.
404 */
405 private void createDynamicProbeGroup() {
406 GridLayout layout;
407 GridData data;
408 Group probeMainGroup = new Group(this, SWT.SHADOW_NONE);
409 probeMainGroup.setText(Messages.TraceControl_EnableEventsProbeGroupName);
410 layout = new GridLayout(2, false);
411 probeMainGroup.setLayout(layout);
412 data = new GridData(GridData.FILL_HORIZONTAL);
413 probeMainGroup.setLayoutData(data);
414
415 Composite buttonComposite = new Composite(probeMainGroup, SWT.NONE);
416 layout = new GridLayout(1, false);
417 buttonComposite.setLayout(layout);
418 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
419 buttonComposite.setLayoutData(data);
420
421 fProbeActivateButton = new Button(buttonComposite, SWT.RADIO);
422 fProbeActivateButton.setText(Messages.TraceControl_EnableGroupSelectionName);
423 fProbeActivateButton.setSelection(false);
424 data = new GridData(GridData.FILL_HORIZONTAL);
425 fProbeActivateButton.setLayoutData(data);
426 fProbeActivateButton.addSelectionListener(new SelectionAdapter() {
427 @Override
428 public void widgetSelected(SelectionEvent e) {
429 setKernelEnablements(KernelGroupEnum.PROBE);
430 }
431 });
432
433 Group probeGroup = new Group(probeMainGroup, SWT.SHADOW_NONE);
434 layout = new GridLayout(4, true);
435 probeGroup.setLayout(layout);
436 probeGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
437
438 Label probeNameLabel = new Label(probeGroup, SWT.LEFT);
439 probeNameLabel.setText(Messages.TraceControl_EnableEventsEventNameLabel);
440 data = new GridData(GridData.FILL_BOTH);
441 data.horizontalSpan = 1;
442 probeNameLabel.setLayoutData(data);
443
444 fProbeEventNameText = new Text(probeGroup, SWT.LEFT);
445 fProbeEventNameText.setToolTipText(Messages.TraceControl_EnableEventsProbeEventNameTooltip);
446
447 data = new GridData(GridData.FILL_BOTH);
448 data.horizontalSpan = 3;
449 fProbeEventNameText.setLayoutData(data);
450
451 Label probeLabel = new Label(probeGroup, SWT.LEFT);
452 probeLabel.setText(Messages.TraceControl_EnableEventsProbeNameLabel);
453 data = new GridData(GridData.FILL_BOTH);
454 data.horizontalSpan = 1;
455 probeLabel.setLayoutData(data);
456
457 fProbeText = new Text(probeGroup, SWT.LEFT);
458 fProbeText.setToolTipText(Messages.TraceControl_EnableEventsProbeNameTooltip);
459 data = new GridData(GridData.FILL_BOTH);
460 data.horizontalSpan = 3;
461 fProbeText.setLayoutData(data);
462 }
463
464 /**
465 * Creates dynamic function entry/return probe group.
466 */
467 private void createDynamicFunctionPropeGroup() {
468 GridLayout layout;
469 GridData data;
470 Group functionMainGroup = new Group(this, SWT.SHADOW_NONE);
471 functionMainGroup.setText(Messages.TraceControl_EnableEventsFucntionGroupName);
472 layout = new GridLayout(2, false);
473 functionMainGroup.setLayout(layout);
474 data = new GridData(GridData.FILL_HORIZONTAL);
475 functionMainGroup.setLayoutData(data);
476
477 Composite buttonComposite = new Composite(functionMainGroup, SWT.NONE);
478 layout = new GridLayout(1, false);
479 buttonComposite.setLayout(layout);
480 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
481 buttonComposite.setLayoutData(data);
482
483 fFunctionActivateButton = new Button(buttonComposite, SWT.RADIO);
484 fFunctionActivateButton.setText(Messages.TraceControl_EnableGroupSelectionName);
485 fFunctionActivateButton.setSelection(false);
486 data = new GridData(GridData.FILL_HORIZONTAL);
487 fFunctionActivateButton.setLayoutData(data);
488 fFunctionActivateButton.addSelectionListener(new SelectionAdapter() {
489 @Override
490 public void widgetSelected(SelectionEvent e) {
491 setKernelEnablements(KernelGroupEnum.FUNCTION);
492 }
493 });
494
495 Group functionGroup = new Group(functionMainGroup, SWT.SHADOW_NONE);
496 layout = new GridLayout(4, true);
497 functionGroup.setLayout(layout);
498 functionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
499
500 Label functionNameLabel = new Label(functionGroup, SWT.LEFT);
501 functionNameLabel.setText(Messages.TraceControl_EnableEventsEventNameLabel);
502 data = new GridData(GridData.FILL_BOTH);
503 data.horizontalSpan = 1;
504 functionNameLabel.setLayoutData(data);
505
506 fFunctionEventNameText = new Text(functionGroup, SWT.LEFT);
507 fFunctionEventNameText.setToolTipText(Messages.TraceControl_EnableEventsFunctionEventNameTooltip);
508 data = new GridData(GridData.FILL_BOTH);
509 data.horizontalSpan = 3;
510 fFunctionEventNameText.setLayoutData(data);
511
512 Label functionLabel = new Label(functionGroup, SWT.LEFT);
513 functionLabel.setText(Messages.TraceControl_EnableEventsFunctionNameLabel);
514 data = new GridData(GridData.FILL_BOTH);
515 data.horizontalSpan = 1;
516 functionLabel.setLayoutData(data);
517
518 fFunctionText = new Text(functionGroup, SWT.LEFT);
519 fFunctionText.setToolTipText(Messages.TraceControl_EnableEventsProbeNameTooltip);
520 data = new GridData(GridData.FILL_BOTH);
521 data.horizontalSpan = 3;
522 fFunctionText.setLayoutData(data);
523 }
524
525 /**
526 * Enable/selects widgets depending on the group specified.
527 * @param group - group to enable.
528 */
529 private void setKernelEnablements(KernelGroupEnum group) {
530 fTracepointsActivateButton.setSelection(group == KernelGroupEnum.TRACEPOINTS);
531 fTracepointsViewer.getTree().setEnabled(group == KernelGroupEnum.TRACEPOINTS);
532
533 fSysCallsActivateButton.setSelection(group == KernelGroupEnum.SYSCALLS);
534
535 fProbeActivateButton.setSelection(group == KernelGroupEnum.PROBE);
536 fProbeEventNameText.setEnabled(group == KernelGroupEnum.PROBE);
537 fProbeText.setEnabled(group == KernelGroupEnum.PROBE);
538
539 fFunctionActivateButton.setSelection(group == KernelGroupEnum.FUNCTION);
540 fFunctionEventNameText.setEnabled(group == KernelGroupEnum.FUNCTION);
541 fFunctionText.setEnabled(group == KernelGroupEnum.FUNCTION);
542 }
543
544 // ------------------------------------------------------------------------
545 // Local classes
546 // ------------------------------------------------------------------------
547 /**
548 * Content provider for the tracepoints tree.
549 */
550 public static final class KernelContentProvider extends TraceControlContentProvider {
551 @Override
552 public Object[] getChildren(Object parentElement) {
553 if (parentElement instanceof TraceProviderGroup) {
554 List<ITraceControlComponent> children = ((ITraceControlComponent)parentElement).getChildren(KernelProviderComponent.class);
555 return children.toArray(new ITraceControlComponent[children.size()]);
556 }
557 if (parentElement instanceof ITraceControlComponent) {
558 return ((ITraceControlComponent)parentElement).getChildren();
559 }
560 return new Object[0];
561 }
562 }
563
564 /**
565 * Content label for the tracepoints tree.
566 */
567 public static final class KernelLabelProvider extends TraceControlLabelProvider {
568 @Override
569 public Image getImage(Object element) {
570 return null;
571 }
572 @Override
573 public String getText(Object element) {
574 if ((element != null) && (element instanceof KernelProviderComponent)) {
575 return Messages.TraceControl_EnableEventsTracepointTreeAllLabel;
576 }
577 return super.getText(element);
578 }
579 }
580
581 /**
582 * Check state listener for the tracepoints tree.
583 */
584 public final class KernelCheckListener implements ICheckStateListener {
585 @Override
586 public void checkStateChanged(CheckStateChangedEvent event) {
587 if (event.getChecked()) {
588 if (event.getElement() instanceof KernelProviderComponent) {
589 fTracepointsViewer.setSubtreeChecked(event.getElement(), true);
590 }
591 } else {
592 if (event.getElement() instanceof KernelProviderComponent) {
593 fTracepointsViewer.setSubtreeChecked(event.getElement(), false);
594 } else {
595 ITraceControlComponent component = (ITraceControlComponent) event.getElement();
596 fTracepointsViewer.setChecked(component.getParent(), false);
597 }
598 }
599 }
600 }
601 }
This page took 0.044993 seconds and 5 git commands to generate.