1 | <?xml version="1.0" encoding="utf-8"?> |
---|
2 | <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" |
---|
3 | xmlns:browser="clarin.cmdi.componentregistry.browser.*" |
---|
4 | initialize="init()" |
---|
5 | creationComplete="creationComplete()" |
---|
6 | width="100%" |
---|
7 | height="100%" |
---|
8 | label="Component Browser" |
---|
9 | implements="clarin.cmdi.componentregistry.common.components.RegistryView" xmlns:components="clarin.cmdi.componentregistry.common.components.*" |
---|
10 | > |
---|
11 | <mx:Metadata> |
---|
12 | [Event(name="startItemLoaded",type="flash.events.Event")] |
---|
13 | </mx:Metadata> |
---|
14 | <mx:Script> |
---|
15 | <![CDATA[ |
---|
16 | import clarin.cmdi.componentregistry.common.ItemDescription; |
---|
17 | import clarin.cmdi.componentregistry.common.components.BrowseContextMenu; |
---|
18 | //import clarin.cmdi.componentregistry.common.components.RssContextMenu; |
---|
19 | import clarin.cmdi.componentregistry.common.components.RegistryViewStack; |
---|
20 | import clarin.cmdi.componentregistry.services.BrowserService; |
---|
21 | import clarin.cmdi.componentregistry.services.ComponentInfoService; |
---|
22 | import clarin.cmdi.componentregistry.services.ComponentListService; |
---|
23 | import clarin.cmdi.componentregistry.services.Config; |
---|
24 | import clarin.cmdi.componentregistry.services.DeleteService; |
---|
25 | import clarin.cmdi.componentregistry.services.ProfileInfoService; |
---|
26 | import clarin.cmdi.componentregistry.services.ProfileListService; |
---|
27 | |
---|
28 | import mx.controls.Text; |
---|
29 | |
---|
30 | public static const START_ITEM_LOADED:String = "startItemLoaded"; |
---|
31 | |
---|
32 | private var startupItemLoaded:Boolean = false; |
---|
33 | |
---|
34 | [Bindable] |
---|
35 | private var componentsSrv:ComponentListService = ComponentListService.getInstance(Config.instance.userSpace); |
---|
36 | [Bindable] |
---|
37 | private var profilesSrv:ProfileListService = ProfileListService.getInstance(Config.instance.userSpace); |
---|
38 | [Bindable] |
---|
39 | private var profileSrv:ProfileInfoService = new ProfileInfoService(); |
---|
40 | [Bindable] |
---|
41 | private var componentSrv:ComponentInfoService = new ComponentInfoService(); |
---|
42 | |
---|
43 | private var deleteSrv:DeleteService = DeleteService.instance; |
---|
44 | |
---|
45 | [Bindable] |
---|
46 | private var profilesMenu:BrowseContextMenu; |
---|
47 | [Bindable] |
---|
48 | private var componentsMenu:BrowseContextMenu; |
---|
49 | [Bindable] |
---|
50 | private var selectedProfileItem:ItemDescription; |
---|
51 | [Bindable] |
---|
52 | private var selectedComponentItem:ItemDescription; |
---|
53 | private var startupItemId:String = null; |
---|
54 | private var startupPanel:String = null; |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | public function init():void { |
---|
59 | profilesMenu = new BrowseContextMenu(); |
---|
60 | profilesMenu.viewStack = this.parent as RegistryViewStack; |
---|
61 | profilesMenu.deleteService = deleteSrv; |
---|
62 | componentsMenu = new BrowseContextMenu(true); |
---|
63 | componentsMenu.viewStack = this.parent as RegistryViewStack; |
---|
64 | componentsMenu.deleteService = deleteSrv; |
---|
65 | deleteSrv.addEventListener(DeleteService.ITEM_DELETED, handleItemDeleted); |
---|
66 | |
---|
67 | Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, toggleUserSpace); |
---|
68 | Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, setUserSpace); |
---|
69 | |
---|
70 | setUserSpace(); |
---|
71 | |
---|
72 | } |
---|
73 | |
---|
74 | private function toggleUserSpace(event:Event):void { |
---|
75 | var userSpace:Boolean = Config.instance.userSpace; |
---|
76 | componentsSrv = ComponentListService.getInstance(userSpace); |
---|
77 | profilesSrv = ProfileListService.getInstance(userSpace); |
---|
78 | |
---|
79 | |
---|
80 | refresh(); |
---|
81 | } |
---|
82 | |
---|
83 | private function creationComplete():void { |
---|
84 | refresh(); |
---|
85 | } |
---|
86 | |
---|
87 | public function loadStartup():void { |
---|
88 | startupItemId = Config.instance.startupItem; |
---|
89 | startupPanel = Config.instance.browserPanel; |
---|
90 | if (startupItemId) { //only load this once on startup |
---|
91 | componentsSrv.addEventListener(BrowserService.ITEMS_LOADED, componentsLoaded); |
---|
92 | profilesSrv.addEventListener(BrowserService.ITEMS_LOADED, profilesLoaded); |
---|
93 | } |
---|
94 | |
---|
95 | refresh(); |
---|
96 | } |
---|
97 | |
---|
98 | public function refresh():void { |
---|
99 | componentsSrv.load(); |
---|
100 | profilesSrv.load(); |
---|
101 | } |
---|
102 | |
---|
103 | private function profilesLoaded(event:Event):void { |
---|
104 | var item:ItemDescription = ProfileListService.findDescription(startupItemId); |
---|
105 | loadStartupItem(item); |
---|
106 | profileInfoPage.infoPanel.setPanel(Config.instance.browserPanel); |
---|
107 | profilesSrv.removeEventListener(BrowserService.ITEMS_LOADED, profilesLoaded); |
---|
108 | } |
---|
109 | |
---|
110 | private function componentsLoaded(event:Event):void { |
---|
111 | var item:ItemDescription = ComponentListService.findDescription(startupItemId); |
---|
112 | if(item != null){ |
---|
113 | loadStartupItem(item); |
---|
114 | componentInfoPage.infoPanel.setPanel(Config.instance.browserPanel); |
---|
115 | componentsSrv.removeEventListener(BrowserService.ITEMS_LOADED, componentsLoaded); |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | private function loadStartupItem(item:ItemDescription):void { |
---|
120 | if (item) { |
---|
121 | setSelectedDescription(item); |
---|
122 | startupItemId = null; |
---|
123 | dispatchEvent(new Event(START_ITEM_LOADED)); |
---|
124 | } else if (startupItemLoaded) { |
---|
125 | dispatchEvent(new Event(START_ITEM_LOADED)); |
---|
126 | } |
---|
127 | startupItemLoaded = true; |
---|
128 | } |
---|
129 | |
---|
130 | private function loadProfileInfoPage(event:BrowserSelectionEvent):void { |
---|
131 | profileSrv.load(event.itemDescription); |
---|
132 | } |
---|
133 | |
---|
134 | private function loadComponentInfoPage(event:BrowserSelectionEvent):void { |
---|
135 | componentSrv.load(event.itemDescription); |
---|
136 | } |
---|
137 | |
---|
138 | public function setSelectedDescription(desc:ItemDescription):void { |
---|
139 | if (desc.isProfile) { |
---|
140 | tabnav.selectedIndex = 0; |
---|
141 | this.selectedProfileItem = desc; |
---|
142 | profileSrv.load(desc); |
---|
143 | } else { |
---|
144 | tabnav.selectedIndex = 1; |
---|
145 | this.selectedComponentItem = desc; |
---|
146 | componentSrv.load(desc); |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | public function getSelectedStartItem():ItemDescription { |
---|
151 | if (this.selectedProfileItem) { |
---|
152 | return selectedProfileItem; |
---|
153 | } else { |
---|
154 | return selectedComponentItem; |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | private function handleItemDeleted(event:Event):void { |
---|
159 | refresh(); |
---|
160 | } |
---|
161 | |
---|
162 | public function getType():String { |
---|
163 | return Config.VIEW_BROWSE; |
---|
164 | } |
---|
165 | |
---|
166 | private function createNewProfile(event:Event):void { |
---|
167 | RegistryViewStack(this.parent).getEditor().xmlEditor.clearEditorProfile(); |
---|
168 | RegistryViewStack(this.parent).switchToEditor(null); |
---|
169 | } |
---|
170 | |
---|
171 | private function createNewComponent(event:Event):void { |
---|
172 | RegistryViewStack(this.parent).getEditor().xmlEditor.clearEditorComponent(); |
---|
173 | RegistryViewStack(this.parent).switchToEditor(null); |
---|
174 | } |
---|
175 | |
---|
176 | private function setUserSpace(event:Event = null):void { |
---|
177 | if (Config.instance.userSpace) { |
---|
178 | userSpaceCB.selectedIndex = 1; |
---|
179 | } else { |
---|
180 | userSpaceCB.selectedIndex = 0; |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | ]]> |
---|
186 | </mx:Script> |
---|
187 | |
---|
188 | <browser:BrowserColumns id="browserColumns"/> |
---|
189 | |
---|
190 | <mx:Panel width="100%" |
---|
191 | height="100%" |
---|
192 | headerHeight="0" |
---|
193 | borderThicknessTop="0" |
---|
194 | borderThicknessRight="0" |
---|
195 | borderThicknessBottom="0" |
---|
196 | borderThicknessLeft="0" |
---|
197 | layout="absolute" |
---|
198 | horizontalAlign="center" |
---|
199 | > |
---|
200 | |
---|
201 | |
---|
202 | |
---|
203 | <mx:Box paddingTop="5" paddingLeft="5" |
---|
204 | top="-5" |
---|
205 | horizontalCenter="-110" |
---|
206 | > |
---|
207 | <components:SpaceSwitch id="userSpaceCB" width="110" /> |
---|
208 | </mx:Box> |
---|
209 | |
---|
210 | <mx:VBox left="0" |
---|
211 | top="5" |
---|
212 | borderStyle="none" |
---|
213 | height="100%" |
---|
214 | width="100%"> |
---|
215 | |
---|
216 | <mx:TabNavigator id="tabnav" |
---|
217 | width="100%" |
---|
218 | height="100%" |
---|
219 | color="0x323232" |
---|
220 | y="59" |
---|
221 | borderStyle="outset" |
---|
222 | creationPolicy="all" |
---|
223 | > |
---|
224 | <mx:VDividedBox label="Profiles" |
---|
225 | width="100%"> |
---|
226 | |
---|
227 | <browser:BrowserOverviewList id="profilesOverview" |
---|
228 | viewStack="{this.parent as RegistryViewStack}" |
---|
229 | browserColumns="{browserColumns.getProfileColumns()}" |
---|
230 | browserDataProvider="{profilesSrv.itemDescriptions}" |
---|
231 | browserItemSelected="{loadProfileInfoPage(event)}" |
---|
232 | itemToScrollTo="{selectedProfileItem}" |
---|
233 | width="100%" |
---|
234 | height="70%" |
---|
235 | browseMenu="{profilesMenu}" |
---|
236 | typeOfDescription = "profiles" |
---|
237 | createNew="createNewProfile(event)" |
---|
238 | /> |
---|
239 | <browser:ProfileInfoPage id="profileInfoPage" |
---|
240 | profile="{profileSrv.profile}" |
---|
241 | width="100%" |
---|
242 | height="50%" |
---|
243 | contextMenu="{profilesMenu.cm}"/> |
---|
244 | </mx:VDividedBox> |
---|
245 | |
---|
246 | <mx:VDividedBox label="Components" |
---|
247 | width="100%"> |
---|
248 | |
---|
249 | |
---|
250 | <browser:BrowserOverviewList id="componentsOverview" |
---|
251 | viewStack="{this.parent as RegistryViewStack}" |
---|
252 | browserColumns="{browserColumns.getComponentColumns()}" |
---|
253 | browserDataProvider="{componentsSrv.itemDescriptions}" |
---|
254 | browserItemSelected="{loadComponentInfoPage(event)}" |
---|
255 | itemToScrollTo="{selectedComponentItem}" |
---|
256 | width="100%" |
---|
257 | height="70%" |
---|
258 | browseMenu="{componentsMenu}" |
---|
259 | typeOfDescription= "components" |
---|
260 | createNew="createNewComponent(event)" |
---|
261 | /> |
---|
262 | <browser:ComponentInfoPage id="componentInfoPage" |
---|
263 | component="{componentSrv.component}" |
---|
264 | width="100%" |
---|
265 | height="50%" |
---|
266 | contextMenu="{componentsMenu.cm}"/> |
---|
267 | |
---|
268 | </mx:VDividedBox> |
---|
269 | </mx:TabNavigator> |
---|
270 | </mx:VBox> |
---|
271 | </mx:Panel> |
---|
272 | </mx:Canvas> |
---|