Fix for bug 382684 (connection re-use)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / AssignEventHandler.java
index 2c565bcdc6142e10692f09aede2e5582942a67da..eea654058a6f2d97be250463bb8322d9cb0facae 100644 (file)
@@ -1,12 +1,12 @@
 /**********************************************************************
  * Copyright (c) 2012 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
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
@@ -27,9 +27,9 @@ 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.IGetEventInfoDialog;
 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.ITraceControlComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.KernelProviderComponent;
@@ -40,11 +40,12 @@ import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstPro
 import org.eclipse.ui.IWorkbenchPage;
 
 /**
- * <b><u>AssignEventHandler</u></b>
  * <p>
  * Command handler implementation to assign events to a session and channel and enable/configure them.
  * This is done on the trace provider level.
  * </p>
+ *
+ * @author Bernd Hufmann
  */
 public class AssignEventHandler extends BaseControlViewHandler {
 
@@ -55,7 +56,7 @@ public class AssignEventHandler extends BaseControlViewHandler {
      * The command execution parameter.
      */
     private Parameter fParam;
-    
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -85,13 +86,14 @@ public class AssignEventHandler extends BaseControlViewHandler {
                 @Override
                 protected IStatus run(IProgressMonitor monitor) {
 
-                    StringBuffer errorString = new StringBuffer();
+                    Exception error = null;
+
                     try {
                         List<String> eventNames = new ArrayList<String>();
                         List<BaseEventComponent> events = param.getEvents();
                         // Create list of event names
                         for (Iterator<BaseEventComponent> iterator = events.iterator(); iterator.hasNext();) {
-                            BaseEventComponent event = (BaseEventComponent) iterator.next();
+                            BaseEventComponent event = iterator.next();
                             eventNames.add(event.getName());
                         }
 
@@ -104,21 +106,14 @@ public class AssignEventHandler extends BaseControlViewHandler {
                         }
 
                     } catch (ExecutionException e) {
-                        errorString.append(e.toString());
-                        errorString.append('\n');
+                        error = e;
                     }
 
-                    // get session configuration in all cases
-                    try {
-                        dialog.getSession().getConfigurationFromNode(monitor);
-                    } catch (ExecutionException e) {
-                        errorString.append(Messages.TraceControl_ListSessionFailure);
-                        errorString.append(": "); //$NON-NLS-1$
-                        errorString.append(e.toString());
-                    } 
+                    // refresh in all cases
+                    refresh(new CommandParameter(dialog.getSession()));
 
-                    if (errorString.length() > 0) {
-                        return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString.toString());
+                    if (error != null) {
+                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_EnableEventsFailure, error);
                     }
                     return Status.OK_STATUS;
                 }
@@ -151,14 +146,14 @@ public class AssignEventHandler extends BaseControlViewHandler {
         // Check if one or more session are selected
         ISelection selection = page.getSelection(ControlView.ID);
         if (selection instanceof StructuredSelection) {
-            
+
             StructuredSelection structered = ((StructuredSelection) selection);
             for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
-                Object element = (Object) iterator.next();
+                Object element = iterator.next();
                 if (element instanceof BaseEventComponent) {
                     BaseEventComponent event = (BaseEventComponent) element;
                     ITraceControlComponent provider = event.getParent();
-                    
+
                     // check for kernel or UST provider
                     boolean temp = false;
                     if (provider instanceof KernelProviderComponent) {
@@ -179,7 +174,7 @@ public class AssignEventHandler extends BaseControlViewHandler {
 
                     // Add BaseEventComponents
                     events.add(event);
-                    
+
                     if (sessions == null) {
                         TargetNodeComponent  root = (TargetNodeComponent)event.getParent().getParent().getParent();
                         sessions = root.getSessions();
@@ -202,28 +197,28 @@ public class AssignEventHandler extends BaseControlViewHandler {
     }
 
     /**
-     *  Class containing parameter for the command execution. 
+     *  Class containing parameter for the command execution.
      */
     final static private class Parameter {
 
         /**
-         * The list of event components the command is to be executed on. 
+         * The list of event components the command is to be executed on.
          */
-        private List<BaseEventComponent> fEvents;
-        
+        private final List<BaseEventComponent> fEvents;
+
         /**
          * The list of available sessions.
          */
         final private TraceSessionComponent[] fSessions;
-        
+
         /**
          * Flag for indicating Kernel or UST.
          */
         final private boolean fIsKernel;
-        
+
         /**
          * Constructor
-         * 
+         *
          * @param sessions - a array of trace sessions
          * @param events - a lists of events to enable
          * @param isKernel - domain (true for kernel or UST)
@@ -234,7 +229,7 @@ public class AssignEventHandler extends BaseControlViewHandler {
             fEvents.addAll(events);
             fIsKernel = isKernel;
         }
-        
+
         /**
          * Copy constructor
          * @param other - a parameter to copy
@@ -242,15 +237,15 @@ public class AssignEventHandler extends BaseControlViewHandler {
         public Parameter(Parameter other) {
             this(other.fSessions, other.fEvents, other.fIsKernel);
         }
-        
+
         public TraceSessionComponent[] getSessions() {
             return fSessions;
         }
-        
+
         public List<BaseEventComponent> getEvents() {
             return fEvents;
         }
-        
+
         public boolean isKernel() {
             return fIsKernel;
         }
This page took 0.0264 seconds and 5 git commands to generate.