Author: ptw
Date: 2007-08-04 11:48:44 -0700 (Sat, 04 Aug 2007)
New Revision: 5936

Added:
   openlaszlo/branches/wafflecone/test/explicit-replicators/
   openlaszlo/branches/wafflecone/test/explicit-replicators/replicator.lzx
Modified:
   openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/core/LzNode.lzs
   openlaszlo/branches/wafflecone/lps/components/utils/replicator/replicator.lzx
Log:
Change 20070803-ptw-Q by [EMAIL PROTECTED] on 2007-08-03 18:39:12 EDT
    in /Users/ptw/OpenLaszlo/wafflecone
    for http://svn.openlaszlo.org/openlaszlo/branches/wafflecone

Summary: Bring replicator tag more in compliance with spec

Bugs Fixed:
LPP-4405 'Implement ExplicitReplication' (partial)

Technical Reviewer: henry (pending)
QA Reviewer: max, pablo (Message-ID: <[EMAIL PROTECTED]>)

Details:
    LzNode: add a setter for `data`.  If you set data to an
    LzDataElement, that element becomes the data context for the node
    (i.e., the datapath of the node will point to that data element).

    replicator: Make this a node, not a view.  Add axis, spacing,
    dataset, and xpath attributes.  Remove private API's from
    interface.  Pass the layout up to the parent, compute the nodes
    from the xpath on init.

Tests:
    The test in this change



Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/core/LzNode.lzs
===================================================================
--- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/core/LzNode.lzs      
2007-08-04 09:58:28 UTC (rev 5935)
+++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/core/LzNode.lzs      
2007-08-04 18:48:44 UTC (rev 5936)
@@ -1056,6 +1056,7 @@
     options: "__LZsetOptions",
     placement : -1 ,
     datapath : "setDatapath",
+    data: "setData",
     $setters : -1,
     $classrootdepth : "__LZsetClassRoot",
     $datapath : "__LZmakeDatapath"
@@ -1066,6 +1067,7 @@
 setters.id = "setID"
 setters.placement = -1
 setters.datapath = "setDatapath"
+setters.data = "setData"
 */
 
 /**
@@ -1474,7 +1476,20 @@
     }
 }
 
+  /**
+   * Sets the datacontext for the node to the data element given as an
+   * argument
+   * @access public
+   * @param LzDataElement data: The dataelement to use as the context
+   */
+  function setData(data) {
+    this.data = data;
+    var dp = (this.datapath != null) ? this.datapath : new LzDatapath(this);
+    dp.setPointer(data);
+    if (this.ondata.ready) this.ondata.sendEvent(data);
+  }
 
