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