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