lttng: Add snapshot support - LTTng Tools v2.3
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / CreateSessionDialog.java
index f021a63cf8b137808c185c8d3cf3999fdd101d38..c92a92da7d1f1236136a84bb1a3cd34a969a3c74 100644 (file)
@@ -26,8 +26,8 @@ import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSys
 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.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
+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.graphics.Point;
@@ -84,11 +84,11 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
     /**
      * Index of last supported streaming protocol for common URL configuration.
      */
-    private final static int COMMON_URL_LAST_INDEX = 1;
+    private static final int COMMON_URL_LAST_INDEX = 1;
     /**
      *  Index of default streaming protocol.
      */
-    private final static int DEFAULT_URL_INDEX = 0;
+    private static final int DEFAULT_URL_INDEX = 0;
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -103,10 +103,18 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
      * The text widget for the session name
      */
     private Text fSessionNameText = null;
+    /**
+     * The label widget for the session path.
+     */
+    private Label fSessionPathLabel = null;
     /**
      * The text widget for the session path.
      */
     private Text fSessionPathText = null;
+    /**
+     * The button widget to select a snapshot session
+     */
+    private Button fSnapshotButton = null;
     /**
      * The Group for stream configuration.
      */
@@ -119,6 +127,10 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
      * The composite with streaming configuration parameter.
      */
     private Composite fStreamingComposite = null;
+    /**
+     * The text widget for the trace path.
+     */
+    private Text fTracePathText = null;
     /**
      * The button to link data protocol/Address with control protocol.
      */
@@ -131,10 +143,14 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
      * A selection listener that copies the protocol from control to data when being linked.
      */
     private ControlProtocolSelectionListener fCopyProtocolSelectionListener;
-
+    /**
+     * A selection listener updates the control port text depending on the control protocol selected.
+     */
     private ProtocolComboSelectionListener fControlProtocolSelectionListener;
+    /**
+     * A selection listener updates the data port text depending on the data protocol selected.
+     */
     private ProtocolComboSelectionListener fDataProtocolSelectionListener;
-
     /**
      * The text box for the host/IP address of the control channel.
      */
@@ -142,7 +158,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
     /**
      * A key listener that copies the host address from control to data when being linked.
      */
-    private CopyKeyListener fControlUrlKeyListener;
+    private CopyModifyListener fControlUrlKeyListener;
     /**
      * The text box for the control port.
      */
@@ -159,14 +175,6 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
      * The text box for the data port.
      */
     private Text fDataPortText = null;
-    /**
-     * The button to not activate a consumer.
-     */
-    private Button fNoConsumerButton = null;
-    /**
-     * The button to disable the consumer.
-     */
-    private Button fDisableConsumerButton = null;
     /**
      * The parent where the new node should be added.
      */
@@ -179,6 +187,10 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
      * The  session path string.
      */
     private String fSessionPath = null;
+    /**
+     * The  session path string.
+     */
+    private boolean fIsSnapshot = false;
     /**
      * Flag whether default location (path) shall be used or not
      */
@@ -203,13 +215,9 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
      */
     private String fDataUrl = null;
     /**
-     * Flag for not activating a consumer for this session.
+     * The trace path string.
      */
-    private boolean fIsNoConsumer = false;
-    /**
-     * Flag for disabling a consumer for this session.
-     */
-    private boolean fIsDisableConsumer = false;
+    private String fTracePath = null;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -226,50 +234,34 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
     // ------------------------------------------------------------------------
     // Accessors
     // ------------------------------------------------------------------------
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionName()
-     */
+
     @Override
     public String getSessionName() {
         return fSessionName;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionPath()
-     */
     @Override
     public String getSessionPath() {
         return fSessionPath;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#isDefaultSessionPath()
-     */
     @Override
     public boolean isDefaultSessionPath() {
         return fIsDefaultPath;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#initialze(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup)
-     */
     @Override
     public void initialize(TraceSessionGroup group) {
        fParent = group;
        fStreamingComposite = null;
        fSessionName = null;
        fSessionPath = null;
+       fIsSnapshot = false;
        fIsDefaultPath = true;
        fIsStreamedTrace = false;
        fNetworkUrl = null;
        fControlUrl = null;
        fDataUrl = null;
-       fIsNoConsumer = false;
-       fIsDisableConsumer = false;
     }
 
     @Override
@@ -288,25 +280,14 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
     public String getDataUrl() {
         return fDataUrl;
     }
-
     @Override
-    public boolean isNoConsumer() {
-        return fIsNoConsumer;
+    public boolean isSnapshot() {
+        return fIsSnapshot;
     }
-
-    @Override
-    public boolean isDisableConsumer() {
-        return fIsDisableConsumer;
-    }
-
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
 
-
-    /* (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
-     */
     @Override
     protected Control createContents(Composite parent) {
         fControl = super.createContents(parent);
@@ -318,10 +299,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
 
         return fControl;
     }
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
-     */
+
     @Override
     protected void configureShell(Shell newShell) {
         super.configureShell(newShell);
@@ -329,10 +307,6 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
         newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE));
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
-     */
     @Override
     protected Control createDialogArea(Composite parent) {
 
@@ -351,11 +325,20 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
         fSessionNameText = new Text(sessionGroup, SWT.NONE);
         fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip);
 
-        Label sessionPath = new Label(sessionGroup, SWT.RIGHT);
-        sessionPath.setText(Messages.TraceControl_CreateSessionPathLabel);
+        fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT);
+        fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
         fSessionPathText = new Text(sessionGroup, SWT.NONE);
         fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip);
 
+        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);
+            data.horizontalSpan = 4;
+            fSnapshotButton.setData(data);
+        }
+
         // layout widgets
         GridData data = new GridData(GridData.FILL_HORIZONTAL);
         data.horizontalSpan = 3;
