You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Hugo Ferreira <hf...@gmail.com> on 2022/06/07 19:57:49 UTC

Proposal for labelField with expression support

Hi,

In Flex "world" one can use labelField and labelFunction.
Here in Royale we have only labelField (at least I didn't see so far
support for labelFunction), however I'm not a big fan of labelFunction
anyway.

I always wanted support for something in between of labelField and
labelFunction (labelFunction with multiple fields and fixed strings) and I
implement it on my side.

Ex:
model:
public class User
{
public var Code:String;
public var Name:String;
}

With this model, one can use Code (user code) or Name but not the combined
fields.

With a little adition I can now do something like this: labelField="[Code]
- [Name]" and at runtime every field delimited by [] it's replaced for his
value, allowing multiple fields and complex expressions.

Can I commit this or there is a reason to not do so ?

Thank you,
Hugo.

Re: Proposal for labelField with expression support

Posted by Edward Stangler <es...@bradmark.com>.
Just to clarify:  you mean in MXML or ActionScript?



On 6/7/2022 2:58 PM, Hugo Ferreira wrote:
> Hi,
>
> In Flex "world" one can use labelField and labelFunction.
> Here in Royale we have only labelField (at least I didn't see so far
> support for labelFunction), however I'm not a big fan of labelFunction
> anyway.
...
> With a little adition I can now do something like this: labelField="[Code]
> - [Name]" and at runtime every field delimited by [] it's replaced for his
> value, allowing multiple fields and complex expressions.


Re: Proposal for labelField with expression support

Posted by Harbs <ha...@gmail.com>.
Yes. That’ll likely work.

> On Jun 8, 2022, at 12:34 AM, Hugo Ferreira <hf...@gmail.com> wrote:
> 
> I create the full path on my project
> org.apache.royale.html.util.getLabelFromData
> with the custom code and seems to override the SDK.
> 
> Hugo Ferreira <hf...@gmail.com> escreveu no dia terça, 7/06/2022
> à(s) 22:16:
> 
>> I use itemRenders for more visual complex things (images, text with bold,
>> etc ...)
>> On this case I have a generic itemRender (visual aspect) and what's
>> different it's the content.
>> Doing an itemRender for each ComboBox seems to much work and a simple
>> formula it's something in between for a less complex code structure.
>> 
>> But I understand what you mean, that's why I asked in the first place
>> before commit.
>> 
>> So, what's the best option to have this implemented only on my side (if
>> there is this option) ?
>> I would like to have this behaviour without put on the SDK and without
>> using itemRenderers.
>> For another word, how to have a copy of the custom getLabelFromData and
>> use this instead of the SDK ?
>> 
>> 
>> Harbs <ha...@gmail.com> escreveu no dia terça, 7/06/2022 à(s) 22:04:
>> 
>>> Hard coding it into a function which is widely used by ItemRenderers does
>>> not seem like a good idea or very PAYG.
>>> 
>>> Id suggest creating ItemRenderers which have this behavior.
>>> 
>>> If there’s some way to inject the behavior into existing functions that
>>> would be fine too, but I can’t think off hand of a good way of doing that.
>>> 
>>>> On Jun 7, 2022, at 11:48 PM, Hugo Ferreira <hf...@gmail.com>
>>> wrote:
>>>> 
>>>> Method getLabelFromData from getLabelFromData.as
>>>> 
>>>> I just added a new if block that seek for "[" and thread the keys.
>>>> If it's OK, I can commit, otherwise I ask what's the best alternative
>>>> solution to achive the same result.
>>>> 
>>>>   public function getLabelFromData(obj:Object,data:Object):String
>>>>   {
>>>>       // slightly more code, but we bail early if it's a string which
>>> is
>>>> often
>>>>       if (data is String) return "" + data;
>>>>       if(!data) return "";
>>>>       if(data is ILabeledData) return (data as ILabeledData).label;
>>>> 
>>>>       if (obj is IHasLabelField &&
>>>>           (obj as IHasLabelField).labelField &&
>>>>           (obj as IHasLabelField).labelField.indexOf("[") > -1)
>>>>       {
>>>>           var result:String = (obj as IHasLabelField).labelField;
>>>>           for each (var item:String in result.split("["))
>>>>           {
>>>>               if (item.indexOf("]") > -1)
>>>>               {
>>>>                   var field:String = item.split("]")[0];
>>>>                   result = result.replace("[" + field + "]",
>>> data[field]);
>>>>               }
>>>>           }
>>>>           return result;
>>>>       }
>>>> 
>>>>       if (obj is IHasLabelField &&
>>>>           (obj as IHasLabelField).labelField &&
>>>>           data[(obj as IHasLabelField).labelField] != null)
>>>>       {
>>>>           return "" + data[(obj as IHasLabelField).labelField];
>>>>       }
>>>> 
>>>>       if (obj is IHasDataField &&
>>>>           (obj as IHasDataField).dataField &&
>>>>           data[(obj as IHasDataField).dataField] != null)
>>>>       {
>>>>           return "" + data[(obj as IHasDataField).dataField];
>>>>       }
>>>> 
>>>>       var label:String = data["label"];
>>>>       if(label != null){
>>>>           return label;
>>>>       }
>>>>       return "" + data;
>>>> 
>>>>   }
>>>> 
>>>> Maria Jose Esteve <mj...@iest.com> escreveu no dia terça, 7/06/2022
>>> à(s)
>>>> 21:44:
>>>> 
>>>>> Hugo, could it be seen? Maybe a branch or a PR?
>>>>> 
>>>>> Hiedra
>>>>> 
>>>>> -----Mensaje original-----
>>>>> De: Hugo Ferreira <hf...@gmail.com>
>>>>> Enviado el: martes, 7 de junio de 2022 21:58
>>>>> Para: Apache Royale Development <de...@royale.apache.org>
>>>>> Asunto: Proposal for labelField with expression support
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> In Flex "world" one can use labelField and labelFunction.
>>>>> Here in Royale we have only labelField (at least I didn't see so far
>>>>> support for labelFunction), however I'm not a big fan of labelFunction
>>>>> anyway.
>>>>> 
>>>>> I always wanted support for something in between of labelField and
>>>>> labelFunction (labelFunction with multiple fields and fixed strings)
>>> and I
>>>>> implement it on my side.
>>>>> 
>>>>> Ex:
>>>>> model:
>>>>> public class User
>>>>> {
>>>>> public var Code:String;
>>>>> public var Name:String;
>>>>> }
>>>>> 
>>>>> With this model, one can use Code (user code) or Name but not the
>>> combined
>>>>> fields.
>>>>> 
>>>>> With a little adition I can now do something like this:
>>> labelField="[Code]
>>>>> - [Name]" and at runtime every field delimited by [] it's replaced for
>>> his
>>>>> value, allowing multiple fields and complex expressions.
>>>>> 
>>>>> Can I commit this or there is a reason to not do so ?
>>>>> 
>>>>> Thank you,
>>>>> Hugo.
>>>>> 
>>> 
>>> 


Re: Proposal for labelField with expression support

Posted by Hugo Ferreira <hf...@gmail.com>.
I create the full path on my project
org.apache.royale.html.util.getLabelFromData
with the custom code and seems to override the SDK.

Hugo Ferreira <hf...@gmail.com> escreveu no dia terça, 7/06/2022
à(s) 22:16:

> I use itemRenders for more visual complex things (images, text with bold,
> etc ...)
> On this case I have a generic itemRender (visual aspect) and what's
> different it's the content.
> Doing an itemRender for each ComboBox seems to much work and a simple
> formula it's something in between for a less complex code structure.
>
> But I understand what you mean, that's why I asked in the first place
> before commit.
>
> So, what's the best option to have this implemented only on my side (if
> there is this option) ?
> I would like to have this behaviour without put on the SDK and without
> using itemRenderers.
> For another word, how to have a copy of the custom getLabelFromData and
> use this instead of the SDK ?
>
>
> Harbs <ha...@gmail.com> escreveu no dia terça, 7/06/2022 à(s) 22:04:
>
>> Hard coding it into a function which is widely used by ItemRenderers does
>> not seem like a good idea or very PAYG.
>>
>> Id suggest creating ItemRenderers which have this behavior.
>>
>> If there’s some way to inject the behavior into existing functions that
>> would be fine too, but I can’t think off hand of a good way of doing that.
>>
>> > On Jun 7, 2022, at 11:48 PM, Hugo Ferreira <hf...@gmail.com>
>> wrote:
>> >
>> > Method getLabelFromData from getLabelFromData.as
>> >
>> > I just added a new if block that seek for "[" and thread the keys.
>> > If it's OK, I can commit, otherwise I ask what's the best alternative
>> > solution to achive the same result.
>> >
>> >    public function getLabelFromData(obj:Object,data:Object):String
>> >    {
>> >        // slightly more code, but we bail early if it's a string which
>> is
>> > often
>> >        if (data is String) return "" + data;
>> >        if(!data) return "";
>> >        if(data is ILabeledData) return (data as ILabeledData).label;
>> >
>> >        if (obj is IHasLabelField &&
>> >            (obj as IHasLabelField).labelField &&
>> >            (obj as IHasLabelField).labelField.indexOf("[") > -1)
>> >        {
>> >            var result:String = (obj as IHasLabelField).labelField;
>> >            for each (var item:String in result.split("["))
>> >            {
>> >                if (item.indexOf("]") > -1)
>> >                {
>> >                    var field:String = item.split("]")[0];
>> >                    result = result.replace("[" + field + "]",
>> data[field]);
>> >                }
>> >            }
>> >            return result;
>> >        }
>> >
>> >        if (obj is IHasLabelField &&
>> >            (obj as IHasLabelField).labelField &&
>> >            data[(obj as IHasLabelField).labelField] != null)
>> >        {
>> >            return "" + data[(obj as IHasLabelField).labelField];
>> >        }
>> >
>> >        if (obj is IHasDataField &&
>> >            (obj as IHasDataField).dataField &&
>> >            data[(obj as IHasDataField).dataField] != null)
>> >        {
>> >            return "" + data[(obj as IHasDataField).dataField];
>> >        }
>> >
>> >        var label:String = data["label"];
>> >        if(label != null){
>> >            return label;
>> >        }
>> >        return "" + data;
>> >
>> >    }
>> >
>> > Maria Jose Esteve <mj...@iest.com> escreveu no dia terça, 7/06/2022
>> à(s)
>> > 21:44:
>> >
>> >> Hugo, could it be seen? Maybe a branch or a PR?
>> >>
>> >> Hiedra
>> >>
>> >> -----Mensaje original-----
>> >> De: Hugo Ferreira <hf...@gmail.com>
>> >> Enviado el: martes, 7 de junio de 2022 21:58
>> >> Para: Apache Royale Development <de...@royale.apache.org>
>> >> Asunto: Proposal for labelField with expression support
>> >>
>> >> Hi,
>> >>
>> >> In Flex "world" one can use labelField and labelFunction.
>> >> Here in Royale we have only labelField (at least I didn't see so far
>> >> support for labelFunction), however I'm not a big fan of labelFunction
>> >> anyway.
>> >>
>> >> I always wanted support for something in between of labelField and
>> >> labelFunction (labelFunction with multiple fields and fixed strings)
>> and I
>> >> implement it on my side.
>> >>
>> >> Ex:
>> >> model:
>> >> public class User
>> >> {
>> >> public var Code:String;
>> >> public var Name:String;
>> >> }
>> >>
>> >> With this model, one can use Code (user code) or Name but not the
>> combined
>> >> fields.
>> >>
>> >> With a little adition I can now do something like this:
>> labelField="[Code]
>> >> - [Name]" and at runtime every field delimited by [] it's replaced for
>> his
>> >> value, allowing multiple fields and complex expressions.
>> >>
>> >> Can I commit this or there is a reason to not do so ?
>> >>
>> >> Thank you,
>> >> Hugo.
>> >>
>>
>>

Re: Proposal for labelField with expression support

Posted by Hugo Ferreira <hf...@gmail.com>.
OK, this gave me the idea how to simulate exactly what I have now with a
bead.
I don't know if it will work but I will give a shoot.
Thank you.

Maria Jose Esteve <mj...@iest.com> escreveu no dia quarta, 8/06/2022
à(s) 21:37:

