Update internal packages export in LTTng 2.0 control + update java doc
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / ChangeChannelStateHandler.java
index d18afee82254b2af369bba4c5d1ad3f9756825c8..9ea06971e741ae958fd878e76cb1f93f6b383386 100644 (file)
@@ -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 {
 
@@ -46,21 +47,9 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
     // Attributes
     // ------------------------------------------------------------------------
     /**
-     * Kernel domain component reference.
-     */
-    protected TraceDomainComponent fKernelDomain = null;
-    /**
-     * UST domain component reference.
-     */
-    protected TraceDomainComponent fUstDomain = null;
-    /**
-     * The list of kernel channel components the command is to be executed on. 
-     */
-    protected List<TraceChannelComponent> fKernelChannels = new ArrayList<TraceChannelComponent>();
-    /**
-     * The list of UST channel components the command is to be executed on. 
+     * The command execution parameter.
      */
-    protected List<TraceChannelComponent> fUstChannels = new ArrayList<TraceChannelComponent>();
+    protected Parameter fParam;
 
     // ------------------------------------------------------------------------
     // Accessors
@@ -89,74 +78,86 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
 
-        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        fLock.lock();
+        try {
+            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
 
-        if (window == null) {
-            return false;
-        }
+            if (window == null) {
+                return false;
+            }
 
-        Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
-            @Override
-            protected IStatus run(IProgressMonitor monitor) {
-                String errorString = null;
-
-                TraceSessionComponent session = null;
-
-                try {
-                    if (fKernelDomain != null) {
-                        session = (TraceSessionComponent)fKernelDomain.getParent();
-                        List<String> channelNames = new ArrayList<String>();
-                        for (Iterator<TraceChannelComponent> iterator = fKernelChannels.iterator(); iterator.hasNext();) {
-                            // Enable all selected channels which are disabled
-                            TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
-                            channelNames.add(channel.getName());
-                        }
-                        
-                        changeState(fKernelDomain, channelNames, monitor);
+            final Parameter param = new Parameter(fParam);
 
-                        for (Iterator<TraceChannelComponent> iterator = fKernelChannels.iterator(); iterator.hasNext();) {
-                            // Enable all selected channels which are disabled
-                            TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
-                            channel.setState(getNewState());
-                        }
-                    }
+            Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    Exception error = null;
 
-                    if (fUstDomain != null) {
-                        if (session == null) {
-                            session = (TraceSessionComponent)fUstDomain.getParent();
-                        }
+                    TraceSessionComponent session = null;
+
+                    try {
+                        TraceDomainComponent kernelDomain = param.getKernelDomain();
+                        List<TraceChannelComponent> kernelChannels = param.getKernelChannels();
+
+                        if (kernelDomain != null) {
+                            session = (TraceSessionComponent)kernelDomain.getParent();
+                            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();
+                                channelNames.add(channel.getName());
+                            }
+
+                            changeState(kernelDomain, channelNames, monitor);
 
-                        List<String> channelNames = new ArrayList<String>();
-                        for (Iterator<TraceChannelComponent> iterator = fUstChannels.iterator(); iterator.hasNext();) {
-                            // Enable all selected channels which are disabled
-                            TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
-                            channelNames.add(channel.getName());
+                            for (Iterator<TraceChannelComponent> iterator = kernelChannels.iterator(); iterator.hasNext();) {
+                                // Enable all selected channels which are disabled
+                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
+                                channel.setState(getNewState());
+                            }
                         }
 
-                        changeState(fUstDomain, channelNames, monitor);
-                        
-                        for (Iterator<TraceChannelComponent> iterator = fUstChannels.iterator(); iterator.hasNext();) {
-                            // Enable all selected channels which are disabled
-                            TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
-                            channel.setState(getNewState());
+                        TraceDomainComponent ustDomain = param.getUstDomain();
+                        List<TraceChannelComponent> ustChannels = param.getUstChannels();
+                        if (ustDomain != null) {
+                            if (session == null) {
+                                session = (TraceSessionComponent)ustDomain.getParent();
+                            }
+
+                            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();
+                                channelNames.add(channel.getName());
+                            }
+
+                            changeState(ustDomain, channelNames, monitor);
+
+                            for (Iterator<TraceChannelComponent> iterator = ustChannels.iterator(); iterator.hasNext();) {
+                                // Enable all selected channels which are disabled
+                                TraceChannelComponent channel = (TraceChannelComponent) iterator.next();
+                                channel.setState(getNewState());
+                            }
                         }
+                    } catch (ExecutionException e) {
+                        error = e;
                     }
-                } catch (ExecutionException e) {
-                    errorString = e.toString() + "\n"; //$NON-NLS-1$
-                }
 
-                // In all cases notify listeners  
-                session.fireComponentChanged(session);
+                    // 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(Status.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeChannelStateFailure, error);
+                    }
 
-                return Status.OK_STATUS;
-            }
-        };
-        job.setUser(true);
-        job.schedule();
+                    return Status.OK_STATUS;
+                }
+            };
+            job.setUser(true);
+            job.schedule();
+        } finally {
+            fLock.unlock();
+        }
 
         return null;
     }
