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

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

Moved the public/workspace switch out of Browse into a separate class and added it to both Browse and BrowserOverviewList?, it being optional (off by default) in the latter. Also made the action buttons bar optional. Now the browser panel in Editor can have different controls than the main browser.

File size: 8.2 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.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 function setUserSpace(event:Event = null):void {
165                                if (Config.instance.userSpace) {
166                                        userSpaceCB.selectedIndex = 1;
167                                } else {
168                                        userSpaceCB.selectedIndex = 0;
169                                }
170                        }
171                ]]>
172        </mx:Script>
173       
174        <browser:BrowserColumns id="browserColumns"/>
175       
176        <mx:Panel width="100%"
177                          height="100%"
178                          headerHeight="0"
179                          borderThicknessTop="0"
180                          borderThicknessRight="0"
181                          borderThicknessBottom="0"
182                          borderThicknessLeft="0"
183                          >
184               
185                <mx:VBox left="0"
186                                 top="5"
187                                 borderStyle="none"
188                                 height="100%"
189                                 width="100%">
190                       
191                        <mx:Box paddingTop="5" paddingLeft="5">
192                                <components:SpaceSwitch id="userSpaceCB"  />
193                        </mx:Box>
194                       
195                        <mx:TabNavigator id="tabnav"
196                                                         width="100%"
197                                                         height="100%"
198                                                         color="0x323232"
199                                                         y="59"
200                                                         borderStyle="outset">
201                                <mx:VDividedBox label="Profiles"
202                                                                width="100%">
203                                        <browser:BrowserOverviewList id="profilesOverview"
204                                                                                                 viewStack="{this.parent as RegistryViewStack}"
205                                                                                                 browserColumns="{browserColumns.getProfileColumns()}"
206                                                                                                 browserDataProvider="{profilesSrv.itemDescriptions}"
207                                                                                                 browserItemSelected="{loadProfileInfoPage(event)}"
208                                                                                                 itemToScrollTo="{selectedProfileItem}"
209                                                                                                 width="100%"
210                                                                                                 height="70%"
211                                                                                                 browseMenu="{profilesMenu}"
212                                                                                                 createNew="createNewProfile(event)"
213                                                                                                 />
214                                        <browser:ProfileInfoPage id="profileInfoPage"
215                                                                                         profile="{profileSrv.profile}"
216                                                                                         width="100%"
217                                                                                         height="50%"
218                                                                                         contextMenu="{profilesMenu.cm}"/>
219                                </mx:VDividedBox>
220                               
221                                <mx:VDividedBox label="Components"
222                                                                width="100%">
223                                        <browser:BrowserOverviewList id="componentsOverview"
224                                                                                                 viewStack="{this.parent as RegistryViewStack}"
225                                                                                                 browserColumns="{browserColumns.getComponentColumns()}"
226                                                                                                 browserDataProvider="{componentsSrv.itemDescriptions}"
227                                                                                                 browserItemSelected="{loadComponentInfoPage(event)}"
228                                                                                                 itemToScrollTo="{selectedComponentItem}"
229                                                                                                 width="100%"
230                                                                                                 height="70%"
231                                                                                                 browseMenu="{componentsMenu}"
232                                                                                                 createNew="createNewComponent(event)"
233                                                                                                 />
234                                        <browser:ComponentInfoPage id="componentInfoPage"
235                                                                                           component="{componentSrv.component}"
236                                                                                           width="100%"
237                                                                                           height="50%"
238                                                                                           contextMenu="{componentsMenu.cm}"/>
239                                       
240                                </mx:VDividedBox>
241                        </mx:TabNavigator>
242                </mx:VBox>
243        </mx:Panel>
244</mx:Canvas>
Note: See TracBrowser for help on using the repository browser.