[107722] Redo UI for user settable runtime base location for the server.
diff --git a/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/Messages.java b/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/Messages.java
index 72805ce..2c7fd41 100644
--- a/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/Messages.java
+++ b/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/Messages.java
@@ -57,6 +57,9 @@
 	public static String serverEditorLocationsDescription2;
 	public static String serverEditorGeneralSection;
 	public static String serverEditorGeneralDescription;
+	public static String serverEditorServerDirMetadata;
+	public static String serverEditorServerDirInstall;
+	public static String serverEditorServerDirCustom;
 	public static String serverEditorSetInternalServerDirLink;
 	public static String serverEditorSetInternalServerDirLink2;
 	public static String serverEditorSetInstallServerDirLink;
@@ -70,9 +73,13 @@
 	public static String serverEditorSecure;
 	public static String serverEditorDebugMode;
 	public static String serverEditorNotSupported;
+	public static String serverEditorDoesNotModify;
+	public static String serverEditorTakesControl;
 	public static String errorNoPublishServerMustBeStopped;
 	public static String errorServerDirIsRoot;
 	public static String errorServerDirUnderRoot;
+	public static String errorServerDirCustomNotMetadata;
+	public static String errorServerDirCustomNotInstall;
 	public static String errorDeployDirNotSpecified;
 	public static String serverEditorBrowseServerMessage;
 	public static String serverEditorBrowseDeployMessage;
diff --git a/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/Messages.properties b/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/Messages.properties
index 69d3219..4a3a954 100644
--- a/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/Messages.properties
+++ b/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/Messages.properties
@@ -72,8 +72,8 @@
 
 # --- Server Editor ---
 serverEditorLocationsSection=Server Locations
-serverEditorLocationsDescription=Specify the server and deploy paths. Relative server paths are relative to the workspace. Relative deploy paths are relative to the server path. These settings can be changed only when the server is synchronized with no modules present, or has never been published. 
-serverEditorLocationsDescription2=Specify the server path (i.e. catalina.base) and deploy path. Relative server paths are relative to the workspace. Relative deploy paths are relative to the server path. These settings can be changed only when the server is synchronized with no modules present, or has never been published. 
+serverEditorLocationsDescription=Specify the server and deploy paths. Server must be published with no modules present to make changes.
+serverEditorLocationsDescription2=Specify the server path (i.e. catalina.base) and deploy path. Server must be published with no modules present to make changes.
 serverEditorGeneralSection=Server Options
 serverEditorGeneralDescription=Enter settings for the server.
 
@@ -86,16 +86,28 @@
 serverEditorSetDefaultDeployDirLink2=Set deploy path to the default value (currently set)
 
 # Fields
+# Note: The argument for the following two strings will be the string for
+#       one of serverEditorDoesNotModify or serverEditorTakesControl or and empty string.
+serverEditorServerDirMetadata=Use workspace metadata {0}
+serverEditorServerDirInstall=Use Tomcat installation {0}
+serverEditorServerDirCustom=Use custom location {0}
 serverEditorServerDir=Server path:
 serverEditorDeployDir=Deploy path:
 serverEditorSecure=Enable security
 serverEditorDebugMode=Enable Tomcat debug mode (v4.x and above only)
 serverEditorTestEnvironment=Run modules directly from the workspace (do not modify the Tomcat installation)
+# Note: The argument for the following string will be the serverEditorNotSupported string or an empty string
 serverEditorNoPublish=Serve modules without publishing {0}
 errorServerDirIsRoot=The server path may not be set to the the root of your workspace.
-errorServerDirUnderRoot=The server path may not be under the \"{0}\" folder of your workspace unless it is the internally supplied path.
+errorServerDirUnderRoot=The server path may not be under the \"{0}\" folder of your workspace unless it is the workspace metadata location.
+# Note: The argument for the following string will be the string for serverEditorServerDirMetadata with a blank string for its argument
+errorServerDirCustomNotMetadata=Only the \"{0}\" selection may set the server path to the workspace metadata location.
+# Note: The argument for the following string will be the string for serverEditorServerDirInstall with a blank string for its argument
+errorServerDirCustomNotInstall=Only the \"{0}\" selection may set the server path to the Tomcat installation.
 errorDeployDirNotSpecified=A deploy path must be specified.