@@ -167,13 +168,17 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
      */
     @Override
     public boolean isEnabled() {
-        reset();
 
         // Get workbench page for the Control View
         IWorkbenchPage page = getWorkbenchPage();
         if (page == null) {
             return false;
         }
+
+        TraceDomainComponent kernelDomain = null;
+        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);
@@ -193,36 +198,112 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
 
                     // Enable command only for channels of same session
                     if (!sessionName.equals(channel.getSessionName())) {
-                        reset();
+                        kernelChannels.clear();
+                        ustChannels.clear();
                         break;
                     }
 
                     if ((channel.getState() != getNewState())) {
                         if (channel.isKernel()) {
-                            fKernelChannels.add(channel);
-                            if (fKernelDomain == null) {
-                                fKernelDomain = (TraceDomainComponent) channel.getParent();
+                            kernelChannels.add(channel);
+                            if (kernelDomain == null) {
+                                kernelDomain = (TraceDomainComponent) channel.getParent();
                             }
                         } else {
-                            fUstChannels.add(channel);
-                            if (fUstDomain == null) {
-                                fUstDomain = (TraceDomainComponent) channel.getParent();
+                            ustChannels.add(channel);
+                            if (ustDomain == null) {
+                                ustDomain = (TraceDomainComponent) channel.getParent();
                             }
                         }
                     }
                 }
             }
         }
-        return fKernelChannels.size() + fUstChannels.size() > 0;
+        
+        boolean isEnabled = (!kernelChannels.isEmpty() || !ustChannels.isEmpty());
+        fLock.lock();
+        try {
+            if (isEnabled) {
+                fParam = new Parameter(kernelDomain, ustDomain, kernelChannels, ustChannels);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        
+        return isEnabled;
     }
-
+    
     /**
-     * Reset members
+     *  Class containing parameter for the command execution. 
      */
-    private void reset() {
-        fKernelDomain = null;
-        fUstDomain = null;
-        fKernelChannels.clear();
-        fUstChannels.clear();
+    static protected class Parameter {
+        /**
+         * Kernel domain component reference.
+         */
+        final protected TraceDomainComponent fKernelDomain;
+        /**
+         * UST domain component reference.
+         */
+        final protected TraceDomainComponent fUstDomain;
+        /**
+         * 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. 
+         */
+        final protected List<TraceChannelComponent> fUstChannels;
+        
+        /**
+         * Constructor
+         * @param kernelDomain - a kernel domain component
+         * @param ustDomain - a UST domain component
+         * @param kernelChannels - list of available kernel channels
+         * @param ustChannels - list of available UST channels
+         */
+        public Parameter(TraceDomainComponent kernelDomain, TraceDomainComponent ustDomain, List<TraceChannelComponent> kernelChannels, List<TraceChannelComponent> ustChannels) {
+            fKernelDomain = kernelDomain;
+            fUstDomain = ustDomain;
+            fKernelChannels = new ArrayList<TraceChannelComponent>();
+            fKernelChannels.addAll(kernelChannels);
+            fUstChannels = new ArrayList<TraceChannelComponent>();
+            fUstChannels.addAll(ustChannels);
+        }
+        
+        /**
+         * Copy constructor
+         * @param other a parameter to copy
+         */
+        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.
+         */
+        public List<TraceChannelComponent> getUstChannels() {
+            return fUstChannels;
+        }
     }
 }
This page took 0.028644 seconds and 5 git commands to generate.