| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Adobe Flex SDK
Revision: 3092
Author: clucier@adobe.com
Date: 04 Sep 2008 11:07:33
Changes:Removing 'RemoveItems' since it's currently not leveraged by States code-gen and nobody is using it as an override in other contexts.
QA: No
| ... | ...@@ -80,7 +80,6 @@ | |
| 80 | 80 | |
| 81 | 81 | <!-- states --> |
| 82 | 82 | <component id="AddItems" class="flex.states.AddItems"/> |
| 83 | <component id="RemoveItems" class="flex.states.RemoveItems"/> | |
| 84 | 83 | |
| 85 | 84 | <!-- effects --> |
| 86 | 85 | <component id="AddAction" class="flex.effects.AddAction"/> |
| ... | ...@@ -1,306 +0,0 @@ | |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // | |
| 3 | // ADOBE SYSTEMS INCORPORATED | |
| 4 | // Copyright 2008 Adobe Systems Incorporated | |
| 5 | // All Rights Reserved. | |
| 6 | // | |
| 7 | // NOTICE: Adobe permits you to use, modify, and distribute this file | |
| 8 | // in accordance with the terms of the license agreement accompanying it. | |
| 9 | // | |
| 10 | //////////////////////////////////////////////////////////////////////////////// | |
| 11 | ||
| 12 | package flex.states | |
| 13 | { | |
| 14 | ||
| 15 | import flash.display.DisplayObject; | |
| 16 | import flex.component.ItemsComponent; | |
| 17 | import flash.utils.Dictionary; | |
| 18 | import flex.core.Group; | |
| 19 | import mx.core.Container; | |
| 20 | import mx.core.UIComponent; | |
| 21 | import mx.states.IOverride; | |
| 22 | import mx.states.OverrideBase; | |
| 23 | ||
| 24 | /** | |
| 25 | * Documentation is not currently available. | |
| 26 | */ | |
| 27 | public class RemoveItems extends OverrideBase implements IOverride | |
| 28 | { | |
| 29 | include "../core/Version.as"; | |
| 30 | ||
| 31 | //-------------------------------------------------------------------------- | |
| 32 | // | |
| 33 | // Constructor | |
| 34 | // | |
| 35 | //-------------------------------------------------------------------------- | |
| 36 | ||
| 37 | /** | |
| 38 | * Constructor. | |
| 39 | */ | |
| 40 | public function RemoveItems() | |
| 41 | { | |
| 42 | super(); | |
| 43 | } | |
| 44 | ||
| 45 | //-------------------------------------------------------------------------- | |
| 46 | // | |
| 47 | // Variables | |
| 48 | // | |
| 49 | //-------------------------------------------------------------------------- | |
| 50 | ||
| 51 | /** | |
| 52 | * @private | |
| 53 | */ | |
| 54 | private var indexMap:Dictionary; | |
| 55 | ||
| 56 | //-------------------------------------------------------------------------- | |
| 57 | // | |
| 58 | // Properties | |
| 59 | // | |
| 60 | //-------------------------------------------------------------------------- | |
| 61 | ||
| 62 | /** | |
| 63 | * @private | |
| 64 | */ | |
| 65 | private var removed:Boolean = false; | |
| 66 | ||
| 67 | //---------------------------------- | |
| 68 | // destination | |
| 69 | //---------------------------------- | |
| 70 | ||
| 71 | [Inspectable(category="General")] | |
| 72 | ||
| 73 | /** | |
| 74 | * The parent of the items to remove. | |
| 75 | */ | |
| 76 | public var destination:Object; | |
| 77 | ||
| 78 | //---------------------------------- | |
| 79 | // items | |
| 80 | //---------------------------------- | |
| 81 | ||
| 82 | [Inspectable(category="General")] | |
| 83 | ||
| 84 | /** | |
| 85 | * The items to remove. | |
| 86 | */ | |
| 87 | public var items:*; | |
| 88 | ||
| 89 | //---------------------------------- | |
| 90 | // propertyName | |
| 91 | //---------------------------------- | |
| 92 | ||
| 93 | [Inspectable(category="General")] | |
| 94 | ||
| 95 | /** | |
| 96 | * The name of the property. | |
| 97 | */ | |
| 98 | public var propertyName:String; | |
| 99 | ||
| 100 | //------------------------------------ | |
| 101 | // isStyle | |
| 102 | //------------------------------------ | |
| 103 | ||
| 104 | [Inspectable(category="General")] | |
| 105 | ||
| 106 | /** | |
| 107 | * Denotes whether or not the collection represented by the | |
| 108 | * target property is a style. | |
| 109 | * | |
| 110 | * @default false | |
| 111 | */ | |
| 112 | public var isStyle:Boolean = false; | |
| 113 | ||
| 114 | //-------------------------------------------------------------------------- | |
| 115 | // | |
| 116 | // Methods | |
| 117 | // | |
| 118 | //-------------------------------------------------------------------------- | |
| 119 | ||
| 120 | /** | |
| 121 | * IOverride interface method; this class implements it as an empty method. | |
| 122 | * | |
| 123 | * @copy IOverride#initialize() | |
| 124 | */ | |
| 125 | public function initialize():void | |
| 126 | { | |
| 127 | } | |
| 128 | ||
| 129 | /** | |
| 130 | * @inheritDoc | |
| 131 | */ | |
| 132 | public function apply(parent:UIComponent):void | |
| 133 | { | |
| 134 | var dest:* = destination = getOverrideContext(destination, parent); | |
| 135 | var localItems:Array; | |
| 136 | var i:int; | |
| 137 | var item:Object; | |
| 138 | ||
| 139 | if (items is Array) | |
| 140 | localItems = items; | |
| 141 | else | |
| 142 | localItems = [items]; | |
| 143 | ||
| 144 | indexMap = new Dictionary(true); | |
| 145 | ||
| 146 | if (propertyName == null && (dest is Group || dest is ItemsComponent)) | |
| 147 | { | |
| 148 | for (i = 0; i < localItems.length; i++) | |
| 149 | { | |
| 150 | item = getItemObject(parent, localItems[i]); | |
| 151 | indexMap[localItems[i]] = dest.getItemIndex(item); | |
| 152 | } | |
| 153 | ||
| 154 | for (i = 0; i < localItems.length; i++) | |
| 155 | { | |
| 156 | item = getItemObject(parent, localItems[i]); | |
| 157 | dest.removeItem(item); | |
| 158 | } | |
| 159 | } | |
| 160 | else if (propertyName == null && dest is Container) | |
| 161 | { | |
| 162 | var destCont:Container = dest as Container; | |
| 163 | ||
| 164 | for (i = 0; i < localItems.length; i++) | |
| 165 | { | |
| 166 | item = getItemObject(parent, localItems[i]); | |
| 167 | indexMap[localItems[i]] = destCont.getChildIndex(localItems[i] as DisplayObject); | |
| 168 | } | |
| 169 | ||
| 170 | for (i = 0; i < localItems.length; i++) | |
| 171 | { | |
| 172 | item = getItemObject(parent, localItems[i]); | |
| 173 | destCont.removeChild(localItems[i] as DisplayObject); | |
| 174 | } | |
| 175 | } | |
| 176 | else | |
| 177 | { | |
| 178 | var destArray:Array = isStyle ? dest.getStyle(propertyName) : dest[propertyName]; | |
| 179 | ||
| 180 | for (i = 0; i < localItems.length; i++) | |
| 181 | { | |
| 182 | indexMap[localItems[i]] = destArray.indexOf(localItems[i]); | |
| 183 | } | |
| 184 | ||
| 185 | if (localItems.length != destArray.length) | |
| 186 | { | |
| 187 | for (i = 0; i < localItems.length; i++) | |
| 188 | { | |
| 189 | destArray.splice(destArray.indexOf(localItems[i]), 1); | |
| 190 | } | |
| 191 | ||
| 192 | assignArray(dest, propertyName, destArray); | |
| 193 | } | |
| 194 | else | |
| 195 | { | |
| 196 | // For destinations like ArrayCollection we don't want to | |
| 197 | // affect the array in-place in some cases, as ListCollectionView a | |
| 198 | // attempts to compare the "before" and "after" state of the array | |
| 199 | assignArray(dest, propertyName, new Array()); | |
| 200 | } | |
| 201 | } | |
| 202 | ||
| 203 | removed = true; | |
| 204 | } | |
| 205 | ||
| 206 | /** | |
| 207 | * @inheritDoc | |
| 208 | */ | |
| 209 | public function remove(parent:UIComponent):void | |
| 210 | { | |
| 211 | var dest:* = destination = getOverrideContext(destination, parent); | |
| 212 | var localItems:Array; | |
| 213 | var i:int; | |
| 214 | var item:Object; | |
| 215 | ||
| 216 | if (!removed) | |
| 217 | return; | |
| 218 | ||
| 219 | if (items is Array) | |
| 220 | localItems = items; | |
| 221 | else | |
| 222 | localItems = [items]; | |
| 223 | ||
| 224 | // Sort the items by their index | |
| 225 | localItems.sort(compareIndex); | |
| 226 | ||
| 227 | if (propertyName == null && (dest is Group || dest is ItemsComponent)) | |
| 228 | { | |
| 229 | for (i = 0; i < localItems.length; i++) | |
| 230 | { | |
| 231 | item = getItemObject(parent, localItems[i]); | |
| 232 | dest.addItemAt(item, indexMap[localItems[i]]); | |
| 233 | } | |
| 234 | } | |
| 235 | else if (propertyName == null && dest is Container) | |
| 236 | { | |
| 237 | var destCont:Container = dest as Container; | |
| 238 | ||
| 239 | for (i = 0; i < localItems.length; i++) | |
| 240 | { | |
| 241 | item = getItemObject(parent, localItems[i]); | |
| 242 | destCont.addChildAt(item as DisplayObject, indexMap[localItems[i]]); | |
| 243 | } | |
| 244 | } | |
| 245 | else | |
| 246 | { | |
| 247 | var destArray:Array = isStyle ? dest.getStyle(propertyName) : dest[propertyName]; | |
| 248 | ||
| 249 | for (i = 0; i < localItems.length; i++) | |
| 250 | { | |
| 251 | item = getItemObject(parent, localItems[i]); | |
| 252 | destArray.splice(indexMap[localItems[i]], 0, item); | |
| 253 | } | |
| 254 | ||
| 255 | assignArray(dest, propertyName, new Array()); | |
| 256 | } | |
| 257 | ||
| 258 | removed = false; | |
| 259 | indexMap = null; | |
| 260 | } | |
| 261 | ||
| 262 | /** | |
| 263 | * @private | |
| 264 | */ | |
| 265 | protected function getItemObject(parent:UIComponent, item:Object):Object | |
| 266 | { | |
| 267 | // !!! This won't work if the item is a String object (ie an element of an array of Strings) | |
| 268 | if (item is String) | |
| 269 | return parent.parentDocument[item]; | |
| 270 | ||
| 271 | return item; | |
| 272 | } | |
| 273 | ||
| 274 | /** | |
| 275 | * @private | |
| 276 | */ | |
| 277 | private function compareIndex(a:*, b:*):int | |
| 278 | { | |
| 279 | var index1:int = indexMap[a]; | |
| 280 | var index2:int = indexMap[b]; | |
| 281 | ||
| 282 | if (index1 < index2) | |
| 283 | return -1; | |
| 284 | ||
| 285 | return 1; | |
| 286 | } | |
| 287 | ||
| 288 | /** | |
| 289 | * @private | |
| 290 | */ | |
| 291 | protected function assignArray(dest:Object, propertyName:String, value:Array):void | |
| 292 | { | |
| 293 | if (isStyle) | |
| 294 | { | |
| 295 | dest.setStyle(propertyName, value); | |
| 296 | dest.styleChanged(propertyName); | |
| 297 | dest.notifyStyleChangeInChildren(propertyName, true); | |
| 298 | } | |
| 299 | else | |
| 300 | { | |
| 301 | dest[propertyName] = value; | |
| 302 | } | |
| 303 | } | |
| 304 | } | |
| 305 | ||
| 306 | } |
| ... | ...@@ -75,7 +75,6 @@ | |
| 75 | 75 | <component id="RadioButton" class="flex.component.RadioButton"/> |
| 76 | 76 | <component id="Range" class="flex.component.Range"/> |
| 77 | 77 | <component id="Rect" class="flex.graphics.Rect"/> |
| 78 | <component id="RemoveItems" class="flex.states.RemoveItems"/> | |
| 79 | 78 | <component id="ScrollBar" class="flex.component.ScrollBar"/> |
| 80 | 79 | <component id="Scroller" class="flex.component.Scroller"/> |
| 81 | 80 | <component id="Selector" class="flex.component.Selector"/> |
| ... | ...@@ -48,7 +48,6 @@ | |
| 48 | 48 | |
| 49 | 49 | <!-- states --> |
| 50 | 50 | <component id="AddItems" class="flex.states.AddItems" /> |
| 51 | <component id="RemoveItems" class="flex.states.RemoveItems" /> | |
| 52 | 51 | |
| 53 | 52 | <!-- flex4 graphics --> |
| 54 | 53 | <component id="BitmapGraphic" class="flex.graphics.BitmapGraphic"/> |