> Surely this implementation could be greatly improved. I remember that the
> first thing we tried was to follow Carlos' advice and pass the properties,
> from the list to the itemRenderer, through IItemRendererInitializer but we
> didn't succeed. This solution was the one we were able to implement and I
> haven't really revisited it.
>
> 1.- Interface IPropertiesBead
> package
> {
>         import org.apache.royale.core.IBead;
>
>         public interface IPropertiesBead extends IBead
>         {
>                 function get propertiesIt():Object;
>                 function set propertiesIt(value:Object):void;
>         }
> }
>
> 2.- Bead ListItemRendererPropertiesBead
> package
> {
>         import org.apache.royale.core.Bead;
>         import org.apache.royale.events.Event;
>         import org.apache.royale.core.IDataProviderModel;
>
>         public class ListItemRendererPropertiesBead extends Bead
> implements IPropertiesBead
>         {
>                 public function ListItemRendererPropertiesBead()        {}
>
>                 private var _propertiesIt:Object;
>                 public function get propertiesIt():Object {
>                         return _propertiesIt;
>                         }
>                         public function set
> propertiesIt(value:Object):void {
>                                 _propertiesIt = value;
>                         (_strand.getBeadByType(IDataProviderModel) as
> IDataProviderModel).dispatchEvent(new Event('dataProviderChanged'));
>                         }
>         }
> }
>
> 3.- Custom it ListItemRendererProperties:
> package
> {
>         import org.apache.royale.jewel.itemRenderers.ListItemRenderer;
>         import com.iest.winplusweb.beads.IPropertiesBead
>
>         public class ListItemRendererProperties extends ListItemRenderer
>         {
>                 public function ListItemRendererProperties()
>                 {
>                         super();
>                 }
>                 private var _properties:Object;
>                         public function get properties():Object
>                         {
>                                 return _properties;
>                         }
>                         public function set properties(value:Object):void
>                         {
>                                 _properties = value;
>                         }
>
>                 protected var _propertiesItBead:IPropertiesBead;
>
>                 public function get propertiesItBead():IPropertiesBead {
>                         if(!_propertiesItBead) {
>                                 _propertiesItBead =
> itemRendererOwnerView.host.getBeadByType(IPropertiesBead) as
> IPropertiesBead;
>                         }
>                         return _propertiesItBead;
>                 }
>
>                  override public function set data(value:Object):void{
>                         if(propertiesItBead &&
> propertiesItBead.propertiesIt)
>                                 properties = propertiesItBead.propertiesIt;
>                          super.data = value;
>                  }
>
>         }
> }
>
> 4.- Usage: (One Example... ItemRenderer with a checkBox that is passed
> whether it is editable or not from the main container of the List)
>
> 4.1.- ItemRenderer:
> <?xml version="1.0" encoding="utf-8"?>
> <wp:ListItemRendererProperties xmlns:fx="http://ns.adobe.com/mxml/2009"
>     xmlns:j="library://ns.apache.org/royale/jewel"
>     xmlns:js="library://ns.apache.org/royale/basic"
>     xmlns:wp="library://ns.xxx.com/xxx"
>     className="horItem">
>
>     <fx:Script>
>         <![CDATA[
>             import com.xxx.xxx.security.dto.vo.CTypeTermAccesoNet;
>             import com.xxx.xxx.events.SharedEvent;
>             import org.apache.royale.events.Event;
>
>             [Bindable]
>             private var reg:CTypeTermAccesoNet;
>             [Bindable]
>             private var readOnly:Boolean = true;
>
>             override public function set data(value:Object):void
>             {
>                 super.data = value;
>
>                 if(!data){
>                     reg = new CTypeTermAccesoNet;
>                 }else{
>                     reg = value as CTypeTermAccesoNet;
>                 }
>
>                 if(properties)
>                     readOnly = properties["readOnly"] == null ? true :
> Boolean(properties["readOnly"]);
>             }
>
>             private function onEdit(event:Event):void
>             {
>                 reg.selected = chSel.selected;
>                 itemUpdate();
>             }
>
>             private function onRevert(event:Event):void
>             {
>                 reg.selected = reg.selectedold;
>                 itemUpdate();
>             }
>
>             private function itemUpdate():void
>             {
>                 var evt:SharedEvent = new SharedEvent("changeItemEvent");
>                 evt.index = this.index;
>                 evt.itemSend = reg;
>                 dispatchEvent(evt);
>             }
>
>                 ]]>
>     </fx:Script>
>
>     <wp:beads>
>         <js:ItemRendererDataBinding />
>         <j:HorizontalLayout itemsVerticalAlign="itemsCenter"
> itemsHorizontalAlign="itemsCenter" />
>     </wp:beads>
>
>     <j:HGroup itemsHorizontalAlign="itemsLeft"
> itemsVerticalAlign="itemsCenter" percentWidth="100">
>         <j:CheckBox localId="chSel" selected="{reg.selected}"
> click="onEdit(event)">
>             <j:beads>
>                 <j:ReadOnly localId="bDis" readOnly="{readOnly}"/>
>             </j:beads>
>         </j:CheckBox>
>         <j:Label localId="label" percentWidth="100">
>             <j:beads>
>                 <j:SizeControl size="small"/>
>                 <j:TruncateText/>
>             </j:beads>
>             <j:html><![CDATA[<strong>{reg.id} </strong> -
> {reg.des}]]></j:html>
>         </j:Label>
>         <wp:IconBtnUndoItemRenderer localId="btrevert"
> visible="{reg.selectedold != chSel.selected?true:false}"
> click="onRevert(event)"/>
>     </j:HGroup>
>
> </wp:ListItemRendererProperties>
>
> 4.2.- List
>
>         <wp:ListJwExt localId="dgTerms" percentWidth="100"
> percentHeight="100" minHeight="100" labelField="des"
>         itemRenderer="com.xxx.xxx.itemRenderers.TermAccesoItemRenderer"
>         dataProvider="{dataProvider}">
>             <wp:beads>
>                 <wp:ListItemRendererPropertiesBead
> propertiesIt="{propItList}"/>
>             </wp:beads>
>         </wp:ListJwExt>
>
>
> Hiedra
>
> -----Mensaje original-----
> De: Hugo Ferreira <hf...@gmail.com>
> Enviado el: miércoles, 8 de junio de 2022 20:48
> Para: Apache Royale Development <de...@royale.apache.org>
> Asunto: Re: Proposal for labelField with expression support
>
> I didn't thought that way :)
> There is always more than a way to do the things :) Yes, you can show me
> and can be a possibility to my monkey patch of the getLabel class.
>
> Maria Jose Esteve <mj...@iest.com> escreveu no dia quarta, 8/06/2022
> à(s) 19:27:
>
> > Hugo, how would you like to pass to the itemRenderer the function or
> > the Array of fields, through a bead?
> > I can expose the implementation that I use when I need to pass to an
> > itemRenderer specific properties (in your case it would be an Array of
> > fields to compose the text)
> >
> > I mainly use two new components:
> > 1- Creation of a component "ListItemRendererProperties" that extends
> > "ListItemRenderer" and to which I have added a new property "properties"
> > (Object, key-value pairs).
> > 2- Creation of a new bead "ListItemRendererPropertiesBead" that
> > oversees transferring the object "properties" to each itemRenderer.
> >
> > If you like the idea I can extend it and we can implement your needs.
> >
> > Let me know if you like the idea.
> >
> > Hiedra
> >
> > -----Mensaje original-----
> > De: Hugo Ferreira <hf...@gmail.com> Enviado el: miércoles, 8 de
> > junio de 2022 0:38
> > Para: Apache Royale Development <de...@royale.apache.org>
> > Asunto: Re: Proposal for labelField with expression support
> >
> > @Harbs, that would be nice for this particular use case. Until then, I
> > will use this monkey patch. May not be the best solution but works for
> me.
> >
> > @Eduard, it's for mxml.
> >
> > @Alex, I thought that. I have many, many beads on my side that
> > personalize the behaviours just as I want with things very specific
> > that should not be put on the SDK. Beads are a perfect and elegant
> > solution to modify the SDK behaviour but I don't know how to use them on
> this scenario.
> >
> > For now I will use this monkey patch until we have a better solution
> > to replace.
> >
> > Alex Harui <ah...@adobe.com.invalid> escreveu no dia terça, 7/06/2022
> > à(s)
> > 23:21:
> >
> > > You could probably come up with an app-level bead that overwrites a
> > > utility function.
> > >
> > > But it might be more interesting to explore providing an example of
> > > using
> > > ES5 Template Literals
> > > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Te
> > > mp
> > > late_literals
> > > in an item renderer.
> > >
> > > getLabelFromData is called by a dataToString, so dataToString could
> > > be overridden to return such a string literal.  IMO, that would
> > > perform better since the browser JS engine would do the string
> substitution.
> > > Yes, it means custom item renderers, instead of interpreting
> > > labelField, but it would show that Royale can use new cool ES5
> > > optimizations.  Might require a compiler change, not sure.
> > >
> > > And it wouldn't have backward compatibility implications or
> > > monkey-patch the SDK.
> > >
> > > Just a thought,
> > > -Alex
> > >
> > > On 6/7/22, 2:56 PM, "Harbs" <ha...@gmail.com> wrote:
> > >
> > >     EXTERNAL: Use caution when clicking on links or opening
> attachments.
> > >
> > >
> > >     I’d love to come up a pattern for hot-swapping utility
> > > functions, but we don’t have one yet...
> > >
> > >     > On Jun 8, 2022, at 12:38 AM, Hugo Ferreira
> > > <hf...@gmail.com>
> > > wrote:
> > >     >
> > >     > Yes, I know that.
> > >     > But seems a bazooka for a simple thing.
> > >
> > >
> > >
> >
>

RE: Proposal for labelField with expression support

Posted by Maria Jose Esteve <mj...@iest.com>.
Surely this implementation could be greatly improved. I remember that the first thing we tried was to follow Carlos' advice and pass the properties, from the list to the itemRenderer, through IItemRendererInitializer but we didn't succeed. This solution was the one we were able to implement and I haven't really revisited it.

1.- Interface IPropertiesBead
package 
{	
	import org.apache.royale.core.IBead;

	public interface IPropertiesBead extends IBead
	{		
		function get propertiesIt():Object;
		function set propertiesIt(value:Object):void;
	}
}

2.- Bead ListItemRendererPropertiesBead
package 
{
	import org.apache.royale.core.Bead;
	import org.apache.royale.events.Event;
	import org.apache.royale.core.IDataProviderModel;
	
	public class ListItemRendererPropertiesBead extends Bead implements IPropertiesBead
	{
		public function ListItemRendererPropertiesBead()	{}

		private var _propertiesIt:Object;
		public function get propertiesIt():Object {
			return _propertiesIt;
        		}
	        	public function set propertiesIt(value:Object):void {
            			_propertiesIt = value;
			(_strand.getBeadByType(IDataProviderModel) as IDataProviderModel).dispatchEvent(new Event('dataProviderChanged'));
        		}
	}
}

