Author: kono
Date: 2011-05-02 17:46:04 -0700 (Mon, 02 May 2011)
New Revision: 24894

Added:
   
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NullCyNetworkView.java
Modified:
   
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NetworkViewFactoryImpl.java
   
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NetworkViewImpl.java
   
core3/viewmodel-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
   
core3/viewmodel-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
Log:
NullCyNetworkView is hidden in implementation bundle.  To test null object or 
not, use isNullView() method instead.

Modified: 
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NetworkViewFactoryImpl.java
===================================================================
--- 
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NetworkViewFactoryImpl.java
 2011-05-03 00:45:44 UTC (rev 24893)
+++ 
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NetworkViewFactoryImpl.java
 2011-05-03 00:46:04 UTC (rev 24894)
@@ -4,39 +4,81 @@
 
 import org.cytoscape.event.CyEventHelper;
 import org.cytoscape.model.CyNetwork;
+import org.cytoscape.property.CyProperty;
 import org.cytoscape.service.util.CyServiceRegistrar;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.CyNetworkViewFactory;
 
 public class NetworkViewFactoryImpl implements CyNetworkViewFactory {
 
-       private final CyEventHelper eventHelper;
-       private final CyServiceRegistrar registrar;
+    private final String VIEW_THRESHOLD = "viewThreshold";
 
-       /**
-        * For injection, use this constructor.
-        * 
-        * @param eventHelper
-        */
-       public NetworkViewFactoryImpl(final CyEventHelper eventHelper,
-                       CyServiceRegistrar registrar) {
+    /**
+     * By default, this value will be used as the View Threshold.
+     */
+    private static final int DEF_VIEW_THRESHOLD = 3000;
 
-               if (eventHelper == null)
-                       throw new NullPointerException("CyEventHelper is null");
-               this.eventHelper = eventHelper;
+    private final CyEventHelper eventHelper;
+    private final CyServiceRegistrar registrar;
+    private final Properties props;
 
-               if (registrar == null)
-                       throw new NullPointerException("CyServiceRegistrar is 
null");
-               
-               this.registrar = registrar;
+    /**
+     * For injection, use this constructor.
+     * 
+     * @param eventHelper
+     */
+    public NetworkViewFactoryImpl(final CyEventHelper eventHelper, final 
CyServiceRegistrar registrar,
+           final CyProperty<Properties> prop) {
+
+       if (eventHelper == null)
+           throw new NullPointerException("CyEventHelper is null");
+       this.eventHelper = eventHelper;
+
+       if (registrar == null)
+           throw new NullPointerException("CyServiceRegistrar is null");
+
+       this.registrar = registrar;
+
+       this.props = prop.getProperties();
+    }
+
+    @Override
+    public CyNetworkView getNetworkView(final CyNetwork network) {
+       return getNetworkView(network, true);
+    }
+
+    @Override
+    public CyNetworkView getNetworkView(final CyNetwork network, final Boolean 
useThreshold) {
+
+       CyNetworkView view;
+       
+       if (!useThreshold) {
+           view = new NetworkViewImpl(network, eventHelper);
+           registrar.registerAllServices(view, new Properties());
+           return view;
        }
 
+       final int viewThreshold = getViewThreshold();
+       final int objectCount = network.getEdgeCount() + network.getNodeCount();
+       if (viewThreshold < objectCount)
+           view = new NullCyNetworkView(network);
+       else {
+           view = new NetworkViewImpl(network, eventHelper);
+           registrar.registerAllServices(view, new Properties());
+       }
 
-       @Override
-       public CyNetworkView getNetworkView(final CyNetwork network) {
-               final CyNetworkView view = new NetworkViewImpl(network, 
eventHelper);
-               registrar.registerAllServices(view, new Properties());
+       return view;
+    }
 
-               return view;
+    private int getViewThreshold() {
+       final String vts = props.getProperty(VIEW_THRESHOLD);
+       int threshold;
+       try {
+           threshold = Integer.parseInt(vts);
+       } catch (Exception e) {
+           threshold = DEF_VIEW_THRESHOLD;
        }
+
+       return threshold;
+    }
 }

Modified: 
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NetworkViewImpl.java
===================================================================
--- 
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NetworkViewImpl.java
        2011-05-03 00:45:44 UTC (rev 24893)
+++ 
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NetworkViewImpl.java
        2011-05-03 00:46:04 UTC (rev 24894)
@@ -192,5 +192,11 @@
                
                
cyEventHelper.getMicroListener(NetworkViewChangeMicroListener.class, 
this).networkVisualPropertySet(this, vp, value);   
        }
+
+
+       @Override
+       public Boolean isNullView() {
+           return false;
+       }
        
 }

Added: 
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NullCyNetworkView.java
===================================================================
--- 
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NullCyNetworkView.java
                              (rev 0)
+++ 
core3/viewmodel-impl/trunk/impl/src/main/java/org/cytoscape/view/model/internal/NullCyNetworkView.java
      2011-05-03 00:46:04 UTC (rev 24894)
@@ -0,0 +1,112 @@
+package org.cytoscape.view.model.internal;
+
+import java.util.Collection;
+
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyTableEntry;
+import org.cytoscape.model.SUIDFactory;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.VisualProperty;
+
+/**
+ * Null object for CyNetworkView.
+ * 
+ * Network readers may return this null object.
+ * 
+ */
+public final class NullCyNetworkView implements CyNetworkView {
+
+    private final long suid;
+    private final CyNetwork model;
+
+    public NullCyNetworkView(final CyNetwork model) {
+       this.model = model;
+       this.suid = SUIDFactory.getNextSUID();
+    }
+
+    @Override
+    public CyNetwork getModel() {
+       return model;
+    }
+
+    @Override
+    public long getSUID() {
+       return suid;
+    }
+
+    // All of the methods below are dummy.
+
+    @Override
+    public <T, V extends T> void setVisualProperty(VisualProperty<? extends T> 
vp, V value) {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public <T> T getVisualProperty(VisualProperty<T> vp) {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public <T, V extends T> void setLockedValue(VisualProperty<? extends T> 
vp, V value) {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public boolean isValueLocked(VisualProperty<?> vp) {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public void clearValueLock(VisualProperty<?> vp) {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public View<CyNode> getNodeView(CyNode node) {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public Collection<View<CyNode>> getNodeViews() {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public View<CyEdge> getEdgeView(CyEdge edge) {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public Collection<View<CyEdge>> getEdgeViews() {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public Collection<View<? extends CyTableEntry>> getAllViews() {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public void fitContent() {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public void fitSelected() {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public void updateView() {
+       throw new UnsupportedOperationException("This is a null object and does 
not support this method.");
+    }
+
+    @Override
+    public Boolean isNullView() {
+       return true;
+    }
+
+}

Modified: 
core3/viewmodel-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
--- 
core3/viewmodel-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
  2011-05-03 00:45:44 UTC (rev 24893)
+++ 
core3/viewmodel-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
  2011-05-03 00:46:04 UTC (rev 24894)
@@ -10,6 +10,9 @@
        <osgi:reference id="cyServiceRegistrarRef"
                interface="org.cytoscape.service.util.CyServiceRegistrar" />
 
+       <osgi:reference id="cyPropertyServiceRef" 
interface="org.cytoscape.property.CyProperty"
+               filter="(cyPropertyName=coreSettings)" />
+
        <!-- Export Beans as Services -->
        <osgi:service id="cyNetworkViewFactoryService" 
ref="cyNetworkViewFactory"
                interface="org.cytoscape.view.model.CyNetworkViewFactory">

Modified: 
core3/viewmodel-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- 
core3/viewmodel-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
       2011-05-03 00:45:44 UTC (rev 24893)
+++ 
core3/viewmodel-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
       2011-05-03 00:46:04 UTC (rev 24894)
@@ -16,6 +16,7 @@
                
class="org.cytoscape.view.model.internal.NetworkViewFactoryImpl">
                <constructor-arg ref="cyEventHelperServiceRef" />
                <constructor-arg ref="cyServiceRegistrarRef" />
+               <constructor-arg ref="cyPropertyServiceRef" />
        </bean>
 
        <bean id="cyNetworkViewManager"

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