+
 // hack to create an 'abstract' method to hang the doc off of
 if ($debug) {
 /**

Modified: 
openlaszlo/branches/wafflecone/lps/components/utils/replicator/replicator.lzx
===================================================================
--- 
openlaszlo/branches/wafflecone/lps/components/utils/replicator/replicator.lzx   
    2007-08-04 09:58:28 UTC (rev 5935)
+++ 
openlaszlo/branches/wafflecone/lps/components/utils/replicator/replicator.lzx   
    2007-08-04 18:48:44 UTC (rev 5936)
@@ -2,10 +2,10 @@
 <library>
   <!--- This is a declared replicator for visual elements. Unlike
       OpenLaszlo''s data-replication feature, a replicator can take an
-      arbitrary node set that may be passed in as an array. 
-      Non-replicating elements may be used inside a replicator; only 
-      the last child inside the replicator is replicated. 
-      
+      arbitrary node set that may be passed in as an array.
+      Non-replicating elements may be used inside a replicator; only
+      the last child inside the replicator is replicated.
+
       The data attribute of the replicated (cloned) view is set by the
       setData method with data from the nodes array when the clone is
       bound. -->
@@ -13,34 +13,42 @@
     <!--- If true, then instances of the replicated instance are reused
         when possible -->
     <attribute name="pool" value="true" type="boolean"/>
-    
+
     <!--- The size (width or height) in the replication axis of the view
         being replicated.  Assumes all subviews have same replicated size.
     -->
     <attribute name="replicatedsize" value="null" />
-    
+
     <!--- The axis in which to replicate-->
     <attribute name="axis" value="y" type="string"/>
-    
+
+    <!--- A pixel amount to use between each replicated view -->
+    <attribute name="spacing" value="0" />
+
     <!--- The list of elements controlled by this repliator -->
     <attribute name="clones" />
-    
+
     <!--- The list of nodes over which this replictor acts -->
     <attribute name="nodes" value="null" setter="this.setNodes(nodes)"/>
-    
+
     <event name="onnodes"/>
 
-    <!--- Replicate over the given list of elements 
+    <!--- Replicate over the given list of elements
         @param Array n: The list of elements over which to replicate -->
     <method name="setNodes" args="n" />
-    
-    
+
+
+    <!--- Compute nodes from this dataset -->
+    <attribute name="dataset" />
+    <!--- Compute nodes from this xpath query against the specified dataset -->
+    <attribute name="xpath" />
+
     <!--- Insert a node in existing list of elements.
         @param Number idx: index to insert element
         @param Object n: node to insert -->
     <method name="insertNode" args="idx, n" />
-    
-    
+
+
     <!--- Called internally, but may be overriden. This is the method
         which binds a given clone to an element in the nodes array.
         @param LzView v: The clone being bound
@@ -48,62 +56,30 @@
         bound to.
     -->
     <method name="bind" args="v , n" />
-    
-    
-    <!--- @keywords private -->
-    <method name="setCloneProperty" args="v , prop, val" />
-    
-    
-    <!--- @keywords private -->
-    <method name="setClonePropertyByCN" args="n , prop, val" />
-    
-    
-    <!--- @keywords private -->
-    <method name="update" args="v , n" />
-    
-    
+
+
     <!-- TODO: defaults for clone attributes -->
     <!--- Called internally, but may be overriden. This method is called
         when a given clone is about to be pooled or destroyed -->
     <method name="unbind" args="v" />
-    
-    
-    <!--- @keywords private -->
-    <method name="getClone" />
-    
-    
-    <!--- @keywords private -->
-    <method name="_makeClone" />
-    
-    
-    <!--- @keywords private -->
-    <method name="poolClone" args="c" />
-    
-    
-    <!--- @keywords private -->
-    <method name="getCloneIfVisible" args="n" />
-    
-    
+
+
     <!--- Called internally, but may be overriden. This is the method is
-        called to set the data of a clone to an element in the nodes 
+        called to set the data of a clone to an element in the nodes
         array.
-        
+
         @param LzView v: The clone whose data is being set.
-        @param n: The node to which it is being set. 
+        @param n: The node to which it is being set.
     -->
     <method name="setData" args="v, n" />
-    
-    
-    <!--- @keywords private -->
-    <method name="__adjustVisibleClones" />
-    
-    
+
+
     <!--- Gets the clone for the given offset, scrolling it into view first
         if necessary.
         @param Number n: The offset of the clone to get-->
     <method name="getCloneForOffset" args="n" />
-    
-    
+
+
     <!--- Ensures that the clone at the given offset is visible under
         the mask
         @param Number n: The offset of the clone to scroll in view-->
@@ -114,7 +90,7 @@
   <script when="immediate">
     <![CDATA[
 
-class replicator extends LzView {
+class replicator extends LzNode {
 
     static var tagname = 'replicator';
 
@@ -123,11 +99,13 @@
     // The size (width or height) in the replication axis of the view
     //    being replicated.  Assumes all subviews have same replicated size.
     var replicatedsize = null;
-    
+
     // The axis in which to replicate
     var axis = "y";
-    
-    //  The list of elements controlled by this replicator 
+    // Spacing between replications
+    var spacing = 0;
+
+    //  The list of elements controlled by this replicator
     var clones = null;
     var nodes = null;
     var _sizes = { x : 'width', y: 'height' };
@@ -135,20 +113,35 @@
     var _clonepool = null;
 
 
-    // @keywords private 
+    // @keywords private
     function construct (p,a) {
-        super.construct( p, a );
         this.clones = [];
         this._cloneprops = [];
         this._clonepool = [];
+        super.construct.apply(this, arguments);
     }
 
-    //     @keywords private 
+    // @keywords private
+    function init() {
+      super.init.apply(this, arguments);
+      // Set the layout in the view that will hold the replicated views
+      this.immediateparent.setAttribute('layout', {axis: this.axis, spacing: 
this.spacing});
+      if (this.dataset && this.xpath) {
+        this.setNodes(this.dataset.getPointer().xpathQuery(this.xpath))
+      }
+    }
+
+
+    //     @keywords private
     function createChildren (c) {
         this.replicated = c.pop();
         //Debug.write( 'replicated', replicated );
-        if ( c.length ) super.createChildren( c );
-        else this.__LZinstantiationDone();
+        if ( c.length ) {
+          Debug.warn("%s: only a single child view is replicated", this);
+          this.immediateparent.createChildren( c );
+        } else {
+          this.__LZinstantiationDone();
+        }
     }
 
     DeclareEvent(prototype, 'onnodes');
@@ -158,24 +151,24 @@
      */
     setters.nodes = "setNodes";
 
-
-    // Replicate over the given list of elements 
-    // @param Array n: The list of elements over which to replicate 
+    // Replicate over the given list of elements
+    // @param Array n: The list of elements over which to replicate
+    // TODO: [2007-07-27 ptw] `function set nodes () {` when the compiler 
supports it
     function setNodes (n) {
         this.nodes = n;
         this.__adjustVisibleClones();
-        this.setAttribute("replicatedsize", this.subviews.length == 0 
+        this.setAttribute("replicatedsize", this.clones.length == 0
                      ? 0
-                     : 
this.subviews[this.subviews.length-1][this._sizes[this.axis]]);
+                     : 
this.clones[this.clones.length-1][this._sizes[this.axis]]);
         this.onnodes.sendEvent();
     }
 
     //  Insert a node in existing list of elements.
     //         @param Number idx: index to insert element
-    //             @param Object n: node to insert 
+    //             @param Object n: node to insert
     function insertNode (idx, n) {
         this.nodes.splice(idx, 0, n);
-        this._cloneprops.splice(idx,0, undefined); // maintain cloneprops 
indices 
+        this._cloneprops.splice(idx,0, undefined); // maintain cloneprops 
indices
         this.__adjustVisibleClones();
     }
 
@@ -184,7 +177,7 @@
     //          @param LzView v: The clone being bound
     //          @param Number n: The number of the element the clone is being
     //          bound to.
-         
+
     function bind (v , n) {
         v.setAttribute( "clonenumber" , n );
         this.setData( v , n );
@@ -197,12 +190,12 @@
         }
     }
 