3.- Custom it ListItemRendererProperties:
package 
{
	import org.apache.royale.jewel.itemRenderers.ListItemRenderer;
	import com.iest.winplusweb.beads.IPropertiesBead

	public class ListItemRendererProperties extends ListItemRenderer
	{
		public function ListItemRendererProperties()
		{
			super();
		}
		private var _properties:Object;
        		public function get properties():Object
        		{
            			return _properties;
        		}
        		public function set properties(value:Object):void
        		{
            			_properties = value;
        		}
		
		protected var _propertiesItBead:IPropertiesBead;		
		public function get propertiesItBead():IPropertiesBead {
			if(!_propertiesItBead) {
				_propertiesItBead = itemRendererOwnerView.host.getBeadByType(IPropertiesBead) as IPropertiesBead;
			}
			return _propertiesItBead;
		}

		 override public function set data(value:Object):void{
			if(propertiesItBead && propertiesItBead.propertiesIt)
				properties = propertiesItBead.propertiesIt;
			 super.data = value;
		 }
		
	}
}

4.- Usage: (One Example... ItemRenderer with a checkBox that is passed whether it is editable or not from the main container of the List)

4.1.- ItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<wp:ListItemRendererProperties xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:j="library://ns.apache.org/royale/jewel"
    xmlns:js="library://ns.apache.org/royale/basic"
    xmlns:wp="library://ns.xxx.com/xxx"
    className="horItem">
    
    <fx:Script>
        <![CDATA[
            import com.xxx.xxx.security.dto.vo.CTypeTermAccesoNet;
            import com.xxx.xxx.events.SharedEvent;
            import org.apache.royale.events.Event;
            
            [Bindable]
            private var reg:CTypeTermAccesoNet;
            [Bindable]
            private var readOnly:Boolean = true;

            override public function set data(value:Object):void
            {
                super.data = value;
                
                if(!data){
                    reg = new CTypeTermAccesoNet;
                }else{
                    reg = value as CTypeTermAccesoNet;
                }

                if(properties)
                    readOnly = properties["readOnly"] == null ? true : Boolean(properties["readOnly"]);
            }

            private function onEdit(event:Event):void
            {
                reg.selected = chSel.selected;
                itemUpdate();
            }

            private function onRevert(event:Event):void
            {
                reg.selected = reg.selectedold;
                itemUpdate();
            }

            private function itemUpdate():void
            {
                var evt:SharedEvent = new SharedEvent("changeItemEvent");
                evt.index = this.index;
                evt.itemSend = reg;
                dispatchEvent(evt);
            }
            
		]]>
    </fx:Script>
    
    <wp:beads>
        <js:ItemRendererDataBinding />
        <j:HorizontalLayout itemsVerticalAlign="itemsCenter" itemsHorizontalAlign="itemsCenter" />
    </wp:beads>

    <j:HGroup itemsHorizontalAlign="itemsLeft" itemsVerticalAlign="itemsCenter" percentWidth="100">
        <j:CheckBox localId="chSel" selected="{reg.selected}" click="onEdit(event)">
            <j:beads>
                <j:ReadOnly localId="bDis" readOnly="{readOnly}"/>
            </j:beads>
        </j:CheckBox>
        <j:Label localId="label" percentWidth="100">
            <j:beads>
                <j:SizeControl size="small"/>
                <j:TruncateText/>
            </j:beads>
            <j:html><![CDATA[<strong>{reg.id} </strong> - {reg.des}]]></j:html>
        </j:Label>
        <wp:IconBtnUndoItemRenderer localId="btrevert" visible="{reg.selectedold != chSel.selected?true:false}" click="onRevert(event)"/>
    </j:HGroup>

</wp:ListItemRendererProperties>

4.2.- List

        <wp:ListJwExt localId="dgTerms" percentWidth="100" percentHeight="100" minHeight="100" labelField="des"
        itemRenderer="com.xxx.xxx.itemRenderers.TermAccesoItemRenderer" 
        dataProvider="{dataProvider}">
            <wp:beads>
                <wp:ListItemRendererPropertiesBead propertiesIt="{propItList}"/>
            </wp:beads>
        </wp:ListJwExt>


Hiedra

-----Mensaje original-----
De: Hugo Ferreira <hf...@gmail.com> 
Enviado el: miércoles, 8 de junio de 2022 20:48
Para: Apache Royale Development <de...@royale.apache.org>
Asunto: Re: Proposal for labelField with expression support

I didn't thought that way :)
There is always more than a way to do the things :) Yes, you can show me and can be a possibility to my monkey patch of the getLabel class.

Maria Jose Esteve <mj...@iest.com> escreveu no dia quarta, 8/06/2022
à(s) 19:27:

> Hugo, how would you like to pass to the itemRenderer the function or 
> the Array of fields, through a bead?
> I can expose the implementation that I use when I need to pass to an 
> itemRenderer specific properties (in your case it would be an Array of 
> fields to compose the text)
>
> I mainly use two new components:
> 1- Creation of a component "ListItemRendererProperties" that extends 
> "ListItemRenderer" and to which I have added a new property "properties"
> (Object, key-value pairs).
> 2- Creation of a new bead "ListItemRendererPropertiesBead" that 
> oversees transferring the object "properties" to each itemRenderer.
>
> If you like the idea I can extend it and we can implement your needs.
>
> Let me know if you like the idea.
>
> Hiedra
>
> -----Mensaje original-----
> De: Hugo Ferreira <hf...@gmail.com> Enviado el: miércoles, 8 de 
> junio de 2022 0:38
> Para: Apache Royale Development <de...@royale.apache.org>
> Asunto: Re: Proposal for labelField with expression support
>
> @Harbs, that would be nice for this particular use case. Until then, I 
> will use this monkey patch. May not be the best solution but works for me.
>
> @Eduard, it's for mxml.
>
> @Alex, I thought that. I have many, many beads on my side that 
> personalize the behaviours just as I want with things very specific 
> that should not be put on the SDK. Beads are a perfect and elegant 
> solution to modify the SDK behaviour but I don't know how to use them on this scenario.
>
> For now I will use this monkey patch until we have a better solution 
> to replace.
>
> Alex Harui <ah...@adobe.com.invalid> escreveu no dia terça, 7/06/2022
> à(s)
> 23:21:
>
> > You could probably come up with an app-level bead that overwrites a 
> > utility function.
> >
> > But it might be more interesting to explore providing an example of 
> > using
> > ES5 Template Literals
> > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Te
> > mp
> > late_literals
> > in an item renderer.
> >
> > getLabelFromData is called by a dataToString, so dataToString could 
> > be overridden to return such a string literal.  IMO, that would 
> > perform better since the browser JS engine would do the string substitution.
> > Yes, it means custom item renderers, instead of interpreting 
> > labelField, but it would show that Royale can use new cool ES5 
> > optimizations.  Might require a compiler change, not sure.
> >
> > And it wouldn't have backward compatibility implications or 
> > monkey-patch the SDK.
> >
> > Just a thought,
> > -Alex
> >
> > On 6/7/22, 2:56 PM, "Harbs" <ha...@gmail.com> wrote:
> >
> >     EXTERNAL: Use caution when clicking on links or opening attachments.
> >
> >
> >     I’d love to come up a pattern for hot-swapping utility 
> > functions, but we don’t have one yet...
> >
> >     > On Jun 8, 2022, at 12:38 AM, Hugo Ferreira 
> > <hf...@gmail.com>
> > wrote:
> >     >
> >     > Yes, I know that.
> >     > But seems a bazooka for a simple thing.
> >
> >
> >
>

Re: Proposal for labelField with expression support

Posted by Hugo Ferreira <hf...@gmail.com>.
I didn't thought that way :)
There is always more than a way to do the things :)
Yes, you can show me and can be a possibility to my monkey patch of the
getLabel class.

Maria Jose Esteve <mj...@iest.com> escreveu no dia quarta, 8/06/2022
à(s) 19:27:

