gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / dialogs / CreateSessionDialog.java
index dd090fe55af4b35ca18c4e84a81117289f7f9260..9453ce76371c9b18cda76989309eacd48b39730c 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2012, 2013 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -9,6 +9,7 @@
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
  *   Bernd Hufmann - Updated for support of LTTng Tools 2.1
+ *   Marc-Andre Laperle - Support for creating a live session
  **********************************************************************/
 
 package org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs;
@@ -23,15 +24,20 @@ import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages
 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionGroup;
 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.IRemoteSystemProxy;
+import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.LTTngControlServiceConstants;
 import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
 import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
 import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
@@ -59,6 +65,26 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
      */
     public static final String CREATE_SESSION_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$
 
+    /**
+     *  To indicate that the default value will be used for this field
+     */
+    private static final String DEFAULT_TEXT = "<" + Messages.EnableChannelDialog_DefaultMessage + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+
+    /**
+     * The default port for the connection to Relayd. This actual value is
+     * needed because this is not an optional argument to a command; this is
+     * what is used to connect directly to Relayd from Java through a socket.
+     * There is also currently no way to know the default value by issuing a
+     * command.
+     */
+    private static final int DEFAULT_LIVE_PORT = 5344;
+
+    /**
+     * The default address for the connection to Relayd. Only local is supported
+     * for now. See above comment for why it's needed.
+     */
+    private static final String DEFAULT_LIVE_URL = "127.0.0.1"; //$NON-NLS-1$
+
     /**
      * Supported network protocols for streaming
      */
@@ -71,6 +97,16 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
         file,
    }
 
+    /**
+     * Supported network protocols for Live tracing
+     */
+    private enum LiveProtocol {
+        /** Default network protocol for IPv4 (TCP)*/
+        net,
+        /** Default network protocol for IPv6 (TCP)*/
+        net6
+   }
+
     private enum StreamingProtocol2 {
         /** Default network protocol for IPv4 (TCP)*/
         net,
@@ -109,18 +145,35 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
      * The text widget for the session path.
      */
     private Text fSessionPathText = null;
+    /**
+     * The button widget to select a normal session
+     */
+    private Button fNormalModeButton = null;
     /**
      * The button widget to select a snapshot session
      */
     private Button fSnapshotButton = null;
     /**
-     * The Group for stream configuration.
+     * The group that contains the mutually exclusive mode buttons
+     */
+    private Group fModeButtonGroup = null;
+    /**
+     * The button widget to select a live session
+     */
+    private Button fLiveButton = null;
+
+    /**
+     * The text widget to set a live delay
+     */
+    private Text fLiveDelayText = null;
+    /**
+     * The Group for advanced configuration.
      */
-    private Group fMainStreamingGroup = null;
+    private Group fAdvancedGroup = null;
     /**
-     * The button to show streaming options.
+     * The button to show advanced options.
      */
-    private Button fConfigureStreamingButton = null;
+    private Button fAdvancedButton = null;
     /**
      * The composite with streaming configuration parameter.
      */
@@ -184,7 +237,7 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
     /**
      * The session name string.
      */
-    private String fSessionName = null;
+    private String fSessionName = ""; //$NON-NLS-1$;
     /**
      * The  session path string.
      */
@@ -193,14 +246,38 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
      * Flag whether the session is snapshot or not
      */
     private boolean fIsSnapshot = false;
+    /**
+     * Flag whether the session is live or not
+     */
+    private boolean fIsLive = false;
+    /**
+     * The text box for the live address (relayd).
+     */
+    private Text fLiveHostAddressText = null;
+    /**
+     * The text box for the live port (relayd).
+     */
+    private Text fLivePortText = null;
+    /**
+     * The live delay
+     */
+    private Integer fLiveDelay = 0;
+    /**
+     * The live url.
+     */
+    private String fLiveUrl = null;
+    /**
+     * The live port.
+     */
+    private Integer fLivePort = 0;
     /**
      * Flag whether default location (path) shall be used or not
      */
     private boolean fIsDefaultPath = true;
     /**
-     * Flag whether the trace is streamed or not
+     * Flag whether the advanced options are enabled or not
      */
-    private boolean fIsStreamedTrace = false;
+    private boolean fIsAdvancedEnabled = false;
     /**
      * The network URL in case control and data is configured together.
      * If set, fControlUrl and fDataUrl will be null.
@@ -220,6 +297,10 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
      * The trace path string.
      */
     private String fTracePath = null;
+    /**
+     * The Group for advanced configuration of Live mode.
+     */
+    private Group fLiveGroup = null;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -241,11 +322,15 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
     public void initialize(TraceSessionGroup group) {
        fParent = group;
        fStreamingComposite = null;
-       fSessionName = null;
+       fLiveGroup = null;
+       fLiveButton = null;
+       fIsLive = false;
+       fSnapshotButton = null;
+       fSessionName = ""; //$NON-NLS-1$
        fSessionPath = null;
        fIsSnapshot = false;
        fIsDefaultPath = true;
-       fIsStreamedTrace = false;
+       fIsAdvancedEnabled = false;
        fNetworkUrl = null;
        fControlUrl = null;
        fDataUrl = null;
@@ -284,39 +369,66 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
         fSessionNameText = new Text(sessionGroup, SWT.NONE);
         fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip);
         fSessionNameText.addModifyListener(fUpdateEnablementModifyListener);
+        GridData data = new GridData(GridData.FILL_HORIZONTAL);
+        data.horizontalSpan = 3;
+        fSessionNameText.setLayoutData(data);
 
         fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT);
         fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
         fSessionPathText = new Text(sessionGroup, SWT.NONE);
         fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip);
