Author: kono
Date: 2012-07-31 15:36:34 -0700 (Tue, 31 Jul 2012)
New Revision: 30052

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/select/RowsSetViewUpdater.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
Log:
fixes #1287 Visual Style will be applied when necessary.  Update view will be 
called only when something had been chaned in the view model layer.

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-07-31 22:17:01 UTC (rev 30051)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
       2012-07-31 22:36:34 UTC (rev 30052)
@@ -208,7 +208,7 @@
                                                                               
cyNetworkViewManagerServiceRef, 
                                                                               
renderingEngineManagerServiceRef,
                                                                               
cytoscapePropertiesServiceRef,
-                                                                              
cyHelpBroker);
+                                                                              
cyHelpBroker, visualMappingManagerServiceRef);
 
                BirdsEyeViewHandler birdsEyeViewHandler = new 
BirdsEyeViewHandler(cyApplicationManagerServiceRef,
                                                                                
  dingNavigationPresentationFactoryServiceRef,
@@ -299,7 +299,7 @@
                
                RowsSetViewUpdater rowsSetViewUpdater = new 
RowsSetViewUpdater(cyApplicationManagerServiceRef, 
                                                                               
cyNetworkViewManagerServiceRef, 
-                                                                              
visualMappingManagerServiceRef, rowViewTracker);
+                                                                              
visualMappingManagerServiceRef, rowViewTracker, networkViewManager);
                
                RecentSessionManager recentSessionManager = new 
RecentSessionManager(recentlyOpenedTrackerServiceRef,
                                                                                
     cyServiceRegistrarServiceRef,

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/select/RowsSetViewUpdater.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/select/RowsSetViewUpdater.java
 2012-07-31 22:17:01 UTC (rev 30051)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/select/RowsSetViewUpdater.java
 2012-07-31 22:36:34 UTC (rev 30052)
@@ -6,11 +6,14 @@
 import javax.swing.SwingUtilities;
 
 import org.cytoscape.application.CyApplicationManager;
+import org.cytoscape.internal.view.NetworkViewManager;
+import org.cytoscape.model.CyColumn;
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyIdentifiable;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyRow;
+import org.cytoscape.model.VirtualColumnInfo;
 import org.cytoscape.model.events.RowSetRecord;
 import org.cytoscape.model.events.RowsSetEvent;
 import org.cytoscape.model.events.RowsSetListener;
@@ -22,93 +25,129 @@
 import org.cytoscape.view.vizmap.VisualMappingManager;
 import org.cytoscape.view.vizmap.VisualStyle;
 
-
+/**
+ * Once table values are modified, this object updates the views if necessary.
+ * 
+ */
 public class RowsSetViewUpdater implements RowsSetListener {
 
-       private VisualMappingManager vmm;
+       private final VisualMappingManager vmm;
        private final Map<CyRow, View<?>> rowViewMap;
        private final CyNetworkViewManager vm;
        private final CyApplicationManager am;
-       /**
-        * Constructor.
-        */
-       public RowsSetViewUpdater(CyApplicationManager am, CyNetworkViewManager 
vm, VisualMappingManager vmm, RowViewTracker tracker) {
+       private final NetworkViewManager viewManager;
+       
+
+       private VisualMappingFunction<?, ?> targetFunction;
+
+       public RowsSetViewUpdater(final CyApplicationManager am, final 
CyNetworkViewManager vm,
+                       final VisualMappingManager vmm, final RowViewTracker 
tracker, final NetworkViewManager viewManager) {
                this.am = am;
                this.vm = vm;
                this.vmm = vmm;
+               this.viewManager = viewManager;
                this.rowViewMap = tracker.getRowViewMap();
        }
 
-       
        /**
         * Called whenever {@link CyRow}s are changed. Will attempt to set the
         * visual property on the view with the new value that has been set in 
the
         * row.
         * 
-        * @param RowsSetEvent The event to be processed.
+        * @param RowsSetEvent
+        *            The event to be processed.
         */
-       @SuppressWarnings("unchecked")
+       @Override
        public void handleEvent(final RowsSetEvent e) {
-
                SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
+                               updateView(e);
+                       }
+               });
+       }
 
