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 / RefreshHandler.java
index 2a477972ba9ffc8d06d7ff5cefc9bef99fea345b..43eb113170927f7127cc8a3990074ee46d45432a 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;
@@ -17,17 +17,18 @@ import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TargetNodeState;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent;
 import org.eclipse.ui.IWorkbenchPage;
 
 /**
- * <b><u>RefreshHandler</u></b>
  * <p>
  * Command handler implementation to refresh node configuration.
  * </p>
+ *
+ * @author Bernd Hufmann
  */
 public class RefreshHandler extends BaseControlViewHandler {
 
@@ -38,7 +39,7 @@ public class RefreshHandler extends BaseControlViewHandler {
      * The node component reference.
      */
     private TargetNodeComponent fNode;
-    
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -49,7 +50,12 @@ public class RefreshHandler extends BaseControlViewHandler {
      */
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        fNode.refresh();
+        fLock.lock();
+        try {
+            fNode.refresh();
+        } finally {
+            fLock.unlock();
+        }
         return null;
     }
 
@@ -59,7 +65,6 @@ public class RefreshHandler extends BaseControlViewHandler {
      */
     @Override
     public boolean isEnabled() {
-        fNode = null;
 
         // Get workbench page for the Control View
         IWorkbenchPage page = getWorkbenchPage();
@@ -67,13 +72,14 @@ public class RefreshHandler extends BaseControlViewHandler {
             return false;
         }
 
+        TargetNodeComponent node = null;
         // 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 TraceControlComponent) {
                     TraceControlComponent component = (TraceControlComponent) element;
                     boolean isConnected = component.getTargetNodeState() == TargetNodeState.CONNECTED;
@@ -82,12 +88,25 @@ public class RefreshHandler extends BaseControlViewHandler {
                             component = (TraceControlComponent) component.getParent();
                         }
                         if (component != null) {
-                            fNode = (TargetNodeComponent) component;
+                            node = (TargetNodeComponent) component;
                         }
                     }
                 }
             }
         }
-        return fNode != null;
+
+        boolean isEnabled = node != null;
+
+        fLock.lock();
+        try {
+            fNode = null;
+            if (isEnabled) {
+                fNode = node;
+            }
+        } finally {
+            fLock.unlock();
+        }
+
+        return isEnabled;
     }
 }
This page took 0.025109 seconds and 5 git commands to generate.