+        data = new GridData(GridData.FILL_HORIZONTAL);
+        data.horizontalSpan = 3;
+        fSessionPathText.setLayoutData(data);
         fSessionPathText.addModifyListener(fUpdateEnablementModifyListener);
 
-        if (fParent.isSnapshotSupported()) {
-            fSnapshotButton = new Button(sessionGroup, SWT.CHECK);
-            fSnapshotButton.setText(Messages.TraceControl_CreateSessionSnapshotLabel);
-            fSnapshotButton.setToolTipText(Messages.TraceControl_CreateSessionSnapshotTooltip);
-            GridData data = new GridData(GridData.FILL_HORIZONTAL);
+        if (fParent.isSnapshotSupported() || fParent.isLiveSupported()) {
+            fModeButtonGroup = new Group(sessionGroup, SWT.NONE);
+            data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 4;
-            fSnapshotButton.setLayoutData(data);
-            fSnapshotButton.addSelectionListener(new SelectionAdapter() {
+            fModeButtonGroup.setLayoutData(data);
+            fModeButtonGroup.setLayout(new GridLayout(3, true));
+
+            SelectionAdapter modeChangedListener = new SelectionAdapter() {
                 @Override
                 public void widgetSelected(SelectionEvent e) {
+                    if (fLiveButton != null) {
+                        if (fLiveButton.getSelection()) {
+                            createAdvancedLiveGroup();
+                            updateSessionPathEnablement();
+                            updateProtocolComboItems();
+                        } else {
+                            disposeLiveGroup();
+                            updateSessionPathEnablement();
+                            updateProtocolComboItems();
+                        }
+                    }
                     updateEnablement();
                 }
-            });
-        }
-
-        // layout widgets
-        GridData data = new GridData(GridData.FILL_HORIZONTAL);
-        data.horizontalSpan = 3;
-
-        fSessionNameText.setLayoutData(data);
+            };
+
+            fNormalModeButton = new Button(fModeButtonGroup, SWT.RADIO);
+            fNormalModeButton.setText(Messages.TraceControl_CreateSessionNormalLabel);
+            fNormalModeButton.setToolTipText(Messages.TraceControl_CreateSessionNormalTooltip);
+            fNormalModeButton.setSelection(true);
+            fNormalModeButton.addSelectionListener(modeChangedListener);
+
+            if (fParent.isSnapshotSupported()) {
+                fSnapshotButton = new Button(fModeButtonGroup, SWT.RADIO);
+                fSnapshotButton.setText(Messages.TraceControl_CreateSessionSnapshotLabel);
+                fSnapshotButton.setToolTipText(Messages.TraceControl_CreateSessionSnapshotTooltip);
+                fSnapshotButton.addSelectionListener(modeChangedListener);
+            }
 
-        data = new GridData(GridData.FILL_HORIZONTAL);
-        data.horizontalSpan = 3;
-        fSessionPathText.setLayoutData(data);
+            if (fParent.isLiveSupported()) {
+                fLiveButton = new Button(fModeButtonGroup, SWT.RADIO);
+                fLiveButton.setText(Messages.TraceControl_CreateSessionLiveLabel);
+                fLiveButton.setToolTipText(Messages.TraceControl_CreateSessionLiveTooltip);
+                fLiveButton.addSelectionListener(modeChangedListener);
+            }
+        }
 
