[481726] New server wizard calling setDefaults() entirely too often

Change-Id: I2ca92f63777810730170f2f7a8a16b48f1334443
diff --git a/plugins/org.eclipse.wst.server.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.server.core/META-INF/MANIFEST.MF
index 58c9c4c..5d0d47c 100644
--- a/plugins/org.eclipse.wst.server.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.server.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.wst.server.core; singleton:=true
-Bundle-Version: 1.8.100.qualifier
+Bundle-Version: 1.9.0.qualifier
 Bundle-Activator: org.eclipse.wst.server.core.internal.ServerPlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.wst.server.core/pom.xml b/plugins/org.eclipse.wst.server.core/pom.xml
index 7244b22..4bedb77 100644
--- a/plugins/org.eclipse.wst.server.core/pom.xml
+++ b/plugins/org.eclipse.wst.server.core/pom.xml
@@ -22,6 +22,6 @@
 

   <groupId>org.eclipse.webtools.servertools</groupId>

   <artifactId>org.eclipse.wst.server.core</artifactId>

-  <version>1.8.100-SNAPSHOT</version>

+  <version>1.9.0-SNAPSHOT</version>

   <packaging>eclipse-plugin</packaging>

 </project>

diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/ServerWorkingCopy.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/ServerWorkingCopy.java
index 92358d7..54e3184 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/ServerWorkingCopy.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/ServerWorkingCopy.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2015 IBM Corporation and others.
+ * Copyright (c) 2003, 2016 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
@@ -30,6 +30,7 @@
 import org.eclipse.wst.server.core.model.PublishOperation;
 import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
 import org.eclipse.wst.server.core.model.ServerDelegate;
+
 /**
  * 
  */
@@ -659,9 +660,9 @@
 	}
 
 	/**
-	 * Sets the defaults for this server, including the name. This method should be
-	 * called when creating a server, or when any major settings (e.g. runtime, host)
-	 * change.
+	 * Sets the defaults for this server, including the name. 
+	 * 
+	 * This method will only be called when creating a new server.
 	 * 
 	 * @param monitor a progress monitor, or null
 	 */
@@ -675,6 +676,27 @@
 			}
 		}
 	}
+	
+	/**
+	 * The new server's host or runtime has changed. 
+	 * 
+	 * This method allows delegates to reset the default values 
+	 * for the server in the context of the new runtime and host combination. 
+	 * 
+	 * This method should only be called when creating a new server.
+	 *  
+	 * @param monitor a progress monitor, or null
+	 */
+	public void newServerDetailsChanged(IProgressMonitor monitor) {
+		try {
+			getWorkingCopyDelegate(monitor).newServerDetailsChanged(monitor);
+		} catch (Exception e) {
+			if (Trace.SEVERE) {
+				Trace.trace(Trace.STRING_SEVERE, "Error calling delegate newServerDetailsChanged() " + toString(), e);
+			}
+		}
+	}
+	
 
 	public void renameFiles(IProgressMonitor monitor) throws CoreException {
 		if (getServerConfiguration() != null) {
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/model/ServerDelegate.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/model/ServerDelegate.java
index d34d417..93ddf91 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/model/ServerDelegate.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/model/ServerDelegate.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2010 IBM Corporation and others.
+ * Copyright (c) 2005, 2016 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
@@ -275,6 +275,21 @@
 	}
 	
 	/**
+	 * The new server's host or runtime has changed. 
+	 * 
+	 * This method allows subclasses to reset the default values 
+	 * for the server in the context of the new runtime and host combination. 
+	 * 
+	 * This method should only be called when creating a new server.
+	 * 
+	 * @param monitor a progress monitor, or null
+	 * @since 1.9
+	 */
+	public void newServerDetailsChanged(IProgressMonitor monitor) {
+		setDefaults(monitor);
+	}
+	
+	/**
 	 * Sets the value of the specified integer-valued attribute of this
 	 * element.
 	 * 
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/page/NewManualServerComposite.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/page/NewManualServerComposite.java
index 0e24fb3..7389116 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/page/NewManualServerComposite.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/page/NewManualServerComposite.java
@@ -491,7 +491,7 @@
 		server = cache.getCachedServer(serverType, isLocalhost);
 		if (server != null) {
 			server.setHost(host);
-			((ServerWorkingCopy)server).setDefaults(null);
+			((ServerWorkingCopy)server).newServerDetailsChanged(null);
 			runtime = server.getRuntime();
 			listener.runtimeSelected(runtime);
 			fireServerWorkingCopyChanged();
@@ -654,7 +654,7 @@
 		runtime = runtime2;
 		if (server != null) {
 			server.setRuntime(runtime);
-			((ServerWorkingCopy)server).setDefaults(null);
+			((ServerWorkingCopy)server).newServerDetailsChanged(null);
 			if (!serverNameModified) {
 				updatingServerName = true;
 				serverName.setText(server.getName());