Author: scooter
Date: 2012-01-23 16:30:35 -0800 (Mon, 23 Jan 2012)
New Revision: 28081

Added:
   core3/impl/trunk/group-impl/
   core3/impl/trunk/group-impl/pom.xml
   core3/impl/trunk/group-impl/src/
   core3/impl/trunk/group-impl/src/main/
   core3/impl/trunk/group-impl/src/main/java/
   core3/impl/trunk/group-impl/src/main/java/org/
   core3/impl/trunk/group-impl/src/main/java/org/cytoscape/
   core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/
   core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/
   
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyActivator.java
   
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupFactoryImpl.java
   
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupImpl.java
   
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupManagerImpl.java
   core3/impl/trunk/group-impl/src/test/
   core3/impl/trunk/group-impl/src/test/java/
   core3/impl/trunk/group-impl/src/test/java/org/
   core3/impl/trunk/group-impl/src/test/java/org/cytoscape/
   core3/impl/trunk/group-impl/src/test/java/org/cytoscape/group/
   
core3/impl/trunk/group-impl/src/test/java/org/cytoscape/group/CyGroupTest.java
   
core3/impl/trunk/group-impl/src/test/java/org/cytoscape/group/TestCyGroupFactory.java
Log:
Group api implementation


Added: core3/impl/trunk/group-impl/pom.xml
===================================================================
--- core3/impl/trunk/group-impl/pom.xml                         (rev 0)
+++ core3/impl/trunk/group-impl/pom.xml 2012-01-24 00:30:35 UTC (rev 28081)
@@ -0,0 +1,126 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+       <parent>
+               <groupId>org.cytoscape</groupId>
+               <artifactId>impl-parent</artifactId>
+               <version>3.0.0-alpha8-SNAPSHOT</version>
+       </parent>
+
+  <properties>
+    <bundle.symbolicName>org.cytoscape.group-impl</bundle.symbolicName>
+    <bundle.namespace>org.cytoscape.group.internal</bundle.namespace>
+  </properties>
+
+       <modelVersion>4.0.0</modelVersion>
+  <groupId>org.cytoscape</groupId>
+  <artifactId>group-impl</artifactId>
+
+  <name>${bundle.symbolicName}</name>
+
+  <packaging>bundle</packaging>
+
+       <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>${maven-surefire-plugin.version}</version>
+        <configuration>
+          <redirectTestOutputToFile>true</redirectTestOutputToFile>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>${maven-bundle-plugin.version}</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
+            <Bundle-Version>${project.version}</Bundle-Version>
+                        <Export-Package>!${bundle.namespace}.*</Export-Package>
+                        
<Private-Package>${bundle.namespace}.*</Private-Package>
+                        
<Bundle-Activator>${bundle.namespace}.CyActivator</Bundle-Activator>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+       </build>
+
+       <repositories>
+               <repository>
+                       <id>cytoscape_snapshots</id>
+                       <snapshots>
+                               <enabled>true</enabled>
+                       </snapshots>
+                       <releases>
+                               <enabled>false</enabled>
+                       </releases>
+                       <name>Cytoscape Snapshots</name>
+                       
<url>http://code.cytoscape.org/nexus/content/repositories/snapshots/</url>
+               </repository>
+               <repository>
+                       <id>cytoscape_releases</id>
+                       <snapshots>
+                               <enabled>false</enabled>
+                       </snapshots>
+                       <releases>
+                               <enabled>true</enabled>
+                       </releases>
+                       <name>Cytoscape Releases</name>
+                       
<url>http://code.cytoscape.org/nexus/content/repositories/releases/</url>
+               </repository>
+       </repositories>
+
+       <dependencies>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>group-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>group-api</artifactId>
+                       <scope>test</scope>
+                       <type>test-jar</type>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>model-impl</artifactId>
+                       <scope>test</scope>
+                       <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>model-impl</artifactId>
+                       <scope>test</scope>
+                       <type>test-jar</type>
+                       <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>event-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>model-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>service-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.mockito</groupId>
+                       <artifactId>mockito-all</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>com.googlecode.guava-osgi</groupId>
+                       <artifactId>guava-osgi</artifactId>
+                       <version>9.0.0</version>
+               </dependency>
+       </dependencies>
+</project>
+

