| 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 | * Simon Delisle - Updated for support of LTTng Tools 2.2 |
| 12 | **********************************************************************/ |
| 13 | package org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs; |
| 14 | |
| 15 | import org.eclipse.jface.dialogs.Dialog; |
| 16 | import org.eclipse.jface.dialogs.IDialogConstants; |
| 17 | import org.eclipse.jface.dialogs.MessageDialog; |
| 18 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.IChannelInfo; |
| 19 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.BufferType; |
| 20 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.ChannelInfo; |
| 21 | import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator; |
| 22 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages; |
| 23 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent; |
| 24 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent; |
| 25 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.LTTngControlServiceConstants; |
| 26 | import org.eclipse.swt.SWT; |
| 27 | import org.eclipse.swt.events.FocusEvent; |
| 28 | import org.eclipse.swt.events.FocusListener; |
| 29 | import org.eclipse.swt.events.SelectionAdapter; |
| 30 | import org.eclipse.swt.events.SelectionEvent; |
| 31 | import org.eclipse.swt.events.VerifyEvent; |
| 32 | import org.eclipse.swt.events.VerifyListener; |
| 33 | import org.eclipse.swt.layout.GridData; |
| 34 | import org.eclipse.swt.layout.GridLayout; |
| 35 | import org.eclipse.swt.widgets.Button; |
| 36 | import org.eclipse.swt.widgets.Composite; |
| 37 | import org.eclipse.swt.widgets.Control; |
| 38 | import org.eclipse.swt.widgets.Group; |
| 39 | import org.eclipse.swt.widgets.Label; |
| 40 | import org.eclipse.swt.widgets.Shell; |
| 41 | import org.eclipse.swt.widgets.Text; |
| 42 | |
| 43 | /** |
| 44 | * <p> |
| 45 | * Dialog box for collecting channel information when enabling a channel (which will be created). |
| 46 | * </p> |
| 47 | * |
| 48 | * @author Bernd Hufmann |
| 49 | */ |
| 50 | public class EnableChannelDialog extends Dialog implements IEnableChannelDialog { |
| 51 | |
| 52 | // ------------------------------------------------------------------------ |
| 53 | // Constants |
| 54 | // ------------------------------------------------------------------------ |
| 55 | /** |
| 56 | * The icon file for this dialog box. |
| 57 | */ |
| 58 | public static final String ENABLE_CHANNEL_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$ |
| 59 | |
| 60 | /** |
| 61 | * To indicate that the default value will be used for this field |
| 62 | */ |
| 63 | private static final String DEFAULT_TEXT = "<" + Messages.EnableChannelDialog_DefaultMessage + ">"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 64 | |
| 65 | // ------------------------------------------------------------------------ |
| 66 | // Attributes |
| 67 | // ------------------------------------------------------------------------ |
| 68 | /** |
| 69 | * The text widget for the channel name |
| 70 | */ |
| 71 | private Text fChannelNameText = null; |
| 72 | /** |
| 73 | * The discard mode of the channel. |
| 74 | */ |
| 75 | private Button fDiscardModeButton = null; |
| 76 | /** |
| 77 | * The overwrite mode of the channel. |
| 78 | */ |
| 79 | private Button fOverwriteModeButton = null; |
| 80 | /** |
| 81 | * The sub-buffer size of the channel. |
| 82 | */ |
| 83 | private Text fSubBufferSizeText = null; |
| 84 | /** |
| 85 | * The number of sub-buffers of the channel. |
| 86 | */ |
| 87 | private Text fNumberOfSubBuffersText = null; |
| 88 | /** |
| 89 | * The switch timer interval of the channel. |
| 90 | */ |
| 91 | private Text fSwitchTimerText = null; |
| 92 | /** |
| 93 | * The read timer interval of the channel. |
| 94 | */ |
| 95 | private Text fReadTimerText = null; |
| 96 | /** |
| 97 | * Radio button for selecting kernel domain. |
| 98 | */ |
| 99 | private Button fKernelButton = null; |
| 100 | /** |
| 101 | * Radio button for selecting UST domain. |
| 102 | */ |
| 103 | private Button fUstButton = null; |
| 104 | /** |
| 105 | * The parent domain component where the channel node should be added. |
| 106 | * Null in case of creation on session level. |
| 107 | */ |
| 108 | private TraceDomainComponent fDomain = null; |
| 109 | /** |
| 110 | * The target node component |
| 111 | */ |
| 112 | private TargetNodeComponent fTargetNodeComponent = null; |
| 113 | /** |
| 114 | * Common verify listener for numeric text input. |
| 115 | */ |
| 116 | private VerifyListener fVerifyListener = null; |
| 117 | /** |
| 118 | * Common focus listener |
| 119 | */ |
| 120 | private FocusListener fFocusListener = null; |
| 121 | /** |
| 122 | * Output channel information. |
| 123 | */ |
| 124 | private IChannelInfo fChannelInfo = null; |
| 125 | /** |
| 126 | * Output domain information. True in case of Kernel domain. False for UST. |
| 127 | */ |
| 128 | private boolean fIsKernel; |
| 129 | /** |
| 130 | * Flag which indicates whether Kernel domain is available or not |
| 131 | */ |
| 132 | private boolean fHasKernel; |
| 133 | /** |
| 134 | * Maximum size of trace files of the channel. |
| 135 | */ |
| 136 | private Text fMaxSizeTraceText = null; |
| 137 | /** |
| 138 | * Maximum number of trace files of the channel. |
| 139 | */ |
| 140 | private Text fMaxNumberTraceText = null; |
| 141 | /** |
| 142 | * CheckBox for selecting shared buffers (kernel onlyu). |
| 143 | */ |
| 144 | private Button fSharedBuffersButton = null; |
| 145 | /** |
| 146 | * CheckBox for selecting per UID buffers. |
| 147 | */ |
| 148 | private Button fPIDBuffersButton = null; |
| 149 | /** |
| 150 | * CheckBox for selecting per UID buffers. |
| 151 | */ |
| 152 | private Button fUIDBuffersButton = null; |
| 153 | /** |
| 154 | * CheckBox to configure metadata channel |
| 155 | */ |
| 156 | private Button fMetadataChannelButton = null; |
| 157 | /** |
| 158 | * Previous channel name |
| 159 | */ |
| 160 | private String fPreviousChannelName = null; |
| 161 | |
| 162 | // ------------------------------------------------------------------------ |
| 163 | // Constructors |
| 164 | // ------------------------------------------------------------------------ |
| 165 | |
| 166 | /** |
| 167 | * Constructor |
| 168 | * @param shell - a shell for the display of the dialog |
| 169 | */ |
| 170 | public EnableChannelDialog(Shell shell) { |
| 171 | super(shell); |
| 172 | fIsKernel = true; |
| 173 | |
| 174 | // Common verify listener |
| 175 | fVerifyListener = new VerifyListener() { |
| 176 | @Override |
| 177 | public void verifyText(VerifyEvent e) { |
| 178 | // only numbers and default are allowed. |
| 179 | e.doit = e.text.matches("[0-9]*") || e.text.matches(DEFAULT_TEXT); //$NON-NLS-1$ |
| 180 | } |
| 181 | }; |
| 182 | |
| 183 | // Common focus listener |
| 184 | fFocusListener = new FocusListener() { |
| 185 | |
| 186 | @Override |
| 187 | public void focusLost(FocusEvent e) { |
| 188 | Text focusLostWidget = (Text) e.widget; |
| 189 | if (focusLostWidget.getText().isEmpty()) { |
| 190 | focusLostWidget.setText(DEFAULT_TEXT); |
| 191 | focusLostWidget.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY)); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void focusGained(FocusEvent e) { |
| 197 | Text focusGainedWidget = (Text) e.widget; |
| 198 | if (focusGainedWidget.getText().equals(DEFAULT_TEXT)) { |
| 199 | focusGainedWidget.setText(""); //$NON-NLS-1$ |
| 200 | focusGainedWidget.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK)); |
| 201 | } |
| 202 | } |
| 203 | }; |
| 204 | |
| 205 | setShellStyle(SWT.RESIZE | getShellStyle()); |
| 206 | } |
| 207 | |
| 208 | // ------------------------------------------------------------------------ |
| 209 | // Accessors |
| 210 | // ------------------------------------------------------------------------ |
| 211 | |
| 212 | @Override |
| 213 | public IChannelInfo getChannelInfo() { |
| 214 | return fChannelInfo; |
| 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public void setDomainComponent(TraceDomainComponent domain) { |
| 219 | fDomain = domain; |
| 220 | if (fDomain != null) { |
| 221 | fIsKernel = fDomain.isKernel(); |
| 222 | } else { |
| 223 | fIsKernel = true; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public boolean isKernel() { |
| 229 | return fIsKernel; |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public void setHasKernel(boolean hasKernel) { |
| 234 | if (fDomain != null) { |
| 235 | fIsKernel = fDomain.isKernel(); |
| 236 | } else { |
| 237 | fIsKernel = hasKernel; |
| 238 | } |
| 239 | |
| 240 | fHasKernel = hasKernel; |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public void setTargetNodeComponent(TargetNodeComponent node) { |
| 245 | fTargetNodeComponent = node; |
| 246 | } |
| 247 | |
| 248 | // ------------------------------------------------------------------------ |
| 249 | // Operations |
| 250 | // ------------------------------------------------------------------------ |
| 251 | |
| 252 | @Override |
| 253 | protected void configureShell(Shell newShell) { |
| 254 | super.configureShell(newShell); |
| 255 | newShell.setText(Messages.TraceControl_EnableChannelDialogTitle); |
| 256 | newShell.setImage(Activator.getDefault().loadIcon(ENABLE_CHANNEL_ICON_FILE)); |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | protected Control createDialogArea(Composite parent) { |
| 261 | |
| 262 | int numColumn = 2; |
| 263 | if (fTargetNodeComponent.isBufferTypeConfigSupported()) { |
| 264 | numColumn = 3; |
| 265 | } |
| 266 | |
| 267 | // Main dialog panel |
| 268 | Composite dialogComposite = new Composite(parent, SWT.NONE); |
| 269 | GridLayout layout = new GridLayout(1, true); |
| 270 | dialogComposite.setLayout(layout); |
| 271 | |
| 272 | Composite commonModeGroup = new Composite(dialogComposite, SWT.NONE); |
| 273 | layout = new GridLayout(3, true); |
| 274 | commonModeGroup.setLayout(layout); |
| 275 | |
| 276 | Label channelNameLabel = new Label(commonModeGroup, SWT.RIGHT); |
| 277 | channelNameLabel.setText(Messages.TraceControl_EnableChannelNameLabel); |
| 278 | fChannelNameText = new Text(commonModeGroup, SWT.NONE); |
| 279 | fChannelNameText.setToolTipText(Messages.TraceControl_EnableChannelNameTooltip); |
| 280 | |
| 281 | Label subBufferSizeLabel = new Label(commonModeGroup, SWT.RIGHT); |
| 282 | subBufferSizeLabel.setText(Messages.TraceControl_SubBufferSizePropertyName); |
| 283 | fSubBufferSizeText = new Text(commonModeGroup, SWT.NONE); |
| 284 | fSubBufferSizeText.setToolTipText(Messages.TraceControl_EnableChannelSubBufferSizeTooltip); |
| 285 | fSubBufferSizeText.addVerifyListener(fVerifyListener); |
| 286 | fSubBufferSizeText.addFocusListener(fFocusListener); |
| 287 | fSubBufferSizeText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY)); |
| 288 | |
| 289 | Label numSubBufferLabel = new Label(commonModeGroup, SWT.RIGHT); |
| 290 | numSubBufferLabel.setText(Messages.TraceControl_NbSubBuffersPropertyName); |
| 291 | fNumberOfSubBuffersText = new Text(commonModeGroup, SWT.NONE); |
| 292 | fNumberOfSubBuffersText.setToolTipText(Messages.TraceControl_EnableChannelNbSubBuffersTooltip); |
| 293 | fNumberOfSubBuffersText.addVerifyListener(fVerifyListener); |
| 294 | fNumberOfSubBuffersText.addFocusListener(fFocusListener); |
| 295 | |
| 296 | Label switchTimerLabel = new Label(commonModeGroup, SWT.RIGHT); |
| 297 | switchTimerLabel.setText(Messages.TraceControl_SwitchTimerPropertyName); |
| 298 | fSwitchTimerText = new Text(commonModeGroup, SWT.NONE); |
| 299 | fSwitchTimerText.setToolTipText(Messages.TraceControl_EnableChannelSwitchTimerTooltip); |
| 300 | fSwitchTimerText.addVerifyListener(fVerifyListener); |
| 301 | fSwitchTimerText.addFocusListener(fFocusListener); |
| 302 | |
| 303 | Label readTimerLabel = new Label(commonModeGroup, SWT.RIGHT); |
| 304 | readTimerLabel.setText(Messages.TraceControl_ReadTimerPropertyName); |
| 305 | fReadTimerText = new Text(commonModeGroup, SWT.NONE); |
| 306 | fReadTimerText.setToolTipText(Messages.TraceControl_EnableChannelReadTimerTooltip); |
| 307 | fReadTimerText.addVerifyListener(fVerifyListener); |
| 308 | fReadTimerText.addFocusListener(fFocusListener); |
| 309 | |
| 310 | if (fTargetNodeComponent.isTraceFileRotationSupported()) { |
| 311 | Label maxSizeTraceFilesLabel = new Label(commonModeGroup, SWT.RIGHT); |
| 312 | maxSizeTraceFilesLabel.setText(Messages.TraceControl_MaxSizeTraceFilesPropertyName); |
| 313 | fMaxSizeTraceText = new Text(commonModeGroup, SWT.NONE); |
| 314 | fMaxSizeTraceText.setToolTipText(Messages.TraceControl_EnbleChannelMaxSizeTraceFilesTooltip); |
| 315 | fMaxSizeTraceText.addVerifyListener(fVerifyListener); |
| 316 | fMaxSizeTraceText.addFocusListener(fFocusListener); |
| 317 | |
| 318 | Label maxNumTraceFilesLabel = new Label(commonModeGroup, SWT.RIGHT); |
| 319 | maxNumTraceFilesLabel.setText(Messages.TraceControl_MaxNumTraceFilesPropertyName); |
| 320 | fMaxNumberTraceText = new Text(commonModeGroup, SWT.NONE); |
| 321 | fMaxNumberTraceText.setToolTipText(Messages.TraceControl_EnbleChannelMaxNumTraceFilesTooltip); |
| 322 | fMaxNumberTraceText.addVerifyListener(fVerifyListener); |
| 323 | fMaxNumberTraceText.addFocusListener(fFocusListener); |
| 324 | } |
| 325 | |
| 326 | if (fTargetNodeComponent.isPeriodicalMetadataFlushSupported()) { |
| 327 | fMetadataChannelButton = new Button(commonModeGroup, SWT.CHECK); |
| 328 | fMetadataChannelButton.setText(Messages.TraceControl_ConfigureMetadataChannelName); |
| 329 | fMetadataChannelButton.setSelection(false); |
| 330 | |
| 331 | fMetadataChannelButton.addSelectionListener(new SelectionAdapter() { |
| 332 | @Override |
| 333 | public void widgetSelected(SelectionEvent e) { |
| 334 | if (fMetadataChannelButton.getSelection()) { |
| 335 | fPreviousChannelName = fChannelNameText.getText(); |
| 336 | fChannelNameText.setText("metadata"); //$NON-NLS-1$ |
| 337 | fChannelNameText.setEnabled(false); |
| 338 | } else { |
| 339 | fChannelNameText.setText(fPreviousChannelName); |
| 340 | fChannelNameText.setEnabled(true); |
| 341 | } |
| 342 | } |
| 343 | }); |
| 344 | } |
| 345 | Group discardModeGroup = new Group(dialogComposite, SWT.SHADOW_NONE); |
| 346 | discardModeGroup.setText(Messages.TraceControl_EnableChannelDiscardModeGroupName); |
| 347 | layout = new GridLayout(numColumn, true); |
| 348 | discardModeGroup.setLayout(layout); |
| 349 | |
| 350 | fDiscardModeButton = new Button(discardModeGroup, SWT.RADIO); |
| 351 | fDiscardModeButton.setText(Messages.TraceControl_EnableChannelDiscardModeLabel); |
| 352 | fDiscardModeButton.setToolTipText(Messages.TraceControl_EnableChannelDiscardModeTooltip); |
| 353 | fDiscardModeButton.setSelection(true); |
| 354 | |
| 355 | fOverwriteModeButton = new Button(discardModeGroup, SWT.RADIO); |
| 356 | fOverwriteModeButton.setText(Messages.TraceControl_EnableChannelOverwriteModeLabel); |
| 357 | fOverwriteModeButton.setToolTipText(Messages.TraceControl_EnableChannelOverwriteModeTooltip); |
| 358 | fOverwriteModeButton.setSelection(false); |
| 359 | |
| 360 | Group domainGroup = new Group(dialogComposite, SWT.SHADOW_NONE); |
| 361 | domainGroup.setText(Messages.TraceControl_DomainDisplayName); |
| 362 | layout = new GridLayout(numColumn, true); |
| 363 | domainGroup.setLayout(layout); |
| 364 | |
| 365 | fKernelButton = new Button(domainGroup, SWT.RADIO); |
| 366 | fKernelButton.setText(Messages.TraceControl_KernelDomainDisplayName); |
| 367 | fKernelButton.setSelection(fIsKernel); |
| 368 | fUstButton = new Button(domainGroup, SWT.RADIO); |
| 369 | fUstButton.setText(Messages.TraceControl_UstDisplayName); |
| 370 | fUstButton.setSelection(!fIsKernel); |
| 371 | |
| 372 | if (fTargetNodeComponent.isBufferTypeConfigSupported()) { |
| 373 | Group bufferTypeGroup = new Group(dialogComposite, SWT.SHADOW_NONE); |
| 374 | bufferTypeGroup.setText(Messages.TraceControl_BufferTypeDisplayName); |
| 375 | layout = new GridLayout(numColumn, true); |
| 376 | bufferTypeGroup.setLayout(layout); |
| 377 | |
| 378 | GridData data = new GridData(GridData.FILL, GridData.BEGINNING, false, false); |
| 379 | data.horizontalSpan = 3; |
| 380 | bufferTypeGroup.setLayoutData(data); |
| 381 | |
| 382 | fSharedBuffersButton = new Button(bufferTypeGroup, SWT.RADIO); |
| 383 | fSharedBuffersButton.setText(Messages.TraceControl_SharedBuffersDisplayName); |
| 384 | fSharedBuffersButton.setSelection(fIsKernel); |
| 385 | fSharedBuffersButton.setEnabled(false); |
| 386 | |
| 387 | fPIDBuffersButton = new Button(bufferTypeGroup, SWT.RADIO); |
| 388 | fPIDBuffersButton.setText(Messages.TraceControl_PerPidBuffersDisplayName); |
| 389 | fPIDBuffersButton.setToolTipText(Messages.TraceControl_PerPidBuffersTooltip); |
| 390 | fPIDBuffersButton.setSelection(false); |
| 391 | |
| 392 | fUIDBuffersButton = new Button(bufferTypeGroup, SWT.RADIO); |
| 393 | fUIDBuffersButton.setText(Messages.TraceControl_PerUidBuffersDisplayName); |
| 394 | fUIDBuffersButton.setToolTipText(Messages.TraceControl_PerPidBuffersTooltip); |
| 395 | fUIDBuffersButton.setSelection(false); |
| 396 | |
| 397 | fUIDBuffersButton.setEnabled(!fIsKernel); |
| 398 | fPIDBuffersButton.setEnabled(!fIsKernel); |
| 399 | |
| 400 | // Update buffers type buttons depending on UST or Kernel |
| 401 | fUstButton.addSelectionListener(new SelectionAdapter() { |
| 402 | @Override |
| 403 | public void widgetSelected(SelectionEvent e) { |
| 404 | if (fUstButton.getSelection()) { |
| 405 | fSharedBuffersButton.setSelection(false); |
| 406 | fPIDBuffersButton.setSelection(false); |
| 407 | fUIDBuffersButton.setSelection(false); |
| 408 | fPIDBuffersButton.setEnabled(true); |
| 409 | fUIDBuffersButton.setEnabled(true); |
| 410 | } else { |
| 411 | fSharedBuffersButton.setSelection(true); |
| 412 | fPIDBuffersButton.setSelection(false); |
| 413 | fUIDBuffersButton.setSelection(false); |
| 414 | fPIDBuffersButton.setEnabled(false); |
| 415 | fUIDBuffersButton.setEnabled(false); |
| 416 | } |
| 417 | } |
| 418 | }); |
| 419 | } |
| 420 | |
| 421 | if ((fDomain != null) || (!fHasKernel)) { |
| 422 | fKernelButton.setEnabled(false); |
| 423 | fUstButton.setEnabled(false); |
| 424 | |
| 425 | if (fTargetNodeComponent.isBufferTypeConfigSupported()) { |
| 426 | fSharedBuffersButton.setEnabled(false); |
| 427 | fUIDBuffersButton.setEnabled(!fHasKernel); |
| 428 | fPIDBuffersButton.setEnabled(!fHasKernel); |
| 429 | setBufferTypeButtonSelection(); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | // layout widgets |
| 434 | GridData data = new GridData(GridData.FILL, GridData.BEGINNING, false, false); |
| 435 | data.horizontalSpan = 3; |
| 436 | discardModeGroup.setLayoutData(data); |
| 437 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 438 | fDiscardModeButton.setLayoutData(data); |
| 439 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 440 | fOverwriteModeButton.setLayoutData(data); |
| 441 | |
| 442 | data = new GridData(GridData.FILL, GridData.BEGINNING, false, false); |
| 443 | data.horizontalSpan = 3; |
| 444 | domainGroup.setLayoutData(data); |
| 445 | |
| 446 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 447 | fKernelButton.setLayoutData(data); |
| 448 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 449 | fUstButton.setLayoutData(data); |
| 450 | if (fTargetNodeComponent.isBufferTypeConfigSupported()) { |
| 451 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 452 | fSharedBuffersButton.setLayoutData(data); |
| 453 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 454 | fPIDBuffersButton.setLayoutData(data); |
| 455 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 456 | fUIDBuffersButton.setLayoutData(data); |
| 457 | } |
| 458 | |
| 459 | if (fTargetNodeComponent.isPeriodicalMetadataFlushSupported()) { |
| 460 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); |
| 461 | data.horizontalSpan = numColumn; |
| 462 | fMetadataChannelButton.setLayoutData(data); |
| 463 | } |
| 464 | |
| 465 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 466 | data.horizontalSpan = 2; |
| 467 | |
| 468 | fChannelNameText.setLayoutData(data); |
| 469 | fSubBufferSizeText.setLayoutData(data); |
| 470 | fNumberOfSubBuffersText.setLayoutData(data); |
| 471 | fSwitchTimerText.setLayoutData(data); |
| 472 | fReadTimerText.setLayoutData(data); |
| 473 | if (fTargetNodeComponent.isTraceFileRotationSupported()) { |
| 474 | fMaxNumberTraceText.setLayoutData(data); |
| 475 | fMaxSizeTraceText.setLayoutData(data); |
| 476 | } |
| 477 | |
| 478 | setDefaults(); |
| 479 | |
| 480 | return dialogComposite; |
| 481 | } |
| 482 | |
| 483 | @Override |
| 484 | protected void createButtonsForButtonBar(Composite parent) { |
| 485 | createButton(parent, IDialogConstants.DETAILS_ID, "&Default", true); //$NON-NLS-1$ |
| 486 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ |
| 487 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | protected void okPressed() { |
| 492 | // Set channel information |
| 493 | ChannelInfo channelInfo = new ChannelInfo(fChannelNameText.getText()); |
| 494 | channelInfo.setSubBufferSize(fSubBufferSizeText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fSubBufferSizeText.getText())); |
| 495 | channelInfo.setNumberOfSubBuffers(fNumberOfSubBuffersText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fNumberOfSubBuffersText.getText())); |
| 496 | channelInfo.setSwitchTimer(fSwitchTimerText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fSwitchTimerText.getText())); |
| 497 | channelInfo.setReadTimer(fReadTimerText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fReadTimerText.getText())); |
| 498 | channelInfo.setOverwriteMode(fOverwriteModeButton.getSelection()); |
| 499 | if (fTargetNodeComponent.isTraceFileRotationSupported()) { |
| 500 | channelInfo.setMaxSizeTraceFiles(fMaxSizeTraceText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fMaxSizeTraceText.getText())); |
| 501 | channelInfo.setMaxNumberTraceFiles(fMaxNumberTraceText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fMaxNumberTraceText.getText())); |
| 502 | } |
| 503 | if (fTargetNodeComponent.isBufferTypeConfigSupported()) { |
| 504 | if (fSharedBuffersButton.getSelection()) { |
| 505 | channelInfo.setBufferType(BufferType.BUFFER_SHARED); |
| 506 | } else if (fPIDBuffersButton.getSelection()) { |
| 507 | channelInfo.setBufferType(BufferType.BUFFER_PER_PID); |
| 508 | } else if (fUIDBuffersButton.getSelection()) { |
| 509 | channelInfo.setBufferType(BufferType.BUFFER_PER_UID); |
| 510 | } else { |
| 511 | channelInfo.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | fIsKernel = fKernelButton.getSelection(); |
| 516 | |
| 517 | // Check for invalid names |
| 518 | if (!channelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ |
| 519 | MessageDialog.openError(getShell(), |
| 520 | Messages.TraceControl_EnableChannelDialogTitle, |
| 521 | Messages.TraceControl_InvalidChannelNameError + " (" + channelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | // Check for duplicate names |
| 526 | if (fDomain != null && fDomain.containsChild(channelInfo.getName())) { |
| 527 | MessageDialog.openError(getShell(), |
| 528 | Messages.TraceControl_EnableChannelDialogTitle, |
| 529 | Messages.TraceControl_ChannelAlreadyExistsError + " (" + channelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | fChannelInfo = channelInfo; |
| 534 | |
| 535 | // validation successful -> call super.okPressed() |
| 536 | super.okPressed(); |
| 537 | } |
| 538 | |
| 539 | @Override |
| 540 | protected void buttonPressed(int buttonId) { |
| 541 | if (buttonId == IDialogConstants.DETAILS_ID) { |
| 542 | setDefaults(); |
| 543 | return; |
| 544 | } |
| 545 | super.buttonPressed(buttonId); |
| 546 | } |
| 547 | |
| 548 | // ------------------------------------------------------------------------ |
| 549 | // Helper methods |
| 550 | // ------------------------------------------------------------------------ |
| 551 | |
| 552 | /** |
| 553 | * Sets default value depending on Kernel or UST |
| 554 | */ |
| 555 | private void setDefaults() { |
| 556 | fSwitchTimerText.setText(DEFAULT_TEXT); |
| 557 | fSwitchTimerText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY)); |
| 558 | fReadTimerText.setText(DEFAULT_TEXT); |
| 559 | fReadTimerText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY)); |
| 560 | fOverwriteModeButton.setSelection(IChannelInfo.DEFAULT_OVERWRITE_MODE); |
| 561 | if (fTargetNodeComponent.isTraceFileRotationSupported()) { |
| 562 | fMaxSizeTraceText.setText(DEFAULT_TEXT); |
| 563 | fMaxSizeTraceText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY)); |
| 564 | fMaxNumberTraceText.setText(DEFAULT_TEXT); |
| 565 | fMaxNumberTraceText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY)); |
| 566 | } |
| 567 | fSubBufferSizeText.setText(DEFAULT_TEXT); |
| 568 | fSubBufferSizeText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY)); |
| 569 | fNumberOfSubBuffersText.setText(DEFAULT_TEXT); |
| 570 | fNumberOfSubBuffersText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY)); |
| 571 | if (fTargetNodeComponent.isBufferTypeConfigSupported()) { |
| 572 | setBufferTypeButtonSelection(); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | private void setBufferTypeButtonSelection() { |
| 577 | if ((fDomain != null) && fDomain.getBufferType() != null) { |
| 578 | switch (fDomain.getBufferType()) { |
| 579 | case BUFFER_PER_PID: |
| 580 | fPIDBuffersButton.setSelection(true); |
| 581 | break; |
| 582 | case BUFFER_PER_UID: |
| 583 | fUIDBuffersButton.setSelection(true); |
| 584 | break; |
| 585 | case BUFFER_SHARED: |
| 586 | fSharedBuffersButton.setSelection(true); |
| 587 | break; |
| 588 | //$CASES-OMITTED$ |
| 589 | default: |
| 590 | break; |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | } |