package com.codeaffine.extras.ide.internal.launch;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;


public class LaunchHandler extends AbstractHandler {

  public static final String COMMAND_ID = "com.codeaffine.extras.ide.internal.LaunchCommand";

  @Override
  public Object execute( ExecutionEvent event ) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveWorkbenchWindow( event ).getShell();
    LaunchSelectionDialog dialog = new LaunchSelectionDialog( shell );
    if( dialog.open() == Window.OK ) {
      Object[] selectedElements = dialog.getResult();
      for( Object selectedElement : selectedElements ) {
        ILaunchConfiguration launchConfig = ( ILaunchConfiguration )selectedElement;
        DebugUITools.launch( launchConfig, dialog.getLaunchModeId() );
      }
    }
    return null;
  }
}

@@ -652,16 +652,297 @@
 ption %7B%0A
+    LaunchSelectionDialog dialog = createDialog( event );%0A    if( dialog.open() == Window.OK ) %7B%0A      launchSelectedElements( dialog.getLaunchModeId(), dialog.getResult() );%0A    %7D%0A    return null;%0A  %7D%0A%0A  private static LaunchSelectionDialog createDialog( ExecutionEvent event ) %7B%0A
     Shel
@@ -1017,38 +1017,14 @@
     
-LaunchSelectionDialog dialog =
+return
  new
@@ -1062,50 +1062,77 @@
 ;%0A  
-  if( dialog.open() == Window.OK ) %7B%0A     
+%7D%0A%0A  private static void launchSelectedElements( String launchModeId,
  Obj
@@ -1158,36 +1158,16 @@
 nts 
-= dialog.getResult();%0A 
+) %7B%0A
     
- 
 for(
@@ -1209,26 +1209,24 @@
 lements ) %7B%0A
-  
       ILaunc
@@ -1302,18 +1302,16 @@
 ;%0A      
- 
- 
 DebugUIT
@@ -1337,27 +1337,17 @@
 Config, 
-dialog.getL
+l
 aunchMod
@@ -1349,26 +1349,24 @@
 chModeId
-()
  );%0A    
   %7D%0A    
@@ -1361,34 +1361,9 @@
     
- 
- %7D%0A    %7D%0A    return null;
+%7D
 %0A  %7D

Refactor LaunchHandler