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 * Supported network protocols for streaming
76 private enum StreamingProtocol
{
77 /** Default network protocol for IPv4 (TCP)*/
79 /** Default network protocol for IPv6 (TCP)*/
86 * Supported network protocols for Live tracing
88 private enum LiveProtocol
{
89 /** Default network protocol for IPv4 (TCP)*/
91 /** Default network protocol for IPv6 (TCP)*/
95 private enum StreamingProtocol2
{
96 /** Default network protocol for IPv4 (TCP)*/
98 /** Default network protocol for IPv6 (TCP)*/
100 /** TCP network protocol for IPv4*/
102 /** TCP network protocol for IPv6*/
106 * Index of last supported streaming protocol for common URL configuration.
108 private static final int COMMON_URL_LAST_INDEX
= 1;
110 * Index of default streaming protocol.
112 private static final int DEFAULT_URL_INDEX
= 0;
114 // ------------------------------------------------------------------------
116 // ------------------------------------------------------------------------
118 * The dialog composite.
120 private Composite fDialogComposite
= null;
122 * The text widget for the session name
124 private Text fSessionNameText
= null;
126 * The label widget for the session path.
128 private Label fSessionPathLabel
= null;
130 * The text widget for the session path.
132 private Text fSessionPathText
= null;
134 * The button widget to select a normal session
136 private Button fNormalModeButton
= null;
138 * The button widget to select a snapshot session
140 private Button fSnapshotButton
= null;
142 * The group that contains the mutually exclusive mode buttons
144 private Group fModeButtonGroup
= null;
146 * The button widget to select a live session
148 private Button fLiveButton
= null;
151 * The text widget to set a live delay
153 private Text fLiveDelayText
= null;
155 * The Group for advanced configuration.
157 private Group fAdvancedGroup
= null;
159 * The button to show advanced options.
161 private Button fAdvancedButton
= null;
163 * The composite with streaming configuration parameter.
165 private Composite fStreamingComposite
= null;
167 * The text widget for the trace path.
169 private Text fTracePathText
= null;
171 * The button to link data protocol/Address with control protocol.
173 private Button fLinkDataWithControlButton
= null;
175 * The Combo box for channel protocol selection.
177 private CCombo fControlProtocolCombo
= null;
179 * A selection listener that copies the protocol from control to data when being linked.
181 private ControlProtocolSelectionListener fCopyProtocolSelectionListener
;
183 * A selection listener updates the control port text depending on the control protocol selected.
185 private ProtocolComboSelectionListener fControlProtocolSelectionListener
;
187 * A selection listener updates the data port text depending on the data protocol selected.
189 private ProtocolComboSelectionListener fDataProtocolSelectionListener
;
191 * The text box for the host/IP address of the control channel.
193 private Text fControlHostAddressText
= null;
195 * A key listener that copies the host address from control to data when being linked.
197 private CopyModifyListener fControlUrlKeyListener
;
199 * A modify listener that updates the enablement of the dialog.
201 private UpdateEnablementModifyListener fUpdateEnablementModifyListener
;
203 * The text box for the control port.
205 private Text fControlPortText
= null;
207 * The Combo box for data protocol selection.
209 private CCombo fDataProtocolCombo
= null;
211 * The text box for the host/IP address of the data channel.
213 private Text fDataHostAddressText
= null;
215 * The text box for the data port.
217 private Text fDataPortText
= null;
219 * The parent where the new node should be added.
221 private TraceSessionGroup fParent
= null;
223 * The session name string.
225 private String fSessionName
= ""; //$NON-NLS-1$;
227 * The session path string.
229 private String fSessionPath
= null;
231 * Flag whether the session is snapshot or not
233 private boolean fIsSnapshot
= false;
235 * Flag whether the session is live or not
237 private boolean fIsLive
= false;
241 private Integer fLiveDelay
= 0;
243 * Flag whether default location (path) shall be used or not
245 private boolean fIsDefaultPath
= true;
247 * Flag whether the advanced options are enabled or not
249 private boolean fIsAdvancedEnabled
= false;
251 * The network URL in case control and data is configured together.
252 * If set, fControlUrl and fDataUrl will be null.
254 private String fNetworkUrl
= null;
256 * The control URL in case control and data is configured separately.
257 * If set, fDataUrl will be set too and fNetworkUrl will be null.
259 private String fControlUrl
= null;
261 * The data URL in case control and data is configured separately.
262 * If set, fControlUrl will be set too and fNetworkUrl will be null.
264 private String fDataUrl
= null;
266 * The trace path string.
268 private String fTracePath
= null;
270 * The Group for advanced configuration of Live mode.
272 private Group fLiveGroup
= null;
274 // ------------------------------------------------------------------------
276 // ------------------------------------------------------------------------
279 * @param shell - a shell for the display of the dialog
281 public CreateSessionDialog(Shell shell
) {
283 setShellStyle(SWT
.RESIZE
| getShellStyle());
286 // ------------------------------------------------------------------------
288 // ------------------------------------------------------------------------
291 public void initialize(TraceSessionGroup group
) {
293 fStreamingComposite
= null;
297 fSnapshotButton
= null;
298 fSessionName
= ""; //$NON-NLS-1$
301 fIsDefaultPath
= true;
302 fIsAdvancedEnabled
= false;
307 // ------------------------------------------------------------------------
309 // ------------------------------------------------------------------------
312 protected void configureShell(Shell newShell
) {
313 super.configureShell(newShell
);
314 newShell
.setText(Messages
.TraceControl_CreateSessionDialogTitle
);
315 newShell
.setImage(Activator
.getDefault().loadIcon(CREATE_SESSION_ICON_FILE
));
319 protected Control
createDialogArea(Composite parent
) {
320 Composite dialogAreaa
= (Composite
) super.createDialogArea(parent
);
321 setTitle(Messages
.TraceControl_CreateSessionDialogTitle
);
322 setMessage(Messages
.TraceControl_CreateSessionDialogMessage
);
325 fDialogComposite
= new Composite(dialogAreaa
, SWT
.NONE
);
326 GridLayout layout
= new GridLayout(1, true);
327 fDialogComposite
.setLayout(layout
);
328 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
330 Group sessionGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
331 sessionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
332 sessionGroup
.setLayout(new GridLayout(4, true));
334 fUpdateEnablementModifyListener
= new UpdateEnablementModifyListener();
336 Label sessionNameLabel
= new Label(sessionGroup
, SWT
.RIGHT
);
337 sessionNameLabel
.setText(Messages
.TraceControl_CreateSessionNameLabel
);
338 fSessionNameText
= new Text(sessionGroup
, SWT
.NONE
);
339 fSessionNameText
.setToolTipText(Messages
.TraceControl_CreateSessionNameTooltip
);
340 fSessionNameText
.addModifyListener(fUpdateEnablementModifyListener
);
341 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
342 data
.horizontalSpan
= 3;
343 fSessionNameText
.setLayoutData(data
);
345 fSessionPathLabel
= new Label(sessionGroup
, SWT
.RIGHT
);
346 fSessionPathLabel
.setText(Messages
.TraceControl_CreateSessionPathLabel
);
347 fSessionPathText
= new Text(sessionGroup
, SWT
.NONE
);
348 fSessionPathText
.setToolTipText(Messages
.TraceControl_CreateSessionPathTooltip
);
349 data
= new GridData(GridData
.FILL_HORIZONTAL
);
350 data
.horizontalSpan
= 3;
351 fSessionPathText
.setLayoutData(data
);
352 fSessionPathText
.addModifyListener(fUpdateEnablementModifyListener
);
354 if (fParent
.isSnapshotSupported() || fParent
.isLiveSupported()) {
355 fModeButtonGroup
= new Group(sessionGroup
, SWT
.NONE
);
356 data
= new GridData(GridData
.FILL_HORIZONTAL
);
357 data
.horizontalSpan
= 4;
358 fModeButtonGroup
.setLayoutData(data
);
359 fModeButtonGroup
.setLayout(new GridLayout(3, true));
361 SelectionAdapter modeChangedListener
= new SelectionAdapter() {
363 public void widgetSelected(SelectionEvent e
) {
364 if (fLiveButton
!= null) {
365 if (fLiveButton
.getSelection()) {
366 createAdvancedLiveGroup();
367 updateSessionPathEnablement();
368 updateProtocolComboItems();
371 updateSessionPathEnablement();
372 updateProtocolComboItems();
379 fNormalModeButton
= new Button(fModeButtonGroup
, SWT
.RADIO
);
380 fNormalModeButton
.setText(Messages
.TraceControl_CreateSessionNormalLabel
);
381 fNormalModeButton
.setToolTipText(Messages
.TraceControl_CreateSessionNormalTooltip
);
382 fNormalModeButton
.setSelection(true);
383 fNormalModeButton
.addSelectionListener(modeChangedListener
);
385 if (fParent
.isSnapshotSupported()) {
386 fSnapshotButton
= new Button(fModeButtonGroup
, SWT
.RADIO
);
387 fSnapshotButton
.setText(Messages
.TraceControl_CreateSessionSnapshotLabel
);
388 fSnapshotButton
.setToolTipText(Messages
.TraceControl_CreateSessionSnapshotTooltip
);
389 fSnapshotButton
.addSelectionListener(modeChangedListener
);
392 if (fParent
.isLiveSupported()) {
393 fLiveButton
= new Button(fModeButtonGroup
, SWT
.RADIO
);
394 fLiveButton
.setText(Messages
.TraceControl_CreateSessionLiveLabel
);
395 fLiveButton
.setToolTipText(Messages
.TraceControl_CreateSessionLiveTooltip
);
396 fLiveButton
.addSelectionListener(modeChangedListener
);
400 if (fParent
.isNetworkStreamingSupported() || fParent
.isLiveSupported()) {
401 createAdvancedOptionsComposite();
404 return fDialogComposite
;
407 private void createAdvancedOptionsComposite() {
409 fAdvancedGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
410 fAdvancedGroup
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
411 fAdvancedGroup
.setLayout(new GridLayout(1, true));
413 fAdvancedButton
= new Button(fAdvancedGroup
, SWT
.PUSH
);
414 fAdvancedButton
.setText(Messages
.TraceControl_CreateSessionConfigureStreamingButtonText
+ " >>>"); //$NON-NLS-1$
415 fAdvancedButton
.setToolTipText(Messages
.TraceControl_CreateSessionConfigureStreamingButtonTooltip
);
416 fAdvancedButton
.addSelectionListener(new SelectionAdapter() {
418 public void widgetSelected(SelectionEvent e
) {
419 if (fIsAdvancedEnabled
) {
420 fIsAdvancedEnabled
= false;
421 fAdvancedButton
.setText(">>> " + Messages
.TraceControl_CreateSessionConfigureStreamingButtonText
); //$NON-NLS-1$
422 fAdvancedButton
.setToolTipText(Messages
.TraceControl_CreateSessionConfigureStreamingButtonTooltip
);
424 if (fParent
.isNetworkStreamingSupported()) {
425 updateSessionPathEnablement();
426 disposeConfigureStreamingComposite();
429 if (fParent
.isLiveSupported()) {
433 fIsAdvancedEnabled
= true;
434 fAdvancedButton
.setText("<<< " + Messages
.TraceControl_CreateSessionNoStreamingButtonText
); //$NON-NLS-1$
435 fAdvancedButton
.setToolTipText(Messages
.TraceControl_CreateSessionNoStreamingButtonTooltip
);
437 if (fParent
.isNetworkStreamingSupported()) {
438 updateSessionPathEnablement();
439 createConfigureStreamingComposite();
441 if (fLiveButton
!= null && fLiveButton
.getSelection()) {
442 createAdvancedLiveGroup();
452 private void updateSessionPathEnablement() {
453 if (fIsAdvancedEnabled
|| fIsLive
) {
454 fSessionPathText
.setEnabled(false);
455 fSessionPathText
.setText(""); //$NON-NLS-1$
456 fSessionPathLabel
.setText(""); //$NON-NLS-1$
458 fSessionPathText
.setEnabled(true);
459 fSessionPathLabel
.setText(Messages
.TraceControl_CreateSessionPathLabel
);
463 private void updateProtocolComboItems() {
464 if (fControlProtocolCombo
== null || fControlProtocolCombo
.isDisposed()) {
468 int currentSelection
= fControlProtocolCombo
.getSelectionIndex() <= COMMON_URL_LAST_INDEX ?
469 fControlProtocolCombo
.getSelectionIndex() : DEFAULT_URL_INDEX
;
471 fControlProtocolCombo
.removeAll();
472 Enum
<?
extends Enum
<?
>>[] values
;
474 values
= LiveProtocol
.values();
475 } else if (fLinkDataWithControlButton
.getSelection()) {
476 values
= StreamingProtocol
.values();
478 values
= StreamingProtocol2
.values();
481 String
[] controlItems
= new String
[values
.length
];
482 for (int i
= 0; i
< controlItems
.length
; i
++) {
483 controlItems
[i
] = values
[i
].name();
485 fControlProtocolCombo
.setItems(controlItems
);
486 fDataProtocolCombo
.setItems(controlItems
);
489 if (currentSelection
!= -1) {
490 fControlProtocolCombo
.select(currentSelection
);
491 fDataProtocolCombo
.select(currentSelection
);
495 private void createConfigureStreamingComposite() {
496 if (fStreamingComposite
== null) {
497 fStreamingComposite
= new Group(fAdvancedGroup
, SWT
.SHADOW_NONE
);
498 GridLayout layout
= new GridLayout(1, true);
499 fStreamingComposite
.setLayout(layout
);
500 fStreamingComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
502 layout
= new GridLayout(7, true);
503 fStreamingComposite
.setLayout(layout
);
504 fStreamingComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
506 Label tracePathLabel
= new Label(fStreamingComposite
, SWT
.RIGHT
);
507 tracePathLabel
.setText(Messages
.TraceControl_CreateSessionTracePathText
);
508 fTracePathText
= new Text(fStreamingComposite
, SWT
.NONE
);
509 fTracePathText
.setToolTipText(Messages
.TraceControl_CreateSessionTracePathTooltip
);
512 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
513 data
.horizontalSpan
= 6;
514 fTracePathText
.setLayoutData(data
);
515 fTracePathText
.addModifyListener(fUpdateEnablementModifyListener
);
517 fLinkDataWithControlButton
= new Button(fStreamingComposite
, SWT
.CHECK
);
518 fLinkDataWithControlButton
.setText(Messages
.TraceControl_CreateSessionLinkButtonText
);
519 fLinkDataWithControlButton
.setToolTipText(Messages
.TraceControl_CreateSessionLinkButtonTooltip
);
520 data
= new GridData(GridData
.FILL_HORIZONTAL
);
521 data
.horizontalSpan
= 7;
522 fLinkDataWithControlButton
.setLayoutData(data
);
523 fLinkDataWithControlButton
.setSelection(true);
525 Label label
= new Label(fStreamingComposite
, SWT
.NONE
);
526 data
= new GridData(GridData
.FILL_HORIZONTAL
);
527 data
.horizontalSpan
= 1;
528 label
.setLayoutData(data
);
530 label
= new Label(fStreamingComposite
, SWT
.NONE
);
531 label
.setText(Messages
.TraceControl_CreateSessionProtocolLabelText
);
532 data
= new GridData(GridData
.FILL_HORIZONTAL
);
533 data
.horizontalSpan
= 1;
534 label
.setLayoutData(data
);
536 label
= new Label(fStreamingComposite
, SWT
.NONE
);
537 label
.setText(Messages
.TraceControl_CreateSessionAddressLabelText
);
538 data
= new GridData(GridData
.FILL_HORIZONTAL
);
539 data
.horizontalSpan
= 4;
540 label
.setLayoutData(data
);
542 label
= new Label(fStreamingComposite
, SWT
.NONE
);
543 label
.setText(Messages
.TraceControl_CreateSessionPortLabelText
);
544 data
= new GridData(GridData
.FILL_HORIZONTAL
);
545 data
.horizontalSpan
= 1;
546 label
.setLayoutData(data
);
548 label
= new Label(fStreamingComposite
, SWT
.RIGHT
);
549 label
.setText(Messages
.TraceControl_CreateSessionControlUrlLabel
);
550 data
= new GridData(GridData
.FILL_HORIZONTAL
);
551 data
.horizontalSpan
= 1;
552 label
.setLayoutData(data
);
554 fControlProtocolCombo
= new CCombo(fStreamingComposite
, SWT
.READ_ONLY
);
555 fControlProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionCommonProtocolTooltip
);
556 data
= new GridData(GridData
.FILL_HORIZONTAL
);
557 data
.horizontalSpan
= 1;
558 fControlProtocolCombo
.setLayoutData(data
);
559 fControlProtocolCombo
.addModifyListener(fUpdateEnablementModifyListener
);
561 fControlHostAddressText
= new Text(fStreamingComposite
, SWT
.NONE
);
562 fControlHostAddressText
.setToolTipText(Messages
.TraceControl_CreateSessionControlAddressTooltip
);
563 data
= new GridData(GridData
.FILL_HORIZONTAL
);
564 data
.horizontalSpan
= 4;
565 fControlHostAddressText
.setLayoutData(data
);
566 fControlHostAddressText
.addModifyListener(fUpdateEnablementModifyListener
);
568 fControlPortText
= new Text(fStreamingComposite
, SWT
.NONE
);
569 fControlPortText
.setToolTipText(Messages
.TraceControl_CreateSessionControlPortTooltip
);
570 data
= new GridData(GridData
.FILL_HORIZONTAL
);
571 data
.horizontalSpan
= 1;
572 fControlPortText
.setLayoutData(data
);
573 fControlPortText
.addModifyListener(fUpdateEnablementModifyListener
);
575 label
= new Label(fStreamingComposite
, SWT
.RIGHT
);
576 label
.setText(Messages
.TraceControl_CreateSessionDataUrlLabel
);
577 data
= new GridData(GridData
.FILL_HORIZONTAL
);
578 data
.horizontalSpan
= 1;
579 label
.setLayoutData(data
);
581 fDataProtocolCombo
= new CCombo(fStreamingComposite
, SWT
.READ_ONLY
);
582 fDataProtocolCombo
.setEnabled(false);
583 fDataProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionProtocolTooltip
);
584 data
= new GridData(GridData
.FILL_HORIZONTAL
);
585 data
.horizontalSpan
= 1;
586 fDataProtocolCombo
.setLayoutData(data
);
587 fDataProtocolCombo
.addModifyListener(fUpdateEnablementModifyListener
);
589 updateProtocolComboItems();
591 fDataHostAddressText
= new Text(fStreamingComposite
, SWT
.NONE
);
592 fDataHostAddressText
.setEnabled(false);
593 fDataHostAddressText
.setToolTipText(Messages
.TraceControl_CreateSessionDataAddressTooltip
);
594 data
= new GridData(GridData
.FILL_HORIZONTAL
);
595 data
.horizontalSpan
= 4;
596 fDataHostAddressText
.setLayoutData(data
);
597 fDataHostAddressText
.addModifyListener(fUpdateEnablementModifyListener
);
599 fDataPortText
= new Text(fStreamingComposite
, SWT
.NONE
);
600 fDataPortText
.setEnabled(true);
601 fDataPortText
.setToolTipText(Messages
.TraceControl_CreateSessionDataPortTooltip
);
602 data
= new GridData(GridData
.FILL_HORIZONTAL
);
603 data
.horizontalSpan
= 1;
604 fDataPortText
.setLayoutData(data
);
605 fDataPortText
.addModifyListener(fUpdateEnablementModifyListener
);
607 fCopyProtocolSelectionListener
= new ControlProtocolSelectionListener();
608 fControlProtocolSelectionListener
= new ProtocolComboSelectionListener(fControlProtocolCombo
, fControlPortText
);
609 fDataProtocolSelectionListener
= new ProtocolComboSelectionListener(fDataProtocolCombo
, fDataPortText
);
611 fControlProtocolCombo
.addSelectionListener(fCopyProtocolSelectionListener
);
613 fControlUrlKeyListener
= new CopyModifyListener(fControlHostAddressText
, fDataHostAddressText
);
614 fControlHostAddressText
.addModifyListener(fControlUrlKeyListener
);
616 fControlProtocolCombo
.select(DEFAULT_URL_INDEX
);
617 fDataProtocolCombo
.select(DEFAULT_URL_INDEX
);
619 fLinkDataWithControlButton
.addSelectionListener(new SelectionAdapter() {
621 public void widgetSelected(SelectionEvent e
) {
622 if (fLinkDataWithControlButton
.getSelection()) {
623 // Set enablement control data channel inputs
624 fDataProtocolCombo
.setEnabled(false);
625 fDataHostAddressText
.setEnabled(false);
626 fControlPortText
.setEnabled(true);
627 fDataPortText
.setEnabled(true);
630 fControlProtocolCombo
.removeSelectionListener(fControlProtocolSelectionListener
);
631 fDataProtocolCombo
.removeSelectionListener(fDataProtocolSelectionListener
);
632 fControlProtocolCombo
.addSelectionListener(fCopyProtocolSelectionListener
);
633 fControlHostAddressText
.addModifyListener(fControlUrlKeyListener
);
635 updateProtocolComboItems();
637 fDataHostAddressText
.setText(fControlHostAddressText
.getText());
640 fControlProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionCommonProtocolTooltip
);
642 // Enable data channel inputs
643 fDataProtocolCombo
.setEnabled(true);
644 fDataHostAddressText
.setEnabled(true);
647 fControlProtocolCombo
.removeSelectionListener(fCopyProtocolSelectionListener
);
648 fControlProtocolCombo
.addSelectionListener(fControlProtocolSelectionListener
);
649 fDataProtocolCombo
.addSelectionListener(fDataProtocolSelectionListener
);
650 fControlHostAddressText
.removeModifyListener(fControlUrlKeyListener
);
652 updateProtocolComboItems();
655 fDataProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionProtocolTooltip
);
656 fControlProtocolCombo
.setToolTipText(Messages
.TraceControl_CreateSessionProtocolTooltip
);
658 // Update control/data port enablement and input
659 if (fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.net
.name()) ||
660 fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.net6
.name())) {
661 fControlPortText
.setText(""); //$NON-NLS-1$
662 fControlPortText
.setEnabled(false);
664 fControlPortText
.setEnabled(true);
667 if (fDataProtocolCombo
.getItem(fDataProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.net
.name()) ||
668 fDataProtocolCombo
.getItem(fDataProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.net6
.name())) {
669 fDataPortText
.setText(""); //$NON-NLS-1$
670 fDataPortText
.setEnabled(false);
672 fDataPortText
.setEnabled(true);
680 private void createAdvancedLiveGroup() {
681 if (fLiveGroup
== null && fIsAdvancedEnabled
) {
682 GridLayout layout
= new GridLayout(7, true);
683 fLiveGroup
= new Group(fAdvancedGroup
, SWT
.NONE
);
684 fLiveGroup
.setLayout(layout
);
685 GridData layoutData
= new GridData(GridData
.FILL_BOTH
);
686 fLiveGroup
.setLayoutData(layoutData
);
688 Label liveDelayLabel
= new Label(fLiveGroup
, SWT
.RIGHT
);
689 layoutData
= new GridData(GridData
.FILL_HORIZONTAL
);
690 liveDelayLabel
.setText(Messages
.TraceControl_CreateSessionLiveDelayLabel
);
691 liveDelayLabel
.setLayoutData(layoutData
);
692 fLiveDelayText
= new Text(fLiveGroup
, SWT
.NONE
);
693 fLiveDelayText
.setText(DEFAULT_TEXT
);
694 fLiveDelayText
.setForeground(getShell().getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
695 fLiveDelayText
.setToolTipText(Messages
.TraceControl_CreateSessionLiveDelayTooltip
);
696 fLiveDelayText
.addVerifyListener(new VerifyListener() {
698 public void verifyText(VerifyEvent e
) {
699 // only numbers and default are allowed.
700 e
.doit
= e
.text
.matches("[0-9]*") || e
.text
.matches(DEFAULT_TEXT
); //$NON-NLS-1$
704 fLiveDelayText
.addModifyListener(new ModifyListener() {
706 public void modifyText(ModifyEvent event
) {
711 fLiveDelayText
.addFocusListener(new FocusListener() {
714 public void focusLost(FocusEvent e
) {
715 Text focusLostWidget
= (Text
) e
.widget
;
716 if (focusLostWidget
.getText().isEmpty()) {
717 focusLostWidget
.setText(DEFAULT_TEXT
);
718 focusLostWidget
.setForeground(getShell().getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
723 public void focusGained(FocusEvent e
) {
724 Text focusGainedWidget
= (Text
) e
.widget
;
725 if (focusGainedWidget
.getText().equals(DEFAULT_TEXT
)) {
726 focusGainedWidget
.setText(""); //$NON-NLS-1$
727 focusGainedWidget
.setForeground(getShell().getDisplay().getSystemColor(SWT
.COLOR_BLACK
));
732 layoutData
= new GridData(GridData
.FILL_HORIZONTAL
);
733 layoutData
.grabExcessHorizontalSpace
= true;
734 layoutData
.horizontalSpan
= 6;
735 fLiveDelayText
.setLayoutData(layoutData
);
740 private void disposeLiveGroup() {
741 if (fLiveGroup
!= null) {
742 fLiveGroup
.dispose();
748 private void disposeConfigureStreamingComposite() {
749 if (fStreamingComposite
!= null) {
750 fStreamingComposite
.dispose();
751 fStreamingComposite
= null;
756 protected void createButtonsForButtonBar(Composite parent
) {
757 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
758 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
761 private void updateEnablement() {
763 getButton(IDialogConstants
.OK_ID
).setEnabled(getErrorMessage() == null);
766 private void validate() {
767 // Validate input data
768 fSessionName
= fSessionNameText
.getText();
769 fSessionPath
= fSessionPathText
.getText();
770 setErrorMessage(null);
772 if (fParent
.isLiveSupported() && fLiveButton
!= null) {
773 fIsLive
= fLiveButton
.getSelection();
774 fLiveDelay
= LTTngControlServiceConstants
.UNUSED_VALUE
;
777 if (!"".equals(fSessionPath
)) { //$NON-NLS-1$
778 // validate sessionPath
779 if (!fIsAdvancedEnabled
&& !fIsLive
) {
780 TargetNodeComponent node
= (TargetNodeComponent
)fParent
.getParent();
781 IRemoteSystemProxy proxy
= node
.getRemoteSystemProxy();
782 IFileServiceSubSystem fsss
= proxy
.getFileServiceSubSystem();
785 IRemoteFile remoteFolder
= fsss
.getRemoteFileObject(fSessionPath
, new NullProgressMonitor());
787 if (remoteFolder
== null) {
788 setErrorMessage(Messages
.TraceControl_InvalidSessionPathError
+ " (" + fSessionPath
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
792 if (remoteFolder
.exists()) {
793 setErrorMessage(Messages
.TraceControl_SessionPathAlreadyExistsError
+ " (" + fSessionPath
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
796 } catch (SystemMessageException e
) {
797 setErrorMessage(Messages
.TraceControl_FileSubSystemError
+ "\n" + e
); //$NON-NLS-1$
802 fIsDefaultPath
= false;
805 if (fParent
.isSnapshotSupported()) {
806 fIsSnapshot
= fSnapshotButton
.getSelection();
813 if (fIsAdvancedEnabled
&& fStreamingComposite
!= null) {
814 // Validate input data
816 if (fIsLive
&& fLiveGroup
!= null) {
817 String liveDelayText
= fLiveDelayText
.getText();
819 fLiveDelay
= liveDelayText
.equals(DEFAULT_TEXT
) ? LTTngControlServiceConstants
.UNUSED_VALUE
: Integer
.valueOf(liveDelayText
);
820 } catch (NumberFormatException e
) {
821 setErrorMessage(Messages
.TraceControl_InvalidLiveDelayError
);
826 fTracePath
= fTracePathText
.getText();
828 if (fControlProtocolCombo
.getSelectionIndex() < 0) {
829 setErrorMessage("Control Protocol Text is empty\n"); //$NON-NLS-1$
833 if ("".equals(fControlHostAddressText
.getText())) { //$NON-NLS-1$
834 setErrorMessage("Control Address Text is empty\n"); //$NON-NLS-1$
838 if (!fLinkDataWithControlButton
.getSelection()) {
839 if (fDataProtocolCombo
.getSelectionIndex() < 0) {
840 setErrorMessage("Data Protocol Text is empty\n"); //$NON-NLS-1$
844 if ("".equals(fDataHostAddressText
.getText())) { //$NON-NLS-1$
845 setErrorMessage("Data Address Text is empty\n"); //$NON-NLS-1$
849 fControlUrl
= getUrlString(fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()),
850 fControlHostAddressText
.getText(),
851 fControlPortText
.getText(),
855 fDataUrl
= getUrlString(fDataProtocolCombo
.getItem(fDataProtocolCombo
.getSelectionIndex()),
856 fDataHostAddressText
.getText(),
858 fDataPortText
.getText(),
861 fNetworkUrl
= getUrlString(fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()),
862 fControlHostAddressText
.getText(),
863 fControlPortText
.getText(),
864 fDataPortText
.getText(),
869 if (fIsLive
&& fNetworkUrl
== null && fControlUrl
== null && fDataUrl
== null) {
870 fNetworkUrl
= SessionInfo
.DEFAULT_LIVE_NETWORK_URK
;
873 // Check for invalid names
874 if (!"".equals(fSessionName
) && !fSessionName
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
875 setErrorMessage(Messages
.TraceControl_InvalidSessionNameError
+ " (" + fSessionName
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
879 // Check if node with name already exists in parent
880 if(fParent
.containsChild(fSessionName
)) {
881 setErrorMessage(Messages
.TraceControl_SessionAlreadyExistsError
+ " (" + fSessionName
+ ")"); //$NON-NLS-1$ //$NON-NLS-2$
886 private static String
getUrlString(String proto
, String host
, String ctrlPort
, String dataPort
, String sessionPath
) {
887 //proto://[HOST|IP][:PORT1[:PORT2]][/TRACE_PATH]
888 StringBuilder stringBuilder
= new StringBuilder();
889 stringBuilder
.append(proto
);
890 stringBuilder
.append("://"); //$NON-NLS-1$
891 stringBuilder
.append(host
);
893 if ((ctrlPort
!= null) && (!"".equals(ctrlPort
))) { //$NON-NLS-1$
894 stringBuilder
.append(":"); //$NON-NLS-1$
895 stringBuilder
.append(ctrlPort
);
898 if ((dataPort
!= null) && (!"".equals(dataPort
))) { //$NON-NLS-1$
899 stringBuilder
.append(":"); //$NON-NLS-1$
900 stringBuilder
.append(dataPort
);
903 if ((sessionPath
!= null) && (!"".equals(sessionPath
))) { //$NON-NLS-1$
904 stringBuilder
.append("/"); //$NON-NLS-1$
905 stringBuilder
.append(sessionPath
);
907 return stringBuilder
.toString();
910 private static class CopyModifyListener
implements ModifyListener
{
911 private Text fSource
;
912 private Text fDestination
;
914 public CopyModifyListener(Text source
, Text destination
) {
916 fDestination
= destination
;
920 public void modifyText(ModifyEvent e
) {
921 fDestination
.setText(fSource
.getText());
925 private class ControlProtocolSelectionListener
extends SelectionAdapter
{
928 public void widgetSelected(SelectionEvent e
) {
929 fDataProtocolCombo
.select(fControlProtocolCombo
.getSelectionIndex());
930 if (fControlProtocolCombo
.getItem(fControlProtocolCombo
.getSelectionIndex()).equals(StreamingProtocol
.file
.name())) {
931 fControlPortText
.setText(""); //$NON-NLS-1$
932 fDataPortText
.setText(""); //$NON-NLS-1$
933 fControlPortText
.setEnabled(false);
934 fDataPortText
.setEnabled(false);
936 fControlPortText
.setEnabled(true);
937 fDataPortText
.setEnabled(true);
942 private class ProtocolComboSelectionListener
extends SelectionAdapter
{
944 private CCombo fCombo
;
945 private Text fPortText
;
947 public ProtocolComboSelectionListener(CCombo combo
, Text portText
) {
949 fPortText
= portText
;
953 public void widgetSelected(SelectionEvent e
) {
954 if (fCombo
.getItem(fCombo
.getSelectionIndex()).equals(StreamingProtocol
.net
.name()) ||
955 fCombo
.getItem(fCombo
.getSelectionIndex()).equals(StreamingProtocol
.net6
.name())) {
956 fPortText
.setText(""); //$NON-NLS-1$
957 fPortText
.setEnabled(false);
959 fPortText
.setEnabled(true);
965 public ISessionInfo
getParameters() {
966 ISessionInfo sessionInfo
= new SessionInfo(fSessionName
);
968 boolean isStreaming
= (fIsAdvancedEnabled
&& fStreamingComposite
!= null) || fIsLive
;
970 sessionInfo
.setNetworkUrl(fNetworkUrl
);
971 sessionInfo
.setControlUrl(fControlUrl
);
972 sessionInfo
.setDataUrl(fDataUrl
);
973 sessionInfo
.setStreamedTrace(true);
974 } else if (!fIsDefaultPath
) {
975 sessionInfo
.setSessionPath(fSessionPath
);
978 sessionInfo
.setLive(fIsLive
);
979 sessionInfo
.setLiveDelay(fLiveDelay
);
980 sessionInfo
.setSnapshot(fIsSnapshot
);
985 private final class UpdateEnablementModifyListener
implements ModifyListener
{
987 public void modifyText(ModifyEvent e
) {