-                               boolean refreshView = false;
-                               final CyNetwork network = 
am.getCurrentNetwork();
-                               if (network == null)
-                                       return;
+       private final void updateView(final RowsSetEvent e) {
+               boolean refreshView = false;
+               boolean refreshOtherViews = false;
+               
+               final CyNetwork network = am.getCurrentNetwork();
+               if (network == null)
+                       return;
+               
+               // 1: Update current network view
+               final Collection<CyNetworkView> views = 
vm.getNetworkViews(network);
+               CyNetworkView networkView = null;
+               if (views.isEmpty())
+                       return;
+               else
+                       networkView = views.iterator().next();
 
-                               final Collection<CyNetworkView> views = 
vm.getNetworkViews(network);
-                               CyNetworkView networkView = null;
-                               if (views.size() != 0)
-                                       networkView = views.iterator().next();
+               final VisualStyle vs = vmm.getVisualStyle(networkView);
+               
+               for (final RowSetRecord record : e.getPayloadCollection()) {
+                       
+                       final CyRow row = record.getRow();
+                       final String columnName = record.getColumn();
+                       final CyColumn column = 
row.getTable().getColumn(columnName);
+                       final VirtualColumnInfo virtualColInfo = 
column.getVirtualColumnInfo();
+                       final boolean virtual = virtualColInfo.isVirtual();
+                       final View<?> v = rowViewMap.get(row);
 
-                               if (networkView == null)
-                                       return;
+                       if (v == null)
+                               continue;
 
-                               final VisualStyle vs = 
vmm.getVisualStyle(networkView);
+                       VisualProperty<?> vp = null;
+
+                       if (v.getModel() instanceof CyNode) {
+                               final CyNode node = (CyNode) v.getModel();
+                               if (network.containsNode(node))
+                                       vp = getVPfromVS(vs, columnName);
+                       } else if (v.getModel() instanceof CyEdge) {
+                               final CyEdge edge = (CyEdge) v.getModel();
+                               if (network.containsEdge(edge))
+                                       vp = getVPfromVS(vs, columnName);
+                       } else {
+                               // FIXME: NETWORK?
+                       }
+
+                       if (vp != null) {
+                               targetFunction.apply(record.getRow(), (View<? 
extends CyIdentifiable>) v);
+                               refreshView = true;
                                
-                               for (final RowSetRecord record : 
e.getPayloadCollection()) {
-                                       final String columnName = 
record.getColumn();
-                                       final View<?> v = 
rowViewMap.get(record.getRow());
+                               // If virtual, it may be used in other networks.
+                               if(virtual)
+                                       refreshOtherViews = true;
+                       }
+               }
 
-                                       if (v == null)
+               if (refreshView) {
+                       vs.apply(networkView);
+                       networkView.updateView();
+                       
+                       if (refreshOtherViews) {
+                               // Check other views. If update is required, 
set the flag.
+                               for (final CyNetworkView view : 
vm.getNetworkViewSet()) {
+                                       if (view == networkView)
                                                continue;
 
-                                       VisualProperty<?> vp = null;
-                                       if (v.getModel() instanceof CyNode) {
-                                               final CyNode node = (CyNode) 
v.getModel();
-                                               if (network.containsNode(node))
-                                                       vp = getVPfromVS(vs, 
columnName);
-                                       } else if (v.getModel() instanceof 
CyEdge) {
-                                               final CyEdge edge = (CyEdge) 
v.getModel();
-
-                                               if (network.containsEdge(edge))
-                                                       vp = getVPfromVS(vs, 
columnName);
+                                       final VisualStyle style = 
vmm.getVisualStyle(view);
+                                       if (style == vs) {
+                                               // Same style is in use. Need 
to apply.
+                                               viewManager.setUpdateFlag(view);
                                        }
-
-                                       if (vp != null) {
-                                               
targetFunction.apply(record.getRow(), (View<? extends CyIdentifiable>) v);
-                                               refreshView = true;
-                                       }
                                }
-
-                               if (refreshView)
-                                       networkView.updateView();
                        }
-               });
+               }
        }
-       
-       private VisualMappingFunction<?, ?> targetFunction;
-       
+
        // Check if the columnName is the name of mapping attribute in 
visualStyle,
        // If yes, return the VisualProperty associated with this columnName