-        if (fParent.isNetworkStreamingSupported()) {
+        if (fParent.isNetworkStreamingSupported() || fParent.isLiveSupported()) {
             createAdvancedOptionsComposite();
         }
 
@@ -325,31 +437,41 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
 
     private void createAdvancedOptionsComposite() {
 
-        fMainStreamingGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
-        fMainStreamingGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
-        fMainStreamingGroup.setLayout(new GridLayout(1, true));
+        fAdvancedGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
+        fAdvancedGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
+        fAdvancedGroup.setLayout(new GridLayout(1, true));
 
-        fConfigureStreamingButton = new Button(fMainStreamingGroup, SWT.PUSH);
-        fConfigureStreamingButton.setText(Messages.TraceControl_CreateSessionConfigureStreamingButtonText + " >>>"); //$NON-NLS-1$
-        fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
-        fConfigureStreamingButton.addSelectionListener(new SelectionAdapter() {
+        fAdvancedButton = new Button(fAdvancedGroup, SWT.PUSH);
+        fAdvancedButton.setText(Messages.TraceControl_CreateSessionConfigureStreamingButtonText + " >>>"); //$NON-NLS-1$
+        fAdvancedButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
+        fAdvancedButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                if (fIsStreamedTrace) {
-                    fIsStreamedTrace = false;
-                    fConfigureStreamingButton.setText(">>> " + Messages.TraceControl_CreateSessionConfigureStreamingButtonText); //$NON-NLS-1$
-                    fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
-                    fSessionPathText.setEnabled(true);
-                    fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
-                    disposeConfigureStreamingComposite();
+                if (fIsAdvancedEnabled) {
+                    fIsAdvancedEnabled = false;
+                    fAdvancedButton.setText(">>> " + Messages.TraceControl_CreateSessionConfigureStreamingButtonText); //$NON-NLS-1$
+                    fAdvancedButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
+
+                    if (fParent.isNetworkStreamingSupported()) {
+                        updateSessionPathEnablement();
+                        disposeConfigureStreamingComposite();
+                    }
+
+                    if (fParent.isLiveSupported()) {
+                        disposeLiveGroup();
+                    }
                 } else {
-                    fIsStreamedTrace = true;
-                    fConfigureStreamingButton.setText("<<< " + Messages.TraceControl_CreateSessionNoStreamingButtonText); //$NON-NLS-1$
-                    fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionNoStreamingButtonTooltip);
-                    fSessionPathText.setEnabled(false);
-                    fSessionPathText.setText(""); //$NON-NLS-1$
-                    fSessionPathLabel.setText(""); //$NON-NLS-1$
-                    createConfigureStreamingComposite();
+                    fIsAdvancedEnabled = true;
+                    fAdvancedButton.setText("<<< " + Messages.TraceControl_CreateSessionNoStreamingButtonText); //$NON-NLS-1$
+                    fAdvancedButton.setToolTipText(Messages.TraceControl_CreateSessionNoStreamingButtonTooltip);
+
+                    if (fParent.isNetworkStreamingSupported()) {
+                        updateSessionPathEnablement();
+                        createConfigureStreamingComposite();
+                    }
+                    if (fLiveButton != null && fLiveButton.getSelection()) {
+                        createAdvancedLiveGroup();
+                    }
                 }
 
                 updateEnablement();
@@ -358,21 +480,63 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
         });
     }
 
+    private void updateSessionPathEnablement() {
+        if (fIsAdvancedEnabled || fIsLive) {
+            fSessionPathText.setEnabled(false);
+            fSessionPathText.setText(""); //$NON-NLS-1$
+            fSessionPathLabel.setText(""); //$NON-NLS-1$
+        } else {
+            fSessionPathText.setEnabled(true);
+            fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
+        }
+    }
+
+    private void updateProtocolComboItems() {
+        if (fControlProtocolCombo == null || fControlProtocolCombo.isDisposed()) {
+            return;
+        }
+
+        int currentSelection = fControlProtocolCombo.getSelectionIndex() <= COMMON_URL_LAST_INDEX ?
+                fControlProtocolCombo.getSelectionIndex() : DEFAULT_URL_INDEX;
+
+        fControlProtocolCombo.removeAll();
+        Enum<? extends Enum<?>>[] values;
+        if (fIsLive) {
+            values = LiveProtocol.values();
+        } else if (fLinkDataWithControlButton.getSelection()) {
+            values = StreamingProtocol.values();
+        } else {
+            values = StreamingProtocol2.values();
+        }
+
+        String[] controlItems = new String[values.length];
+        for (int i = 0; i < controlItems.length; i++) {
+            controlItems[i] = values[i].name();
+        }
+        fControlProtocolCombo.setItems(controlItems);
+        fDataProtocolCombo.setItems(controlItems);
+
+        // Set selection
+        if (currentSelection != -1) {
+            fControlProtocolCombo.select(currentSelection);
+            fDataProtocolCombo.select(currentSelection);
+        }
+    }
+
     private void createConfigureStreamingComposite() {
         if (fStreamingComposite == null) {
-            fStreamingComposite = new Composite(fMainStreamingGroup, SWT.NONE);
+            fStreamingComposite = new Group(fAdvancedGroup, SWT.SHADOW_NONE);
             GridLayout layout = new GridLayout(1, true);
             fStreamingComposite.setLayout(layout);
             fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
 
-            Group urlGroup = new Group(fStreamingComposite, SWT.SHADOW_NONE);
             layout = new GridLayout(7, true);
-            urlGroup.setLayout(layout);
-            urlGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
+            fStreamingComposite.setLayout(layout);
+            fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
 
-            Label tracePathLabel = new Label(urlGroup, SWT.RIGHT);
+            Label tracePathLabel = new Label(fStreamingComposite, SWT.RIGHT);
             tracePathLabel.setText(Messages.TraceControl_CreateSessionTracePathText);
-            fTracePathText = new Text(urlGroup, SWT.NONE);
+            fTracePathText = new Text(fStreamingComposite, SWT.NONE);
             fTracePathText.setToolTipText(Messages.TraceControl_CreateSessionTracePathTooltip);
 
             // layout widgets
@@ -381,7 +545,7 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
             fTracePathText.setLayoutData(data);
             fTracePathText.addModifyListener(fUpdateEnablementModifyListener);
 
-            fLinkDataWithControlButton = new Button(urlGroup, SWT.CHECK);
+            fLinkDataWithControlButton = new Button(fStreamingComposite, SWT.CHECK);
             fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText);
             fLinkDataWithControlButton.setToolTipText(Messages.TraceControl_CreateSessionLinkButtonTooltip);
             data = new GridData(GridData.FILL_HORIZONTAL);
@@ -389,63 +553,63 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
             fLinkDataWithControlButton.setLayoutData(data);
             fLinkDataWithControlButton.setSelection(true);
 
-            Label label = new Label(urlGroup, SWT.NONE);
+            Label label = new Label(fStreamingComposite, SWT.NONE);
             data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 1;
             label.setLayoutData(data);
 
-            label = new Label(urlGroup, SWT.NONE);
+            label = new Label(fStreamingComposite, SWT.NONE);
             label.setText(Messages.TraceControl_CreateSessionProtocolLabelText);
             data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 1;
             label.setLayoutData(data);
 
-            label = new Label(urlGroup, SWT.NONE);
+            label = new Label(fStreamingComposite, SWT.NONE);
             label.setText(Messages.TraceControl_CreateSessionAddressLabelText);
             data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 4;
             label.setLayoutData(data);
 
-            label = new Label(urlGroup, SWT.NONE);
+            label = new Label(fStreamingComposite, SWT.NONE);
             label.setText(Messages.TraceControl_CreateSessionPortLabelText);
             data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 1;
             label.setLayoutData(data);
 
-            label = new Label(urlGroup, SWT.RIGHT);
+            label = new Label(fStreamingComposite, SWT.RIGHT);
             label.setText(Messages.TraceControl_CreateSessionControlUrlLabel);
             data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 1;
             label.setLayoutData(data);
 
-            fControlProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY);
+            fControlProtocolCombo = new CCombo(fStreamingComposite, SWT.READ_ONLY);
             fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip);
             data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 1;
             fControlProtocolCombo.setLayoutData(data);
             fControlProtocolCombo.addModifyListener(fUpdateEnablementModifyListener);
 
