| 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 | |
| 14 | package org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs; |
| 15 | |
| 16 | import org.eclipse.core.runtime.NullProgressMonitor; |
| 17 | import org.eclipse.jface.dialogs.IDialogConstants; |
| 18 | import org.eclipse.jface.dialogs.TitleAreaDialog; |
| 19 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo; |
| 20 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SessionInfo; |
| 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.TraceSessionGroup; |
| 25 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.IRemoteSystemProxy; |
| 26 | import org.eclipse.rse.services.clientserver.messages.SystemMessageException; |
| 27 | import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem; |
| 28 | import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; |
| 29 | import org.eclipse.swt.SWT; |
| 30 | import org.eclipse.swt.custom.CCombo; |
| 31 | import org.eclipse.swt.events.ModifyEvent; |
| 32 | import org.eclipse.swt.events.ModifyListener; |
| 33 | import org.eclipse.swt.events.SelectionAdapter; |
| 34 | import org.eclipse.swt.events.SelectionEvent; |
| 35 | import org.eclipse.swt.layout.GridData; |
| 36 | import org.eclipse.swt.layout.GridLayout; |
| 37 | import org.eclipse.swt.widgets.Button; |
| 38 | import org.eclipse.swt.widgets.Composite; |
| 39 | import org.eclipse.swt.widgets.Control; |
| 40 | import org.eclipse.swt.widgets.Group; |
| 41 | import org.eclipse.swt.widgets.Label; |
| 42 | import org.eclipse.swt.widgets.Shell; |
| 43 | import org.eclipse.swt.widgets.Text; |
| 44 | |
| 45 | /** |
| 46 | * <p> |
| 47 | * Dialog box for collecting session creation information. |
| 48 | * </p> |
| 49 | * |
| 50 | * @author Bernd Hufmann |
| 51 | */ |
| 52 | public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessionDialog { |
| 53 | |
| 54 | // ------------------------------------------------------------------------ |
| 55 | // Constants |
| 56 | // ------------------------------------------------------------------------ |
| 57 | /** |
| 58 | * The icon file for this dialog box. |
| 59 | */ |
| 60 | public static final String CREATE_SESSION_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$ |
| 61 | |
| 62 | /** |
| 63 | * Supported network protocols for streaming |
| 64 | */ |
| 65 | private enum StreamingProtocol { |
| 66 | /** Default network protocol for IPv4 (TCP)*/ |
| 67 | net, |
| 68 | /** Default network protocol for IPv6 (TCP)*/ |
| 69 | net6, |
| 70 | /** File */ |
| 71 | file, |
| 72 | } |
| 73 | |
| 74 | private enum StreamingProtocol2 { |
| 75 | /** Default network protocol for IPv4 (TCP)*/ |
| 76 | net, |
| 77 | /** Default network protocol for IPv6 (TCP)*/ |
| 78 | net6, |
| 79 | /** TCP network protocol for IPv4*/ |
| 80 | tcp, |
| 81 | /** TCP network protocol for IPv6*/ |
| 82 | tcp6 } |
| 83 | |
| 84 | /** |
| 85 | * Index of last supported streaming protocol for common URL configuration. |
| 86 | */ |
| 87 | private static final int COMMON_URL_LAST_INDEX = 1; |
| 88 | /** |
| 89 | * Index of default streaming protocol. |
| 90 | */ |
| 91 | private static final int DEFAULT_URL_INDEX = 0; |
| 92 | |
| 93 | // ------------------------------------------------------------------------ |
| 94 | // Attributes |
| 95 | // ------------------------------------------------------------------------ |
| 96 | /** |
| 97 | * The dialog composite. |
| 98 | */ |
| 99 | private Composite fDialogComposite = null; |
| 100 | /** |
| 101 | * The text widget for the session name |
| 102 | */ |
| 103 | private Text fSessionNameText = null; |
| 104 | /** |
| 105 | * The label widget for the session path. |
| 106 | */ |
| 107 | private Label fSessionPathLabel = null; |
| 108 | /** |
| 109 | * The text widget for the session path. |
| 110 | */ |
| 111 | private Text fSessionPathText = null; |
| 112 | /** |
| 113 | * The button widget to select a snapshot session |
| 114 | */ |
| 115 | private Button fSnapshotButton = null; |
| 116 | /** |
| 117 | * The Group for stream configuration. |
| 118 | */ |
| 119 | private Group fMainStreamingGroup = null; |
| 120 | /** |
| 121 | * The button to show streaming options. |
| 122 | */ |
| 123 | private Button fConfigureStreamingButton = null; |
| 124 | /** |
| 125 | * The composite with streaming configuration parameter. |
| 126 | */ |
| 127 | private Composite fStreamingComposite = null; |
| 128 | /** |
| 129 | * The text widget for the trace path. |
| 130 | */ |
| 131 | private Text fTracePathText = null; |
| 132 | /** |
| 133 | * The button to link data protocol/Address with control protocol. |
| 134 | */ |
| 135 | private Button fLinkDataWithControlButton = null; |
| 136 | /** |
| 137 | * The Combo box for channel protocol selection. |
| 138 | */ |
| 139 | private CCombo fControlProtocolCombo = null; |
| 140 | /** |
| 141 | * A selection listener that copies the protocol from control to data when being linked. |
| 142 | */ |
| 143 | private ControlProtocolSelectionListener fCopyProtocolSelectionListener; |
| 144 | /** |
| 145 | * A selection listener updates the control port text depending on the control protocol selected. |
| 146 | */ |
| 147 | private ProtocolComboSelectionListener fControlProtocolSelectionListener; |
| 148 | /** |
| 149 | * A selection listener updates the data port text depending on the data protocol selected. |
| 150 | */ |
| 151 | private ProtocolComboSelectionListener fDataProtocolSelectionListener; |
| 152 | /** |
| 153 | * The text box for the host/IP address of the control channel. |
| 154 | */ |
| 155 | private Text fControlHostAddressText = null; |
| 156 | /** |
| 157 | * A key listener that copies the host address from control to data when being linked. |
| 158 | */ |
| 159 | private CopyModifyListener fControlUrlKeyListener; |
| 160 | /** |
| 161 | * A modify listener that updates the enablement of the dialog. |
| 162 | */ |
| 163 | private UpdateEnablementModifyListener fUpdateEnablementModifyListener; |
| 164 | /** |
| 165 | * The text box for the control port. |
| 166 | */ |
| 167 | private Text fControlPortText = null; |
| 168 | /** |
| 169 | * The Combo box for data protocol selection. |
| 170 | */ |
| 171 | private CCombo fDataProtocolCombo = null; |
| 172 | /** |
| 173 | * The text box for the host/IP address of the data channel. |
| 174 | */ |
| 175 | private Text fDataHostAddressText = null; |
| 176 | /** |
| 177 | * The text box for the data port. |
| 178 | */ |
| 179 | private Text fDataPortText = null; |
| 180 | /** |
| 181 | * The parent where the new node should be added. |
| 182 | */ |
| 183 | private TraceSessionGroup fParent = null; |
| 184 | /** |
| 185 | * The session name string. |
| 186 | */ |
| 187 | private String fSessionName = null; |
| 188 | /** |
| 189 | * The session path string. |
| 190 | */ |
| 191 | private String fSessionPath = null; |
| 192 | /** |
| 193 | * Flag whether the session is snapshot or not |
| 194 | */ |
| 195 | private boolean fIsSnapshot = false; |
| 196 | /** |
| 197 | * Flag whether default location (path) shall be used or not |
| 198 | */ |
| 199 | private boolean fIsDefaultPath = true; |
| 200 | /** |
| 201 | * Flag whether the trace is streamed or not |
| 202 | */ |
| 203 | private boolean fIsStreamedTrace = false; |
| 204 | /** |
| 205 | * The network URL in case control and data is configured together. |
| 206 | * If set, fControlUrl and fDataUrl will be null. |
| 207 | */ |
| 208 | private String fNetworkUrl = null; |
| 209 | /** |
| 210 | * The control URL in case control and data is configured separately. |
| 211 | * If set, fDataUrl will be set too and fNetworkUrl will be null. |
| 212 | */ |
| 213 | private String fControlUrl = null; |
| 214 | /** |
| 215 | * The data URL in case control and data is configured separately. |
| 216 | * If set, fControlUrl will be set too and fNetworkUrl will be null. |
| 217 | */ |
| 218 | private String fDataUrl = null; |
| 219 | /** |
| 220 | * The trace path string. |
| 221 | */ |
| 222 | private String fTracePath = null; |
| 223 | |
| 224 | // ------------------------------------------------------------------------ |
| 225 | // Constructors |
| 226 | // ------------------------------------------------------------------------ |
| 227 | /** |
| 228 | * Constructor |
| 229 | * @param shell - a shell for the display of the dialog |
| 230 | */ |
| 231 | public CreateSessionDialog(Shell shell) { |
| 232 | super(shell); |
| 233 | setShellStyle(SWT.RESIZE | getShellStyle()); |
| 234 | } |
| 235 | |
| 236 | // ------------------------------------------------------------------------ |
| 237 | // Accessors |
| 238 | // ------------------------------------------------------------------------ |
| 239 | |
| 240 | @Override |
| 241 | public void initialize(TraceSessionGroup group) { |
| 242 | fParent = group; |
| 243 | fStreamingComposite = null; |
| 244 | fSessionName = null; |
| 245 | fSessionPath = null; |
| 246 | fIsSnapshot = false; |
| 247 | fIsDefaultPath = true; |
| 248 | fIsStreamedTrace = false; |
| 249 | fNetworkUrl = null; |
| 250 | fControlUrl = null; |
| 251 | fDataUrl = null; |
| 252 | } |
| 253 | // ------------------------------------------------------------------------ |
| 254 | // Operations |
| 255 | // ------------------------------------------------------------------------ |
| 256 | |
| 257 | @Override |
| 258 | protected void configureShell(Shell newShell) { |
| 259 | super.configureShell(newShell); |
| 260 | newShell.setText(Messages.TraceControl_CreateSessionDialogTitle); |
| 261 | newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE)); |
| 262 | } |
| 263 | |
| 264 | @Override |
| 265 | protected Control createDialogArea(Composite parent) { |
| 266 | Composite dialogAreaa = (Composite) super.createDialogArea(parent); |
| 267 | setTitle(Messages.TraceControl_CreateSessionDialogTitle); |
| 268 | setMessage(Messages.TraceControl_CreateSessionDialogMessage); |
| 269 | |
| 270 | // Main dialog panel |
| 271 | fDialogComposite = new Composite(dialogAreaa, SWT.NONE); |
| 272 | GridLayout layout = new GridLayout(1, true); |
| 273 | fDialogComposite.setLayout(layout); |
| 274 | fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 275 | |
| 276 | Group sessionGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); |
| 277 | sessionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 278 | sessionGroup.setLayout(new GridLayout(4, true)); |
| 279 | |
| 280 | fUpdateEnablementModifyListener = new UpdateEnablementModifyListener(); |
| 281 | |
| 282 | Label sessionNameLabel = new Label(sessionGroup, SWT.RIGHT); |
| 283 | sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel); |
| 284 | fSessionNameText = new Text(sessionGroup, SWT.NONE); |
| 285 | fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip); |
| 286 | fSessionNameText.addModifyListener(fUpdateEnablementModifyListener); |
| 287 | |
| 288 | fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT); |
| 289 | fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel); |
| 290 | fSessionPathText = new Text(sessionGroup, SWT.NONE); |
| 291 | fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip); |
| 292 | fSessionPathText.addModifyListener(fUpdateEnablementModifyListener); |
| 293 | |
| 294 | if (fParent.isSnapshotSupported()) { |
| 295 | fSnapshotButton = new Button(sessionGroup, SWT.CHECK); |
| 296 | fSnapshotButton.setText(Messages.TraceControl_CreateSessionSnapshotLabel); |
| 297 | fSnapshotButton.setToolTipText(Messages.TraceControl_CreateSessionSnapshotTooltip); |
| 298 | GridData data = new GridData(GridData.FILL_HORIZONTAL); |
| 299 | data.horizontalSpan = 4; |
| 300 | fSnapshotButton.setData(data); |
| 301 | } |
| 302 | |
| 303 | // layout widgets |
| 304 | GridData data = new GridData(GridData.FILL_HORIZONTAL); |
| 305 | data.horizontalSpan = 3; |
| 306 | |
| 307 | fSessionNameText.setLayoutData(data); |
| 308 | |
| 309 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 310 | data.horizontalSpan = 3; |
| 311 | fSessionPathText.setLayoutData(data); |
| 312 | |
| 313 | if (fParent.isNetworkStreamingSupported()) { |
| 314 | createAdvancedOptionsComposite(); |
| 315 | } |
| 316 | |
| 317 | return fDialogComposite; |
| 318 | } |
| 319 | |
| 320 | private void createAdvancedOptionsComposite() { |
| 321 | |
| 322 | fMainStreamingGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); |
| 323 | fMainStreamingGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 324 | fMainStreamingGroup.setLayout(new GridLayout(1, true)); |
| 325 | |
| 326 | fConfigureStreamingButton = new Button(fMainStreamingGroup, SWT.PUSH); |
| 327 | fConfigureStreamingButton.setText(Messages.TraceControl_CreateSessionConfigureStreamingButtonText + " >>>"); //$NON-NLS-1$ |
| 328 | fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip); |
| 329 | fConfigureStreamingButton.addSelectionListener(new SelectionAdapter() { |
| 330 | @Override |
| 331 | public void widgetSelected(SelectionEvent e) { |
| 332 | if (fIsStreamedTrace) { |
| 333 | fIsStreamedTrace = false; |
| 334 | fConfigureStreamingButton.setText(">>> " + Messages.TraceControl_CreateSessionConfigureStreamingButtonText); //$NON-NLS-1$ |
| 335 | fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip); |
| 336 | fSessionPathText.setEnabled(true); |
| 337 | fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel); |
| 338 | disposeConfigureStreamingComposite(); |
| 339 | } else { |
| 340 | fIsStreamedTrace = true; |
| 341 | fConfigureStreamingButton.setText("<<< " + Messages.TraceControl_CreateSessionNoStreamingButtonText); //$NON-NLS-1$ |
| 342 | fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionNoStreamingButtonTooltip); |
| 343 | fSessionPathText.setEnabled(false); |
| 344 | fSessionPathText.setText(""); //$NON-NLS-1$ |
| 345 | fSessionPathLabel.setText(""); //$NON-NLS-1$ |
| 346 | createConfigureStreamingComposite(); |
| 347 | } |
| 348 | |
| 349 | updateEnablement(); |
| 350 | getShell().pack(); |
| 351 | } |
| 352 | }); |
| 353 | } |
| 354 | |
| 355 | private void createConfigureStreamingComposite() { |
| 356 | if (fStreamingComposite == null) { |
| 357 | fStreamingComposite = new Composite(fMainStreamingGroup, SWT.NONE); |
| 358 | GridLayout layout = new GridLayout(1, true); |
| 359 | fStreamingComposite.setLayout(layout); |
| 360 | fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 361 | |
| 362 | Group urlGroup = new Group(fStreamingComposite, SWT.SHADOW_NONE); |
| 363 | layout = new GridLayout(7, true); |
| 364 | urlGroup.setLayout(layout); |
| 365 | urlGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 366 | |
| 367 | Label tracePathLabel = new Label(urlGroup, SWT.RIGHT); |
| 368 | tracePathLabel.setText(Messages.TraceControl_CreateSessionTracePathText); |
| 369 | fTracePathText = new Text(urlGroup, SWT.NONE); |
| 370 | fTracePathText.setToolTipText(Messages.TraceControl_CreateSessionTracePathTooltip); |
| 371 | |
| 372 | // layout widgets |
| 373 | GridData data = new GridData(GridData.FILL_HORIZONTAL); |
| 374 | data.horizontalSpan = 6; |
| 375 | fTracePathText.setLayoutData(data); |
| 376 | fTracePathText.addModifyListener(fUpdateEnablementModifyListener); |
| 377 | |
| 378 | fLinkDataWithControlButton = new Button(urlGroup, SWT.CHECK); |
| 379 | fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText); |
| 380 | fLinkDataWithControlButton.setToolTipText(Messages.TraceControl_CreateSessionLinkButtonTooltip); |
| 381 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 382 | data.horizontalSpan = 7; |
| 383 | fLinkDataWithControlButton.setLayoutData(data); |
| 384 | fLinkDataWithControlButton.setSelection(true); |
| 385 | |
| 386 | Label label = new Label(urlGroup, SWT.NONE); |
| 387 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 388 | data.horizontalSpan = 1; |
| 389 | label.setLayoutData(data); |
| 390 | |
| 391 | label = new Label(urlGroup, SWT.NONE); |
| 392 | label.setText(Messages.TraceControl_CreateSessionProtocolLabelText); |
| 393 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 394 | data.horizontalSpan = 1; |
| 395 | label.setLayoutData(data); |
| 396 | |
| 397 | label = new Label(urlGroup, SWT.NONE); |
| 398 | label.setText(Messages.TraceControl_CreateSessionAddressLabelText); |
| 399 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 400 | data.horizontalSpan = 4; |
| 401 | label.setLayoutData(data); |
| 402 | |
| 403 | label = new Label(urlGroup, SWT.NONE); |
| 404 | label.setText(Messages.TraceControl_CreateSessionPortLabelText); |
| 405 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 406 | data.horizontalSpan = 1; |
| 407 | label.setLayoutData(data); |
| 408 | |
| 409 | label = new Label(urlGroup, SWT.RIGHT); |
| 410 | label.setText(Messages.TraceControl_CreateSessionControlUrlLabel); |
| 411 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 412 | data.horizontalSpan = 1; |
| 413 | label.setLayoutData(data); |
| 414 | |
| 415 | fControlProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY); |
| 416 | fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip); |
| 417 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 418 | data.horizontalSpan = 1; |
| 419 | fControlProtocolCombo.setLayoutData(data); |
| 420 | fControlProtocolCombo.addModifyListener(fUpdateEnablementModifyListener); |
| 421 | |
| 422 | fControlHostAddressText = new Text(urlGroup, SWT.NONE); |
| 423 | fControlHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionControlAddressTooltip); |
| 424 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 425 | data.horizontalSpan = 4; |
| 426 | fControlHostAddressText.setLayoutData(data); |
| 427 | fControlHostAddressText.addModifyListener(fUpdateEnablementModifyListener); |
| 428 | |
| 429 | fControlPortText = new Text(urlGroup, SWT.NONE); |
| 430 | fControlPortText.setToolTipText(Messages.TraceControl_CreateSessionControlPortTooltip); |
| 431 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 432 | data.horizontalSpan = 1; |
| 433 | fControlPortText.setLayoutData(data); |
| 434 | fControlPortText.addModifyListener(fUpdateEnablementModifyListener); |
| 435 | |
| 436 | label = new Label(urlGroup, SWT.RIGHT); |
| 437 | label.setText(Messages.TraceControl_CreateSessionDataUrlLabel); |
| 438 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 439 | data.horizontalSpan = 1; |
| 440 | label.setLayoutData(data); |
| 441 | |
| 442 | fDataProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY); |
| 443 | fDataProtocolCombo.setEnabled(false); |
| 444 | fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip); |
| 445 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 446 | data.horizontalSpan = 1; |
| 447 | fDataProtocolCombo.setLayoutData(data); |
| 448 | fDataProtocolCombo.addModifyListener(fUpdateEnablementModifyListener); |
| 449 | |
| 450 | String items[] = new String[StreamingProtocol.values().length]; |
| 451 | for (int i = 0; i < items.length; i++) { |
| 452 | items[i] = StreamingProtocol.values()[i].name(); |
| 453 | } |
| 454 | fControlProtocolCombo.setItems(items); |
| 455 | fDataProtocolCombo.setItems(items); |
| 456 | |
| 457 | fDataHostAddressText = new Text(urlGroup, SWT.NONE); |
| 458 | fDataHostAddressText.setEnabled(false); |
| 459 | fDataHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionDataAddressTooltip); |
| 460 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 461 | data.horizontalSpan = 4; |
| 462 | fDataHostAddressText.setLayoutData(data); |
| 463 | fDataHostAddressText.addModifyListener(fUpdateEnablementModifyListener); |
| 464 | |
| 465 | fDataPortText = new Text(urlGroup, SWT.NONE); |
| 466 | fDataPortText.setEnabled(true); |
| 467 | fDataPortText.setToolTipText(Messages.TraceControl_CreateSessionDataPortTooltip); |
| 468 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 469 | data.horizontalSpan = 1; |
| 470 | fDataPortText.setLayoutData(data); |
| 471 | fDataPortText.addModifyListener(fUpdateEnablementModifyListener); |
| 472 | |
| 473 | fCopyProtocolSelectionListener = new ControlProtocolSelectionListener(); |
| 474 | fControlProtocolSelectionListener = new ProtocolComboSelectionListener(fControlProtocolCombo, fControlPortText); |
| 475 | fDataProtocolSelectionListener = new ProtocolComboSelectionListener(fDataProtocolCombo, fDataPortText); |
| 476 | |
| 477 | fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener); |
| 478 | |
| 479 | fControlUrlKeyListener = new CopyModifyListener(fControlHostAddressText, fDataHostAddressText); |
| 480 | fControlHostAddressText.addModifyListener(fControlUrlKeyListener); |
| 481 | |
| 482 | fControlProtocolCombo.select(DEFAULT_URL_INDEX); |
| 483 | fDataProtocolCombo.select(DEFAULT_URL_INDEX); |
| 484 | |
| 485 | fLinkDataWithControlButton.addSelectionListener(new SelectionAdapter() { |
| 486 | @Override |
| 487 | public void widgetSelected(SelectionEvent e) { |
| 488 | if (fLinkDataWithControlButton.getSelection()) { |
| 489 | // Set enablement control data channel inputs |
| 490 | fDataProtocolCombo.setEnabled(false); |
| 491 | fDataHostAddressText.setEnabled(false); |
| 492 | fControlPortText.setEnabled(true); |
| 493 | fDataPortText.setEnabled(true); |
| 494 | |
| 495 | // Update listeners |
| 496 | fControlProtocolCombo.removeSelectionListener(fControlProtocolSelectionListener); |
| 497 | fDataProtocolCombo.removeSelectionListener(fDataProtocolSelectionListener); |
| 498 | fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener); |
| 499 | fControlHostAddressText.addModifyListener(fControlUrlKeyListener); |
| 500 | |
| 501 | // Get previous selection and validate |
| 502 | int currentSelection = fControlProtocolCombo.getSelectionIndex() <= COMMON_URL_LAST_INDEX ? |
| 503 | fControlProtocolCombo.getSelectionIndex() : DEFAULT_URL_INDEX; |
| 504 | |
| 505 | // Update combo box items |
| 506 | fControlProtocolCombo.removeAll(); |
| 507 | String[] controlItems = new String[StreamingProtocol.values().length]; |
| 508 | for (int i = 0; i < controlItems.length; i++) { |
| 509 | controlItems[i] = StreamingProtocol.values()[i].name(); |
| 510 | } |
| 511 | fControlProtocolCombo.setItems(controlItems); |
| 512 | fDataProtocolCombo.setItems(controlItems); |
| 513 | |
| 514 | // Set selection |
| 515 | fControlProtocolCombo.select(currentSelection); |
| 516 | fDataProtocolCombo.select(currentSelection); |
| 517 | fDataHostAddressText.setText(fControlHostAddressText.getText()); |
| 518 | |
| 519 | // Update tool tips |
| 520 | fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip); |
| 521 | } else { |
| 522 | // Enable data channel inputs |
| 523 | fDataProtocolCombo.setEnabled(true); |
| 524 | fDataHostAddressText.setEnabled(true); |
| 525 | |
| 526 | // Update listeners |
| 527 | fControlProtocolCombo.removeSelectionListener(fCopyProtocolSelectionListener); |
| 528 | fControlProtocolCombo.addSelectionListener(fControlProtocolSelectionListener); |
| 529 | fDataProtocolCombo.addSelectionListener(fDataProtocolSelectionListener); |
| 530 | fControlHostAddressText.removeModifyListener(fControlUrlKeyListener); |
| 531 | |
| 532 | // Update combo box items |
| 533 | int currentSelection = fControlProtocolCombo.getSelectionIndex(); |
| 534 | fControlProtocolCombo.removeAll(); |
| 535 | String[] controlItems = new String[StreamingProtocol2.values().length]; |
| 536 | for (int i = 0; i < controlItems.length; i++) { |
| 537 | controlItems[i] = StreamingProtocol2.values()[i].name(); |
| 538 | } |
| 539 | fControlProtocolCombo.setItems(controlItems); |
| 540 | fDataProtocolCombo.setItems(controlItems); |
| 541 | |
| 542 | // Set selection |
| 543 | fControlProtocolCombo.select(currentSelection); |
| 544 | fDataProtocolCombo.select(currentSelection); |
| 545 | |
| 546 | // Update tool tips |
| 547 | fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip); |
| 548 | fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip); |
| 549 | |
| 550 | // Update control/data port enablement and input |
| 551 | if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) || |
| 552 | fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) { |
| 553 | fControlPortText.setText(""); //$NON-NLS-1$ |
| 554 | fControlPortText.setEnabled(false); |
| 555 | } else { |
| 556 | fControlPortText.setEnabled(true); |
| 557 | } |
| 558 | |
| 559 | if (fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) || |
| 560 | fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) { |
| 561 | fDataPortText.setText(""); //$NON-NLS-1$ |
| 562 | fDataPortText.setEnabled(false); |
| 563 | } else { |
| 564 | fDataPortText.setEnabled(true); |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | }); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | private void disposeConfigureStreamingComposite() { |
| 573 | if (fStreamingComposite != null) { |
| 574 | fStreamingComposite.dispose(); |
| 575 | fStreamingComposite = null; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | @Override |
| 580 | protected void createButtonsForButtonBar(Composite parent) { |
| 581 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ |
| 582 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
| 583 | } |
| 584 | |
| 585 | private void updateEnablement() { |
| 586 | validate(); |
| 587 | getButton(IDialogConstants.OK_ID).setEnabled(getErrorMessage() == null); |
| 588 | } |
| 589 | |
| 590 | private void validate() { |
| 591 | // Validate input data |
| 592 | fSessionName = fSessionNameText.getText(); |
| 593 | fSessionPath = fSessionPathText.getText(); |
| 594 | setErrorMessage(null); |
| 595 | |
| 596 | if (!"".equals(fSessionPath)) { //$NON-NLS-1$ |
| 597 | // validate sessionPath |
| 598 | if (!fIsStreamedTrace) { |
| 599 | TargetNodeComponent node = (TargetNodeComponent)fParent.getParent(); |
| 600 | IRemoteSystemProxy proxy = node.getRemoteSystemProxy(); |
| 601 | IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem(); |
| 602 | if (fsss != null) { |
| 603 | try { |
| 604 | IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSessionPath, new NullProgressMonitor()); |
| 605 | |
| 606 | if (remoteFolder == null) { |
| 607 | setErrorMessage(Messages.TraceControl_InvalidSessionPathError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 608 | return; |
| 609 | } |
| 610 | |
| 611 | if (remoteFolder.exists()) { |
| 612 | setErrorMessage(Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 613 | return; |
| 614 | } |
| 615 | } catch (SystemMessageException e) { |
| 616 | setErrorMessage(Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$ |
| 617 | return; |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | fIsDefaultPath = false; |
| 622 | } |
| 623 | |
| 624 | if (fParent.isSnapshotSupported()) { |
| 625 | fIsSnapshot = fSnapshotButton.getSelection(); |
| 626 | } |
| 627 | |
| 628 | fNetworkUrl = null; |
| 629 | fControlUrl = null; |
| 630 | fDataUrl = null; |
| 631 | |
| 632 | if (fIsStreamedTrace && fStreamingComposite != null) { |
| 633 | // Validate input data |
| 634 | fTracePath = fTracePathText.getText(); |
| 635 | |
| 636 | if (fControlProtocolCombo.getSelectionIndex() < 0) { |
| 637 | setErrorMessage("Control Protocol Text is empty\n"); //$NON-NLS-1$ |
| 638 | return; |
| 639 | } |
| 640 | |
| 641 | if ("".equals(fControlHostAddressText.getText())) { //$NON-NLS-1$ |
| 642 | setErrorMessage("Control Address Text is empty\n"); //$NON-NLS-1$ |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | if (!fLinkDataWithControlButton.getSelection()) { |
| 647 | if (fDataProtocolCombo.getSelectionIndex() < 0) { |
| 648 | setErrorMessage("Data Protocol Text is empty\n"); //$NON-NLS-1$ |
| 649 | return; |
| 650 | } |
| 651 | |
| 652 | if ("".equals(fDataHostAddressText.getText())) { //$NON-NLS-1$ |
| 653 | setErrorMessage("Data Address Text is empty\n"); //$NON-NLS-1$ |
| 654 | return; |
| 655 | } |
| 656 | |
| 657 | fControlUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()), |
| 658 | fControlHostAddressText.getText(), |
| 659 | fControlPortText.getText(), |
| 660 | null, |
| 661 | fTracePath); |
| 662 | |
| 663 | fDataUrl = getUrlString(fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()), |
| 664 | fDataHostAddressText.getText(), |
| 665 | null, |
| 666 | fDataPortText.getText(), |
| 667 | fTracePath); |
| 668 | } else { |
| 669 | fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()), |
| 670 | fControlHostAddressText.getText(), |
| 671 | fControlPortText.getText(), |
| 672 | fDataPortText.getText(), |
| 673 | fTracePath); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | // Check for invalid names |
| 678 | if (!"".equals(fSessionName) && !fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 679 | setErrorMessage(Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | // Check if node with name already exists in parent |
| 684 | if(fParent.containsChild(fSessionName)) { |
| 685 | setErrorMessage(Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 686 | return; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | private static String getUrlString(String proto, String host, String ctrlPort, String dataPort, String sessionPath) { |
| 691 | //proto://[HOST|IP][:PORT1[:PORT2]][/TRACE_PATH] |
| 692 | StringBuilder stringBuilder = new StringBuilder(); |
| 693 | stringBuilder.append(proto); |
| 694 | stringBuilder.append("://"); //$NON-NLS-1$ |
| 695 | stringBuilder.append(host); |
| 696 | |
| 697 | if ((ctrlPort != null) && (!"".equals(ctrlPort))) { //$NON-NLS-1$ |
| 698 | stringBuilder.append(":"); //$NON-NLS-1$ |
| 699 | stringBuilder.append(ctrlPort); |
| 700 | } |
| 701 | |
| 702 | if ((dataPort != null) && (!"".equals(dataPort))) { //$NON-NLS-1$ |
| 703 | stringBuilder.append(":"); //$NON-NLS-1$ |
| 704 | stringBuilder.append(dataPort); |
| 705 | } |
| 706 | |
| 707 | if ((sessionPath != null) && (!"".equals(sessionPath))) { //$NON-NLS-1$ |
| 708 | stringBuilder.append("/"); //$NON-NLS-1$ |
| 709 | stringBuilder.append(sessionPath); |
| 710 | } |
| 711 | return stringBuilder.toString(); |
| 712 | } |
| 713 | |
| 714 | private static class CopyModifyListener implements ModifyListener { |
| 715 | private Text fSource; |
| 716 | private Text fDestination; |
| 717 | |
| 718 | public CopyModifyListener(Text source, Text destination) { |
| 719 | fSource = source; |
| 720 | fDestination = destination; |
| 721 | } |
| 722 | |
| 723 | @Override |
| 724 | public void modifyText(ModifyEvent e) { |
| 725 | fDestination.setText(fSource.getText()); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | private class ControlProtocolSelectionListener extends SelectionAdapter { |
| 730 | |
| 731 | @Override |
| 732 | public void widgetSelected(SelectionEvent e) { |
| 733 | fDataProtocolCombo.select(fControlProtocolCombo.getSelectionIndex()); |
| 734 | if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.file.name())) { |
| 735 | fControlPortText.setText(""); //$NON-NLS-1$ |
| 736 | fDataPortText.setText(""); //$NON-NLS-1$ |
| 737 | fControlPortText.setEnabled(false); |
| 738 | fDataPortText.setEnabled(false); |
| 739 | } else { |
| 740 | fControlPortText.setEnabled(true); |
| 741 | fDataPortText.setEnabled(true); |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | private class ProtocolComboSelectionListener extends SelectionAdapter { |
| 747 | |
| 748 | private CCombo fCombo; |
| 749 | private Text fPortText; |
| 750 | |
| 751 | public ProtocolComboSelectionListener(CCombo combo, Text portText) { |
| 752 | fCombo = combo; |
| 753 | fPortText = portText; |
| 754 | } |
| 755 | |
| 756 | @Override |
| 757 | public void widgetSelected(SelectionEvent e) { |
| 758 | if (fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) || |
| 759 | fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) { |
| 760 | fPortText.setText(""); //$NON-NLS-1$ |
| 761 | fPortText.setEnabled(false); |
| 762 | } else { |
| 763 | fPortText.setEnabled(true); |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | @Override |
| 769 | public ISessionInfo getParameters() { |
| 770 | ISessionInfo sessionInfo = new SessionInfo(fSessionName); |
| 771 | |
| 772 | if (fIsStreamedTrace) { |
| 773 | sessionInfo.setNetworkUrl(fNetworkUrl); |
| 774 | sessionInfo.setControlUrl(fControlUrl); |
| 775 | sessionInfo.setDataUrl(fDataUrl); |
| 776 | sessionInfo.setStreamedTrace(true); |
| 777 | } else if (!fIsDefaultPath) { |
| 778 | sessionInfo.setSessionPath(fSessionPath); |
| 779 | } |
| 780 | |
| 781 | sessionInfo.setSnapshot(fIsSnapshot); |
| 782 | |
| 783 | return sessionInfo; |
| 784 | } |
| 785 | |
| 786 | private final class UpdateEnablementModifyListener implements ModifyListener { |
| 787 | @Override |
| 788 | public void modifyText(ModifyEvent e) { |
| 789 | updateEnablement(); |
| 790 | } |
| 791 | } |
| 792 | } |