Author: rozagh
Date: 2012-02-16 11:40:53 -0800 (Thu, 16 Feb 2012)
New Revision: 28298

Modified:
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/util/undo/UndoMonitor.java
Log:
fixes #637 Listener handlers for NetworkDestroy and NetworkViewDestroy events 
are implemented in the undoMonitor class which discard the edits when the last 
view or the last network is destroyed. The SetCurrentNetworkView listener 
handles the other situations where the undo stack needs to be cleaned out.

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
       2012-02-16 19:29:07 UTC (rev 28297)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
       2012-02-16 19:40:53 UTC (rev 28298)
@@ -98,6 +98,7 @@
 import org.cytoscape.model.CyNetworkFactory;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.events.NetworkDestroyedListener;
 import org.cytoscape.property.CyProperty;
 import org.cytoscape.property.bookmark.BookmarksUtil;
 import org.cytoscape.service.util.AbstractCyActivator;
@@ -116,6 +117,7 @@
 import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
 import org.cytoscape.view.model.CyNetworkViewFactory;
 import org.cytoscape.view.model.CyNetworkViewManager;
+import org.cytoscape.view.model.events.NetworkViewDestroyedListener;
 import org.cytoscape.view.presentation.RenderingEngineFactory;
 import org.cytoscape.view.vizmap.VisualMappingManager;
 import org.cytoscape.work.SynchronousTaskManager;
@@ -360,6 +362,8 @@
                registerAllServices(bc, networkViewManager, new Properties());
                registerAllServices(bc, birdsEyeViewHandler, new Properties());
                registerService(bc, undoMonitor, 
SetCurrentNetworkViewListener.class, new Properties());
+               registerService(bc, undoMonitor, 
NetworkDestroyedListener.class, new Properties());
+               registerService(bc, undoMonitor, 
NetworkViewDestroyedListener.class, new Properties());
                registerAllServices(bc, rowViewTracker, new Properties());
                registerAllServices(bc, selecteEdgeViewUpdater, new 
Properties());
                registerAllServices(bc, selecteNodeViewUpdater, new 
Properties());

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/util/undo/UndoMonitor.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/util/undo/UndoMonitor.java
     2012-02-16 19:29:07 UTC (rev 28297)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/util/undo/UndoMonitor.java
     2012-02-16 19:40:53 UTC (rev 28298)
@@ -38,9 +38,17 @@
 
 import java.util.Properties;
 
+import org.cytoscape.view.model.CyNetworkViewManager;
+import org.cytoscape.view.model.events.NetworkViewDestroyedEvent;
+import org.cytoscape.view.model.events.NetworkViewDestroyedListener;
 import org.cytoscape.work.swing.undo.SwingUndoSupport;
 import org.cytoscape.application.events.SetCurrentNetworkViewEvent;
 import org.cytoscape.application.events.SetCurrentNetworkViewListener;
+import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
+import org.cytoscape.model.events.NetworkDestroyedEvent;
+import org.cytoscape.model.events.NetworkDestroyedListener;
 import org.cytoscape.property.CyProperty;
 
 /**
@@ -48,7 +56,7 @@
  * discard policy we might have. Currently, we discard all edits if
  * the network view focus changes.
  */
-public class UndoMonitor implements SetCurrentNetworkViewListener {
+public class UndoMonitor implements SetCurrentNetworkViewListener, 
NetworkDestroyedListener, NetworkViewDestroyedListener {
 
        private SwingUndoSupport undo;
        private Properties props;
@@ -86,5 +94,37 @@
                if ( e.getNetworkView() != null )
                        undo.getUndoManager().discardAllEdits();
     }
+
+    /**
+        * This method listens for a network destroy event. If the network 
being destroyed 
+        * is the only available network, it discards all of its edits. Hence, 
when more
+        * than one network is available, destruction of an inactive network 
(which does not
+        * have the current network view) will not discard the useful edits of 
the active 
+        * network.
+        * Moreover, if the edits are related to the destroyed network, the
+        * SetCurrentNetwrkViewEvent will handle the discard of edits.
+        *
+        * @param e The change event.
+        */
+       @Override
+       public void handleEvent(NetworkDestroyedEvent e) {
+               if (e.getSource().getNetworkSet().isEmpty())
+                       undo.getUndoManager().discardAllEdits();
+       }
+
+       
+       /**
+        * This method listens for a network view destroy event. If the network 
view being destroyed 
+        * is the only visible view, it discards all of its edits. In case more
+        * than one network view is available, the SetCurrentNetworkView handles
+        * the discard of the edits. 
+        * @param e The change event.
+        */
+       @Override
+       public void handleEvent(NetworkViewDestroyedEvent e) {
+
+               if (e.getSource().getNetworkViewSet().isEmpty())
+                       undo.reset();
+       }
 }
 

-- 
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