gt: 		Set values = new HashSet();
context: /*
   *------------------------------------------------------------------------------
   *  Copyright (C) 2006-2017 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.dataBrowser;
  
  
  import java.util.Collection;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Set;
  
  import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowserFactory;
  import org.openmicroscopy.shoola.agents.events.iviewer.CopyRndSettings;
  import org.openmicroscopy.shoola.agents.events.iviewer.RndSettingsCopied;
  import org.openmicroscopy.shoola.agents.events.metadata.AnnotatedEvent;
  import org.openmicroscopy.shoola.agents.events.treeviewer.CopyItems;
  import org.openmicroscopy.shoola.agents.events.treeviewer.DisplayModeEvent;
  import org.openmicroscopy.shoola.env.Agent;
  import org.openmicroscopy.shoola.env.Environment;
  import org.openmicroscopy.shoola.env.LookupNames;
  import org.openmicroscopy.shoola.env.config.Registry;
  import org.openmicroscopy.shoola.env.data.AdminService;
  import org.openmicroscopy.shoola.env.data.events.ReconnectedEvent;
  import org.openmicroscopy.shoola.env.data.events.UserGroupSwitched;
  import org.openmicroscopy.shoola.env.data.util.AgentSaveInfo;
  
  import omero.gateway.SecurityContext;
  
  import org.openmicroscopy.shoola.env.event.AgentEvent;
  import org.openmicroscopy.shoola.env.event.AgentEventListener;
  import org.openmicroscopy.shoola.env.event.EventBus;
  
  import omero.gateway.model.ExperimenterData;
  import omero.gateway.model.GroupData;
  
  /** 
   * The DataBrowser agent. This agent manages and presents a thumbnail view
   * of a <code>DataObject</code> and its children.
   *
   * @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
   * @since OME3.0
   */
  public class DataBrowserAgent 
  	implements Agent, AgentEventListener
  {
  
  	/** Reference to the registry. */
      private static Registry         registry; 
      
      /** The display mode.*/
  	private int displayMode = -1;
  	
      /**
       * Helper method. 
       * 
       * @return A reference to the <code>Registry</code>.
       */
      public static Registry getRegistry() { return registry; }
  
  	/**
  	 * Returns the available user groups.
  	 * 
  	 * @return See above.
  	 */
  	public static Collection getAvailableUserGroups()
  	{
  		return (Collection) registry.lookup(LookupNames.USER_GROUP_DETAILS);
  	}
  	
  	/**
  	 * Returns the context for an administrator.
  	 * 
  	 * @return See above.
  	 */
  	public static SecurityContext getAdminContext()
  	{
  		if (!isAdministrator()) return null;
          Collection<GroupData> groups = getAvailableUserGroups();
          Iterator<GroupData> i = groups.iterator();
          GroupData g;
          AdminService svc = registry.getAdminService();
          while (i.hasNext()) {
              g = i.next();
              if (svc.isSecuritySystemGroup(g.getId(), GroupData.SYSTEM))
                  return new SecurityContext(g.getId());
          }
          return null;
  	}
  	
      /**
       * Returns the identifier of the plugin to run.
       * 
       * @return See above.
       */
      public static int runAsPlugin()
      {
      	Environment env = (Environment) registry.lookup(LookupNames.ENV);
      	if (env == null) return -1;
      	return env.runAsPlugin();
      }
      
      /**
  	 * Helper method returning the current user's details.
  	 * 
  	 * @return See above.
  	 */
  	public static ExperimenterData getUserDetails()
  	{ 
  		return (ExperimenterData) registry.lookup(
  								LookupNames.CURRENT_USER_DETAILS);
  	}
  	
  	/**
  	 * Returns <code>true</code> if the currently logged in user
  	 * is an administrator, <code>false</code> otherwise.
  	 * 
  	 * @return See above.
  	 */
  	public static boolean isAdministrator()
  	{
  		Boolean b = (Boolean) registry.lookup(LookupNames.USER_ADMINISTRATOR);
  		if (b == null) return false;
  		return b.booleanValue();
  	}
  	
  	/**
       * Returns <code>true</code> if the currently logged in user
       * can edit users, <code>false</code> otherwise.
       * 
       * @return See above.
       */
      public static boolean isEditUser()
      {
          Boolean b = (Boolean) registry.lookup(LookupNames.PRIV_EDIT_USER);
          if (b == null) return false;
          return b.booleanValue();
      }
      
  	/**
       * Returns <code>true</code> if the currently logged in user
       * can edit groups, <code>false</code> otherwise.
       * 
       * @return See above.
       */
      public static boolean isEditGroup()
      {
          Boolean b = (Boolean) registry.lookup(LookupNames.PRIV_EDIT_GROUP);
          if (b == null) return false;
          return b.booleanValue();
      }
      
      /**
       * Returns <code>true</code> if the currently logged in user
       * can add users to groups, <code>false</code> otherwise.
       * 
       * @return See above.
       */
      public static boolean isAddToGroup()
      {
          Boolean b = (Boolean) registry.lookup(LookupNames.PRIV_GROUP_ADD);
          if (b == null) return false;
          return b.booleanValue();
      }
      
      /**
       * Returns <code>true</code> if the currently logged in user
       * can move object to/from groups, <code>false</code> otherwise.
       * 
       * @return See above.
       */
      public static boolean isMoveGroup()
      {
          Boolean b = (Boolean) registry.lookup(LookupNames.PRIV_MOVE_GROUP);
          if (b == null) return false;
          return b.booleanValue();
      }
  	
  	/**
  	 * Returns the collection of groups the current user is the leader of.
  	 * 
  	 * @return See above.
  	 */
  	public static Set getGroupsLeaderOf()
  	{
  