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