-            fControlHostAddressText = new Text(urlGroup, SWT.NONE);
+            fControlHostAddressText = new Text(fStreamingComposite, SWT.NONE);
             fControlHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionControlAddressTooltip);
             data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 4;
             fControlHostAddressText.setLayoutData(data);
             fControlHostAddressText.addModifyListener(fUpdateEnablementModifyListener);
 
-            fControlPortText = new Text(urlGroup, SWT.NONE);
+            fControlPortText = new Text(fStreamingComposite, SWT.NONE);
             fControlPortText.setToolTipText(Messages.TraceControl_CreateSessionControlPortTooltip);
             data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 1;
             fControlPortText.setLayoutData(data);
             fControlPortText.addModifyListener(fUpdateEnablementModifyListener);
 
-            label = new Label(urlGroup, SWT.RIGHT);
+            label = new Label(fStreamingComposite, SWT.RIGHT);
             label.setText(Messages.TraceControl_CreateSessionDataUrlLabel);
             data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 1;
             label.setLayoutData(data);
 
-            fDataProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY);
+            fDataProtocolCombo = new CCombo(fStreamingComposite, SWT.READ_ONLY);
             fDataProtocolCombo.setEnabled(false);
             fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
             data = new GridData(GridData.FILL_HORIZONTAL);
