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