Added: 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyActivator.java
                             (rev 0)
+++ 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyActivator.java
     2012-01-24 00:30:35 UTC (rev 28081)
@@ -0,0 +1,36 @@
+
+package org.cytoscape.group.internal;
+
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.service.util.CyServiceRegistrar;
+
+import org.cytoscape.group.CyGroupManager;
+import org.cytoscape.group.CyGroupFactory;
+
+
+import org.osgi.framework.BundleContext;
+
+import org.cytoscape.service.util.AbstractCyActivator;
+
+import java.util.Properties;
+
+
+public class CyActivator extends AbstractCyActivator {
+       public CyActivator() {
+               super();
+       }
+
+       public void start(BundleContext bc) {
+
+               CyEventHelper cyEventHelperServiceRef = 
getService(bc,CyEventHelper.class);
+               CyServiceRegistrar cyServiceRegistrarServiceRef = 
getService(bc,CyServiceRegistrar.class);
+               
+               CyGroupManagerImpl cyGroupManager = new 
CyGroupManagerImpl(cyEventHelperServiceRef);
+               CyGroupFactoryImpl cyGroupFactory = new 
CyGroupFactoryImpl(cyEventHelperServiceRef, 
+                                                                          
cyGroupManager, 
+                                                                          
cyServiceRegistrarServiceRef);
+               registerService(bc,cyGroupManager,CyGroupManager.class, new 
Properties());
+               registerService(bc,cyGroupFactory,CyGroupFactory.class, new 
Properties());
+       }
+}
+

Added: 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupFactoryImpl.java
===================================================================
--- 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupFactoryImpl.java
                              (rev 0)
+++ 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupFactoryImpl.java
      2012-01-24 00:30:35 UTC (rev 28081)
