0 Replies Latest reply on May 6, 2008 6:19 PM by mcagagnon

    Widget system with lists

    mcagagnon
      Hi,

      I am implementing a widget environment. The concept is simple : Widgets are draggables windows with unique content and can be moved and reordered in a defined space in the application.

      A Widget is simply a custom component extended from the TitleWindows control. To implement the drag&drop and reordering behaviours, i have used 2 List controls which natively support these capabilities and i've used a Widget as the itemrenderer (so the widgets are IN the list control but the style of the list have been modified so the appear "free"). The widgets can be dragged across the 2 lists and can be reordered in any order. So far everything work as expected.

      Here is the problem : The itemrenderer of a list, which can render the generic Widget component correctly (with the title and the content), is unable to render the specific widgets (WeatherWidget,PostItWidget,etc.) components correctly, even if there are extended from the Widget component. The appear as blank TitleWindow with no title...

      Here is the brief code :
      quote:


      WIDGET generic component
      <mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      </mx:TitleWindow>



      quote:


      DERIVED WIDGET (ex:WeatherWidget or any widget derived from the Widget component)
      <Widget xmlns="*" xmlns:mx=" http://www.adobe.com/2006/mxml" width="286" height="144" title="Météo locale">
      <mx:Label x="75.5" y="25" text="Weather forecast..."/>
      <mx:Button x="10" y="8" label="Button" click="someAction()"/>
      </Widget>



      quote:


      WIDGETCONTAINER (list component)
      <mx:List xmlns:mx=" http://www.adobe.com/2006/mxml" itemRenderer="WidgetRenderer" dataProvider="{widgetList}" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" styleName="pnl" useRollOver="false" xmlns:local="*" paddingBottom="20">

      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;

      [Bindable]
      private var widgetList:ArrayCollection=new ArrayCollection();

      public function addWidget(widget:Widget):void{
      widgetList.addItem(widget);
      }

      ]]>
      </mx:Script>
      </mx:List>



      quote:


      WIDGETRENDERER (the item renderer which can render the generic Widget component perfectly, but not derived components)
      <?xml version="1.0" encoding="utf-8" ?>
      <Widget xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" >
      </Widget>



      With this code, the generic Widget is rendered correctly (with title and content), but derived Widgets (WeatherWidget, etc.) are rendered as blank TitleWindow without any content or any title.

      Is there any way to render all derived Widgets (which are all different) with a single itemrenderer ?

      Thank you !