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