Create a separate BugPanel, and move the panels into a subfolder - perhaps do this...
[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()">
53         <mx:HBox width="100%" id="iconContainer" styleName="featureSelector">
54             <mx:Image id="iconImage"/>
55             <mx:VBox width="100%" verticalGap="1">
56               <mx:PopUpButton id="popupChange" creationComplete="initFeatureBox()" openAlways="true" width="100%"/>
57               <mx:Text condenseWhite="true" width="100%" id="iconText"/>
58             </mx:VBox>
59             <mx:LinkButton label="?" click="openDescription()" id="helpLabel" styleName="helpInfo"/>
60         </mx:HBox>
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/>Use the menu above to say 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 = "editorContainer";
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
334                 editorStackAccordion = new Accordion();
335                 editorStackAccordion.percentWidth=100;
336                 editorStackAccordion.percentHeight=100;
337                 editorStackAccordion.creationPolicy="auto";
338
339                 setEditorStackUI(true);
340         }
341
342         private function setEditorStackUI(isTabbed:Boolean):void {
343                 var children:Array=[]; var i:uint;
344
345                 if (editorStack) {
346                         // blank existing component
347                         editorStack.removeEventListener("change",editorStackUIChange);
348                         editorStack.removeEventListener("updateComplete",editorStackUIUpdate);
349                         editorStack.removeAllChildren();
350                         editorContainer.removeChildAt(1);
351                 }
352
353                 // replace with new component
354                 editorStack = (isTabbed ? editorStackTabNavigator : editorStackAccordion) as Container;
355                 editorContainer.addChild(editorStack);
356
357                 // re-add children and listeners
358                 initialiseEditors();
359                 editorStack.addEventListener("change",editorStackUIChange);
360                 editorStack.addEventListener("updateComplete",editorStackUIUpdate);
361         }
362         
363         private function editorStackUIChange(event:Event):void {
364                 ensureEditorsPopulated(IndexChangedEvent(event).relatedObject as VBox);
365         }
366
367         private function editorStackUIUpdate(event:Event):void {
368                 if (editorStack is SuperTabNavigator) {
369                         var e:SuperTabNavigator = editorStack as SuperTabNavigator;
370                         if (e.selectedIndex<0) { return; }
371                         for (var i:uint=0; i<e.numChildren; i++) {
372                                 e.getTabAt(i).selected=(i==e.selectedIndex);
373                         }
374                 }
375         }
376
377
378         public function togglePanel():void {
379                 if (stack.selectedChild==editorContainer && selectedEntity!=null) {
380                         stack.selectedChild=advancedContainer;
381                 } else if (stack.selectedChild!=editorContainer) {
382                         stack.selectedChild=editorContainer;
383                 }
384         }
385
386       private function checkAdvanced():void {
387           if ( selectedEntity != null )
388              setupAdvanced(selectedEntity);
389       }
390
391       /**
392       * When you enter a new tag and press enter, the focus moves to the add button
393       * Adding an event listener to the button and listening for + means that you
394       * can add two consecutive tags with the same keypress. This relies on focus
395       * moving to the "add" button, though, so it's not robust to rearranging the UI.
396       */
397       private function advancedAddButtonKeyboardEvent(event:KeyboardEvent):void {
398           switch (event.keyCode) {
399             case 187:   addNewTag(); break;                          // + - add tag
400           }
401       }
402
403       private var listeningToRelations:Array = [];
404       
405       private function setupAdvanced(entity:Entity):void {
406                 advancedTagGrid.init(entity);
407         advancedAddButton.addEventListener(KeyboardEvent.KEY_DOWN, advancedAddButtonKeyboardEvent);
408
409                 if ( entity == null ) {
410                         advancedID.htmlText = "";
411                 } else {
412                         var entityText:String = "xx";
413                         if      ( entity is Node     ) entityText = "Node";
414                         else if ( entity is Way      ) entityText = "Way";
415                         else if ( entity is Relation ) entityText = "Relation";
416                         advancedID.htmlText = entityText+": <b>"+entity.id+"</b>";
417                 }
418
419                 removeRelationListeners();
420                 if ( selectedEntity != null ) {
421                         selectedEntity.removeEventListener(Connection.ADDED_TO_RELATION, addedToRelation);
422                         selectedEntity.removeEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation);
423                 }
424
425                 if ( entity == null ) {
426                         relationsGrid.dataProvider = null;
427                 } else {
428                         resetRelationsGrid(entity);
429                         entity.addEventListener(Connection.ADDED_TO_RELATION, addedToRelation);
430                         entity.addEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation);
431                 }
432       }
433
434           public function addNewTag():void {
435                 if (stack.selectedChild!=advancedContainer) { return; }
436                 advancedTagGrid.addNewTag();
437           }
438       
439       private function addedToRelation(event:RelationMemberEvent):void {
440          resetRelationsGrid(selectedEntity);
441       }
442
443       private function removedFromRelation(event:RelationMemberEvent):void {
444          resetRelationsGrid(selectedEntity);
445       }
446
447       private function removeRelationListeners():void {
448           for each( var rel:Relation in listeningToRelations ) {
449               rel.removeEventListener(Connection.TAG_CHANGED, relationTagChanged);
450               rel.removeEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
451               rel.removeEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
452           }
453           listeningToRelations = [];
454           relationsGrid.removeEventListener(DataGridEvent.ITEM_EDIT_END, relationRoleChanged);
455       }
456             
457       private function resetRelationsGrid(entity:Entity):void {
458           removeRelationListeners();
459           var relations:Array = [];
460           for each( var rel:Relation in entity.parentRelations ) {
461               for each( var memberIndex:int in rel.findEntityMemberIndexes(entity)) {
462                   var props:Object = {};
463                   props["relation"] = rel;
464                   props["id"] = rel.id;
465                   props["index"] = memberIndex;
466                   props["role"] = rel.getMember(memberIndex).role;
467                   props["description"] = rel.getDescription();
468                   props["id_idx"] = rel.id + "/"+memberIndex;
469
470                   relations.push(props);
471               }
472               
473               rel.addEventListener(Connection.TAG_CHANGED, relationTagChanged);
474               rel.addEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
475               rel.addEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
476               listeningToRelations.push(rel);
477           }
478           relationsGrid.dataProvider = relations;
479           relationsGrid.addEventListener(DataGridEvent.ITEM_EDIT_END, relationRoleChanged, false, -100);
480       }
481       
482       private function relationRoleChanged(event:DataGridEvent):void {
483                 if (event.dataField != 'role') { return; }      // shouldn't really happen
484
485                 var relations:Array=event.currentTarget.dataProvider.toArray();
486                 var props:Object=relations[event.rowIndex];
487
488                 var relation:Relation=props['relation'];
489                 var index:uint=props['index'];
490                 var newRole:String=event.itemRenderer.data['role'];
491
492                 relation.setMember(index, new RelationMember(selectedEntity,newRole));
493       }
494
495       private function relationTagChanged(event:TagEvent):void {
496           resetRelationsGrid(selectedEntity);
497       }
498
499       private function entityRelationMemberChanged(event:RelationMemberEvent):void {
500           resetRelationsGrid(selectedEntity);
501       }
502       
503       private function checkMembers():void {
504           if (selectedEntity is Relation) {
505             setupMembers(selectedEntity as Relation);
506           }
507       }
508       
509       private function setupMembers(rel:Relation):void {
510           var members:Array = [];
511           for (var i:int=0 ; i<rel.length; i++) {
512             var props:Object = {};
513             var member:RelationMember = rel.getMember(i);
514             props["id"] = member.entity.id;
515             props["type"] = member.entity.getType();
516             props["role"] = member.role;
517             
518             members.push(props);
519           }
520           membersGrid.dataProvider = members;
521           membersGrid.dataProvider.addEventListener('collectionChange', membersChange); 
522       }
523       
524       private function membersChange(event:Event):void {
525           // Dropping all the members and re-adding them isn't exactly optimal
526           // but is at least robust for any kind of change.
527           // Figuring out a better way is someone else's FIXME
528           
529           var conn:Connection = Connection.getConnectionInstance();
530           var rel:Relation = selectedEntity as Relation
531           
532           // drop members
533           for (var i:int=rel.length-1 ; i>=0; i--) {
534             rel.removeMemberByIndex(i);
535           }
536           
537           // add members in new order
538           for each(var memberObject:Object in membersGrid.dataProvider) {
539             var e:Entity;
540             var id:Number = memberObject.id;
541             if(memberObject.type == 'node') {
542               e = conn.getNode(id);
543             } else if (memberObject.type == 'way') {
544               e = conn.getWay(id);
545             } else if (memberObject.type == 'relation') {
546               e = conn.getRelation(id);
547             }
548             rel.appendMember(new RelationMember(e, memberObject.role));
549           }
550       }
551       
552       private function editRelation(id:Number):void {
553           var panel:RelationEditorPanel = RelationEditorPanel(
554               PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
555           panel.setRelation(Connection.getConnectionInstance().getRelation(id));
556           PopUpManager.centerPopUp(panel);
557       }
558       
559       private function tagChanged(event:TagEvent):void {
560           refreshFeatureIcon();
561           // if the advancedTagGrid has already been set up, it needs to be refreshed.
562           // FIXME make this better, maybe advancedTagGrid should be event listening.
563           setupAdvanced(selectedEntity);
564       }
565
566       public function loadFeatures():void {
567           mapFeatures = MapFeatures.getInstance();
568           stack.removeChild(membersVBox); // remove by default, will be added if relation
569       }
570
571       public function openDescription():void {
572           if ( feature != null && feature.hasHelpURL() )
573               navigateToURL(new URLRequest(feature.helpURL), "potlatch_help");
574       }
575
576       public function openEntityPage():void {
577           if (selectedEntity != null && selectedEntity.id >= 0) {
578               // This is slightly hard-coded, but not drastically. The ../s could be changed for string manipulation of the apiBase
579               var urlBase:String = Connection.getConnectionInstance().apiBase + '../../browse/'
580               navigateToURL(new URLRequest(urlBase+selectedEntity.getType()+'/'+selectedEntity.id), "potlatch_browse");
581           }
582       }
583
584       public function addToRelation():void {
585           new RelationSelectPanel().init(selectedEntity,new Object());
586       }
587       
588       public function removeFromRelation(id:Number, index:int):void {
589           Connection.getConnectionInstance().getRelation(id).removeMemberByIndex(index);
590       }
591       
592       public function initFeatureBox():void {
593           tw = new CategorySelector();
594           tw.addEventListener("selectedType", changeFeatureType);
595           popupChange.popUp = tw;
596       }
597       
598       public function changeFeatureType(event:Event):void {
599           if ( selectedEntity == null )
600               return;
601
602           UIComponent.suspendBackgroundProcessing();
603           var newFeature:Feature = tw.selectedType;
604           var undoStack:Function = MainUndoStack.getGlobalStack().addAction;
605           var action:CompositeUndoableAction = new CompositeUndoableAction(
606                   "Set "+selectedEntity.getType()+" "+selectedEntity.id+" to "+newFeature.name);
607                   selectedEntity.suspend();
608
609           // remove tags from the current feature
610           if ( feature != null ) {
611               for each( var oldtag:Object in feature.tags ) {
612                   selectedEntity.setTag(oldtag["k"], null, action.push);
613               }
614           }
615           
616           // set tags for new feature
617           if ( newFeature != null ) {
618               for each( var newtag:Object in newFeature.tags ) {
619                   selectedEntity.setTag(newtag["k"], newtag["v"], action.push);
620               }
621           }
622           
623                   selectedEntity.resume();
624           undoStack(action);
625           popupChange.close();
626           initialiseEditors();
627           UIComponent.resumeBackgroundProcessing();
628       }
629       
630         private function resizePOIGrid(event:Event):void {
631                 var rows:Number=event.target.dataProvider.length/event.target.columnCount;
632                 if (rows!=Math.floor(rows)) { rows=Math.floor(rows+1); }
633                 event.target.height=rows*(event.target.rowHeight+1);
634         }
635   ]]></mx:Script>
636 </mx:VBox>
637