@@ -367,38 +350,6 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
         fSessionPathText.setLayoutData(data);
 
         if (fParent.isNetworkStreamingSupported()) {
-            fNoConsumerButton = new Button(sessionGroup, SWT.CHECK);
-            fNoConsumerButton.setText(Messages.TraceControl_CreateSessionNoConsumertText);
-            fNoConsumerButton.setToolTipText(Messages.TraceControl_CreateSessionNoConsumertTooltip);
-            data = new GridData(GridData.FILL_HORIZONTAL);
-            data.horizontalSpan = 2;
-            fNoConsumerButton.setLayoutData(data);
-
-            fDisableConsumerButton = new Button(sessionGroup, SWT.CHECK);
-            fDisableConsumerButton.setText(Messages.TraceControl_CreateSessionDisableConsumertText);
-            fDisableConsumerButton.setToolTipText(Messages.TraceControl_CreateSessionDisableConsumertTooltip);
-            data = new GridData(GridData.FILL_HORIZONTAL);
-            data.horizontalSpan = 2;
-            fDisableConsumerButton.setLayoutData(data);
-
-            fNoConsumerButton.addSelectionListener(new SelectionAdapter() {
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    if (fNoConsumerButton.getSelection()) {
-                        fDisableConsumerButton.setSelection(false);
-                    }
-                }
-            });
-
-            fDisableConsumerButton.addSelectionListener(new SelectionAdapter() {
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    if (fDisableConsumerButton.getSelection()) {
-                        fNoConsumerButton.setSelection(false);
-                    }
-                }
-            });
-
             createAdvancedOptionsComposite();
         }
 
@@ -412,7 +363,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
         fMainStreamingGroup.setLayout(new GridLayout(1, true));
 
         fConfigureStreamingButton = new Button(fMainStreamingGroup, SWT.PUSH);
-        fConfigureStreamingButton.setText(">>> " + Messages.TraceControl_CreateSessionConfigureStreamingButtonText); //$NON-NLS-1$
+        fConfigureStreamingButton.setText(Messages.TraceControl_CreateSessionConfigureStreamingButtonText + " >>>"); //$NON-NLS-1$
         fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
         fConfigureStreamingButton.addSelectionListener(new SelectionAdapter() {
             @Override
@@ -421,11 +372,16 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
                     fIsStreamedTrace = false;
                     fConfigureStreamingButton.setText(">>> " + Messages.TraceControl_CreateSessionConfigureStreamingButtonText); //$NON-NLS-1$
                     fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
+                    fSessionPathText.setEnabled(true);
+                    fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
                     disposeConfigureStreamingComposite();
                 } 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();
                 }
 
@@ -450,10 +406,20 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
             urlGroup.setLayout(layout);
             urlGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
 
+            Label tracePathLabel = new Label(urlGroup, SWT.RIGHT);
+            tracePathLabel.setText(Messages.TraceControl_CreateSessionTracePathText);
+            fTracePathText = new Text(urlGroup, SWT.NONE);
+            fTracePathText.setToolTipText(Messages.TraceControl_CreateSessionTracePathTooltip);
+
+            // layout widgets
+            GridData data = new GridData(GridData.FILL_HORIZONTAL);
+            data.horizontalSpan = 6;
+            fTracePathText.setLayoutData(data);
+
             fLinkDataWithControlButton = new Button(urlGroup, SWT.CHECK);
             fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText);
             fLinkDataWithControlButton.setToolTipText(Messages.TraceControl_CreateSessionLinkButtonTooltip);
-            GridData data = new GridData(GridData.FILL_HORIZONTAL);
+            data = new GridData(GridData.FILL_HORIZONTAL);
             data.horizontalSpan = 7;
             fLinkDataWithControlButton.setLayoutData(data);
             fLinkDataWithControlButton.setSelection(true);
@@ -545,19 +511,9 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
 
             fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
 