-serverEditorNotSupported= (not supported by this Tomcat version)
+serverEditorNotSupported=(not supported by this Tomcat version)
+serverEditorDoesNotModify=(does not modify Tomcat installation)
+serverEditorTakesControl=(takes control of Tomcat installation)
 errorNoPublishServerMustBeStopped=The server must be stopped before a change to the \"{0}\" setting can be saved.
 
 # Browse for Server dialog
diff --git a/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/editor/ServerLocationEditorSection.java b/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/editor/ServerLocationEditorSection.java
index d1f5705..3f051a2 100644
--- a/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/editor/ServerLocationEditorSection.java
+++ b/plugins/org.eclipse.jst.server.tomcat.ui/tomcatui/org/eclipse/jst/server/tomcat/ui/internal/editor/ServerLocationEditorSection.java
@@ -64,14 +64,14 @@
 	protected Section section;
 	protected TomcatServer tomcatServer;
 
-	protected Hyperlink setInternalServerDir;
-	protected Hyperlink setRuntimeServerDir;
 	protected Hyperlink setDefaultDeployDir;
 	
-	protected boolean internalServerDirIsSet;
-	protected boolean installServerDirIsSet;
 	protected boolean defaultDeployDirIsSet;
 	
+	protected Button serverDirMetadata;
+	protected Button serverDirInstall;
+	protected Button serverDirCustom;
+	
 	protected Text serverDir;
 	protected Button serverDirBrowse;
 	protected Text deployDir;
@@ -85,6 +85,7 @@
 	
 	protected boolean allowRestrictedEditing;
 	protected IPath tempDirPath;
+	protected IPath installDirPath;
 
 	// Avoid hardcoding this at some point
 	private final static String METADATADIR = ".metadata";
@@ -106,6 +107,7 @@
 				updating = true;
 				if (ITomcatServer.PROPERTY_INSTANCE_DIR.equals(event.getPropertyName())
 						|| ITomcatServer.PROPERTY_TEST_ENVIRONMENT.equals(event.getPropertyName())) {
+					updateServerDirButtons();
 					updateServerDirFields();
 					validate();
 				}
