Updated Branches: refs/heads/develop 146dc0ac4 -> ae3a4756d
Removed "list" display and replaced with list in pop-up. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/ae3a4756 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/ae3a4756 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/ae3a4756 Branch: refs/heads/develop Commit: ae3a4756d5161ab8c831412ee4aede9568ffbfeb Parents: 146dc0a Author: Peter Ent <[email protected]> Authored: Tue Mar 26 15:53:19 2013 -0400 Committer: Peter Ent <[email protected]> Committed: Tue Mar 26 15:53:19 2013 -0400 ---------------------------------------------------------------------- frameworks/as/defaults.css | 1 + .../as/src/org/apache/flex/core/IComboBoxBead.as | 5 + .../as/src/org/apache/flex/core/IComboBoxModel.as | 4 +- .../apache/flex/html/staticControls/ComboBox.as | 7 +- .../flex/html/staticControls/beads/ComboBoxBead.as | 84 ++++++++++----- .../beads/controllers/ComboBoxController.as | 71 ++++++++++++ .../apache/flex/html/staticControls/ComboBox.js | 46 ++++++++- 7 files changed, 186 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ae3a4756/frameworks/as/defaults.css ---------------------------------------------------------------------- diff --git a/frameworks/as/defaults.css b/frameworks/as/defaults.css index a197ad6..4abbeff 100644 --- a/frameworks/as/defaults.css +++ b/frameworks/as/defaults.css @@ -37,6 +37,7 @@ ComboBox { IComboBoxBead: ClassReference("org.apache.flex.html.staticControls.beads.ComboBoxBead"); IComboBoxModel: ClassReference("org.apache.flex.html.staticControls.beads.models.ComboBoxModel"); + IPopUp: ClassReference("org.apache.flex.html.staticControls.supportClasses.DropDownListList"); } DropDownList http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ae3a4756/frameworks/as/src/org/apache/flex/core/IComboBoxBead.as ---------------------------------------------------------------------- diff --git a/frameworks/as/src/org/apache/flex/core/IComboBoxBead.as b/frameworks/as/src/org/apache/flex/core/IComboBoxBead.as index 814339c..6fd3e7a 100644 --- a/frameworks/as/src/org/apache/flex/core/IComboBoxBead.as +++ b/frameworks/as/src/org/apache/flex/core/IComboBoxBead.as @@ -26,5 +26,10 @@ package org.apache.flex.core function get html():String; function set html(value:String):void; + + function get popUp():IStrand; + + function get popUpVisible():Boolean; + function set popUpVisible(value:Boolean):void; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ae3a4756/frameworks/as/src/org/apache/flex/core/IComboBoxModel.as ---------------------------------------------------------------------- diff --git a/frameworks/as/src/org/apache/flex/core/IComboBoxModel.as b/frameworks/as/src/org/apache/flex/core/IComboBoxModel.as index 9aa003c..f68638b 100644 --- a/frameworks/as/src/org/apache/flex/core/IComboBoxModel.as +++ b/frameworks/as/src/org/apache/flex/core/IComboBoxModel.as @@ -18,7 +18,9 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.core { - public interface IComboBoxModel + import org.apache.flex.events.IEventDispatcher; + + public interface IComboBoxModel extends IEventDispatcher, IBeadModel { function get text():String; function set text(value:String):void; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ae3a4756/frameworks/as/src/org/apache/flex/html/staticControls/ComboBox.as ---------------------------------------------------------------------- diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/ComboBox.as b/frameworks/as/src/org/apache/flex/html/staticControls/ComboBox.as index 4fd6f54..40920a8 100644 --- a/frameworks/as/src/org/apache/flex/html/staticControls/ComboBox.as +++ b/frameworks/as/src/org/apache/flex/html/staticControls/ComboBox.as @@ -24,6 +24,9 @@ package org.apache.flex.html.staticControls import org.apache.flex.core.IInitSkin; import org.apache.flex.core.UIBase; import org.apache.flex.core.ValuesManager; + import org.apache.flex.html.staticControls.beads.controllers.ComboBoxController; + + [Event("change", org.apache.flex.events.Event)] public class ComboBox extends UIBase implements IInitSkin { @@ -60,7 +63,9 @@ package org.apache.flex.html.staticControls { if (getBeadByType(IComboBoxBead) == null) { var cb:IComboBoxBead = new (ValuesManager.valuesImpl.getValue(this, "iComboBoxBead")) as IComboBoxBead; - addBead(cb); + addBead(cb); + var lc:ComboBoxController = new ComboBoxController(); + addBead(lc); } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ae3a4756/frameworks/as/src/org/apache/flex/html/staticControls/beads/ComboBoxBead.as ---------------------------------------------------------------------- diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/ComboBoxBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/ComboBoxBead.as index ef31444..82d2ec0 100644 --- a/frameworks/as/src/org/apache/flex/html/staticControls/beads/ComboBoxBead.as +++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/ComboBoxBead.as @@ -18,17 +18,22 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.staticControls.beads { + import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; import flash.display.Sprite; import org.apache.flex.binding.ConstantBinding; import org.apache.flex.core.IBead; import org.apache.flex.core.IComboBoxBead; + import org.apache.flex.core.IComboBoxModel; + import org.apache.flex.core.IInitModel; + import org.apache.flex.core.IInitSkin; + import org.apache.flex.core.ISelectionModel; import org.apache.flex.core.IStrand; + import org.apache.flex.core.ValuesManager; import org.apache.flex.events.Event; import org.apache.flex.events.IEventDispatcher; import org.apache.flex.html.staticControls.Button; - import org.apache.flex.html.staticControls.List; import org.apache.flex.html.staticControls.TextInput; public class ComboBoxBead implements IBead, IComboBoxBead @@ -39,7 +44,6 @@ package org.apache.flex.html.staticControls.beads private var textInput:TextInput; private var button:Button; - private var list:List; public function get text():String { @@ -65,9 +69,13 @@ package org.apache.flex.html.staticControls.beads return _strand; } + private var selectionModel:IComboBoxModel; + public function set strand(value:IStrand):void { _strand = value; + selectionModel = value.getBeadByType(IComboBoxModel) as IComboBoxModel; + selectionModel.addEventListener("selectedIndexChanged", selectionChangeHandler); textInput = new TextInput(); textInput.addToParent(DisplayObjectContainer(strand)); @@ -92,23 +100,6 @@ package org.apache.flex.html.staticControls.beads button.y = textInput.y; button.initSkin(); - list = new List(); - list.addToParent(DisplayObjectContainer(strand)); - list.initModel(); - list.width = 118; - list.height = 100; - list.x = textInput.x; - list.y = textInput.y + textInput.height + 2; - - if( value.getBeadByType(ConstantBinding) ) { - var cb:ConstantBinding = value.getBeadByType(ConstantBinding) as ConstantBinding; - list.addBead(cb); - } - list.initSkin(); - - // listen for events on the list and take those selections to the text input - list.addEventListener("change", listChangeHandler,false,0,true); - // listen for events on the text input and modify the list and selection textInput.addEventListener("change", textChangeHandler,false,0,true); } @@ -137,20 +128,55 @@ package org.apache.flex.html.staticControls.beads sprite.graphics.endFill(); } - private function listChangeHandler(event:Event):void + private var _popUp:IStrand; + public function get popUp():IStrand { - var item:Object = list.selectedItem; - textInput.text = item.toString(); - - var newEvent:Event = new Event("change"); - IEventDispatcher(strand).dispatchEvent(newEvent); + return _popUp; } - private function textChangeHandler(event:Event):void + private var _popUpVisible:Boolean; + + public function get popUpVisible():Boolean { - list.selectedItem = textInput.text; - list.selectedIndex = -1; - + return _popUpVisible; + } + + public function set popUpVisible(value:Boolean):void + { + if (value != _popUpVisible) + { + _popUpVisible = value; + if (value) + { + if (!_popUp) + { + var popUpClass:Class = ValuesManager.valuesImpl.getValue(_strand, "iPopUp") as Class; + _popUp = new popUpClass() as IStrand; + } + var root:Object = DisplayObject(_strand).root; + var host:DisplayObjectContainer = DisplayObject(_strand).parent; + while (host.parent != root) + host = host.parent; + host.addChild(_popUp as DisplayObject); + if (_popUp is IInitModel) + IInitModel(_popUp).initModel(); + if (_popUp is IInitSkin) + IInitSkin(_popUp).initSkin(); + } + else + { + DisplayObject(_popUp).parent.removeChild(_popUp as DisplayObject); + } + } + } + + private function selectionChangeHandler(event:Event):void + { + text = selectionModel.selectedItem.toString(); + } + + private function textChangeHandler(event:Event):void + { var newEvent:Event = new Event("change"); IEventDispatcher(strand).dispatchEvent(newEvent); } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ae3a4756/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/ComboBoxController.as ---------------------------------------------------------------------- diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/ComboBoxController.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/ComboBoxController.as new file mode 100644 index 0000000..6439bf8 --- /dev/null +++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/ComboBoxController.as @@ -0,0 +1,71 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.staticControls.beads.controllers +{ + import flash.display.DisplayObject; + import flash.events.MouseEvent; + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IComboBoxBead; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + public class ComboBoxController implements IBead + { + public function ComboBoxController() + { + } + + private var _strand:IStrand; + + public function set strand(value:IStrand):void + { + _strand = value; + IEventDispatcher(value).addEventListener(MouseEvent.CLICK, clickHandler); + } + + private function clickHandler(event:MouseEvent):void + { + var viewBead:IComboBoxBead = _strand.getBeadByType(IComboBoxBead) as IComboBoxBead; + viewBead.popUpVisible = true; + var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel; + var popUpModel:ISelectionModel = viewBead.popUp.getBeadByType(ISelectionModel) as ISelectionModel; + popUpModel.dataProvider = selectionModel.dataProvider; + popUpModel.selectedIndex = selectionModel.selectedIndex; + DisplayObject(viewBead.popUp).width = DisplayObject(_strand).width; + DisplayObject(viewBead.popUp).height = 200; + DisplayObject(viewBead.popUp).x = DisplayObject(_strand).x; + DisplayObject(viewBead.popUp).y = DisplayObject(_strand).y; + IEventDispatcher(viewBead.popUp).addEventListener("change", changeHandler); + } + + private function changeHandler(event:Event):void + { + var viewBead:IComboBoxBead = _strand.getBeadByType(IComboBoxBead) as IComboBoxBead; + viewBead.popUpVisible = false; + var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel; + var popUpModel:ISelectionModel = viewBead.popUp.getBeadByType(ISelectionModel) as ISelectionModel; + selectionModel.selectedIndex = popUpModel.selectedIndex; + IEventDispatcher(_strand).dispatchEvent(new Event("change")); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ae3a4756/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/ComboBox.js ---------------------------------------------------------------------- diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/ComboBox.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/ComboBox.js index 5e63d38..fbfc29d 100644 --- a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/ComboBox.js +++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/ComboBox.js @@ -40,7 +40,7 @@ goog.inherits( * @param {Object} p The parent element. */ org.apache.flex.html.staticControls.ComboBox.prototype.addToParent = - function(p) { +function(p) { this.element = document.createElement('div'); var input = document.createElement('input'); @@ -50,10 +50,23 @@ org.apache.flex.html.staticControls.ComboBox.prototype.addToParent = box.onchange = this.selectChanged; this.element.appendChild(box); + var button = document.createElement('div'); + button.style.position = "absolute"; + button.style.top = "0px"; + button.style.right = "0px"; + button.style.background = "#bbb"; + button.style.width = "16px"; + button.style.height = "20px"; + button.style.margin = "0"; + button.style.border = "solid #609 1px"; + button.onclick = this.buttonClicked; + this.element.appendChild(button); + this.element.style.position = "relative"; input.style.width = "100px"; input.style["float"] = "left"; box.style["float"] = "left"; + button.style["float"] = "left"; p.appendChild(this.element); @@ -71,6 +84,37 @@ function() { input.value = box.value; }; +org.apache.flex.html.staticControls.ComboBox.prototype.buttonClicked = +function() { + var box = this.parentNode.childNodes.item(1); + + var popup = document.createElement('div'); + popup.className = 'popup'; + popup.id = 'test'; + popup.style.position = "absolute"; + popup.style.top = "0px"; + popup.style.left = "0px"; + popup.style.margin = "100px auto"; + popup.style.width = "200px"; + popup.style.height = "150px"; + popup.style.padding = "10px"; + popup.style['background-color'] = "rgb(240,240,240)"; + popup.style.border = "2px solid grey"; + popup.style['z-index'] = "100000000000000000"; + popup.style.display = "none"; + var cancel = document.createElement('div'); + cancel.className = 'cancel'; + cancel.innerHTML = 'close'; + cancel.onclick = function (e) { popup.parentNode.removeChild(popup) }; + var message = document.createElement('span'); + message.innerHTML = "This is a test message"; + popup.appendChild(message); + popup.appendChild(cancel); + document.body.appendChild(popup); + + +}; + /** * @expose * @this {org.apache.flex.html.staticControls.ComboBox}
