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 2018/12/12 11:59:50 UTC
[royale-asjs] branch develop updated: DispatchChangeOnStartup is
used by Jewel components with data provider to dispatch a CHANGE event when
the component is initialized
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 f003672 DispatchChangeOnStartup is used by Jewel components with data provider to dispatch a CHANGE event when the component is initialized
f003672 is described below
commit f0036722d04b9fa7a8617caf042b2b3c97b4f276
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Wed Dec 12 12:59:43 2018 +0100
DispatchChangeOnStartup is used by Jewel components with data provider to dispatch a CHANGE event when the component is initialized
---
.../Jewel/src/main/resources/jewel-manifest.xml | 1 +
.../beads/controls/DispatchChangeOnStartup.as | 110 +++++++++++++++++++++
2 files changed, 111 insertions(+)
diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
index 5e982ba..1fa2c24 100644
--- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
+++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
@@ -119,6 +119,7 @@
<component id="ResponsiveDrawer" class="org.apache.royale.jewel.beads.controls.drawer.ResponsiveDrawer"/>
+ <component id="DispatchChangeOnStartup" class="org.apache.royale.jewel.beads.controls.DispatchChangeOnStartup"/>
<component id="DropDownListTextPrompt" class="org.apache.royale.jewel.beads.controls.dropdownlist.DropDownListTextPrompt"/>
<component id="ComboBoxTextPrompt" class="org.apache.royale.jewel.beads.controls.combobox.ComboBoxTextPrompt"/>
<component id="SearchFilter" class="org.apache.royale.jewel.beads.controls.combobox.SearchFilter"/>
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/DispatchChangeOnStartup.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/DispatchChangeOnStartup.as
new file mode 100644
index 0000000..2ca3e50
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/DispatchChangeOnStartup.as
@@ -0,0 +1,110 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ import org.apache.royale.core.IBead;
+ import org.apache.royale.core.IStrand;
+ import org.apache.royale.events.IEventDispatcher;
+ import org.apache.royale.events.Event;
+ import org.apache.royale.jewel.beads.models.IJewelSelectionModel;
+
+ /**
+ * The DispatchChangeOnStartup bead class is a specialty bead that can be used
+ * with components that implements IJewelSelectionModel and uses dataProvider
+ * to dispatch a CHANGE event when the component is initialized
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.4
+ */
+ public class DispatchChangeOnStartup implements IBead
+ {
+ /**
+ * constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.4
+ */
+ public function DispatchChangeOnStartup()
+ {
+ }
+
+
+ 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.4
+ * @royaleignorecoercion org.apache.royale.events.IEventDispatcher;
+ */
+ public function set strand(value:IStrand):void
+ {
+ _strand = value;
+ IEventDispatcher(_strand).addEventListener('beadsAdded', adjustModel);
+ }
+
+
+ /**
+ * adjust the way the model behaves for dispatching change events
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.4
+ * @royaleignorecoercion org.apache.royale.events.IEventDispatcher
+ */
+ private function adjustModel(event:Event):void
+ {
+ IEventDispatcher(_strand).removeEventListener('beadsAdded', adjustModel);
+ const model:IJewelSelectionModel = _strand.getBeadByType(IJewelSelectionModel) as IJewelSelectionModel;
+ if (model) {
+ model.dispatchChangeOnDataProviderChange = true;
+ IEventDispatcher(model).addEventListener('dataProviderChanged', onChange);
+ IEventDispatcher(model).addEventListener('change', onChange);
+ } else {
+ //for now
+ throw new Error('DispatchChangeOnStartup bead is not yet compatible with the component it is being applied to');
+ }
+ }
+
+ private var _sawDataProviderChange:Boolean;
+ private function onChange(event:Event):void{
+ if (event.type == 'dataProviderChanged') {
+ _sawDataProviderChange = true;
+ return;
+ }
+ //event here is normal change event
+ if (!_sawDataProviderChange) {
+ //wait for a change event after dataProviderChange? needs review, maybe not
+ return;
+ }
+ const model:IJewelSelectionModel = _strand.getBeadByType(IJewelSelectionModel) as IJewelSelectionModel;
+ model.dispatchChangeOnDataProviderChange = false;
+ IEventDispatcher(model).removeEventListener('dataProviderChanged', onChange);
+ IEventDispatcher(model).removeEventListener('change', onChange);
+ }
+ }
+}