> Hugo, how would you like to pass to the itemRenderer the function or the
> Array of fields, through a bead?
> I can expose the implementation that I use when I need to pass to an
> itemRenderer specific properties (in your case it would be an Array of
> fields to compose the text)
>
> I mainly use two new components:
> 1- Creation of a component "ListItemRendererProperties" that extends
> "ListItemRenderer" and to which I have added a new property "properties"
> (Object, key-value pairs).
> 2- Creation of a new bead "ListItemRendererPropertiesBead" that oversees
> transferring the object "properties" to each itemRenderer.
>
> If you like the idea I can extend it and we can implement your needs.
>
> Let me know if you like the idea.
>
> Hiedra
>
> -----Mensaje original-----
> De: Hugo Ferreira <hf...@gmail.com>
> Enviado el: miércoles, 8 de junio de 2022 0:38
> Para: Apache Royale Development <de...@royale.apache.org>
> Asunto: Re: Proposal for labelField with expression support
>
> @Harbs, that would be nice for this particular use case. Until then, I
> will use this monkey patch. May not be the best solution but works for me.
>
> @Eduard, it's for mxml.
>
> @Alex, I thought that. I have many, many beads on my side that personalize
> the behaviours just as I want with things very specific that should not be
> put on the SDK. Beads are a perfect and elegant solution to modify the SDK
> behaviour but I don't know how to use them on this scenario.
>
> For now I will use this monkey patch until we have a better solution to
> replace.
>
> Alex Harui <ah...@adobe.com.invalid> escreveu no dia terça, 7/06/2022
> à(s)
> 23:21:
>
> > You could probably come up with an app-level bead that overwrites a
> > utility function.
> >
> > But it might be more interesting to explore providing an example of
> > using
> > ES5 Template Literals
> > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Temp
> > late_literals
> > in an item renderer.
> >
> > getLabelFromData is called by a dataToString, so dataToString could be
> > overridden to return such a string literal.  IMO, that would perform
> > better since the browser JS engine would do the string substitution.
> > Yes, it means custom item renderers, instead of interpreting
> > labelField, but it would show that Royale can use new cool ES5
> > optimizations.  Might require a compiler change, not sure.
> >
> > And it wouldn't have backward compatibility implications or
> > monkey-patch the SDK.
> >
> > Just a thought,
> > -Alex
> >
> > On 6/7/22, 2:56 PM, "Harbs" <ha...@gmail.com> wrote:
> >
> >     EXTERNAL: Use caution when clicking on links or opening attachments.
> >
> >
> >     I’d love to come up a pattern for hot-swapping utility functions,
> > but we don’t have one yet...
> >
> >     > On Jun 8, 2022, at 12:38 AM, Hugo Ferreira
> > <hf...@gmail.com>
> > wrote:
> >     >
> >     > Yes, I know that.
> >     > But seems a bazooka for a simple thing.
> >
> >
> >
>

RE: Proposal for labelField with expression support

Posted by Maria Jose Esteve <mj...@iest.com>.
Hugo, how would you like to pass to the itemRenderer the function or the Array of fields, through a bead?
I can expose the implementation that I use when I need to pass to an itemRenderer specific properties (in your case it would be an Array of fields to compose the text)

I mainly use two new components:
1- Creation of a component "ListItemRendererProperties" that extends "ListItemRenderer" and to which I have added a new property "properties" (Object, key-value pairs).
2- Creation of a new bead "ListItemRendererPropertiesBead" that oversees transferring the object "properties" to each itemRenderer.

If you like the idea I can extend it and we can implement your needs.

Let me know if you like the idea.

Hiedra

-----Mensaje original-----
De: Hugo Ferreira <hf...@gmail.com> 
Enviado el: miércoles, 8 de junio de 2022 0:38
Para: Apache Royale Development <de...@royale.apache.org>
Asunto: Re: Proposal for labelField with expression support

@Harbs, that would be nice for this particular use case. Until then, I will use this monkey patch. May not be the best solution but works for me.

@Eduard, it's for mxml.

@Alex, I thought that. I have many, many beads on my side that personalize the behaviours just as I want with things very specific that should not be put on the SDK. Beads are a perfect and elegant solution to modify the SDK behaviour but I don't know how to use them on this scenario.

For now I will use this monkey patch until we have a better solution to replace.

Alex Harui <ah...@adobe.com.invalid> escreveu no dia terça, 7/06/2022 à(s)
23:21:

> You could probably come up with an app-level bead that overwrites a 
> utility function.
>
> But it might be more interesting to explore providing an example of 
> using
> ES5 Template Literals
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Temp
> late_literals
> in an item renderer.
>
> getLabelFromData is called by a dataToString, so dataToString could be 
> overridden to return such a string literal.  IMO, that would perform 
> better since the browser JS engine would do the string substitution.  
> Yes, it means custom item renderers, instead of interpreting 
> labelField, but it would show that Royale can use new cool ES5 
> optimizations.  Might require a compiler change, not sure.
>
> And it wouldn't have backward compatibility implications or 
> monkey-patch the SDK.
>
> Just a thought,
> -Alex
>
> On 6/7/22, 2:56 PM, "Harbs" <ha...@gmail.com> wrote:
>
>     EXTERNAL: Use caution when clicking on links or opening attachments.
>
>
>     I’d love to come up a pattern for hot-swapping utility functions, 
> but we don’t have one yet...
>
>     > On Jun 8, 2022, at 12:38 AM, Hugo Ferreira 
> <hf...@gmail.com>
> wrote:
>     >
>     > Yes, I know that.
>     > But seems a bazooka for a simple thing.
>
>
>

Re: Proposal for labelField with expression support

Posted by Hugo Ferreira <hf...@gmail.com>.
@Harbs, that would be nice for this particular use case. Until then, I will
use this monkey patch. May not be the best solution but works for me.

@Eduard, it's for mxml.

@Alex, I thought that. I have many, many beads on my side that personalize
the behaviours just as I want with things very specific that should not be
put on the SDK. Beads are a perfect and elegant solution to modify the SDK
behaviour but I don't know how to use them on this scenario.

For now I will use this monkey patch until we have a better solution to
replace.

Alex Harui <ah...@adobe.com.invalid> escreveu no dia terça, 7/06/2022 à(s)
23:21:

> You could probably come up with an app-level bead that overwrites a
> utility function.
>
> But it might be more interesting to explore providing an example of using
> ES5 Template Literals
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
> in an item renderer.
>
> getLabelFromData is called by a dataToString, so dataToString could be
> overridden to return such a string literal.  IMO, that would perform better
> since the browser JS engine would do the string substitution.  Yes, it
> means custom item renderers, instead of interpreting labelField, but it
> would show that Royale can use new cool ES5 optimizations.  Might require a
> compiler change, not sure.
>
> And it wouldn't have backward compatibility implications or monkey-patch
> the SDK.
>
> Just a thought,
> -Alex
>
> On 6/7/22, 2:56 PM, "Harbs" <ha...@gmail.com> wrote:
>
>     EXTERNAL: Use caution when clicking on links or opening attachments.
>
>
>     I’d love to come up a pattern for hot-swapping utility functions, but
> we don’t have one yet...
>
>     > On Jun 8, 2022, at 12:38 AM, Hugo Ferreira <hf...@gmail.com>
> wrote:
>     >
>     > Yes, I know that.
>     > But seems a bazooka for a simple thing.
>
>
>

Re: Proposal for labelField with expression support

Posted by Alex Harui <ah...@adobe.com.INVALID>.
You could probably come up with an app-level bead that overwrites a utility function.

But it might be more interesting to explore providing an example of using ES5 Template Literals https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals in an item renderer.

getLabelFromData is called by a dataToString, so dataToString could be overridden to return such a string literal.  IMO, that would perform better since the browser JS engine would do the string substitution.  Yes, it means custom item renderers, instead of interpreting labelField, but it would show that Royale can use new cool ES5 optimizations.  Might require a compiler change, not sure.

