gt: 				map = object.getExperimenters();
context: /*
   * org.openmicroscopy.shoola.agents.treeviewer.util.AdminDialog 
   *
   *------------------------------------------------------------------------------
   *  Copyright (C) 2006-2010 University of Dundee. All rights reserved.
   *
   *
   * 	This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *  
   *  You should have received a copy of the GNU General Public License along
   *  with this program; if not, write to the Free Software Foundation, Inc.,
   *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   *
   *------------------------------------------------------------------------------
   */
  package org.openmicroscopy.shoola.agents.treeviewer.util;
  
  
  //Java imports
  import java.awt.BorderLayout;
  import java.awt.Container;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.beans.PropertyChangeEvent;
  import java.beans.PropertyChangeListener;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Map.Entry;
  
  import javax.swing.Box;
  import javax.swing.BoxLayout;
  import javax.swing.JButton;
  import javax.swing.JDialog;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  //Third-party libraries
  
  //Application-internal dependencies
  import org.openmicroscopy.shoola.agents.treeviewer.IconManager;
  import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent;
  import org.openmicroscopy.shoola.env.data.AdminService;
  import org.openmicroscopy.shoola.env.data.login.UserCredentials;
  import org.openmicroscopy.shoola.env.data.model.AdminObject;
  import org.openmicroscopy.shoola.env.ui.UserNotifier;
  import org.openmicroscopy.shoola.util.ui.TitlePanel;
  import org.openmicroscopy.shoola.util.ui.UIUtilities;
  
  import pojos.DataObject;
  import pojos.ExperimenterData;
  import pojos.GroupData;
  
  /** 
   * Dialog used to create <code>Group</code> or <code>Experimenter</code>.
   *
   * @author Jean-Marie Burel &nbsp;&nbsp;&nbsp;&nbsp;
   * <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
   * @author Donald MacDonald &nbsp;&nbsp;&nbsp;&nbsp;
   * <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a>
   * @version 3.0
   * <small>
   * (<b>Internal version:</b> $Revision: $Date: $)
   * </small>
   * @since 3.0-Beta4
   */
  public class AdminDialog 
  	extends JDialog
  	implements ActionListener, PropertyChangeListener
  {
  
  	/** Bound property indicating to create the object. */
  	public static final String CREATE_ADMIN_PROPERTY = "createAdmin";
  	
  	/** Bound property indicating to enable of not the save property. */
  	static final String ENABLE_SAVE_PROPERTY = "enableSave";
  	
  	/** The title of the dialog if the object to create is a group. */
  	private static final String TITLE_GROUP = "Create Group";
  	
  	/** The title of the dialog if the object to create is an group.. */
  	private static final String TITLE_EXPERIMENTER = "Create Experimenter";
  	
  	/** The text displayed if the object to create is a group. */
  	private static final String TEXT_GROUP = "Create a new group";
  	
  	/** The text displayed if the object to create is a group. */
  	private static final String TEXT_EXPERIMENTER = 
  		"Create a new Experimenter.";
  	
  	/** Action ID to close the dialog. */
  	private static final int CANCEL = 0;
  	
  	/** Action ID to save the data. */
  	private static final int SAVE = 1;
  	
  	/** Button to close the dialog. */
  	private JButton cancel;
  	
  	/** Button to close the dialog. */
  	private JButton save;
  	
  	/** The type of object to create. */
  	private Class	type;
  	
  	/** The parent of the data object. */
  	private Object parent;
  	
  	/** 
  	 * The main component displaying parameters required to 
  	 * create a group or an experimenter. 
  	 */
  	private DataPane body;
  	
  	/** Initializes the components. */
  	private void initComponents()
  	{
  		cancel = new JButton("Cancel");
  		cancel.setActionCommand(""+CANCEL);
  		cancel.addActionListener(this);
  		save = new JButton("Create");
  		save.setActionCommand(""+SAVE);
  		save.addActionListener(this);
  		save.setEnabled(false);
  	}
  
  	/** Closes and disposes of the dialog. */
  	private void cancel()
  	{
  		setVisible(false);
  		dispose();
  	}
  	
  	/**
  	 * Returns <code>true</code> if the name of the group already exists,
  	 * <code>false</code> otherwise.
  	 * 
  	 * @return See above.
  	 */
  	private boolean isExistingObject(String name, boolean group)
  	{
  		AdminService svc = TreeViewerAgent.getRegistry().getAdminService();
  		try {
  			if (group) return svc.lookupGroup(name) != null;
  			return svc.lookupExperimenter(name) != null;
  		} catch (Exception e) {
  			// TODO: handle exception
  		}
  		return true;
  	}
  	
  	/**
  	 * Notifies that a group with same name already exists if the passed
  	 * value is <code>true</code>, that an experimenter with the same name
  	 * already exists if the passed value is <code>false</code>.
  	 * 
  	 * @param group Pass <code>true</code> to indicate that the message is
  	 * 				related to a group, <code>false</code> if related to an
  	 * 				experimenter.
  	 */
  	private void notifyUser(boolean group)
  	{
  		UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
  		StringBuffer text = new StringBuffer();
  		if (group) text.append("This Group name already exists.");
  		else text.append("This Experimenter name already exists.");
  		text.append("\nPlease choose another name.");
  		un.notifyInfo("Admin Error", text.toString());
  	}
  	
  	/** Saves the data. */
  	private void save()
  	{
  		AdminObject object = null;
  		if (body instanceof GroupPane) {
  			object = ((GroupPane) body).getObjectToSave();
  		} else if (body instanceof ExperimenterPane) {
  			ExperimenterPane pane = (ExperimenterPane) body;
  			Map<ExperimenterData, UserCredentials> m = pane.getObjectToSave();
  			if (m.size() == 0) return;
  			object = new AdminObject(m, AdminObject.CREATE_EXPERIMENTER);
  			object.setGroups(pane.getSelectedGroups());
  		}
  		if (object == null) return;
  		//Check if group already exist.
  		Entry entry;
  		Iterator i;
  		UserCredentials uc;
  		Map<ExperimenterData, UserCredentials>  map;
  		boolean b = false;
  		switch (object.getIndex()) {
  			case AdminObject.CREATE_GROUP:
  				b = isExistingObject(object.getGroup().getName(), true);
  				if (b) {
  					notifyUser(true);
  					return;
  				}
  