tag viewer as either SuperTabNavigator (for Dave's netbook) or Accordion (for my...
[potlatch2.git] / net / systemeD / potlatch2 / TagViewer.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:VBox
3         xmlns:mx="http://www.adobe.com/2006/mxml"
4         xmlns:flexlib="flexlib.containers.*"
5     backgroundColor="white"
6     initialize="loadFeatures()">
7
8 <mx:ViewStack id="sidebar" width="100%" height="100%" creationPolicy="all">
9   <mx:VBox id="dndPanel" width="100%" height="100%">
10     <!-- FIXME the panel text is repeated below for mouseOut -->
11     <mx:Text id="dndPanelText" text="Drag and Drop Points of Interest" />
12     <mx:TileList id="poiGrid" dataProvider="{MapFeatures.getInstance().pois}" width="100%" height="100%">
13       <mx:itemRenderer>
14         <mx:Component>
15           <mx:VBox mouseOver="parentDocument.dndPanelText.text = data.name"
16                    mouseOut="parentDocument.dndPanelText.text = 'Drag and Drop Points of Interest'">
17             <mx:Script><![CDATA[
18               import mx.events.DragEvent;
19               import mx.managers.DragManager;
20               import mx.core.DragSource;
21                   
22               private function dragPOI(event:MouseEvent, tags:Array):void {
23                   // Get the drag initiator component from the event object.
24                   var dragInitiator:Image = event.currentTarget as Image;
25                   var dragSource:DragSource = new DragSource();
26                   dragSource.addData(tags, 'tags');
27                   
28                   var dragProxy:Image = new Image();
29                   dragProxy.source = dragInitiator.source;
30                   dragProxy.width = dragInitiator.width;   // must set width and height explicitly
31                   dragProxy.height = dragInitiator.height; // for non-embedded images
32                   DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
33               }
34             ]]></mx:Script>
35             <mx:Image id="foo" source="{data.image}" height="25" width="25" mouseMove="dragPOI(event, data.tags)" toolTip="{data.name}" />
36           </mx:VBox>
37         </mx:Component>
38       </mx:itemRenderer>
39     </mx:TileList>
40   </mx:VBox>
41   
42   <mx:VBox id="tagsPanel" width="100%" height="100%" creationPolicy="auto">
43     <mx:ViewStack id="stack" width="100%" height="100%">
44       <mx:VBox width="100%" height="100%" label="Simple" id="editorContainer" creationComplete="initEditorStackUIs()">
45         <mx:HBox borderStyle="inset" verticalAlign="middle" width="100%" paddingLeft="3" id="iconContainer">
46             <mx:Image id="iconImage"/>
47             <mx:VBox width="100%" verticalGap="1">
48               <mx:PopUpButton id="popupChange" creationComplete="initFeatureBox()" openAlways="true" width="100%"/>
49               <mx:Text condenseWhite="true" width="100%" id="iconText"/>
50             </mx:VBox>
51             <mx:LinkButton label="?" click="openDescription()" id="helpLabel"/>
52         </mx:HBox>
53       </mx:VBox>
54       <mx:VBox width="100%" height="100%" label="Advanced" initialize="checkAdvanced()" verticalGap="1">
55         <mx:Label id="advancedID">
56           <mx:htmlText><![CDATA[<i>No Selection</i>]]></mx:htmlText>
57         </mx:Label>
58
59         <mx:DataGrid editable="true" width="100%" height="75%" id="advancedTagGrid">
60                 <mx:columns>
61                     <mx:DataGridColumn editable="true" dataField="key" headerText="Key"/>
62                     <mx:DataGridColumn editable="true" dataField="value" headerText="Value"/>
63                 </mx:columns>
64         </mx:DataGrid>
65
66         <mx:HBox horizontalAlign="right" width="100%">
67           <mx:LinkButton label="Delete" click="removeTag()" enabled="{advancedTagGrid.selectedItem != null? true : false}"/>
68           <mx:LinkButton label="Add" click="addNewTag()"/>
69         </mx:HBox>
70         
71         <mx:DataGrid editable="true" width="100%" height="25%" id="relationsGrid"
72             doubleClickEnabled="true"
73             itemDoubleClick="editRelation(relationsGrid.selectedItem.id)">
74             <mx:columns>
75                 <mx:DataGridColumn editable="false" dataField="description" headerText="Relation"/>
76                 <mx:DataGridColumn editable="false" dataField="id_idx" headerText="ID"/>
77                 <mx:DataGridColumn editable="true" dataField="role" headerText="Role"/>
78             </mx:columns>
79         </mx:DataGrid>
80
81         <mx:HBox horizontalAlign="right" width="100%">
82           <mx:LinkButton label="Remove from" click="removeFromRelation(relationsGrid.selectedItem.id, relationsGrid.selectedItem.index)" 
83                           enabled="{relationsGrid.selectedItem != null? true : false}"/>
84           <mx:LinkButton label="Add to" click="addToRelation()"/>
85         </mx:HBox>
86
87       </mx:VBox>
88
89       <mx:VBox width="100%" height="100%" label="Members" id="membersVBox" initialize="checkMembers()" verticalGap="1">
90         <mx:Label id="membersText" text="Relation Members"/>
91         <mx:DataGrid editable="true" width="100%" height="100%" id="membersGrid"
92                       dragEnabled="true" dragMoveEnabled="true" dropEnabled="true">
93           <mx:columns>
94             <mx:DataGridColumn editable="false" dataField="type" headerText="Type"/>
95             <mx:DataGridColumn editable="false" dataField="id" headerText="ID"/>
96             <mx:DataGridColumn editable="true" dataField="role" headerText="Role"/>
97           </mx:columns>
98         </mx:DataGrid>
99       </mx:VBox>
100       
101       </mx:ViewStack>
102
103           <mx:HBox width="100%">
104                 <mx:LinkBar dataProvider="{stack}"/>
105                 <mx:Spacer width="100%"/>
106                 <mx:LinkButton 
107                         icon="@Embed('../../../embedded/view_tabbed.png')"
108                         disabledIcon="@Embed('../../../embedded/view_tabbed_disabled.png')"
109                         click="setEditorStackUI(true)" id="tabNavigatorLabel" paddingTop="6" 
110                         enabled="{editorStack is Accordion &amp;&amp; stack.selectedIndex==0}" />
111                 <mx:LinkButton
112                         icon="@Embed('../../../embedded/view_accordion.png')" 
113                         disabledIcon="@Embed('../../../embedded/view_accordion_disabled.png')"
114                         click="setEditorStackUI(false)" id="accordionLabel" paddingTop="6"
115                         enabled="{editorStack is SuperTabNavigator &amp;&amp; stack.selectedIndex==0}" />
116           </mx:HBox>
117   </mx:VBox>
118 </mx:ViewStack>
119
120   <mx:Script><![CDATA[
121       import net.systemeD.halcyon.connection.*;
122       import net.systemeD.potlatch2.mapfeatures.*;
123
124       import mx.collections.*;
125       import mx.containers.*;
126       import mx.events.*;
127       import mx.core.*;
128       import mx.managers.PopUpManager;
129       import flash.geom.Point;
130       import flash.net.*;
131       import mx.events.DragEvent;
132       import mx.managers.DragManager;
133       import mx.core.DragSource;
134       import flexlib.containers.SuperTabNavigator;
135
136       private var editorStackTabNavigator:SuperTabNavigator;
137       private var editorStackAccordion:Accordion;
138       [Bindable] private var editorStack:Container;
139
140       private var mapFeatures:MapFeatures;
141       private var selectedEntity:Entity;
142       private var tagDataProvider:ArrayCollection;
143       private var tw:CategorySelector = null;
144       private var feature:Feature = null;
145
146       public function setEntity(entity:Entity):void {
147           UIComponent.suspendBackgroundProcessing();
148           if ( selectedEntity != entity ) {
149               if ( selectedEntity != null )
150                   selectedEntity.removeEventListener(Connection.TAG_CHANGED, tagChanged);
151               selectedEntity = entity;
152               if ( selectedEntity != null )
153                   selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged);
154           }
155
156           if ( advancedID != null )
157               setupAdvanced(entity);
158           if (entity is Relation) {
159               stack.addChild(membersVBox);
160           }
161           refreshFeatureIcon(); 
162           if (selectedEntity == null) {
163             sidebar.selectedChild = dndPanel;
164           } else {
165             initialiseEditors();
166             sidebar.selectedChild = tagsPanel;
167           }
168           UIComponent.resumeBackgroundProcessing();
169       }
170
171       private function refreshFeatureIcon():void {
172           var oldFeature:Feature = feature;
173           feature = selectedEntity == null ? null : mapFeatures.findMatchingFeature(selectedEntity);
174           if ( feature != oldFeature ) {
175               if ( oldFeature != null )
176                   oldFeature.removeEventListener("imageChanged", featureImageChanged);
177               if ( feature != null )
178                   feature.addEventListener("imageChanged", featureImageChanged);
179           }
180
181           if ( feature != null ) {
182               setFeatureIcon(selectedEntity, feature);
183           } else {
184               blankFeatureIcon(selectedEntity);
185           }
186       }
187
188       private function featureImageChanged(event:Event):void {
189           setFeatureIcon(selectedEntity, feature);
190       }
191       
192       private function setFeatureIcon(entity:Entity, feature:Feature):void {
193           //blankFeatureIcon(entity);
194           
195           iconImage.source = feature.image;
196
197           var txt:String = feature.htmlDetails(entity);
198           iconText.htmlText = txt;
199           popupChange.label = feature.name;
200           setLimitTypes(entity);
201           tw.setSelectedFeature(feature);
202           helpLabel.visible = feature.hasHelpURL();
203       }
204       
205       private function setLimitTypes(entity:Entity):void {
206           var type:String = null;
207           if ( entity is Node )
208               type = "point";
209           else if ( entity is Way )
210               type = Way(entity).isArea() ? "area" : "line";
211           else if ( entity is Relation )
212               type = "relation";
213           tw.setLimitTypes(type);
214       }
215
216       private function blankFeatureIcon(entity:Entity):void {
217           iconImage.source = null;
218           popupChange.label = "unknown";
219           setLimitTypes(entity);
220                   if (entity == null) { 
221                         iconText.htmlText = "<i>Nothing selected</i>";
222             tw.setNoSelectedFeature();
223                   } else if (entity.hasTags()) {
224                         iconText.htmlText = "<b>Not recognised</b><br/>Try looking at the tags under the advanced properties";
225             tw.setSelectedFeature(null);
226                   } else {
227                         iconText.htmlText = "<b>No tags set</b><br/>Use the menu above to say what this "+entity.getType()+" is";
228             tw.setSelectedFeature(null);
229           }
230           helpLabel.visible = false;
231       }
232
233       private var tabComponents:Object = {};
234       
235       private function initialiseEditors():void {
236           editorStack.removeAllChildren();
237           if ( selectedEntity == null || feature == null )
238               return;
239           
240           var editorBox:VBox = createEditorBox();
241           editorBox.label = "Basic";
242           editorStack.addChild(editorBox);
243           
244           var tabs:Object = {};
245           tabComponents = {};
246           
247           for each (var factory:EditorFactory in feature.editors) {
248               if ( factory.presence.isEditorPresent(factory, selectedEntity, null) ) {
249                   var editor:DisplayObject = factory.createEditorInstance(selectedEntity);
250                   if ( editor != null )
251                       editorBox.addChild(editor);
252               }
253               var category:String = factory.category;
254               var tab:VBox = tabs[category];
255               if ( tab == null ) {
256                   tab = createEditorBox();
257                   tab.label = category;
258                   editorStack.addChild(tab);
259                   tabs[category] = tab;
260                   tabComponents[tab] = [];
261               }
262               var catEditor:DisplayObject = factory.createEditorInstance(selectedEntity);
263               if ( catEditor != null )
264                   tabComponents[tab].push(catEditor);
265               //    tab.addChild(catEditor);
266           }
267       }
268       
269       private function createEditorBox():VBox {
270           var box:VBox = new VBox();
271           box.percentWidth = 100;
272           box.percentHeight = 100;
273           return box;
274       }
275
276       private function ensureEditorsPopulated(tab:VBox):void {
277           var components:Array = tabComponents[tab];
278           if ( components == null || tab == null || tab.numChildren >= components.length )
279               return;
280           for each (var component:DisplayObject in components ) {
281               tab.addChild(component);
282           }
283       }
284       
285         private function initEditorStackUIs():void {
286                 editorStackTabNavigator = new SuperTabNavigator();
287                 editorStackTabNavigator.allowTabSqueezing=false;
288                 editorStackTabNavigator.minTabWidth=10;
289                 editorStackTabNavigator.closePolicy="close_never";
290                 editorStackTabNavigator.scrollSpeed=20;
291                 editorStackTabNavigator.creationPolicy="auto";
292                 editorStackTabNavigator.percentWidth=100;
293                 editorStackTabNavigator.percentHeight=100;
294                 editorStackTabNavigator.paddingLeft=1;
295                 editorStackTabNavigator.paddingRight=1;
296
297                 editorStackAccordion = new Accordion();
298                 editorStackAccordion.percentWidth=100;
299                 editorStackAccordion.percentHeight=100;
300                 editorStackAccordion.creationPolicy="auto";
301
302                 setEditorStackUI(true);
303         }
304
305         private function setEditorStackUI(isTabbed:Boolean):void {
306                 var children:Array=[]; var i:uint;
307
308                 if (editorStack) {
309                         // blank existing component
310                         editorStack.removeEventListener("change",editorStackUIChange);
311                         editorStack.removeEventListener("updateComplete",editorStackUIUpdate);
312                         editorStack.removeAllChildren();
313                         editorContainer.removeChildAt(1);
314                 }
315
316                 // replace with new component
317                 editorStack = (isTabbed ? editorStackTabNavigator : editorStackAccordion) as Container;
318                 editorContainer.addChild(editorStack);
319
320                 // re-add children and listeners
321                 initialiseEditors();
322                 editorStack.addEventListener("change",editorStackUIChange);
323                 editorStack.addEventListener("updateComplete",editorStackUIUpdate);
324         }
325         
326         private function editorStackUIChange(event:Event):void {
327                 ensureEditorsPopulated(IndexChangedEvent(event).relatedObject as VBox);
328         }
329
330         private function editorStackUIUpdate(event:Event):void {
331                 if (editorStack is SuperTabNavigator) {
332                         var e:SuperTabNavigator = editorStack as SuperTabNavigator;
333                         if (e.selectedIndex<0) { return; }
334                         for (var i:uint=0; i<e.numChildren; i++) {
335                                 e.getTabAt(i).selected=(i==e.selectedIndex);
336                         }
337                 }
338         }
339
340
341       private function checkAdvanced():void {
342           if ( selectedEntity != null )
343              setupAdvanced(selectedEntity);
344       }
345
346       private var listeningToRelations:Array = [];
347       
348       private function setupAdvanced(entity:Entity):void {
349           if ( tagDataProvider == null ) {
350               tagDataProvider = new ArrayCollection();
351               advancedTagGrid.dataProvider = tagDataProvider;
352           }
353
354           tagDataProvider.removeAll();
355           
356           if ( entity == null ) {
357               advancedID.htmlText = "";
358           } else {
359               var entityText:String = "xx";
360               if ( entity is Node ) entityText = "Node";
361               else if ( entity is Way ) entityText = "Way";
362               else if ( entity is Relation ) entityText = "Relation";
363               advancedID.htmlText = entityText+": <b>"+entity.id+"</b>";
364
365               var tags:Array = entity.getTagArray();
366               tags.sortOn("key");
367               for each(var tag:Tag in tags)
368                   tagDataProvider.addItem(tag);
369           }
370                     
371           removeRelationListeners();
372           if ( selectedEntity != null ) {
373               selectedEntity.removeEventListener(Connection.ADDED_TO_RELATION, addedToRelation);
374               selectedEntity.removeEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation);
375           }
376           
377           if ( entity == null ) {
378               relationsGrid.dataProvider = null;
379           } else {
380               resetRelationsGrid(entity);
381               entity.addEventListener(Connection.ADDED_TO_RELATION, addedToRelation);
382               entity.addEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation);
383           }
384       }
385       
386       private function addedToRelation(event:RelationMemberEvent):void {
387          resetRelationsGrid(selectedEntity);
388       }
389
390       private function removedFromRelation(event:RelationMemberEvent):void {
391          resetRelationsGrid(selectedEntity);
392       }
393
394       private function removeRelationListeners():void {
395           for each( var rel:Relation in listeningToRelations ) {
396               rel.removeEventListener(Connection.TAG_CHANGED, relationTagChanged);
397               rel.removeEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
398               rel.removeEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
399           }
400           listeningToRelations = [];
401           relationsGrid.removeEventListener(DataGridEvent.ITEM_EDIT_END, relationRoleChanged);
402       }
403             
404       private function resetRelationsGrid(entity:Entity):void {
405           removeRelationListeners();
406           var relations:Array = [];
407           for each( var rel:Relation in entity.parentRelations ) {
408               for each( var memberIndex:int in rel.findEntityMemberIndexes(entity)) {
409                   var props:Object = {};
410                   props["relation"] = rel;
411                   props["id"] = rel.id;
412                   props["index"] = memberIndex;
413                   props["role"] = rel.getMember(memberIndex).role;
414                   props["description"] = rel.getDescription();
415                   props["id_idx"] = rel.id + "/"+memberIndex;
416
417                   relations.push(props);
418               }
419               
420               rel.addEventListener(Connection.TAG_CHANGED, relationTagChanged);
421               rel.addEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
422               rel.addEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
423               listeningToRelations.push(rel);
424           }
425           relationsGrid.dataProvider = relations;
426           relationsGrid.addEventListener(DataGridEvent.ITEM_EDIT_END, relationRoleChanged, false, -100);
427       }
428       
429       private function relationRoleChanged(event:DataGridEvent):void {
430                 if (event.dataField != 'role') { return; }      // shouldn't really happen
431
432                 var relations:Array=event.currentTarget.dataProvider.toArray();
433                 var props:Object=relations[event.rowIndex];
434
435                 var relation:Relation=props['relation'];
436                 var index:uint=props['index'];
437                 var newRole:String=event.itemRenderer.data['role'];
438
439                 relation.setMember(index, new RelationMember(selectedEntity,newRole));
440       }
441
442       private function relationTagChanged(event:TagEvent):void {
443           resetRelationsGrid(selectedEntity);
444       }
445
446       private function entityRelationMemberChanged(event:RelationMemberEvent):void {
447           resetRelationsGrid(selectedEntity);
448       }
449       
450       private function checkMembers():void {
451           if (selectedEntity is Relation) {
452             setupMembers(selectedEntity as Relation);
453           }
454       }
455       
456       private function setupMembers(rel:Relation):void {
457           var members:Array = [];
458           for (var i:int=0 ; i<rel.length; i++) {
459             var props:Object = {};
460             var member:RelationMember = rel.getMember(i);
461             props["id"] = member.entity.id;
462             props["type"] = member.entity.getType();
463             props["role"] = member.role;
464             
465             members.push(props);
466           }
467           membersGrid.dataProvider = members;
468           membersGrid.dataProvider.addEventListener('collectionChange', membersChange); 
469       }
470       
471       private function membersChange(event:Event):void {
472           // Dropping all the members and re-adding them isn't exactly optimal
473           // but is at least robust for any kind of change.
474           // Figuring out a better way is someone else's FIXME
475           
476           var conn:Connection = Connection.getConnectionInstance();
477           var rel:Relation = selectedEntity as Relation
478           
479           // drop members
480           trace("Dropping "+rel.length+" members");
481           for (var i:int=rel.length-1 ; i>=0; i--) {
482             rel.removeMemberByIndex(i);
483           }
484           
485           // add members in new order
486           for each(var memberObject:Object in membersGrid.dataProvider) {
487             var e:Entity;
488             var id:Number = memberObject.id;
489             if(memberObject.type == 'node') {
490               e = conn.getNode(id);
491             } else if (memberObject.type == 'way') {
492               e = conn.getWay(id);
493             } else if (memberObject.type == 'relation') {
494               e = conn.getRelation(id);
495             }
496             rel.appendMember(new RelationMember(e, memberObject.role));
497             trace("added member "+memberObject.type+" "+id+" in role "+memberObject.role);
498           }
499           trace("complete: relation "+rel.id+" now has "+rel.length+" members");
500       }
501       
502       private function editRelation(id:Number):void {
503           var panel:RelationEditorPanel = RelationEditorPanel(
504               PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
505           panel.setRelation(Connection.getConnectionInstance().getRelation(id));
506           PopUpManager.centerPopUp(panel);
507       }
508       
509       private function tagChanged(event:TagEvent):void {
510           refreshFeatureIcon();
511           
512           if ( tagDataProvider != null ) {
513               // check to see if the key is already in our list
514               var exists:Boolean = false;
515               var tag:Tag = null;
516               var i:uint;
517               for ( i = 0; i < tagDataProvider.length && !exists; i++ ) {
518                   tag = Tag(tagDataProvider.getItemAt(i));
519                   exists = tag.key == event.key;
520               }
521               if ( !exists ) {
522                   tag = new Tag(selectedEntity, event.key, event.newValue);
523                   tagDataProvider.addItem(tag);
524                   tagDataProvider.refresh();
525               } else {
526                   if ( event.newValue == null ) {
527                       tagDataProvider.removeItemAt(i-1);
528                       tagDataProvider.refresh();
529                   } else {
530                       tagDataProvider.itemUpdated(tag, "value");
531                   }
532               }
533           }
534       }
535
536       public function loadFeatures():void {
537           mapFeatures = MapFeatures.getInstance();
538           stack.removeChild(membersVBox); // remove by default, will be added if relation
539       }
540
541       public function openDescription():void {
542           trace("open description here");
543           if ( feature != null && feature.hasHelpURL() )
544               navigateToURL(new URLRequest(feature.helpURL), "potlatch_help");
545       }
546
547       public function addNewTag():void {
548           var newKey:String = "(new tag)";
549           var newTag:Tag = new Tag(selectedEntity, newKey, "(new value)");
550           tagDataProvider.addItem(newTag);
551           advancedTagGrid.editedItemPosition = {rowIndex: tagDataProvider.getItemIndex(newTag), columnIndex: 0};
552       }
553
554       public function removeTag():void {
555           var k:String = advancedTagGrid.selectedItem.key;
556           selectedEntity.setTag(k, null, MainUndoStack.getGlobalStack().addAction);
557       }
558       
559       public function addToRelation():void {
560           new RelationSelectPanel().init(selectedEntity,new Object());
561       }
562       
563       public function removeFromRelation(id:Number, index:int):void {
564           Connection.getConnectionInstance().getRelation(id).removeMemberByIndex(index);
565       }
566       
567       public function initFeatureBox():void {
568           tw = new CategorySelector();
569           tw.addEventListener("selectedType", changeFeatureType);
570           popupChange.popUp = tw;
571       }
572       
573       public function changeFeatureType(event:Event):void {
574           if ( selectedEntity == null )
575               return;
576
577           UIComponent.suspendBackgroundProcessing();
578           var newFeature:Feature = tw.selectedType;
579           var undoStack:Function = MainUndoStack.getGlobalStack().addAction;
580           var action:CompositeUndoableAction = new CompositeUndoableAction(
581                   "Set "+selectedEntity.getType()+" "+selectedEntity.id+" to "+newFeature.name);
582                   selectedEntity.suspend();
583
584           // remove tags from the current feature
585           if ( feature != null ) {
586               for each( var oldtag:Object in feature.tags ) {
587                   selectedEntity.setTag(oldtag["k"], null, action.push);
588               }
589           }
590           
591           // set tags for new feature
592           if ( newFeature != null ) {
593               for each( var newtag:Object in newFeature.tags ) {
594                   selectedEntity.setTag(newtag["k"], newtag["v"], action.push);
595               }
596           }
597           
598                   selectedEntity.resume();
599           undoStack(action);
600           popupChange.close();
601           initialiseEditors();
602           UIComponent.resumeBackgroundProcessing();
603       }
604       
605       private function dragPOI(event:MouseEvent, tags:Array):void {
606           // Get the drag initiator component from the event object.
607           var dragInitiator:Image = event.currentTarget as Image;
608           var dragSource:DragSource = new DragSource();
609           dragSource.addData(tags, 'tags');
610           
611           var dragProxy:Image = new Image();
612           dragProxy.source = event.currentTarget.source;
613           
614           DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
615       }
616   ]]></mx:Script>
617 </mx:VBox>
618