source: ComponentRegistry/branches/ComponentRegistry-1.12.0/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/Browse.mxml @ 2093

Last change on this file since 2093 was 2093, checked in by twagoo, 12 years ago

Added section title bar to Main

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