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 | [Bindable] |
---|
57 | private var rssProfilesMenu:RssContextMenu; |
---|
58 | [Bindable] |
---|
59 | private var rssComponentsMenu:RssContextMenu; |
---|
60 | |
---|
61 | |
---|
62 | public function init():void { |
---|
63 | profilesMenu = new BrowseContextMenu(); |
---|
64 | profilesMenu.viewStack = this.parent as RegistryViewStack; |
---|
65 | profilesMenu.deleteService = deleteSrv; |
---|
66 | componentsMenu = new BrowseContextMenu(true); |
---|
67 | componentsMenu.viewStack = this.parent as RegistryViewStack; |
---|
68 | componentsMenu.deleteService = deleteSrv; |
---|
69 | deleteSrv.addEventListener(DeleteService.ITEM_DELETED, handleItemDeleted); |
---|
70 | |
---|
71 | Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, toggleUserSpace); |
---|
72 | |
---|
73 | Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, setUserSpace); |
---|
74 | |
---|
75 | //profilesOverview.rssUri = Config.getRssUriDescriptions("profiles"); |
---|
76 | //componentsOverview.rssUri = Config.getRssUriDescriptions("components"); |
---|
77 | |
---|
78 | rssProfilesMenu = new RssContextMenu(Config.getRssUriDescriptions("profiles")); |
---|
79 | rssComponentsMenu = new RssContextMenu(Config.getRssUriDescriptions("components")); |
---|
80 | |
---|
81 | setUserSpace(); |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | private function toggleUserSpace(event:Event):void { |
---|
86 | var userSpace:Boolean = Config.instance.userSpace; |
---|
87 | componentsSrv = ComponentListService.getInstance(userSpace); |
---|
88 | profilesSrv = ProfileListService.getInstance(userSpace); |
---|
89 | |
---|
90 | //profilesOverview.rssUri = Config.getRssUriDescriptions("profiles"); |
---|
91 | //componentsOverview.rssUri = Config.getRssUriDescriptions("components"); |
---|
92 | |
---|
93 | rssProfilesMenu.rssUri = Config.getRssUriDescriptions("profiles"); |
---|
94 | rssComponentsMenu.rssUri=Config.getRssUriDescriptions("components"); |
---|
95 | |
---|
96 | refresh(); |
---|
97 | } |
---|
98 | |
---|
99 | private function creationComplete():void { |
---|
100 | refresh(); |
---|
101 | } |
---|
102 | |
---|
103 | public function loadStartup():void { |
---|
104 | startupItemId = Config.instance.startupItem; |
---|
105 | startupPanel = Config.instance.browserPanel; |
---|
106 | if (startupItemId) { //only load this once on startup |
---|
107 | componentsSrv.addEventListener(BrowserService.ITEMS_LOADED, componentsLoaded); |
---|
108 | profilesSrv.addEventListener(BrowserService.ITEMS_LOADED, profilesLoaded); |
---|
109 | } |
---|
110 | |
---|
111 | refresh(); |
---|
112 | } |
---|
113 | |
---|
114 | public function refresh():void { |
---|
115 | componentsSrv.load(); |
---|
116 | profilesSrv.load(); |
---|
117 | } |
---|
118 | |
---|
119 | private function profilesLoaded(event:Event):void { |
---|
120 | var item:ItemDescription = ProfileListService.findDescription(startupItemId); |
---|
121 | loadStartupItem(item); |
---|
122 | profileInfoPage.infoPanel.setPanel(Config.instance.browserPanel); |
---|
123 | profilesSrv.removeEventListener(BrowserService.ITEMS_LOADED, profilesLoaded); |
---|
124 | } |
---|
125 | |
---|
126 | private function componentsLoaded(event:Event):void { |
---|
127 | var item:ItemDescription = ComponentListService.findDescription(startupItemId); |
---|
128 | if(item != null){ |
---|
129 | loadStartupItem(item); |
---|
130 | componentInfoPage.infoPanel.setPanel(Config.instance.browserPanel); |
---|
131 | componentsSrv.removeEventListener(BrowserService.ITEMS_LOADED, componentsLoaded); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | private function loadStartupItem(item:ItemDescription):void { |
---|
136 | if (item) { |
---|
137 | setSelectedDescription(item); |
---|
138 | startupItemId = null; |
---|
139 | dispatchEvent(new Event(START_ITEM_LOADED)); |
---|
140 | } else if (startupItemLoaded) { |
---|
141 | dispatchEvent(new Event(START_ITEM_LOADED)); |
---|
142 | } |
---|
143 | startupItemLoaded = true; |
---|
144 | } |
---|
145 | |
---|
146 | private function loadProfileInfoPage(event:BrowserSelectionEvent):void { |
---|
147 | profileSrv.load(event.itemDescription); |
---|
148 | } |
---|
149 | |
---|
150 | private function loadComponentInfoPage(event:BrowserSelectionEvent):void { |
---|
151 | componentSrv.load(event.itemDescription); |
---|
152 | } |
---|
153 | |
---|
154 | public function setSelectedDescription(desc:ItemDescription):void { |
---|
155 | if (desc.isProfile) { |
---|
156 | tabnav.selectedIndex = 0; |
---|
157 | this.selectedProfileItem = desc; |
---|
158 | profileSrv.load(desc); |
---|
159 | } else { |
---|
160 | tabnav.selectedIndex = 1; |
---|
161 | this.selectedComponentItem = desc; |
---|
162 | componentSrv.load(desc); |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | public function getSelectedStartItem():ItemDescription { |
---|
167 | if (this.selectedProfileItem) { |
---|
168 | return selectedProfileItem; |
---|
169 | } else { |
---|
170 | return selectedComponentItem; |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | private function handleItemDeleted(event:Event):void { |
---|
175 | refresh(); |
---|
176 | } |
---|
177 | |
---|
178 | public function getType():String { |
---|
179 | return Config.VIEW_BROWSE; |
---|
180 | } |
---|
181 | |
---|
182 | private function createNewProfile(event:Event):void { |
---|
183 | RegistryViewStack(this.parent).getEditor().xmlEditor.clearEditorProfile(); |
---|
184 | RegistryViewStack(this.parent).switchToEditor(null); |
---|
185 | } |
---|
186 | |
---|
187 | private function createNewComponent(event:Event):void { |
---|
188 | RegistryViewStack(this.parent).getEditor().xmlEditor.clearEditorComponent(); |
---|
189 | RegistryViewStack(this.parent).switchToEditor(null); |
---|
190 | } |
---|
191 | |
---|
192 | private function setUserSpace(event:Event = null):void { |
---|
193 | if (Config.instance.userSpace) { |
---|
194 | userSpaceCB.selectedIndex = 1; |
---|
195 | } else { |
---|
196 | userSpaceCB.selectedIndex = 0; |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | ]]> |
---|
202 | </mx:Script> |
---|
203 | |
---|
204 | <browser:BrowserColumns id="browserColumns"/> |
---|
205 | |
---|
206 | <mx:Panel width="100%" |
---|
207 | height="100%" |
---|
208 | headerHeight="0" |
---|
209 | borderThicknessTop="0" |
---|
210 | borderThicknessRight="0" |
---|
211 | borderThicknessBottom="0" |
---|
212 | borderThicknessLeft="0" |
---|
213 | layout="absolute" |
---|
214 | horizontalAlign="center" |
---|
215 | > |
---|
216 | |
---|
217 | |
---|
218 | |
---|
219 | <mx:Box paddingTop="5" paddingLeft="5" |
---|
220 | top="-5" |
---|
221 | horizontalCenter="-110" |
---|
222 | > |
---|
223 | <components:SpaceSwitch id="userSpaceCB" width="110" /> |
---|
224 | </mx:Box> |
---|
225 | |
---|
226 | <mx:VBox left="0" |
---|
227 | top="5" |
---|
228 | borderStyle="none" |
---|
229 | height="100%" |
---|
230 | width="100%"> |
---|
231 | |
---|
232 | <mx:TabNavigator id="tabnav" |
---|
233 | width="100%" |
---|
234 | height="100%" |
---|
235 | color="0x323232" |
---|
236 | y="59" |
---|
237 | borderStyle="outset" |
---|
238 | creationPolicy="all" |
---|
239 | > |
---|
240 | <mx:VDividedBox label="Profiles" |
---|
241 | width="100%"> |
---|
242 | |
---|
243 | <browser:BrowserOverviewList id="profilesOverview" |
---|
244 | viewStack="{this.parent as RegistryViewStack}" |
---|
245 | browserColumns="{browserColumns.getProfileColumns()}" |
---|
246 | browserDataProvider="{profilesSrv.itemDescriptions}" |
---|
247 | browserItemSelected="{loadProfileInfoPage(event)}" |
---|
248 | itemToScrollTo="{selectedProfileItem}" |
---|
249 | width="100%" |
---|
250 | height="70%" |
---|
251 | browseMenu="{profilesMenu}" |
---|
252 | rssLinkMenu = "{rssProfilesMenu}" |
---|
253 | createNew="createNewProfile(event)" |
---|
254 | /> |
---|
255 | <browser:ProfileInfoPage id="profileInfoPage" |
---|
256 | profile="{profileSrv.profile}" |
---|
257 | width="100%" |
---|
258 | height="50%" |
---|
259 | contextMenu="{profilesMenu.cm}"/> |
---|
260 | </mx:VDividedBox> |
---|
261 | |
---|
262 | <mx:VDividedBox label="Components" |
---|
263 | width="100%"> |
---|
264 | |
---|
265 | |
---|
266 | <browser:BrowserOverviewList id="componentsOverview" |
---|
267 | viewStack="{this.parent as RegistryViewStack}" |
---|
268 | browserColumns="{browserColumns.getComponentColumns()}" |
---|
269 | browserDataProvider="{componentsSrv.itemDescriptions}" |
---|
270 | browserItemSelected="{loadComponentInfoPage(event)}" |
---|
271 | itemToScrollTo="{selectedComponentItem}" |
---|
272 | width="100%" |
---|
273 | height="70%" |
---|
274 | browseMenu="{componentsMenu}" |
---|
275 | createNew="createNewComponent(event)" |
---|
276 | /> |
---|
277 | <browser:ComponentInfoPage id="componentInfoPage" |
---|
278 | component="{componentSrv.component}" |
---|
279 | width="100%" |
---|
280 | height="50%" |
---|
281 | contextMenu="{componentsMenu.cm}"/> |
---|
282 | |
---|
283 | </mx:VDividedBox> |
---|
284 | </mx:TabNavigator> |
---|
285 | </mx:VBox> |
---|
286 | </mx:Panel> |
---|
287 | </mx:Canvas> |
---|