Commit | Line | Data |
---|---|---|
ccc66d01 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.List; | |
15 | ||
16 | import org.eclipse.jface.dialogs.Dialog; | |
17 | import org.eclipse.jface.dialogs.IDialogConstants; | |
18 | import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; | |
19 | import org.eclipse.linuxtools.lttng.ui.views.control.Messages; | |
20 | import org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType; | |
21 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; | |
22 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceDomainComponent; | |
23 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceProviderGroup; | |
24 | import org.eclipse.swt.SWT; | |
25 | import org.eclipse.swt.events.SelectionAdapter; | |
26 | import org.eclipse.swt.events.SelectionEvent; | |
27 | import org.eclipse.swt.graphics.Point; | |
28 | import org.eclipse.swt.layout.GridData; | |
29 | import org.eclipse.swt.layout.GridLayout; | |
30 | import org.eclipse.swt.widgets.Button; | |
31 | import org.eclipse.swt.widgets.Composite; | |
32 | import org.eclipse.swt.widgets.Control; | |
33 | import org.eclipse.swt.widgets.Group; | |
34 | import org.eclipse.swt.widgets.Shell; | |
35 | ||
36 | /** | |
37 | * <b><u>EnableEventsDialog</u></b> | |
38 | * <p> | |
39 | * Dialog box for collecting information events to be enabled. | |
40 | * </p> | |
41 | */ | |
42 | public class EnableEventsDialog extends Dialog implements IEnableEventsDialog { | |
43 | ||
44 | // ------------------------------------------------------------------------ | |
45 | // Constants | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
48 | /** | |
49 | * The icon file for this dialog box. | |
50 | */ | |
51 | public static final String ENABLE_EVENT_ICON_FILE = "icons/elcl16/edit.gif"; //$NON-NLS-1$ | |
52 | ||
53 | // ------------------------------------------------------------------------ | |
54 | // Attributes | |
55 | // ------------------------------------------------------------------------ | |
56 | /** | |
57 | * The dialog composite. | |
58 | */ | |
59 | private Composite fDialogComposite; | |
60 | /** | |
61 | * The composite with widgets for collecting information about kernel events. | |
62 | */ | |
63 | private EnableKernelEventComposite fKernelComposite; | |
64 | /** | |
65 | * The composite with widgets for collecting information about UST events. | |
66 | */ | |
67 | private EnableUstEventsComposite fUstComposite; | |
68 | /** | |
69 | * Radio button for selecting kernel domain. | |
70 | */ | |
71 | private Button fKernelButton; | |
72 | /** | |
73 | * Radio button for selecting UST domain. | |
74 | */ | |
75 | private Button fUstButton; | |
76 | /** | |
77 | * The referenced trace provider group containing the kernel provider and UST | |
78 | * provider component which contains a list of available tracepoints. | |
79 | */ | |
80 | private TraceProviderGroup fProviderGroup; | |
81 | /** | |
82 | * The parent domain component where the channel node should be added. | |
83 | * Null in case the domain is not known (i.e. on session level). | |
84 | */ | |
85 | private TraceDomainComponent fDomain; | |
86 | /** | |
87 | * Output domain information. True in case of Kernel domain. False for UST. | |
88 | */ | |
89 | private boolean fIsKernel; | |
90 | ||
91 | // ------------------------------------------------------------------------ | |
92 | // Constructors | |
93 | // ------------------------------------------------------------------------ | |
94 | /** | |
95 | * Constructor | |
96 | * @param shell - a shell for the display of the dialog | |
97 | * @param providerGroup - the trace provider group | |
98 | */ | |
99 | public EnableEventsDialog(Shell shell, TraceProviderGroup providerGroup) { | |
100 | this(shell, providerGroup, null); | |
101 | } | |
102 | ||
103 | /** | |
104 | * Constructor | |
105 | * @param shell - a shell for the display of the dialog | |
106 | * @param providerGroup - a trace provider group | |
107 | * @param domain - a domain of the events (null if not known) | |
108 | */ | |
109 | public EnableEventsDialog(Shell shell, TraceProviderGroup providerGroup, TraceDomainComponent domain) { | |
110 | super(shell); | |
111 | fProviderGroup = providerGroup; | |
112 | setShellStyle(SWT.RESIZE); | |
113 | fDomain = domain; | |
114 | if (fDomain != null) { | |
115 | fIsKernel = fDomain.isKernel(); | |
116 | } else { | |
117 | fIsKernel = true; | |
118 | } | |
119 | } | |
120 | ||
121 | // ------------------------------------------------------------------------ | |
122 | // Accessors | |
123 | // ------------------------------------------------------------------------ | |
124 | ||
125 | /* | |
126 | * (non-Javadoc) | |
127 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#isTracpoints() | |
128 | */ | |
129 | @Override | |
130 | public boolean isTracepoints() { | |
131 | if (fIsKernel) { | |
132 | return fKernelComposite.isTracepoints(); | |
133 | } | |
134 | return fUstComposite.isTracepoints(); | |
135 | } | |
136 | ||
137 | /* (non-Javadoc) | |
138 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#isAllTracePoints() | |
139 | */ | |
140 | @Override | |
141 | public boolean isAllTracePoints() { | |
142 | if (fIsKernel) { | |
143 | return fKernelComposite.isAllTracePoints(); | |
144 | } | |
145 | return fUstComposite.isAllTracePoints(); | |
146 | } | |
147 | ||
148 | /* | |
149 | * (non-Javadoc) | |
150 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#isSysCalls() | |
151 | */ | |
152 | @Override | |
153 | public boolean isSysCalls() { | |
154 | if (fIsKernel) { | |
155 | return fKernelComposite.isSysCalls(); | |
156 | } | |
157 | return false; | |
158 | } | |
159 | ||
160 | /* (non-Javadoc) | |
161 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#isAllSysCalls() | |
162 | */ | |
163 | @Override | |
164 | public boolean isAllSysCalls() { | |
165 | if (fIsKernel) { | |
166 | return fKernelComposite.isSysCalls(); | |
167 | } | |
168 | return false; | |
169 | } | |
170 | ||
171 | /* (non-Javadoc) | |
172 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#getEventNames() | |
173 | */ | |
174 | @Override | |
175 | public List<String> getEventNames() { | |
176 | if (fIsKernel) { | |
177 | return fKernelComposite.getEventNames(); | |
178 | } | |
179 | return fUstComposite.getEventNames(); | |
180 | } | |
181 | /* | |
182 | * (non-Javadoc) | |
183 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#isDynamicProbe() | |
184 | */ | |
185 | @Override | |
186 | public boolean isDynamicProbe() { | |
187 | if (fIsKernel) { | |
188 | return fKernelComposite.isDynamicProbe(); | |
189 | } | |
190 | return false; | |
191 | } | |
192 | ||
193 | /* (non-Javadoc) | |
194 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#getProbeName() | |
195 | */ | |
196 | @Override | |
197 | public String getProbeName() { | |
198 | if (fIsKernel) { | |
199 | return fKernelComposite.getProbeName(); | |
200 | } | |
201 | return null; | |
202 | } | |
203 | ||
204 | /* (non-Javadoc) | |
205 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#getProbeEventName() | |
206 | */ | |
207 | @Override | |
208 | public String getProbeEventName() { | |
209 | if (fIsKernel) { | |
210 | return fKernelComposite.getProbeEventName(); | |
211 | } | |
212 | return null; | |
213 | } | |
214 | ||
215 | /* | |
216 | * (non-Javadoc) | |
217 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#isDynamicFunctionProbe() | |
218 | */ | |
219 | @Override | |
220 | public boolean isDynamicFunctionProbe() { | |
221 | if (fIsKernel) { | |
222 | return fKernelComposite.isDynamicFunctionProbe(); | |
223 | } | |
224 | return false; | |
225 | } | |
226 | ||
227 | /* (non-Javadoc) | |
228 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#getFunctionEventName() | |
229 | */ | |
230 | @Override | |
231 | public String getFunctionEventName() { | |
232 | if (fIsKernel) { | |
233 | return fKernelComposite.getFunctionEventName(); | |
234 | } | |
235 | return null; | |
236 | } | |
237 | ||
238 | /* | |
239 | * (non-Javadoc) | |
240 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableKernelEvents#getFunction() | |
241 | */ | |
242 | @Override | |
243 | public String getFunction() { | |
244 | if (fIsKernel) { | |
245 | return fKernelComposite.getFunction(); | |
246 | } | |
247 | return null; | |
248 | } | |
249 | ||
250 | /* | |
251 | * (non-Javadoc) | |
252 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableUstEvents#isWildcard() | |
253 | */ | |
254 | @Override | |
255 | public boolean isWildcard() { | |
256 | if (!fIsKernel) { | |
257 | return fUstComposite.isWildcard(); | |
258 | } | |
259 | return false; | |
260 | } | |
261 | ||
262 | /* | |
263 | * (non-Javadoc) | |
264 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableUstEvents#getWildcard() | |
265 | */ | |
266 | @Override | |
267 | public String getWildcard() { | |
268 | if (!fIsKernel) { | |
269 | return fUstComposite.getWildcard(); | |
270 | } | |
271 | return null; | |
272 | ||
273 | } | |
274 | ||
275 | /* | |
276 | * (non-Javadoc) | |
277 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableUstEvents#isLogLevel() | |
278 | */ | |
279 | @Override | |
280 | public boolean isLogLevel() { | |
281 | if (!fIsKernel) { | |
282 | return fUstComposite.isLogLevel(); | |
283 | } | |
284 | return false; | |
285 | ||
286 | } | |
287 | ||
288 | /* | |
289 | * (non-Javadoc) | |
290 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableUstEvents#getLogLevelType() | |
291 | */ | |
292 | @Override | |
293 | public LogLevelType getLogLevelType() { | |
294 | if (!fIsKernel) { | |
295 | return fUstComposite.getLogLevelType(); | |
296 | } | |
297 | return null; | |
298 | ||
299 | } | |
300 | ||
301 | /* | |
302 | * (non-Javadoc) | |
303 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableUstEvents#getLogLevel() | |
304 | */ | |
305 | @Override | |
306 | public TraceLogLevel getLogLevel() { | |
307 | if (!fIsKernel) { | |
308 | return fUstComposite.getLogLevel(); | |
309 | } | |
310 | return null; | |
311 | ||
312 | } | |
313 | ||
314 | /* | |
315 | * (non-Javadoc) | |
316 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableUstEvents#getLogLevelEventName() | |
317 | */ | |
318 | @Override | |
319 | public String getLogLevelEventName() { | |
320 | if (!fIsKernel) { | |
321 | return fUstComposite.getLogLevelEventName(); | |
322 | } | |
323 | return null; | |
324 | } | |
325 | ||
326 | /* | |
327 | * (non-Javadoc) | |
328 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableEventsDialog#isKernel() | |
329 | */ | |
330 | @Override | |
331 | public boolean isKernel() { | |
332 | return fIsKernel; | |
333 | } | |
334 | ||
335 | // ------------------------------------------------------------------------ | |
336 | // Operations | |
337 | // ------------------------------------------------------------------------ | |
338 | /* | |
339 | * (non-Javadoc) | |
340 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) | |
341 | */ | |
342 | @Override | |
343 | protected void configureShell(Shell newShell) { | |
344 | super.configureShell(newShell); | |
345 | newShell.setText(Messages.TraceControl_EnableEventsDialogTitle); | |
346 | newShell.setImage(LTTngUiPlugin.getDefault().loadIcon(ENABLE_EVENT_ICON_FILE)); | |
347 | } | |
348 | ||
349 | /* | |
350 | * (non-Javadoc) | |
351 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
352 | */ | |
353 | @Override | |
354 | protected Control createDialogArea(Composite parent) { | |
355 | ||
356 | // Main dialog panel | |
357 | fDialogComposite = new Composite(parent, SWT.NONE); | |
358 | GridLayout layout = new GridLayout(1, true); | |
359 | fDialogComposite.setLayout(layout); | |
360 | fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
361 | ||
362 | // ------------------------------------------------------------------------ | |
363 | // Domain Group | |
364 | // ------------------------------------------------------------------------ | |
365 | Group domainGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); | |
366 | domainGroup.setText(Messages.TraceControl_DomainDisplayName); | |
367 | layout = new GridLayout(2, true); | |
368 | domainGroup.setLayout(layout); | |
369 | ||
370 | fKernelButton = new Button(domainGroup, SWT.RADIO); | |
371 | fKernelButton.setText(Messages.TraceControl_KernelDomainDisplayName); | |
372 | fKernelButton.setSelection(fIsKernel); | |
373 | fUstButton = new Button(domainGroup, SWT.RADIO); | |
374 | fUstButton.setText(Messages.TraceControl_UstDisplayName); | |
375 | fUstButton.setSelection(!fIsKernel); | |
376 | ||
377 | if (fDomain != null) { | |
378 | fKernelButton.setEnabled(false); | |
379 | fUstButton.setEnabled(false); | |
380 | } | |
381 | ||
382 | // layout widgets | |
383 | GridData data = new GridData(GridData.FILL_HORIZONTAL); | |
384 | domainGroup.setLayoutData(data); | |
385 | ||
386 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
387 | fKernelButton.setLayoutData(data); | |
388 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
389 | fUstButton.setLayoutData(data); | |
390 | ||
391 | // ------------------------------------------------------------------------ | |
392 | // Kernel or UST event data group | |
393 | // ------------------------------------------------------------------------ | |
394 | if (fIsKernel) { | |
395 | createKernelComposite(); | |
396 | } else { | |
397 | createUstComposite(); | |
398 | } | |
399 | ||
400 | fKernelButton.addSelectionListener(new SelectionAdapter() { | |
401 | @Override | |
402 | public void widgetSelected(SelectionEvent e) { | |
403 | if (fKernelButton.getSelection()) { | |
404 | disposeUstComposite(); | |
405 | createKernelComposite(); | |
406 | fDialogComposite.layout(); | |
407 | } | |
408 | } | |
409 | }); | |
410 | ||
411 | fUstButton.addSelectionListener(new SelectionAdapter() { | |
412 | @Override | |
413 | public void widgetSelected(SelectionEvent e) { | |
414 | if (fUstButton.getSelection()) { | |
415 | disposeKernelComposite(); | |
416 | createUstComposite(); | |
417 | fDialogComposite.layout(); | |
418 | } | |
419 | } | |
420 | }); | |
421 | ||
422 | fDialogComposite.layout(); | |
423 | ||
424 | getShell().setMinimumSize(new Point(500, 650)); | |
425 | ||
426 | return fDialogComposite; | |
427 | } | |
428 | ||
429 | ||
430 | /* | |
431 | * (non-Javadoc) | |
432 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
433 | */ | |
434 | @Override | |
435 | protected void createButtonsForButtonBar(Composite parent) { | |
436 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ | |
437 | } | |
438 | ||
439 | /* | |
440 | * (non-Javadoc) | |
441 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
442 | */ | |
443 | @Override | |
444 | protected void okPressed() { | |
445 | if (fKernelButton.getSelection() == true) { | |
446 | fIsKernel = true; | |
447 | } else { | |
448 | fIsKernel = false; | |
449 | } | |
450 | ||
451 | // Validate kernel composite in case of kernel domain | |
452 | if (fKernelComposite != null && !fKernelComposite.isValid()) { | |
453 | return; | |
454 | } | |
455 | ||
456 | // Validate UST composite in case of UST domain | |
457 | if (fUstComposite != null && !fUstComposite.isValid()) { | |
458 | return; | |
459 | } | |
460 | ||
461 | // validation successful -> call super.okPressed() | |
462 | super.okPressed(); | |
463 | } | |
464 | ||
465 | // ------------------------------------------------------------------------ | |
466 | // Helper methods | |
467 | // ------------------------------------------------------------------------ | |
468 | /** | |
469 | * Creates the kernel composite (if not existing) | |
470 | */ | |
471 | private void createKernelComposite() { | |
472 | if (fKernelComposite == null) { | |
473 | fKernelComposite = new EnableKernelEventComposite(fDialogComposite, SWT.NONE, fProviderGroup); | |
474 | GridLayout layout = new GridLayout(1, true); | |
475 | fKernelComposite.setLayout(layout); | |
476 | fKernelComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
477 | ||
478 | fKernelComposite.createContent(); | |
479 | } | |
480 | } | |
481 | ||
482 | /** | |
483 | * Disposes the kernel composite (if existing) | |
484 | */ | |
485 | private void disposeKernelComposite() { | |
486 | if (fKernelComposite != null) { | |
487 | fKernelComposite.dispose(); | |
488 | fKernelComposite = null; | |
489 | } | |
490 | } | |
491 | ||
492 | /** | |
493 | * Creates the UST composite (if not existing) | |
494 | */ | |
495 | private void createUstComposite() { | |
496 | if (fUstComposite == null) { | |
497 | fUstComposite = new EnableUstEventsComposite(fDialogComposite, SWT.NONE, fProviderGroup); | |
498 | GridLayout layout = new GridLayout(1, true); | |
499 | fUstComposite.setLayout(layout); | |
500 | fUstComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
501 | ||
502 | fUstComposite.createContent(); | |
503 | } | |
504 | } | |
505 | ||
506 | /** | |
507 | * Disposes the UST composite (if existing) | |
508 | */ | |
509 | private void disposeUstComposite() { | |
510 | if (fUstComposite != null) { | |
511 | fUstComposite.dispose(); | |
512 | fUstComposite = null; | |
513 | } | |
514 | } | |
515 | } |