package cucumber.eclipse.launching;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.ILaunchShortcut2;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.pde.ui.launcher.AbstractLaunchShortcut;
import org.eclipse.ui.IEditorPart;

public class CucumberFeatureLaunchShortcut extends AbstractLaunchShortcut implements ILaunchShortcut2 {

	@Override
	public void launch(ISelection selection, String arg1) {
		// TODO Auto-generated method stub
		
	}

  	@Override
	public void launch(IEditorPart part, String mode) {
		launch(mode);
	}

	@Override
	public ILaunchConfiguration[] getLaunchConfigurations(ISelection arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ILaunchConfiguration[] getLaunchConfigurations(IEditorPart arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public IResource getLaunchableResource(ISelection arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public IResource getLaunchableResource(IEditorPart arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected String getLaunchConfigurationTypeName() {
		return CucumberFeatureLaunchConstants.CUCUMBER_FEATURE_LAUNCH_CONFIG_TYPE;
	}

	@Override
	protected void initializeConfiguration(ILaunchConfigurationWorkingCopy config) {
		IProject project = CucumberFeaureLaunchUtils.getProject();
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName());
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_FEATURE_PATH, CucumberFeaureLaunchUtils.getFeaturePath());
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_GLUE_PATH, CucumberFeatureLaunchConstants.DEFAULT_CLASSPATH);
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_IS_MONOCHROME, true);
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_IS_PRETTY, true);
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_IS_HTML, false);
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_IS_PROGRESS, false);
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_IS_JSON, false);
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_IS_JUNIT, false);
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_IS_RERUN, false);
		config.setAttribute(CucumberFeatureLaunchConstants.ATTR_IS_USAGE, false);
		
	}

	
	@Override
	protected boolean isGoodMatch(ILaunchConfiguration configuration) {
		// TODO Auto-generated method stub
		return false;
	}


}

@@ -167,24 +167,80 @@
 figuration;%0A
+import org.eclipse.debug.core.ILaunchConfigurationType;%0A
 import org.e
@@ -649,16 +649,62 @@
 cut2 %7B%0A%0A
+%09private String newLaunchConfigurationName;%0A%0A%0A
 %09@Overri
@@ -873,16 +873,66 @@
 mode) %7B%0A
+  %09%09newLaunchConfigurationName = part.getTitle();%0A
 %09%09launch
@@ -2728,16 +2728,206 @@
 );%0A%09%09%0A%09%7D
+%0A%09%0A%09@Override%0A%09protected String getName(ILaunchConfigurationType type) %7B%0A%09%09if(newLaunchConfigurationName != null) %7B%0A%09%09%09return newLaunchConfigurationName;%0A%09%09%7D%0A%09%09return super.getName(type);%0A%09%7D
 %0A%0A%09%0A%09@Ov

Set the title of the selected editorpart as launchconfiguration name.