/*******************************************************************************
 * This file is a component of the Taverna project, and is licensed  under the
 *  GNU LGPL. Copyright Edward Kawas, The BioMoby Project
 ******************************************************************************/
/*
 * This file is a component of the Taverna project,
 * and is licensed under the GNU LGPL.
 * Copyright Edward Kawas, The BioMoby Project
 */
package net.sf.taverna.t2.activities.biomoby.actions;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.biomoby.registry.meta.Registries;
import org.biomoby.registry.meta.RegistriesList;
import org.biomoby.shared.MobyException;

import net.sf.taverna.t2.lang.ui.ShadedLabel;

/**
 * a dialog for helping create scavengers for BioMoby registries that are not
 * the default registry.
 * 
 */
public class BiomobyScavengerDialog extends JPanel {

	private static final long serialVersionUID = -57047613557546674L;
	private JTextField registryEndpoint = new JTextField(
			"http://moby.ucalgary.ca/moby/MOBY-Central.pl");
	private JTextField registryURI = new JTextField(
			"http://moby.ucalgary.ca/MOBY/Central");

	/**
	 * Default constructor.
	 * 
	 */
	/**
	 * Default constructor.
	 * 
	 */
	public BiomobyScavengerDialog() {
		super();
		GridLayout layout = new GridLayout(5, 2);
		setLayout(layout);
		// a combo box showing known registries
		final Registries regs = RegistriesList.getInstance();
		JComboBox regList = new JComboBox(regs.list());
		regList.setToolTipText("A selection will fill text fields below");
		regList.setSelectedItem(Registries.DEFAULT_REGISTRY_SYNONYM);
		regList.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String contents = (String) ((JComboBox) e.getSource())
						.getSelectedItem();

				org.biomoby.registry.meta.Registry theReg = null;
				try {
					theReg = regs.get(contents);
				} catch (MobyException ee) {
					try {
						theReg = regs.get(null);
					} catch (MobyException ee2) {

					}
				}
				if (theReg != null) {

					registryEndpoint.setText(theReg.getEndpoint());
					registryURI.setText(theReg.getNamespace());

				}
			}
		});
		add(new ShadedLabel("Choose a registry from the list: ",
				ShadedLabel.BLUE, true));
		add(regList);
		add(new ShadedLabel("Or enter your own below,", ShadedLabel.BLUE, true));
		add(new ShadedLabel("", ShadedLabel.BLUE, true));
		add(new ShadedLabel(
				"Location (URL) of your BioMoby central registry: ",
				ShadedLabel.BLUE, true));
		registryEndpoint
				.setToolTipText("BioMoby Services will be retrieved from the endpoint that you specify here!");
		add(registryEndpoint);
		add(new ShadedLabel(
				"Namespace (URI) of your BioMoby central registry: ",
				ShadedLabel.BLUE, true));
		registryURI
				.setToolTipText("BioMoby Services will be retrieved from the endpoint/URI that you specify here!");
		add(registryURI);
		// add(Box.createHorizontalGlue());add(Box.createHorizontalGlue());
		setPreferredSize(this.getPreferredSize());
		setMinimumSize(this.getPreferredSize());
		setMaximumSize(this.getPreferredSize());

	}

	/**
	 * 
	 * @return the string representation of the BioMoby Registry endpoint
	 */
	public String getRegistryEndpoint() {
		return registryEndpoint.getText();
	}

	/**
	 * 
	 * @return the string representation of the BioMoby Registry endpoint
	 */
	public String getRegistryURI() {
		return registryURI.getText();
	}
}

@@ -592,16 +592,92 @@
 istener;
+%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;
 %0A%0Aimport
@@ -1111,16 +1111,64 @@
 anel %7B%0A%0A
+%09private static final String CUSTOM = %22Custom%22;%0A
 %09private
@@ -1619,16 +1619,95 @@
 ayout);%0A
+%09%09%0A%09%09registryEndpoint.setEnabled(false);%0A%09%09registryURI.setEnabled(false);%09%09%0A%09%09%0A
 %09%09// a c
@@ -1796,16 +1796,118 @@
 ance();%0A
+%09%09List%3CString%3E choices = new ArrayList%3CString%3E(Arrays.asList(regs.list()));%0A%09%09choices.add(CUSTOM);%0A%09%09%0A
 %09%09JCombo
@@ -1934,25 +1934,31 @@
 omboBox(
-regs.list
+choices.toArray
 ());%0A%09%09r
@@ -2268,24 +2268,249 @@
 tedItem();%0A%0A
+%09%09%09%09if (contents.equals(CUSTOM)) %7B%0A%09%09%09%09%09registryEndpoint.setEnabled(true);%0A%09%09%09%09%09registryURI.setEnabled(true);%0A%09%09%09%09%09return;%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09registryEndpoint.setEnabled(false);%0A%09%09%09%09%09registryURI.setEnabled(false);%09%09%09%09%09%0A%09%09%09%09%7D%0A 
 %09%09%09%09org.biom
@@ -2551,16 +2551,16 @@
 = null;%0A
-
 %09%09%09%09try 
@@ -2741,25 +2741,24 @@
  != null) %7B%0A
-%0A
 %09%09%09%09%09registr
@@ -2966,24 +2966,24 @@
 d(regList);%0A
-
 %09%09add(new Sh
@@ -2996,16 +2996,43 @@
 bel(%22Or 
+select '%22 + CUSTOM + %22' to 
 enter yo

Add an option "Custom" and gray out text areas unless Custom is chosen.