lttng: Support for port number in lttng control (bug 406122)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / NewConnectionDialog.java
index 752c7a81dcef2b0fc330c05a8fc6c28bc6c34f57..e5a0c867a341d17d848b89795efd2fb1c053f439 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -19,11 +19,14 @@ import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy;
 import org.eclipse.rse.core.model.IHost;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -83,6 +86,10 @@ public class NewConnectionDialog extends Dialog implements INewConnectionDialog
      * The text widget for the node address (IP or DNS name)
      */
     private Text fHostNameText = null;
+    /**
+     * The text widget for the IP port
+     */
+    private Text fPortText = null;
     /**
      * The parent where the new node should be added.
      */
@@ -95,7 +102,10 @@ public class NewConnectionDialog extends Dialog implements INewConnectionDialog
      * The node address (IP or DNS name) string.
      */
     private String fHostName = null;
-
+    /**
+     * The IP port of the connection.
+     */
+    private int fPort = IRemoteSystemProxy.INVALID_PORT_NUMBER;
     /**
      * Input list of existing RSE hosts available for selection.
      */
@@ -136,6 +146,11 @@ public class NewConnectionDialog extends Dialog implements INewConnectionDialog
         return fHostName;
     }
 
+    @Override
+    public int getPort() {
+        return fPort;
+    }
+
     /*
      * (non-Javadoc)
      * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.INewConnectionDialog#setTraceControlParent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent)
@@ -156,6 +171,11 @@ public class NewConnectionDialog extends Dialog implements INewConnectionDialog
         }
     }
 
+    @Override
+    public void setPort(int port) {
+        fPort = port;
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -227,6 +247,19 @@ public class NewConnectionDialog extends Dialog implements INewConnectionDialog
         fHostNameText.setToolTipText(Messages.TraceControl_NewNodeHostNameTooltip);
         fHostNameText.setEnabled(fExistingHosts.length == 0);
 
+        Label portLabel = new Label(fTextGroup, SWT.RIGHT);
+        portLabel.setText(Messages.TraceControl_NewNodePortLabel);
+        fPortText = new Text(fTextGroup, SWT.NONE);
+        fPortText.setToolTipText(Messages.TraceControl_NewNodePortTooltip);
+        fPortText.setEnabled(fExistingHosts.length == 0);
+        fPortText.addVerifyListener(new VerifyListener() {
+            @Override
+            public void verifyText(VerifyEvent e) {
+                // only numbers are allowed.
+                e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$
+            }
+        });
+
         fButton.addSelectionListener(new SelectionListener() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -235,10 +268,12 @@ public class NewConnectionDialog extends Dialog implements INewConnectionDialog
                     fExistingHostsCombo.setEnabled(false);
                     fConnectionNameText.setEnabled(true);
                     fHostNameText.setEnabled(true);
+                    fPortText.setEnabled(true);
                 } else {
                     fExistingHostsCombo.setEnabled(true);
                     fConnectionNameText.setEnabled(false);
                     fHostNameText.setEnabled(false);
+                    fPortText.setEnabled(false);
                 }
             }
 
@@ -253,6 +288,7 @@ public class NewConnectionDialog extends Dialog implements INewConnectionDialog
                 int index = fExistingHostsCombo.getSelectionIndex();
                 fConnectionNameText.setText(fExistingHosts[index].getAliasName());
                 fHostNameText.setText(fExistingHosts[index].getHostName());
+                fPortText.setText(""); //$NON-NLS-1$
             }
 
             @Override
@@ -264,12 +300,21 @@ public class NewConnectionDialog extends Dialog implements INewConnectionDialog
         data = new GridData(GridData.FILL_HORIZONTAL);
         fHostNameText.setText("666.666.666.666"); //$NON-NLS-1$
         Point minSize = fHostNameText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
-        data.widthHint = minSize.x + 5;
+        int widthHint = minSize.x + 5;
+        data.widthHint = widthHint;
         data.horizontalSpan = 2;
-
         fConnectionNameText.setLayoutData(data);
+
+        data = new GridData(GridData.FILL_HORIZONTAL);
+        data.widthHint = widthHint;
+        data.horizontalSpan = 2;
         fHostNameText.setLayoutData(data);
 
+        data = new GridData(GridData.FILL_HORIZONTAL);
+        data.widthHint = widthHint;
+        data.horizontalSpan = 2;
+        fPortText.setLayoutData(data);
+
         fHostNameText.setText(""); //$NON-NLS-1$
 
         return fDialogComposite;
@@ -294,6 +339,7 @@ public class NewConnectionDialog extends Dialog implements INewConnectionDialog
         // Validate input data
         fConnectionName = fConnectionNameText.getText();
         fHostName = fHostNameText.getText();
+        fPort = (fPortText.getText().length() > 0) ? Integer.parseInt(fPortText.getText()) : IRemoteSystemProxy.INVALID_PORT_NUMBER;
 
         if (!"".equals(fHostName)) { //$NON-NLS-1$
             // If no node name is specified use the node address as name
This page took 0.025595 seconds and 5 git commands to generate.