And it wouldn't have backward compatibility implications or monkey-patch the SDK.

Just a thought,
-Alex

On 6/7/22, 2:56 PM, "Harbs" <ha...@gmail.com> wrote:

    EXTERNAL: Use caution when clicking on links or opening attachments.


    I’d love to come up a pattern for hot-swapping utility functions, but we don’t have one yet...

    > On Jun 8, 2022, at 12:38 AM, Hugo Ferreira <hf...@gmail.com> wrote:
    >
    > Yes, I know that.
    > But seems a bazooka for a simple thing.



Re: Proposal for labelField with expression support

Posted by Harbs <ha...@gmail.com>.
I’d love to come up a pattern for hot-swapping utility functions, but we don’t have one yet...

> On Jun 8, 2022, at 12:38 AM, Hugo Ferreira <hf...@gmail.com> wrote:
> 
> Yes, I know that.
> But seems a bazooka for a simple thing.


Re: Proposal for labelField with expression support

Posted by Hugo Ferreira <hf...@gmail.com>.
Yes, I know that.
But seems a bazooka for a simple thing.
For now I have a copy of the file on my project to override the SDK with
the behaviour implemented.

Harbs <ha...@gmail.com> escreveu no dia terça, 7/06/2022 à(s) 22:35:

> I’d just create my own ItemRenderer with the custom label behavior.
>
> I have MANY custom renderers in my apps.
>
> > On Jun 8, 2022, at 12:16 AM, Hugo Ferreira <hf...@gmail.com>
> wrote:
> >
> > I use itemRenders for more visual complex things (images, text with bold,
> > etc ...)
> > On this case I have a generic itemRender (visual aspect) and what's
> > different it's the content.
> > Doing an itemRender for each ComboBox seems to much work and a simple
> > formula it's something in between for a less complex code structure.
> >
> > But I understand what you mean, that's why I asked in the first place
> > before commit.
> >
> > So, what's the best option to have this implemented only on my side (if
> > there is this option) ?
> > I would like to have this behaviour without put on the SDK and without
> > using itemRenderers.
> > For another word, how to have a copy of the custom getLabelFromData and
> use
> > this instead of the SDK ?
> >
> >
> > Harbs <ha...@gmail.com> escreveu no dia terça, 7/06/2022 à(s)
> 22:04:
> >
> >> Hard coding it into a function which is widely used by ItemRenderers
> does
> >> not seem like a good idea or very PAYG.
> >>
> >> Id suggest creating ItemRenderers which have this behavior.
> >>
> >> If there’s some way to inject the behavior into existing functions that
> >> would be fine too, but I can’t think off hand of a good way of doing
> that.
> >>
> >>> On Jun 7, 2022, at 11:48 PM, Hugo Ferreira <hf...@gmail.com>
> >> wrote:
> >>>
> >>> Method getLabelFromData from getLabelFromData.as
> >>>
> >>> I just added a new if block that seek for "[" and thread the keys.
> >>> If it's OK, I can commit, otherwise I ask what's the best alternative
> >>> solution to achive the same result.
> >>>
> >>>   public function getLabelFromData(obj:Object,data:Object):String
> >>>   {
> >>>       // slightly more code, but we bail early if it's a string which
> is
> >>> often
> >>>       if (data is String) return "" + data;
> >>>       if(!data) return "";
> >>>       if(data is ILabeledData) return (data as ILabeledData).label;
> >>>
> >>>       if (obj is IHasLabelField &&
> >>>           (obj as IHasLabelField).labelField &&
> >>>           (obj as IHasLabelField).labelField.indexOf("[") > -1)
> >>>       {
> >>>           var result:String = (obj as IHasLabelField).labelField;
> >>>           for each (var item:String in result.split("["))
> >>>           {
> >>>               if (item.indexOf("]") > -1)
> >>>               {
> >>>                   var field:String = item.split("]")[0];
> >>>                   result = result.replace("[" + field + "]",
> >> data[field]);
> >>>               }
> >>>           }
> >>>           return result;
> >>>       }
> >>>
> >>>       if (obj is IHasLabelField &&
> >>>           (obj as IHasLabelField).labelField &&
> >>>           data[(obj as IHasLabelField).labelField] != null)
> >>>       {
> >>>           return "" + data[(obj as IHasLabelField).labelField];
> >>>       }
> >>>
> >>>       if (obj is IHasDataField &&
> >>>           (obj as IHasDataField).dataField &&
> >>>           data[(obj as IHasDataField).dataField] != null)
> >>>       {
> >>>           return "" + data[(obj as IHasDataField).dataField];
> >>>       }
> >>>
> >>>       var label:String = data["label"];
> >>>       if(label != null){
> >>>           return label;
> >>>       }
> >>>       return "" + data;
> >>>
> >>>   }
> >>>
> >>> Maria Jose Esteve <mj...@iest.com> escreveu no dia terça, 7/06/2022
> >> à(s)
> >>> 21:44:
> >>>
> >>>> Hugo, could it be seen? Maybe a branch or a PR?
> >>>>
> >>>> Hiedra
> >>>>
> >>>> -----Mensaje original-----
> >>>> De: Hugo Ferreira <hf...@gmail.com>
> >>>> Enviado el: martes, 7 de junio de 2022 21:58
> >>>> Para: Apache Royale Development <de...@royale.apache.org>
> >>>> Asunto: Proposal for labelField with expression support
> >>>>
> >>>> Hi,
> >>>>
> >>>> In Flex "world" one can use labelField and labelFunction.
> >>>> Here in Royale we have only labelField (at least I didn't see so far
> >>>> support for labelFunction), however I'm not a big fan of labelFunction
> >>>> anyway.
> >>>>
> >>>> I always wanted support for something in between of labelField and
> >>>> labelFunction (labelFunction with multiple fields and fixed strings)
> >> and I
> >>>> implement it on my side.
> >>>>
> >>>> Ex:
> >>>> model:
> >>>> public class User
> >>>> {
> >>>> public var Code:String;
> >>>> public var Name:String;
> >>>> }
> >>>>
> >>>> With this model, one can use Code (user code) or Name but not the
> >> combined
> >>>> fields.
> >>>>
> >>>> With a little adition I can now do something like this:
> >> labelField="[Code]
> >>>> - [Name]" and at runtime every field delimited by [] it's replaced for
> >> his
> >>>> value, allowing multiple fields and complex expressions.
> >>>>
> >>>> Can I commit this or there is a reason to not do so ?
> >>>>
> >>>> Thank you,
> >>>> Hugo.
> >>>>
> >>
> >>
>
>

Re: Proposal for labelField with expression support

Posted by Harbs <ha...@gmail.com>.
I’d just create my own ItemRenderer with the custom label behavior.

I have MANY custom renderers in my apps.