@@ -130,14 +132,19 @@
 					// Update the state of the fields
 					PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
 						public void run() {
-							if (!ServerLocationEditorSection.this.setInternalServerDir.isDisposed())
-								ServerLocationEditorSection.this.setInternalServerDir.setEnabled(allowRestrictedEditing);
-							if (!ServerLocationEditorSection.this.setRuntimeServerDir.isDisposed())
-								ServerLocationEditorSection.this.setRuntimeServerDir.setEnabled(allowRestrictedEditing);
+							boolean customServerDir = false;
+							if (!ServerLocationEditorSection.this.serverDirCustom.isDisposed())
+								customServerDir = ServerLocationEditorSection.this.serverDirCustom.getSelection();
+							if (!ServerLocationEditorSection.this.serverDirMetadata.isDisposed())
+								ServerLocationEditorSection.this.serverDirMetadata.setEnabled(allowRestrictedEditing);
+							if (!ServerLocationEditorSection.this.serverDirInstall.isDisposed())
+								ServerLocationEditorSection.this.serverDirInstall.setEnabled(allowRestrictedEditing);
+							if (!ServerLocationEditorSection.this.serverDirCustom.isDisposed())
+								ServerLocationEditorSection.this.serverDirCustom.setEnabled(allowRestrictedEditing);
 							if (!ServerLocationEditorSection.this.serverDir.isDisposed())
-								ServerLocationEditorSection.this.serverDir.setEnabled(allowRestrictedEditing);
+								ServerLocationEditorSection.this.serverDir.setEnabled(allowRestrictedEditing && customServerDir);
 							if (!ServerLocationEditorSection.this.serverDirBrowse.isDisposed())
-								ServerLocationEditorSection.this.serverDirBrowse.setEnabled(allowRestrictedEditing);
+								ServerLocationEditorSection.this.serverDirBrowse.setEnabled(allowRestrictedEditing && customServerDir);
 							if (!ServerLocationEditorSection.this.setDefaultDeployDir.isDisposed())
 								ServerLocationEditorSection.this.setDefaultDeployDir.setEnabled(allowRestrictedEditing);
 							if (!ServerLocationEditorSection.this.deployDir.isDisposed())
@@ -182,11 +189,15 @@
 		toolkit.paintBordersFor(composite);
 		section.setClient(composite);
 
-		// server directory links
-		setInternalServerDir = toolkit.createHyperlink(composite,
-				NLS.bind(Messages.serverEditorSetInternalServerDirLink, ""), SWT.WRAP);
-		setInternalServerDir.addHyperlinkListener(new HyperlinkAdapter() {
-			public void linkActivated(HyperlinkEvent e) {
+		serverDirMetadata = toolkit.createButton(composite,
+				NLS.bind(Messages.serverEditorServerDirMetadata, Messages.serverEditorDoesNotModify), SWT.RADIO);
+		GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
+		data.horizontalSpan = 3;
+		serverDirMetadata.setLayoutData(data);
+		serverDirMetadata.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				if (updating || !serverDirMetadata.getSelection())
+					return;
 				updating = true;
 				execute(new SetTestEnvironmentCommand(tomcatServer, true));
 				updateServerDirFields();
@@ -194,14 +205,16 @@
 				validate();
 			}
 		});
-		GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
-		data.horizontalSpan = 3;
-		setInternalServerDir.setLayoutData(data);
 
-		setRuntimeServerDir = toolkit.createHyperlink(composite,
-				NLS.bind(Messages.serverEditorSetInstallServerDirLink, ""), SWT.WRAP);
-		setRuntimeServerDir.addHyperlinkListener(new HyperlinkAdapter() {
-			public void linkActivated(HyperlinkEvent e) {
+		serverDirInstall = toolkit.createButton(composite,
+				NLS.bind(Messages.serverEditorServerDirInstall, Messages.serverEditorTakesControl), SWT.RADIO);
+		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
+		data.horizontalSpan = 3;
+		serverDirInstall.setLayoutData(data);
+		serverDirInstall.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				if (updating || !serverDirInstall.getSelection())
+					return;
 				updating = true;
 				execute(new SetTestEnvironmentCommand(tomcatServer, false));
 				updateServerDirFields();
@@ -209,10 +222,24 @@
 				validate();
 			}
 		});
+
+		serverDirCustom = toolkit.createButton(composite,
+				NLS.bind(Messages.serverEditorServerDirCustom, Messages.serverEditorDoesNotModify), SWT.RADIO);
 		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
 		data.horizontalSpan = 3;
-		setRuntimeServerDir.setLayoutData(data);
-		
+		serverDirCustom.setLayoutData(data);
+		serverDirCustom.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				if (updating || !serverDirCustom.getSelection())
+					return;
+				updating = true;
+				execute(new SetTestEnvironmentCommand(tomcatServer, true));
+				updateServerDirFields();
+				updating = false;
+				validate();
+			}
+		});
+
 		// server directory
 		Label label = createLabel(toolkit, composite, Messages.serverEditorServerDir);
 		data = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
@@ -249,6 +276,7 @@
 						selectedDirectory = path.toOSString();
 					}
 					execute(new SetInstanceDirectoryCommand(tomcatServer, selectedDirectory));
+					updateServerDirButtons();
 					updateServerDirFields();
 					updating = false;
 					validate();
@@ -362,7 +390,8 @@
 		// If not Tomcat 3.2, update description to mention catalina.base
 		if (runtime != null && runtime.getRuntimeType().getId().indexOf("32") < 0)
 			section.setDescription(Messages.serverEditorLocationsDescription2);
-		
+		installDirPath = runtime.getLocation();
+
 		// determine if editing of locations is allowed
 		allowRestrictedEditing = false;
 		IPath basePath = tomcatServer.getRuntimeBaseDirectory();
@@ -375,14 +404,14 @@
 				allowRestrictedEditing = true;
 			}
 		}
-
+		
 		// Update server related fields
+		updateServerDirButtons();
 		updateServerDirFields();
 
-		setInternalServerDir.setEnabled(allowRestrictedEditing);
-		setRuntimeServerDir.setEnabled(allowRestrictedEditing);
-		serverDir.setEnabled(allowRestrictedEditing);
-		serverDirBrowse.setEnabled(allowRestrictedEditing);
+		serverDirMetadata.setEnabled(allowRestrictedEditing);
+		serverDirInstall.setEnabled(allowRestrictedEditing);
+		serverDirCustom.setEnabled(allowRestrictedEditing);
 
 		// Update deployment related fields
 		updateDefaultDeployLink();