-       private VisualProperty<?> getVPfromVS(VisualStyle vs, String 
columnName){
+       private VisualProperty<?> getVPfromVS(VisualStyle vs, String 
columnName) {
                VisualProperty<?> vp = null;
-               final Collection<VisualMappingFunction<?,?>> vmfs = 
vs.getAllVisualMappingFunctions();
-               
-               for(final VisualMappingFunction<?,?> f: vmfs) {
-                       if 
(f.getMappingColumnName().equalsIgnoreCase(columnName)){
+               final Collection<VisualMappingFunction<?, ?>> vmfs = 
vs.getAllVisualMappingFunctions();
+
+               for (final VisualMappingFunction<?, ?> f : vmfs) {
+                       if 
(f.getMappingColumnName().equalsIgnoreCase(columnName)) {
                                vp = f.getVisualProperty();
                                targetFunction = f;
                                break;

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
   2012-07-31 22:17:01 UTC (rev 30051)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
   2012-07-31 22:36:34 UTC (rev 30052)
@@ -45,8 +45,10 @@
 import java.beans.PropertyVetoException;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.WeakHashMap;
 
 import javax.swing.JDesktopPane;
@@ -81,6 +83,8 @@
 import org.cytoscape.view.presentation.RenderingEngineFactory;
 import org.cytoscape.view.presentation.RenderingEngineManager;
 import org.cytoscape.view.presentation.property.BasicVisualLexicon;
+import org.cytoscape.view.vizmap.VisualMappingManager;
+import org.cytoscape.view.vizmap.VisualStyle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -106,6 +110,7 @@
        // Key is MODEL ID
        private final Map<CyNetworkView, JInternalFrame> 
presentationContainerMap;
        private final Map<CyNetworkView, RenderingEngine<CyNetwork>> 
presentationMap;
+       private final Set<CyNetworkView> viewUpdateRequired;
 
        private final Map<JInternalFrame, CyNetworkView> iFrameMap;
        private final Map<JInternalFrame, InternalFrameListener> frameListeners;
@@ -125,13 +130,14 @@
        private final CyNetworkViewManager netViewMgr;
        private final CyApplicationManager appMgr;
        private final RenderingEngineManager renderingEngineMgr;
+       private final VisualMappingManager vmm;
        
        
        public NetworkViewManager(final CyApplicationManager appMgr,
                                                          final 
CyNetworkViewManager netViewMgr,
                                                          final 
RenderingEngineManager renderingEngineManager,
                                                          final 
CyProperty<Properties> cyProps,
-                                                         final CyHelpBroker 
help) {
+                                                         final CyHelpBroker 
help, final VisualMappingManager vmm) {
 
                if (appMgr == null)
                        throw new NullPointerException("CyApplicationManager is 
null.");
@@ -145,6 +151,7 @@
                this.netViewMgr = netViewMgr;
                this.appMgr = appMgr;
                this.props = cyProps.getProperties();
+               this.vmm = vmm;
 
                this.desktopPane = new JDesktopPane();
 
@@ -155,6 +162,7 @@
                presentationMap = new WeakHashMap<CyNetworkView, 
RenderingEngine<CyNetwork>>();
                iFrameMap = new WeakHashMap<JInternalFrame, CyNetworkView>();
                frameListeners = new HashMap<JInternalFrame, 
InternalFrameListener>();
+               viewUpdateRequired = new HashSet<CyNetworkView>();
        }
 
        /**
@@ -221,18 +229,25 @@
         */
        @Override
        public void internalFrameActivated(InternalFrameEvent e) {
-               final CyNetworkView view = iFrameMap.get(e.getInternalFrame());
+               final CyNetworkView targetView = 
iFrameMap.get(e.getInternalFrame());
                
-               if (view != null) {
+               if (targetView != null) {
                        final RenderingEngine<CyNetwork> currentEngine = 
appMgr.getCurrentRenderingEngine();
                        
-                       if (netViewMgr.getNetworkViewSet().contains(view)) {
-                               if 
(!view.equals(appMgr.getCurrentNetworkView()))
-                                       appMgr.setCurrentNetworkView(view);
+                       if 
(netViewMgr.getNetworkViewSet().contains(targetView)) {
+                               if 
(!targetView.equals(appMgr.getCurrentNetworkView()))
+                                       
appMgr.setCurrentNetworkView(targetView);
        
-                               if (currentEngine == null || 
currentEngine.getViewModel() != view)
-                                       
appMgr.setCurrentRenderingEngine(presentationMap.get(view));
+                               if (currentEngine == null || 
currentEngine.getViewModel() != targetView)
+                                       
appMgr.setCurrentRenderingEngine(presentationMap.get(targetView));
                        }
+                       
+                       if(viewUpdateRequired.contains(targetView)) {
+                               viewUpdateRequired.remove(targetView);
+                               final VisualStyle style = 
vmm.getVisualStyle(targetView);
+                               style.apply(targetView);
+                               targetView.updateView();
+                       }
                }
        }
 
@@ -586,4 +601,8 @@
                
                return iFrameMap.get(selectedFrame);
        }
+       
+       public void setUpdateFlag(CyNetworkView view) {
+               this.viewUpdateRequired.add(view);
+       }
 }

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