> On Jun 8, 2022, at 12:16 AM, Hugo Ferreira <hf...@gmail.com> wrote:
> 
> I use itemRenders for more visual complex things (images, text with bold,
> etc ...)
> On this case I have a generic itemRender (visual aspect) and what's
> different it's the content.
> Doing an itemRender for each ComboBox seems to much work and a simple
> formula it's something in between for a less complex code structure.
> 
> But I understand what you mean, that's why I asked in the first place
> before commit.
> 
> So, what's the best option to have this implemented only on my side (if
> there is this option) ?
> I would like to have this behaviour without put on the SDK and without
> using itemRenderers.
> For another word, how to have a copy of the custom getLabelFromData and use
> this instead of the SDK ?
> 
> 
> Harbs <ha...@gmail.com> escreveu no dia terça, 7/06/2022 à(s) 22:04:
> 
>> Hard coding it into a function which is widely used by ItemRenderers does
>> not seem like a good idea or very PAYG.
>> 
>> Id suggest creating ItemRenderers which have this behavior.
>> 
>> If there’s some way to inject the behavior into existing functions that
>> would be fine too, but I can’t think off hand of a good way of doing that.
>> 
>>> On Jun 7, 2022, at 11:48 PM, Hugo Ferreira <hf...@gmail.com>
>> wrote:
>>> 
>>> Method getLabelFromData from getLabelFromData.as
>>> 
>>> I just added a new if block that seek for "[" and thread the keys.
>>> If it's OK, I can commit, otherwise I ask what's the best alternative
>>> solution to achive the same result.
>>> 
>>>   public function getLabelFromData(obj:Object,data:Object):String
>>>   {
>>>       // slightly more code, but we bail early if it's a string which is
>>> often
>>>       if (data is String) return "" + data;
>>>       if(!data) return "";
>>>       if(data is ILabeledData) return (data as ILabeledData).label;
>>> 
>>>       if (obj is IHasLabelField &&
>>>           (obj as IHasLabelField).labelField &&
>>>           (obj as IHasLabelField).labelField.indexOf("[") > -1)
>>>       {
>>>           var result:String = (obj as IHasLabelField).labelField;
>>>           for each (var item:String in result.split("["))
>>>           {
>>>               if (item.indexOf("]") > -1)
>>>               {
>>>                   var field:String = item.split("]")[0];
>>>                   result = result.replace("[" + field + "]",
>> data[field]);
>>>               }
>>>           }
>>>           return result;
>>>       }
>>> 
>>>       if (obj is IHasLabelField &&
>>>           (obj as IHasLabelField).labelField &&
>>>           data[(obj as IHasLabelField).labelField] != null)
>>>       {
>>>           return "" + data[(obj as IHasLabelField).labelField];
>>>       }
>>> 
>>>       if (obj is IHasDataField &&
>>>           (obj as IHasDataField).dataField &&
>>>           data[(obj as IHasDataField).dataField] != null)
>>>       {
>>>           return "" + data[(obj as IHasDataField).dataField];
>>>       }
>>> 
>>>       var label:String = data["label"];
>>>       if(label != null){
>>>           return label;
>>>       }
>>>       return "" + data;
>>> 
>>>   }
>>> 
>>> Maria Jose Esteve <mj...@iest.com> escreveu no dia terça, 7/06/2022
>> à(s)
>>> 21:44:
>>> 
>>>> Hugo, could it be seen? Maybe a branch or a PR?
>>>> 
>>>> Hiedra
>>>> 
>>>> -----Mensaje original-----
>>>> De: Hugo Ferreira <hf...@gmail.com>
>>>> Enviado el: martes, 7 de junio de 2022 21:58
>>>> Para: Apache Royale Development <de...@royale.apache.org>
>>>> Asunto: Proposal for labelField with expression support
>>>> 
>>>> Hi,
>>>> 
>>>> In Flex "world" one can use labelField and labelFunction.
>>>> Here in Royale we have only labelField (at least I didn't see so far
>>>> support for labelFunction), however I'm not a big fan of labelFunction
>>>> anyway.
>>>> 
>>>> I always wanted support for something in between of labelField and
>>>> labelFunction (labelFunction with multiple fields and fixed strings)
>> and I
>>>> implement it on my side.
>>>> 
>>>> Ex:
>>>> model:
>>>> public class User
>>>> {
>>>> public var Code:String;
>>>> public var Name:String;
>>>> }
>>>> 
>>>> With this model, one can use Code (user code) or Name but not the
>> combined
>>>> fields.
>>>> 
>>>> With a little adition I can now do something like this:
>> labelField="[Code]
>>>> - [Name]" and at runtime every field delimited by [] it's replaced for
>> his
>>>> value, allowing multiple fields and complex expressions.
>>>> 
>>>> Can I commit this or there is a reason to not do so ?
>>>> 
>>>> Thank you,
>>>> Hugo.
>>>> 
>> 
>> 


Re: Proposal for labelField with expression support

Posted by Hugo Ferreira <hf...@gmail.com>.
I use itemRenders for more visual complex things (images, text with bold,
etc ...)
On this case I have a generic itemRender (visual aspect) and what's
different it's the content.
Doing an itemRender for each ComboBox seems to much work and a simple
formula it's something in between for a less complex code structure.

But I understand what you mean, that's why I asked in the first place
before commit.

So, what's the best option to have this implemented only on my side (if
there is this option) ?
I would like to have this behaviour without put on the SDK and without
using itemRenderers.
For another word, how to have a copy of the custom getLabelFromData and use
this instead of the SDK ?


Harbs <ha...@gmail.com> escreveu no dia terça, 7/06/2022 à(s) 22:04:

> Hard coding it into a function which is widely used by ItemRenderers does
> not seem like a good idea or very PAYG.
>
> Id suggest creating ItemRenderers which have this behavior.
>
> If there’s some way to inject the behavior into existing functions that
> would be fine too, but I can’t think off hand of a good way of doing that.
>
> > On Jun 7, 2022, at 11:48 PM, Hugo Ferreira <hf...@gmail.com>
> wrote:
> >
> > Method getLabelFromData from getLabelFromData.as
> >
> > I just added a new if block that seek for "[" and thread the keys.
> > If it's OK, I can commit, otherwise I ask what's the best alternative
> > solution to achive the same result.
> >
> >    public function getLabelFromData(obj:Object,data:Object):String
> >    {
> >        // slightly more code, but we bail early if it's a string which is
> > often
> >        if (data is String) return "" + data;
> >        if(!data) return "";
> >        if(data is ILabeledData) return (data as ILabeledData).label;
> >
> >        if (obj is IHasLabelField &&
> >            (obj as IHasLabelField).labelField &&
> >            (obj as IHasLabelField).labelField.indexOf("[") > -1)
> >        {
> >            var result:String = (obj as IHasLabelField).labelField;
> >            for each (var item:String in result.split("["))
> >            {
> >                if (item.indexOf("]") > -1)
> >                {
> >                    var field:String = item.split("]")[0];
> >                    result = result.replace("[" + field + "]",
> data[field]);
> >                }
> >            }
> >            return result;
> >        }
> >
> >        if (obj is IHasLabelField &&
> >            (obj as IHasLabelField).labelField &&
> >            data[(obj as IHasLabelField).labelField] != null)
> >        {
> >            return "" + data[(obj as IHasLabelField).labelField];
> >        }
> >
> >        if (obj is IHasDataField &&
> >            (obj as IHasDataField).dataField &&
> >            data[(obj as IHasDataField).dataField] != null)
> >        {
> >            return "" + data[(obj as IHasDataField).dataField];
> >        }
> >
> >        var label:String = data["label"];
> >        if(label != null){
> >            return label;
> >        }
> >        return "" + data;
> >
> >    }
> >
> > Maria Jose Esteve <mj...@iest.com> escreveu no dia terça, 7/06/2022
> à(s)
> > 21:44:
> >
> >> Hugo, could it be seen? Maybe a branch or a PR?
> >>
> >> Hiedra
> >>
> >> -----Mensaje original-----
> >> De: Hugo Ferreira <hf...@gmail.com>
> >> Enviado el: martes, 7 de junio de 2022 21:58
> >> Para: Apache Royale Development <de...@royale.apache.org>
> >> Asunto: Proposal for labelField with expression support
> >>
> >> Hi,
> >>
> >> In Flex "world" one can use labelField and labelFunction.
> >> Here in Royale we have only labelField (at least I didn't see so far
> >> support for labelFunction), however I'm not a big fan of labelFunction
> >> anyway.
> >>
> >> I always wanted support for something in between of labelField and
> >> labelFunction (labelFunction with multiple fields and fixed strings)
> and I
> >> implement it on my side.
> >>
> >> Ex:
> >> model:
> >> public class User
> >> {
> >> public var Code:String;
> >> public var Name:String;
> >> }
> >>
> >> With this model, one can use Code (user code) or Name but not the
> combined
> >> fields.
> >>
> >> With a little adition I can now do something like this:
> labelField="[Code]
> >> - [Name]" and at runtime every field delimited by [] it's replaced for
> his
> >> value, allowing multiple fields and complex expressions.
> >>
> >> Can I commit this or there is a reason to not do so ?
> >>
> >> Thank you,
> >> Hugo.
> >>
>
>

