Bug 21809 - Let user specify installation directory of Ant
diff --git a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPage.java b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPage.java
index c815fa0..9a16a81 100644
--- a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPage.java
+++ b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPage.java
@@ -68,9 +68,10 @@
 	/**
 	 * Adds an object to the contents
 	 */
-	protected final void addContent(Object o) {
-		if (contentProvider != null)
+	protected void addContent(Object o) {
+		if (contentProvider != null) {
 			contentProvider.add(o);
+		}
 	}
 	
 	/**
@@ -202,8 +203,9 @@
 	protected void removeButtonPressed() {
 		IStructuredSelection sel = (IStructuredSelection) tableViewer.getSelection();
 		Iterator enum = sel.iterator();
-		while (enum.hasNext())
+		while (enum.hasNext()) {
 			contentProvider.remove(enum.next());
+		}
 	}
 	
 	/**
@@ -272,8 +274,9 @@
 		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
 			this.viewer = (TableViewer) viewer;
 			elements.clear();
-			if (newInput != null)
+			if (newInput != null) {
 				elements.addAll((List) newInput);
+			}
 		}
 		
 		public void remove(Object o) {
diff --git a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPreferencePage.java b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPreferencePage.java
index 0ce2d0f..ecdf6d3 100644
--- a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPreferencePage.java
+++ b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPreferencePage.java
@@ -127,6 +127,9 @@
 			prefs.setCustomProperties(properties);
 		}
 		
+		String[] files = propertiesPage.getPropertyFiles();
+		prefs.setCustomPropertyFiles(files);
+		
 		prefs.updatePluginPreferences();
 		return super.performOk();
 	}
diff --git a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPreferencesMessages.properties b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPreferencesMessages.properties
index 52d96ef..da8707e 100644
--- a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPreferencesMessages.properties
+++ b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPreferencesMessages.properties
@@ -22,7 +22,7 @@
 AddCustomDialog.class = &Class:
 AddCustomDialog.library = &Library:
 
-AntPreferencePage.description = &Customize the classpath, tasks, types, and properties\nused when running Ant build files from Eclipse.
+AntPreferencePage.description = &Customize the classpath, tasks, types, properties and property files\nused when running Ant build files from Eclipse.
 
 AntPropertiesPage.title = Properties
 AntPropertiesPage.addButton = Add &Property...
diff --git a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPropertiesPage.java b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPropertiesPage.java
index 29e5327..ae66c9e 100644
--- a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPropertiesPage.java
+++ b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/preferences/AntPropertiesPage.java
@@ -1,12 +1,15 @@
 package org.eclipse.ui.externaltools.internal.ant.preferences;
 
-import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 
 import org.eclipse.ant.core.AntCorePlugin;
 import org.eclipse.ant.core.Property;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
@@ -22,6 +25,7 @@
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.TabFolder;
 import org.eclipse.swt.widgets.TabItem;
@@ -29,6 +33,7 @@
 import org.eclipse.ui.ISharedImages;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
+import org.eclipse.ui.externaltools.internal.ui.IExternalToolsUIConstants;
 
 /**
  * Preference page for setting global Ant user properties.
@@ -47,7 +52,6 @@
 	
 	private Button addButton;
 	private Button addFileButton;
-	private Button editFileButton;
 	private Button removeFileButton;
 	
 	private TableViewer fileTableViewer;
@@ -55,11 +59,14 @@
 	
 	private final AntPropertiesLabelProvider labelProvider = new AntPropertiesLabelProvider();
 	
+	private IDialogSettings fDialogSettings;
+	
 	/**
 	 * Creates an instance.
 	 */
 	public AntPropertiesPage(AntPreferencePage preferencePage) {
 		super(preferencePage);
+		fDialogSettings= ExternalToolsPlugin.getDefault().getDialogSettings();
 	}
 	
 	/* (non-Javadoc)
@@ -79,7 +86,6 @@
 			removeButton= createButton(parent, "AntPropertiesPage.removeButton", REMOVE_BUTTON); //$NON-NLS-1$;
 		} else {
 			addFileButton= createButton(parent, "AntPropertiesPage.addFileButton", ADD_PROPERTY_FILE_BUTTON); //$NON-NLS-1$;
-			editFileButton= createButton(parent, "AntPropertiesPage.editFileButton", EDIT_PROPERTY_FILE_BUTTON); //$NON-NLS-1$;
 			removeFileButton= createButton(parent, "AntPropertiesPage.removeButton", REMOVE_PROPERTY_FILE_BUTTON); //$NON-NLS-1$;
 		}
 	}
@@ -157,17 +163,22 @@
 				removeButtonPressed();
 				break;
 			case ADD_PROPERTY_FILE_BUTTON :
-				//addFile();
-				break;
-			case EDIT_PROPERTY_FILE_BUTTON :
-				//editFile(getSelection());
+				addPropertyFile();
 				break;
 			case REMOVE_PROPERTY_FILE_BUTTON :
-				//removeFile();
+				removePropertyFile();
 				break;
 		}
 	}
 	
+	private void removePropertyFile() {
+		IStructuredSelection selection= ((IStructuredSelection)fileTableViewer.getSelection());
+		Iterator itr = selection.iterator();
+		while (itr.hasNext()) {
+			fileContentProvider.remove(itr.next());
+		}
+	}
+	
 	/**
 	 * Allows the user to enter a global user property
 	 */
@@ -284,9 +295,7 @@
 	 */
 	protected void fileTableSelectionChanged(IStructuredSelection newSelection) {
 		int size = newSelection.size();
-		editFileButton.setEnabled(size == 1);
 		removeFileButton.setEnabled(size > 0);
-		addFileButton.setEnabled(false);
 	}
 	
 	/**
@@ -295,8 +304,60 @@
 	 */
 	public void initialize() {
 		getTableViewer().setInput(Arrays.asList(AntCorePlugin.getPlugin().getPreferences().getCustomProperties()));
-		fileTableViewer.setInput(new ArrayList());
+		fileTableViewer.setInput(Arrays.asList(AntCorePlugin.getPlugin().getPreferences().getCustomPropertyFiles()));
 		tableSelectionChanged((IStructuredSelection) getTableViewer().getSelection());
 		fileTableSelectionChanged((IStructuredSelection)fileTableViewer.getSelection());
 	}
+	
+	/**
+	 * Allows the user to enter JARs to the classpath.
+	 */
+	private void addPropertyFile() {
+		String lastUsedPath;
+		lastUsedPath= fDialogSettings.get(IExternalToolsUIConstants.DIALOGSTORE_LASTEXTFILE);
+		if (lastUsedPath == null) {
+			lastUsedPath= ""; //$NON-NLS-1$
+		}
+		FileDialog dialog = new FileDialog(getShell(), SWT.MULTI);
+		dialog.setFilterExtensions(new String[] { "*.properties" }); //$NON-NLS-1$;
+		dialog.setFilterPath(lastUsedPath);
+
+		String result = dialog.open();
+		if (result == null) {
+			return;
+		}
+		IPath filterPath= new Path(dialog.getFilterPath());
+		String[] results= dialog.getFileNames();
+		for (int i = 0; i < results.length; i++) {
+			String fileName = results[i];	
+			IPath path= filterPath.append(fileName).makeAbsolute();	
+			addContent(path.toOSString());
+		}
+		
+		fDialogSettings.put(IExternalToolsUIConstants.DIALOGSTORE_LASTEXTFILE, filterPath.toOSString());
+	}
+	/**
+	 * @see org.eclipse.ui.externaltools.internal.ant.preferences.AntPage#addContent(java.lang.Object)
+	 */
+	protected void addContent(Object o) {
+		if (o instanceof String) {
+			fileContentProvider.add(o);
+		} else {
+			super.addContent(o);
+		}
+	}
+	
+	/**
+	 * Returns the specified property files
+	 * 
+	 * @return String[]
+	 */
+	public String[] getPropertyFiles() {
+		Object[] elements = fileContentProvider.getElements(null);
+		String[] files= new String[elements.length];
+		for (int i = 0; i < elements.length; i++) {
+			files[i] = (String)elements[i];
+		}
+		return files;
+	}
 }
\ No newline at end of file
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/IExternalToolsUIConstants.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/IExternalToolsUIConstants.java
index 4eb7ac3..80142e1 100644
--- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/IExternalToolsUIConstants.java
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/IExternalToolsUIConstants.java
@@ -1,18 +1,17 @@
 package org.eclipse.ui.externaltools.internal.ui;
 
-import org.eclipse.ui.externaltools.model.IExternalToolConstants;
-
 /**********************************************************************
 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
 This file is made available under the terms of the Common Public License v1.0
 which accompanies this distribution, and is available at
 http://www.eclipse.org/legal/cpl-v10.html

-Contributors:
 **********************************************************************/
 
+import org.eclipse.ui.externaltools.model.IExternalToolConstants;
+
+
 public interface IExternalToolsUIConstants {
 
 	public static final String DIALOGSTORE_LASTEXTJAR= IExternalToolConstants.PLUGIN_ID + ".lastextjar"; //$NON-NLS-1$
-
+	public static final String DIALOGSTORE_LASTEXTFILE= IExternalToolConstants.PLUGIN_ID + ".lastextfile"; //$NON-NLS-1$
 }