[337210] Need hook in RunOnServerAction to pass information to LaunchableAdapterDelegate extensions
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/actions/RunOnServerAction.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/actions/RunOnServerAction.java
index 5633299..e940092 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/actions/RunOnServerAction.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/actions/RunOnServerAction.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 2011 IBM Corporation and others.
  * 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
@@ -10,6 +10,8 @@
  *******************************************************************************/
 package org.eclipse.wst.server.ui.actions;
 
+import java.util.HashMap;
+
 import org.eclipse.debug.core.ILaunchManager;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.viewers.StructuredSelection;
@@ -30,6 +32,7 @@
 public class RunOnServerAction extends Action {
 	protected RunOnServerActionDelegate delegate;
 
+	protected HashMap<String,Object> actionProperties;
 	/**
 	 * Create a new Run on Server action for run mode.
 	 * 
@@ -38,6 +41,17 @@
 	public RunOnServerAction(Object object) {
 		this(object, ILaunchManager.RUN_MODE);
 	}
+	
+	/**
+	 * Create a new Run on Server action for run mode.
+	 * 
+	 * @param object the object to attempt to run
+	 */
+	public RunOnServerAction(Object object, HashMap<String,Object> actionProperties) {		
+		this(object, ILaunchManager.RUN_MODE);
+		this.actionProperties = actionProperties;
+		delegate.setActionProperties(actionProperties);
+	}
 
 	/**
 	 * Create a new Run on Server action.
@@ -48,6 +62,10 @@
 	public RunOnServerAction(Object object, String launchMode) {
 		super();
 		
+		if (actionProperties == null){
+			actionProperties = new HashMap<String, Object>();
+		}
+		
 		if (ILaunchManager.DEBUG_MODE.equals(launchMode)) {
 			setText(Messages.actionDebugOnServer);
 			setDisabledImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_DTOOL_DEBUG_ON_SERVER));
@@ -65,7 +83,7 @@
 			setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_ETOOL_RUN_ON_SERVER));
 		}
 		
-		delegate = new RunOnServerActionDelegate();
+		delegate = new RunOnServerActionDelegate(actionProperties);
 		delegate.setLaunchMode(launchMode);
 		if (object != null) {
 			StructuredSelection sel = new StructuredSelection(object);
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/actions/RunOnServerAction.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/actions/RunOnServerAction.java
index 67642d3..d516a92 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/actions/RunOnServerAction.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/actions/RunOnServerAction.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
  * 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
@@ -10,6 +10,8 @@
  *******************************************************************************/
 package org.eclipse.wst.server.ui.internal.actions;
 
+import java.util.HashMap;
+
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.wst.server.ui.internal.ImageResource;
@@ -23,6 +25,7 @@
 public class RunOnServerAction extends Action {
 	protected RunOnServerActionDelegate delegate;
 
+	protected HashMap<String,Object> map;
 	/**
 	 * Run on server action.
 	 * 
@@ -42,6 +45,11 @@
 		} else
 			delegate.selectionChanged(this, null);
 	}
+	
+	public RunOnServerAction(Object object, HashMap<String,Object> map){		
+		this(object);
+		delegate.setMap(map);
+	}
 
 	/**
 	 * Implementation of method defined on <code>IAction</code>.
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/actions/RunOnServerActionDelegate.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/actions/RunOnServerActionDelegate.java
index 5beb83c..c07ccec 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/actions/RunOnServerActionDelegate.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/actions/RunOnServerActionDelegate.java
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2003, 2010 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
  * 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
@@ -10,10 +10,7 @@
  **********************************************************************/
 package org.eclipse.wst.server.ui.internal.actions;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
@@ -28,6 +25,11 @@
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.window.Window;
 import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 import org.eclipse.wst.server.core.*;
 import org.eclipse.wst.server.core.internal.IClient;
 import org.eclipse.wst.server.core.internal.ILaunchableAdapter;
@@ -36,12 +38,7 @@
 import org.eclipse.wst.server.core.model.ModuleArtifactDelegate;
 import org.eclipse.wst.server.ui.internal.*;
 import org.eclipse.wst.server.ui.internal.viewers.ModuleArtifactComposite;
-import org.eclipse.wst.server.ui.internal.wizard.*;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.wst.server.ui.internal.wizard.RunOnServerWizard;
 /**
  * Support for starting/stopping server and clients for resources running on a server.
  */
@@ -49,6 +46,9 @@
 	protected static final String[] launchModes = {
 		ILaunchManager.RUN_MODE, ILaunchManager.DEBUG_MODE, ILaunchManager.PROFILE_MODE };
 
+	public static String ROS_CLIENT = "ros_client";
+	public static String ROS_LAUNCHABLE = "ros_launchable";
+	
 	protected Object selection;
 
 	protected IWorkbenchWindow window;
@@ -59,6 +59,8 @@
 	protected String launchMode = ILaunchManager.RUN_MODE;
 
 	protected boolean tasksAndClientShown;
+	
+	protected HashMap<String, Object> wiz_properties; 
 
 	protected ILaunchableAdapter launchableAdapter;
 	protected IClient client;
@@ -69,6 +71,17 @@
 	public RunOnServerActionDelegate() {
 		super();
 	}
+	
+	/**
+	 * RunOnServerActionDelegate constructor comment.
+	 */
+	public RunOnServerActionDelegate(HashMap<String, Object>properties) {
+		this.wiz_properties = properties;
+	}
+	
+	public void setActionProperties(HashMap<String,Object>properties){
+		this.wiz_properties = properties;
+	}
 
 	/**
 	 * Disposes this action delegate.  The implementor should unhook any references
@@ -114,7 +127,8 @@
 		if (server == null) {
 			// try the full wizard
 			Trace.trace(Trace.FINEST, "Launching wizard");
-			RunOnServerWizard wizard = new RunOnServerWizard(module, launchMode, moduleArtifact);
+			RunOnServerWizard wizard = new RunOnServerWizard(module, launchMode, moduleArtifact, wiz_properties);
+
 			WizardDialog dialog = new WizardDialog(shell, wizard);
 			if (dialog.open() == Window.CANCEL) {
 				if (monitor != null)
@@ -130,8 +144,10 @@
 			server = wizard.getServer();
 			boolean preferred = wizard.isPreferredServer();
 			tasksAndClientShown = true;
-			client = wizard.getSelectedClient();
-			launchableAdapter = wizard.getLaunchableAdapter();
+			if (client == null || launchableAdapter == null){
+				client = wizard.getSelectedClient();
+				launchableAdapter = wizard.getLaunchableAdapter();
+			}
 			
 			// set preferred server if requested
 			if (server != null && preferred) {
@@ -185,7 +201,7 @@
 			}
 		};
 		
-		// get a valid ModuleArtifact that we can use for launching
+		// If there is more than 1 moduleArtifact, get a valid ModuleArtifact that we can use for launching
 		// TODO The ModuleArtifactComposite should be part of the RunOnServerWizard
 		final IModuleArtifact moduleArtifact;
 		if (moduleArtifacts.length > 1) {
@@ -245,11 +261,13 @@
 		
 		if (!ServerUIPlugin.saveEditors())
 			return;
-		
+
 		tasksAndClientShown = false;
 		IServer server2 = null;
-		client = null;
-		launchableAdapter = null;
+		// initialize its value using the predefined value if one has been given
+		client = (IClient)getOverwriteValue(ROS_CLIENT);
+		launchableAdapter = (ILaunchableAdapter) getOverwriteValue(ROS_LAUNCHABLE);
+		
 		try {
 			IProgressMonitor monitor = new NullProgressMonitor();
 			server2 = getServer(module, moduleArtifact, monitor);
@@ -280,8 +298,9 @@
 		if (!ServerUIPlugin.promptIfDirty(shell, server))
 			return;
 		
+		// We need to check if the client and launchable were pre-populated
 		if (!tasksAndClientShown) {
-			RunOnServerWizard wizard = new RunOnServerWizard(server, launchMode, moduleArtifact);
+			RunOnServerWizard wizard = new RunOnServerWizard(server, launchMode, moduleArtifact, wiz_properties);
 			if (wizard.shouldAppear()) {
 				WizardDialog dialog = new WizardDialog(shell, wizard);
 				if (dialog.open() == Window.CANCEL)
@@ -814,4 +833,23 @@
 		}
 		return true;
 	}
+	
+	protected void setMap(HashMap<String,Object> map){
+		this.wiz_properties = map;
+	}
+	
+	/**
+	 * Returns the value from the hashmap provided in the constructor of this class
+	 *  
+	 * @param key  
+	 * @param obj the type of object to be returned
+	 * @return
+	 */
+	protected Object getOverwriteValue(String key){
+		if (wiz_properties != null){ 
+			Object o = wiz_properties.get(key);
+			return o;	
+		}
+		return null;
+	}
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/RunOnServerWizard.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/RunOnServerWizard.java
index 7801f41..c74e13f 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/RunOnServerWizard.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/RunOnServerWizard.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2007 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
  * 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
@@ -10,28 +10,43 @@
  *******************************************************************************/
 package org.eclipse.wst.server.ui.internal.wizard;
 
+import java.util.HashMap;
+
 import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.IModuleArtifact;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.TaskModel;
+import org.eclipse.wst.server.core.*;
 import org.eclipse.wst.server.core.internal.IClient;
 import org.eclipse.wst.server.core.internal.ILaunchableAdapter;
 import org.eclipse.wst.server.ui.internal.Messages;
+import org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate;
 import org.eclipse.wst.server.ui.internal.wizard.fragment.RunOnServerWizardFragment;
 /**
  * A wizard used for Run on Server.
  */
 public class RunOnServerWizard extends TaskWizard {
+	
 	/**
 	 * RunOnServerWizard constructor comment.
 	 * 
 	 * @param module a module
 	 * @param launchMode a launch mode
 	 * @param moduleArtifact a module artifact
+	 * 
+	 * @deprecated
 	 */
 	public RunOnServerWizard(IModule module, String launchMode, IModuleArtifact moduleArtifact) {
-		super(Messages.wizRunOnServerTitle, new RunOnServerWizardFragment(module, launchMode, moduleArtifact));
+		this(module, launchMode,moduleArtifact, null);
+	}
+	
+	/**
+	 * RunOnServerWizard constructor comment.
+	 * 
+	 * @param module a module
+	 * @param launchMode a launch mode
+	 * @param moduleArtifact a module artifact
+	 * @param properties a HashMap with the key/value pair that defines the behaviour of the wizard 
+	 */
+	public RunOnServerWizard(IModule module, String launchMode, IModuleArtifact moduleArtifact, HashMap properties) {
+		super(Messages.wizRunOnServerTitle, createRootWizard(module, launchMode, moduleArtifact, properties));
 		
 		setNeedsProgressMonitor(true);
 		if (ILaunchManager.DEBUG_MODE.equals(launchMode))
@@ -41,6 +56,25 @@
 		getTaskModel().putObject(TaskModel.TASK_LAUNCH_MODE, launchMode);
 	}
 
+	private static RunOnServerWizardFragment createRootWizard(IModule module, String launchMode, IModuleArtifact moduleArtifact, HashMap properties){
+		RunOnServerWizardFragment fragment = new RunOnServerWizardFragment(module, launchMode, moduleArtifact);
+		setFragmentProperties(fragment, properties);
+		return fragment;
+	}
+	
+	private static RunOnServerWizardFragment createRootWizard	(IServer server, String launchMode, IModuleArtifact moduleArtifact,HashMap properties) {
+		RunOnServerWizardFragment fragment = new RunOnServerWizardFragment(server, launchMode, moduleArtifact);
+		setFragmentProperties(fragment, properties);		
+		return fragment;
+	}
+	
+	private static void setFragmentProperties(RunOnServerWizardFragment fragment, HashMap properties){
+		if (properties != null){
+			fragment.setClient((IClient)properties.get(RunOnServerActionDelegate.ROS_CLIENT));
+			fragment.setLaunchable((ILaunchableAdapter)properties.get(RunOnServerActionDelegate.ROS_LAUNCHABLE));
+		}
+	}
+	
 	/**
 	 * RunOnServerWizard constructor comment.
 	 * 
@@ -48,8 +82,8 @@
 	 * @param launchMode a launch mode
 	 * @param moduleArtifact a module artifact
 	 */
-	public RunOnServerWizard(IServer server, String launchMode, IModuleArtifact moduleArtifact) {
-		super(Messages.wizRunOnServerTitle, new RunOnServerWizardFragment(server, launchMode, moduleArtifact));
+	public RunOnServerWizard(IServer server, String launchMode, IModuleArtifact moduleArtifact,HashMap properties) {
+		super(Messages.wizRunOnServerTitle, createRootWizard(server,launchMode,moduleArtifact, properties));
 		
 		setNeedsProgressMonitor(true);
 		if (ILaunchManager.DEBUG_MODE.equals(launchMode))
@@ -103,6 +137,14 @@
 	}
 
 	/**
+	 * Set the launchable adapter
+	 * @param launch
+	 */
+	public void setLaunchableAdapter(ILaunchableAdapter launch){
+		getTaskModel().putObject(WizardTaskUtil.TASK_LAUNCHABLE_ADAPTER, launch);
+	}
+	
+	/**
 	 * Return the launchable adapter.
 	 * 
 	 * @return the adapter
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/fragment/RunOnServerWizardFragment.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/fragment/RunOnServerWizardFragment.java
index b2fcf7a..11ea6c6 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/fragment/RunOnServerWizardFragment.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/fragment/RunOnServerWizardFragment.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 2011 IBM Corporation and others.
  * 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
@@ -15,6 +15,8 @@
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IModuleArtifact;
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.internal.IClient;
+import org.eclipse.wst.server.core.internal.ILaunchableAdapter;
 import org.eclipse.wst.server.ui.internal.wizard.WizardTaskUtil;
 import org.eclipse.wst.server.ui.wizard.WizardFragment;
 /**
@@ -24,6 +26,9 @@
 	protected IServer server;
 	protected IModule module;
 	protected IModuleArtifact moduleArtifact;
+	
+	protected IClient client;
+	protected ILaunchableAdapter launchable;
 
 	/**
 	 * Create the Run on Server wizard with all pages.
@@ -67,7 +72,16 @@
 		list.add(WizardTaskUtil.SaveServerFragment);
 		if (server == null)
 			list.add(WizardTaskUtil.SaveHostnameFragment);
-		
-		list.add(new OptionalClientWizardFragment(moduleArtifact));
+		if (client == null || launchable == null){
+			list.add(new OptionalClientWizardFragment(moduleArtifact));
+		}
+	}
+
+	public void setClient(IClient client) {
+		this.client = client;			
+	}
+
+	public void setLaunchable(ILaunchableAdapter launchable) {
+		this.launchable = launchable;	
 	}
 }
\ No newline at end of file