Added Tree component to FlexJS. Includes HierarchicalData collection.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/86ebc1d4 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/86ebc1d4 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/86ebc1d4 Branch: refs/heads/spark Commit: 86ebc1d4e2fd724d29030f992747b777d49fcfae Parents: 9312539 Author: Peter Ent <[email protected]> Authored: Thu Feb 18 13:53:40 2016 -0500 Committer: Alex Harui <[email protected]> Committed: Tue Feb 23 21:44:22 2016 -0800 ---------------------------------------------------------------------- examples/build.xml | 2 + .../src/productsView/ProductListItem.mxml | 10 + examples/flexjs/TreeExample/build.xml | 44 +++ examples/flexjs/TreeExample/pom.xml | 50 ++++ .../flexjs/TreeExample/src/MyInitialView.mxml | 37 +++ .../flexjs/TreeExample/src/TreeExample.mxml | 36 +++ .../flexjs/TreeExample/src/models/MyModel.as | 72 +++++ .../src/main/flex/CollectionsClasses.as | 2 + .../apache/flex/collections/FlattenedList.as | 203 ++++++++++++++ .../apache/flex/collections/HierarchicalData.as | 269 +++++++++++++++++++ .../flex/collections/IHierarchicalData.as | 119 ++++++++ .../src/main/resources/basic-manifest.xml | 1 + .../projects/HTML/src/main/flex/HTMLClasses.as | 6 +- .../src/main/flex/org/apache/flex/html/Tree.as | 73 +++++ ...ataItemRendererFactoryForHierarchicalData.as | 109 ++++++++ .../ListSingleSelectionMouseController.as | 10 +- .../TreeSingleSelectionMouseController.as | 82 ++++++ .../html/supportClasses/StringItemRenderer.as | 3 - .../html/supportClasses/TreeItemRenderer.as | 59 ++++ .../flex/html/supportClasses/TreeListData.as | 76 ++++++ .../HTML/src/main/resources/basic-manifest.xml | 2 + .../HTML/src/main/resources/defaults.css | 22 ++ 22 files changed, 1277 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/examples/build.xml ---------------------------------------------------------------------- diff --git a/examples/build.xml b/examples/build.xml index 894573e..7efccfc 100644 --- a/examples/build.xml +++ b/examples/build.xml @@ -86,6 +86,7 @@ <ant dir="${basedir}/flexjs/MobileTrader"/> <ant dir="${basedir}/flexjs/ChartExample"/> <ant dir="${basedir}/flexjs/TodoListSampleApp"/> + <ant dir="${basedir}/flexjs/TreeExample"/> <ant dir="${basedir}/native/ButtonExample"/> <ant dir="${basedir}/native/USStatesMap"/> </target> @@ -113,6 +114,7 @@ <ant dir="${basedir}/flexjs/MobileTrader" target="clean"/> <ant dir="${basedir}/flexjs/ChartExample" target="clean"/> <ant dir="${basedir}/flexjs/TodoListSampleApp" target="clean"/> + <ant dir="${basedir}/flexjs/TreeExample" target="clean"/> <ant dir="${basedir}/native/ButtonExample" target="clean"/> <ant dir="${basedir}/native/USStatesMap" target="clean"/> </target> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/examples/flexjs/FlexJSStore/src/productsView/ProductListItem.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexJSStore/src/productsView/ProductListItem.mxml b/examples/flexjs/FlexJSStore/src/productsView/ProductListItem.mxml index 2864cca..8e98c3b 100755 --- a/examples/flexjs/FlexJSStore/src/productsView/ProductListItem.mxml +++ b/examples/flexjs/FlexJSStore/src/productsView/ProductListItem.mxml @@ -60,6 +60,16 @@ limitations under the License. { _data = value; } + + public function get listData():Object + { + return null; + } + + public function set listData(value:Object):void + { + // not used + } private var _itemRendererParent:Object; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/examples/flexjs/TreeExample/build.xml ---------------------------------------------------------------------- diff --git a/examples/flexjs/TreeExample/build.xml b/examples/flexjs/TreeExample/build.xml new file mode 100644 index 0000000..c2fcd0d --- /dev/null +++ b/examples/flexjs/TreeExample/build.xml @@ -0,0 +1,44 @@ +<?xml version="1.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. + +--> + + +<project name="treeexample" default="main" basedir="."> + <property name="FLEXJS_HOME" location="../../.."/> + <property name="example" value="TreeExample" /> + + <property file="${FLEXJS_HOME}/env.properties"/> + <property environment="env"/> + <property file="${FLEXJS_HOME}/build.properties"/> + <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> + + <include file="${basedir}/../../build_example.xml" /> + + <property name="extlib_arg" value="-external-library-path=${FALCONJX_HOME}/../externs/js/out/bin/js.swc"/> + + <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of ${example}"> + </target> + + <target name="clean"> + <delete dir="${basedir}/bin" failonerror="false" /> + <delete dir="${basedir}/bin-debug" failonerror="false" /> + <delete dir="${basedir}/bin-release" failonerror="false" /> + </target> + +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/examples/flexjs/TreeExample/pom.xml ---------------------------------------------------------------------- diff --git a/examples/flexjs/TreeExample/pom.xml b/examples/flexjs/TreeExample/pom.xml new file mode 100644 index 0000000..1cf03f8 --- /dev/null +++ b/examples/flexjs/TreeExample/pom.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.examples.flexjs</groupId> + <artifactId>examples</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>TreeExample</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>swf</packaging> + + <build> + <sourceDirectory>src</sourceDirectory> + <plugins> + <plugin> + <groupId>net.flexmojos.oss</groupId> + <artifactId>flexmojos-maven-plugin</artifactId> + <version>7.1.0-SNAPSHOT</version> + <extensions>true</extensions> + <configuration> + <sourceFile>TreeExample.mxml</sourceFile> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/examples/flexjs/TreeExample/src/MyInitialView.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/TreeExample/src/MyInitialView.mxml b/examples/flexjs/TreeExample/src/MyInitialView.mxml new file mode 100644 index 0000000..d7fa22f --- /dev/null +++ b/examples/flexjs/TreeExample/src/MyInitialView.mxml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +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. + +--> +<js:ViewBase xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:js="library://ns.apache.org/flexjs/basic"> + + <js:beads> + <js:ViewBaseDataBinding /> + </js:beads> + + <js:Tree id="tree" x="30" y="30" width="400" height="300" + labelField="title"> + <js:beads> + <js:ConstantBinding + sourceID="applicationModel" + sourcePropertyName="treeData" + destinationPropertyName="dataProvider" /> + </js:beads> + </js:Tree> + +</js:ViewBase> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/examples/flexjs/TreeExample/src/TreeExample.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/TreeExample/src/TreeExample.mxml b/examples/flexjs/TreeExample/src/TreeExample.mxml new file mode 100644 index 0000000..e969146 --- /dev/null +++ b/examples/flexjs/TreeExample/src/TreeExample.mxml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8"?> +<!--- +// +// 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. +// +//////////////////////////////////////////////////////////////////////////////// +--> +<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:local="*" + xmlns:models="models.*" + xmlns:js="library://ns.apache.org/flexjs/basic" + > + + <js:valuesImpl> + <js:SimpleCSSValuesImpl /> + </js:valuesImpl> + <js:model> + <models:MyModel /> + </js:model> + <js:initialView> + <local:MyInitialView /> + </js:initialView> +</js:Application> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/examples/flexjs/TreeExample/src/models/MyModel.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/TreeExample/src/models/MyModel.as b/examples/flexjs/TreeExample/src/models/MyModel.as new file mode 100644 index 0000000..d224293 --- /dev/null +++ b/examples/flexjs/TreeExample/src/models/MyModel.as @@ -0,0 +1,72 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.collections.HierarchicalData; + + public class MyModel extends EventDispatcher + { + public function MyModel() + { + treeData = new HierarchicalData(store); + treeData.childrenField = "children"; + } + + public var treeData:HierarchicalData; + + private var store:Object = { title:"That's Entertainment", + children:[ + {title:"My Music", + children:[ + {title:"Language and Perspective", artist:"Bad Suns", + children:[ + {title:"Matthew James", length:"3:24"}, + {title:"We Move Like the Ocean", length:"3:56"}, + {title:"Cardiac Arrest", length:"3:15"} + ]}, + {title:"Strange Desire", artist:"Bleachers", + children:[ + {title:"Wild Heart", length:"4:15"}, + {title:"Rollercoaster", length:"3:39"}, + {title:"Shadow", length:"3:46"}, + {title:"I Wanna Get Better", length:"4:23"} + ]} + ]}, + {title:"My Books", + children:[ + {title:"Wizard of Oz", + children:[ + {title:"So this is Kansas?", length:"82"}, + {title:"A Might Dusty Here", length:"63"}, + {title:"Is that a Tornado?", length:"103"} + ]}, + {title:"Favorite Book #2", + children:[ + {title:"Chapter 1", length:"15"}, + {title:"Chapter 2", length:"86"}, + {title:"Chapter 3", length:"104"}, + {title:"Chapter 4", length:"99"} + ]} + ]} + ]}; + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/Collections/src/main/flex/CollectionsClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/CollectionsClasses.as b/frameworks/projects/Collections/src/main/flex/CollectionsClasses.as index 5112c5c..58e601f 100644 --- a/frameworks/projects/Collections/src/main/flex/CollectionsClasses.as +++ b/frameworks/projects/Collections/src/main/flex/CollectionsClasses.as @@ -28,6 +28,8 @@ package internal class CollectionsClasses { import org.apache.flex.collections.ArrayList; ArrayList; + import org.apache.flex.collections.FlattenedList; FlattenedList; + import org.apache.flex.collections.HierarchicalData; HierarchicalData; import org.apache.flex.collections.LazyCollection; LazyCollection; } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/FlattenedList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/FlattenedList.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/FlattenedList.as new file mode 100644 index 0000000..3fd98be --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/FlattenedList.as @@ -0,0 +1,203 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.collections +{ + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.parsers.IInputParser; + import org.apache.flex.collections.converters.IItemConverter; + + + /** + * The FlattenedList class takes a HierarchicalData object and "flattens" it + * using all of the open members. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class FlattenedList extends ArrayList + { + public var hdata:HierarchicalData; + public var openNodes:Array; + + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function FlattenedList(hdata:HierarchicalData) + { + super(); + this.hdata = hdata; + this.openNodes = []; + reset(); + } + + /** + * Resets the list so that only the top root node is open. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function reset():void + { + var arr:Array = []; + addChildren(hdata.getRoot(), arr); + source = arr; + } + + /** + * @private + */ + protected function addChildren(node:Object, arr:Array):void + { + var children:Array = hdata.getChildren(node) as Array; + var n:int = children.length; + + for (var i:int=0; i < n; i++) { + arr.push(children[i]); + if (isOpen(children[i])) { + addChildren(children[i], arr); + } + } + } + + /** + * Returns true if the node has children nodes. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function hasChildren(node:Object):Boolean + { + return hdata.hasChildren(node); + } + + /** + * Returns true if the node is currently open. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function isOpen(node:Object):Boolean + { + return openNodes.indexOf(node) != -1; + } + + /** + * Opens the given node. The array data now contains more elements. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function openNode(node:Object):void + { + if (hdata.hasChildren(node)) { + openNodes.push(node); + var arr:Array = []; + addChildren(node, arr); + var i:int = getItemIndex(node); + while (arr.length) { + addItemAt(arr.shift(), ++i); + } + } + } + + /** + * Closes the given node. The array data now contains fewer elements. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function closeNode(node:Object):void + { + var i:int = openNodes.indexOf(node); + if (i != -1) { + + if (hdata.hasChildren(node)) { + var children:Array = hdata.getChildren(node) as Array; + var n:int = children.length; + for (var j:int=0; j < n; j++) { + closeNode(children[j]); + } + } + + openNodes.splice(i, 1); + var arr:Array = []; + addChildren(node, arr); + i = getItemIndex(node) + 1; + while (arr.length) { + removeItemAt(i); + arr.shift(); + } + } + } + + /** + * Returns the depth of the node with the root being zero. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function getDepth(node:Object):int + { + var depth:int = godeep(node, hdata.getRoot(), 0); + return depth; + } + + /** + * @private + */ + private function godeep(seeking:Object, node:Object, depth:int):int + { + if (seeking == node) return depth; + + if (hdata.hasChildren(node)) { + var children:Array = hdata.getChildren(node) as Array; + for (var i:int=0; i < children.length; i++) { + var newDepth:int = godeep(seeking, children[i], depth+1) + if (newDepth > 0) return newDepth; + } + } + + return -1; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/HierarchicalData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/HierarchicalData.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/HierarchicalData.as new file mode 100644 index 0000000..fb4b607 --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/HierarchicalData.as @@ -0,0 +1,269 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.collections +{ + +import org.apache.flex.events.Event; +import org.apache.flex.events.EventDispatcher; + + +/** + * Hierarchical data is data already in a structure of parent and child data items. + * The HierarchicalData class provides a default implementation for + * accessing and manipulating data. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ +public class HierarchicalData extends EventDispatcher implements IHierarchicalData +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructor. + * + * @param value The data used to populate the HierarchicalData instance. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function HierarchicalData(value:Object = null) + { + super(); + + source = value; + } + + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + //-------------------------------------------------------------------------- + // childrenField + //-------------------------------------------------------------------------- + + /** + * @private + * The field name to be used to detect children field. + */ + private var _childrenField:String = "children"; + + /** + * Indicates the field name to be used to detect children objects in + * a data item. + * By default, all subnodes are considered as children for + * XML data, and the <code>children</code> property is used for the Object data type. + * + * This is helpful in adapting to a data format that uses custom data fields + * to represent children. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get childrenField():String + { + return _childrenField; + } + + /** + * @private + */ + public function set childrenField(value:String):void + { + _childrenField = value; + } + + //-------------------------------------------------------------------------- + // source + //-------------------------------------------------------------------------- + + /** + * @private + * The source collection. + */ + private var _source:Object; + + /** + * The source collection. + * The collection should implement the IList interface + * to facilitate operation like the addition and removal of items. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get source():Object + { + return _source; + } + + /** + * @private + */ + public function set source(value:Object):void + { + _source = value; + + dispatchEvent(new Event("collectionChanged")); + } + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function canHaveChildren(node:Object):Boolean + { + if (node == null) + return false; + + var branch:Boolean = false; + + if (node is Object) + { + try + { + if (node[childrenField] != undefined) + { + branch = true; + } + } + catch (e:Error) + { + } + } + return branch; + } + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function getChildren(node:Object):Object + { + if (node == null) + return null; + + var children:*; + + //first get the children based on the type of node. + if (node is Object) + { + //we'll try the default children property + try + { + children = node[childrenField]; + } + catch (e:Error) + { + } + } + + //no children exist for this node + if(children === undefined) + return null; + + return children; + } + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function hasChildren(node:Object):Boolean + { + if (node == null) + return false; + + //This default impl can't optimize this call to getChildren + //since we can't make any assumptions by type. Custom impl's + //can probably avoid this call and reduce the number of calls to + //getChildren if need be. + var children:Object = getChildren(node); + try + { + if (children.length > 0) + return true; + } + catch (e:Error) + { + } + return false; + } + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function getData(node:Object):Object + { + return Object(node); + } + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function getRoot():Object + { + return source; + } + +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IHierarchicalData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IHierarchicalData.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IHierarchicalData.as new file mode 100644 index 0000000..5ff2b65 --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IHierarchicalData.as @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.collections +{ +import org.apache.flex.events.IEventDispatcher; + +/** + * The IHierarchicalData interface defines the interface + * used to represent hierarchical data as the data provider for + * a FlexJS component. + * Hierarchical data is data in a structure of parent + * and child data items. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ +public interface IHierarchicalData extends IEventDispatcher +{ + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + /** + * Returns <code>true</code> if the node can contain children. + * + * <p>Nodes do not have to contain children for the method + * to return <code>true</code>. + * This method is useful in determining whether other + * nodes can be appended as children to the specified node.</p> + * + * @param node The Object that defines the node. + * + * @return <code>true</code> if the node can contain children. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function canHaveChildren(node:Object):Boolean; + + /** + * Returns <code>true</code> if the node has children. + * + * @param node The Object that defines the node. + * + * @return <code>true</code> if the node has children. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function hasChildren(node:Object):Boolean; + + /** + * Returns an Object representing the node's children. + * + * @param node The Object that defines the node. + * If <code>null</code>, return a collection of top-level nodes. + * + * @return An Object containing the children nodes. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function getChildren(node:Object):Object; + + /** + * Returns data from a node. + * + * @param node The node Object from which to get the data. + * + * @return The requested data. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function getData(node:Object):Object; + + /** + * Returns the root data item. + * + * @return The Object containing the root data item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function getRoot():Object; +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/Collections/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/resources/basic-manifest.xml b/frameworks/projects/Collections/src/main/resources/basic-manifest.xml index 5ea77b7..dd1c47f 100644 --- a/frameworks/projects/Collections/src/main/resources/basic-manifest.xml +++ b/frameworks/projects/Collections/src/main/resources/basic-manifest.xml @@ -22,6 +22,7 @@ <componentPackage> <component id="ArrayList" class="org.apache.flex.collections.ArrayList"/> + <component id="HierarchicalData" class="org.apache.flex.collections.HierarchicalData"/> <component id="LazyCollection" class="org.apache.flex.collections.LazyCollection"/> <component id="JSONInputParser" class="org.apache.flex.collections.parsers.JSONInputParser"/> <component id="JSONItemConverter" class="org.apache.flex.collections.converters.JSONItemConverter"/> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/flex/HTMLClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/HTMLClasses.as b/frameworks/projects/HTML/src/main/flex/HTMLClasses.as index 80073e7..e5171d4 100644 --- a/frameworks/projects/HTML/src/main/flex/HTMLClasses.as +++ b/frameworks/projects/HTML/src/main/flex/HTMLClasses.as @@ -89,7 +89,7 @@ internal class HTMLClasses import org.apache.flex.html.beads.TextInputWithBorderView; TextInputWithBorderView; import org.apache.flex.html.beads.models.AlertModel; AlertModel; } - import org.apache.flex.html.beads.models.ArraySelectionModel; ArraySelectionModel; + import org.apache.flex.html.beads.models.ArraySelectionModel; ArraySelectionModel; import org.apache.flex.html.beads.models.RangeModel; RangeModel; COMPILE::AS3 { @@ -122,6 +122,7 @@ internal class HTMLClasses } import org.apache.flex.html.beads.controllers.ItemRendererMouseController; ItemRendererMouseController; import org.apache.flex.html.beads.controllers.ListSingleSelectionMouseController; ListSingleSelectionMouseController; + import org.apache.flex.html.beads.controllers.TreeSingleSelectionMouseController; TreeSingleSelectionMouseController; COMPILE::AS3 { import org.apache.flex.html.beads.controllers.SliderMouseController; SliderMouseController; @@ -142,6 +143,7 @@ internal class HTMLClasses import org.apache.flex.html.beads.TextItemRendererFactoryForArrayData; TextItemRendererFactoryForArrayData; import org.apache.flex.html.beads.DataItemRendererFactoryForArrayData; DataItemRendererFactoryForArrayData; import org.apache.flex.html.beads.DataItemRendererFactoryForArrayList; DataItemRendererFactoryForArrayList; + import org.apache.flex.html.beads.DataItemRendererFactoryForHierarchicalData; DataItemRendererFactoryForHierarchicalData; import org.apache.flex.html.supportClasses.DataGroup; DataGroup; import org.apache.flex.html.supportClasses.Viewport; Viewport; import org.apache.flex.html.supportClasses.ScrollingViewport; ScrollingViewport; @@ -163,7 +165,7 @@ internal class HTMLClasses import org.apache.flex.html.MXMLBeadViewBase; MXMLBeadViewBase; import org.apache.flex.html.beads.TitleBarView; TitleBarView; import org.apache.flex.html.beads.TitleBarMeasurementBead; TitleBarMeasurementBead; - + import org.apache.flex.html.beads.WebBrowserView; WebBrowserView; import org.apache.flex.html.beads.models.WebBrowserModel; WebBrowserModel; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Tree.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Tree.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Tree.as new file mode 100644 index 0000000..c23e7f9 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Tree.as @@ -0,0 +1,73 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.html +{ + import org.apache.flex.collections.FlattenedList; + import org.apache.flex.collections.HierarchicalData; + + /** + * The Tree component displays structured data. The Tree uses a HierarchicalData + * object as its data provider. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class Tree extends List + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function Tree() + { + super(); + } + + private var _hierarchicalData:HierarchicalData; + private var _flatList:FlattenedList; + + /** + * The dataProvider should be of type HierarchicalData. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @see org.apache.flex.collections.HierarchicalData. + */ + override public function get dataProvider():Object + { + return _hierarchicalData; + } + override public function set dataProvider(value:Object):void + { + _hierarchicalData = value as HierarchicalData; + + _flatList = new FlattenedList(_hierarchicalData); + + super.dataProvider = _flatList; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryForHierarchicalData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryForHierarchicalData.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryForHierarchicalData.as new file mode 100644 index 0000000..58bfd21 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryForHierarchicalData.as @@ -0,0 +1,109 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.html.beads +{ + import org.apache.flex.core.IBead; + import org.apache.flex.core.IDataProviderItemRendererMapper; + import org.apache.flex.core.IItemRendererClassFactory; + import org.apache.flex.core.IItemRendererParent; + import org.apache.flex.core.IListPresentationModel; + import org.apache.flex.core.ISelectableItemRenderer; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.SimpleCSSStyles; + import org.apache.flex.core.UIBase; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.List; + import org.apache.flex.html.supportClasses.TreeListData; + import org.apache.flex.collections.FlattenedList; + + /** + * The DataItemRendererFactoryForHierarchicalData class reads a + * HierarchicalData object and creates an item renderer for every + * item in the array. Other implementations of + * IDataProviderItemRendererMapper map different data + * structures or manage a virtual set of renderers. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class DataItemRendererFactoryForHierarchicalData extends DataItemRendererFactoryForArrayList + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function DataItemRendererFactoryForHierarchicalData() + { + super(); + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override public function set strand(value:IStrand):void + { + _strand = value; + + super.strand = value; + } + + /** + * Sets the itemRenderer's data with additional tree-related data. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override protected function setData(ir:ISelectableItemRenderer, data:Object, index:int):void + { + // Set the listData with the depth of this item + var flatList:FlattenedList = selectionModel.dataProvider as FlattenedList; + var depth:int = flatList.getDepth(data); + var isOpen:Boolean = flatList.isOpen(data); + var hasChildren:Boolean = flatList.hasChildren(data); + + var treeData:TreeListData = new TreeListData(); + treeData.depth = depth; + treeData.isOpen = isOpen; + treeData.hasChildren = hasChildren; + + ir.listData = treeData; + + super.setData(ir, data, index); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ListSingleSelectionMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ListSingleSelectionMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ListSingleSelectionMouseController.as index e8a1f1f..dbeac6b 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ListSingleSelectionMouseController.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ListSingleSelectionMouseController.as @@ -111,27 +111,27 @@ package org.apache.flex.html.beads.controllers IEventDispatcher(_strand).addEventListener("itemRemoved", handleItemRemoved); } - private function handleItemAdded(event:ItemAddedEvent):void + protected function handleItemAdded(event:ItemAddedEvent):void { IEventDispatcher(event.item).addEventListener("itemClicked", selectedHandler); IEventDispatcher(event.item).addEventListener("itemRollOver", rolloverHandler); IEventDispatcher(event.item).addEventListener("itemRollOut", rolloutHandler); } - private function handleItemRemoved(event:ItemAddedEvent):void + protected function handleItemRemoved(event:ItemAddedEvent):void { IEventDispatcher(event.item).removeEventListener("itemClicked", selectedHandler); IEventDispatcher(event.item).removeEventListener("itemRollOver", rolloverHandler); IEventDispatcher(event.item).removeEventListener("itemRollOut", rolloutHandler); } - private function selectedHandler(event:ItemClickedEvent):void + protected function selectedHandler(event:ItemClickedEvent):void { listModel.selectedIndex = event.index; listView.host.dispatchEvent(new Event("change")); } - private function rolloverHandler(event:Event):void + protected function rolloverHandler(event:Event):void { var renderer:ISelectableItemRenderer = event.currentTarget as ISelectableItemRenderer; if (renderer) { @@ -140,7 +140,7 @@ package org.apache.flex.html.beads.controllers } } - private function rolloutHandler(event:Event):void + protected function rolloutHandler(event:Event):void { var renderer:ISelectableItemRenderer = event.currentTarget as ISelectableItemRenderer; if (renderer) { http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/TreeSingleSelectionMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/TreeSingleSelectionMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/TreeSingleSelectionMouseController.as new file mode 100644 index 0000000..a668fa4 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/TreeSingleSelectionMouseController.as @@ -0,0 +1,82 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.html.beads.controllers +{ + import org.apache.flex.collections.FlattenedList; + import org.apache.flex.html.Tree + import org.apache.flex.events.ItemClickedEvent; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + + /** + * The TreeSingleSelectionMouseController class is a controller for + * org.apache.flex.html.Tree. This controller watches for selection + * events on the tree item renderers and uses those events to open + * or close nodes of the tree. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class TreeSingleSelectionMouseController extends ListSingleSelectionMouseController + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function TreeSingleSelectionMouseController() + { + super(); + } + + private var _strand:IStrand; + + /** + * @private + */ + override public function set strand(value:IStrand):void + { + _strand = value; + super.strand = value; + } + + /** + * @private + */ + override protected function selectedHandler(event:ItemClickedEvent):void + { + var tree:Tree = _strand as Tree; + var flatList:FlattenedList = listModel.dataProvider as FlattenedList; + var node:Object = event.data; + + if (flatList.isOpen(node)) { + flatList.closeNode(node); + } else { + flatList.openNode(node); + } + + listModel.dispatchEvent(new Event("dataProviderChanged")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/StringItemRenderer.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/StringItemRenderer.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/StringItemRenderer.as index 9568932..db0977e 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/StringItemRenderer.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/StringItemRenderer.as @@ -173,9 +173,6 @@ package org.apache.flex.html.supportClasses // the selection and highlight backgroundView = element; - controller = new ItemRendererMouseController(); - controller.strand = this; - return element; } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/TreeItemRenderer.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/TreeItemRenderer.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/TreeItemRenderer.as new file mode 100644 index 0000000..bf545b0 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/TreeItemRenderer.as @@ -0,0 +1,59 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.html.supportClasses +{ + public class TreeItemRenderer extends StringItemRenderer + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function TreeItemRenderer() + { + super(); + } + + /** + * Sets the data for the itemRenderer instance along with the listData + * (TreeListData). + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override public function set data(value:Object):void + { + super.data = value; + + var treeData:TreeListData = listData as TreeListData; + + var indent:String = treeData.hasChildren ? (treeData.isOpen ? "-" : "+") : " "; + for (var i:int=0; i < treeData.depth; i++) { + indent += " "; + } + + this.text = indent + this.text; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/TreeListData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/TreeListData.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/TreeListData.as new file mode 100644 index 0000000..c6da4d5 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/TreeListData.as @@ -0,0 +1,76 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.html.supportClasses +{ + /** + * The TreeListData class contains information that Tree item renderers may + * find useful when displaying the data for a node in the tree. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignoreimport goog.events.Event + */ + public class TreeListData + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function TreeListData() + { + } + + /** + * The depth of the data within the tree with the root being zero. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var depth:Number; + + /** + * Whether or not the node for this data is open (and its children + * visible). + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var isOpen:Boolean; + + /** + * Whether or not the node for this data has any children. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var hasChildren:Boolean; + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml index 3b72af6..8a4db07 100644 --- a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml +++ b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml @@ -49,6 +49,7 @@ <component id="TitleBar" class="org.apache.flex.html.TitleBar"/> <component id="TitleBarModel" class="org.apache.flex.html.beads.models.TitleBarModel"/> <component id="ToolTip" class="org.apache.flex.html.ToolTip"/> + <component id="Tree" class="org.apache.flex.html.Tree"/> <component id="BasicLayout" class="org.apache.flex.html.beads.layouts.BasicLayout"/> <component id="VerticalLayout" class="org.apache.flex.html.beads.layouts.VerticalLayout"/> <component id="HorizontalLayout" class="org.apache.flex.html.beads.layouts.HorizontalLayout"/> @@ -62,6 +63,7 @@ <component id="Slider" class="org.apache.flex.html.Slider"/> <component id="NumericStepper" class="org.apache.flex.html.NumericStepper" /> <component id="StringItemRenderer" class="org.apache.flex.html.supportClasses.StringItemRenderer"/> + <component id="TreeItemRenderer" class="org.apache.flex.html.supportClasses.TreeItemRenderer"/> <component id="DataItemRenderer" class="org.apache.flex.html.supportClasses.DataItemRenderer"/> <component id="ButtonBarButtonItemRenderer" class="org.apache.flex.html.supportClasses.ButtonBarButtonItemRenderer"/> <!-- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86ebc1d4/frameworks/projects/HTML/src/main/resources/defaults.css ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/resources/defaults.css b/frameworks/projects/HTML/src/main/resources/defaults.css index 13d7418..ea0c0c8 100644 --- a/frameworks/projects/HTML/src/main/resources/defaults.css +++ b/frameworks/projects/HTML/src/main/resources/defaults.css @@ -206,6 +206,22 @@ List border-color: #222222; } +Tree +{ + IBeadModel: ClassReference("org.apache.flex.html.beads.models.ArraySelectionModel"); + IBeadView: ClassReference("org.apache.flex.html.beads.ListView"); + IBeadController: ClassReference("org.apache.flex.html.beads.controllers.TreeSingleSelectionMouseController"); + IBeadLayout: ClassReference("org.apache.flex.html.beads.layouts.VerticalLayout"); + IContentView: ClassReference("org.apache.flex.html.supportClasses.DataGroup"); + IDataProviderItemRendererMapper: ClassReference("org.apache.flex.html.beads.DataItemRendererFactoryForHierarchicalData"); + IItemRendererClassFactory: ClassReference("org.apache.flex.core.ItemRendererClassFactory"); + IItemRenderer: ClassReference("org.apache.flex.html.supportClasses.TreeItemRenderer"); + IViewport: ClassReference("org.apache.flex.html.supportClasses.ScrollingViewport"); + IViewportModel: ClassReference("org.apache.flex.html.beads.models.ViewportModel"); + border-style: solid; + border-color: #222222; +} + NumericStepper { IBeadModel: ClassReference("org.apache.flex.html.beads.models.RangeModel"); @@ -266,6 +282,12 @@ StringItemRenderer height: 16; } +TreeItemRenderer +{ + IBeadController: ClassReference("org.apache.flex.html.beads.controllers.ItemRendererMouseController"); + height: 16; +} + TextInput { border: 1px solid #808080;
