source: ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/Browse.mxml @ 3120

Last change on this file since 3120 was 3120, checked in by olhsha, 12 years ago

Bug 322 (visible in Opera and 50% f times in Chrome) seems to be fixed by: splitting up BrowserService?.ITEM_LOADED event into ComponentListService?.COMPONENTS_LOADED and ProfilesListService?.PROFILES_LOADED, and running load infor page only AFTER BOTH these events have dispatched.

File size: 10.0 KB
Line 
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.RegistryViewStack;
19                        import clarin.cmdi.componentregistry.services.ComponentInfoService;
20                        import clarin.cmdi.componentregistry.services.ComponentListService;
21                        import clarin.cmdi.componentregistry.services.Config;
22                        import clarin.cmdi.componentregistry.services.DeleteService;
23                        import clarin.cmdi.componentregistry.services.ProfileInfoService;
24                        import clarin.cmdi.componentregistry.services.ProfileListService;
25                       
26                        //debug
27                        import clarin.cmdi.componentregistry.common.Profile;
28                       
29                        public static const START_ITEM_LOADED:String = "startItemLoaded";
30                       
31                        private var startupItemLoaded:Boolean = false;
32                       
33                        [Bindable]
34                        private var componentsSrv:ComponentListService = ComponentListService.getInstance(Config.instance.userSpace);
35                        [Bindable]
36                        private var profilesSrv:ProfileListService = ProfileListService.getInstance(Config.instance.userSpace);
37                        [Bindable]
38                        private var selectedProfileSrv:ProfileInfoService = new ProfileInfoService();
39                        [Bindable]
40                        private var selectedComponentSrv:ComponentInfoService = new ComponentInfoService();
41                       
42                        private var _deleteSrvProfiles:DeleteService;
43                        private var _deleteSrvComponents:DeleteService;
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                        private const padding:int = 5;
57                        private const bigPadding:int =10;
58                       
59                        public function init():void {
60                               
61                                _deleteSrvProfiles=new DeleteService();
62                                _deleteSrvComponents=new DeleteService();
63                               
64                                profilesMenu = new BrowseContextMenu();
65                                profilesMenu.viewStack = this.parent as RegistryViewStack;
66                                profilesMenu.deleteService = _deleteSrvProfiles;
67                                componentsMenu = new BrowseContextMenu(true);
68                                componentsMenu.viewStack = this.parent as RegistryViewStack;
69                                componentsMenu.deleteService = _deleteSrvProfiles;
70                               
71                                _deleteSrvProfiles.addEventListener(_deleteSrvProfiles.ITEM_DELETED, handleItemDeleted);
72                                _deleteSrvComponents.addEventListener(_deleteSrvComponents.ITEM_DELETED, handleItemDeleted);
73                               
74                                Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, toggleUserSpace);
75                                Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, setUserSpace);
76                       
77                                setUserSpace();
78                               
79                        }
80                       
81                        private function toggleUserSpace(event:Event):void {
82                                var userSpace:Boolean = Config.instance.userSpace;
83                                componentsSrv = ComponentListService.getInstance(userSpace);
84                                profilesSrv = ProfileListService.getInstance(userSpace);
85                                refresh();
86                        }
87                       
88                        private function creationComplete():void {
89                                refresh();
90                        }
91                       
92                        public function loadStartup():void {
93                                startupItemId = Config.instance.startupItem;
94                                startupPanel = Config.instance.browserPanel;
95                                if (startupItemId) { //only load this once on startup                                   
96                                        profilesSrv.addEventListener(ProfileListService.PROFILES_LOADED, profilesLoaded);
97                                        componentsSrv.addEventListener(ComponentListService.COMPONENTS_LOADED, componentsLoaded);                                       
98                                        profilesSrv.load();
99                                }
100                                else{
101                                        refresh();
102                                }
103                        }
104                       
105                        public function refresh():void {
106                                componentsSrv.load();
107                                profilesSrv.load();                             
108                                selectedComponentSrv = new ComponentInfoService();
109                                selectedProfileSrv = new ProfileInfoService();
110                        }
111                       
112                       
113                       
114                        private function profilesLoaded(event:Event):void {                             
115                                profilesSrv.removeEventListener(ProfileListService.PROFILES_LOADED, profilesLoaded);
116                                componentsSrv.load();   
117                        }
118                       
119                        private function componentsLoaded(event:Event):void {                                   
120                                componentsSrv.removeEventListener(ComponentListService.COMPONENTS_LOADED, componentsLoaded);
121                               
122                                var item:ItemDescription = ProfileListService.findDescription(startupItemId);
123                                if(item != null){                                       
124                                        selectedProfileSrv = new ProfileInfoService();
125                                        loadStartupItem(item);
126                                        profileInfoPage.infoPanel.setPanel(Config.instance.browserPanel);       
127                                }
128                               
129                                item = ComponentListService.findDescription(startupItemId);
130                                if(item != null){                                       
131                                        selectedComponentSrv = new ComponentInfoService();
132                                        loadStartupItem(item);
133                                        componentInfoPage.infoPanel.setPanel(Config.instance.browserPanel);     
134                                }
135                        }
136                       
137                        private function loadStartupItem(item:ItemDescription):void {
138                                if (item) {
139                                        setSelectedDescription(item);
140                                        startupItemId = null;
141                                        dispatchEvent(new Event(START_ITEM_LOADED));
142                                } else if (startupItemLoaded) {
143                                        dispatchEvent(new Event(START_ITEM_LOADED));
144                                }
145                                startupItemLoaded = true;
146                        }
147                       
148                        private function loadProfileInfoPage(event:BrowserSelectionEvent):void {
149                                selectedProfileSrv.load(event.itemDescription);
150                        }
151                       
152                        private function loadComponentInfoPage(event:BrowserSelectionEvent):void {
153                                selectedComponentSrv.load(event.itemDescription);
154                        }
155                       
156                        public function setSelectedDescription(desc:ItemDescription):void {
157                                if (desc.isProfile) {
158                                        tabnav.selectedIndex = 0;
159                                        this.selectedProfileItem = desc;
160                                        selectedProfileSrv.load(desc);
161                                } else {
162                                        tabnav.selectedIndex = 1;
163                                        this.selectedComponentItem = desc;
164                                        selectedComponentSrv.load(desc);
165                                }
166                        }
167                       
168                        public function getSelectedStartItem():ItemDescription {
169                                if (this.selectedProfileItem) {
170                                        return selectedProfileItem;
171                                } else {
172                                        return selectedComponentItem;
173                                }
174                        }
175                       
176                        private function handleItemDeleted(event:Event):void {
177                                refresh();
178                        }
179                       
180                        public function getType():String {
181                                return Config.VIEW_BROWSE;
182                        }
183                       
184                        private function createNewProfile(event:Event):void {
185                                RegistryViewStack(this.parent).getEditor().xmlEditor.clearEditorProfile();
186                                RegistryViewStack(this.parent).switchToEditor(null);
187                        }
188                       
189                        private function createNewComponent(event:Event):void {
190                                RegistryViewStack(this.parent).getEditor().xmlEditor.clearEditorComponent();
191                                RegistryViewStack(this.parent).switchToEditor(null);
192                        }
193                       
194                        private function setUserSpace(event:Event = null):void {
195                                if (Config.instance.userSpace) {
196                                        userSpaceCB.selectedIndex = 1;
197                                } else {
198                                        userSpaceCB.selectedIndex = 0;
199                                }
200                        }
201                       
202                        private function getSelectedIndex():int{
203                                if (isComponentId(Config.instance.startupItem)) {
204                                        return 1;
205                                } else {
206                                        return 0;
207                                }
208                        }
209                       
210                        private function isComponentId(id:String):Boolean{
211                                if (id==null) {return false;}
212                                var index:int=id.search(Config.COMPONENT_PREFIX);
213                                if (index>=0) {
214                                        return true;
215                                } else {
216                                        return false;
217                                }
218                        }
219                       
220                        private function debugProfile():Profile{
221                                trace("in mxml: "+selectedProfileSrv.profile.components.length + "components for the given profile");
222                                return selectedProfileSrv.profile;
223                        }
224                       
225                ]]>
226        </mx:Script>
227       
228       
229       
230        <browser:BrowserColumns id="browserColumns"/>
231       
232        <mx:Panel width="100%"
233                          height="100%"
234                          headerHeight="0"
235                          borderThicknessTop="0"
236                          borderThicknessRight="0"
237                          borderThicknessBottom="0"
238                          borderThicknessLeft="0"
239                          layout="absolute"
240                          horizontalAlign="center"
241                          >
242               
243               
244               
245                <mx:Box paddingTop="{padding}" paddingLeft="{padding}"
246                                horizontalCenter="-110"
247                                >
248                        <components:SpaceSwitch id="userSpaceCB" width="110" />
249                </mx:Box>
250               
251                <mx:VBox left="0"
252                                 paddingTop="{bigPadding}"
253                                 borderStyle="none"
254                                 height="100%"
255                                 width="100%">
256                       
257                        <mx:TabNavigator id="tabnav"
258                                                         selectedIndex="{getSelectedIndex()}"
259                                                         width="100%"
260                                                         height="100%"
261                                                         color="0x323232"
262                                                         y="59"
263                                                         borderStyle="outset"
264                                                         creationPolicy="all"
265                                                         >
266                                <mx:VDividedBox label="Profiles"
267                                                                width="100%">
268                                       
269                                        <browser:BrowserOverviewList id="profilesOverview"
270                                                                                                 viewStack="{this.parent as RegistryViewStack}"
271                                                                                                 browserColumns="{browserColumns.getProfileColumns()}"
272                                                                                                 browserDataProvider="{profilesSrv.itemDescriptions}"
273                                                                                                 browserItemSelected="{loadProfileInfoPage(event)}"
274                                                                                                 itemToScrollTo="{selectedProfileItem}"
275                                                                                                 width="100%"
276                                                                                                 height="70%"
277                                                                                                 browseMenu="{profilesMenu}"
278                                                                                                 typeOfDescription = "profiles"
279                                                                                                 createNew="createNewProfile(event)"
280                                                                                                 />
281                                        <browser:ProfileInfoPage id="profileInfoPage"
282                                                                                         profile="{selectedProfileSrv.profile}"
283                                                                                         width="100%"
284                                                                                         height="50%"
285                                                                                         contextMenu="{profilesMenu.cm}"/>
286                                </mx:VDividedBox>
287                               
288                                <mx:VDividedBox label="Components"
289                                                                width="100%"
290                                                                >
291                                        <browser:BrowserOverviewList id="componentsOverview"
292                                                                                                 viewStack="{this.parent as RegistryViewStack}"
293                                                                                                 browserColumns="{browserColumns.getComponentColumns()}"
294                                                                                                 browserDataProvider="{componentsSrv.itemDescriptions}"
295                                                                                                 browserItemSelected="{loadComponentInfoPage(event)}"
296                                                                                                 itemToScrollTo="{selectedComponentItem}"
297                                                                                                 width="100%"
298                                                                                                 height="70%"
299                                                                                                 browseMenu="{componentsMenu}"
300                                                                                                 typeOfDescription= "components"
301                                                                                                 createNew="createNewComponent(event)"
302                                                                                                 />
303                                        <browser:ComponentInfoPage id="componentInfoPage"
304                                                                                           component="{selectedComponentSrv.component}"
305                                                                                           width="100%"
306                                                                                           height="50%"
307                                                                                           contextMenu="{componentsMenu.cm}"/>
308                                       
309                                </mx:VDividedBox>
310                        </mx:TabNavigator>
311                </mx:VBox>
312        </mx:Panel>
313</mx:Canvas>
Note: See TracBrowser for help on using the repository browser.