@@ -415,32 +444,34 @@
 		return dir;
 	}
 	
-	protected void updateServerDirFields() {
-		updateServerDir();
-		updateInternalServerDirLink();
-		updateInstallServerDirLink();
+	protected void updateServerDirButtons() {
+		if (tomcatServer.getInstanceDirectory() == null) {
+			IPath path = tomcatServer.getRuntimeBaseDirectory();
+			if (path.equals(installDirPath)) {
+				serverDirInstall.setSelection(true);
+				serverDirMetadata.setSelection(false);
+				serverDirCustom.setSelection(false);
+			}
+			else {
+				serverDirMetadata.setSelection(true);
+				serverDirInstall.setSelection(false);
+				serverDirCustom.setSelection(false);
+			}
+		}
+		else {
+			serverDirCustom.setSelection(true);
+			serverDirMetadata.setSelection(false);
+			serverDirInstall.setSelection(false);
+		}
 	}
 	
-	protected void updateInternalServerDirLink() {
-		boolean newState = tomcatServer.isTestEnvironment() && tomcatServer.getInstanceDirectory() == null;
-		if (newState != internalServerDirIsSet) {
-			setInternalServerDir.setText(
-					newState ? Messages.serverEditorSetInternalServerDirLink2
-							: Messages.serverEditorSetInternalServerDirLink);
-			internalServerDirIsSet = newState;
-		}
+	protected void updateServerDirFields() {
+		updateServerDir();
+		boolean customServerDir = serverDirCustom.getSelection();
+		serverDir.setEnabled(allowRestrictedEditing && customServerDir);
+		serverDirBrowse.setEnabled(allowRestrictedEditing && customServerDir);
 	}
-
-	protected void updateInstallServerDirLink() {
-		boolean newState = !tomcatServer.isTestEnvironment();
-		if (newState != installServerDirIsSet) {
-			setRuntimeServerDir.setText(
-					newState ? Messages.serverEditorSetInstallServerDirLink2
-							: Messages.serverEditorSetInstallServerDirLink);
-			installServerDirIsSet = newState;
-		}
-	}
-
+	
 	protected void updateServerDir() {
 		IPath path = tomcatServer.getRuntimeBaseDirectory();
 		if (workspacePath.isPrefixOf(path)) {
@@ -490,6 +521,21 @@
 								new Status(IStatus.ERROR, TomcatUIPlugin.PLUGIN_ID, NLS.bind(Messages.errorServerDirUnderRoot, METADATADIR))};
 					}
 				}
+				else if (installDirPath.equals(path))
+					return new IStatus [] {
+						new Status(IStatus.ERROR, TomcatUIPlugin.PLUGIN_ID,
+								NLS.bind(Messages.errorServerDirCustomNotInstall,
+										NLS.bind(Messages.serverEditorServerDirInstall, "").trim()))};
+			}
+			else {
+				IPath path = tomcatServer.getRuntimeBaseDirectory();
+				// If non-custom instance dir is not the install and metadata isn't the selection, return error
+				if (!path.equals(installDirPath) && !serverDirMetadata.getSelection()) {
+					return new IStatus [] {
+							new Status(IStatus.ERROR, TomcatUIPlugin.PLUGIN_ID,
+									NLS.bind(Messages.errorServerDirCustomNotMetadata, 
+											NLS.bind(Messages.serverEditorServerDirMetadata, "").trim()))};
+				}
 			}
 
 			// Check the deployment directory
@@ -524,6 +570,19 @@
 						return;
 					}
 				}
+				else if (installDirPath.equals(path)) {
+					setErrorMessage(NLS.bind(Messages.errorServerDirCustomNotInstall,
+							NLS.bind(Messages.serverEditorServerDirInstall, "").trim()));
+					return;
+				}
+			}
+			else {
+				IPath path = tomcatServer.getRuntimeBaseDirectory();
+				// If non-custom instance dir is not the install and metadata isn't the selection, return error
+				if (!path.equals(installDirPath) && !serverDirMetadata.getSelection()) {
+					setErrorMessage(NLS.bind(Messages.errorServerDirCustomNotMetadata, 
+							NLS.bind(Messages.serverEditorServerDirMetadata, "").trim()));
+				}
 			}
 
 			// Check the deployment directory