You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2019/01/02 14:46:18 UTC
[royale-asjs] branch develop updated: SearchFilterForList is a bead
to use with TextInput to filter a List
This is an automated email from the ASF dual-hosted git repository.
carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new d6bfd3a SearchFilterForList is a bead to use with TextInput to filter a List
d6bfd3a is described below
commit d6bfd3af67d4f7669395012af5a828c033b3b241
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Wed Jan 2 15:46:11 2019 +0100
SearchFilterForList is a bead to use with TextInput to filter a List
---
.../src/main/royale/ListPlayGround.mxml | 7 ++
.../Jewel/src/main/resources/jewel-manifest.xml | 1 +
.../controls/textinput/SearchFilterForList.as | 139 +++++++++++++++++++++
3 files changed, 147 insertions(+)
diff --git a/examples/royale/TourDeJewel/src/main/royale/ListPlayGround.mxml b/examples/royale/TourDeJewel/src/main/royale/ListPlayGround.mxml
index f5f87d3..4073aab 100644
--- a/examples/royale/TourDeJewel/src/main/royale/ListPlayGround.mxml
+++ b/examples/royale/TourDeJewel/src/main/royale/ListPlayGround.mxml
@@ -168,6 +168,13 @@ limitations under the License.
<j:Label html="{'Selected Index: ' + iconList.selectedIndex}"/>
<j:Label html="Selected Item description:"/>
<j:Label html="{describeIconItem(iconList.selectedItem)}"/>
+ <j:TextInput>
+ <j:beads>
+ <j:TextPrompt prompt="filter list..."/>
+ <j:SearchFilterForList list="{iconList}"/>
+ <!-- property="label" defaults to label so it's not needed -->
+ </j:beads>
+ </j:TextInput>
<!-- example below for dataProvider binding -->
<!--<j:List labelField="label" dataProvider="{iconList.dataProvider}" selectedIndex="3" width="120" height="200" />-->
</j:VGroup>
diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
index adc8285..a99e66f 100644
--- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
+++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
@@ -131,6 +131,7 @@
<component id="MaxNumberCharacters" class="org.apache.royale.jewel.beads.controls.textinput.MaxNumberCharacters"/>
<component id="Restrict" class="org.apache.royale.jewel.beads.controls.textinput.Restrict"/>
<component id="UpperCase" class="org.apache.royale.jewel.beads.controls.textinput.UpperCase"/>
+ <component id="SearchFilterForList" class="org.apache.royale.jewel.beads.controls.textinput.SearchFilterForList"/>
<component id="LowerCase" class="org.apache.royale.jewel.beads.controls.textinput.LowerCase"/>
<component id="ComboUpperCase" class="org.apache.royale.jewel.beads.controls.combobox.ComboUpperCase"/>
<component id="ComboLowerCase" class="org.apache.royale.jewel.beads.controls.combobox.ComboLowerCase"/>
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/textinput/SearchFilterForList.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/textinput/SearchFilterForList.as
new file mode 100644
index 0000000..cafa779
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/textinput/SearchFilterForList.as
@@ -0,0 +1,139 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.jewel.beads.controls.textinput
+{
+ import org.apache.royale.core.IBead;
+ import org.apache.royale.core.IStrand;
+ import org.apache.royale.events.Event;
+ import org.apache.royale.events.IEventDispatcher;
+ import org.apache.royale.events.KeyboardEvent;
+ import org.apache.royale.jewel.List;
+ import org.apache.royale.jewel.itemRenderers.ListItemRenderer;
+ import org.apache.royale.jewel.supportClasses.textinput.TextInputBase;
+
+ /**
+ * The SearchFilterForList bead class is a specialty bead that can be used with
+ * a Jewel TextInput to filter options in other List component
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.5
+ */
+ public class SearchFilterForList implements IBead
+ {
+ /**
+ * constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.5
+ */
+ public function SearchFilterForList()
+ {
+ }
+
+ private var _textInput:TextInputBase;
+ private var _strand:IStrand;
+
+ /**
+ * @copy org.apache.royale.core.IBead#strand
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.5
+ * @royaleignorecoercion org.apache.royale.events.IEventDispatcher;
+ */
+ public function set strand(value:IStrand):void
+ {
+ _strand = value;
+ IEventDispatcher(_strand).addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
+ IEventDispatcher(_strand).addEventListener('beadsAdded', onBeadsAdded);
+ }
+
+ protected function onBeadsAdded(event:Event):void{
+ COMPILE::JS{
+ TextInputBase(_strand).element.addEventListener('focus', onInputFocus);
+ }
+ }
+
+ /**
+ * the filter function to use to filter entries in the combobox popup list
+ */
+ [Bindable]
+ public var filterFunction:Function = defaultFilterFunction;
+
+ /**
+ * default filter function just filters substrings
+ * you can use other advanced methods like levenshtein distance
+ */
+ protected function defaultFilterFunction(text:String, filterText:String):Boolean
+ {
+ return text.toUpperCase().indexOf(filterText) > -1;
+ }
+
+ COMPILE::JS
+ protected function onInputFocus(event:Event):void{
+ applyFilter(_textInput);
+ }
+
+ protected function keyUpHandler(event:KeyboardEvent):void
+ {
+ const inputBase:TextInputBase = event.target as TextInputBase;
+ //keyup can include other things like tab navigation
+
+ if (!inputBase) {
+ //if (popUpVisible) event.target.parent.view.popUpVisible = false;
+ return;
+ }
+
+ applyFilter(inputBase);
+ }
+
+ [Bindable]
+ public var list:List;
+
+ [Bindable]
+ public var property:String = "label";
+
+ protected function applyFilter(input:TextInputBase):void{
+ var filterText:String = TextInputBase(_strand).text.toUpperCase();
+
+ var ir:ListItemRenderer;
+ var numElements:int = list.numElements;
+ var count:uint = 0;
+ var lastActive:ListItemRenderer;
+ for (var i:int = 0; i < numElements; i++)
+ {
+ ir = list.getElementAt(i) as ListItemRenderer;
+ if (filterFunction(ir.data[property], filterText))
+ {
+ ir.visible = true;
+ lastActive = ir;
+ count++;
+ } else {
+ ir.visible = false;
+ }
+ }
+ }
+
+ }
+}