Changeset 2572


Ignore:
Timestamp:
02/13/13 08:49:29 (11 years ago)
Author:
twagoo
Message:

Prevented loading of component XML until XML tab is actually selected. Also truncated large XML content to prevent plugin/browser hangs and crashes. [Fixes #268]

Location:
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/infoPage.mxml

    r2278 r2572  
    2323                                  height="100%"
    2424                                  width="100%"
    25                                   styleName="borderStyles">
     25                                  styleName="borderStyles"
     26                                  change="infoViewStack_changeHandler(event)"
     27                                  >
    2628
    2729                <browser:xmlBrowsePanel id="viewPanel"
     
    2931                                                                cmdComponent="{cmdComponent}"
    3032                                                                itemDescription="{_itemDescription}"/>
     33               
    3134                <browser:xmlPanel id="xmlPanel"
    3235                                                  label="xml"
    3336                                                  cmdComponent="{cmdComponent}"/>
     37               
    3438                <browser:CommentsPanel id="commentsPanel"
    3539                                                           label="{commentsLabel}"
     
    4650                       
    4751                        import mx.events.FlexEvent;
     52                        import mx.events.IndexChangedEvent;
     53                        import mx.messaging.SubscriptionInfo;
    4854                       
    4955                        [Bindable]
     
    5460                                        infoViewStack.selectedChild = viewPanel;
    5561                                } else if(startupPanel == Config.BROWSER_PANEL_XML) {                                   
    56                                         infoViewStack.selectedChild = xmlPanel;
     62                                        //infoViewStack.selectedChild = xmlPanel;
    5763                                } else if(startupPanel == Config.BROWSER_PANEL_COMMENTS) {
    5864                                        infoViewStack.selectedChild = commentsPanel;
     
    7783                        }
    7884
     85                        protected function infoViewStack_changeHandler(event:IndexChangedEvent):void
     86                        {
     87                                xmlPanel.updateCmdComponentText();
     88                        }
     89
    7990                ]]>
    8091        </mx:Script>
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/xmlPanel.mxml

    r1730 r2572  
    33                 xmlns:comp="clarin.cmdi.componentregistry.common.components.*">
    44
    5         <mx:XML id="cmdComponent"/>
    65        <comp:ScrollableTextArea id="infoTextArea"
    76                                                         styleName="xmlTextArea"
    87                                                         editable="false"
    9                                                          text="{cmdComponent}"
    108                                                         width="100%"
    119                                                         height="100%"
     
    1311                                                         paddingTop="5"
    1412                                                         />
     13       
     14        <mx:Script>
     15                <!--
     16                        The code below assures lazy loading of the component XML into the scrollable text area.
     17                        Large component specifications can cause the application to hang or even crash the browser,
     18                        see <https://trac.clarin.eu/ticket/268>
     19                -->
     20                <![CDATA[
     21                        import mx.containers.ViewStack;
     22                        import mx.core.Application;
     23                        private var componentXML:XML;
     24                        private var MAX_XML_LENGTH:int = 10000;
     25                       
     26                        public function set cmdComponent(xml:XML):void {
     27                                if(this.componentXML != xml){
     28                                        this.componentXML = xml;
     29                                        updateCmdComponentText();
     30                                }
     31                        }
     32                       
     33                        public function updateCmdComponentText():void {
     34                                // Only forward the XML to the text area if the XML panel is the selected view
     35                                if(isSelectedView()){
     36                                        var xmlText:String = componentXML.toXMLString();
     37                                        if(xmlText.length > MAX_XML_LENGTH + 3){
     38                                                // XML too lengthy, truncate (otherwise we run into performance issues)
     39                                                infoTextArea.text = xmlText.substr(0, MAX_XML_LENGTH) + "...\n\nSpecification too large to display. Download XML to see the entire specification.";
     40                                        } else{
     41                                                infoTextArea.text = xmlText;
     42                                        }
     43                                }
     44                        }
     45                       
     46                        private function isSelectedView():Boolean
     47                        {
     48                                var obj:DisplayObject = this;
     49                                // Whole chain until application root should be visible
     50                                while (obj && obj !== Application.application)
     51                                {
     52                                        // Special case: viewstack - this item should be the selected item
     53                                        if(obj.parent is ViewStack){
     54                                                return ViewStack(obj.parent).selectedChild == obj;
     55                                        }
     56                                       
     57                                        obj = obj.parent;
     58                                }
     59                                return true;
     60                        }
     61                ]]>
     62        </mx:Script>
    1563</mx:VBox>
Note: See TracChangeset for help on using the changeset viewer.