source: ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/BrowserService.as @ 2515

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

Merged changes from Olha's branch to trunk

File size: 1.8 KB
Line 
1package clarin.cmdi.componentregistry.services {
2        import clarin.cmdi.componentregistry.common.ItemDescription;
3       
4        import com.adobe.net.URI;
5       
6        import mx.collections.ArrayCollection;
7       
8        import mx.rpc.events.ResultEvent;
9       
10       
11        [Event(name="itemsLoaded", type="flash.events.Event")]
12        public class BrowserService extends ComponentRegistryService {
13        public static const ITEMS_LOADED:String = "itemsLoaded";
14
15                /**
16                 * Typed ArrayCollection publicly available for outside code to bind to and watch.
17                 */
18                [Bindable]
19                [ArrayElementType("ItemDescription")]
20                public var itemDescriptions:ArrayCollection;
21
22                // Not bindable needed for lookups over the whole collections of itemDescriptions
23                protected var unFilteredItemDescriptions:ArrayCollection;
24                protected var userSpace:Boolean;
25
26                public function BrowserService(restUrl:String, userSpace:Boolean) {
27                        super(restUrl);
28                        this.userSpace = userSpace;
29                }
30               
31                override protected function initServiceUrl(url:URI):void{
32                        if (userSpace) {
33                                url.setQueryValue(Config.PARAM_USERSPACE, "true");
34                        }
35                }
36               
37                /**
38                 * Override in concrete subclasses
39                 */
40                override protected function result(resultEvent:ResultEvent):void {
41                        dispatchEvent(new Event(ITEMS_LOADED));
42                }
43
44                protected function setItemDescriptions(items:ArrayCollection):void {
45                        itemDescriptions = items;
46                        unFilteredItemDescriptions = new ArrayCollection(); //create a copy
47                        for each (var item:Object in items) {
48                                unFilteredItemDescriptions.addItem(item);
49                        }
50                }
51
52                /**
53                 * Looks up itemDescription, returns null if not found.
54                 */
55                public function lookUpDescription(componentId:String):ItemDescription {
56                        for each (var item:ItemDescription in unFilteredItemDescriptions) {
57                                if (item.id == componentId) {
58                                        return item;
59                                }
60                        }
61                        return null;
62                }
63               
64               
65        }
66}
67
Note: See TracBrowser for help on using the repository browser.