@@ -453,14 +617,9 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
             fDataProtocolCombo.setLayoutData(data);
             fDataProtocolCombo.addModifyListener(fUpdateEnablementModifyListener);
 
-            String items[] = new String[StreamingProtocol.values().length];
-            for (int i = 0; i < items.length; i++) {
-                items[i] = StreamingProtocol.values()[i].name();
-            }
-            fControlProtocolCombo.setItems(items);
-            fDataProtocolCombo.setItems(items);
+            updateProtocolComboItems();
 
-            fDataHostAddressText = new Text(urlGroup, SWT.NONE);
+            fDataHostAddressText = new Text(fStreamingComposite, SWT.NONE);
             fDataHostAddressText.setEnabled(false);
             fDataHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionDataAddressTooltip);
             data = new GridData(GridData.FILL_HORIZONTAL);
@@ -468,7 +627,7 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
             fDataHostAddressText.setLayoutData(data);
             fDataHostAddressText.addModifyListener(fUpdateEnablementModifyListener);
 
-            fDataPortText = new Text(urlGroup, SWT.NONE);
+            fDataPortText = new Text(fStreamingComposite, SWT.NONE);
             fDataPortText.setEnabled(true);
             fDataPortText.setToolTipText(Messages.TraceControl_CreateSessionDataPortTooltip);
             data = new GridData(GridData.FILL_HORIZONTAL);
@@ -504,22 +663,8 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
                         fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
                         fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
 
-                        // Get previous selection and validate
-                        int currentSelection = fControlProtocolCombo.getSelectionIndex() <= COMMON_URL_LAST_INDEX ?
-                                fControlProtocolCombo.getSelectionIndex() : DEFAULT_URL_INDEX;
+                        updateProtocolComboItems();
 
-                        // Update combo box items
-                        fControlProtocolCombo.removeAll();
-                        String[] controlItems = new String[StreamingProtocol.values().length];
-                        for (int i = 0; i < controlItems.length; i++) {
-                            controlItems[i] = StreamingProtocol.values()[i].name();
-                        }
-                        fControlProtocolCombo.setItems(controlItems);
-                        fDataProtocolCombo.setItems(controlItems);
-
-                        // Set selection
-                        fControlProtocolCombo.select(currentSelection);
-                        fDataProtocolCombo.select(currentSelection);
                         fDataHostAddressText.setText(fControlHostAddressText.getText());
 
                         // Update tool tips
