Bug 45450 - Rework the presentation of the Ant classpath
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
index 1260b38..6c5ddc6 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
@@ -211,4 +211,8 @@
 			model= new ClasspathModel(classpathString, customAntHome);
 		}
 	}
+	
+	protected ClasspathModel getClasspathModel() {
+		return model;
+	}
 }
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
index 89d463e..64c0c21 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
@@ -28,6 +28,7 @@
 import org.eclipse.ant.internal.ui.model.IAntUIConstants;
 import org.eclipse.ant.internal.ui.model.IAntUIHelpContextIds;
 import org.eclipse.ant.internal.ui.model.IAntUIPreferenceConstants;
+import org.eclipse.ant.internal.ui.preferences.ClasspathModel;
 import org.eclipse.ant.internal.ui.preferences.MessageDialogWithToggle;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.ILibrary;
@@ -165,8 +166,7 @@
 	
 	/**
 	 * Updates the classpath for this Ant build based on the selected JRE.
-	 * If running in the same VM as Eclipse, the appropriate tools.jar is added and 
-	 * the Xerces JARs are removed.
+	 * If running in the same VM as Eclipse, the appropriate tools.jar is added if not already present.
 	 * If running in the separate VM from Eclipse, the appropriate tools.jar is added and 
 	 * the Xerces JARs are added.
 	 */
@@ -196,36 +196,34 @@
 		
 		IAntClasspathEntry newToolsEntry= prefs.getToolsJarEntry(newJavaPath);
 		
-		List antURLs= new ArrayList();
-		List userURLs= new ArrayList();
-		
-		getEntries(prefs, configuration, antURLs, userURLs);
-
-		StringBuffer urlString= new StringBuffer();
+		List antEntries= new ArrayList();
+		List userEntries= new ArrayList();	
+		getEntries(prefs, configuration, antEntries, userEntries);
+	
+		StringBuffer classpath= new StringBuffer();
 		boolean found= false;
-		boolean[] xercesFlags;
-		{ 
-			boolean xercesImplFound= false;
-			boolean xercesAPIFound= false;
-			xercesFlags= new boolean[]{xercesImplFound, xercesAPIFound};
-		}
-		found= lookForToolsAndXerces(urlString, antURLs, oldToolsEntry, newToolsEntry, xercesFlags);
+		boolean xercesImplFound= false;
+		boolean xercesAPIFound= false;
+		boolean[] xercesFlags= new boolean[]{xercesImplFound, xercesAPIFound};
 		
-		//mark as additional classpath entries
-		urlString.append(AntUtil.ANT_CLASSPATH_DELIMITER);
-		
+		found= lookForToolsAndXerces(antEntries, oldToolsEntry, newToolsEntry, xercesFlags);
+					
 		//look for the tools.jar and xerces in the additional classpath entries
-		boolean foundInAdditional= lookForToolsAndXerces(urlString, userURLs, oldToolsEntry, newToolsEntry, xercesFlags);
+		boolean foundInAdditional= lookForToolsAndXerces(userEntries, oldToolsEntry, newToolsEntry, xercesFlags);
 		if (newToolsEntry != null && !found && !foundInAdditional) {
-			urlString.append(newToolsEntry.getLabel());
-			urlString.append(AntUtil.ATTRIBUTE_SEPARATOR);
+			classpath.append(newToolsEntry.getLabel());
+			classpath.append(AntUtil.ATTRIBUTE_SEPARATOR);
 		}
 		
+		//add the xerces JARs if required and not previously found
 		if (!fJREBlock.isDefaultJRE() && (!xercesFlags[0] || !xercesFlags[1])) {
 			IPluginDescriptor descriptor = Platform.getPlugin("org.apache.xerces").getDescriptor(); //$NON-NLS-1$
-			addLibraries(descriptor, urlString, !xercesFlags[1], !xercesFlags[0]);
+			addLibraries(descriptor, classpath, !xercesFlags[1], !xercesFlags[0]);
 		}
-		configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_CUSTOM_CLASSPATH, urlString.substring(0, urlString.length() - 1));
+		
+		ClasspathModel model= getClasspathModel();
+		classpath.append(model.serializeClasspath(true));
+		configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_CUSTOM_CLASSPATH, classpath.toString());
 		previousJRE= vm;
 		updateTargetsTab();
 	}
@@ -243,6 +241,19 @@
 		}
 	}
 	
