You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by yi...@apache.org on 2022/03/15 18:08:34 UTC
[royale-asjs] branch develop updated: Fix #1181
This is an automated email from the ASF dual-hosted git repository.
yishayw 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 1cfe1e6 Fix #1181
new 75d3272 Merge branch 'develop' of https://github.com/apache/royale-asjs into develop
1cfe1e6 is described below
commit 1cfe1e6ed770a2c0fdc9fca884ea65d939a1eee6
Author: Yishay Weiss <yi...@hotmail.com>
AuthorDate: Tue Mar 15 20:05:03 2022 +0200
Fix #1181
---
.../projects/Basic/src/main/royale/BasicClasses.as | 1 +
.../apache/royale/html/util/getLabelFromXMLData.as | 80 ++++++++++++++++++++++
.../MXRoyale/src/main/resources/defaults.css | 7 +-
.../src/main/resources/mx-royale-manifest.xml | 2 +
.../main/royale/mx/controls/beads/ComboBoxView.as | 18 ++++-
.../main/royale/mx/supportClasses/ComboBoxList.as | 48 +++++++++++++
.../royale/mx/supportClasses/StringItemRenderer.as | 58 ++++++++++++++++
7 files changed, 212 insertions(+), 2 deletions(-)
diff --git a/frameworks/projects/Basic/src/main/royale/BasicClasses.as b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
index bccfa7b..d55dd8d 100644
--- a/frameworks/projects/Basic/src/main/royale/BasicClasses.as
+++ b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
@@ -353,6 +353,7 @@ internal class BasicClasses
import org.apache.royale.html.util.getLabelFromData; getLabelFromData;
+ import org.apache.royale.html.util.getLabelFromXMLData; getLabelFromXMLData;
COMPILE::JS
{
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/util/getLabelFromXMLData.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/util/getLabelFromXMLData.as
new file mode 100644
index 0000000..896809a
--- /dev/null
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/util/getLabelFromXMLData.as
@@ -0,0 +1,80 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 "Licens"); 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.html.util
+{
+
+ import org.apache.royale.core.IHasLabelField;
+ import org.apache.royale.core.IHasDataField;
+ import org.apache.royale.core.ILabeledData;
+ import org.apache.royale.core.IHasImage;
+
+ /**
+ * Utility function to get a label string from an XML value object
+ * It will use the following logic flow:
+ * First it tries a `labelField`
+ * Then the `dataField`
+ * If both of those fail, it tries a `label` property
+ * If all else fails, it just converts the object to a string
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.10
+ * @royaleignorecoercion org.apache.royale.core.IHasLabelField
+ * @royaleignorecoercion org.apache.royale.core.IHasDataField
+ * @royaleignorecoercion org.apache.royale.core.ILabeledData
+ */
+ public function getLabelFromXMLData(obj:Object, data:Object):String
+ {
+ var result:String;
+ var getLabelFromLabelField:Function = function(labelField:String, data:Object):String
+ {
+ if (labelField.charAt(0) == '@')
+ {
+ return data.attribute(labelField.split("@")[1]) as String;
+ }
+ return data.child(labelField).toString();
+ }
+ if (obj is IHasLabelField && (obj as IHasLabelField).labelField)
+ {
+ result = getLabelFromLabelField((obj as IHasLabelField).labelField, data);
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ if (obj is IHasDataField && (obj as IHasDataField).dataField)
+ {
+ result = getLabelFromLabelField((obj as IHasDataField).dataField, data);
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ var label:String = getLabelFromLabelField("label", data);
+ if(label != null)
+ {
+ return label;
+ }
+ return "" + data;
+ }
+
+}
diff --git a/frameworks/projects/MXRoyale/src/main/resources/defaults.css b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
index b3ffe2a..b7348d9 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/defaults.css
+++ b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
@@ -216,7 +216,12 @@ ComboBox
IBeadModel: ClassReference("mx.controls.beads.models.ComboBoxModel");
IBeadView: ClassReference("mx.controls.beads.ComboBoxView");
IBeadController: ClassReference("org.apache.royale.html.beads.controllers.ComboBoxController");
- IPopUp: ClassReference("org.apache.royale.html.supportClasses.ComboBoxList");
+ IPopUp: ClassReference("mx.supportClasses.ComboBoxList");
+}
+
+ComboBoxList
+{
+ IItemRenderer: ClassReference("mx.supportClasses.StringItemRenderer");
}
Container
diff --git a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
index 09c5ba5..4cd2886 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
+++ b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
@@ -76,6 +76,8 @@
<component id="ListItemRenderer" class="mx.controls.listClasses.ListItemRenderer" />
<component id="ButtonItemRenderer" class="mx.supportClasses.ButtonItemRenderer" />
<component id="FormItemRequired" class="mx.supportClasses.FormItemRequired" />
+ <component id="StringItemRenderer" class="mx.supportClasses.StringItemRenderer" />
+ <component id="ComboBoxList" class="mx.supportClasses.ComboBoxList" />
<!--<component id="ArrayList" class="mx.collections.ArrayList"/>-->
<component id="UIComponent" class="mx.core.UIComponent"/>
<component id="Container" class="mx.core.Container"/>
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/ComboBoxView.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/ComboBoxView.as
index bcb10d9..338d5fc 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/ComboBoxView.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/ComboBoxView.as
@@ -22,6 +22,10 @@ package mx.controls.beads
import org.apache.royale.events.Event;
import org.apache.royale.events.IEventDispatcher;
import org.apache.royale.html.beads.ComboBoxView;
+ import org.apache.royale.core.IComboBoxModel;
+ import org.apache.royale.html.util.getModelByType;
+ import org.apache.royale.html.util.getLabelFromXMLData;
+ import org.apache.royale.html.TextInput;
/**
* The ComboBoxView class.
@@ -61,6 +65,18 @@ package mx.controls.beads
if (sendClose)
IEventDispatcher(_strand).dispatchEvent(new Event("close"));
}
-
+
+ override protected function itemChangeAction():void
+ {
+ var model:IComboBoxModel = getModelByType(_strand,IComboBoxModel) as IComboBoxModel;
+ var selectedItem:Object = model.selectedItem;
+ if (selectedItem is XML)
+ {
+ (textInputField as TextInput).text = getLabelFromXMLData(model, selectedItem as XML);
+ } else
+ {
+ super.itemChangeAction();
+ }
+ }
}
}
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/supportClasses/ComboBoxList.as b/frameworks/projects/MXRoyale/src/main/royale/mx/supportClasses/ComboBoxList.as
new file mode 100644
index 0000000..77fb182
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/supportClasses/ComboBoxList.as
@@ -0,0 +1,48 @@
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 mx.supportClasses
+{
+ import org.apache.royale.html.supportClasses.ComboBoxList;
+
+ /**
+ * The ComboBoxList class is the List class used internally
+ * by ComboBox as the dropdown/popup.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.10
+ */
+ public class ComboBoxList extends org.apache.royale.html.supportClasses.ComboBoxList
+ {
+ /**
+ * Constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.10
+ */
+ public function ComboBoxList()
+ {
+ super();
+ }
+ }
+}
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/supportClasses/StringItemRenderer.as b/frameworks/projects/MXRoyale/src/main/royale/mx/supportClasses/StringItemRenderer.as
new file mode 100644
index 0000000..54350d9
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/supportClasses/StringItemRenderer.as
@@ -0,0 +1,58 @@
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 mx.supportClasses
+{
+ import org.apache.royale.html.supportClasses.StringItemRenderer;
+ import org.apache.royale.html.util.getLabelFromXMLData;
+
+ /**
+ * The ComboBoxList class is the item renderer used internally in ComboBoxList
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.10
+ */
+ public class StringItemRenderer extends org.apache.royale.html.supportClasses.StringItemRenderer
+ {
+ /**
+ * Constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.10
+ */
+ public function StringItemRenderer()
+ {
+ super();
+ }
+
+
+ override protected function dataToString(value:Object):String
+ {
+ if (value is XML)
+ {
+ return getLabelFromXMLData(this,value);
+ }
+ return super.dataToString(value);
+ }
+ }
+}