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 <hferreira...@gmail.com> 
Enviado el: miércoles, 8 de junio de 2022 20:48
Para: Apache Royale Development <dev@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 <mjest...@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 <hferreira...@gmail.com> Enviado el: miércoles, 8 de 
> junio de 2022 0:38
> Para: Apache Royale Development <dev@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 <aha...@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" <harbs.li...@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 
> > <hferreira...@gmail.com>
> > wrote:
> >     >
> >     > Yes, I know that.
> >     > But seems a bazooka for a simple thing.
> >
> >
> >
>

Reply via email to