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