Remove VectorLayer import statements from refactored files
[potlatch2.git] / net / systemeD / potlatch2 / mygpx / MyGpxDialog.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:TitleWindow
3         xmlns:mx="http://www.adobe.com/2006/mxml"
4         layout="vertical" showCloseButton="true"
5         horizontalAlign="center" title="MyGpx Files"
6         width="600" height="400"
7         verticalGap="0">
8   <mx:Script><![CDATA[
9     import mx.managers.PopUpManager;
10     import mx.events.CloseEvent;
11     import mx.core.Application;
12
13     import net.systemeD.halcyon.connection.*;
14     import net.systemeD.potlatch2.save.*;
15     import net.systemeD.halcyon.Map;
16     import net.systemeD.halcyon.Globals;
17     import net.systemeD.potlatch2.utils.Importer;
18     import net.systemeD.potlatch2.utils.GpxImporter;
19     import mx.controls.Alert;
20
21     private var map:Map;
22     private var conn:Connection;
23
24     public function init():void {
25         PopUpManager.addPopUp(this, Application(Application.application), true);
26         PopUpManager.centerPopUp(this);
27         this.addEventListener(CloseEvent.CLOSE, myGpxDialog_close);
28
29                 // >>>> REFACTOR: really horrible way of getting both map and connection
30         map = Globals.vars.root;
31                 conn = map.editableLayer.connection;
32
33         conn.addEventListener(Connection.TRACES_LOADED, onTracesLoaded);
34         SaveManager.ensureAccess(fetchList, conn);
35     }
36
37     private function myGpxDialog_close(evt:CloseEvent):void {
38         PopUpManager.removePopUp(this);
39         conn.removeEventListener(Connection.TRACES_LOADED, onTracesLoaded);
40     }
41
42     private function fetchList(refresh:Boolean=false):void {
43         results.text = "Fetching Traces...";
44         conn.fetchUserTraces(refresh);
45     }
46
47     private function onTracesLoaded(e:Event):void {
48         results.text = "Traces Loaded";
49         dispatchEvent(new Event("traces_loaded"));
50     }
51
52     [Bindable(event="traces_loaded")]
53     private function get traces():Array {
54         return conn.getTraces();
55     }
56
57     public function loadFile(t:Trace):void {
58         t.addToMap();
59     }
60
61     public function filesLoaded(success:Boolean,message:String=null):void {
62         if (success) {
63             dispatchEvent(new Event("layers_changed"));
64         } else {
65             Alert.show(message, 'Error', mx.controls.Alert.OK);
66         }
67     }
68               ]]>
69   </mx:Script>
70
71   <mx:Text text="Traces" id="results" />
72   <mx:DataGrid dataProvider="{traces}" width="100%" height="100%" id="traceGrid">
73     <mx:columns>
74             <mx:DataGridColumn editable="false" dataField="id" headerText="id" width="45"/>
75             <mx:DataGridColumn editable="false" dataField="filename" headerText="filename"/>
76             <mx:DataGridColumn editable="false" dataField="description" headerText="description"/>
77             <mx:DataGridColumn editable="false" dataField="tagsText" headerText="tags"/>
78             <mx:DataGridColumn editable="false">
79               <mx:itemRenderer>
80                 <mx:Component>
81                   <mx:VBox>
82                     <mx:Button label="Load"
83                       click="parentDocument.loadFile(data)"/>
84                   </mx:VBox>
85                 </mx:Component>
86               </mx:itemRenderer>
87             </mx:DataGridColumn>
88     </mx:columns>
89   </mx:DataGrid>
90   <mx:ControlBar>
91     <mx:Button label="Refresh List" click="fetchList(true)" />
92   </mx:ControlBar>
93 </mx:TitleWindow>