-    //  @keywords private 
+    //  @keywords private
     function setCloneProperty (v , prop, val) {
         this.setClonePropertyByCN( v.clonenumber, prop ,val );
     }
 
-    //  @keywords private 
+    //  @keywords private
     function setClonePropertyByCN (n , prop, val) {
         if ( !this._cloneprops[ n ] ) this._cloneprops[ n ] = {};
         this._cloneprops[ n ][ prop ] = val;
@@ -210,14 +203,14 @@
         if ( v ) v.setAttribute( prop , val );
     }
 
-    //  @keywords private 
+    //  @keywords private
     function update (v , n) {
         if ( v[ "update" ] ) v.update( v.data , n );
     }
 
-    // TODO: defaults for clone attributes 
+    // TODO: defaults for clone attributes
     //  Called internally, but may be overriden. This method is called
-    //          when a given clone is about to be pooled or destroyed 
+    //          when a given clone is about to be pooled or destroyed
     function unbind (v) {
         var n = v.clonenumber;
         v.setAttribute( "clonenumber", null );
@@ -230,7 +223,7 @@
         }
     }
 
-    //  @keywords private 
+    //  @keywords private
     function getClone () {
         var v;
         if ( this._clonepool.length ) {
@@ -242,38 +235,38 @@
         return v;
     }
 
-    //  @keywords private 
+    //  @keywords private
     function _makeClone () {
-        var v = this.makeChild( this.replicated );
+        var v = this.immediateparent.makeChild( this.replicated );
         v.setAttribute( "clonenumber", null );
         return v;
     }
 
-    //  @keywords private 
+    //  @keywords private
     function poolClone (c) {
         if ( c.clonenumber ) this.unbind( c );
         c.setVisible( false );
         this._clonepool.push( c );
     }
 
-    //  @keywords private 
+    //  @keywords private
     function getCloneIfVisible (n) {
         return this.clones[ n ];
     }
 
     //  Called internally, but may be overriden. This is the method is
-    //          called to set the data of a clone to an element in the nodes 
+    //          called to set the data of a clone to an element in the nodes
     //          array.
 
     //          @param LzView v: The clone whose data is being set.
-    //          @param n: The node to which it is being set. 
-         
+    //          @param n: The node to which it is being set.
+
     function setData (v, n) {
         v.setAttribute( "data" , this.nodes[ n ] );
         v.applyData(this.nodes[n]);
     }
 
-    //  @keywords private 
+    //  @keywords private
     function __adjustVisibleClones () {
         while( this.clones.length ) this.poolClone( this.clones.pop() );
         if (this.nodes != null) {

Added: openlaszlo/branches/wafflecone/test/explicit-replicators/replicator.lzx


Property changes on: 
openlaszlo/branches/wafflecone/test/explicit-replicators/replicator.lzx
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to