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