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 / handlers / CreateSessionHandler.java
index f7756f11d72473dabeaef13501642b6c699363b2..327f901c57d317e887636b7c1970332cacbdfec4 100644 (file)
@@ -1,13 +1,14 @@
 /**********************************************************************
- * 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
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors: 
+ *
+ * Contributors:
  *   Bernd Hufmann - Initial API and implementation
+ *   Bernd Hufmann - Updated for support of LTTng Tools 2.1
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
 
@@ -22,87 +23,102 @@ import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.window.Window;
 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup;
 import org.eclipse.ui.IWorkbenchPage;
 
 /**
- * <b><u>CreateSessionHandler</u></b>
  * <p>
  * Command handler implementation to create a trace session.
  * </p>
+ *
+ * @author Bernd Hufmann
  */
 public class CreateSessionHandler extends BaseControlViewHandler {
 
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
+
     /**
-     * The trace session group the command is to be executed on. 
+     * The trace session group the command is to be executed on.
      */
     private TraceSessionGroup fSessionGroup = null;
-    
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-     */
+
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
 
-        // Open dialog box for the node name and address
-        ICreateSessionDialog dialog = TraceControlDialogFactory.getInstance().getCreateSessionDialog();
-        dialog.setTraceSessionGroup(fSessionGroup);
+        fLock.lock();
+        try {
+            final TraceSessionGroup sessionGroup = fSessionGroup;
 
-        if (dialog.open() != Window.OK) {
-            return null;
-        }
-
-        final String sessionName = dialog.getSessionName();
-        final String sessionPath = dialog.isDefaultSessionPath() ? null : dialog.getSessionPath();
+            // Open dialog box for the node name and address
+            final ICreateSessionDialog dialog = TraceControlDialogFactory.getInstance().getCreateSessionDialog();
+            dialog.initialize(sessionGroup);
 
-        Job job = new Job(Messages.TraceControl_CreateSessionJob) {
-            @Override
-            protected IStatus run(IProgressMonitor monitor) {
-                try {
-                    fSessionGroup.createSession(sessionName, sessionPath, monitor);
-                } catch (ExecutionException e) {
-                    return new Status(Status.ERROR, Activator.PLUGIN_ID, e.toString());
-                } 
-                return Status.OK_STATUS;
+            if (dialog.open() != Window.OK) {
+                return null;
             }
-        };
-        job.setUser(true);
-        job.schedule();
-        
+
+            Job job = new Job(Messages.TraceControl_CreateSessionJob) {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    try {
+                        if (dialog.isStreamedTrace()) {
+                            sessionGroup.createSession(dialog.getSessionName(), dialog.getNetworkUrl(), dialog.getControlUrl(),
+                                    dialog.getDataUrl(), dialog.isSnapshot(), monitor);
+                        } else {
+                            String sessionPath = dialog.isDefaultSessionPath() ? null : dialog.getSessionPath();
+                            sessionGroup.createSession(dialog.getSessionName(), sessionPath, dialog.isSnapshot(), monitor);
+                        }
+                    } catch (ExecutionException e) {
+                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateSessionFailure, e);
+                    }
+                    return Status.OK_STATUS;
+                }
+            };
+            job.setUser(true);
+            job.schedule();
+        } finally {
+            fLock.unlock();
+        }
         return null;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
-     */
     @Override
     public boolean isEnabled() {
-        
+
         // Get workbench page for the Control View
         IWorkbenchPage page = getWorkbenchPage();
         if (page == null) {
             return false;
         }
 
-        fSessionGroup = null;
+        TraceSessionGroup sessionGroup = null;
 
         // Check if the session group project is selected
         ISelection selection = page.getSelection(ControlView.ID);
         if (selection instanceof StructuredSelection) {
             Object element = ((StructuredSelection) selection).getFirstElement();
-            fSessionGroup = (element instanceof TraceSessionGroup) ? (TraceSessionGroup) element : null;
+            sessionGroup = (element instanceof TraceSessionGroup) ? (TraceSessionGroup) element : null;
+        }
+
+        boolean isEnabled = sessionGroup != null;
+        fLock.lock();
+        try {
+            fSessionGroup = null;
+            if(isEnabled) {
+                fSessionGroup = sessionGroup;
+            }
+        } finally {
+            fLock.unlock();
         }
-        return fSessionGroup != null;
+        return isEnabled;
     }
 }
This page took 0.025758 seconds and 5 git commands to generate.