+	private ClasspathModel getClasspathModel() {
+		//the classpath has changed...set the targets tab to 
+		//need to be recomputed
+		ILaunchConfigurationTab[] tabs=  getLaunchConfigurationDialog().getTabs();
+		for (int i = 0; i < tabs.length; i++) {
+			ILaunchConfigurationTab tab = tabs[i];
+			if (tab instanceof AntClasspathTab) {
+				return ((AntClasspathTab)tab).getClasspathModel();
+			}
+		}
+		return null;
+	}
+	
 	private void getEntries(AntCorePreferences prefs, ILaunchConfigurationWorkingCopy configuration, List antHomeEntries, List additionalEntries) {
 		String entryStrings= null;
 		try {
@@ -264,38 +275,22 @@
 	 * with the specified JRE.
 	 * The xerces flags are set based on the Xerces JARs that are found.
 	 */
-	private boolean lookForToolsAndXerces(StringBuffer urlString, List entries, IAntClasspathEntry oldToolsEntry, IAntClasspathEntry newToolsEntry, boolean[] xercesFlags){
-		boolean include= true;
+	private boolean lookForToolsAndXerces(List entries, IAntClasspathEntry oldToolsEntry, IAntClasspathEntry newToolsEntry, boolean[] xercesFlags){
 		boolean found= false;
 		for (Iterator iter = entries.iterator(); iter.hasNext();) {
 			IAntClasspathEntry entry = (IAntClasspathEntry) iter.next();
 			if (sameURL(oldToolsEntry, entry)) {
 				entry= newToolsEntry;
 				found= newToolsEntry != null;
-				include= found;
 			} else if (sameURL(newToolsEntry, entry)) {
 				found= true;
 			} else if (entry.getLabel().endsWith(XERCES_API)) {
 				xercesFlags[1]= true;
-				if (fJREBlock.isDefaultJRE()) {
-					include= false;
-				}
 			} else if (entry.getLabel().endsWith(XERCES_IMPL)) {
 				xercesFlags[0]= true;
-				if (fJREBlock.isDefaultJRE()) {
-					include= false;
-				}
 			} else if (entry.getLabel().endsWith(XERCES_PARSER_API)) {
 				xercesFlags[1]= true;
-				if (fJREBlock.isDefaultJRE()) {
-					include= false;
-				}
 			}
-			if (include) {
-				urlString.append(entry.getEntryURL().getFile());
-				urlString.append(AntUtil.ATTRIBUTE_SEPARATOR);
-			}
-			include= true;
 		}
 		return found;
 	}
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathBlock.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathBlock.java
index 3e17052..5f87fe7 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathBlock.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathBlock.java
@@ -10,7 +10,6 @@
  *******************************************************************************/
 package org.eclipse.ant.internal.ui.preferences;
 
-
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -52,7 +51,6 @@
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -90,7 +88,6 @@
 	
 	private boolean localBlock= false;
 	
-	private Button antHomeButton;
 	private Text antHome;
 	private Button browseAntHomeButton;
 
@@ -155,7 +152,7 @@
 			}
 		});
 		if (localBlock) {
-			restoreButton= container.createPushButton(parent, AntPreferencesMessages.getString("AntClasspathBlock.45")); //$NON-NLS-1$
+			restoreButton= container.createPushButton(parent, AntPreferencesMessages.getString("AntClasspathBlock.54")); //$NON-NLS-1$
 			restoreButton.addSelectionListener(new SelectionAdapter() {
 				public void widgetSelected(SelectionEvent evt) {
 					restoreGlobalEntries();
@@ -394,37 +391,14 @@
 	}
 			
 	public void createContents(Composite parent) {
-		Font font = parent.getFont();
-		Label label = new Label(parent, SWT.NONE);
-		GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
-		gd.horizontalSpan = 2;
-		label.setLayoutData(gd);
-		label.setFont(font);
-		label.setText(AntPreferencesMessages.getString("AntClasspathBlock.Run&time_classpath__8")); //$NON-NLS-1$
-
 		createClasspathTree(parent);
 		createButtonGroup(parent);
 
-		createSeparator(parent);
-
 		createAntHome(parent);
 		
 		tableSelectionChanged((IStructuredSelection)treeViewer.getSelection(), antContentProvider);
 	}
 
-	/**
-	 * Creates a space between controls
-	 */
-	private Label createSeparator(Composite parent) {
-		Label separator = new Label(parent, SWT.NONE);
-		GridData gd =
-			new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
-		gd.heightHint = 4;
-		gd.horizontalSpan = 2;
-		separator.setLayoutData(gd);
-		return separator;
-	}
-
 	private void createAntHome(Composite top) {
 		Composite antHomeComposite = new Composite(top, SWT.NONE);
 		antHomeComposite.setLayoutData(
@@ -437,21 +411,15 @@
 		antHomeComposite.setLayout(layout);
 		antHomeComposite.setFont(top.getFont());
 
-		antHomeButton = new Button(antHomeComposite, SWT.CHECK);
-		antHomeButton.setFont(top.getFont());
-		antHomeButton.setText(AntPreferencesMessages.getString("AntClasspathBlock.Set_ANT_HO&ME_9")); //$NON-NLS-1$
-		antHomeButton.addSelectionListener(new SelectionAdapter() {
-			public void widgetSelected(SelectionEvent evt) {
-				specifyAntHome();
-			}
-		});
-
+		Label antHomeLabel = new Label(antHomeComposite, SWT.NONE);
+		antHomeLabel.setFont(top.getFont());
+		antHomeLabel.setText(AntPreferencesMessages.getString("AntClasspathBlock.55"));  //$NON-NLS-1$
+		
 		antHome = new Text(antHomeComposite, SWT.BORDER);
 		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
 		gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
 		antHome.setLayoutData(gd);
 		antHome.setFont(top.getFont());
-		antHome.setEnabled(false);
 		antHome.addModifyListener(new ModifyListener() {
 			public void modifyText(ModifyEvent e) {
 				if (initializing) {
@@ -477,7 +445,6 @@
 				browseAntHome();
 			}
 		});
-		browseAntHomeButton.setEnabled(false);
 	}
 	
 	/* (non-Javadoc)
@@ -522,10 +489,6 @@
 				currentParent= antContentProvider.getModel();
 			} else {
 				resolveCurrentParent(selection);
-				if (currentParent.getParent() != antContentProvider.getModel()) {
-					//first= true;
-					//last= true;
-				}
 				if (haveGlobalEntrySelected) {
 					canRemove= false;
 				}
@@ -572,21 +535,6 @@
 		return true;
 	}
 
-	private void specifyAntHome() {
-		antHome.setEnabled(!antHome.getEnabled());
-		browseAntHomeButton.setEnabled(!browseAntHomeButton.getEnabled());
-		if (antHome.isEnabled()) {
-			File rootDir = validateAntHome(antHome.getText());
-			if (rootDir != null) {
-				setAntHome(rootDir);
-			}
-		} else {
-			container.setMessage(null);
-			container.setErrorMessage(null);
-		}
-		updateContainer();
-	}
-	
 	private File validateAntHome(String path) {
 		File rootDir = null;
 		if (path.length() > 0) {
@@ -647,22 +595,15 @@
 	
 	public String getAntHome() {
 		String antHomeText= antHome.getText().trim();
-		if (!antHomeButton.getSelection() || antHomeText.length() == 0) {
-			antHomeText= null;
+		if (antHomeText.length() == 0) {
+			antHomeText= ""; //$NON-NLS-1$
 		}
 		return antHomeText;
 	}
 	
 	public void initializeAntHome(String antHomeString, boolean setInitializing) {
-		this.initializing= setInitializing;
-		antHomeButton.setSelection(antHomeString != null);
-		antHome.setEnabled(antHomeString != null);
-		browseAntHomeButton.setEnabled(antHomeString != null);
-		if (antHomeString != null) {
-			antHome.setText(antHomeString);
-		} else {
-			antHome.setText(""); //$NON-NLS-1$
-		}
+		this.initializing= setInitializing; //possible turn off the modifytext callback
+		antHome.setText(antHomeString);
 		this.initializing= false;
 	}
 	
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathPage.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathPage.java
index f31527c..9f1cbe1 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathPage.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathPage.java
@@ -89,7 +89,7 @@
 		model.setAntHomeEntries(prefs.getDefaultAntHomeEntries());
 		model.setGlobalEntries(new IAntClasspathEntry[] {prefs.getToolsJarEntry()});
 		antClasspathBlock.setInput(model);
-		antClasspathBlock.initializeAntHome(prefs.getDefaultAntHome(), true);
+		antClasspathBlock.initializeAntHome(prefs.getDefaultAntHome(), false);
 		update();
 	}
 	
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
index 5ed1bdb..b6063fb 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
@@ -17,8 +17,6 @@
 AntClasspathBlock.removeButtonTitle = R&emove
 AntClasspathBlock.3=Choose a folder that will be used as the location of ANT_HOME
 AntClasspathBlock.Specified_ANT_HOME_does_not_contain_a___lib___directory_7=Specified ANT_HOME does not contain a \"lib\" directory
-AntClasspathBlock.Run&time_classpath__8=Runt&ime classpath:
-AntClasspathBlock.Set_ANT_HO&ME_9=Set ANT_&HOME
 AntClasspathBlock.&Browse..._10=&Browse...
 AntClasspathBlock.31=No tools.jar
 AntClasspathBlock.32=The specified Ant runtime classpath does not include a tools.jar library. This may affect the ability to use various tasks. Ignore this possible problem?
@@ -32,7 +30,8 @@
 AntClasspathBlock.45=&Choose JARs and ZIPs to add:
 AntClasspathBlock.52=Xerces JARs are required on the Ant runtime classpath when running in a separate VM. Ignore this possible problem?
 AntClasspathBlock.53=Missing Xerces JARs on Ant runtime classpath
-AntClasspathBlock.45=&Global Entries...
+AntClasspathBlock.54=&Global Entries...
+AntClasspathBlock.55=Ant Home:
 
 AntClasspathPage.title = C&lasspath
 
@@ -143,4 +142,4 @@
 GlobalClasspathEntriesSelectionDialog.0=Global Entries
 GlobalClasspathEntriesSelectionDialog.1=&Select the global classpath entry and how it should be added to the local classpath:
 GlobalClasspathEntriesSelectionDialog.2=As a &unit
-GlobalClasspathEntriesSelectionDialog.3=As &individual entries
+GlobalClasspathEntriesSelectionDialog.3=As &individual entries
\ No newline at end of file