Re: Proposal for labelField with expression support

Posted by Harbs <ha...@gmail.com>.
Hard coding it into a function which is widely used by ItemRenderers does not seem like a good idea or very PAYG.

Id suggest creating ItemRenderers which have this behavior.

If there’s some way to inject the behavior into existing functions that would be fine too, but I can’t think off hand of a good way of doing that.

> On Jun 7, 2022, at 11:48 PM, Hugo Ferreira <hf...@gmail.com> wrote:
> 
> Method getLabelFromData from getLabelFromData.as
> 
> I just added a new if block that seek for "[" and thread the keys.
> If it's OK, I can commit, otherwise I ask what's the best alternative
> solution to achive the same result.
> 
>    public function getLabelFromData(obj:Object,data:Object):String
>    {
>        // slightly more code, but we bail early if it's a string which is
> often
>        if (data is String) return "" + data;
>        if(!data) return "";
>        if(data is ILabeledData) return (data as ILabeledData).label;
> 
>        if (obj is IHasLabelField &&
>            (obj as IHasLabelField).labelField &&
>            (obj as IHasLabelField).labelField.indexOf("[") > -1)
>        {
>            var result:String = (obj as IHasLabelField).labelField;
>            for each (var item:String in result.split("["))
>            {
>                if (item.indexOf("]") > -1)
>                {
>                    var field:String = item.split("]")[0];
>                    result = result.replace("[" + field + "]", data[field]);
>                }
>            }
>            return result;
>        }
> 
>        if (obj is IHasLabelField &&
>            (obj as IHasLabelField).labelField &&
>            data[(obj as IHasLabelField).labelField] != null)
>        {
>            return "" + data[(obj as IHasLabelField).labelField];
>        }
> 
>        if (obj is IHasDataField &&
>            (obj as IHasDataField).dataField &&
>            data[(obj as IHasDataField).dataField] != null)
>        {
>            return "" + data[(obj as IHasDataField).dataField];
>        }
> 
>        var label:String = data["label"];
>        if(label != null){
>            return label;
>        }
>        return "" + data;
> 
>    }
> 
> Maria Jose Esteve <mj...@iest.com> escreveu no dia terça, 7/06/2022 à(s)
> 21:44:
> 
>> Hugo, could it be seen? Maybe a branch or a PR?
>> 
>> Hiedra
>> 
>> -----Mensaje original-----
>> De: Hugo Ferreira <hf...@gmail.com>
>> Enviado el: martes, 7 de junio de 2022 21:58
>> Para: Apache Royale Development <de...@royale.apache.org>
>> Asunto: Proposal for labelField with expression support
>> 
>> Hi,
>> 
>> In Flex "world" one can use labelField and labelFunction.
>> Here in Royale we have only labelField (at least I didn't see so far
>> support for labelFunction), however I'm not a big fan of labelFunction
>> anyway.
>> 
>> I always wanted support for something in between of labelField and
>> labelFunction (labelFunction with multiple fields and fixed strings) and I
>> implement it on my side.
>> 
>> Ex:
>> model:
>> public class User
>> {
>> public var Code:String;
>> public var Name:String;
>> }
>> 
>> With this model, one can use Code (user code) or Name but not the combined
>> fields.
>> 
>> With a little adition I can now do something like this: labelField="[Code]
>> - [Name]" and at runtime every field delimited by [] it's replaced for his
>> value, allowing multiple fields and complex expressions.
>> 
>> Can I commit this or there is a reason to not do so ?
>> 
>> Thank you,
>> Hugo.
>> 


Re: Proposal for labelField with expression support

Posted by Hugo Ferreira <hf...@gmail.com>.
Method getLabelFromData from getLabelFromData.as

I just added a new if block that seek for "[" and thread the keys.
If it's OK, I can commit, otherwise I ask what's the best alternative
solution to achive the same result.

    public function getLabelFromData(obj:Object,data:Object):String
    {
        // slightly more code, but we bail early if it's a string which is
often
        if (data is String) return "" + data;
        if(!data) return "";
        if(data is ILabeledData) return (data as ILabeledData).label;

        if (obj is IHasLabelField &&
            (obj as IHasLabelField).labelField &&
            (obj as IHasLabelField).labelField.indexOf("[") > -1)
        {
            var result:String = (obj as IHasLabelField).labelField;
            for each (var item:String in result.split("["))
            {
                if (item.indexOf("]") > -1)
                {
                    var field:String = item.split("]")[0];
                    result = result.replace("[" + field + "]", data[field]);
                }
            }
            return result;
        }

        if (obj is IHasLabelField &&
            (obj as IHasLabelField).labelField &&
            data[(obj as IHasLabelField).labelField] != null)
        {
            return "" + data[(obj as IHasLabelField).labelField];
        }

        if (obj is IHasDataField &&
            (obj as IHasDataField).dataField &&
            data[(obj as IHasDataField).dataField] != null)
        {
            return "" + data[(obj as IHasDataField).dataField];
        }

        var label:String = data["label"];
        if(label != null){
            return label;
        }
        return "" + data;

    }

Maria Jose Esteve <mj...@iest.com> escreveu no dia terça, 7/06/2022 à(s)
21:44:

> Hugo, could it be seen? Maybe a branch or a PR?
>
> Hiedra
>
> -----Mensaje original-----
> De: Hugo Ferreira <hf...@gmail.com>
> Enviado el: martes, 7 de junio de 2022 21:58
> Para: Apache Royale Development <de...@royale.apache.org>
> Asunto: Proposal for labelField with expression support
>
> Hi,
>
> In Flex "world" one can use labelField and labelFunction.
> Here in Royale we have only labelField (at least I didn't see so far
> support for labelFunction), however I'm not a big fan of labelFunction
> anyway.
>
> I always wanted support for something in between of labelField and
> labelFunction (labelFunction with multiple fields and fixed strings) and I
> implement it on my side.
>
> Ex:
> model:
> public class User
> {
> public var Code:String;
> public var Name:String;
> }
>
> With this model, one can use Code (user code) or Name but not the combined
> fields.
>
> With a little adition I can now do something like this: labelField="[Code]
> - [Name]" and at runtime every field delimited by [] it's replaced for his
> value, allowing multiple fields and complex expressions.
>
> Can I commit this or there is a reason to not do so ?
>
> Thank you,
> Hugo.
>

RE: Proposal for labelField with expression support

Posted by Maria Jose Esteve <mj...@iest.com>.
Hugo, could it be seen? Maybe a branch or a PR?

Hiedra

-----Mensaje original-----
De: Hugo Ferreira <hf...@gmail.com> 
Enviado el: martes, 7 de junio de 2022 21:58
Para: Apache Royale Development <de...@royale.apache.org>
Asunto: Proposal for labelField with expression support

Hi,

In Flex "world" one can use labelField and labelFunction.
Here in Royale we have only labelField (at least I didn't see so far support for labelFunction), however I'm not a big fan of labelFunction anyway.

I always wanted support for something in between of labelField and labelFunction (labelFunction with multiple fields and fixed strings) and I implement it on my side.

Ex:
model:
public class User
{
public var Code:String;
public var Name:String;
}

With this model, one can use Code (user code) or Name but not the combined fields.

With a little adition I can now do something like this: labelField="[Code]
- [Name]" and at runtime every field delimited by [] it's replaced for his value, allowing multiple fields and complex expressions.

Can I commit this or there is a reason to not do so ?

Thank you,
Hugo.