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