home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / mx / controls / treeClasses / DefaultDataDescriptor.as next >
Encoding:
Text File  |  2010-06-23  |  12.8 KB  |  472 lines

  1. package mx.controls.treeClasses
  2. {
  3.    import flash.utils.Dictionary;
  4.    import mx.collections.ArrayCollection;
  5.    import mx.collections.CursorBookmark;
  6.    import mx.collections.ICollectionView;
  7.    import mx.collections.IList;
  8.    import mx.collections.IViewCursor;
  9.    import mx.collections.XMLListCollection;
  10.    import mx.controls.menuClasses.IMenuDataDescriptor;
  11.    import mx.core.mx_internal;
  12.    
  13.    use namespace mx_internal;
  14.    
  15.    public class DefaultDataDescriptor implements ITreeDataDescriptor2, IMenuDataDescriptor
  16.    {
  17.       mx_internal static const VERSION:String = "3.5.0.12683";
  18.       
  19.       private var ChildCollectionCache:Dictionary = new Dictionary(true);
  20.       
  21.       public function DefaultDataDescriptor()
  22.       {
  23.          super();
  24.       }
  25.       
  26.       public function setEnabled(param1:Object, param2:Boolean) : void
  27.       {
  28.          var node:Object = param1;
  29.          var value:Boolean = param2;
  30.          if(node is XML)
  31.          {
  32.             node.@enabled = value;
  33.          }
  34.          else if(node is Object)
  35.          {
  36.             try
  37.             {
  38.                node.enabled = value;
  39.             }
  40.             catch(e:Error)
  41.             {
  42.             }
  43.          }
  44.       }
  45.       
  46.       public function removeChildAt(param1:Object, param2:Object, param3:int, param4:Object = null) : Boolean
  47.       {
  48.          var cursor:IViewCursor = null;
  49.          var children:ICollectionView = null;
  50.          var parent:Object = param1;
  51.          var child:Object = param2;
  52.          var index:int = param3;
  53.          var model:Object = param4;
  54.          if(!parent)
  55.          {
  56.             try
  57.             {
  58.                if(index > model.length)
  59.                {
  60.                   index = int(model.length);
  61.                }
  62.                if(model is IList)
  63.                {
  64.                   model.removeItemAt(index);
  65.                }
  66.                else
  67.                {
  68.                   cursor = model.createCursor();
  69.                   cursor.seek(CursorBookmark.FIRST,index);
  70.                   cursor.remove();
  71.                }
  72.                return true;
  73.             }
  74.             catch(e:Error)
  75.             {
  76.             }
  77.          }
  78.          else
  79.          {
  80.             children = ICollectionView(getChildren(parent,model));
  81.             try
  82.             {
  83.                if(index > children.length)
  84.                {
  85.                   index = children.length;
  86.                }
  87.                if(children is IList)
  88.                {
  89.                   IList(children).removeItemAt(index);
  90.                }
  91.                else
  92.                {
  93.                   cursor = children.createCursor();
  94.                   cursor.seek(CursorBookmark.FIRST,index);
  95.                   cursor.remove();
  96.                }
  97.                return true;
  98.             }
  99.             catch(e:Error)
  100.             {
  101.             }
  102.          }
  103.          return false;
  104.       }
  105.       
  106.       public function isToggled(param1:Object) : Boolean
  107.       {
  108.          var toggled:* = undefined;
  109.          var node:Object = param1;
  110.          if(node is XML)
  111.          {
  112.             toggled = node.@toggled;
  113.             if(toggled[0] == true)
  114.             {
  115.                return true;
  116.             }
  117.          }
  118.          else if(node is Object)
  119.          {
  120.             try
  121.             {
  122.                return Boolean(node.toggled);
  123.             }
  124.             catch(e:Error)
  125.             {
  126.             }
  127.          }
  128.          return false;
  129.       }
  130.       
  131.       public function getHierarchicalCollectionAdaptor(param1:ICollectionView, param2:Function, param3:Object, param4:Object = null) : ICollectionView
  132.       {
  133.          return new HierarchicalCollectionView(param1,this,param2,param3);
  134.       }
  135.       
  136.       public function addChildAt(param1:Object, param2:Object, param3:int, param4:Object = null) : Boolean
  137.       {
  138.          var cursor:IViewCursor = null;
  139.          var children:ICollectionView = null;
  140.          var temp:XMLList = null;
  141.          var parent:Object = param1;
  142.          var newChild:Object = param2;
  143.          var index:int = param3;
  144.          var model:Object = param4;
  145.          if(!parent)
  146.          {
  147.             try
  148.             {
  149.                if(index > model.length)
  150.                {
  151.                   index = int(model.length);
  152.                }
  153.                if(model is IList)
  154.                {
  155.                   IList(model).addItemAt(newChild,index);
  156.                }
  157.                else
  158.                {
  159.                   cursor = model.createCursor();
  160.                   cursor.seek(CursorBookmark.FIRST,index);
  161.                   cursor.insert(newChild);
  162.                }
  163.                return true;
  164.             }
  165.             catch(e:Error)
  166.             {
  167.             }
  168.          }
  169.          else
  170.          {
  171.             children = ICollectionView(getChildren(parent,model));
  172.             if(!children)
  173.             {
  174.                if(parent is XML)
  175.                {
  176.                   temp = new XMLList();
  177.                   XML(parent).appendChild(temp);
  178.                   children = new XMLListCollection(parent.children());
  179.                }
  180.                else if(parent is Object)
  181.                {
  182.                   parent.children = new ArrayCollection();
  183.                   children = parent.children;
  184.                }
  185.             }
  186.             try
  187.             {
  188.                if(index > children.length)
  189.                {
  190.                   index = children.length;
  191.                }
  192.                if(children is IList)
  193.                {
  194.                   IList(children).addItemAt(newChild,index);
  195.                }
  196.                else
  197.                {
  198.                   cursor = children.createCursor();
  199.                   cursor.seek(CursorBookmark.FIRST,index);
  200.                   cursor.insert(newChild);
  201.                }
  202.                return true;
  203.             }
  204.             catch(e:Error)
  205.             {
  206.             }
  207.          }
  208.          return false;
  209.       }
  210.       
  211.       public function getData(param1:Object, param2:Object = null) : Object
  212.       {
  213.          return Object(param1);
  214.       }
  215.       
  216.       public function setToggled(param1:Object, param2:Boolean) : void
  217.       {
  218.          var node:Object = param1;
  219.          var value:Boolean = param2;
  220.          if(node is XML)
  221.          {
  222.             node.@toggled = value;
  223.          }
  224.          else if(node is Object)
  225.          {
  226.             try
  227.             {
  228.                node.toggled = value;
  229.             }
  230.             catch(e:Error)
  231.             {
  232.             }
  233.          }
  234.       }
  235.       
  236.       public function getNodeDepth(param1:Object, param2:IViewCursor, param3:Object = null) : int
  237.       {
  238.          if(param1 == param2.current)
  239.          {
  240.             return HierarchicalViewCursor(param2).currentDepth;
  241.          }
  242.          return -1;
  243.       }
  244.       
  245.       public function getType(param1:Object) : String
  246.       {
  247.          var node:Object = param1;
  248.          if(node is XML)
  249.          {
  250.             return String(node.@type);
  251.          }
  252.          if(node is Object)
  253.          {
  254.             try
  255.             {
  256.                return String(node.type);
  257.             }
  258.             catch(e:Error)
  259.             {
  260.             }
  261.          }
  262.          return "";
  263.       }
  264.       
  265.       public function getGroupName(param1:Object) : String
  266.       {
  267.          var node:Object = param1;
  268.          if(node is XML)
  269.          {
  270.             return node.@groupName;
  271.          }
  272.          if(node is Object)
  273.          {
  274.             try
  275.             {
  276.                return node.groupName;
  277.             }
  278.             catch(e:Error)
  279.             {
  280.             }
  281.          }
  282.          return "";
  283.       }
  284.       
  285.       public function getParent(param1:Object, param2:ICollectionView, param3:Object = null) : Object
  286.       {
  287.          return HierarchicalCollectionView(param2).getParentItem(param1);
  288.       }
  289.       
  290.       public function hasChildren(param1:Object, param2:Object = null) : Boolean
  291.       {
  292.          var children:ICollectionView;
  293.          var node:Object = param1;
  294.          var model:Object = param2;
  295.          if(node == null)
  296.          {
  297.             return false;
  298.          }
  299.          children = getChildren(node,model);
  300.          try
  301.          {
  302.             if(children.length > 0)
  303.             {
  304.                return true;
  305.             }
  306.          }
  307.          catch(e:Error)
  308.          {
  309.          }
  310.          return false;
  311.       }
  312.       
  313.       public function isBranch(param1:Object, param2:Object = null) : Boolean
  314.       {
  315.          var branch:Boolean;
  316.          var childList:XMLList = null;
  317.          var branchFlag:XMLList = null;
  318.          var node:Object = param1;
  319.          var model:Object = param2;
  320.          if(node == null)
  321.          {
  322.             return false;
  323.          }
  324.          branch = false;
  325.          if(node is XML)
  326.          {
  327.             childList = node.children();
  328.             branchFlag = node.@isBranch;
  329.             if(branchFlag.length() == 1)
  330.             {
  331.                if(branchFlag[0] == "true")
  332.                {
  333.                   branch = true;
  334.                }
  335.             }
  336.             else if(childList.length() != 0)
  337.             {
  338.                branch = true;
  339.             }
  340.          }
  341.          else if(node is Object)
  342.          {
  343.             try
  344.             {
  345.                if(node.children != undefined)
  346.                {
  347.                   branch = true;
  348.                }
  349.             }
  350.             catch(e:Error)
  351.             {
  352.             }
  353.          }
  354.          return branch;
  355.       }
  356.       
  357.       public function getChildren(param1:Object, param2:Object = null) : ICollectionView
  358.       {
  359.          var children:* = undefined;
  360.          var childrenCollection:ICollectionView = null;
  361.          var oldArrayCollection:ArrayCollection = null;
  362.          var oldXMLCollection:XMLListCollection = null;
  363.          var p:* = undefined;
  364.          var childArray:Array = null;
  365.          var node:Object = param1;
  366.          var model:Object = param2;
  367.          if(node == null)
  368.          {
  369.             return null;
  370.          }
  371.          if(node is XML)
  372.          {
  373.             children = node.*;
  374.          }
  375.          else if(node is Object)
  376.          {
  377.             try
  378.             {
  379.                children = node.children;
  380.             }
  381.             catch(e:Error)
  382.             {
  383.             }
  384.          }
  385.          if(children == undefined && !(children is XMLList))
  386.          {
  387.             return null;
  388.          }
  389.          if(children is ICollectionView)
  390.          {
  391.             childrenCollection = ICollectionView(children);
  392.          }
  393.          else if(children is Array)
  394.          {
  395.             oldArrayCollection = ChildCollectionCache[node];
  396.             if(!oldArrayCollection)
  397.             {
  398.                childrenCollection = new ArrayCollection(children);
  399.                ChildCollectionCache[node] = childrenCollection;
  400.             }
  401.             else
  402.             {
  403.                childrenCollection = oldArrayCollection;
  404.                ArrayCollection(childrenCollection).mx_internal::dispatchResetEvent = false;
  405.                ArrayCollection(childrenCollection).source = children;
  406.             }
  407.          }
  408.          else if(children is XMLList)
  409.          {
  410.             oldXMLCollection = ChildCollectionCache[node];
  411.             if(!oldXMLCollection)
  412.             {
  413.                for(p in ChildCollectionCache)
  414.                {
  415.                   if(p === node)
  416.                   {
  417.                      oldXMLCollection = ChildCollectionCache[p];
  418.                      break;
  419.                   }
  420.                }
  421.             }
  422.             if(!oldXMLCollection)
  423.             {
  424.                childrenCollection = new XMLListCollection(children);
  425.                ChildCollectionCache[node] = childrenCollection;
  426.             }
  427.             else
  428.             {
  429.                childrenCollection = oldXMLCollection;
  430.                XMLListCollection(childrenCollection).mx_internal::dispatchResetEvent = false;
  431.                XMLListCollection(childrenCollection).source = children;
  432.             }
  433.          }
  434.          else
  435.          {
  436.             childArray = new Array(children);
  437.             if(childArray != null)
  438.             {
  439.                childrenCollection = new ArrayCollection(childArray);
  440.             }
  441.          }
  442.          return childrenCollection;
  443.       }
  444.       
  445.       public function isEnabled(param1:Object) : Boolean
  446.       {
  447.          var enabled:* = undefined;
  448.          var node:Object = param1;
  449.          if(node is XML)
  450.          {
  451.             enabled = node.@enabled;
  452.             if(enabled[0] == false)
  453.             {
  454.                return false;
  455.             }
  456.          }
  457.          else if(node is Object)
  458.          {
  459.             try
  460.             {
  461.                return "false" != String(node.enabled);
  462.             }
  463.             catch(e:Error)
  464.             {
  465.             }
  466.          }
  467.          return true;
  468.       }
  469.    }
  470. }
  471.  
  472.