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

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

Track changes in specs being edited and show confirm dialog if there changes are about to be discarded.
Fixes #202

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="Browser"
9                   implements="clarin.cmdi.componentregistry.common.components.RegistryView">
10        <mx:Metadata>
11                [Event(name="startItemLoaded",type="flash.events.Event")]
12        </mx:Metadata>
13        <mx:Script>
14                <![CDATA[
15                        import clarin.cmdi.componentregistry.common.Credentials;
16                        import clarin.cmdi.componentregistry.common.ItemDescription;
17                        import clarin.cmdi.componentregistry.common.Login;
18                        import clarin.cmdi.componentregistry.common.components.BrowseContextMenu;
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.collections.ArrayCollection;
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                       
55                        public function init():void {
56                                profilesMenu = new BrowseContextMenu();
57                                profilesMenu.viewStack = this.parent as RegistryViewStack;
58                                profilesMenu.deleteService = deleteSrv;
59                                componentsMenu = new BrowseContextMenu(true);
60                                componentsMenu.viewStack = this.parent as RegistryViewStack;
61                                componentsMenu.deleteService = deleteSrv;
62                                deleteSrv.addEventListener(DeleteService.ITEM_DELETED, handleItemDeleted);
63                                Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, toggleUserSpace);
64                               
65                                Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, setUserSpace);
66                                setUserSpace();
67                        }
68                       
69                        private function toggleUserSpace(event:Event):void {
70                                var userSpace:Boolean = Config.instance.userSpace;
71                                componentsSrv = ComponentListService.getInstance(userSpace);
72                                profilesSrv = ProfileListService.getInstance(userSpace);
73                                refresh();
74                        }
75                       
76                        private function creationComplete():void {
77                                refresh();
78                        }
79                       
80                        public function loadStartup():void {
81                                startupItemId = Config.instance.startupItem;
82                                if (startupItemId) { //only load this once on startup
83                                        componentsSrv.addEventListener(BrowserService.ITEMS_LOADED, componentsLoaded);
84                                        profilesSrv.addEventListener(BrowserService.ITEMS_LOADED, profilesLoaded);
85                                }
86                                refresh();
87                        }
88                       
89                        public function refresh():void {
90                                componentsSrv.load();
91                                profilesSrv.load();
92                        }
93                       
94                        private function profilesLoaded(event:Event):void {
95                                var item:ItemDescription = ProfileListService.findDescription(startupItemId);
96                                loadStartupItem(item);
97                                profilesSrv.removeEventListener(BrowserService.ITEMS_LOADED, profilesLoaded);
98                        }
99                       
100                        private function componentsLoaded(event:Event):void {
101                                var item:ItemDescription = ComponentListService.findDescription(startupItemId);
102                                loadStartupItem(item);
103                                componentsSrv.removeEventListener(BrowserService.ITEMS_LOADED, componentsLoaded);
104                        }
105                       
106                        private function loadStartupItem(item:ItemDescription):void {
107                                if (item) {
108                                        setSelectedDescription(item);
109                                        startupItemId = null;
110                                        dispatchEvent(new Event(START_ITEM_LOADED));
111                                } else if (startupItemLoaded) {
112                                        dispatchEvent(new Event(START_ITEM_LOADED));
113                                }
114                                startupItemLoaded = true;
115                        }
116                       
117                        private function loadProfileInfoPage(event:BrowserSelectionEvent):void {
118                                profileSrv.load(event.itemDescription);
119                        }
120                       
121                        private function loadComponentInfoPage(event:BrowserSelectionEvent):void {
122                                componentSrv.load(event.itemDescription);
123                        }
124                       
125                        public function setSelectedDescription(desc:ItemDescription):void {
126                                if (desc.isProfile) {
127                                        tabnav.selectedIndex = 0;
128                                        this.selectedProfileItem = desc;
129                                        profileSrv.load(desc);
130                                } else {
131                                        tabnav.selectedIndex = 1;
132                                        this.selectedComponentItem = desc;
133                                        componentSrv.load(desc);
134                                }
135                        }
136                       
137                        public function getSelectedStartItem():ItemDescription {
138                                if (this.selectedProfileItem) {
139                                        return selectedProfileItem;
140                                } else {
141                                        return selectedComponentItem;
142                                }
143                        }
144                       
145                        private function handleItemDeleted(event:Event):void {
146                                refresh();
147                        }
148                       
149                        public function getType():String {
150                                return Config.VIEW_BROWSE;
151                        }
152                       
153                        private function createNewProfile(event:Event):void {
154                                RegistryViewStack(this.parent).getEditor().xmlEditor.clearEditorProfile();
155                                RegistryViewStack(this.parent).switchToEditor(null);
156                        }
157                       
158                        private function createNewComponent(event:Event):void {
159                                RegistryViewStack(this.parent).getEditor().xmlEditor.clearEditorComponent();
160                                RegistryViewStack(this.parent).switchToEditor(null);
161                        }
162                       
163                        private static const USERSPACE_LABEL:String = "Work space";
164                        private static const PUBLICSPACE_LABEL:String = "Public space";
165                        [Bindable]
166                        public var spaces:ArrayCollection = new ArrayCollection([{label: PUBLICSPACE_LABEL, data: 1}, {label: USERSPACE_LABEL, data: 2}]);
167                       
168                        private function setUserSpace(event:Event = null):void {
169                                if (Config.instance.userSpace) {
170                                        userSpaceCB.selectedIndex = 1;
171                                } else {
172                                        userSpaceCB.selectedIndex = 0;
173                                }
174                        }
175                       
176                        private function userSpaceCloseHandler(event:Event):void {
177                                if (Credentials.instance.isLoggedIn()) {
178                                        Config.instance.userSpace = ComboBox(event.target).selectedItem.data == 2;
179                                } else if (userSpaceCB.selectedIndex != 0) {
180                                        userSpaceCB.selectedIndex = 0;
181                                        new Login().show(this, Config.VIEW_BROWSE, Config.SPACE_USER, null);
182                                }
183                               
184                        }
185                ]]>
186        </mx:Script>
187       
188        <browser:BrowserColumns id="browserColumns"/>
189       
190        <mx:Panel layout="absolute"
191                          width="100%"
192                          height="100%"
193                          headerHeight="0"
194                          borderThicknessTop="0"
195                          borderThicknessRight="0"
196                          borderThicknessBottom="0"
197                          borderThicknessLeft="0"
198                          >
199                       
200                <mx:ComboBox right="0"
201                                         top="0"                               
202                                         id="userSpaceCB"
203                                         dataProvider="{spaces}"
204                                         width="110"
205                                         close="userSpaceCloseHandler(event);"/>
206               
207                <mx:VBox left="0"
208                                 top="5"
209                                 borderStyle="none"
210                                 horizontalAlign="center"
211                                 height="100%"
212                                 width="100%">
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.