Fix findbugs warnings + address concurrency issues in handlers
authorBernd Hufmann <bhufmann@gmail.com>
Fri, 16 Mar 2012 19:09:37 +0000 (15:09 -0400)
committerBernd Hufmann <bhufmann@gmail.com>
Fri, 16 Mar 2012 19:09:37 +0000 (15:09 -0400)
44 files changed:
org.eclipse.linuxtools.lttng2.ui.tests/src/org/eclipse/linuxtools/lttng2/ui/tests/control/model/component/TraceControlProviderTests.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/Messages.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/CreateChannelDialog.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/CreateSessionDialog.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableEventsDialog.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableKernelEventComposite.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableUstEventsComposite.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/GetEventInfoDialog.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/ICreateChannelDialog.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/ICreateChannelOnSessionDialog.java [deleted file]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/TraceControlDialogFactory.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AssignEventHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseControlViewHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseCreateChannelHandler.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseEnableEventHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseNodeHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChangeChannelStateHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChangeEventStateHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChangeSessionStateHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChannelCommandParameter.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/CommandParameter.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ConnectHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/CreateChannelOnDomainHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/CreateChannelOnSessionHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/CreateSessionHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/DeleteHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/DestroySessionHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/DisconnectHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/DomainCommandParameter.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EnableEventOnChannelHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EnableEventOnDomainHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EnableEventOnSessionHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/NewConnectionHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/RefreshHandler.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/BaseEventInfo.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/ChannelInfo.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/DomainInfo.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/EventInfo.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/ProbeEventInfo.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/SessionInfo.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceSessionComponent.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/property/TraceProbeEventPropertySource.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java

index 706ffc69cae69313f9cfc6ed3196106285eafcc5..d9f50123d00c479e77d3bee80fdf047076b36b9a 100644 (file)
@@ -26,7 +26,7 @@ import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IConfirmDialog;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelOnSessionDialog;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
@@ -286,7 +286,7 @@ public class TraceControlProviderTests extends TestCase {
         // ------------------------------------------------------------------------
         // Create Channel on UST global domain
         // ------------------------------------------------------------------------
-        TraceControlDialogFactory.getInstance().setCreateChannelOnSessionDialog(new CreateChannelOnSessionDialogStub());
+        TraceControlDialogFactory.getInstance().setCreateChannelDialog(new CreateChannelDialogStub());
 
         fFacility.getControlView().setSelection(session);
         // Give GUI time to actually execute refresh
@@ -917,7 +917,7 @@ public class TraceControlProviderTests extends TestCase {
         }
     }
     