@@ -0,0 +1,99 @@
+/*
+ Copyright (c) 2008, 2010-2011, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library 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.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.group.internal;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.group.CyGroup;
+import org.cytoscape.group.CyGroupFactory;
+import org.cytoscape.group.CyGroupManager;
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.service.util.CyServiceRegistrar;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CyGroupFactoryImpl implements CyGroupFactory {
+       private static final Logger logger = 
LoggerFactory.getLogger(CyGroupFactoryImpl.class);
+       
+       private final CyEventHelper help;
+       private final CyGroupManagerImpl mgr;
+       private final CyServiceRegistrar serviceRegistrar;
+
+       /**
+        * Creates a new CyNetworkFactoryImpl object.
+        *
+        * @param help An instance of CyEventHelper. 
+        */
+       public CyGroupFactoryImpl(final CyEventHelper help, final 
CyGroupManagerImpl mgr,
+                                   final CyServiceRegistrar serviceRegistrar)
+       {
+               if (help == null)
+                       throw new NullPointerException("CyEventHelper is 
null!");
+
+               if (mgr == null)
+                       throw new NullPointerException("CyGroupManager is 
null!");
+
+               if (serviceRegistrar == null)
+                       throw new NullPointerException("CyServiceRegistrar is 
null!");
+
+               this.help             = help;
+               this.mgr              = mgr;
+               this.serviceRegistrar = serviceRegistrar;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public CyGroup createGroup(CyNetwork network) {
+               return new CyGroupImpl(help, mgr, network, null, null, null);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public CyGroup createGroup(CyNetwork network, List<CyNode> nodes, 
List<CyEdge> edges) {
+               return new CyGroupImpl(help, mgr, network, null, nodes, edges);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public CyGroup createGroup(CyNetwork network, CyNode node, List<CyNode> 
nodes, List<CyEdge> edges) {
+               return new CyGroupImpl(help, mgr, network, node, nodes, edges);
+       }
+}

Added: 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupImpl.java
===================================================================
--- 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupImpl.java
                             (rev 0)
+++ 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupImpl.java
     2012-01-24 00:30:35 UTC (rev 28081)
@@ -0,0 +1,394 @@
+/*
+ Copyright (c) 2008, 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library 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.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.group.internal;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.group.CyGroup;
+import org.cytoscape.group.CyGroupManager;
+import org.cytoscape.group.events.GroupAboutToBeRemovedEvent;
+import org.cytoscape.group.events.GroupAddedToNetworkEvent;
+import org.cytoscape.group.events.GroupCollapsedEvent;
+
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.subnetwork.CyRootNetwork;
+import org.cytoscape.model.subnetwork.CySubNetwork;
+
+
+class CyGroupImpl implements CyGroup {
+       final private CyEventHelper cyEventHelper;
+       final private CyGroupManager mgr;
+
+       private CyNode groupNode;
+       private CySubNetwork groupNet;
+       private Set<CyEdge> externalEdges;
+       private Set<CyEdge> metaEdges;
+       private CyRootNetwork rootNetwork = null;
+       private Set<CyNetwork> networkSet = null;
+       private Set<CyNetwork> collapseSet = null;
+
+       CyGroupImpl(final CyEventHelper eventHelper, 
+                   final CyGroupManager mgr, CyNetwork network, CyNode node,
+                   List<CyNode>nodes, List<CyEdge>edges) {
+               this.cyEventHelper = eventHelper;
+               this.mgr = mgr;
+
+               this.rootNetwork = ((CySubNetwork)network).getRootNetwork();
+               if (node == null)
+                       this.groupNode = this.rootNetwork.addNode();
+               else
+                       this.groupNode = node;
+
+               this.externalEdges = new HashSet<CyEdge>();
+               this.metaEdges = new HashSet<CyEdge>();
+               this.networkSet = new HashSet<CyNetwork>();
+               this.collapseSet = new HashSet<CyNetwork>();
+
+               networkSet.add(network);
+
+               if (nodes == null)
+                       nodes = new ArrayList<CyNode>();
+
+               Set<CyNode> nodeMap = new HashSet<CyNode>(nodes);
+
+               if (edges != null) {
+                       List<CyEdge> intEdges = new ArrayList<CyEdge>();
+                       // Remove those edges in the list that aren't attached 
to nodes in
+                       // the list.  Otherwise, we'll wind up adding nodes to 
the group
+                       // that the user didn't request.
+                       for (CyEdge e: edges) {
+                               if (nodeMap.contains(e.getSource()) && 
nodeMap.contains(e.getTarget())) {
+                                       intEdges.add(e);
+                               } else {
+                                       externalEdges.add(e);
+                               }
+                       }
+                       edges = intEdges;
+               } else if (edges == null) {
+                       // Create the edge lists
+                       edges = new ArrayList<CyEdge>();
+
+                       // Get all of the edges and put them in the right lists
+                       for (CyNode n: nodes) {
+                               List<CyEdge> aEdges = 
network.getAdjacentEdgeList(n, CyEdge.Type.ANY);
+                               for (CyEdge e: aEdges) {
+                                       if (nodeMap.contains(e.getSource()) && 
nodeMap.contains(e.getTarget()))
+                                               edges.add(e);
+                                       else {
+                                               // This is an external edge, 
which means that we need to create
+                                               // a corresponding meta-edge
+                                               externalEdges.add(e);
+                                               CyNode source = e.getSource();
+                                               CyNode target = e.getTarget();
+                                               boolean directed = 
e.isDirected();
+                                               if (nodeMap.contains(source))
+                                                       source = groupNode;
+                                               else
+                                                       target = groupNode;
+                                               
metaEdges.add(rootNetwork.addEdge(source, target, directed));
+                                       }
+                               }
+                       }
+               }
+
+               // Create the subnetwork
+               groupNet = rootNetwork.addSubNetwork(nodes, edges);
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#getGroupNode()
+        */
+       @Override
+       public CyNode getGroupNode() {
+               return groupNode;
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#getNodeList()
+        */
+       @Override
+       public List<CyNode> getNodeList() {
+               return groupNet.getNodeList();
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#getContainedEdgeList()
+        */
+       @Override
+       public List<CyEdge> getInteriorEdgeList() {
+               return groupNet.getEdgeList();
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#getExteriorEdgeList()
+        */
+       @Override
+       public Set<CyEdge> getExteriorEdgeList() {
+               return externalEdges;
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#getGroupNetwork()
+        */
+       @Override
+       public CyNetwork getGroupNetwork() {
+               return groupNet;
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#addNode()
+        */
+       @Override
+       public void addNode(CyNode node) {
+               if (!rootNetwork.containsNode(node))
+                       throw new IllegalArgumentException("Can only add a node 
in the same network tree");
+               groupNet.addNode(node);
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#addInternalEdge()
+        */
+       @Override
+       public void addInternalEdge(CyEdge edge) {
+               if (!rootNetwork.containsEdge(edge))
+                       throw new IllegalArgumentException("Can only add an 
edge in the same network tree");
+               groupNet.addEdge(edge);
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#addExternalEdge()
+        */
+       @Override
+       public void addExternalEdge(CyEdge edge) {
+               if (!rootNetwork.containsEdge(edge))
+                       throw new IllegalArgumentException("Can only add an 
edge in the same network tree");
+               if (!externalEdges.contains(edge))
+                       externalEdges.add(edge);
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#addNodes()
+        */
+       @Override
+       public void addNodes(List<CyNode> nodes) {
+               Set<CyEdge> edgeSet = new HashSet<CyEdge>();
+               for (CyNode n: nodes) {
+                       if (!rootNetwork.containsNode(n))
+                               throw new IllegalArgumentException("Can only 
add a node in the same network tree");
+
+                       addNode(n);
+                       edgeSet.addAll(rootNetwork.getAdjacentEdgeList(n, 
CyEdge.Type.ANY));
+               }
+
+               for (CyEdge e: edgeSet) {
+                       if (groupNet.containsNode(e.getSource()) && 
groupNet.containsNode(e.getTarget())) {
+                               addInternalEdge(e);
+                       } else {
+                               addExternalEdge(e);
+                       }
+               }
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#removeNodes()
+        */
+       @Override
+       public void removeNodes(Collection<CyNode> nodes) {
+               groupNet.removeNodes(nodes);
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#getRootNetwork()
+        */
+       @Override
+       public CyRootNetwork getRootNetwork() {
+               return this.rootNetwork;
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#getNetworkSet()
+        */
+       @Override
+       public Set<CyNetwork> getNetworkSet() {
+               return networkSet;
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#isInNetwork()
+        */
+       @Override
+       public boolean isInNetwork(CyNetwork network) {
+               return networkSet.contains(network);
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#addGroupToNetwork()
+        */
+       @Override
+       public synchronized void addGroupToNetwork(CyNetwork network) {
+               // First, we need to make sure this network is in the same
+               // root network as the group node
+               if (!inSameRoot(network))
+                       throw new IllegalArgumentException("Network not in same 
root network as group");
+
+               if(!networkSet.contains(network))
+                       networkSet.add(network);
+
+               // Notify
+               cyEventHelper.fireEvent(new 
GroupAddedToNetworkEvent(CyGroupImpl.this, network));
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#removeGroupFromNetwork()
+        */
+       @Override
+       public synchronized void removeGroupFromNetwork(CyNetwork network) {
+               // Notify
+               cyEventHelper.fireEvent(new 
GroupAboutToBeRemovedEvent(CyGroupImpl.this, network));
+
+               if(networkSet.contains(network))
+                       networkSet.remove(network);
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#collapse()
+        */
+       @Override
+       public void collapse(CyNetwork net) {
+               if (isCollapsed(net))
+                       return; // Already collapsed
+
+               if (!networkSet.contains(net))
+                       return; // We're not in that network
+
+               CySubNetwork subnet = (CySubNetwork) net;
+
+               // Collapse it.
+               // Remove all of the nodes from the target network
+               subnet.removeNodes(getNodeList());
+
+               subnet.addNode(groupNode);
+
+               // Add the group node and it's edges
+               List<CyEdge> groupNodeEdges = 
rootNetwork.getAdjacentEdgeList(groupNode, CyEdge.Type.ANY);
+               for (CyEdge e: groupNodeEdges)
+                       subnet.addEdge(e);
+
+               Set<CyNode> memberNodes = new HashSet<CyNode>(getNodeList());
+
+               // Add the meta-edges
+               for (CyEdge e: getMetaEdgeList()) {
+                       subnet.addEdge(e);
+               }
+
+               collapseSet.add(net);
+               cyEventHelper.fireEvent(new 
GroupCollapsedEvent(CyGroupImpl.this, net, true));
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#expand()
+        */
+       @Override
+       public void expand(CyNetwork net) {
+               if (!isCollapsed(net))
+                       return; // Already expanded
+
+               if (!networkSet.contains(net))
+                       return; // We're not in that network
+
+               CySubNetwork subnet = (CySubNetwork) net;
+
+               // Expand it.
+               // Remove the group node from the target network
+               List<CyNode> nodesToRemove = new ArrayList<CyNode>();
+               nodesToRemove.add(groupNode);
+               subnet.removeNodes(nodesToRemove);
+
+               // Add all of the member nodes and edges in
+               for (CyNode n: getNodeList())
+                       subnet.addNode(n);
+
+               // Add all of the interior edges in
+               for (CyEdge e: getInteriorEdgeList())
+                       subnet.addEdge(e);
+
+               // Add all of the exterior edges in
+               for (CyEdge e: getExteriorEdgeList()) {
+                       // We need to be careful to only add the edge in
+                       // if both the edge and the target are available
+                       // since the target node might have been part of a
+                       // collapsed group
+                       if (subnet.containsNode(e.getSource()) && 
subnet.containsNode(e.getTarget()))
+                               subnet.addEdge(e);
+               }
+
+               collapseSet.remove(net);
+               cyEventHelper.fireEvent(new 
GroupCollapsedEvent(CyGroupImpl.this, net, false));
+       }
+
+       /**
+        * @see org.cytoscape.group.CyGroup#isCollapsed()
+        */
+       @Override
+       public boolean isCollapsed(CyNetwork net) {
+               System.out.println("collapseSet = "+collapseSet);
+               System.out.println("collapseSet has "+collapseSet.size()+" 
elements");
+               return collapseSet.contains(net);
+       }
+
+       protected void addMetaEdge(CyEdge edge) {
+               if (!metaEdges.contains(edge))
+                       metaEdges.add(edge);
+       }
+
+       protected Set<CyEdge> getMetaEdgeList() {
+               return metaEdges;
+       }
+
+       @Override
+       public String toString() {
+               return "Group suid: " + groupNode.getSUID() + " node: " + 
groupNode;
+       }
+
+       private boolean inSameRoot(CyNetwork network) {
+               CyRootNetwork root = ((CySubNetwork) network).getRootNetwork();
+               if (!root.equals(rootNetwork))
+                       return false;
+               return true;
+       }
+}

Added: 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupManagerImpl.java
===================================================================
--- 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupManagerImpl.java
                              (rev 0)
+++ 
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupManagerImpl.java
      2012-01-24 00:30:35 UTC (rev 28081)
@@ -0,0 +1,131 @@
+/*
+ File: NetworkManager.java
+
+ Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library 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.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.cytoscape.group.internal;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.group.CyGroup;
+import org.cytoscape.group.CyGroupFactory;
+import org.cytoscape.group.CyGroupManager;
+import org.cytoscape.group.events.GroupAboutToBeDestroyedEvent;
+import org.cytoscape.group.events.GroupAddedEvent;
+
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.subnetwork.CyRootNetwork;
+import org.cytoscape.model.subnetwork.CySubNetwork;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An implementation of CyNetworkManager.
+ */
+public class CyGroupManagerImpl implements CyGroupManager {
+
+       private final CyEventHelper cyEventHelper;
+       private static final Logger logger = 
LoggerFactory.getLogger(CyGroupManagerImpl.class);
+
+       private Set<CyGroup> groupSet;
+       /**
+        * 
+        * @param cyEventHelper
+        */
+       public CyGroupManagerImpl(final CyEventHelper cyEventHelper) {
+               this.groupSet = new HashSet<CyGroup>();
+               this.cyEventHelper = cyEventHelper;
+       }
+
+       @Override
+       public synchronized Set<CyGroup> getGroupSet(CyNetwork network) {
+               Set<CyGroup> groupNetSet = new HashSet<CyGroup>();
+               for (CyGroup group: groupSet) {
+                       if (group.isInNetwork(network))
+                               groupNetSet.add(group);
+               }
+               return groupNetSet;
+       }
+
+       @Override
+       public synchronized void addGroup(final CyGroup group) {
+               if (!groupSet.contains(group)) {
+                       groupSet.add(group);
+                       cyEventHelper.fireEvent(new 
GroupAddedEvent(CyGroupManagerImpl.this, group));
+               }
+       }
+
+       @Override
+       public synchronized List<CyGroup> getGroupsForNode(CyNode node) {
+               List<CyGroup> returnList = new ArrayList<CyGroup>();
+
+               // This is a little inefficient....
+               for (CyGroup group: groupSet) {
+                       if (group.getGroupNetwork().containsNode(node))
+                               returnList.add(group);
+               }
+
+               return returnList;
+       }
+
+       @Override
+       public synchronized boolean isGroup(CyNode node, CyNetwork network) {
+               for (CyGroup group: groupSet) {
+                       if (group.isInNetwork(network) && 
group.getGroupNode().equals(node))
+                               return true;
+               }
+
+               return false;
+       }
+
+       @Override
+       public synchronized void destroyGroup(CyGroup group) {
+               if (!groupSet.contains(group))
+                       return;
+
+               cyEventHelper.fireEvent(new 
GroupAboutToBeDestroyedEvent(CyGroupManagerImpl.this, group));
+
+               groupSet.remove(group);
+               for (CyNetwork network: group.getNetworkSet())
+                       group.removeGroupFromNetwork(network);
+       }
+
+       @Override
+       public synchronized void reset() {
+               this.groupSet = new HashSet<CyGroup>();
+       }
+
+}

Added: 
core3/impl/trunk/group-impl/src/test/java/org/cytoscape/group/CyGroupTest.java
===================================================================
--- 
core3/impl/trunk/group-impl/src/test/java/org/cytoscape/group/CyGroupTest.java  
                            (rev 0)
+++ 
core3/impl/trunk/group-impl/src/test/java/org/cytoscape/group/CyGroupTest.java  
    2012-01-24 00:30:35 UTC (rev 28081)
@@ -0,0 +1,52 @@
+/*
+ Copyright (c) 2008, 2011, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library 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.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.group;
+
+
+import org.junit.After;
+import org.junit.Before;
+
+import org.cytoscape.group.AbstractCyGroupTest;
+import org.cytoscape.model.NetworkTestSupport;
+
+
+public class CyGroupTest extends AbstractCyGroupTest {
+       @Before
+       public void setUp() {
+               NetworkTestSupport support = new NetworkTestSupport();
+               net = support.getNetwork();
+               groupFactory = TestCyGroupFactory.getFactory();
+               defaultSetUp();
+       }
+
+       @After
+       public void tearDown() {
+               net = null;
+               groupFactory = null;
+       }
+}

Added: 
core3/impl/trunk/group-impl/src/test/java/org/cytoscape/group/TestCyGroupFactory.java
===================================================================
--- 
core3/impl/trunk/group-impl/src/test/java/org/cytoscape/group/TestCyGroupFactory.java
                               (rev 0)
+++ 
core3/impl/trunk/group-impl/src/test/java/org/cytoscape/group/TestCyGroupFactory.java
       2012-01-24 00:30:35 UTC (rev 28081)
@@ -0,0 +1,111 @@
+/*
+ Copyright (c) 2008, 2010-2011, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library 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.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.group;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import org.cytoscape.event.DummyCyEventHelper;
+import org.cytoscape.group.internal.CyGroupFactoryImpl;
+import org.cytoscape.group.internal.CyGroupManagerImpl;
+
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.NetworkTestSupport;
+
+import org.cytoscape.model.subnetwork.CyRootNetwork;
+import org.cytoscape.service.util.CyServiceRegistrar;
+import org.junit.Test;
+
+
+public class TestCyGroupFactory {
+       public TestCyGroupFactory() { }
+
+       public static CyGroupFactory getFactory() {
+               DummyCyEventHelper deh = new DummyCyEventHelper();
+               CyGroupManagerImpl mgr = new CyGroupManagerImpl(deh);
+               final CyServiceRegistrar serviceRegistrar = 
mock(CyServiceRegistrar.class);
+               CyGroupFactoryImpl groupFactory = new CyGroupFactoryImpl(deh, 
mgr, serviceRegistrar);
+               return groupFactory; 
+       }
+
+       @Test
+       public void testGroupCreate () throws Exception {
+               CyGroupFactory factory = TestCyGroupFactory.getFactory();
+               // Net to create a network to test this..
+               NetworkTestSupport support = new NetworkTestSupport();
+               
+               CyNetwork network = support.getNetwork();
+
+               // Create some nodes and edges
+               CyNode node1 = network.addNode();
+               CyNode node2 = network.addNode();
+               CyNode node3 = network.addNode();
+               CyNode node4 = network.addNode();
+               CyNode node5 = network.addNode();
+               List<CyNode> groupNodes = new ArrayList<CyNode>();
+               groupNodes.add(node1);
+               groupNodes.add(node2);
+               groupNodes.add(node3);
+
+               CyEdge edge1 = network.addEdge(node1, node2, false);
+               CyEdge edge2 = network.addEdge(node2, node3, false);
+               CyEdge edge3 = network.addEdge(node2, node4, false);
+               CyEdge edge4 = network.addEdge(node2, node5, false);
+               CyEdge edge5 = network.addEdge(node3, node5, false);
+               List<CyEdge> groupEdges = new ArrayList<CyEdge>();
+               groupEdges.add(edge1);
+               groupEdges.add(edge2);
+               groupEdges.add(edge3);
+               groupEdges.add(edge4);
+
+               CyGroup group1 = factory.createGroup(network, groupNodes, null);
+               assertNotNull(group1);
+               assertTrue("group1 node count = 3", group1.getNodeList().size() 
== 3);
+               assertTrue("group1 internal edge count = 2", 
group1.getInteriorEdgeList().size() == 2);
+               assertTrue("group1 external edge count = 3", 
group1.getExteriorEdgeList().size() == 3);
+               CyGroup group2 = factory.createGroup(network, groupNodes, new 
ArrayList<CyEdge>());
+               assertNotNull(group2);
+               assertTrue("group2 node count = 3", group2.getNodeList().size() 
== 3);
+               assertTrue("group2 internal edge count = 0", 
group2.getInteriorEdgeList().size() == 0);
+               assertTrue("group2 external edge count = 0", 
group2.getExteriorEdgeList().size() == 0);
+               CyGroup group3 = factory.createGroup(network, groupNodes, 
groupEdges);
+               assertNotNull(group3);
+               assertTrue("group3 node count = 3", group3.getNodeList().size() 
== 3);
+               assertTrue("group3 internal edge count = 2", 
group3.getInteriorEdgeList().size() == 2);
+               assertTrue("group3 external edge count = 2", 
group3.getExteriorEdgeList().size() == 2);
+       }
+
+}
+

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to