Select to view content in your preferred language

How to get widget instance by id in flexviewer2.2?

1251
1
03-02-2011 12:50 AM
jianhuizhou
Emerging Contributor
Help!!!
How to get widget instance by id in flexviewer2.2?
just like "SiteContainer.getInstance().widgetManager.getWidget(id)"
Tags (2)
0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus
Jianhui,

Here is the new function for the WidgetManager:

   //My Add
   //=====================================================================
   //Get Widget and return it to calling function
   //=====================================================================
   public function getWidget(id:Number):IBaseWidget
   {
    var idx:Object = configData.widgetIndex[id];
    
    var wgtContainer:IWidgetContainer = configData.widgetContainers[idx.container].container.obj;
    var wgt:Object = configData.widgetContainers[idx.container].widgets[idx.widget];
    
    var preload:String  = wgt.preload;
    var label:String    = wgt.label;
    var icon:String     = wgt.icon;
    var config:String   = wgt.config;
    var url:String      = wgt.url;
    var headless:String = wgt.headless;
    
    var wx:Number       = Number(wgt.x);
    var wy:Number       = Number(wgt.y);
    var wleft:String    = wgt.left;
    var wtop:String     = wgt.top;
    var wright:String   = wgt.right;
    var wbottom:String  = wgt.bottom;
    
    //widget loaded
    var widget:IBaseWidget;
    if (widgetTable.containsKey(id))
    {
     widget = widgetTable.find(id) as IBaseWidget;
     
     //add back the container if exists
     widget.setState(BaseWidget.WIDGET_OPENED);
     wgtContainer.focusWidget(id);
    }
    else
    {
     //module loaded
     if (moduleTable.containsKey(url))
     {
      var modInfo:IModuleInfo = moduleTable.find(url) as IModuleInfo;
      widget = modInfo.factory.create() as IBaseWidget;
      widget.widgetId     = id;
      widget.widgetTitle  = label;
      widget.widgetIcon   = icon;
      widget.config       = config;
      widget.configData   = configData;
      widget.map          = map;
      widget.isDraggable  = this.isDraggable;
      widget.isResizeable = this.isResizeable;
      
      widget.setPreload(preload);
      
      // if no X and Y both configured, use system X/Y for positioning
      if (wleft||wtop||wright||wbottom)
      {
       widget.setRelativePosition(wleft,wright,wtop,wbottom);
      }
      else if (wx && wy)
      {
       widget.setXYPosition(wx,wy);
      }
      else
      {
       setAutoXY();
       wx = _refX;
       wy = _refY
       widget.setXYPosition(wx, wy);
      }
      
      wgtContainer.addWidget(widget);
      
      if (preload)
       widget.setState(preload);
      else
       widget.setState(BaseWidget.WIDGET_OPENED);
      
      widgetTable.add(id, widget);
     }
     else
     {
      loadWidget(id);
     }
    }
    return widget;
   }
   //End My Add


and here is the new code to call it:

ViewerContainer.getInstance().widgetManager.getWidget(id)
0 Kudos