Commit | Line | Data |
---|---|---|
498704b3 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 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.views.control.dialogs; | |
13 | ||
14 | import java.util.ArrayList; | |
15 | import java.util.List; | |
16 | ||
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; | |
41 | ||
42 | /** | |
43 | * <b><u>EnableKernelEventDialog</u></b> | |
44 | * <p> | |
45 | * Dialog box for collecting information kernel events to be enabled. | |
46 | * </p> | |
47 | */ | |
48 | public class EnableKernelEventDialog extends Dialog implements IEnableKernelEventsDialog { | |
49 | ||
50 | // ------------------------------------------------------------------------ | |
51 | // Constants | |
52 | // ------------------------------------------------------------------------ | |
53 | /** | |
54 | * The icon file for this dialog box. | |
55 | */ | |
56 | public static final String ENABLE_EVENT_ICON_FILE = "icons/elcl16/edit.gif"; //$NON-NLS-1$ | |
57 | ||
58 | // ------------------------------------------------------------------------ | |
59 | // Attributes | |
60 | // ------------------------------------------------------------------------ | |
61 | /** | |
62 | * The dialog composite. | |
63 | */ | |
64 | private Composite fDialogComposite; | |
65 | /** | |
66 | * The goup for the list of available tracepoints. | |
67 | */ | |
68 | private Group fTracepointsGroup; | |
69 | /** | |
70 | * A tree viewer for diplaying and selection of available tracepoints. | |
71 | */ | |
72 | private CheckboxTreeViewer fTracepointsViewer; | |
73 | /** | |
74 | * The Group for Syscalls selection. | |
75 | */ | |
76 | private Group fSyscallGroup; | |
77 | /** | |
78 | * The button to enable or disable all syscalls | |
79 | */ | |
80 | private Button fSyscallButton; | |
81 | /** | |
82 | * The group for defining a dynamic probe. | |
83 | */ | |
84 | private Group fProbeGroup; | |
85 | /** | |
86 | * The text field for the event name for the dynamic probe. | |
87 | */ | |
88 | private Text fProbeEventNameText; | |
89 | /** | |
90 | * The text field for the dynamic probe. | |
91 | */ | |
92 | private Text fProbeText; | |
93 | /** | |
94 | * The group for defining a dynamic function probe. | |
95 | */ | |
96 | private Group fFunctionGroup; | |
97 | /** | |
98 | * The text field for the event name for the dynamic probe. | |
99 | */ | |
100 | private Text fFunctionEventNameText; | |
101 | /** | |
102 | * The text field for the dynamic function entry/return probe. | |
103 | */ | |
104 | private Text fFunctionText; | |
105 | /** | |
106 | * The referenced kernel provider component which contains a list of available tracepoints. | |
107 | */ | |
108 | private KernelProviderComponent fKernelProvider; | |
109 | /** | |
110 | * The flag indicating that all tracepoints are selected. | |
111 | */ | |
112 | private boolean fIsAllTracepoints; | |
113 | /** | |
114 | * The flag indicating that syscalls are selected. | |
115 | */ | |
116 | private boolean fIsAllSysCalls; | |
117 | /** | |
118 | * The list of tracepoints to be enabled. | |
119 | */ | |
120 | private List<String> fSelectedEvents; | |
121 | /** | |
122 | * The event name of the dynamic probe. | |
123 | */ | |
124 | private String fProbeEventName; | |
125 | /** | |
126 | * The dynamic probe. | |
127 | */ | |
128 | private String fProbeString; | |
129 | /** | |
130 | * The event name of the dynamic function entry/return probe. | |
131 | */ | |
132 | private String fFunctionEventName; | |
133 | /** | |
134 | * The dynamic function entry/return probe. | |
135 | */ | |
136 | private String fFunctionString; | |
137 | ||
138 | // ------------------------------------------------------------------------ | |
139 | // Constructors | |
140 | // ------------------------------------------------------------------------ | |
141 | ||
142 | /** | |
143 | * Constructor | |
144 | * @param shell - a shell for the display of the dialog | |
145 | * @param kernelProvider - the kernel provider component | |
146 | */ | |
147 | public EnableKernelEventDialog(Shell shell, KernelProviderComponent kernelProvider) { | |
148 | super(shell); | |
149 | fKernelProvider = kernelProvider; | |
150 | setShellStyle(SWT.RESIZE); | |
151 | } | |
152 | ||
153 | // ------------------------------------------------------------------------ | |
154 | // Accessors | |
155 | // ------------------------------------------------------------------------ | |
156 | ||
157 | /* (non-Javadoc) | |
158 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#isAllTracePoints() | |
159 | */ | |
160 | @Override | |
161 | public boolean isAllTracePoints() { | |
162 | return fIsAllTracepoints; | |
163 | } | |
164 | ||
165 | /* (non-Javadoc) | |
166 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#isAllSysCalls() | |
167 | */ | |
168 | @Override | |
169 | public boolean isAllSysCalls() { | |
170 | return fIsAllSysCalls; | |
171 | } | |
172 | ||
173 | /* (non-Javadoc) | |
174 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getEventNames() | |
175 | */ | |
176 | @Override | |
177 | public List<String> getEventNames() { | |
178 | return new ArrayList<String>(fSelectedEvents); | |
179 | } | |
180 | ||
181 | /* (non-Javadoc) | |
182 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getProbeName() | |
183 | */ | |
184 | @Override | |
185 | public String getProbeName() { | |
186 | return fProbeString; | |
187 | } | |
188 | ||
189 | /* (non-Javadoc) | |
190 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getProbeEventName() | |
191 | */ | |
192 | @Override | |
193 | public String getProbeEventName() { | |
194 | return fProbeEventName; | |
195 | } | |
196 | ||
197 | /* (non-Javadoc) | |
198 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getFunctionEventName() | |
199 | */ | |
200 | @Override | |
201 | public String getFunctionEventName() { | |
202 | return fFunctionEventName; | |
203 | } | |
204 | ||
205 | /* (non-Javadoc) | |
206 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEventsDialog#getFunction() | |
207 | */ | |
208 | @Override | |
209 | public String getFunction() { | |
210 | return fFunctionString; | |
211 | } | |
212 | ||
213 | // ------------------------------------------------------------------------ | |
214 | // Operations | |
215 | // ------------------------------------------------------------------------ | |
216 | /* | |
217 | * (non-Javadoc) | |
218 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) | |
219 | */ | |
220 | @Override | |
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)); | |
225 | } | |
226 | ||
227 | /* | |
228 | * (non-Javadoc) | |
229 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
230 | */ | |
231 | @Override | |
232 | protected Control createDialogArea(Composite parent) { | |
233 | ||
234 | // Main dialog panel | |
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)); | |
239 | ||
240 | // ------------------------------------------------------------------------ | |
241 | // Tracepoints Group | |
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); | |
249 | ||
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() { | |
253 | @Override | |
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()]); | |
258 | } | |
259 | if (parentElement instanceof ITraceControlComponent) { | |
260 | return ((ITraceControlComponent)parentElement).getChildren(); | |
261 | } | |
262 | return new Object[0]; | |
263 | } | |
264 | }); | |
265 | ||
266 | fTracepointsViewer.setLabelProvider(new TraceControlLabelProvider() { | |
267 | @Override | |
268 | public Image getImage(Object element) { | |
269 | return null; | |
270 | } | |
271 | @Override | |
272 | public String getText(Object element) { | |
273 | if ((element != null) && (element instanceof KernelProviderComponent)) { | |
274 | return Messages.TraceControl_EnableEventsTracepointTreeAllLabel; | |
275 | } | |
276 | return super.getText(element); | |
277 | } | |
278 | }); | |
279 | ||
280 | fTracepointsViewer.addCheckStateListener(new ICheckStateListener() { | |
281 | @Override | |
282 | public void checkStateChanged(CheckStateChangedEvent event) { | |
283 | if (event.getChecked()) { | |
284 | if (event.getElement() instanceof KernelProviderComponent) { | |
285 | fTracepointsViewer.setSubtreeChecked(event.getElement(), true); | |
286 | } | |
287 | } else { | |
288 | if (event.getElement() instanceof KernelProviderComponent) { | |
289 | fTracepointsViewer.setSubtreeChecked(event.getElement(), false); | |
290 | } else { | |
291 | ITraceControlComponent component = (ITraceControlComponent) event.getElement(); | |
292 | fTracepointsViewer.setChecked(component.getParent(), false); | |
293 | } | |
294 | } | |
295 | } | |
296 | }); | |
297 | ||
298 | fTracepointsViewer.setInput(fKernelProvider.getParent()); | |
299 | fTracepointsViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); | |
300 | ||
301 | // ------------------------------------------------------------------------ | |
302 | // Syscalls Group | |
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)); | |
308 | ||
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); | |
315 | ||
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)); | |
324 | ||
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); | |
330 | ||
331 | fProbeEventNameText = new Text(fProbeGroup, SWT.LEFT); | |
332 | fProbeEventNameText.setToolTipText(Messages.TraceControl_EnableEventsProbeEventNameTooltip); | |
333 | ||
334 | data = new GridData(GridData.FILL_BOTH); | |
335 | data.horizontalSpan = 3; | |
336 | fProbeEventNameText.setLayoutData(data); | |
337 | ||
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); | |
343 | ||
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); | |
349 | ||
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)); | |
358 | ||
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); | |
364 | ||
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); | |
370 | ||
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); | |
376 | ||
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); | |
382 | ||
383 | fDialogComposite.layout(); | |
384 | ||
385 | return fDialogComposite; | |
386 | } | |
387 | ||
388 | /* | |
389 | * (non-Javadoc) | |
390 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
391 | */ | |
392 | @Override | |
393 | protected void createButtonsForButtonBar(Composite parent) { | |
394 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ | |
395 | } | |
396 | ||
397 | /* | |
398 | * (non-Javadoc) | |
399 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
400 | */ | |
401 | @Override | |
402 | protected void okPressed() { | |
403 | fIsAllTracepoints = fTracepointsViewer.getChecked(fKernelProvider); | |
404 | fIsAllSysCalls = fSyscallButton.getSelection(); | |
405 | ||
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()); | |
411 | } | |
412 | } | |
413 | ||
414 | // initialize probe string | |
415 | fProbeEventName = null; | |
416 | fProbeString = 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$ | |
422 | ||
423 | return; | |
424 | } | |
425 | ||
426 | if(!fProbeText.getText().matches("\\s*")) { //$NON-NLS-1$ | |
427 | fProbeEventName = temp; | |
428 | // fProbeString will be validated by lttng-tools | |
429 | fProbeString = fProbeText.getText(); | |
430 | } | |
431 | ||
432 | // initialize function string | |
433 | fFunctionEventName = null; | |
434 | fFunctionString = null; | |
435 | ||
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$ | |
441 | ||
442 | return; | |
443 | } | |
444 | ||
445 | if(!fFunctionText.getText().matches("\\s*")) { //$NON-NLS-1$ | |
446 | fFunctionEventName = temp; | |
447 | // fFunctionString will be validated by lttng-tools | |
448 | fFunctionString = fFunctionText.getText(); | |
449 | } | |
450 | ||
451 | // validation successful -> call super.okPressed() | |
452 | super.okPressed(); | |
453 | } | |
454 | ||
455 | /* | |
456 | * (non-Javadoc) | |
457 | * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) | |
458 | */ | |
459 | @Override | |
460 | protected void buttonPressed(int buttonId) { | |
461 | super.buttonPressed(buttonId); | |
462 | } | |
463 | ||
464 | // ------------------------------------------------------------------------ | |
465 | // Helper methods | |
466 | // ------------------------------------------------------------------------ | |
467 | ||
468 | ||
469 | } |