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