| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012, 2013 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.linuxtools.internal.lttng2.ui.views.control.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.linuxtools.internal.lttng2.core.control.model.LogLevelType; |
| 20 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; |
| 21 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
| 22 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
| 23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent; |
| 24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProviderGroup; |
| 25 | import org.eclipse.swt.SWT; |
| 26 | import org.eclipse.swt.events.SelectionAdapter; |
| 27 | import org.eclipse.swt.events.SelectionEvent; |
| 28 | import org.eclipse.swt.graphics.Point; |
| 29 | import org.eclipse.swt.layout.GridData; |
| 30 | import org.eclipse.swt.layout.GridLayout; |
| 31 | import org.eclipse.swt.widgets.Button; |
| 32 | import org.eclipse.swt.widgets.Composite; |
| 33 | import org.eclipse.swt.widgets.Control; |
| 34 | import org.eclipse.swt.widgets.Group; |
| 35 | import org.eclipse.swt.widgets.Shell; |
| 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); |
| 103 | } |
| 104 | |
| 105 | // ------------------------------------------------------------------------ |
| 106 | // Accessors |
| 107 | // ------------------------------------------------------------------------ |
| 108 | |
| 109 | /* |
| 110 | * (non-Javadoc) |
| 111 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isTracpoints() |
| 112 | */ |
| 113 | @Override |
| 114 | public boolean isTracepoints() { |
| 115 | if (fIsKernel) { |
| 116 | return fKernelComposite.isTracepoints(); |
| 117 | } |
| 118 | return fUstComposite.isTracepoints(); |
| 119 | } |
| 120 | |
| 121 | /* (non-Javadoc) |
| 122 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isAllTracePoints() |
| 123 | */ |
| 124 | @Override |
| 125 | public boolean isAllTracePoints() { |
| 126 | if (fIsKernel) { |
| 127 | return fKernelComposite.isAllTracePoints(); |
| 128 | } |
| 129 | return fUstComposite.isAllTracePoints(); |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * (non-Javadoc) |
| 134 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isSysCalls() |
| 135 | */ |
| 136 | @Override |
| 137 | public boolean isSysCalls() { |
| 138 | if (fIsKernel) { |
| 139 | return fKernelComposite.isSysCalls(); |
| 140 | } |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | /* (non-Javadoc) |
| 145 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isAllSysCalls() |
| 146 | */ |
| 147 | @Override |
| 148 | public boolean isAllSysCalls() { |
| 149 | if (fIsKernel) { |
| 150 | return fKernelComposite.isSysCalls(); |
| 151 | } |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | /* (non-Javadoc) |
| 156 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getEventNames() |
| 157 | */ |
| 158 | @Override |
| 159 | public List<String> getEventNames() { |
| 160 | if (fIsKernel) { |
| 161 | return fKernelComposite.getEventNames(); |
| 162 | } |
| 163 | return fUstComposite.getEventNames(); |
| 164 | } |
| 165 | /* |
| 166 | * (non-Javadoc) |
| 167 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isDynamicProbe() |
| 168 | */ |
| 169 | @Override |
| 170 | public boolean isDynamicProbe() { |
| 171 | if (fIsKernel) { |
| 172 | return fKernelComposite.isDynamicProbe(); |
| 173 | } |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | /* (non-Javadoc) |
| 178 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getProbeName() |
| 179 | */ |
| 180 | @Override |
| 181 | public String getProbeName() { |
| 182 | if (fIsKernel) { |
| 183 | return fKernelComposite.getProbeName(); |
| 184 | } |
| 185 | return null; |
| 186 | } |
| 187 | |
| 188 | /* (non-Javadoc) |
| 189 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getProbeEventName() |
| 190 | */ |
| 191 | @Override |
| 192 | public String getProbeEventName() { |
| 193 | if (fIsKernel) { |
| 194 | return fKernelComposite.getProbeEventName(); |
| 195 | } |
| 196 | return null; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * (non-Javadoc) |
| 201 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isDynamicFunctionProbe() |
| 202 | */ |
| 203 | @Override |
| 204 | public boolean isDynamicFunctionProbe() { |
| 205 | if (fIsKernel) { |
| 206 | return fKernelComposite.isDynamicFunctionProbe(); |
| 207 | } |
| 208 | return false; |
| 209 | } |
| 210 | |
| 211 | /* (non-Javadoc) |
| 212 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getFunctionEventName() |
| 213 | */ |
| 214 | @Override |
| 215 | public String getFunctionEventName() { |
| 216 | if (fIsKernel) { |
| 217 | return fKernelComposite.getFunctionEventName(); |
| 218 | } |
| 219 | return null; |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * (non-Javadoc) |
| 224 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getFunction() |
| 225 | */ |
| 226 | @Override |
| 227 | public String getFunction() { |
| 228 | if (fIsKernel) { |
| 229 | return fKernelComposite.getFunction(); |
| 230 | } |
| 231 | return null; |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * (non-Javadoc) |
| 236 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableUstEvents#isWildcard() |
| 237 | */ |
| 238 | @Override |
| 239 | public boolean isWildcard() { |
| 240 | if (!fIsKernel) { |
| 241 | return fUstComposite.isWildcard(); |
| 242 | } |
| 243 | return false; |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | * (non-Javadoc) |
| 248 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableUstEvents#getWildcard() |
| 249 | */ |
| 250 | @Override |
| 251 | public String getWildcard() { |
| 252 | if (!fIsKernel) { |
| 253 | return fUstComposite.getWildcard(); |
| 254 | } |
| 255 | return null; |
| 256 | |
| 257 | } |
| 258 | |
| 259 | /* |
| 260 | * (non-Javadoc) |
| 261 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableUstEvents#isLogLevel() |
| 262 | */ |
| 263 | @Override |
| 264 | public boolean isLogLevel() { |
| 265 | if (!fIsKernel) { |
| 266 | return fUstComposite.isLogLevel(); |
| 267 | } |
| 268 | return false; |
| 269 | |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * (non-Javadoc) |
| 274 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableUstEvents#getLogLevelType() |
| 275 | */ |
| 276 | @Override |
| 277 | public LogLevelType getLogLevelType() { |
| 278 | if (!fIsKernel) { |
| 279 | return fUstComposite.getLogLevelType(); |
| 280 | } |
| 281 | return null; |
| 282 | |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * (non-Javadoc) |
| 287 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableUstEvents#getLogLevel() |
| 288 | */ |
| 289 | @Override |
| 290 | public TraceLogLevel getLogLevel() { |
| 291 | if (!fIsKernel) { |
| 292 | return fUstComposite.getLogLevel(); |
| 293 | } |
| 294 | return null; |
| 295 | |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * (non-Javadoc) |
| 300 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableUstEvents#getLogLevelEventName() |
| 301 | */ |
| 302 | @Override |
| 303 | public String getLogLevelEventName() { |
| 304 | if (!fIsKernel) { |
| 305 | return fUstComposite.getLogLevelEventName(); |
| 306 | } |
| 307 | return null; |
| 308 | } |
| 309 | |
| 310 | /* |
| 311 | * (non-Javadoc) |
| 312 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#isKernel() |
| 313 | */ |
| 314 | @Override |
| 315 | public boolean isKernel() { |
| 316 | return fIsKernel; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * (non-Javadoc) |
| 321 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#setTraceProviderGroup(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProviderGroup) |
| 322 | */ |
| 323 | @Override |
| 324 | public void setTraceProviderGroup(TraceProviderGroup providerGroup) { |
| 325 | fProviderGroup = providerGroup; |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | * (non-Javadoc) |
| 330 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#setTraceDomainComponent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent) |
| 331 | */ |
| 332 | @Override |
| 333 | public void setTraceDomainComponent(TraceDomainComponent domain) { |
| 334 | fDomain = domain; |
| 335 | if (fDomain != null) { |
| 336 | fIsKernel = fDomain.isKernel(); |
| 337 | } else { |
| 338 | fIsKernel = fProviderGroup != null ? fProviderGroup.hasKernelProvider() : true; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | * (non-Javadoc) |
| 344 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableUstEvents#getFilterExpression() |
| 345 | */ |
| 346 | @Override |
| 347 | public String getFilterExpression() { |
| 348 | if (!fIsKernel) { |
| 349 | return fUstComposite.getFilterExpression(); |
| 350 | } |
| 351 | return null; |
| 352 | } |
| 353 | |
| 354 | // ------------------------------------------------------------------------ |
| 355 | // Operations |
| 356 | // ------------------------------------------------------------------------ |
| 357 | /* |
| 358 | * (non-Javadoc) |
| 359 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) |
| 360 | */ |
| 361 | @Override |
| 362 | protected void configureShell(Shell newShell) { |
| 363 | super.configureShell(newShell); |
| 364 | newShell.setText(Messages.TraceControl_EnableEventsDialogTitle); |
| 365 | newShell.setImage(Activator.getDefault().loadIcon(ENABLE_EVENT_ICON_FILE)); |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * (non-Javadoc) |
| 370 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
| 371 | */ |
| 372 | @Override |
| 373 | protected Control createDialogArea(Composite parent) { |
| 374 | |
| 375 | // Main dialog panel |
| 376 | fDialogComposite = new Composite(parent, SWT.NONE); |
| 377 | GridLayout layout = new GridLayout(1, true); |
| 378 | fDialogComposite.setLayout(layout); |
| 379 | fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 380 | |
| 381 | // ------------------------------------------------------------------------ |
| 382 | // Domain Group |
| 383 | // ------------------------------------------------------------------------ |
| 384 | Group domainGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); |
| 385 | domainGroup.setText(Messages.TraceControl_DomainDisplayName); |
| 386 | layout = new GridLayout(2, true); |
| 387 | domainGroup.setLayout(layout); |
| 388 | |
| 389 | fKernelButton = new Button(domainGroup, SWT.RADIO); |
| 390 | fKernelButton.setText(Messages.TraceControl_KernelDomainDisplayName); |
| 391 | fKernelButton.setSelection(fIsKernel); |
| 392 | fUstButton = new Button(domainGroup, SWT.RADIO); |
| 393 | fUstButton.setText(Messages.TraceControl_UstDisplayName); |
| 394 | fUstButton.setSelection(!fIsKernel); |
| 395 | |
| 396 | if ((fDomain != null) || ((fProviderGroup != null) && (!fProviderGroup.hasKernelProvider()))) { |
| 397 | fKernelButton.setEnabled(false); |
| 398 | fUstButton.setEnabled(false); |
| 399 | } |
| 400 | |
| 401 | // layout widgets |
| 402 | GridData data = new GridData(GridData.FILL_HORIZONTAL); |
| 403 | domainGroup.setLayoutData(data); |
| 404 | |
| 405 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 406 | fKernelButton.setLayoutData(data); |
| 407 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 408 | fUstButton.setLayoutData(data); |
| 409 | |
| 410 | // ------------------------------------------------------------------------ |
| 411 | // Kernel or UST event data group |
| 412 | // ------------------------------------------------------------------------ |
| 413 | fUstComposite = null; |
| 414 | fKernelComposite = null; |
| 415 | if (fIsKernel) { |
| 416 | createKernelComposite(); |
| 417 | fUstComposite = null; |
| 418 | } else { |
| 419 | createUstComposite(); |
| 420 | } |
| 421 | |
| 422 | fKernelButton.addSelectionListener(new SelectionAdapter() { |
| 423 | @Override |
| 424 | public void widgetSelected(SelectionEvent e) { |
| 425 | if (fKernelButton.getSelection()) { |
| 426 | disposeUstComposite(); |
| 427 | createKernelComposite(); |
| 428 | fDialogComposite.layout(); |
| 429 | } |
| 430 | } |
| 431 | }); |
| 432 | |
| 433 | fUstButton.addSelectionListener(new SelectionAdapter() { |
| 434 | @Override |
| 435 | public void widgetSelected(SelectionEvent e) { |
| 436 | if (fUstButton.getSelection()) { |
| 437 | disposeKernelComposite(); |
| 438 | createUstComposite(); |
| 439 | fDialogComposite.layout(); |
| 440 | } |
| 441 | } |
| 442 | }); |
| 443 | |
| 444 | fDialogComposite.layout(); |
| 445 | |
| 446 | getShell().setMinimumSize(new Point(500, 650)); |
| 447 | |
| 448 | return fDialogComposite; |
| 449 | } |
| 450 | |
| 451 | |
| 452 | /* |
| 453 | * (non-Javadoc) |
| 454 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) |
| 455 | */ |
| 456 | @Override |
| 457 | protected void createButtonsForButtonBar(Composite parent) { |
| 458 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ |
| 459 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
| 460 | } |
| 461 | |
| 462 | /* |
| 463 | * (non-Javadoc) |
| 464 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() |
| 465 | */ |
| 466 | @Override |
| 467 | protected void okPressed() { |
| 468 | fIsKernel = fKernelButton.getSelection(); |
| 469 | |
| 470 | // Validate kernel composite in case of kernel domain |
| 471 | if (fKernelComposite != null && !fKernelComposite.isValid()) { |
| 472 | return; |
| 473 | } |
| 474 | |
| 475 | // Validate UST composite in case of UST domain |
| 476 | if (fUstComposite != null && !fUstComposite.isValid()) { |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | // validation successful -> call super.okPressed() |
| 481 | super.okPressed(); |
| 482 | } |
| 483 | |
| 484 | // ------------------------------------------------------------------------ |
| 485 | // Helper methods |
| 486 | // ------------------------------------------------------------------------ |
| 487 | /** |
| 488 | * Creates the kernel composite (if not existing) |
| 489 | */ |
| 490 | private void createKernelComposite() { |
| 491 | if (fKernelComposite == null) { |
| 492 | fKernelComposite = new EnableKernelEventComposite(fDialogComposite, SWT.NONE, fProviderGroup); |
| 493 | GridLayout layout = new GridLayout(1, true); |
| 494 | fKernelComposite.setLayout(layout); |
| 495 | fKernelComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 496 | |
| 497 | fKernelComposite.createContent(); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Disposes the kernel composite (if existing) |
| 503 | */ |
| 504 | private void disposeKernelComposite() { |
| 505 | if (fKernelComposite != null) { |
| 506 | fKernelComposite.dispose(); |
| 507 | fKernelComposite = null; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Creates the UST composite (if not existing) |
| 513 | */ |
| 514 | private void createUstComposite() { |
| 515 | if (fUstComposite == null) { |
| 516 | fUstComposite = new EnableUstEventsComposite(fDialogComposite, SWT.NONE, fProviderGroup); |
| 517 | GridLayout layout = new GridLayout(1, true); |
| 518 | fUstComposite.setLayout(layout); |
| 519 | fUstComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 520 | |
| 521 | fUstComposite.createContent(); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Disposes the UST composite (if existing) |
| 527 | */ |
| 528 | private void disposeUstComposite() { |
| 529 | if (fUstComposite != null) { |
| 530 | fUstComposite.dispose(); |
| 531 | fUstComposite = null; |
| 532 | } |
| 533 | } |
| 534 | } |