Bug 427841 - Project Deployment: add deploymentType
diff --git a/bundles/org.eclipse.orion.client.cf/web/cfui/plugins/cFDeployPlugin.html b/bundles/org.eclipse.orion.client.cf/web/cfui/plugins/cFDeployPlugin.html
index 128e44b..14e007a 100644
--- a/bundles/org.eclipse.orion.client.cf/web/cfui/plugins/cFDeployPlugin.html
+++ b/bundles/org.eclipse.orion.client.cf/web/cfui/plugins/cFDeployPlugin.html
@@ -33,6 +33,7 @@
 				{
 					name: "Deploy to Cloud Foundry",
 					id: "org.eclipse.orion.client.cf.deploy",
+					deployTypes: ["Cloud Foundry"],
 					tooltip: "Deploy application in cloud.",
 					validationProperties: [{source: "NoShow" }]
 				});
diff --git a/bundles/org.eclipse.orion.client.cf/web/cfui/plugins/cFDeployService.js b/bundles/org.eclipse.orion.client.cf/web/cfui/plugins/cFDeployService.js
index e5ddfe1..acf7cb6 100644
--- a/bundles/org.eclipse.orion.client.cf/web/cfui/plugins/cFDeployService.js
+++ b/bundles/org.eclipse.orion.client.cf/web/cfui/plugins/cFDeployService.js
@@ -197,6 +197,7 @@
 									},
 									Url: "http://" + result.Route.entity.host + "." + result.Domain,
 									UrlTitle: result.App.entity.name,
+									Type: "Cloud Foundry",
 									ManageUrl: result.ManageUrl,
 									Path: appPath
 								}
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/projectClient.js b/bundles/org.eclipse.orion.client.core/web/orion/projectClient.js
index 0089178..12c805e 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/projectClient.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/projectClient.js
@@ -377,12 +377,23 @@
 		return types;
 	},
 	
