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 / ChangeChannelStateHandler.java
index 9a8545be42f8b8029c81ffbc9d1ffef3bd9d5eeb..90dc7a3e0baab1f994e6095aa6e6c7305a1fda47 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;
@@ -23,10 +23,10 @@ import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
 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.model.TraceEnablement;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
@@ -35,10 +35,11 @@ import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
 
 /**
- * <b><u>ChangeChannelStateHandler</u></b>
  * <p>
  * Abstract command handler implementation to enable or disabling a trace channel.
  * </p>
+ *
+ * @author Bernd Hufmann
  */
 abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
 
@@ -56,7 +57,7 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
     /**
      * @return the new state to set
      */
-    abstract protected TraceEnablement getNewState(); 
+    abstract protected TraceEnablement getNewState();
 
     // ------------------------------------------------------------------------
     // Operations
@@ -64,11 +65,11 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
     /**
      * Changes the state of the given channels.
      * @param domain - the domain of the channels.
-     * @param channelNames - a list of channel names 
+     * @param channelNames - a list of channel names
      * @param monitor - a progress monitor
      * @throws ExecutionException
      */
-    abstract protected void changeState(TraceDomainComponent domain, List<String> channelNames, IProgressMonitor monitor) throws ExecutionException; 
+    abstract protected void changeState(TraceDomainComponent domain, List<String> channelNames, IProgressMonitor monitor) throws ExecutionException;
 
     /*
      * (non-Javadoc)
@@ -90,7 +91,7 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
             Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
                 @Override
                 protected IStatus run(IProgressMonitor monitor) {
-                    String errorString = null;
+                    Exception error = null;
 
                     TraceSessionComponent session = null;
 
@@ -103,7 +104,7 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
                             List<String> channelNames = new ArrayList<String>();
                             for (Iterator<TraceChannelComponent> iterator = kernelChannels.iterator(); iterator.hasNext();) {
                                 // Enable all selected channels which are disabled
-                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
+                                TraceChannelComponent channel = iterator.next();
                                 channelNames.add(channel.getName());
                             }
 
@@ -111,7 +112,7 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
 
                             for (Iterator<TraceChannelComponent> iterator = kernelChannels.iterator(); iterator.hasNext();) {
                                 // Enable all selected channels which are disabled
-                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
+                                TraceChannelComponent channel = iterator.next();
                                 channel.setState(getNewState());
                             }
                         }
@@ -126,7 +127,7 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
                             List<String> channelNames = new ArrayList<String>();
                             for (Iterator<TraceChannelComponent> iterator = ustChannels.iterator(); iterator.hasNext();) {
                                 // Enable all selected channels which are disabled
-                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
+                                TraceChannelComponent channel = iterator.next();
                                 channelNames.add(channel.getName());
                             }
 
@@ -134,19 +135,19 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
 
                             for (Iterator<TraceChannelComponent> iterator = ustChannels.iterator(); iterator.hasNext();) {
                                 // Enable all selected channels which are disabled
-                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
+                                TraceChannelComponent channel = iterator.next();
                                 channel.setState(getNewState());
                             }
                         }
                     } catch (ExecutionException e) {
-                        errorString = e.toString() + "\n"; //$NON-NLS-1$
+                        error = e;
                     }
 
-                    // In all cases notify listeners  
+                    // In all cases notify listeners
                     session.fireComponentChanged(session);
 
-                    if (errorString != null) {
-                        return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString);
+                    if (error != null) {
+                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeChannelStateFailure, error);
                     }
 
                     return Status.OK_STATUS;
@@ -178,17 +179,17 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
         TraceDomainComponent ustDomain = null;
         List<TraceChannelComponent> kernelChannels = new ArrayList<TraceChannelComponent>();
         List<TraceChannelComponent> ustChannels = new ArrayList<TraceChannelComponent>();
-        
+
         // Check if one or more session are selected
         ISelection selection = page.getSelection(ControlView.ID);
         if (selection instanceof StructuredSelection) {
             StructuredSelection structered = ((StructuredSelection) selection);
             String sessionName = null;
             for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
-                Object element = (Object) iterator.next();
-                 
+                Object element = iterator.next();
+
                 if (element instanceof TraceChannelComponent) {
-                    
+
                     // Add only TraceChannelComponents that are disabled
                     TraceChannelComponent channel = (TraceChannelComponent) element;
                     if (sessionName == null) {
@@ -218,7 +219,7 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
                 }
             }
         }
-        
+
         boolean isEnabled = (!kernelChannels.isEmpty() || !ustChannels.isEmpty());
         fLock.lock();
         try {
@@ -228,12 +229,12 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
         } finally {
             fLock.unlock();
         }
-        
+
         return isEnabled;
     }
-    
+
     /**
-     *  Class containing parameter for the command execution. 
+     *  Class containing parameter for the command execution.
      */
     static protected class Parameter {
         /**
@@ -245,14 +246,14 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
          */
         final protected TraceDomainComponent fUstDomain;
         /**
-         * The list of kernel channel components the command is to be executed on. 
+         * The list of kernel channel components the command is to be executed on.
          */
         final protected List<TraceChannelComponent> fKernelChannels;
         /**
-         * The list of UST channel components the command is to be executed on. 
+         * The list of UST channel components the command is to be executed on.
          */
         final protected List<TraceChannelComponent> fUstChannels;
-        
+
         /**
          * Constructor
          * @param kernelDomain - a kernel domain component
@@ -268,7 +269,7 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
             fUstChannels = new ArrayList<TraceChannelComponent>();
             fUstChannels.addAll(ustChannels);
         }
-        
+
         /**
          * Copy constructor
          * @param other a parameter to copy
@@ -276,28 +277,28 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
         public Parameter(Parameter other) {
             this(other.fKernelDomain, other.fUstDomain, other.fKernelChannels, other.fUstChannels);
         }
-        
+
         /**
          * @return the kernel domain component.
          */
         public TraceDomainComponent getKernelDomain() {
             return fKernelDomain;
         }
-        
+
         /**
          * @return the UST domain component.
          */
         public TraceDomainComponent getUstDomain() {
             return fUstDomain;
-        }   
-        
+        }
+
         /**
          * @return the list of kernel channel components.
          */
         public List<TraceChannelComponent> getKernelChannels() {
             return fKernelChannels;
         }
-        
+
         /**
          * @return the list of UST channel components.
          */
This page took 0.027095 seconds and 5 git commands to generate.