@@ -535,19 +680,7 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
                         fDataProtocolCombo.addSelectionListener(fDataProtocolSelectionListener);
                         fControlHostAddressText.removeModifyListener(fControlUrlKeyListener);
 
-                        // Update combo box items
-                        int currentSelection = fControlProtocolCombo.getSelectionIndex();
-                        fControlProtocolCombo.removeAll();
-                        String[] controlItems = new String[StreamingProtocol2.values().length];
-                        for (int i = 0; i < controlItems.length; i++) {
-                            controlItems[i] = StreamingProtocol2.values()[i].name();
-                        }
-                        fControlProtocolCombo.setItems(controlItems);
-                        fDataProtocolCombo.setItems(controlItems);
-
-                        // Set selection
-                        fControlProtocolCombo.select(currentSelection);
-                        fDataProtocolCombo.select(currentSelection);
+                        updateProtocolComboItems();
 
                         // Update tool tips
                         fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
@@ -575,6 +708,94 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
         }
     }
 
+    private void createAdvancedLiveGroup() {
+        if (fLiveGroup == null && fIsAdvancedEnabled) {
+            GridLayout layout = new GridLayout(7, true);
+            fLiveGroup = new Group(fAdvancedGroup, SWT.NONE);
+            fLiveGroup.setLayout(layout);
+            GridData layoutData = new GridData(GridData.FILL_BOTH);
+            fLiveGroup.setLayoutData(layoutData);
+
+            Label label = new Label(fLiveGroup, SWT.NONE);
+            label.setText(Messages.TraceControl_CreateSessionLiveConnectionLabel);
+            layoutData = new GridData(GridData.FILL_HORIZONTAL);
+            layoutData.horizontalSpan = 2;
+            label.setLayoutData(layoutData);
+
+            fLiveHostAddressText = new Text(fLiveGroup, SWT.NONE);
+            fLiveHostAddressText.setText(DEFAULT_LIVE_URL);
+            fLiveHostAddressText.setEnabled(false);
+            fLiveHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionLiveConnectionUrlTooltip);
+            layoutData = new GridData(GridData.FILL_HORIZONTAL);
+            layoutData.horizontalSpan = 4;
+            fLiveHostAddressText.setLayoutData(layoutData);
+
+            fLivePortText = new Text(fLiveGroup, SWT.NONE);
+            fLivePortText.setText(Integer.toString(DEFAULT_LIVE_PORT));
+            fLivePortText.setToolTipText(Messages.TraceControl_CreateSessionLiveConnectionPortTooltip);
+            layoutData = new GridData(GridData.FILL_HORIZONTAL);
+            fLivePortText.setLayoutData(layoutData);
+
+            Label liveDelayLabel = new Label(fLiveGroup, SWT.NONE);
+            layoutData = new GridData(GridData.FILL_HORIZONTAL);
+            liveDelayLabel.setText(Messages.TraceControl_CreateSessionLiveDelayLabel);
+            liveDelayLabel.setLayoutData(layoutData);
+            fLiveDelayText = new Text(fLiveGroup, SWT.NONE);
+            fLiveDelayText.setText(DEFAULT_TEXT);
+            fLiveDelayText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
+            fLiveDelayText.setToolTipText(Messages.TraceControl_CreateSessionLiveDelayTooltip);
+            fLiveDelayText.addVerifyListener(new VerifyListener() {
+                @Override
+                public void verifyText(VerifyEvent e) {
+                    // only numbers and default are allowed.
+                    e.doit = e.text.matches("[0-9]*") || e.text.matches(DEFAULT_TEXT); //$NON-NLS-1$
+                    updateEnablement();
+                }
+            });
+            fLiveDelayText.addModifyListener(new ModifyListener() {
+                @Override
+                public void modifyText(ModifyEvent event) {
+                    updateEnablement();
+                }
+            });
+
+            fLiveDelayText.addFocusListener(new FocusListener() {
+
+                @Override
+                public void focusLost(FocusEvent e) {
+                    Text focusLostWidget = (Text) e.widget;
+                    if (focusLostWidget.getText().isEmpty()) {
+                        focusLostWidget.setText(DEFAULT_TEXT);
+                        focusLostWidget.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
+                    }
+                }
+
+                @Override
+                public void focusGained(FocusEvent e) {
+                    Text focusGainedWidget = (Text) e.widget;
+                    if (focusGainedWidget.getText().equals(DEFAULT_TEXT)) {
+                        focusGainedWidget.setText(""); //$NON-NLS-1$
+                        focusGainedWidget.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
+                    }
+                }
+            });
+
+            layoutData = new GridData(GridData.FILL_HORIZONTAL);
+            layoutData.grabExcessHorizontalSpace = true;
+            layoutData.horizontalSpan = 6;
+            fLiveDelayText.setLayoutData(layoutData);
+            getShell().pack();
+        }
+    }
+
+    private void disposeLiveGroup() {
+        if (fLiveGroup != null) {
+            fLiveGroup.dispose();
+            fLiveGroup = null;
+            getShell().pack();
+        }
+    }
+
     private void disposeConfigureStreamingComposite() {
         if (fStreamingComposite != null) {
             fStreamingComposite.dispose();
@@ -599,9 +820,16 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
         fSessionPath = fSessionPathText.getText();
         setErrorMessage(null);
 
+        if (fParent.isLiveSupported() && fLiveButton != null) {
+            fIsLive = fLiveButton.getSelection();
+            fLiveDelay = LTTngControlServiceConstants.UNUSED_VALUE;
+            fLiveUrl = DEFAULT_LIVE_URL;
+            fLivePort = DEFAULT_LIVE_PORT;
+        }
+
         if (!"".equals(fSessionPath)) { //$NON-NLS-1$
             // validate sessionPath
-            if (!fIsStreamedTrace) {
+            if (!fIsAdvancedEnabled && !fIsLive) {
                 TargetNodeComponent node = (TargetNodeComponent)fParent.getParent();
                 IRemoteSystemProxy proxy = node.getRemoteSystemProxy();
                 IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem();
@@ -635,8 +863,21 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
         fControlUrl = null;
         fDataUrl = null;
 
-        if (fIsStreamedTrace && fStreamingComposite != null) {
+        if (fIsAdvancedEnabled && fStreamingComposite != null) {
             // Validate input data
+
+            if (fIsLive && fLiveGroup != null) {
+                String liveDelayText = fLiveDelayText.getText();
+                try {
+                    fLiveDelay = liveDelayText.equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.valueOf(liveDelayText);
+                    fLivePort = Integer.valueOf(fLivePortText.getText());
+                    fLiveUrl = fLiveHostAddressText.getText();
+                } catch (NumberFormatException e) {
+                    setErrorMessage(Messages.TraceControl_InvalidLiveDelayError);
+                    return;
+                }
+            }
+
             fTracePath = fTracePathText.getText();
 
             if (fControlProtocolCombo.getSelectionIndex() < 0) {
@@ -680,6 +921,10 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
             }
         }
 
+        if (fIsLive && fNetworkUrl == null && fControlUrl == null && fDataUrl == null) {
+            fNetworkUrl = SessionInfo.DEFAULT_LIVE_NETWORK_URK;
+        }
+
         // Check for invalid names
         if (!"".equals(fSessionName) && !fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
             setErrorMessage(Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n");  //$NON-NLS-1$ //$NON-NLS-2$
@@ -775,7 +1020,8 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
     public ISessionInfo getParameters() {
         ISessionInfo sessionInfo = new SessionInfo(fSessionName);
 
-        if (fIsStreamedTrace) {
+        boolean isStreaming = (fIsAdvancedEnabled && fStreamingComposite != null) || fIsLive;
+        if (isStreaming) {
             sessionInfo.setNetworkUrl(fNetworkUrl);
             sessionInfo.setControlUrl(fControlUrl);
             sessionInfo.setDataUrl(fDataUrl);
@@ -784,6 +1030,10 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
             sessionInfo.setSessionPath(fSessionPath);
         }
 
+        sessionInfo.setLive(fIsLive);
+        sessionInfo.setLiveUrl(fLiveUrl);
+        sessionInfo.setLivePort(fLivePort);
+        sessionInfo.setLiveDelay(fLiveDelay);
         sessionInfo.setSnapshot(fIsSnapshot);
 
         return sessionInfo;
This page took 0.065832 seconds and 5 git commands to generate.