Added custom RowHeightBead and ProductItemRenderer to DataGridExample.

Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c9db817c
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c9db817c
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c9db817c

Branch: refs/heads/develop
Commit: c9db817cb227c7741197714fb3be61da4240a887
Parents: 20320a8
Author: Peter Ent <[email protected]>
Authored: Wed Jan 29 15:25:17 2014 -0500
Committer: Peter Ent <[email protected]>
Committed: Wed Jan 29 15:25:17 2014 -0500

----------------------------------------------------------------------
 .../src/models/MyGridPresentation.as            |  32 ----
 .../DataGridExample/src/models/ProductsModel.as |  12 +-
 .../src/mybeads/RowHeightBead.as                | 155 +++++++++++++++++++
 .../DataGridExample/src/products/Product.as     |   6 +-
 .../src/products/ProductItemRenderer.as         |  61 ++++++++
 examples/DataGridExample/src/smallbluerect.jpg  | Bin 0 -> 13500 bytes
 examples/DataGridExample/src/smallgreenrect.jpg | Bin 0 -> 13542 bytes
 .../DataGridExample/src/smallorangerect.gif     | Bin 0 -> 821 bytes
 .../DataGridExample/src/smallorangerect.jpg     | Bin 0 -> 13571 bytes
 .../DataGridExample/src/smallpurplerect.jpg     | Bin 0 -> 13517 bytes
 examples/DataGridExample/src/smallredrect.jpg   | Bin 0 -> 13477 bytes
 .../DataGridExample/src/smallyellowrect.jpg     | Bin 0 -> 13598 bytes
 12 files changed, 226 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/models/MyGridPresentation.as
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/models/MyGridPresentation.as 
b/examples/DataGridExample/src/models/MyGridPresentation.as
deleted file mode 100644
index 3434348..0000000
--- a/examples/DataGridExample/src/models/MyGridPresentation.as
+++ /dev/null
@@ -1,32 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-//
-//  Licensed to the Apache Software Foundation (ASF) under one or more
-//  contributor license agreements.  See the NOTICE file distributed with
-//  this work for additional information regarding copyright ownership.
-//  The ASF licenses this file to You under the Apache License, Version 2.0
-//  (the "License"); you may not use this file except in compliance with
-//  the License.  You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-//  Unless required by applicable law or agreed to in writing, software
-//  distributed under the License is distributed on an "AS IS" BASIS,
-//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//  See the License for the specific language governing permissions and
-//  limitations under the License.
-//
-////////////////////////////////////////////////////////////////////////////////
-package models
-{
-       import 
org.apache.flex.html.staticControls.beads.models.DataGridPresentationModel;
-       
-       public class MyGridPresentation extends DataGridPresentationModel
-       {
-               public function MyGridPresentation()
-               {
-                       super();
-                       
-                       this.columnLabels = ["ID","Title","Inventory"];
-               }
-       }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/models/ProductsModel.as
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/models/ProductsModel.as 
b/examples/DataGridExample/src/models/ProductsModel.as
index 5b452b8..88f6662 100644
--- a/examples/DataGridExample/src/models/ProductsModel.as
+++ b/examples/DataGridExample/src/models/ProductsModel.as
@@ -29,18 +29,18 @@ package models
                }
 
                private var _productList:Array = [
-                       new Product("ps100","Widgets","44","smallbluerect.jpg"),
-                       new Product("tx200","Thingys","out of 
stock","smallgreenrect.jpg"),
-                       new 
Product("rz300","Sprockets","8,000","smallyellowrect.jpg"),
-                       new Product("dh440","Doohickies","out of 
stock","smallredrect.jpg"),
-                       new 
Product("ps220","Weejets","235","smallorangerect.jpg")
+                       new 
Product("ps100","Widgets",44,200,"smallbluerect.jpg"),
+                       new 
Product("tx200","Thingys",5,285,"smallgreenrect.jpg"),
+                       new 
Product("rz300","Sprockets",80,105,"smallyellowrect.jpg"),
+                       new 
Product("dh440","Doohickies",10,340,"smallredrect.jpg"),
+                       new 
Product("ps220","Weejets",35,190,"smallorangerect.jpg")
                        ];
                public function get productList():Array
                {
                        return _productList;
                }
 
-               private var _labelFields:Array = [ "id", "title", "detail" ];
+               private var _labelFields:Array = [ "id", "title", "sales", 
"detail" ];
                public function get labelFields():Array
                {
                        return _labelFields;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/mybeads/RowHeightBead.as
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/mybeads/RowHeightBead.as 
b/examples/DataGridExample/src/mybeads/RowHeightBead.as
new file mode 100644
index 0000000..2b0661e
--- /dev/null
+++ b/examples/DataGridExample/src/mybeads/RowHeightBead.as
@@ -0,0 +1,155 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package mybeads
+{
+       import flash.display.DisplayObject;
+       
+       import org.apache.flex.core.IBead;
+       import org.apache.flex.core.IDataGridModel;
+       import org.apache.flex.core.IItemRenderer;
+       import org.apache.flex.core.IItemRendererParent;
+       import org.apache.flex.core.IStrand;
+       import org.apache.flex.core.UIBase;
+       import org.apache.flex.events.Event;
+       import org.apache.flex.events.IEventDispatcher;
+       import org.apache.flex.html.staticControls.List;
+       import org.apache.flex.html.staticControls.beads.DataGridView;
+       import org.apache.flex.html.staticControls.beads.IListView;
+       
+       public class RowHeightBead implements IBead
+       {
+               public function RowHeightBead()
+               {
+               }
+               
+               private var _strand:IStrand;
+               public function set strand(value:IStrand):void
+               {
+                       _strand = value;
+                       
+                       
IEventDispatcher(_strand).addEventListener("layoutComplete",handleLayoutComplete);
+               }
+               
+               private var _rowHeight:Number = 30;
+               public function get rowHeight():Number
+               {
+                       return _rowHeight;
+               }
+               public function set rowHeight(value:Number):void
+               {
+                       _rowHeight = value;
+                       // dispatch some event which will trigger layout 
recalculation
+               }
+               
+               private var _minRowHeight:Number = 30;
+               public function get minRowHeight():Number
+               {
+                       return _minRowHeight;
+               }
+               public function set minRowHeight(value:Number):void
+               {
+                       _minRowHeight = value;
+                       // dispatch some event which will trigger layout 
recalculation
+               }
+               
+               private var _variableRowHeight:Boolean = false;
+               public function get variableRowHeight():Boolean
+               {
+                       return _variableRowHeight;
+               }
+               public function set variableRowHeight(value:Boolean):void
+               {
+                       _variableRowHeight = value;
+                       // dispatch some event which will trigger a layout 
recalculation
+               }
+               
+               private function handleLayoutComplete(event:Event):void
+               {
+                       if (variableRowHeight) {
+                               makeAllRowsVariableHeight(minRowHeight);
+                       }
+                       else {
+                               makeAllRowsSameHeight(rowHeight);
+                       }
+               }
+               
+               private function makeAllRowsSameHeight(newHeight:Number):void
+               {
+                       // this function forces every cell in the DataGrid to 
be the same height
+                       var view:DataGridView = 
_strand.getBeadByType(DataGridView) as DataGridView;
+                       var lists:Array = view.getColumnLists();
+                       
+                       for(var i:int=0; i < lists.length; i++)
+                       {
+                               var list:List = lists[i] as List;
+                               var listView:IListView = 
list.getBeadByType(IListView) as IListView;
+                               var p:IItemRendererParent = listView.dataGroup;
+                               var n:Number = (list.dataProvider as 
Array).length;
+
+                               for(var j:int=0; j < n; j++)
+                               {
+                                       var c:UIBase = 
p.getItemRendererForIndex(j) as UIBase;
+                                       c.height = newHeight;
+                               }
+                               
+                               IEventDispatcher(list).dispatchEvent( new 
Event("layoutNeeded") );
+                       }
+               }
+               
+               private function 
makeAllRowsVariableHeight(minHeight:Number):void
+               {
+                       // this function makes every cell in a row the same 
height
+                       // (at least minHeight) but all the rows can have 
different
+                       // heights
+                       var view:DataGridView = 
_strand.getBeadByType(DataGridView) as DataGridView;
+                       var lists:Array = view.getColumnLists();
+                       
+                       // future: maybe IDataGridModel.dataProvider should 
implement IDataProvider which
+                       // can have a length property and not assume that the 
.dataProvider is an Array.
+                       var n:Number = ((_strand.getBeadByType(IDataGridModel) 
as IDataGridModel).dataProvider as Array).length;
+                       
+                       for(var i:int=0; i < n; i++)
+                       {
+                               var maxHeight:Number = minHeight;
+                               for(var j:int=0; j < lists.length; j++)
+                               {
+                                       var list:List = lists[j] as List;
+                                       var listView:IListView = 
list.getBeadByType(IListView) as IListView;
+                                       var p:IItemRendererParent = 
listView.dataGroup;
+                                       var c:UIBase = 
p.getItemRendererForIndex(i) as UIBase;
+                                       maxHeight = 
Math.max(maxHeight,c.height);
+                               }
+                               for(j=0; j < lists.length; j++)
+                               {
+                                       list = lists[j] as List;
+                                       listView = 
list.getBeadByType(IListView) as IListView;
+                                       p = listView.dataGroup;
+                                       c = p.getItemRendererForIndex(i) as 
UIBase;
+                                       c.height = maxHeight;
+                               }
+                       }
+                       
+                       for(j=0; j < lists.length; j++)
+                       {
+                               list = lists[j] as List;
+                               IEventDispatcher(list).dispatchEvent( new 
Event("layoutNeeded") );
+                       }
+               }
+       }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/products/Product.as
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/products/Product.as 
b/examples/DataGridExample/src/products/Product.as
index 34abf6b..fd4b31e 100644
--- a/examples/DataGridExample/src/products/Product.as
+++ b/examples/DataGridExample/src/products/Product.as
@@ -20,18 +20,20 @@ package products
 {
        public class Product
        {
-               public function 
Product(id:String,title:String,detail:String,image:String)
+               public function 
Product(id:String,title:String,detail:Number,sales:Number,image:String)
                {
                        this.id = id;
                        this.title = title;
                        this.detail = detail;
+                       this.sales = sales;
                        this.image = image;
                }
                
                public var id:String;
                public var title:String;
-               public var detail:String;
+               public var detail:Number;
                public var image:String;
+               public var sales:Number;
                
                public function toString():String
                {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/products/ProductItemRenderer.as
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/products/ProductItemRenderer.as 
b/examples/DataGridExample/src/products/ProductItemRenderer.as
new file mode 100644
index 0000000..f24da32
--- /dev/null
+++ b/examples/DataGridExample/src/products/ProductItemRenderer.as
@@ -0,0 +1,61 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package products
+{
+       import org.apache.flex.html.staticControls.Image;
+       import 
org.apache.flex.html.staticControls.supportClasses.DataItemRenderer;
+       
+       public class ProductItemRenderer extends DataItemRenderer
+       {
+               public function ProductItemRenderer()
+               {
+                       super();
+               }
+               
+               private var image:Image;
+               
+               override public function addedToParent():void
+               {
+                       super.addedToParent();
+                       
+                       // add an image and two labels
+                       image = new Image();
+                       addElement(image);
+               }
+               
+               override public function set data(value:Object):void
+               {
+                       super.data = value;
+                       
+                       image.source = value.image;
+               }
+               
+               override public function adjustSize():void
+               {
+                       var cy:Number = this.height/2;
+                       
+                       image.x = 4;
+                       image.y = cy - 16;
+                       image.width = 32;
+                       image.height = 32;
+                       
+                       updateRenderer();
+               }
+       }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/smallbluerect.jpg
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/smallbluerect.jpg 
b/examples/DataGridExample/src/smallbluerect.jpg
new file mode 100755
index 0000000..80ed275
Binary files /dev/null and b/examples/DataGridExample/src/smallbluerect.jpg 
differ

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/smallgreenrect.jpg
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/smallgreenrect.jpg 
b/examples/DataGridExample/src/smallgreenrect.jpg
new file mode 100755
index 0000000..c5f9ce6
Binary files /dev/null and b/examples/DataGridExample/src/smallgreenrect.jpg 
differ

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/smallorangerect.gif
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/smallorangerect.gif 
b/examples/DataGridExample/src/smallorangerect.gif
new file mode 100644
index 0000000..603f810
Binary files /dev/null and b/examples/DataGridExample/src/smallorangerect.gif 
differ

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/smallorangerect.jpg
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/smallorangerect.jpg 
b/examples/DataGridExample/src/smallorangerect.jpg
new file mode 100755
index 0000000..4982d87
Binary files /dev/null and b/examples/DataGridExample/src/smallorangerect.jpg 
differ

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/smallpurplerect.jpg
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/smallpurplerect.jpg 
b/examples/DataGridExample/src/smallpurplerect.jpg
new file mode 100755
index 0000000..201f625
Binary files /dev/null and b/examples/DataGridExample/src/smallpurplerect.jpg 
differ

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/smallredrect.jpg
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/smallredrect.jpg 
b/examples/DataGridExample/src/smallredrect.jpg
new file mode 100644
index 0000000..d2cfa31
Binary files /dev/null and b/examples/DataGridExample/src/smallredrect.jpg 
differ

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9db817c/examples/DataGridExample/src/smallyellowrect.jpg
----------------------------------------------------------------------
diff --git a/examples/DataGridExample/src/smallyellowrect.jpg 
b/examples/DataGridExample/src/smallyellowrect.jpg
new file mode 100755
index 0000000..b17b62d
Binary files /dev/null and b/examples/DataGridExample/src/smallyellowrect.jpg 
differ

Reply via email to