1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 * Marc-Andre Laperle - Support for creating a live session
13 **********************************************************************/
15 package org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
;
17 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
18 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
19 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.Activator
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionGroup
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.IRemoteSystemProxy
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceConstants
;
28 import org
.eclipse
.rse
.services
.clientserver
.messages
.SystemMessageException
;
29 import org
.eclipse
.rse
.subsystems
.files
.core
.servicesubsystem
.IFileServiceSubSystem
;
30 import org
.eclipse
.rse
.subsystems
.files
.core
.subsystems
.IRemoteFile
;
31 import org
.eclipse
.swt
.SWT
;
32 import org
.eclipse
.swt
.custom
.CCombo
;
33 import org
.eclipse
.swt
.events
.FocusEvent
;
34 import org
.eclipse
.swt
.events
.FocusListener
;
35 import org
.eclipse
.swt
.events
.ModifyEvent
;
36 import org
.eclipse
.swt
.events
.ModifyListener
;
37 import org
.eclipse
.swt
.events
.SelectionAdapter
;
38 import org
.eclipse
.swt
.events
.SelectionEvent
;
39 import org
.eclipse
.swt
.events
.VerifyEvent
;
40 import org
.eclipse
.swt
.events
.VerifyListener
;
41 import org
.eclipse
.swt
.layout
.GridData
;
42 import org
.eclipse
.swt
.layout
.GridLayout
;
43 import org
.eclipse
.swt
.widgets
.Button
;
44 import org
.eclipse
.swt
.widgets
.Composite
;
45 import org
.eclipse
.swt
.widgets
.Control
;
46 import org
.eclipse
.swt
.widgets
.Group
;
47 import org
.eclipse
.swt
.widgets
.Label
;
48 import org
.eclipse
.swt
.widgets
.Shell
;
49 import org
.eclipse
.swt
.widgets
.Text
;
53 * Dialog box for collecting session creation information.
56 * @author Bernd Hufmann
58 public class CreateSessionDialog
extends TitleAreaDialog
implements ICreateSessionDialog
{
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 * The icon file for this dialog box.
66 public static final String CREATE_SESSION_ICON_FILE
= "icons/elcl16/add_button.gif"; //$NON-NLS-1$
69 * To indicate that the default value will be used for this field
71 private static final String DEFAULT_TEXT
= "<" + Messages
.EnableChannelDialog_DefaultMessage
+ ">"; //$NON-NLS-1$ //$NON-NLS-2$
74 * The default port for the connection to Relayd. This actual value is
75 * needed because this is not an optional argument to a command; this is
76 * what is used to connect directly to Relayd from Java through a socket.
77 * There is also currently no way to know the default value by issuing a
80 private static final int DEFAULT_LIVE_PORT
= 5344;
83 * The default address for the connection to Relayd. Only local is supported
84 * for now. See above comment for why it's needed.
86 private static final String DEFAULT_LIVE_URL
= "127.0.0.1"; //$NON-NLS-1$
89 * Supported network protocols for streaming
91 private enum StreamingProtocol
{
92 /** Default network protocol for IPv4 (TCP)*/
94 /** Default network protocol for IPv6 (TCP)*/
101 * Supported network protocols for Live tracing
103 private enum LiveProtocol
{
104 /** Default network protocol for IPv4 (TCP)*/
106 /** Default network protocol for IPv6 (TCP)*/
110 private enum StreamingProtocol2
{
111 /** Default network protocol for IPv4 (TCP)*/
113 /** Default network protocol for IPv6 (TCP)*/
115 /** TCP network protocol for IPv4*/
117 /** TCP network protocol for IPv6*/
121 * Index of last supported streaming protocol for common URL configuration.
123 private static final int COMMON_URL_LAST_INDEX
= 1;
125 * Index of default streaming protocol.
127 private static final int DEFAULT_URL_INDEX
= 0;
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
133 * The dialog composite.
135 private Composite fDialogComposite
= null;
137 * The text widget for the session name
139 private Text fSessionNameText
= null;
141 * The label widget for the session path.
143 private Label fSessionPathLabel
= null;
145 * The text widget for the session path.
147 private Text fSessionPathText
= null;
149 * The button widget to select a normal session
151 private Button fNormalModeButton
= null;
153 * The button widget to select a snapshot session
155 private Button fSnapshotButton
= null;
157 * The group that contains the mutually exclusive mode buttons
159 private Group fModeButtonGroup
= null;
161 * The button widget to select a live session
163 private Button fLiveButton
= null;
166 * The text widget to set a live delay
168 private Text fLiveDelayText
= null;
170 * The Group for advanced configuration.
172 private Group fAdvancedGroup
= null;
174 * The button to show advanced options.
176 private Button fAdvancedButton
= null;
178 * The composite with streaming configuration parameter.
180 private Composite fStreamingComposite
= null;
182 * The text widget for the trace path.
184 private Text fTracePathText
= null;
186 * The button to link data protocol/Address with control protocol.
188 private Button fLinkDataWithControlButton
= null;
190 * The Combo box for channel protocol selection.
192 private CCombo fControlProtocolCombo
= null;
194 * A selection listener that copies the protocol from control to data when being linked.
196 private ControlProtocolSelectionListener fCopyProtocolSelectionListener
;
198 * A selection listener updates the control port text depending on the control protocol selected.
200 private ProtocolComboSelectionListener fControlProtocolSelectionListener
;
202 * A selection listener updates the data port text depending on the data protocol selected.
204 private ProtocolComboSelectionListener fDataProtocolSelectionListener
;
206 * The text box for the host/IP address of the control channel.
208 private Text fControlHostAddressText
= null;
210 * A key listener that copies the host address from control to data when being linked.
212 private CopyModifyListener fControlUrlKeyListener
;
214 * A modify listener that updates the enablement of the dialog.
216 private UpdateEnablementModifyListener fUpdateEnablementModifyListener
;
218 * The text box for the control port.
220 private Text fControlPortText
= null;
222 * The Combo box for data protocol selection.
224 private CCombo fDataProtocolCombo
= null;
226 * The text box for the host/IP address of the data channel.
228 private Text fDataHostAddressText
= null;
230 * The text box for the data port.
232 private Text fDataPortText
= null;
234 * The parent where the new node should be added.
236 private TraceSessionGroup fParent
= null;
238 * The session name string.
240 private String fSessionName
= ""; //$NON-NLS-1$;
242 * The session path string.
244 private String fSessionPath
= null;
246 * Flag whether the session is snapshot or not
248 private boolean fIsSnapshot
= false;
250 * Flag whether the session is live or not
252 private boolean fIsLive
= false;
254 * The text box for the live address (relayd).
256 private Text fLiveHostAddressText
= null;
258 * The text box for the live port (relayd).
260 private Text fLivePortText
= null;
264 private Integer fLiveDelay
= 0;
268 private String fLiveUrl
= null;
272 private Integer fLivePort
= 0;
274 * Flag whether default location (path) shall be used or not
276 private boolean fIsDefaultPath
= true;
278 * Flag whether the advanced options are enabled or not
280 private boolean fIsAdvancedEnabled
= false;
282 * The network URL in case control and data is configured together.
283 * If set, fControlUrl and fDataUrl will be null.
285 private String fNetworkUrl
= null;
287 * The control URL in case control and data is configured separately.
288 * If set, fDataUrl will be set too and fNetworkUrl will be null.
290 private String fControlUrl
= null;
292 * The data URL in case control and data is configured separately.
293 * If set, fControlUrl will be set too and fNetworkUrl will be null.
295 private String fDataUrl
= null;
297 * The trace path string.
299 private String fTracePath
= null;
301 * The Group for advanced configuration of Live mode.
303 private Group fLiveGroup
= null;
305 // ------------------------------------------------------------------------
307 // ------------------------------------------------------------------------
310 * @param shell - a shell for the display of the dialog
312 public CreateSessionDialog(Shell shell
) {
314 setShellStyle(SWT
.RESIZE
| getShellStyle());
317 // ------------------------------------------------------------------------
319 // ------------------------------------------------------------------------
322 public void initialize(TraceSessionGroup group
) {
324 fStreamingComposite
= null;
328 fSnapshotButton
= null;
329 fSessionName
= ""; //$NON-NLS-1$
332 fIsDefaultPath
= true;
333 fIsAdvancedEnabled
= false;
338 // ------------------------------------------------------------------------
340 // ------------------------------------------------------------------------
343 protected void configureShell(Shell newShell
) {
344 super.configureShell(newShell
);
345 newShell
.setText(Messages
.TraceControl_CreateSessionDialogTitle
);
346 newShell
.setImage(Activator
.getDefault().loadIcon(CREATE_SESSION_ICON_FILE
));
350 protected Control
createDialogArea(Composite parent
) {
351 Composite dialogAreaa
= (Composite
) super.createDialogArea(parent
);
352 setTitle(Messages
.TraceControl_CreateSessionDialogTitle
);
353 setMessage(Messages
.TraceControl_CreateSessionDialogMessage
);
356 fDialogComposite
= new Composite(dialogAreaa
, SWT
.NONE
);
357 GridLayout layout
= new GridLayout(1, true);
358 fDialogComposite
.setLayout(layout
);
359 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
361 Group sessionGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
362 sessionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
363 sessionGroup
.setLayout(new GridLayout(4, true));
365 fUpdateEnablementModifyListener
= new UpdateEnablementModifyListener();
367 Label sessionNameLabel
= new Label(sessionGroup
, SWT
.RIGHT
);
368 sessionNameLabel
.setText(Messages
.TraceControl_CreateSessionNameLabel
);
369 fSessionNameText
= new Text(sessionGroup
, SWT
.NONE
);
370 fSessionNameText
.setToolTipText(Messages
.TraceControl_CreateSessionNameTooltip
);
371 fSessionNameText
.addModifyListener(fUpdateEnablementModifyListener
);
372 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
373 data
.horizontalSpan
= 3;
374 fSessionNameText
.setLayoutData(data
);
376 fSessionPathLabel
= new Label(sessionGroup
, SWT
.RIGHT
);
377 fSessionPathLabel
.setText(Messages
.TraceControl_CreateSessionPathLabel
);
378 fSessionPathText
= new Text(sessionGroup
, SWT
.NONE
);
379 fSessionPathText
.setToolTipText(Messages
.TraceControl_CreateSessionPathTooltip
);
380 data
= new GridData(GridData
.FILL_HORIZONTAL
);
381 data
.horizontalSpan
= 3;
382 fSessionPathText
.setLayoutData(data
);
383 fSessionPathText
.addModifyListener(fUpdateEnablementModifyListener
);
385 if (fParent
.isSnapshotSupported() || fParent
.isLiveSupported()) {
386 fModeButtonGroup
= new Group(sessionGroup
, SWT
.NONE
);
387 data
= new GridData(GridData
.FILL_HORIZONTAL
);
388 data
.horizontalSpan
= 4;
389 fModeButtonGroup
.setLayoutData(data
);
390 fModeButtonGroup
.setLayout(new GridLayout(3, true));
392 SelectionAdapter modeChangedListener
= new SelectionAdapter() {
394 public void widgetSelected(SelectionEvent e
) {
395 if (fLiveButton
!= null) {
396 if (fLiveButton
.getSelection()) {
397 createAdvancedLiveGroup();
398 updateSessionPathEnablement();
399 updateProtocolComboItems();
402 updateSessionPathEnablement();
403 updateProtocolComboItems();
410 fNormalModeButton
= new Button(fModeButtonGroup
, SWT
.RADIO
);
411 fNormalModeButton
.setText(Messages
.TraceControl_CreateSessionNormalLabel
);
412 fNormalModeButton
.setToolTipText(Messages
.TraceControl_CreateSessionNormalTooltip
);
413 fNormalModeButton
.setSelection(true);
414 fNormalModeButton
.addSelectionListener(modeChangedListener
);
416 if (fParent
.isSnapshotSupported()) {
417 fSnapshotButton
= new Button(fModeButtonGroup
, SWT
.RADIO
);
418 fSnapshotButton
.setText(Messages
.TraceControl_CreateSessionSnapshotLabel
);
419 fSnapshotButton
.setToolTipText(Messages
.TraceControl_CreateSessionSnapshotTooltip
);
420 fSnapshotButton
.addSelectionListener(modeChangedListener
);
423 if (fParent
.isLiveSupported()) {
424 fLiveButton
= new Button(fModeButtonGroup
, SWT
.RADIO
);
425 fLiveButton
.setText(Messages
.TraceControl_CreateSessionLiveLabel
);
426 fLiveButton
.setToolTipText(Messages
.TraceControl_CreateSessionLiveTooltip
);
427 fLiveButton
.addSelectionListener(modeChangedListener
);
431 if (fParent
.isNetworkStreamingSupported() || fParent
.isLiveSupported()) {
432 createAdvancedOptionsComposite();
435 return fDialogComposite
;
438 private void createAdvancedOptionsComposite() {
440 fAdvancedGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
441 fAdvancedGroup
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
442 fAdvancedGroup
.setLayout(new GridLayout(1, true));
444 fAdvancedButton
= new Button(fAdvancedGroup
, SWT
.PUSH
);
445 fAdvancedButton
.setText(Messages
.TraceControl_CreateSessionConfigureStreamingButtonText
+ " >>>"); //$NON-NLS-1$
446 fAdvancedButton
.setToolTipText(Messages
.TraceControl_CreateSessionConfigureStreamingButtonTooltip
);
447 fAdvancedButton
.addSelectionListener(new SelectionAdapter() {
449 public void widgetSelected(SelectionEvent e
) {
450 if (fIsAdvancedEnabled
) {
451 fIsAdvancedEnabled
= false;
452 fAdvancedButton
.setText(">>> " + Messages
.TraceControl_CreateSessionConfigureStreamingButtonText
); //$NON-NLS-1$
453 fAdvancedButton
.setToolTipText(Messages
.TraceControl_CreateSessionConfigureStreamingButtonTooltip
);
455 if (fParent
.isNetworkStreamingSupported()) {
456 updateSessionPathEnablement();
457 disposeConfigureStreamingComposite();
460 if (fParent
.isLiveSupported()) {
464 fIsAdvancedEnabled
= true;
465 fAdvancedButton
.setText("<<< " + Messages
.TraceControl_CreateSessionNoStreamingButtonText
); //$NON-NLS-1$
466 fAdvancedButton
.setToolTipText(Messages
.TraceControl_CreateSessionNoStreamingButtonTooltip
);
468 if (fParent
.isNetworkStreamingSupported()) {
469 updateSessionPathEnablement();
470 createConfigureStreamingComposite();
472 if (fLiveButton
!= null && fLiveButton
.getSelection()) {
473 createAdvancedLiveGroup();
483 private void updateSessionPathEnablement() {
484 if (fIsAdvancedEnabled
|| fIsLive
) {
485 fSessionPathText
.setEnabled(false);
486 fSessionPathText
.setText(""); //$NON-NLS-1$
487 fSessionPathLabel
.setText(""); //$NON-NLS-1$
489 fSessionPathText
.setEnabled(true);
490 fSessionPathLabel
.setText(Messages
.TraceControl_CreateSessionPathLabel
);
494 private void updateProtocolComboItems() {
495 if (fControlProtocolCombo
== null || fControlProtocolCombo
.isDisposed()) {
499 int currentSelection
= fControlProtocolCombo
.getSelectionIndex() <= COMMON_URL_LAST_INDEX ?
500 fControlProtocolCombo
.getSelectionIndex() : DEFAULT_URL_INDEX
;
502 fControlProtocolCombo
.removeAll();
503 Enum
<?
extends Enum
<?
>>[] values
;
505 values
= LiveProtocol
.values();
506 } else if (fLinkDataWithControlButton
.getSelection()) {
507 values
= StreamingProtocol
.values();
509 values
= StreamingProtocol2
.values();
512 String
[] controlItems
= new String
[values
.length
];
513 for (int i
= 0; i
< controlItems
.length
; i
++) {
514 controlItems
[i
] = values
[i
].name();
516 fControlProtocolCombo
.setItems(controlItems
);
517 fDataProtocolCombo
.setItems(controlItems
);
520 if (currentSelection
!= -1) {
521 fControlProtocolCombo
.select(currentSelection
);
522 fDataProtocolCombo
.select(currentSelection
);
526 private void createConfigureStreamingComposite() {
527 if (fStreamingComposite
== null) {
528 fStreamingComposite
= new Group(fAdvancedGroup
, SWT
.SHADOW_NONE
);
529 GridLayout layout
= new GridLayout(1, true);
530 fStreamingComposite
.setLayout(layout
);
531 fStreamingComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
533 layout
= new GridLayout(7, true);
534 fStreamingComposite
.setLayout(layout
);
535 fStreamingComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
537 Label tracePathLabel
= new Label(fStreamingComposite
, SWT
.RIGHT
);
538 tracePathLabel
.setText(Messages
.TraceControl_CreateSessionTracePathText
);
539 fTracePathText
= new Text(fStreamingComposite
, SWT
.NONE
);
540 fTracePathText
.setToolTipText(Messages
.TraceControl_CreateSessionTracePathTooltip
);
543 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
544 data
.horizontalSpan
= 6;
545 fTracePathText
.setLayoutData(data
);
546 fTracePathText
.addModifyListener(fUpdateEnablementModifyListener
);
548 fLinkDataWithControlButton
= new Button(fStreamingComposite
, SWT
.CHECK
);
549 fLinkDataWithControlButton
.setText(Messages
.TraceControl_CreateSessionLinkButtonText
);
550 fLinkDataWithControlButton
.setToolTipText(Messages
.TraceControl_CreateSessionLinkButtonTooltip
);
551 data
= new GridData(GridData
.FILL_HORIZONTAL
);
552 data
.horizontalSpan
= 7;
553 fLinkDataWithControlButton
.setLayoutData(data
);
554 fLinkDataWithControlButton
.setSelection(true);
556 Label label
= new Label(fStreamingComposite
, SWT
.NONE
);
557 data
= new GridData(GridData
.FILL_HORIZONTAL
);
558 data
.horizontalSpan
= 1;
559 label
.setLayoutData(data
);
561 label
= new Label(fStreamingComposite
, SWT
.NONE
);
562 label
.setText(Messages
.TraceControl_CreateSessionProtocolLabelText
);
563 data
= new GridData(GridData
.FILL_HORIZONTAL
);
564 data
.horizontalSpan
= 1;
565 label
.setLayoutData(data
);
567 label
= new Label(fStreamingComposite
, SWT
.NONE
);
568 label
.setText(Messages
.TraceControl_CreateSessionAddressLabelText
);
569 data
= new GridData(GridData
.FILL_HORIZONTAL
);
570 data
.horizontalSpan
= 4;
571 label
.setLayoutData(data
);
573 label
= new Label(fStreamingComposite
, SWT
.NONE
);
574 label
.setText(Messages
.TraceControl_CreateSessionPortLabelText
);
575 data
= new GridData(GridData
.FILL_HORIZONTAL
);
576 data
.horizontalSpan
= 1;
577 label
.setLayoutData(data
);
579 label
= new Label(fStreamingComposite
, SWT
.RIGHT
);
580 label
.setText(Messages
.TraceControl_CreateSessionControlUrlLabel
);
581 data
= new GridData(GridData
.FILL_HORIZONTAL
);
582 data
.horizontalSpan
= 1;
583 label
.setLayoutData(data
);
585 fControlProtocolCombo
= new CCombo(fStreamingComposite
, SWT
.READ_ONLY
);
586 fControlProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionCommonProtocolTooltip
);
587 data
= new GridData(GridData
.FILL_HORIZONTAL
);
588 data
.horizontalSpan
= 1;
589 fControlProtocolCombo
.setLayoutData(data
);
590 fControlProtocolCombo
.addModifyListener(fUpdateEnablementModifyListener
);
592 fControlHostAddressText
= new Text(fStreamingComposite
, SWT
.NONE
);
593 fControlHostAddressText
.setToolTipText(Messages
.TraceControl_CreateSessionControlAddressTooltip
);
594 data
= new GridData(GridData
.FILL_HORIZONTAL
);
595 data
.horizontalSpan
= 4;
596 fControlHostAddressText
.setLayoutData(data
);
597 fControlHostAddressText
.addModifyListener(fUpdateEnablementModifyListener
);
599 fControlPortText
= new Text(fStreamingComposite
, SWT
.NONE
);
600 fControlPortText
.setToolTipText(Messages
.TraceControl_CreateSessionControlPortTooltip
);
601 data
= new GridData(GridData
.FILL_HORIZONTAL
);
602 data
.horizontalSpan
= 1;
603 fControlPortText
.setLayoutData(data
);
604 fControlPortText
.addModifyListener(fUpdateEnablementModifyListener
);
606 label
= new Label(fStreamingComposite
, SWT
.RIGHT
);
607 label
.setText(Messages
.TraceControl_CreateSessionDataUrlLabel
);
608 data
= new GridData(GridData
.FILL_HORIZONTAL
);
609 data
.horizontalSpan
= 1;
610 label
.setLayoutData(data
);
612 fDataProtocolCombo
= new CCombo(fStreamingComposite
, SWT
.READ_ONLY
);
613 fDataProtocolCombo
.setEnabled(false);
614 fDataProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionProtocolTooltip
);
615 data
= new GridData(GridData
.FILL_HORIZONTAL
);
616 data
.horizontalSpan
= 1;
617 fDataProtocolCombo
.setLayoutData(data
);
618 fDataProtocolCombo
.addModifyListener(fUpdateEnablementModifyListener
);
620 updateProtocolComboItems();
622 fDataHostAddressText
= new Text(fStreamingComposite
, SWT
.NONE
);
623 fDataHostAddressText
.setEnabled(false);
624 fDataHostAddressText
.setToolTipText(Messages
.TraceControl_CreateSessionDataAddressTooltip
);
625 data
= new GridData(GridData
.FILL_HORIZONTAL
);
626 data
.horizontalSpan
= 4;
627 fDataHostAddressText
.setLayoutData(data
);
628 fDataHostAddressText
.addModifyListener(fUpdateEnablementModifyListener
);
630 fDataPortText
= new Text(fStreamingComposite
, SWT
.NONE
);
631 fDataPortText
.setEnabled(true);
632 fDataPortText
.setToolTipText(Messages
.TraceControl_CreateSessionDataPortTooltip
);
633 data
= new GridData(GridData
.FILL_HORIZONTAL
);
634 data
.horizontalSpan
= 1;
635 fDataPortText
.setLayoutData(data
);
636 fDataPortText
.addModifyListener(fUpdateEnablementModifyListener
);
638 fCopyProtocolSelectionListener
= new ControlProtocolSelectionListener();
639 fControlProtocolSelectionListener
= new ProtocolComboSelectionListener(fControlProtocolCombo
, fControlPortText
);
640 fDataProtocolSelectionListener
= new ProtocolComboSelectionListener(fDataProtocolCombo
, fDataPortText
);
642 fControlProtocolCombo
.addSelectionListener(fCopyProtocolSelectionListener
);
644 fControlUrlKeyListener
= new CopyModifyListener(fControlHostAddressText
, fDataHostAddressText
);
645 fControlHostAddressText
.addModifyListener(fControlUrlKeyListener
);
647 fControlProtocolCombo
.select(DEFAULT_URL_INDEX
);
648 fDataProtocolCombo
.select(DEFAULT_URL_INDEX
);
650 fLinkDataWithControlButton
.addSelectionListener(new SelectionAdapter() {
652 public void widgetSelected(SelectionEvent e
) {
653 if (fLinkDataWithControlButton
.getSelection()) {
654 // Set enablement control data channel inputs
655 fDataProtocolCombo
.setEnabled(false);
656 fDataHostAddressText
.setEnabled(false);
657 fControlPortText
.setEnabled(true);
658 fDataPortText
.setEnabled(true);
661 fControlProtocolCombo
.removeSelectionListener(fControlProtocolSelectionListener
);
662 fDataProtocolCombo
.removeSelectionListener(fDataProtocolSelectionListener
);
663 fControlProtocolCombo
.addSelectionListener(fCopyProtocolSelectionListener
);
664 fControlHostAddressText
.addModifyListener(fControlUrlKeyListener
);
666 updateProtocolComboItems();
668 fDataHostAddressText
.setText(fControlHostAddressText
.getText());
671 fControlProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionCommonProtocolTooltip
);
673 // Enable data channel inputs
674 fDataProtocolCombo
.setEnabled(true);
675 fDataHostAddressText
.setEnabled(true);
678 fControlProtocolCombo
.removeSelectionListener(fCopyProtocolSelectionListener
);
679 fControlProtocolCombo
.addSelectionListener(fControlProtocolSelectionListener
);
680 fDataProtocolCombo
.addSelectionListener(fDataProtocolSelectionListener
);
681 fControlHostAddressText
.removeModifyListener(fControlUrlKeyListener
);
683 updateProtocolComboItems();
686 fDataProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionProtocolTooltip
);
687 fControlProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionProtocolTooltip
);
689 // Update control/data port enablement and input
690 if (fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.net
.name()) ||
691 fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.net6
.name())) {
692 fControlPortText
.setText(""); //$NON-NLS-1$
693 fControlPortText
.setEnabled(false);
695 fControlPortText
.setEnabled(true);
698 if (fDataProtocolCombo
.getItem(fDataProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.net
.name()) ||
699 fDataProtocolCombo
.getItem(fDataProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.net6
.name())) {
700 fDataPortText
.setText(""); //$NON-NLS-1$
701 fDataPortText
.setEnabled(false);
703 fDataPortText
.setEnabled(true);
711 private void createAdvancedLiveGroup() {
712 if (fLiveGroup
== null && fIsAdvancedEnabled
) {
713 GridLayout layout
= new GridLayout(7, true);
714 fLiveGroup
= new Group(fAdvancedGroup
, SWT
.NONE
);
715 fLiveGroup
.setLayout(layout
);
716 GridData layoutData
= new GridData(GridData
.FILL_BOTH
);
717 fLiveGroup
.setLayoutData(layoutData
);
719 Label label
= new Label(fLiveGroup
, SWT
.NONE
);
720 label
.setText(Messages
.TraceControl_CreateSessionLiveConnectionLabel
);
721 layoutData
= new GridData(GridData
.FILL_HORIZONTAL
);
722 layoutData
.horizontalSpan
= 2;
723 label
.setLayoutData(layoutData
);
725 fLiveHostAddressText
= new Text(fLiveGroup
, SWT
.NONE
);
726 fLiveHostAddressText
.setText(DEFAULT_LIVE_URL
);
727 fLiveHostAddressText
.setEnabled(false);
728 fLiveHostAddressText
.setToolTipText(Messages
.TraceControl_CreateSessionLiveConnectionUrlTooltip
);
729 layoutData
= new GridData(GridData
.FILL_HORIZONTAL
);
730 layoutData
.horizontalSpan
= 4;
731 fLiveHostAddressText
.setLayoutData(layoutData
);
733 fLivePortText
= new Text(fLiveGroup
, SWT
.NONE
);
734 fLivePortText
.setText(Integer
.toString(DEFAULT_LIVE_PORT
));
735 fLivePortText
.setToolTipText(Messages
.TraceControl_CreateSessionLiveConnectionPortTooltip
);
736 layoutData
= new GridData(GridData
.FILL_HORIZONTAL
);
737 fLivePortText
.setLayoutData(layoutData
);
739 Label liveDelayLabel
= new Label(fLiveGroup
, SWT
.NONE
);
740 layoutData
= new GridData(GridData
.FILL_HORIZONTAL
);
741 liveDelayLabel
.setText(Messages
.TraceControl_CreateSessionLiveDelayLabel
);
742 liveDelayLabel
.setLayoutData(layoutData
);
743 fLiveDelayText
= new Text(fLiveGroup
, SWT
.NONE
);
744 fLiveDelayText
.setText(DEFAULT_TEXT
);
745 fLiveDelayText
.setForeground(getShell().getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
746 fLiveDelayText
.setToolTipText(Messages
.TraceControl_CreateSessionLiveDelayTooltip
);
747 fLiveDelayText
.addVerifyListener(new VerifyListener() {
749 public void verifyText(VerifyEvent e
) {
750 // only numbers and default are allowed.
751 e
.doit
= e
.text
.matches("[0-9]*") || e
.text
.matches(DEFAULT_TEXT
); //$NON-NLS-1$
755 fLiveDelayText
.addModifyListener(new ModifyListener() {
757 public void modifyText(ModifyEvent event
) {
762 fLiveDelayText
.addFocusListener(new FocusListener() {
765 public void focusLost(FocusEvent e
) {
766 Text focusLostWidget
= (Text
) e
.widget
;
767 if (focusLostWidget
.getText().isEmpty()) {
768 focusLostWidget
.setText(DEFAULT_TEXT
);
769 focusLostWidget
.setForeground(getShell().getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
774 public void focusGained(FocusEvent e
) {
775 Text focusGainedWidget
= (Text
) e
.widget
;
776 if (focusGainedWidget
.getText().equals(DEFAULT_TEXT
)) {
777 focusGainedWidget
.setText(""); //$NON-NLS-1$
778 focusGainedWidget
.setForeground(getShell().getDisplay().getSystemColor(SWT
.COLOR_BLACK
));
783 layoutData
= new GridData(GridData
.FILL_HORIZONTAL
);
784 layoutData
.grabExcessHorizontalSpace
= true;
785 layoutData
.horizontalSpan
= 6;
786 fLiveDelayText
.setLayoutData(layoutData
);
791 private void disposeLiveGroup() {
792 if (fLiveGroup
!= null) {
793 fLiveGroup
.dispose();
799 private void disposeConfigureStreamingComposite() {
800 if (fStreamingComposite
!= null) {
801 fStreamingComposite
.dispose();
802 fStreamingComposite
= null;
807 protected void createButtonsForButtonBar(Composite parent
) {
808 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
809 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
812 private void updateEnablement() {
814 getButton(IDialogConstants
.OK_ID
).setEnabled(getErrorMessage() == null);
817 private void validate() {
818 // Validate input data
819 fSessionName
= fSessionNameText
.getText();
820 fSessionPath
= fSessionPathText
.getText();
821 setErrorMessage(null);
823 if (fParent
.isLiveSupported() && fLiveButton
!= null) {
824 fIsLive
= fLiveButton
.getSelection();
825 fLiveDelay
= LTTngControlServiceConstants
.UNUSED_VALUE
;
826 fLiveUrl
= DEFAULT_LIVE_URL
;
827 fLivePort
= DEFAULT_LIVE_PORT
;
830 if (!"".equals(fSessionPath
)) { //$NON-NLS-1$
831 // validate sessionPath
832 if (!fIsAdvancedEnabled
&& !fIsLive
) {
833 TargetNodeComponent node
= (TargetNodeComponent
)fParent
.getParent();
834 IRemoteSystemProxy proxy
= node
.getRemoteSystemProxy();
835 IFileServiceSubSystem fsss
= proxy
.getFileServiceSubSystem();
838 IRemoteFile remoteFolder
= fsss
.getRemoteFileObject(fSessionPath
, new NullProgressMonitor());
840 if (remoteFolder
== null) {
841 setErrorMessage(Messages
.TraceControl_InvalidSessionPathError
+ " (" + fSessionPath
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
845 if (remoteFolder
.exists()) {
846 setErrorMessage(Messages
.TraceControl_SessionPathAlreadyExistsError
+ " (" + fSessionPath
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
849 } catch (SystemMessageException e
) {
850 setErrorMessage(Messages
.TraceControl_FileSubSystemError
+ "\n" + e
); //$NON-NLS-1$
855 fIsDefaultPath
= false;
858 if (fParent
.isSnapshotSupported()) {
859 fIsSnapshot
= fSnapshotButton
.getSelection();
866 if (fIsAdvancedEnabled
&& fStreamingComposite
!= null) {
867 // Validate input data
869 if (fIsLive
&& fLiveGroup
!= null) {
870 String liveDelayText
= fLiveDelayText
.getText();
872 fLiveDelay
= liveDelayText
.equals(DEFAULT_TEXT
) ? LTTngControlServiceConstants
.UNUSED_VALUE
: Integer
.valueOf(liveDelayText
);
873 fLivePort
= Integer
.valueOf(fLivePortText
.getText());
874 fLiveUrl
= fLiveHostAddressText
.getText();
875 } catch (NumberFormatException e
) {
876 setErrorMessage(Messages
.TraceControl_InvalidLiveDelayError
);
881 fTracePath
= fTracePathText
.getText();
883 if (fControlProtocolCombo
.getSelectionIndex() < 0) {
884 setErrorMessage("Control Protocol Text is empty\n"); //$NON-NLS-1$
888 if ("".equals(fControlHostAddressText
.getText())) { //$NON-NLS-1$
889 setErrorMessage("Control Address Text is empty\n"); //$NON-NLS-1$
893 if (!fLinkDataWithControlButton
.getSelection()) {
894 if (fDataProtocolCombo
.getSelectionIndex() < 0) {
895 setErrorMessage("Data Protocol Text is empty\n"); //$NON-NLS-1$
899 if ("".equals(fDataHostAddressText
.getText())) { //$NON-NLS-1$
900 setErrorMessage("Data Address Text is empty\n"); //$NON-NLS-1$
904 fControlUrl
= getUrlString(fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()),
905 fControlHostAddressText
.getText(),
906 fControlPortText
.getText(),
910 fDataUrl
= getUrlString(fDataProtocolCombo
.getItem(fDataProtocolCombo
.getSelectionIndex()),
911 fDataHostAddressText
.getText(),
913 fDataPortText
.getText(),
916 fNetworkUrl
= getUrlString(fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()),
917 fControlHostAddressText
.getText(),
918 fControlPortText
.getText(),
919 fDataPortText
.getText(),
924 if (fIsLive
&& fNetworkUrl
== null && fControlUrl
== null && fDataUrl
== null) {
925 fNetworkUrl
= SessionInfo
.DEFAULT_LIVE_NETWORK_URK
;
928 // Check for invalid names
929 if (!"".equals(fSessionName
) && !fSessionName
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
930 setErrorMessage(Messages
.TraceControl_InvalidSessionNameError
+ " (" + fSessionName
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
934 // Check if node with name already exists in parent
935 if(fParent
.containsChild(fSessionName
)) {
936 setErrorMessage(Messages
.TraceControl_SessionAlreadyExistsError
+ " (" + fSessionName
+ ")"); //$NON-NLS-1$ //$NON-NLS-2$
941 private static String
getUrlString(String proto
, String host
, String ctrlPort
, String dataPort
, String sessionPath
) {
942 //proto://[HOST|IP][:PORT1[:PORT2]][/TRACE_PATH]
943 StringBuilder stringBuilder
= new StringBuilder();
944 stringBuilder
.append(proto
);
945 stringBuilder
.append("://"); //$NON-NLS-1$
946 stringBuilder
.append(host
);
948 if ((ctrlPort
!= null) && (!"".equals(ctrlPort
))) { //$NON-NLS-1$
949 stringBuilder
.append(":"); //$NON-NLS-1$
950 stringBuilder
.append(ctrlPort
);
953 if ((dataPort
!= null) && (!"".equals(dataPort
))) { //$NON-NLS-1$
954 stringBuilder
.append(":"); //$NON-NLS-1$
955 stringBuilder
.append(dataPort
);
958 if ((sessionPath
!= null) && (!"".equals(sessionPath
))) { //$NON-NLS-1$
959 stringBuilder
.append("/"); //$NON-NLS-1$
960 stringBuilder
.append(sessionPath
);
962 return stringBuilder
.toString();
965 private static class CopyModifyListener
implements ModifyListener
{
966 private Text fSource
;
967 private Text fDestination
;
969 public CopyModifyListener(Text source
, Text destination
) {
971 fDestination
= destination
;
975 public void modifyText(ModifyEvent e
) {
976 fDestination
.setText(fSource
.getText());
980 private class ControlProtocolSelectionListener
extends SelectionAdapter
{
983 public void widgetSelected(SelectionEvent e
) {
984 fDataProtocolCombo
.select(fControlProtocolCombo
.getSelectionIndex());
985 if (fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.file
.name())) {
986 fControlPortText
.setText(""); //$NON-NLS-1$
987 fDataPortText
.setText(""); //$NON-NLS-1$
988 fControlPortText
.setEnabled(false);
989 fDataPortText
.setEnabled(false);
991 fControlPortText
.setEnabled(true);
992 fDataPortText
.setEnabled(true);
997 private class ProtocolComboSelectionListener
extends SelectionAdapter
{
999 private CCombo fCombo
;
1000 private Text fPortText
;
1002 public ProtocolComboSelectionListener(CCombo combo
, Text portText
) {
1004 fPortText
= portText
;
1008 public void widgetSelected(SelectionEvent e
) {
1009 if (fCombo
.getItem(fCombo
.getSelectionIndex()).equals(StreamingProtocol
.net
.name()) ||
1010 fCombo
.getItem(fCombo
.getSelectionIndex()).equals(StreamingProtocol
.net6
.name())) {
1011 fPortText
.setText(""); //$NON-NLS-1$
1012 fPortText
.setEnabled(false);
1014 fPortText
.setEnabled(true);
1020 public ISessionInfo
getParameters() {
1021 ISessionInfo sessionInfo
= new SessionInfo(fSessionName
);
1023 boolean isStreaming
= (fIsAdvancedEnabled
&& fStreamingComposite
!= null) || fIsLive
;
1025 sessionInfo
.setNetworkUrl(fNetworkUrl
);
1026 sessionInfo
.setControlUrl(fControlUrl
);
1027 sessionInfo
.setDataUrl(fDataUrl
);
1028 sessionInfo
.setStreamedTrace(true);
1029 } else if (!fIsDefaultPath
) {
1030 sessionInfo
.setSessionPath(fSessionPath
);
1033 sessionInfo
.setLive(fIsLive
);
1034 sessionInfo
.setLiveUrl(fLiveUrl
);
1035 sessionInfo
.setLivePort(fLivePort
);
1036 sessionInfo
.setLiveDelay(fLiveDelay
);
1037 sessionInfo
.setSnapshot(fIsSnapshot
);
1042 private final class UpdateEnablementModifyListener
implements ModifyListener
{
1044 public void modifyText(ModifyEvent e
) {