-    public class CreateChannelOnSessionDialogStub implements ICreateChannelOnSessionDialog {
+    public class CreateChannelDialogStub implements ICreateChannelDialog {
 
         @Override
         public IChannelInfo getChannelInfo() {
index 05548466f137b91f6ccb5c133ccd3c7fc6f5f17b..6c9981a95d5b09f3402b2287815e213370bd3d07 100644 (file)
@@ -130,6 +130,7 @@ final public class Messages extends NLS {
     public static String TraceControl_InvalidProbeNameError;
     public static String TraceControl_InvalidWildcardError;
     public static String TraceControl_InvalidLogLevelEventNameError;
+    public static String TraceControl_InvalidLogLevel;
     
 
     // Tree structure strings
index 10e9c2d126e2bddcb1974828f23df6dc04124e14..dde5aaef5488611790ac23bf6ec0939d24122362 100644 (file)
@@ -39,7 +39,7 @@ import org.eclipse.swt.widgets.Text;
  * Dialog box for collecting channel creation information.
  * </p>
  */
-public class CreateChannelDialog extends Dialog implements ICreateChannelOnSessionDialog {
+public class CreateChannelDialog extends Dialog implements ICreateChannelDialog {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -63,23 +63,23 @@ public class CreateChannelDialog extends Dialog implements ICreateChannelOnSessi
     /**
      * The overwrite mode of the channel.
      */
-    private Button fOverwriteModeButton;
+    private Button fOverwriteModeButton = null;
     /**
      * The sub-buffer size of the channel.
      */
-    private Text fSubBufferSizeText;
+    private Text fSubBufferSizeText = null;
     /**
      * The number of sub-buffers of the channel.
      */
-    private Text fNumberOfSubBuffersText;
+    private Text fNumberOfSubBuffersText = null;
     /**
      * The switch timer interval of the channel.
      */
-    private Text fSwitchTimerText;
+    private Text fSwitchTimerText = null;
     /**
      * The read timer interval of the channel.
      */
-    private Text fReadTimerText;
+    private Text fReadTimerText = null;
     /**
      * Group composite for domain selection.
      */
@@ -87,24 +87,24 @@ public class CreateChannelDialog extends Dialog implements ICreateChannelOnSessi
     /**
      * Radio button for selecting kernel domain.
      */
-    private Button fKernelButton;
+    private Button fKernelButton = null;
     /**
      * Radio button for selecting UST domain.
      */
-    private Button fUstButton;
+    private Button fUstButton = null;
     /**
      * The parent domain component where the channel node should be added. 
      * Null in case of creation on session level.
      */
-    private TraceDomainComponent fDomain;
+    private TraceDomainComponent fDomain = null;
     /**
      * Common verify listener for numeric text input.  
      */
-    private VerifyListener fVerifyListener;
+    private VerifyListener fVerifyListener = null;
     /**
      * Output channel information.
      */
-    private IChannelInfo fChannelInfo;
+    private IChannelInfo fChannelInfo = null;
     /**
      * Output domain information. True in case of Kernel domain. False for UST.     
      */
@@ -160,7 +160,7 @@ public class CreateChannelDialog extends Dialog implements ICreateChannelOnSessi
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelOnSessionDialog#isKernel()
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#isKernel()
      */
     @Override
     public boolean isKernel() {
@@ -295,11 +295,7 @@ public class CreateChannelDialog extends Dialog implements ICreateChannelOnSessi
         fChannelInfo.setReadTimer(Long.parseLong(fReadTimerText.getText()));
         fChannelInfo.setOverwriteMode(fOverwriteModeButton.getSelection());
 
-        if (fKernelButton.getSelection() == true) {
-            fIsKernel = true;
-        } else {
-            fIsKernel = false;
-        }
+        fIsKernel = fKernelButton.getSelection();
 
         // Check for invalid names
         if (!fChannelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
index f4ce9c440e5d4d42aa73f414ad36e5442c26bf85..c975e0518da52276da775afdf0cadccafed9ca41 100644 (file)
@@ -67,7 +67,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog
     /**
      * The parent where the new node should be added.
      */
-    private TraceSessionGroup fParent;
+    private TraceSessionGroup fParent = null;
     /**
      * The session name string.
      */
index 28e961f376fe60cab348a847837e36fdd9563416..3bdef6602370ca402771501edae01a34c5169e43 100644 (file)
@@ -451,11 +451,7 @@ public class EnableEventsDialog extends Dialog implements IEnableEventsDialog  {
      */
     @Override
     protected void okPressed() {
-        if (fKernelButton.getSelection() == true) {
-            fIsKernel = true;
-        } else {
-            fIsKernel = false;
-        }
+        fIsKernel = fKernelButton.getSelection();
 
         // Validate kernel composite in case of kernel domain
         if (fKernelComposite != null && !fKernelComposite.isValid()) {
index cb1a0b5b692fb634d9759bee8742651149c94e68..b448ab6a861ab39fcfa921d0e141a9c027719b95 100644 (file)
@@ -555,7 +555,7 @@ public class EnableKernelEventComposite extends Composite implements IEnableKern
     /**
      * Content provider for the tracepoints tree. 
      */
-    final public class KernelContentProvider extends TraceControlContentProvider {
+    final static public class KernelContentProvider extends TraceControlContentProvider {
         @Override
         public Object[] getChildren(Object parentElement) {
             if (parentElement instanceof TraceProviderGroup) {
@@ -572,7 +572,7 @@ public class EnableKernelEventComposite extends Composite implements IEnableKern
     /**
      * Content label for the tracepoints tree. 
      */
-    final public class KernelLabelProvider extends TraceControlLabelProvider {
+    final static public class KernelLabelProvider extends TraceControlLabelProvider {
         @Override
         public Image getImage(Object element) {
             return null;
index b76856868ec745a8eaaef0b45daca60d549d95fc..34571df59f6e95232fc865ce1f5aad017ac8c3b0 100644 (file)
@@ -258,7 +258,7 @@ public class EnableUstEventsComposite extends Composite implements IEnableUstEve
     }
 
     /**
-    * Validates the kernel composite input data.
+    * Validates the UST composite input data.
     * @return true if configured data is valid and can be retrieved.
     */
     public boolean isValid() {
@@ -303,6 +303,18 @@ public class EnableUstEventsComposite extends Composite implements IEnableUstEve
           fLogLevelEventName = temp;
         }
 
+        TraceLogLevel[] levels = TraceLogLevel.values();
+        int id = fLogLevelCombo.getSelectionIndex();
+        if ((id < 0) && fIsLogLevel) {
+            MessageDialog.openError(getShell(),
+                    Messages.TraceControl_EnableEventsDialogTitle,
+                    Messages.TraceControl_InvalidLogLevel + " (" + temp + ") \n");  //$NON-NLS-1$ //$NON-NLS-2$
+
+            return false;
+        } else {
+            fLogLevel = levels[id];
+        }
+
         // initialize log level event name string
         fWildcard = null;
         temp = fWildcardText.getText();
@@ -524,7 +536,7 @@ public class EnableUstEventsComposite extends Composite implements IEnableUstEve
     /**
      * Content provider for the tracepoints tree. 
      */
-    final public class UstContentProvider extends TraceControlContentProvider {
+    final static public class UstContentProvider extends TraceControlContentProvider {
         @Override
         public Object[] getChildren(Object parentElement) {
             if (parentElement instanceof TargetNodeComponent) {
@@ -545,7 +557,7 @@ public class EnableUstEventsComposite extends Composite implements IEnableUstEve
     /**
      * Content label for the tracepoints tree. 
      */
-     final public class UstLabelProvider extends TraceControlLabelProvider {
+     final static public class UstLabelProvider extends TraceControlLabelProvider {
         @Override
         public Image getImage(Object element) {
             return null;
index 2392d3604abef3492834744ba58db4f4134920f7..ebf0e27d388d13b20526a551ebc47223c99fd04f 100644 (file)
@@ -25,6 +25,7 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
@@ -238,6 +239,9 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
             public void widgetDefaultSelected(SelectionEvent e) {
             }
         });
+        
+        getShell().setMinimumSize(new Point(300, 200));
+        
         return fDialogComposite;
     }
 
index 94910801ff5b1109095e6062cc52e9bfc12dd5f1..49679e89d453a4dc144a3b7b866a2058196f1a9c 100644 (file)
@@ -36,6 +36,12 @@ public interface ICreateChannelDialog {
      */
     public void setDomainComponent(TraceDomainComponent domain);
     
+    /**
+     * @return true for Kernel domain. False for UST.
+     */
+    public boolean isKernel();
+
+    
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/ICreateChannelOnSessionDialog.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/ICreateChannelOnSessionDialog.java
deleted file mode 100644 (file)
index 426230c..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/**********************************************************************
- * 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: 
- *   Bernd Hufmann - Initial API and implementation
- **********************************************************************/
-package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
-
-
-/**
- * <b><u>ICreateChannelOnSessionDialog</u></b>
- * <p>
- * Interface for the create channel dialog when domain is known, i.e. dialog 
- * was opened on session level.
- * </p>
- */
-public interface ICreateChannelOnSessionDialog extends ICreateChannelDialog {
-
-    // ------------------------------------------------------------------------
-    // Accessors
-    // ------------------------------------------------------------------------
-    /**
-     * @return true for Kernel domain. False for UST.
-     */
-    public boolean isKernel();
-
-}
index 2c26f2afed35dd06059792f8245a4a05db1312ca..f8d5d8a7205fc9f6e2a8942231cf259b65075723 100644 (file)
@@ -3,7 +3,7 @@ package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
 import org.eclipse.ui.PlatformUI;
 
 
-public class TraceControlDialogFactory {
+final public class TraceControlDialogFactory {
 
     // ------------------------------------------------------------------------
     // Members
@@ -24,11 +24,6 @@ public class TraceControlDialogFactory {
      */
     private ICreateChannelDialog fCreateChannelDialog;
     
-    /**
-     * The create channel dialog (on session level)
-     */
-    private ICreateChannelOnSessionDialog fCreateChannelOnSessionDialog;
-    
     /**
      * The create session dialog.
      */
@@ -66,8 +61,8 @@ public class TraceControlDialogFactory {
     /**
      * @return TraceControlDialogFactory instance
      */
-    public static TraceControlDialogFactory getInstance() {
-        if (null == fInstance) {
+    public synchronized static TraceControlDialogFactory getInstance() {
+        if (fInstance == null) {
             fInstance = new TraceControlDialogFactory();
         }
         return fInstance;
@@ -77,7 +72,7 @@ public class TraceControlDialogFactory {
      * @return new connection dialog
      */
     public INewConnectionDialog getNewConnectionDialog() {
-        if (null == fNewConnectionDialog) {
+        if (fNewConnectionDialog == null) {
             fNewConnectionDialog = new NewConnectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
         }
         return fNewConnectionDialog;
@@ -95,7 +90,7 @@ public class TraceControlDialogFactory {
      * @return create channel dialog (on domain level)
      */
     public ICreateChannelDialog getCreateChannelDialog() {
-        if (null == fCreateChannelDialog) {
+        if (fCreateChannelDialog == null) {
             fCreateChannelDialog = new CreateChannelDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
         }
         return fCreateChannelDialog;
@@ -109,29 +104,11 @@ public class TraceControlDialogFactory {
         fCreateChannelDialog = createChannelDialog;
     }
     
-    /**
-     * @return create channel dialog (on session level)
-     */
-    public ICreateChannelOnSessionDialog getCreateChannelOnSessionDialog() {
-        if (null == fCreateChannelOnSessionDialog) {
-            fCreateChannelOnSessionDialog = new CreateChannelDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
-        }
-        return fCreateChannelOnSessionDialog;
-    }
-
-    /**
-     * Sets a create channel dialog implementation (on domain level).
-     * @param createChannelDialog - a create channel dialog implementation
-     */
-    public void setCreateChannelOnSessionDialog(ICreateChannelOnSessionDialog createChannelDialog) {
-        fCreateChannelOnSessionDialog = createChannelDialog;
-    }
-
     /**
      * @return create session dialog implementation
      */
     public ICreateSessionDialog getCreateSessionDialog() {
-        if (null == fCreateSessionDialog) {
+        if (fCreateSessionDialog == null) {
             fCreateSessionDialog = new CreateSessionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
         }
         return fCreateSessionDialog;
@@ -149,7 +126,7 @@ public class TraceControlDialogFactory {
      * @return enable events dialog implementation.
      */
     public IEnableEventsDialog getEnableEventsDialog() {
-        if (null == fEnableEventsDialog) {
+        if (fEnableEventsDialog == null) {
             fEnableEventsDialog = new EnableEventsDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
         }
         return fEnableEventsDialog;
@@ -167,7 +144,7 @@ public class TraceControlDialogFactory {
      * @return get events info dialog implementation.
      */
     public IGetEventInfoDialog getGetEventInfoDialog() {
-        if (null == fGetEventInfoDialog) {
+        if (fGetEventInfoDialog == null) {
             fGetEventInfoDialog = new GetEventInfoDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
         }
         return fGetEventInfoDialog;
@@ -185,7 +162,7 @@ public class TraceControlDialogFactory {
      * @return the confirmation dialog implementation
      */
     public IConfirmDialog getConfirmDialog() {
-        if (null == fConfirmDialog) {
+        if (fConfirmDialog == null) {
             fConfirmDialog = new ConfirmDialog();
         }
         return fConfirmDialog;
index 94cabd8941f5312037143915f5302d4318b5f7fa..2c565bcdc6142e10692f09aede2e5582942a67da 100644 (file)
@@ -12,6 +12,7 @@
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
@@ -39,7 +40,7 @@ import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstPro
 import org.eclipse.ui.IWorkbenchPage;
 
 /**
- * <b><u>EnableEventHandler</u></b>
+ * <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.
@@ -51,19 +52,9 @@ public class AssignEventHandler extends BaseControlViewHandler {
     // Attributes
     // ------------------------------------------------------------------------
     /**
-     * The list of event components the command is to be executed on. 
+     * The command execution parameter.
      */
-    private List<BaseEventComponent> fEvents = new ArrayList<BaseEventComponent>();
-    
-    /**
-     * The list of available sessions.
-     */
-    private TraceSessionComponent[] fSessions;
-    
-    /**
-     * Flag for indicating Kernel or UST.
-     */
-    Boolean fIsKernel = null;
+    private Parameter fParam;
     
     // ------------------------------------------------------------------------
     // Operations
@@ -76,58 +67,68 @@ public class AssignEventHandler extends BaseControlViewHandler {
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
 
-        // Open dialog box to retrieve the session and channel where the events should be enabled in.
-        final IGetEventInfoDialog dialog = TraceControlDialogFactory.getInstance().getGetEventInfoDialog();
-        dialog.setIsKernel(fIsKernel);
-        dialog.setSessions(fSessions);
+        fLock.lock();
+        try {
+            // Make a copy for thread safety
+            final Parameter param = new Parameter(fParam);
 
-        if (dialog.open() != Window.OK) {
-            return null;
-        }
+            // Open dialog box to retrieve the session and channel where the events should be enabled in.
+            final IGetEventInfoDialog dialog = TraceControlDialogFactory.getInstance().getGetEventInfoDialog();
+            dialog.setIsKernel(param.isKernel());
+            dialog.setSessions(param.getSessions());
 
-        Job job = new Job(Messages.TraceControl_EnableEventsJob) {
-            @Override
-            protected IStatus run(IProgressMonitor monitor) {
-
-                String errorString = null;
-                try {
-                    List<String> eventNames = new ArrayList<String>();
-                    // Create list of event names
-                    for (Iterator<BaseEventComponent> iterator = fEvents.iterator(); iterator.hasNext();) {
-                        BaseEventComponent event = (BaseEventComponent) iterator.next();
-                        eventNames.add(event.getName());
-                    }
+            if (dialog.open() != Window.OK) {
+                return null;
+            }
 
-                    TraceChannelComponent channel = dialog.getChannel();
-                    if (channel == null) {
-                        // enable events on default channel (which will be created by lttng-tools)
-                        dialog.getSession().enableEvents(eventNames, fIsKernel, monitor);
-                    } else {
-                        channel.enableEvents(eventNames, monitor);
-                    }
+            Job job = new Job(Messages.TraceControl_EnableEventsJob) {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
 
-                } catch (ExecutionException e) {
-                    errorString = e.toString() + "\n"; //$NON-NLS-1$
-                }
+                    StringBuffer errorString = new StringBuffer();
+                    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();
+                            eventNames.add(event.getName());
+                        }
 
-                // get session configuration in all cases
-                try {
-                    dialog.getSession().getConfigurationFromNode(monitor);
-                } catch (ExecutionException e) {
-                    if (errorString == null) {
-                        errorString = new String();
+                        TraceChannelComponent channel = dialog.getChannel();
+                        if (channel == null) {
+                            // enable events on default channel (which will be created by lttng-tools)
+                            dialog.getSession().enableEvents(eventNames, param.isKernel(), monitor);
+                        } else {
+                            channel.enableEvents(eventNames, monitor);
+                        }
+
+                    } catch (ExecutionException e) {
+                        errorString.append(e.toString());
+                        errorString.append('\n');
                     }
-                    errorString += Messages.TraceControl_ListSessionFailure + ": " + e.toString();  //$NON-NLS-1$ 
-                } 
 
-                if (errorString != null) {
-                    return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString);
+                    // 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());
+                    } 
+
+                    if (errorString.length() > 0) {
+                        return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString.toString());
+                    }
+                    return Status.OK_STATUS;
                 }
-                return Status.OK_STATUS;
-            }
-        };
-        job.setUser(true);
-        job.schedule();
+            };
+            job.setUser(true);
+            job.schedule();
+        } finally {
+            fLock.unlock();
+        }
+
         return null;
     }
 
@@ -137,11 +138,11 @@ public class AssignEventHandler extends BaseControlViewHandler {
      */
     @Override
     public boolean isEnabled() {
-        fEvents.clear();
-        fSessions = null;
-        fIsKernel = null;
+        ArrayList<BaseEventComponent> events = new ArrayList<BaseEventComponent>();
+        TraceSessionComponent[] sessions = null;
+        Boolean isKernel = null;
 
-     // Get workbench page for the Control View
+        // Get workbench page for the Control View
         IWorkbenchPage page = getWorkbenchPage();
         if (page == null) {
             return false;
@@ -167,25 +168,91 @@ public class AssignEventHandler extends BaseControlViewHandler {
                     } else {
                         return false;
                     }
-                    if (fIsKernel == null) {
-                        fIsKernel = Boolean.valueOf(temp);
+                    if (isKernel == null) {
+                        isKernel = Boolean.valueOf(temp);
                     } else {
                         // don't mix events from Kernel and UST provider
-                        if (fIsKernel.booleanValue() != temp) {
+                        if (isKernel.booleanValue() != temp) {
                             return false;
                         }
                     }
 
                     // Add BaseEventComponents
-                    fEvents.add(event);
+                    events.add(event);
                     
-                    if (fSessions == null) {
+                    if (sessions == null) {
                         TargetNodeComponent  root = (TargetNodeComponent)event.getParent().getParent().getParent();
-                        fSessions = root.getSessions();
+                        sessions = root.getSessions();
                     }
                 }
             }
         }
-        return ((fEvents.size() > 0) && (fSessions != null) && (fSessions.length > 0));
+
+        boolean isEnabled = ((!events.isEmpty()) && (sessions != null) && (sessions.length > 0));
+        fLock.lock();
+        try {
+            fParam = null;
+            if(isEnabled) {
+                fParam = new Parameter(sessions, events, isKernel);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
+    }
+
+    /**
+     *  Class containing parameter for the command execution. 
+     */
+    final static private class Parameter {
+
+        /**
+         * The list of event components the command is to be executed on. 
+         */
+        private 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)
+         */
+        public Parameter(TraceSessionComponent[] sessions, List<BaseEventComponent> events, boolean isKernel) {
+            fSessions = Arrays.copyOf(sessions, sessions.length);
+            fEvents = new ArrayList<BaseEventComponent>();
+            fEvents.addAll(events);
+            fIsKernel = isKernel;
+        }
+        
+        /**
+         * Copy constructor
+         * @param other - a parameter to copy
+         */
+        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;
+        }
     }
 }
index d25f03e709d36295effc11c328d0b4517747becc..80782b04802da410c6abef24f7b73e5bf458068b 100644 (file)
@@ -11,6 +11,8 @@
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
 
+import java.util.concurrent.locks.ReentrantLock;
+
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
 import org.eclipse.ui.IWorkbenchPage;
@@ -26,6 +28,14 @@ import org.eclipse.ui.PlatformUI;
  */
 abstract public class BaseControlViewHandler extends AbstractHandler {
 
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+    /**
+     * The synchronization lock.
+     */
+    protected ReentrantLock fLock = new ReentrantLock();
+    
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseCreateChannelHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseCreateChannelHandler.java
new file mode 100644 (file)
index 0000000..f069d8a
--- /dev/null
@@ -0,0 +1,121 @@
+/**********************************************************************
+ * 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: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.window.Window;
+import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
+
+/**
+ * <b><u>BaseCreateChannelHandler</u></b>
+ * <p>
+ * Base implementation of aCommand handler implementation to create a trace channel.  
+ * </p>
+ */
+abstract class BaseCreateChannelHandler extends BaseControlViewHandler {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+    protected CommandParameter fParam;
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+    /**
+     * Enables channels with given names which are part of this domain. If a given channel 
+     * doesn't exists it creates a new channel with the given parameters (or default values 
+     * if given parameter is null). 
+     * @param - a parameter instance with data for the command execution
+     * @param channelNames - a list of channel names to enable on this domain
+     * @param info - channel information to set for the channel (use null for default)
+     * @param isKernel -  a flag for indicating kernel or UST.
+     * @param monitor - a progress monitor
+     * @throws ExecutionException
+     */
+    abstract public void enableChannel(CommandParameter param, List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException; 
+    
+    /**
+     * @param - a parameter instance with data for the command execution
+     * @return returns the relevant domain (null if domain is not known)
+     */
+    abstract public TraceDomainComponent getDomain(CommandParameter param);
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+     */
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        fLock.lock();
+        try {
+            final CommandParameter param = fParam.clone();
+
+            final ICreateChannelDialog dialog =  TraceControlDialogFactory.getInstance().getCreateChannelDialog();
+            dialog.setDomainComponent(getDomain(param));
+
+            if (dialog.open() != Window.OK) {
+                return null;
+            }
+
+            Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    StringBuffer errorString = new StringBuffer();
+
+                    List<String> channelNames = new ArrayList<String>();                    
+                    channelNames.add(dialog.getChannelInfo().getName());
+
+                    try {
+                        enableChannel(param, channelNames, dialog.getChannelInfo(), dialog.isKernel(), monitor);
+                    } catch (ExecutionException e) {
+                        errorString.append(e.toString());
+                        errorString.append("\n"); //$NON-NLS-1$
+                    }
+
+                    // get session configuration in all cases
+                    try {
+                        param.getSession().getConfigurationFromNode(monitor);
+                    } catch (ExecutionException e) {
+                        errorString.append(Messages.TraceControl_ListSessionFailure);
+                        errorString.append(": "); //$NON-NLS-1$
+                        errorString.append(e.toString());
+                    } 
+
+                    if (errorString.length() > 0) {
+                        return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString.toString());
+                    }
+                    return Status.OK_STATUS;
+                }
+            };
+            job.setUser(true);
+            job.schedule();
+        } finally {
+            fLock.unlock();
+        }
+        return null;
+    }
+
+}
index af1e743b5373892fb4c333f8347686ca3c9f6f1d..e0772c68a713e4256bb1047f27e00fd826690b36 100644 (file)
@@ -30,7 +30,6 @@ import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLev
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProviderGroup;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
 
@@ -46,52 +45,58 @@ abstract public class BaseEnableEventHandler extends BaseControlViewHandler {
     // Attributes
     // ------------------------------------------------------------------------
     /**
-     * The session component the command is to be executed on. 
+     * The command execution parameter.
      */
-    protected TraceSessionComponent fSession = null;
+    protected CommandParameter fParam = null;
 
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
     /**
      * Enables a list of events for given parameters.
+     * @param - a parameter instance with data for the command execution
      * @param eventNames - list of event names
      * @param isKernel - true if kernel domain else false
      * @param monitor - a progress monitor
      * @throws ExecutionException
      */
-    abstract public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException;
+    abstract public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException;
+
     /**
      * Enables all syscall events.
+     * @param - a parameter instance with data for the command execution
      * @param monitor - a progress monitor
      * @throws ExecutionException
      */
-    abstract public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException;
+    abstract public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException;
     
     /**
      * Enables a dynamic probe.
+     * @param - a parameter instance with data for the command execution
      * @param eventName - a event name
      * @param isFunction - true for dynamic function entry/return probe else false
      * @param probe - a dynamic probe information
      * @param monitor - a progress monitor
      * @throws ExecutionException
      */
-    abstract public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
+    abstract public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
     
     /**
      * Enables events using log level
+     * @param - a parameter instance with data for the command execution
      * @param eventName - a event name
      * @param logLevelType - a log level type 
      * @param level - a log level 
      * @param monitor - a progress monitor  
      * @throws ExecutionException
      */    
-    abstract public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException;
+    abstract public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException;
     
     /**
+     * @param - a parameter instance with data for the command execution
      * @return returns the relevant domain (null if domain is not known)
      */
-    abstract TraceDomainComponent getDomain();
+    abstract TraceDomainComponent getDomain(CommandParameter param);
 
     /*
      * (non-Javadoc)
@@ -105,98 +110,95 @@ abstract public class BaseEnableEventHandler extends BaseControlViewHandler {
         if (window == null) {
             return false;
         }
+        fLock.lock();
+        try {
+            // Make a copy for thread safety
+            final CommandParameter param = fParam.clone();
 
-        TargetNodeComponent node = fSession.getTargetNode();
-        List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
+            TargetNodeComponent node = param.getSession().getTargetNode();
+            List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
 
-        final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
-        dialog.setTraceProviderGroup((TraceProviderGroup)providers.get(0));
-        dialog.setTraceDomainComponent(getDomain());
+            final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
+            dialog.setTraceProviderGroup((TraceProviderGroup)providers.get(0));
+            dialog.setTraceDomainComponent(getDomain(param));
 
-        if (dialog.open() != Window.OK) {
-            return null;
-        }
+            if (dialog.open() != Window.OK) {
+                return null;
+            }
 
-        Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
-            @Override
-            protected IStatus run(IProgressMonitor monitor) {
-                String errorString = null;
-
-                try {
-                    // Enable tracepoint events
-                    if (dialog.isTracepoints()) {
-                        if (dialog.isAllTracePoints()) {
-                            enableEvents(null, dialog.isKernel(), monitor);
-                        } else {
-                            List<String> eventNames = dialog.getEventNames();
-                            if (eventNames.size() > 0) {
-                                enableEvents(eventNames, dialog.isKernel(), monitor);
+            Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    StringBuffer errorString = new StringBuffer();
+
+                    try {
+                        // Enable tracepoint events
+                        if (dialog.isTracepoints()) {
+                            if (dialog.isAllTracePoints()) {
+                                enableEvents(param, null, dialog.isKernel(), monitor);
+                            } else {
+                                List<String> eventNames = dialog.getEventNames();
+                                if (!eventNames.isEmpty()) {
+                                    enableEvents(param, eventNames, dialog.isKernel(), monitor);
+                                }
                             }
                         }
-                    }
 
-                    // Enable syscall events
-                    if (dialog.isAllSysCalls()) {
+                        // Enable syscall events
                         if (dialog.isAllSysCalls()) {
-                            enableSyscalls(monitor);
-                        } 
-                    }
+                            enableSyscalls(param, monitor);
+                        }
 
-                    // Enable dynamic probe
-                    if (dialog.isDynamicProbe()) {
-                        if ((dialog.getProbeEventName() != null && dialog.getProbeName() != null)) {
-                            enableProbe(dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
-                        } 
-                    }
+                        // Enable dynamic probe
+                        if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
+                            enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
+                        }
 
-                    // Enable dynamic function probe
-                    if (dialog.isDynamicFunctionProbe()) {
-                        if ((dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
-                            enableProbe(dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
-                        } 
-                    }
+                        // Enable dynamic function probe
+                        if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
+                            enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
+                        }
 
-                    // Enable event using a wildcard
-                    if (dialog.isWildcard()) {
-                        List<String> eventNames = dialog.getEventNames();
-                        eventNames.add(dialog.getWildcard());
+                        // Enable event using a wildcard
+                        if (dialog.isWildcard()) {
+                            List<String> eventNames = dialog.getEventNames();
+                            eventNames.add(dialog.getWildcard());
 
-                        if (eventNames.size() > 0) {
-                            enableEvents(eventNames, dialog.isKernel(), monitor);
+                            if (!eventNames.isEmpty()) {
+                                enableEvents(param, eventNames, dialog.isKernel(), monitor);
+                            }
                         }
-                    }
-                    
-                    // Enable events using log level
-                    if (dialog.isLogLevel()) {
-                        enableLogLevel(dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), monitor);
+
+                        // Enable events using log level
+                        if (dialog.isLogLevel()) {
+                            enableLogLevel(param, dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), monitor);
+                        }
+
+                    } catch (ExecutionException e) {
+                        errorString.append(e.toString());
+                        errorString.append('\n');
                     }
 
-                } catch (ExecutionException e) {
-                    if (errorString == null) {
-                        errorString = new String();
+                    // get session configuration in all cases
+                    try {
+                        param.getSession().getConfigurationFromNode(monitor);
+                    } catch (ExecutionException e) {
+                        errorString.append(Messages.TraceControl_ListSessionFailure);
+                        errorString.append(": "); //$NON-NLS-1$
+                        errorString.append(e.toString());
                     } 
-                    errorString += e.toString() + "\n"; //$NON-NLS-1$
-                }
 
-                // get session configuration in all cases
-                try {
-                    fSession.getConfigurationFromNode(monitor);
-                } catch (ExecutionException e) {
-                    if (errorString == null) {
-                        errorString = new String();
+                    if (errorString.length() > 0) {
+                        return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString.toString());
                     }
-                    errorString += Messages.TraceControl_ListSessionFailure + ": " + e.toString();  //$NON-NLS-1$ 
-                } 
-
-                if (errorString != null) {
-                    return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString);
+                    return Status.OK_STATUS;
                 }
-                return Status.OK_STATUS;
-            }
-        };
-        job.setUser(true);
-        job.schedule();
-
+            };
+            job.setUser(true);
+            job.schedule();
+        } finally {
+            fLock.unlock();
+        }
         return null;
     }
 }
index b22ac58994c97776e2236e975bb0654d51f07923..fe45ac63cb4f2603d263af28b24de3fd309551de 100644 (file)
@@ -49,15 +49,23 @@ abstract public class BaseNodeHandler extends BaseControlViewHandler {
             return false;
         }
 
-        fTargetNode = null;
-        
+        TargetNodeComponent node = null;
         // Check if the node component is selected
         ISelection selection = page.getSelection(ControlView.ID);
         if (selection instanceof StructuredSelection) {
             Object element = ((StructuredSelection) selection).getFirstElement();
-            fTargetNode = (element instanceof TargetNodeComponent) ? (TargetNodeComponent) element : null;
+            node = (element instanceof TargetNodeComponent) ? (TargetNodeComponent) element : null;
         }
-        return fTargetNode != null;
+        boolean isEnabled = node != null;
+        fLock.lock();
+        try {
+            if (isEnabled) {
+                fTargetNode = node;
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
     }
 
     
index d18afee82254b2af369bba4c5d1ad3f9756825c8..9a8545be42f8b8029c81ffbc9d1ffef3bd9d5eeb 100644 (file)
@@ -46,21 +46,9 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler {
     // Attributes
     // ------------------------------------------------------------------------
     /**
-     * Kernel domain component reference.
+     * The command execution parameter.
      */
-    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. 
-     */
-    protected List<TraceChannelComponent> fUstChannels = new ArrayList<TraceChannelComponent>();
+    protected Parameter fParam;
 
     // ------------------------------------------------------------------------
     // Accessors
@@ -89,74 +77,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) {
+                    String errorString = 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) {
+                        errorString = e.toString() + "\n"; //$NON-NLS-1$
                     }
-                } 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 (errorString != null) {
+                        return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString);
+                    }
 
-                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 +167,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 +197,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;
+        }
     }
 }
index b0647a4a6dca8a30a7914528e0ea89e528bae353..28c7c86bdac0778aebf4d407141529485c284d53 100644 (file)
@@ -46,13 +46,9 @@ abstract public class ChangeEventStateHandler extends BaseControlViewHandler {
     // Attributes
     // ------------------------------------------------------------------------
     /**
-     * Channel component reference.
+     * The command execution parameter.
      */
-    protected TraceChannelComponent fChannel = null;
-    /**
-     * The list of kernel channel components the command is to be executed on. 
-     */
-    protected List<TraceEventComponent> fEvents = new ArrayList<TraceEventComponent>();
+    protected Parameter fParam;
     
     // ------------------------------------------------------------------------
     // Accessors
@@ -87,60 +83,72 @@ abstract public class ChangeEventStateHandler extends BaseControlViewHandler {
             return false;
         }
 
-        Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
-            @Override
-            protected IStatus run(IProgressMonitor monitor) {
-                String errorString = null;
-
-                TraceSessionComponent session = null;
-                
-                try {
-                    boolean isAll = false;
-                    if (fChannel != null) {
-                        session = fChannel.getSession();
-                        List<String> eventNames = new ArrayList<String>();
-                        for (Iterator<TraceEventComponent> iterator = fEvents.iterator(); iterator.hasNext();) {
-                            // Enable/disable all selected channels which are disabled
-                            TraceEventComponent event = (TraceEventComponent) iterator.next();
+        fLock.lock();
+        try {
+            
+            final Parameter param = new Parameter(fParam);
+
+            Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    StringBuffer errorString = new StringBuffer();
+
+                    TraceSessionComponent session = null;
+
+                    try {
+                        boolean isAll = false;
+                        if (param.getChannel() != null) {
+                            session = param.getChannel().getSession();
+                            List<String> eventNames = new ArrayList<String>();
+                            List<TraceEventComponent> events = param.getEvents();
                             
-                            // Workaround for wildcard handling in lttng-tools
-                            if ("*".equals(event.getName())) { //$NON-NLS-1$
-                                isAll = true;
-                            } else { 
-                                eventNames.add(event.getName());
+                            for (Iterator<TraceEventComponent> iterator = events.iterator(); iterator.hasNext();) {
+                                // Enable/disable all selected channels which are disabled
+                                TraceEventComponent event = (TraceEventComponent) iterator.next();
+
+                                // Workaround for wildcard handling in lttng-tools
+                                if ("*".equals(event.getName())) { //$NON-NLS-1$
+                                    isAll = true;
+                                } else { 
+                                    eventNames.add(event.getName());
+                                }
+                            }
+                            if (isAll) {
+                                changeState(param.getChannel(), null, monitor);
                             }
-                        }
-                        if (isAll) {
-                            changeState(fChannel, null, monitor);
-                        }
 
-                        if (eventNames.size() > 0) {
-                            changeState(fChannel, eventNames, monitor);
-                        }
+                            if (!eventNames.isEmpty()) {
+                                changeState(param.getChannel(), eventNames, monitor);
+                            }
 
-                        for (Iterator<TraceEventComponent> iterator = fEvents.iterator(); iterator.hasNext();) {
-                            // Enable all selected channels which are disabled
-                            TraceEventComponent ev = (TraceEventComponent) iterator.next();
-                            ev.setState(getNewState());
+                            for (Iterator<TraceEventComponent> iterator = events.iterator(); iterator.hasNext();) {
+                                // Enable all selected channels which are disabled
+                                TraceEventComponent ev = (TraceEventComponent) iterator.next();
+                                ev.setState(getNewState());
+                            }
                         }
+                    } catch (ExecutionException e) {
+                        errorString.append(e.toString());
+                        errorString.append('\n');
                     }
-                } catch (ExecutionException e) {
-                    errorString = e.toString() + "\n"; //$NON-NLS-1$
-                }
-
-                // In all cases notify listeners  
-                session.fireComponentChanged(session);
 
-                if (errorString != null) {
-                    return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString);
-                }
+                    if (session != null) {
+                        // In all cases notify listeners  
+                        session.fireComponentChanged(session);
+                    }
 
-                return Status.OK_STATUS;
-            }
-        };
-        job.setUser(true);
-        job.schedule();
+                    if (errorString.length() > 0) {
+                        return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString.toString());
+                    }
 
+                    return Status.OK_STATUS;
+                }
+            };
+            job.setUser(true);
+            job.schedule();
+        } finally {
+            fLock.unlock();
+        }
         return null;
     }
 
@@ -156,10 +164,12 @@ abstract public class ChangeEventStateHandler extends BaseControlViewHandler {
             return false;
         }
 
-        reset();
-
         // Check if one or more session are selected
         ISelection selection = page.getSelection(ControlView.ID);
+        
+        TraceChannelComponent channel = null;
+        List<TraceEventComponent> events = new ArrayList<TraceEventComponent>();
+
         if (selection instanceof StructuredSelection) {
             StructuredSelection structered = ((StructuredSelection) selection);
             String sessionName = null;
@@ -175,8 +185,8 @@ abstract public class ChangeEventStateHandler extends BaseControlViewHandler {
                         sessionName = String.valueOf(event.getSessionName());
                     }
                     
-                    if (fChannel == null) {
-                        fChannel = (TraceChannelComponent)event.getParent();
+                    if (channel == null) {
+                        channel = (TraceChannelComponent)event.getParent();
                     }
 
                     if (channelName == null) {
@@ -186,25 +196,69 @@ abstract public class ChangeEventStateHandler extends BaseControlViewHandler {
                     // Enable command only for events of same session, same channel and domain
                     if ((!sessionName.equals(event.getSessionName())) ||
                         (!channelName.equals(event.getChannelName())) ||
-                        (fChannel.isKernel() != event.isKernel())) {
-                        reset();
+                        (channel.isKernel() != event.isKernel())) {
+                        events.clear();
                         break;
                     }
 
                     if ((event.getState() != getNewState())) {
-                        fEvents.add(event);
+                        events.add(event);
                     }
                 }
             }
         }
-        return fEvents.size() > 0;
+        boolean isEnabled = !events.isEmpty();
+
+        fLock.lock();
+        try {
+            fParam = null;
+            if (isEnabled) {
+                fParam = new Parameter(channel, events);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
     }
 
     /**
-     * Reset members
+     *  Class containing parameter for the command execution. 
      */
-    private void reset() {
-        fChannel = null;
-        fEvents.clear();
+    protected class Parameter {
+        /**
+         * Channel component reference.
+         */
+        final private TraceChannelComponent fChannel;
+        /**
+         * The list of kernel channel components the command is to be executed on. 
+         */
+        final private List<TraceEventComponent> fEvents = new ArrayList<TraceEventComponent>();
+        
+        public Parameter(TraceChannelComponent channel, List<TraceEventComponent> events) {
+            fChannel = channel;
+            fEvents.addAll(events);
+        }
+        
+        /**
+         * Copy constructor
+         * @param other - a parameter to copy
+         */
+        public Parameter(Parameter other) {
+            this(other.fChannel, other.fEvents);
+        }
+        
+        /**
+         * @return the trace channel component.
+         */
+        public TraceChannelComponent getChannel() {
+            return fChannel;
+        }
+        
+        /**
+         * @return a list of trace event components.
+         */
+        public List<TraceEventComponent> getEvents() {
+            return fEvents;
+        }
     }
 }
index 6ed94399f9c3c16990aae81b67baef235981dff9..2065c30a82a3312ddaeffd7a926d973cdc2ec970 100644 (file)
@@ -81,28 +81,37 @@ abstract public class ChangeSessionStateHandler extends BaseControlViewHandler {
             return false;
         }
 
-        Job job = new Job(Messages.TraceControl_StartSessionJob) {
-            @Override
-            protected IStatus run(IProgressMonitor monitor) {
-                try {
-                    for (Iterator<TraceSessionComponent> iterator = fSessions.iterator(); iterator.hasNext();) {
+        fLock.lock();
+        try {
+            
+            final List<TraceSessionComponent> sessions = new ArrayList<TraceSessionComponent>();
+            sessions.addAll(fSessions);
 
-                        // Start all selected sessions
-                        TraceSessionComponent session = (TraceSessionComponent) iterator.next();
-                        changeState(session, monitor);
+            Job job = new Job(Messages.TraceControl_StartSessionJob) {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    try {
+                        for (Iterator<TraceSessionComponent> iterator = sessions.iterator(); iterator.hasNext();) {
 
-                        // Set Session state
-                        session.setSessionState(getNewState());
-                        session.fireComponentChanged(session);
-                    }
-                } catch (ExecutionException e) {
-                    return new Status(Status.ERROR, Activator.PLUGIN_ID, e.toString());
-                }  
-                return Status.OK_STATUS;
-            }
-        };
-        job.setUser(true);
-        job.schedule();
+                            // Start all selected sessions
+                            TraceSessionComponent session = (TraceSessionComponent) iterator.next();
+                            changeState(session, monitor);
+
+                            // Set Session state
+                            session.setSessionState(getNewState());
+                            session.fireComponentChanged(session);
+                        }
+                    } catch (ExecutionException e) {
+                        return new Status(Status.ERROR, Activator.PLUGIN_ID, e.toString());
+                    }  
+                    return Status.OK_STATUS;
+                }
+            };
+            job.setUser(true);
+            job.schedule();
+        } finally {
+            fLock.unlock();
+        }
         return null;
     }
 
@@ -118,7 +127,7 @@ abstract public class ChangeSessionStateHandler extends BaseControlViewHandler {
             return false;
         }
 
-        fSessions.clear();
+        List<TraceSessionComponent> sessions = new ArrayList<TraceSessionComponent>(0);
 
         // Check if one or more session are selected
         ISelection selection = page.getSelection(ControlView.ID);
@@ -130,11 +139,21 @@ abstract public class ChangeSessionStateHandler extends BaseControlViewHandler {
                     // Add only TraceSessionComponents that are inactive and not destroyed
                     TraceSessionComponent session = (TraceSessionComponent) element;
                     if ((session.getSessionState() != getNewState()) && (!session.isDestroyed())) {
-                        fSessions.add((TraceSessionComponent)element);
+                        sessions.add(session);
                     }
                 }
             }
         }
-        return fSessions.size() > 0;
+        boolean isEnabled = !sessions.isEmpty();
+        fLock.lock();
+        try {
+            fSessions = null;
+            if (isEnabled) {
+                fSessions = sessions;
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
     }
 }
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChannelCommandParameter.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChannelCommandParameter.java
new file mode 100644 (file)
index 0000000..b08b4ad
--- /dev/null
@@ -0,0 +1,68 @@
+/**********************************************************************
+ * 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: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+
+/**
+ *  Class containing parameter for the command execution. 
+ */
+public class ChannelCommandParameter extends CommandParameter implements Cloneable {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private TraceChannelComponent fChannel;
+
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor
+     * @param session - a trace session component.
+     * @param channel - a trace channel component
+     */
+    public ChannelCommandParameter(TraceSessionComponent session, TraceChannelComponent channel) {
+        super(session);
+        fChannel = channel;
+    }
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the trace channel component
+     */
+    public TraceChannelComponent getChannel() {
+        return fChannel;
+    }
+    
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public ChannelCommandParameter clone() {
+        ChannelCommandParameter clone = (ChannelCommandParameter) super.clone();
+        clone.fChannel = fChannel;
+        return clone;
+    }
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/CommandParameter.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/CommandParameter.java
new file mode 100644 (file)
index 0000000..ccfb7c8
--- /dev/null
@@ -0,0 +1,71 @@
+/**********************************************************************
+ * 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: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+
+/**
+ *  Class containing parameter for the command execution. 
+ */
+public class CommandParameter implements Cloneable {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * The trace session component.
+     */
+    private TraceSessionComponent fSession;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor 
+     * @param session a trace session component.
+     */
+    public CommandParameter(TraceSessionComponent session) {
+        fSession = session;
+    }
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the session component.
+     */
+    public TraceSessionComponent getSession() {
+        return fSession;
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public CommandParameter clone() {
+        CommandParameter clone = null;
+        try {
+            clone = (CommandParameter) super.clone();
+            clone.fSession = fSession;
+        } catch (CloneNotSupportedException e) {
+        }
+        return clone;
+    }
+}
\ No newline at end of file
index 6a7794e40ae44fdc80c82e8a43a115b8924f315c..9bede57a2ecf1b7ec31352b845d08ea371a84200 100644 (file)
@@ -33,7 +33,12 @@ public class ConnectHandler extends BaseNodeHandler {
      */
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        fTargetNode.connect();
+        fLock.lock();
+        try {
+            fTargetNode.connect();
+        } finally {
+            fLock.unlock();
+        }
         return null;
     }
 
@@ -43,6 +48,13 @@ public class ConnectHandler extends BaseNodeHandler {
      */
     @Override
     public boolean isEnabled() {
-        return (super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.DISCONNECTED));    
+        boolean isEnabled = false;
+        fLock.lock();
+        try {
+           isEnabled = (super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.DISCONNECTED));
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
      }
 }
index b7d5c537acd728a4153790615af04925d34cdca2..56b51c10bf32d586c1fe422278cab3c9d5c1b6db 100644 (file)
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
 
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-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.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.ICreateChannelDialog;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
@@ -40,71 +31,35 @@ import org.eclipse.ui.IWorkbenchPage;
  * Command handler implementation to create a trace channel for known domain.
  * </p>
  */
-public class CreateChannelOnDomainHandler extends BaseControlViewHandler {
+public class CreateChannelOnDomainHandler extends BaseCreateChannelHandler {
 
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
-    /**
-     * The the domain component the command is to be executed on. 
-     */
-    private TraceDomainComponent fDomain; 
 
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
     /*
      * (non-Javadoc)
-     * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseCreateChannelHandler#enableChannel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo, boolean, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public Object execute(ExecutionEvent event) throws ExecutionException {
-
-        // Get channel information from user
-        final ICreateChannelDialog dialog = TraceControlDialogFactory.getInstance().getCreateChannelDialog();
-        dialog.setDomainComponent(fDomain);
-
-        if (dialog.open() != Window.OK) {
-            return null;
+    public void enableChannel(CommandParameter param, List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof DomainCommandParameter) {
+            ((DomainCommandParameter)param).getDomain().enableChannels(channelNames, info, monitor);
+        }
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseCreateChannelHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter)
+     */
+    @Override
+    public TraceDomainComponent getDomain(CommandParameter param) {
+        if (param instanceof DomainCommandParameter) {
+            return ((DomainCommandParameter)param).getDomain();
         }
-
-        Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
-            @Override
-            protected IStatus run(IProgressMonitor monitor) {
-                String errorString = null;
-
-                List<String> channelNames = new ArrayList<String>();
-                channelNames.add(dialog.getChannelInfo().getName());
-
-                try {
-                    fDomain.enableChannels(channelNames, dialog.getChannelInfo(), monitor);
-                } catch (ExecutionException e) {
-                    if (errorString == null) {
-                        errorString = new String();
-                    } 
-                    errorString += e.toString() + "\n"; //$NON-NLS-1$
-                }
-
-                // get session configuration in all cases
-                try {
-                    fDomain.getConfigurationFromNode(monitor);
-                } catch (ExecutionException e) {
-                    if (errorString == null) {
-                        errorString = new String();
-                    }
-                    errorString += Messages.TraceControl_ListSessionFailure + ": " + e.toString();  //$NON-NLS-1$ 
-                } 
-
-                if (errorString != null) {
-                    return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString);
-                }
-                return Status.OK_STATUS;
-            }
-        };
-        
-        job.setUser(true);
-        job.schedule();
-            
         return null;
     }
 
@@ -120,8 +75,10 @@ public class CreateChannelOnDomainHandler extends BaseControlViewHandler {
         if (page == null) {
             return false;
         }
-        fDomain = null;
-
+        
+        TraceDomainComponent domain = null;
+        TraceSessionComponent session = null;
+        
         // Check if one domain is selected
         ISelection selection = page.getSelection(ControlView.ID);
         if (selection instanceof StructuredSelection) {
@@ -129,15 +86,30 @@ public class CreateChannelOnDomainHandler extends BaseControlViewHandler {
             for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
                 Object element = (Object) iterator.next();
                 if (element instanceof TraceDomainComponent) {
-                    TraceDomainComponent domain = (TraceDomainComponent) element;
-                    TraceSessionComponent session = (TraceSessionComponent) domain.getParent();
+                    TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
+                    session = (TraceSessionComponent) tmpDomain.getParent();
+                    
                     // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed
                     if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
-                        fDomain = domain;
+                        domain = tmpDomain;
                     }
                 }
             }
         }
-        return fDomain != null;
+        
+        boolean isEnabled = domain != null;
+        
+        fLock.lock();
+        try {
+            fParam = null;
+            if (isEnabled) {
+                fParam = new DomainCommandParameter(session, domain);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        
+        return isEnabled;
     }
+    
 }
index a0ab18da037e387b9a2dc60d3bde7701b9f8bc88..425d814f9b392b0cc7a56af4659b37716caa3f75 100644 (file)
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
 
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-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.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.ICreateChannelOnSessionDialog;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
@@ -41,73 +32,33 @@ import org.eclipse.ui.IWorkbenchPage;
  * (on session level).
  * </p>
  */
-public class CreateChannelOnSessionHandler extends BaseControlViewHandler {
+public class CreateChannelOnSessionHandler extends BaseCreateChannelHandler {
 
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
-    /**
-     * The session component the command is to be executed on. 
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseCreateChannelHandler#enableChannel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo, boolean, org.eclipse.core.runtime.IProgressMonitor)
      */
-    private TraceSessionComponent fSession = null;
-
-    // ------------------------------------------------------------------------
-    // Operations
-    // ------------------------------------------------------------------------
+    @Override
+    public void enableChannel(CommandParameter param, List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+        param.getSession().enableChannels(channelNames, info, isKernel, monitor);
+    }
+    
     /*
      * (non-Javadoc)
-     * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseCreateChannelHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter)
      */
     @Override
-    public Object execute(ExecutionEvent event) throws ExecutionException {
-
-        final ICreateChannelOnSessionDialog dialog =  TraceControlDialogFactory.getInstance().getCreateChannelOnSessionDialog();
-
-        if (dialog.open() != Window.OK) {
-            return null;
-        }
-
-        Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
-            @Override
-            protected IStatus run(IProgressMonitor monitor) {
-                String errorString = null;
-
-                List<String> channelNames = new ArrayList<String>();                    
-                TraceDomainComponent newDomain = new TraceDomainComponent("dummy", fSession); //$NON-NLS-1$
-                channelNames.add(dialog.getChannelInfo().getName());
-                newDomain.setIsKernel(dialog.isKernel());
-
-                try {
-                    newDomain.enableChannels(channelNames, dialog.getChannelInfo(), monitor);
-                } catch (ExecutionException e) {
-                    if (errorString == null) {
-                        errorString = new String();
-                    } 
-                    errorString += e.toString() + "\n"; //$NON-NLS-1$
-                }
-
-                // get session configuration in all cases
-                try {
-                    fSession.getConfigurationFromNode(monitor);
-                } catch (ExecutionException e) {
-                    if (errorString == null) {
-                        errorString = new String();
-                    }
-                    errorString += Messages.TraceControl_ListSessionFailure + ": " + e.toString();  //$NON-NLS-1$ 
-                } 
-
-                if (errorString != null) {
-                    return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString);
-                }
-                return Status.OK_STATUS;
-            }
-        };
-        job.setUser(true);
-        job.schedule();
-
+    public TraceDomainComponent getDomain(CommandParameter param) {
         return null;
     }
 
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
     /*
      * (non-Javadoc)
      * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
@@ -120,8 +71,7 @@ public class CreateChannelOnSessionHandler extends BaseControlViewHandler {
             return false;
         }
 
-        fSession = null;
-
+        TraceSessionComponent session = null;
         // Check if one session is selected
         ISelection selection = page.getSelection(ControlView.ID);
         if (selection instanceof StructuredSelection) {
@@ -130,13 +80,25 @@ public class CreateChannelOnSessionHandler extends BaseControlViewHandler {
                 Object element = (Object) iterator.next();
                 if (element instanceof TraceSessionComponent) {
                     // Add only TraceSessionComponents that are inactive and not destroyed
-                    TraceSessionComponent session = (TraceSessionComponent) element;
-                    if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
-                        fSession = session;
+                    TraceSessionComponent tmpSession = (TraceSessionComponent) element;
+                    if ((tmpSession.getSessionState() == TraceSessionState.INACTIVE) && (!tmpSession.isDestroyed())) {
+                        session = tmpSession;
                     }
                 }
             }
         }
-        return fSession != null;
+        boolean isEnabled = session != null;
+        
+        fLock.lock();
+        try {
+            fParam = null;
+            if (isEnabled) {
+                fParam = new CommandParameter(session);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        
+        return isEnabled;
     }
 }
index f7756f11d72473dabeaef13501642b6c699363b2..08eb91621dd273b1cf3eb3068c99acd24681fd69 100644 (file)
@@ -54,31 +54,37 @@ public class CreateSessionHandler extends BaseControlViewHandler {
     @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; 
+                    
+            // Open dialog box for the node name and address
+            ICreateSessionDialog dialog = TraceControlDialogFactory.getInstance().getCreateSessionDialog();
+            dialog.setTraceSessionGroup(sessionGroup);
 
-        if (dialog.open() != Window.OK) {
-            return null;
-        }
+            if (dialog.open() != Window.OK) {
+                return null;
+            }
 
-        final String sessionName = dialog.getSessionName();
-        final String sessionPath = dialog.isDefaultSessionPath() ? null : dialog.getSessionPath();
+            final String sessionName = dialog.getSessionName();
+            final String sessionPath = dialog.isDefaultSessionPath() ? null : dialog.getSessionPath();
 
-        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;
-            }
-        };
-        job.setUser(true);
-        job.schedule();
-        
+            Job job = new Job(Messages.TraceControl_CreateSessionJob) {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    try {
+                        sessionGroup.createSession(sessionName, sessionPath, monitor);
+                    } catch (ExecutionException e) {
+                        return new Status(Status.ERROR, Activator.PLUGIN_ID, e.toString());
+                    } 
+                    return Status.OK_STATUS;
+                }
+            };
+            job.setUser(true);
+            job.schedule();
+        } finally {
+            fLock.unlock();
+        }
         return null;
     }
 
@@ -95,14 +101,25 @@ public class CreateSessionHandler extends BaseControlViewHandler {
             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;
     }
 }
index ffff78ef780293046da5ac66166ad750691ffe30..34cbe187919ba473d2c91043c39d203ed1a8fff6 100644 (file)
@@ -33,9 +33,14 @@ public class DeleteHandler extends BaseNodeHandler {
      */
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        ITraceControlComponent root = fTargetNode.getParent();
-        fTargetNode.removeAllChildren();
-        root.removeChild(fTargetNode);
+        fLock.lock();
+        try {
+            ITraceControlComponent root = fTargetNode.getParent();
+            fTargetNode.removeAllChildren();
+            root.removeChild(fTargetNode);
+        } finally {
+            fLock.unlock();
+        }
         return null;
     }
 
@@ -45,6 +50,13 @@ public class DeleteHandler extends BaseNodeHandler {
      */
     @Override
     public boolean isEnabled() {
-        return (super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.DISCONNECTED));    
+        boolean isEnabled = false;
+        fLock.lock();
+        try {
+           isEnabled = (super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.DISCONNECTED));
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
      }
 }
index 99c2cc75e04ff57d93d54c478f693903907ed76c..e20da5fd53764e16ad6e5c901ee7051548c361df 100644 (file)
@@ -130,6 +130,6 @@ public class DestroySessionHandler extends BaseControlViewHandler {
                 }
             }
         }
-        return fSessions.size() > 0;
+        return !fSessions.isEmpty();
     }
 }
index 25e3cc6e44c43ce891f52473993bf7c834311264..4aedb75e9ec7b7ff42998888ad4674fcdcd8f56c 100644 (file)
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
 
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TargetNodeState;
 
 /**
@@ -33,7 +34,14 @@ public class DisconnectHandler extends BaseNodeHandler {
      */
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        fTargetNode.disconnect();
+        fLock.lock();
+        try {
+            ITraceControlComponent root = fTargetNode.getParent();
+            fTargetNode.disconnect();
+            root.removeChild(fTargetNode);
+        } finally {
+            fLock.unlock();
+        }
         return null;
     }
 
@@ -43,6 +51,13 @@ public class DisconnectHandler extends BaseNodeHandler {
     */
     @Override
     public boolean isEnabled() {
-        return super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.CONNECTED);
+        boolean isEnabled = false;
+        fLock.lock();
+        try {
+           isEnabled = super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.CONNECTED);
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
     }
 }
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/DomainCommandParameter.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/DomainCommandParameter.java
new file mode 100644 (file)
index 0000000..715a23b
--- /dev/null
@@ -0,0 +1,68 @@
+/**********************************************************************
+ * 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: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+
+/**
+ *  Class containing parameter for the command execution. 
+ */
+public class DomainCommandParameter extends CommandParameter {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private TraceDomainComponent fDomain;
+
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor
+     * @param session - a trace session component.
+     * @param domain - a trace domain component
+     */
+    public DomainCommandParameter(TraceSessionComponent session, TraceDomainComponent domain) {
+        super(session);
+        fDomain = domain;
+    }
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the trace domain component
+     */
+    public TraceDomainComponent getDomain() {
+        return fDomain;
+    }
+    
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public DomainCommandParameter clone() {
+        DomainCommandParameter clone = (DomainCommandParameter) super.clone();
+        clone.fDomain = fDomain;
+        return clone;
+    }
+}
\ No newline at end of file
index 596e19371dd85e6c6f940b331bfe5480edba1a8a..1d714e81c2af90c1b63a99a890586dd50f9e9cd6 100644 (file)
@@ -38,57 +38,64 @@ public class EnableEventOnChannelHandler extends BaseEnableEventHandler {
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
-    /**
-     * The channel component the command is to be executed on. 
-     */
-    private TraceChannelComponent fChannel = null;
 
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
-        fChannel.enableEvents(eventNames, monitor);
+    public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof ChannelCommandParameter) {
+            ((ChannelCommandParameter)param).getChannel().enableEvents(eventNames, monitor);
+        }
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
-        fChannel.enableSyscalls(monitor);
+    public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof ChannelCommandParameter) {
+            ((ChannelCommandParameter)param).getChannel().enableSyscalls(monitor);
+        }
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(java.lang.String, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
-        fChannel.enableProbe(eventName, isFunction, probe, monitor);
+    public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof ChannelCommandParameter) {
+            ((ChannelCommandParameter)param).getChannel().enableProbe(eventName, isFunction, probe, monitor);
+        }
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableLogLevel(java.lang.String, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableLogLevel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
-        fChannel.enableLogLevel(eventName, logLevelType, level, monitor);
+    public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof ChannelCommandParameter) {
+            ((ChannelCommandParameter)param).getChannel().enableLogLevel(eventName, logLevelType, level, monitor);
+        }
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain()
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter)
      */
     @Override
-    public TraceDomainComponent getDomain() {
-        return (TraceDomainComponent) fChannel.getParent();
+    public TraceDomainComponent getDomain(CommandParameter param) {
+        if (param instanceof ChannelCommandParameter) {
+            return (TraceDomainComponent) ((ChannelCommandParameter)param).getChannel().getParent();
+        } 
+        return null;
     }
 
     /*
@@ -103,7 +110,8 @@ public class EnableEventOnChannelHandler extends BaseEnableEventHandler {
             return false;
         }
 
-        fChannel = null;
+        TraceChannelComponent channel = null;
+        TraceSessionComponent session = null;
         ISelection selection = page.getSelection(ControlView.ID);
         if (selection instanceof StructuredSelection) {
             StructuredSelection structered = ((StructuredSelection) selection);
@@ -111,16 +119,26 @@ public class EnableEventOnChannelHandler extends BaseEnableEventHandler {
                 Object element = (Object) iterator.next();
                 if (element instanceof TraceChannelComponent) {
                     // Add only if corresponding TraceSessionComponents is inactive and not destroyed
-                    TraceChannelComponent channel = (TraceChannelComponent) element; 
-                    TraceSessionComponent session = channel.getSession();
+                    TraceChannelComponent tmpChannel = (TraceChannelComponent) element; 
+                    session = tmpChannel.getSession();
                     if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
-                        fChannel = channel;
-                        fSession = session;
+                        channel = tmpChannel;
                     }
                 }
             }
         }
-        return fChannel != null;
+        
+        boolean isEnabled = (channel != null);
+        fLock.lock();
+        try {
+            fParam = null;
+            if(isEnabled) {
+                fParam = new ChannelCommandParameter(session, channel);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
     }
-
 }
+
index b01a7b0f8c55ad9512577eb903adbcee88b08e36..17d03555212fc6064b39b8c13630554ace637f8f 100644 (file)
@@ -38,58 +38,66 @@ public class EnableEventOnDomainHandler extends BaseEnableEventHandler {
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
-    /**
-     * The domain component the command is to be executed on. 
-     */
-    private TraceDomainComponent fDomain = null;
 
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
-        fDomain.enableEvents(eventNames, monitor);
+    public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof DomainCommandParameter) {
+            ((DomainCommandParameter)param).getDomain().enableEvents(eventNames, monitor);
+        }
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
-        fDomain.enableSyscalls(monitor);
+    public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof DomainCommandParameter) {
+            ((DomainCommandParameter)param).getDomain().enableSyscalls(monitor);
+        }
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(java.lang.String, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
-        fDomain.enableProbe(eventName, isFunction, probe, monitor);
+    public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof DomainCommandParameter) {
+            ((DomainCommandParameter)param).getDomain().enableProbe(eventName, isFunction, probe, monitor);
+        }
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableLogLevel(java.lang.String, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableLogLevel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
-        fDomain.enableLogLevel(eventName, logLevelType, level, monitor);
+    public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof DomainCommandParameter) {
+            ((DomainCommandParameter)param).getDomain().enableLogLevel(eventName, logLevelType, level, monitor);
+        }
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain()
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter)
      */
     @Override
-    public TraceDomainComponent getDomain() {
-        return fDomain;
+    public TraceDomainComponent getDomain(CommandParameter param) {
+        if (param instanceof DomainCommandParameter) {
+            return ((DomainCommandParameter)param).getDomain();
+        }
+        return null;
     }
+
     /*
      * (non-Javadoc)
      * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
@@ -102,7 +110,8 @@ public class EnableEventOnDomainHandler extends BaseEnableEventHandler {
             return false;
         }
 
-        fDomain = null;
+        TraceDomainComponent domain = null;
+        TraceSessionComponent session = null;
         ISelection selection = page.getSelection(ControlView.ID);
         if (selection instanceof StructuredSelection) {
             StructuredSelection structered = ((StructuredSelection) selection);
@@ -110,15 +119,25 @@ public class EnableEventOnDomainHandler extends BaseEnableEventHandler {
                 Object element = (Object) iterator.next();
                 if (element instanceof TraceDomainComponent) {
                     // Add only if corresponding TraceSessionComponents is inactive and not destroyed
-                    TraceDomainComponent domain = (TraceDomainComponent) element; 
-                    TraceSessionComponent session = domain.getSession();
+                    TraceDomainComponent tmpDomain = (TraceDomainComponent) element; 
+                    session = tmpDomain.getSession();
                     if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
-                        fDomain = domain;
-                        fSession = session;
+                        domain = tmpDomain;
                     }
                 }
             }
         }
-        return fDomain != null;
+        
+        boolean isEnabled = (domain != null);
+        fLock.lock();
+        try {
+            fParam = null;
+            if(isEnabled) {
+                fParam = new DomainCommandParameter(session, domain);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
     }
 }
index 5aa9deb84ac1c5958bdc05990ac69907008f025f..ba455db82f01681fba9fea0f1f343ac726afa557 100644 (file)
@@ -44,47 +44,47 @@ public class EnableEventOnSessionHandler extends BaseEnableEventHandler {
     // ------------------------------------------------------------------------
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
-        fSession.enableEvents(eventNames, isKernel, monitor);
+    public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+        param.getSession().enableEvents(eventNames, isKernel, monitor);
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
-        fSession.enableSyscalls(monitor);
+    public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException {
+        param.getSession().enableSyscalls(monitor);
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(java.lang.String, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
-        fSession.enableProbe(eventName, isFunction, probe, monitor);
+    public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
+        param.getSession().enableProbe(eventName, isFunction, probe, monitor);
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableLogLevel(java.lang.String, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableLogLevel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
-    public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
-        fSession.enableLogLevel(eventName, logLevelType, level, monitor);
+    public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
+        param.getSession().enableLogLevel(eventName, logLevelType, level, monitor);
     }
 
     
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain()
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter)
      */
     @Override
-    public TraceDomainComponent getDomain() {
+    public TraceDomainComponent getDomain(CommandParameter param) {
         return null;
     }
 
@@ -100,8 +100,7 @@ public class EnableEventOnSessionHandler extends BaseEnableEventHandler {
             return false;
         }
 
-        fSession = null;
-
+        TraceSessionComponent session = null;
         // Check if one session is selected
         ISelection selection = page.getSelection(ControlView.ID);
         if (selection instanceof StructuredSelection) {
@@ -110,13 +109,23 @@ public class EnableEventOnSessionHandler extends BaseEnableEventHandler {
                 Object element = (Object) iterator.next();
                 if (element instanceof TraceSessionComponent) {
                     // Add only if corresponding TraceSessionComponents is inactive and not destroyed
-                    TraceSessionComponent session = (TraceSessionComponent) element; 
-                    if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
-                        fSession = session;
+                    TraceSessionComponent tmpSession = (TraceSessionComponent) element; 
+                    if(tmpSession.getSessionState() == TraceSessionState.INACTIVE && !tmpSession.isDestroyed()) {
+                        session = tmpSession;
                     }
                 }
             }
         }
-        return fSession != null;
+        boolean isEnabled = (session != null);
+        fLock.lock();
+        try {
+            fParam = null;
+            if(isEnabled) {
+                fParam = new CommandParameter(session);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
     }
 }
index f635102a359f96a5ed4d07a7c1ad3829d32e346b..0f898eb3c0a5a3b6fabd3e4c18241699ad83285d 100644 (file)
@@ -114,19 +114,24 @@ public class NewConnectionHandler extends BaseControlViewHandler {
                 return null;
             }
         }
-
+        
         if (host != null) {
-            // successful creation of host
-            TargetNodeComponent node = null;
-            if (!fRoot.containsChild(hostName)) {
-                node = new TargetNodeComponent(hostName, fRoot, host);
-                fRoot.addChild(node);
-            }
-            else {
-                node = (TargetNodeComponent)fRoot.getChild(hostName);
+            fLock.lock();
+            try {
+                // successful creation of host
+                TargetNodeComponent node = null;
+                if (!fRoot.containsChild(hostName)) {
+                    node = new TargetNodeComponent(hostName, fRoot, host);
+                    fRoot.addChild(node);
+                }
+                else {
+                    node = (TargetNodeComponent)fRoot.getChild(hostName);
+                }
+
+                node.connect();
+            } finally {
+                fLock.unlock();
             }
-
-            node.connect();
         }
         return null;
     }
@@ -145,12 +150,24 @@ public class NewConnectionHandler extends BaseControlViewHandler {
             return false;
         }
 
-        fRoot = null;
+        ITraceControlComponent root = null;
 
         // no need to verify part because it has been already done in getWorkbenchPage()
         IWorkbenchPart part = page.getActivePart(); 
-        fRoot = ((ControlView) part).getTraceControlRoot();
+        root = ((ControlView) part).getTraceControlRoot();
+        
+        boolean isEnabled = root != null;
+        
+        fLock.lock();
+        try {
+            fRoot = null;
+            if (isEnabled) {
+                fRoot = root;
+            }
+        } finally {
+            fLock.unlock();
+        }
         
-        return (fRoot != null);
+        return isEnabled;
     }
 }
index 2a477972ba9ffc8d06d7ff5cefc9bef99fea345b..ab6eae01d3f84746a7f74b9ef8f272836b64662b 100644 (file)
@@ -49,7 +49,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 +64,6 @@ public class RefreshHandler extends BaseControlViewHandler {
      */
     @Override
     public boolean isEnabled() {
-        fNode = null;
 
         // Get workbench page for the Control View
         IWorkbenchPage page = getWorkbenchPage();
@@ -67,6 +71,7 @@ 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) {
@@ -82,12 +87,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;
     }
 }
index 24a2a96cde4cfa2238ddb00c89ac7e878bf6fa3a..8dc114118faec2f17ebe5fbac1352a4da101fb49 100644 (file)
@@ -103,6 +103,7 @@ TraceControl_EnableEventsLoglevelEventNameTooltip=Event name for enabling log le
 TraceControl_InvalidProbeNameError=The probe name is invalid 
 TraceControl_InvalidWildcardError=The wild card name is invalid
 TraceControl_InvalidLogLevelEventNameError=The event name for log level is invalid
+TraceControl_InvalidLogLevel=No log level selected
 
 # Tree structure strings
 TraceControl_KernelDomainDisplayName=Kernel
index 2f4aa662c83338e44092861b9b00bd07e3f155ac..dd3db48249715e3b83b406281900079fa481199f 100644 (file)
@@ -175,7 +175,7 @@ public class BaseEventInfo extends TraceInfo implements IBaseEventInfo {
         }
         output.append(" (type: ");
         output.append(fEventType.getInName());
-        output.append(")");
+        output.append(')');
         return output.toString();
     }
     
index 549bb31f8d42d19a0e0adb08d3de50ad21bf77d4..6d538073f29c321d38d6aecb6356d75da1d1ebeb 100644 (file)
@@ -318,7 +318,7 @@ public class ChannelInfo extends TraceInfo implements IChannelInfo {
                 output.append(event.formatString());
             }
         }
-        output.append("\n");
+        output.append('\n');
 
         return output.toString();
     }
index 375e960386a2729425c45b24d481890b29d56c42..33692d9e371c7f5b1f574559c756646389d7e0b4 100644 (file)
@@ -139,7 +139,7 @@ public class DomainInfo extends TraceInfo implements IDomainInfo {
                 output.append(channel.formatString());
             }
         }
-        output.append("\n");
+        output.append('\n');
         return output.toString();
     }
     
index 0e7265b5cabfc25fb77752543d260ff5594f848c..bf88b84098ee192041cbcd1214169a7be06be3c7 100644 (file)
@@ -84,7 +84,7 @@ public class EventInfo extends BaseEventInfo implements IEventInfo {
         output.append(super.formatString());
         output.append(" [");
         output.append(fState.getInName());
-        output.append("]");
+        output.append(']');
         return output.toString();
     }
 
index 2cf38dfd3f0c9d86d4dd499711e696bf460303e8..551a5d726897befeae1ef96198c6d90814e8d6d9 100644 (file)
@@ -140,7 +140,7 @@ public class ProbeEventInfo extends EventInfo implements IProbeEventInfo {
        } else {
            output.append("\n        offset: ");
            output.append(fOffset);
-           output.append("\n");
+           output.append('\n');
            output.append("        symbol: ");
            output.append(fSymbol);
        }
index 61e01936e51d42e5202f1413fecb3fa1a37a3c4a..1817c1e2676a4ac4a2db7deda684ef978074bf52 100644 (file)
@@ -177,7 +177,7 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
         //    Trace path: /home/user/lttng-traces/mysession-20120129-084256
         output.append("    Trace path: ");
         output.append(getSessionPath());
-        output.append("\n");
+        output.append('\n');
         
         for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) {
             IDomainInfo domain = (IDomainInfo) iterator.next();
index 2203c73aedca82b3ed740925550baa96ea163675..e8cffe2da5218c0ebee7783a628d3f0dc4827558 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
@@ -251,6 +252,33 @@ public class TraceSessionComponent extends TraceControlComponent {
         getControlService().stopSession(getName(), monitor);
     }
 
+    /**
+     * Enables channels with given names which are part of this domain. If a given channel 
+     * doesn't exists it creates a new channel with the given parameters (or default values 
+     * if given parameter is null). 
+     * @param channelNames - a list of channel names to enable on this domain
+     * @param info - channel information to set for the channel (use null for default)
+     * @param isKernel -  a flag for indicating kernel or UST.
+     * @throws ExecutionException
+     */
+    public void enableChannels(List<String> channelNames, IChannelInfo info, boolean isKernel) throws ExecutionException {
+        enableChannels(channelNames, info, isKernel, new NullProgressMonitor());
+    }
+
+    /**
+     * Enables channels with given names which are part of this domain. If a given channel 
+     * doesn't exists it creates a new channel with the given parameters (or default values 
+     * if given parameter is null). 
+     * @param channelNames - a list of channel names to enable on this domain
+     * @param info - channel information to set for the channel (use null for default)
+     * @param isKernel -  a flag for indicating kernel or UST.
+     * @param monitor - a progress monitor
+     * @throws ExecutionException
+     */
+    public void enableChannels(List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+        getControlService().enableChannels(getName(), channelNames, isKernel, info, monitor);
+    }
+    
     /**
      * Enables a list of events with no additional parameters.
      * @param eventNames - a list of event names to enabled.
index d33938eebaea3f437c29645fc62f75b7a2ac449c..75234ad07d2692261a64d038f90b6e9af5d3a5bc 100644 (file)
@@ -12,6 +12,7 @@
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.property;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
@@ -80,11 +81,11 @@ public class TraceProbeEventPropertySource extends TraceEventPropertySource {
     @Override
     public IPropertyDescriptor[] getPropertyDescriptors() {
         IPropertyDescriptor[] superProperties = super.getPropertyDescriptors();
-        List<IPropertyDescriptor> list = new ArrayList<IPropertyDescriptor>();
-        for (int i = 0; i < superProperties.length; i++) {
-            list.add(superProperties[i]);
-        }
-        
+
+        List<IPropertyDescriptor> superList = Arrays.asList(superProperties);
+        ArrayList<IPropertyDescriptor> list = new ArrayList<IPropertyDescriptor>();
+        list.addAll(superList);
+
         if (fEvent instanceof TraceProbeEventComponent) {
             TraceProbeEventComponent event = (TraceProbeEventComponent) fEvent;
             if (event.getAddress() != null) {
index 69aea44014d0dbcf0f97dce4ec2aeea6825bdfc3..ef08cae9d85be0207c87d179fd96042757209276 100644 (file)
@@ -100,6 +100,10 @@ public class LTTngControlService implements ILttngControlService {
     private final static String COMMAND_DISABLE_EVENT = CONTROL_COMMAND + " disable-event "; //$NON-NLS-1$
 
     // Command options constants 
+    /**
+     * Command line option for output path.
+     */
+    private final static String OPTION_OUTPUT_PATH = " -o "; //$NON-NLS-1$
     /**
      * Command line option for kernel tracer.
      */
@@ -358,8 +362,7 @@ public class LTTngControlService implements ILttngControlService {
         
         String command = COMMAND_LIST + sessionName;
         ICommandResult result = fCommandShell.executeCommand(command, monitor);
-        
-        
+
         if (isError(result)) {
             throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
         }
@@ -531,12 +534,16 @@ public class LTTngControlService implements ILttngControlService {
         String newName = formatParameter(sessionName);
         String newPath = formatParameter(sessionPath);
 
-        String command = COMMAND_CREATE_SESSION + newName;
+        StringBuffer command = new StringBuffer(); 
+        command.append(COMMAND_CREATE_SESSION);
+        command.append(newName);
+
         if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$
-            command += " -o " + newPath; //$NON-NLS-1$
+            command.append(OPTION_OUTPUT_PATH);
+            command.append(newPath);
         }
 
-        ICommandResult result = fCommandShell.executeCommand(command, monitor);
+        ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
         
         if (isError(result)) {
             throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
@@ -597,15 +604,12 @@ public class LTTngControlService implements ILttngControlService {
         ICommandResult result = fCommandShell.executeCommand(command, monitor);
         String[] output = result.getOutput();
         
-        if (isError(result)) {
-            // In case "session not found" treat it as success 
-            if ((output == null) || (!SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches())) {
+        if (isError(result) && ((output == null) || (!SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches()))) {
                 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
-            }
-        }
+       }
         //Session <sessionName> destroyed
     }
-
+    
     /*
      * (non-Javadoc)
      * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
@@ -651,7 +655,7 @@ public class LTTngControlService implements ILttngControlService {
     public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException {
 
         // no channels to enable
-        if (channelNames.size() == 0) {
+        if (channelNames.isEmpty()) {
             return;
         }
 
@@ -663,7 +667,7 @@ public class LTTngControlService implements ILttngControlService {
             String channel = (String) iterator.next();
             command.append(channel);
             if (iterator.hasNext()) {
-                command.append(","); //$NON-NLS-1$
+                command.append(',');
             }
         }
 
@@ -717,7 +721,7 @@ public class LTTngControlService implements ILttngControlService {
     public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
         
         // no channels to enable
-        if (channelNames.size() == 0) {
+        if (channelNames.isEmpty()) {
             return;
         }
 
@@ -729,7 +733,7 @@ public class LTTngControlService implements ILttngControlService {
             String channel = (String) iterator.next();
             command.append(channel);
             if (iterator.hasNext()) {
-                command.append(","); //$NON-NLS-1$
+                command.append(',');
             }
         }
 
@@ -760,7 +764,7 @@ public class LTTngControlService implements ILttngControlService {
         
         StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT);
 
-        if (eventNames == null || eventNames.size() == 0) {
+        if (eventNames == null || eventNames.isEmpty()) {
             command.append(OPTION_ALL);
         } else {
 
@@ -768,7 +772,7 @@ public class LTTngControlService implements ILttngControlService {
                 String event = (String) iterator.next();
                 command.append(event);
                 if (iterator.hasNext()) {
-                    command.append(","); //$NON-NLS-1$
+                    command.append(',');
                 }
             }
         }
@@ -912,7 +916,7 @@ public class LTTngControlService implements ILttngControlService {
             command.append(OPTION_ALL);
         } else {
             // no events to enable
-            if (eventNames.size() == 0) {
+            if (eventNames.isEmpty()) {
                 return;
             }
 
@@ -920,7 +924,7 @@ public class LTTngControlService implements ILttngControlService {
                 String event = (String) iterator.next();
                 command.append(event);
                 if (iterator.hasNext()) {
-                    command.append(","); //$NON-NLS-1$
+                    command.append(',');
                 }
             }
         }
@@ -1223,12 +1227,14 @@ public class LTTngControlService implements ILttngControlService {
      */
     private String formatParameter(String parameter) {
         if (parameter != null) {
-            String newString = String.valueOf(parameter);
+            StringBuffer newString = new StringBuffer();
+            newString.append(parameter);
 
             if (parameter.contains(" ")) { //$NON-NLS-1$
-                newString = "\"" + newString + "\""; //$NON-NLS-1$ //$NON-NLS-2$
+                newString.insert(0, "\""); //$NON-NLS-1$
+                newString.append("\""); //$NON-NLS-1$
             }
-            return newString;
+            return newString.toString();
         }
         return null;
     }
This page took 0.075079 seconds and 5 git commands to generate.