-	getProjectDelpoyService: function(type){
+	getProjectDelpoyService: function(serviceId, type){
 		for(var i=0; i<this.allProjectDeployReferences.length; i++){
-			if(this.allProjectDeployReferences[i].getProperty("id") === type){
+			if(this.allProjectDeployReferences[i].getProperty("id") === serviceId){
 				return this._getProjectDeployService(this.allProjectDeployReferences[i]);
 			}
 		}
+		if(type){
+			for(var i=0; i<this.allProjectDeployReferences.length; i++){
+				var deployTypes = this.allProjectDeployReferences[i].getProperty("deployTypes");
+				if(!deployTypes){
+					continue;
+				}
+				if(deployTypes.some(function(typeFromService){return type === typeFromService;})){
+					return this._getProjectDeployService(this.allProjectDeployReferences[i]);
+				}
+			}
+		}
 	},
 	
 	_getProjectHandlerService: function(serviceReference){
@@ -509,7 +520,7 @@
 		return deferred;
 	},
 	
-	saveProjectLaunchConfiguration: function(projectMetadata, configurationName, serviceId, params, url, manageUrl, path, urlTitle){
+	saveProjectLaunchConfiguration: function(projectMetadata, configurationName, serviceId, params, url, manageUrl, path, urlTitle, deployType){
 		var deferred = new Deferred();
 		var configurationFile = configurationName;
 		configurationFile = configurationFile.replace(/\ /g,' ');
@@ -528,6 +539,9 @@
 		if(urlTitle){
 			launchConfigurationEnry.UrlTitle= urlTitle;
 		}
+		if(deployType){
+			launchConfigurationEnry.Type = deployType;
+		}
 		this._getLaunchConfigurationsDir(projectMetadata, true).then(function(launchConfDir){
 			if(launchConfDir.Children){
 				for(var i=0; i<launchConfDir.Children.length; i++){
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/projectCommands.js b/bundles/org.eclipse.orion.client.ui/web/orion/projectCommands.js
index d799a57..9c5c342 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/projectCommands.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/projectCommands.js
@@ -89,7 +89,7 @@
 		progress.setProgressResult(status);
 		
 		if(status.ToSave){
-			progress.showWhile(context.projectClient.saveProjectLaunchConfiguration(context.project, status.ToSave.ConfigurationName, context.deployService.id, status.ToSave.Parameters, status.ToSave.Url, status.ToSave.ManageUrl, status.ToSave.Path, status.ToSave.UrlTitle), "Saving configuration").then(
+			progress.showWhile(context.projectClient.saveProjectLaunchConfiguration(context.project, status.ToSave.ConfigurationName, context.deployService.id, status.ToSave.Parameters, status.ToSave.Url, status.ToSave.ManageUrl, status.ToSave.Path, status.ToSave.UrlTitle, status.ToSave.Type), "Saving configuration").then(
 				function(configuration){
 					storeLastDeployment(context.project, context.deployService, configuration);
 					if(sharedLaunchConfigurationDispatcher){
@@ -161,7 +161,7 @@
 			}
 			
 			if(result.ToSave){
-				progress.showWhile(context.projectClient.saveProjectLaunchConfiguration(context.project, result.ToSave.ConfigurationName, context.deployService.id, result.ToSave.Parameters, result.ToSave.Url, result.ToSave.ManageUrl, result.ToSave.Path, result.ToSave.UrlTitle), "Saving configuration").then(
+				progress.showWhile(context.projectClient.saveProjectLaunchConfiguration(context.project, result.ToSave.ConfigurationName, context.deployService.id, result.ToSave.Parameters, result.ToSave.Url, result.ToSave.ManageUrl, result.ToSave.Path, result.ToSave.UrlTitle, result.ToSave.Type), "Saving configuration").then(
 					function(configuration){
 						storeLastDeployment(context.project.Name, context.deployService, configuration);
 						if(sharedLaunchConfigurationDispatcher){
@@ -258,7 +258,7 @@
 					var launchConfToPass = objects.clone(launchConfiguration);
 					launchConfToPass.Params = params;
 					
-					projectClient.getProjectDelpoyService(launchConfiguration.ServiceId).then(function(service){
+					projectClient.getProjectDelpoyService(launchConfiguration.ServiceId, launchConfiguration.Type).then(function(service){
 						if(service && service.deploy){
 							fileClient.loadWorkspace(item.Project.ContentLocation).then(function(projectFolder){
 								runDeploy(launchConfToPass, {project: treeRoot.Project, deployService: service, data: data, errorHandler: errorHandler, projectClient: projectClient, commandService: commandService, launchConfiguration: launchConfiguration});
@@ -368,7 +368,7 @@
 					return;
 				}
 				
-				projectClient.getProjectDelpoyService(item.ServiceId).then(function(service){
+				projectClient.getProjectDelpoyService(item.ServiceId, item.Type).then(function(service){
 					if(sharedLaunchConfigurationDispatcher){
 						item.status = {State: "PROGRESS"};
 						sharedLaunchConfigurationDispatcher.dispatchEvent({type: "changeState", newValue: item });
@@ -436,7 +436,7 @@
 						return;
 					}
 					
-					projectClient.getProjectDelpoyService(item.ServiceId).then(function(service){
+					projectClient.getProjectDelpoyService(item.ServiceId, item.Type).then(function(service){
 						if(service && (start ? service.start : service.stop)){
 							if(sharedLaunchConfigurationDispatcher){
 								item.status = {State: "PROGRESS"};
@@ -448,7 +448,7 @@
 									sharedLaunchConfigurationDispatcher.dispatchEvent({type: "changeState", newValue: item });
 								}
 								if(result.ToSave){
-									progress.showWhile(projectClient.saveProjectLaunchConfiguration(item.project, result.ToSave.ConfigurationName, service.id, result.ToSave.Parameters, result.ToSave.Url, result.ToSave.ManageUrl, result.ToSave.Path, result.ToSave.UrlTitle), "Saving configuration").then(
+									progress.showWhile(projectClient.saveProjectLaunchConfiguration(item.project, result.ToSave.ConfigurationName, service.id, result.ToSave.Parameters, result.ToSave.Url, result.ToSave.ManageUrl, result.ToSave.Path, result.ToSave.UrlTitle, result.ToSave.Type), "Saving configuration").then(
 										function(configuration){
 											storeLastDeployment(item.project.Name, service, configuration);
 											if(sharedLaunchConfigurationDispatcher){
@@ -524,7 +524,7 @@
 				var launchConfToPass = objects.clone(item);
 				launchConfToPass.Params = params;
 				
-				projectClient.getProjectDelpoyService(item.ServiceId).then(function(service){
+				projectClient.getProjectDelpoyService(item.ServiceId, item.Type).then(function(service){
 					if(service && service.deploy){
 						fileClient.loadWorkspace(item.project.ContentLocation).then(function(projectFolder){
 							runDeploy(launchConfToPass, {project: item.project, deployService: service, data: data, errorHandler: errorHandler, projectClient: projectClient, commandService: commandService, launchConfiguration: item});
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/projects/projectEditor.js b/bundles/org.eclipse.orion.client.ui/web/orion/projects/projectEditor.js
index 4ed3c02..bf8a22d 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/projects/projectEditor.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/projects/projectEditor.js
@@ -351,7 +351,7 @@
 		if(col_no===2){
 			var td = document.createElement("td");
 			if(item.ServiceId){
-				this.projectClient.getProjectDelpoyService(item.ServiceId).then(function(service){
+				this.projectClient.getProjectDelpoyService(item.ServiceId, item.Type).then(function(service){
 					if(!service){
 						return;
 					}
@@ -430,7 +430,7 @@
 				}
 			}
 			if(item.ServiceId){
-				this.projectClient.getProjectDelpoyService(item.ServiceId).then(function(service){
+				this.projectClient.getProjectDelpoyService(item.ServiceId, item.Type).then(function(service){
 					if(service && service.getState){
 						item.status = {State: "PROGRESS"};
 						td.innerHTML = this.getCellElement(col_no, item, tableRow).innerHTML;