-            fControlUrlKeyListener = new CopyKeyListener(fControlHostAddressText, fDataHostAddressText);
-            fControlHostAddressText.addKeyListener(fControlUrlKeyListener);
-
-//            InetAddress inet = null;
-//            try {
-//                inet = InetAddress.getLocalHost();
-//                inet = InetAddress.getByName(inet.getHostName());
-//            } catch (UnknownHostException e1) {
-//            }
-//            if (inet != null) {
-//                fControlUrlAddressText.setText(inet.getHostAddress());
-//                fDataUrlAddressText.setText(inet.getHostAddress());
-//            }
+            fControlUrlKeyListener = new CopyModifyListener(fControlHostAddressText, fDataHostAddressText);
+            fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
+
             fControlProtocolCombo.select(DEFAULT_URL_INDEX);
             fDataProtocolCombo.select(DEFAULT_URL_INDEX);
 
@@ -575,7 +531,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
                         fControlProtocolCombo.removeSelectionListener(fControlProtocolSelectionListener);
                         fDataProtocolCombo.removeSelectionListener(fDataProtocolSelectionListener);
                         fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
-                        fControlHostAddressText.addKeyListener(fControlUrlKeyListener);
+                        fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
 
                         // Get previous selection and validate
                         int currentSelection = fControlProtocolCombo.getSelectionIndex() <= COMMON_URL_LAST_INDEX ?
@@ -606,7 +562,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
                         fControlProtocolCombo.removeSelectionListener(fCopyProtocolSelectionListener);
                         fControlProtocolCombo.addSelectionListener(fControlProtocolSelectionListener);
                         fDataProtocolCombo.addSelectionListener(fDataProtocolSelectionListener);
-                        fControlHostAddressText.removeKeyListener(fControlUrlKeyListener);
+                        fControlHostAddressText.removeModifyListener(fControlUrlKeyListener);
 
                         // Update combo box items
                         int currentSelection = fControlProtocolCombo.getSelectionIndex();
@@ -655,20 +611,12 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
         }
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
-     */
     @Override
     protected void createButtonsForButtonBar(Composite parent) {
         createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
         createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
-     */
     @Override
     protected void okPressed() {
         // Validate input data
@@ -684,6 +632,14 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
                 if (fsss != null) {
                     try {
                         IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSessionPath, new NullProgressMonitor());
+
+                        if (remoteFolder == null) {
+                            MessageDialog.openError(getShell(),
+                                    Messages.TraceControl_CreateSessionDialogTitle,
+                                    Messages.TraceControl_InvalidSessionPathError + " (" + fSessionPath + ") \n");  //$NON-NLS-1$ //$NON-NLS-2$
+                            return;
+                        }
+
                         if (remoteFolder.exists()) {
                             MessageDialog.openError(getShell(),
                                     Messages.TraceControl_CreateSessionDialogTitle,
@@ -701,11 +657,18 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
             fIsDefaultPath = false;
         }
 
+        if(fParent.isSnapshotSupported()) {
+            fIsSnapshot = fSnapshotButton.getSelection();
+        }
+
         fNetworkUrl = null;
         fControlUrl = null;
         fDataUrl = null;
 
         if (fIsStreamedTrace) {
+            // Validate input data
+            fTracePath = fTracePathText.getText();
+
             if (fControlProtocolCombo.getSelectionIndex() < 0) {
                 MessageDialog.openError(getShell(),
                         Messages.TraceControl_CreateSessionDialogTitle,
@@ -739,19 +702,19 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
                         fControlHostAddressText.getText(),
                         fControlPortText.getText(),
                         null,
-                        fSessionPath);
+                        fTracePath);
 
                 fDataUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()),
                         fDataHostAddressText.getText(),
                         null,
                         fDataPortText.getText(),
-                        fSessionPath);
+                        fTracePath);
             } else {
                 fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()),
                         fControlHostAddressText.getText(),
                         fControlPortText.getText(),
                         fDataPortText.getText(),
-                        fSessionPath);
+                        fTracePath);
             }
         }
 
@@ -771,11 +734,6 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
             return;
         }
 
-        if (fParent.isNetworkStreamingSupported()) {
-            fIsNoConsumer = fNoConsumerButton.getSelection();
-            fIsDisableConsumer = fDisableConsumerButton.getSelection();
-        }
-
         // validation successful -> call super.okPressed()
         super.okPressed();
     }
@@ -804,17 +762,17 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
         return stringBuilder.toString();
     }
 
-    private static class CopyKeyListener extends KeyAdapter {
+    private static class CopyModifyListener implements ModifyListener {
         private Text fSource;
         private Text fDestination;
 
-        public CopyKeyListener(Text source, Text destination) {
+        public CopyModifyListener(Text source, Text destination) {
             fSource = source;
             fDestination = destination;
         }
 
         @Override
-        public void keyReleased(KeyEvent e) {
+        public void modifyText(ModifyEvent e) {
             fDestination.setText(fSource.getText());
         }
     }
This page took 0.030192 seconds and 5 git commands to generate.