/*
 * Copyright (c) SSI Schaefer IT Solutions
 */
package com.wamas.ide.launchview;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.jface.action.Action;

import com.wamas.ide.launchview.model.LaunchObjectModel;

public class LaunchAction extends Action {

	private static final Map<String, String> COMMON_MODE_ICONS;
	
	static {
		COMMON_MODE_ICONS = new TreeMap<>();
		COMMON_MODE_ICONS.put("run", "icons/launch_run.gif");
		COMMON_MODE_ICONS.put("debug", "icons/debug_exc.gif");
		COMMON_MODE_ICONS.put("profile", "icons/profile_exc.gif");
	}
	
    private final Set<LaunchObjectModel> models;
    private final ILaunchMode mode;

    public LaunchAction(ILaunchMode mode, Set<LaunchObjectModel> models) {
        this.mode = mode;
        this.models = models;

        setText(mode.getLabel() + " selected");
        
        if(COMMON_MODE_ICONS.containsKey(mode.getIdentifier())) {
        	setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, COMMON_MODE_ICONS.get(mode.getIdentifier())));
        }
    }

    @Override
    public void run() {
        for (LaunchObjectModel m : models) {
            m.getObject().launch(mode);
        }
    }

}

@@ -78,16 +78,46 @@
 hview;%0A%0A
+import java.util.Collections;%0A
 import j
@@ -179,16 +179,104 @@
 eeMap;%0A%0A
+import org.eclipse.core.runtime.CoreException;%0Aimport org.eclipse.core.runtime.IStatus;%0A
 import o
@@ -453,17 +453,20 @@
 tion %7B%0A%0A
-%09
+    
 private 
@@ -521,11 +521,13 @@
 NS;%0A
-%09%0A%09
+%0A    
 stat
@@ -531,18 +531,24 @@
 tatic %7B%0A
-%09%09
+        
 COMMON_M
@@ -576,18 +576,24 @@
 ap%3C%3E();%0A
-%09%09
+        
 COMMON_M
@@ -630,34 +630,40 @@
 unch_run.gif%22);%0A
-%09%09
+        
 COMMON_MODE_ICON
@@ -705,10 +705,16 @@
 %22);%0A
-%09%09
+        
 COMM
@@ -772,12 +772,14 @@
 %22);%0A
-%09
+    
 %7D%0A
-%09
 %0A   
@@ -1041,24 +1041,16 @@
 cted%22);%0A
-        
 %0A       
@@ -1052,16 +1052,17 @@
       if
+ 
 (COMMON_
@@ -1121,9 +1121,12 @@
     
-%09
+    
 setI
@@ -1140,16 +1140,37 @@
 criptor(
+%0A                    
 Activato
@@ -1278,24 +1278,533 @@
    %7D%0A    %7D%0A%0A
+    @Override%0A    public boolean isEnabled() %7B%0A        return models.stream().allMatch((m) -%3E %7B%0A            if (m.getObject() == null) %7B%0A                return false;%0A            %7D%0A            try %7B%0A                return m.getObject().getType().getDelegates(Collections.singleton(mode.getIdentifier())).length %3E 0;%0A            %7D catch (CoreException e) %7B%0A                Activator.log(IStatus.WARNING, %22problem retreiving launch delegates%22, e);%0A                return false;%0A            %7D%0A        %7D);%0A    %7D%0A%0A
     @Overrid

fix enablement of actions