Added some more JUnit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / handlers / CreateChannelOnSessionHandler.java
index fd0262f79672ed2abcdb81fe26619f3ebb46dd32..4becd61354e5481bd3111d98228a64f18fb02bb7 100644 (file)
@@ -15,7 +15,6 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -28,15 +27,12 @@ import org.eclipse.jface.window.Window;
 import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
 import org.eclipse.linuxtools.lttng.ui.views.control.ControlView;
 import org.eclipse.linuxtools.lttng.ui.views.control.Messages;
-import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.CreateChannelDialog;
 import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateChannelOnSessionDialog;
+import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.TraceControlDialogFactory;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceDomainComponent;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent;
 import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
 
 /**
  * <b><u>CreateChannelOnSessionHandler</u></b>
@@ -45,7 +41,7 @@ import org.eclipse.ui.PlatformUI;
  * (on session level).
  * </p>
  */
-public class CreateChannelOnSessionHandler extends AbstractHandler {
+public class CreateChannelOnSessionHandler extends BaseControlViewHandler {
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -65,52 +61,49 @@ public class CreateChannelOnSessionHandler extends AbstractHandler {
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
 
-        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        final ICreateChannelOnSessionDialog dialog =  TraceControlDialogFactory.getInstance().getCreateChannelOnSessionDialog();
 
-        if (window == null) {
-            return false;
+        if (dialog.open() != Window.OK) {
+            return null;
         }
 
-        final ICreateChannelOnSessionDialog dialog = new CreateChannelDialog(window.getShell());
-
-        if (dialog.open() == Window.OK) {
-            Job job = new Job(Messages.TraceControl_EnableChannelJob) {
-                @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$ 
+        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$
+                }
 
-                    if (errorString != null) {
-                        return new Status(Status.ERROR, LTTngUiPlugin.PLUGIN_ID, errorString);
+                // get session configuration in all cases
+                try {
+                    fSession.getConfigurationFromNode(monitor);
+                } catch (ExecutionException e) {
+                    if (errorString == null) {
+                        errorString = new String();
                     }
-                    return Status.OK_STATUS;
-                }};
-                job.setUser(true);
-                job.schedule();
-        }
+                    errorString += Messages.TraceControl_ListSessionFailure + ": " + e.toString();  //$NON-NLS-1$ 
+                } 
+
+                if (errorString != null) {
+                    return new Status(Status.ERROR, LTTngUiPlugin.PLUGIN_ID, errorString);
+                }
+                return Status.OK_STATUS;
+            }
+        };
+        job.setUser(true);
+        job.schedule();
 
         return null;
     }
@@ -121,24 +114,13 @@ public class CreateChannelOnSessionHandler extends AbstractHandler {
      */
     @Override
     public boolean isEnabled() {
-        fSession = null;
-
-        // Check if we are closing down
-        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null) {
-            return false;
-        }
-
-        // Check if we are in the Project View
-        IWorkbenchPage page = window.getActivePage();
+        // Get workbench page for the Control View
+        IWorkbenchPage page = getWorkbenchPage();
         if (page == null) {
             return false;
         }
 
-        IWorkbenchPart part = page.getActivePart();
-        if (!(part instanceof ControlView)) {
-            return false;
-        }
+        fSession = null;
 
         // Check if one session is selected
         ISelection selection = page.getSelection(ControlView.ID);
This page took 0.025976 seconds and 5 git commands to generate.