BaseWidget's close() function missing after API upgrade?

2449
8
06-24-2011 04:53 AM
MattMoyles
New Contributor III
I'm working on upgrading our App to Flex 4.5 and ArcGIS Flex API 2.3.1. Everything went smoothly thanks to some tips I read in another thread but there is still one thing I can't figure out.

We have code in many of our widgets that will close the current running widget if another widget is opened.

This is not even really the behavior I wanted in the first place. I would rather have the reverse where the openDetect function will close the widget that it is trying to open but I haven't been able to figure that one out.

So the actual error is that this.close(); does not exist. I tried tacking an id onto BaseWidget like id="myBaseWidget" but myBaseWidget.close() does not exists either.

I would very much appreciate if anyone could tell me what's up with the close function and If anyone knows how I could block the widget trying to be opened in openDetect that would be even better.

            private function openDetect(event:AppEvent):void {
                var id:Number = event.data as Number;
                var idx:Object = configData.widgetIndex[id];
                var wgt:Object = configData.widgetContainers[idx.container].widgets[idx.widget];
                var wid:String = wgt.url;
                var blocked:ArrayCollection = new ArrayCollection([
                    "widgets/EditSWEATIR/EditSWEATIRWidget.swf"
                ]);
                if(blocked.contains(wid)){
                    this.close();
                }
            }

            private function widgetOpenedHandler(event:Event):void
            {
                ViewerContainer.addEventListener(AppEvent.WIDGET_RUN, openDetect);
            }
Tags (2)
0 Kudos
8 Replies
MattMoyles
New Contributor III
Well it appears that the close() function was something one of my co-workers added in, and I overwrote the modified BaseWidget while upgrading.

But I'm still looking for a better way to handle this if anyone has any ideas.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Matt,

   Can you break down your request a little more for me? Are you try to prevent a certain widget from opening and if that is the case when would you allow it to be opened? I'm sure I could help if I understood...
0 Kudos
MattMoyles
New Contributor III
We have a few sets of widget where one widget is an 'Editor' and the other is the 'Viewer'. It would not make sense, and would cause problems if both of these widgets were allowed to be open at the same time.

That code I posted above would be in both the Editor and Viewer widgets preventing them from being open at the same time. Currently the way it works is if you have the Editor widget open and decide to open the viewer widget it will close the Editor widget.

What I was originally looking to do was if you had the Editor widget open and tried to open the viewer widget it would block the viewer widget from opening, instead of closing the editor widget.

I hope that makes sense. And thank you for the response!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Matt,

  
What I was originally looking to do was if you had the Editor widget  open and tried to open the viewer widget it would block the viewer  widget from opening, instead of closing the editor widget.

Is this still your preferred behavior?
0 Kudos
MattMoyles
New Contributor III
Yes, that's the way I'd like it to happen, is there an event I'm missing that could do that?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Matt,

   Well it was a lot harder than I thought it would be...

I managed it in the HeaderControllerWidget.mxml, you have to replace two existing function and add a new one and a couple of import statements. And of course replace the widget names in the code with your own.

What this does is prevents the other defined widget from running if the second one is visible and vice versa.

            import com.esri.viewer.IBaseWidget;
            import com.esri.viewer.IWidgetContainer;
            import mx.core.IVisualElement;
            import widgets.WidgetContainer.WidgetContainerWidget;

            private function widgetItemDG_widgetItemClickHandler(event:Event):void
            {
                var widgetItem:WidgetItem = ItemRenderer(event.target).data as WidgetItem;
                if (widgetItem.isGroup)
                {
                    groupWidgetAC = new ArrayCollection();
                    // check the array of widgets if they are open before hand
                    for each (var widgetObj:Object in widgetItem.widgets)
                    {
                        var widgetItem1:WidgetItem = new WidgetItem;
                        widgetItem1.id = widgetObj.widget.id;
                        widgetItem1.label = widgetObj.widget.label;
                        widgetItem1.icon = widgetObj.widget.icon;
                        widgetItem1.url = widgetObj.widget.url;
                        widgetItem1.open = widgetObj.open;

                        groupWidgetAC.addItem(widgetItem1);
                    }
                    menuToolTip.visible = false;
                    widgetList.visible = true;
                }
                else
                {
                    checkIfRunOk(widgetItem);
                }
            }
            private function checkIfRunOk(widgetItem:WidgetItem):void
            {
                var allow:Boolean = true;
                var sid:Number = ViewerContainer.getInstance().getWidgetId("Enhanced Search");
                var sid2:Number = ViewerContainer.getInstance().getWidgetId("Draw and Measure");
                if(!isNaN(sid)){
                    var idx:Object = configData.widgetIndex[widgetItem.id];
                    var wgtContainer:IWidgetContainer = configData.widgetContainers[idx.container].container.obj;
                    var wc:* = wgtContainer;
                    if(wc){
                        var ve:IVisualElement;
                        for (var e:int = 0; e < wc.widgetContainer.widgetContainer.numElements; e++)
                        {
                            ve = wc.widgetContainer.widgetContainer.getElementAt(e);
                            
                            var baseWidget:IBaseWidget = ve as IBaseWidget;
                            
                            if (baseWidget.widgetId == sid)
                            {                            
                                if(ve.visible && widgetItem.label == "Draw and Measure"){
                                    allow = false;
                                    break;
                                }    
                            }else if(baseWidget.widgetId == sid2){
                                if(ve.visible && widgetItem.label == "Enhanced Search"){
                                    allow = false;
                                    break;
                                }
                            }
                        }
                    }
                }
                if(allow)    
                    ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, widgetItem.id));
            }

            private function widgetList_widgetItemClickHandler(event:Event):void
            {
                var widgetItem:WidgetItem = ItemRenderer(event.target).data as WidgetItem;
                checkIfRunOk(widgetItem);
            }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Matt,

   I forgot you will need the getWidgetId function added to your ViewerContainer.mxml also.

//My Add    
            public var _configData:ConfigData;
//End My Add

//My Add
            public function getWidgetId(widgetLabel:String):Number
            {
                var id:Number = Number.NaN;
                for (var i:Number = 0; i < _configData.widgets.length; i++)
                {
                    if (_configData.widgets.label == widgetLabel)
                        id = _configData.widgets.id;
                }
                return id;
            }
//End My Add

            private function postConfigHandler(event:AppEvent):void
            {
//My Change
                var configData:ConfigData = _configData = event.data as ConfigData;
//End My Change
                var ui:Array = configData.viewerUI;
                var splash:Object = {};

                for (var i:int = 0; i < ui.length; i++)
                {
                    if (ui.id == "splashpage")
                    {
                        splash.url = ui.value;
                        splash.config = ui.config;
                        splash.title = ui.title;
                    }
                }

                if (splash.url)
                {
                    loadSplash(splash);
                }
            }
0 Kudos
RobertRectenwald
New Contributor
I've used this functionality to close my widgets after a map click event:

[INDENT]private function mapClicked(event:MapMouseEvent):void
{
[INDENT]this.setState('closed');[/INDENT]
}
[/INDENT]
I've also verified that it fires the widget close handler.
0 Kudos