source: ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/components/ExpandingComponentLabel.as @ 249

Last change on this file since 249 was 249, checked in by patdui, 14 years ago
  • created rightclick context menu "Edit..." works on profiles and components
File size: 2.9 KB
Line 
1package clarin.cmdi.componentregistry.common.components {
2        import clarin.cmdi.componentregistry.browser.CMDComponentXMLBrowser;
3        import clarin.cmdi.componentregistry.common.Component;
4        import clarin.cmdi.componentregistry.common.ItemDescription;
5        import clarin.cmdi.componentregistry.common.StyleConstants;
6        import clarin.cmdi.componentregistry.editor.CMDComponentXMLEditor;
7        import clarin.cmdi.componentregistry.editor.CMDSpecRenderer;
8        import clarin.cmdi.componentregistry.editor.model.CMDModelFactory;
9        import clarin.cmdi.componentregistry.services.ComponentInfoService;
10        import clarin.cmdi.componentregistry.services.ComponentListService;
11       
12        import flash.display.DisplayObject;
13        import flash.events.MouseEvent;
14       
15        import mx.containers.VBox;
16        import mx.controls.Alert;
17        import mx.controls.Label;
18
19        public class ExpandingComponentLabel extends VBox {
20
21                [Bindable]
22                public var isExpanded:Boolean = false;
23
24                private var expanded:DisplayObject;
25                private var componentId:String;
26                private var componentSrv:ComponentInfoService = new ComponentInfoService();
27
28                private var editable:Boolean;
29
30                public function ExpandingComponentLabel(componentId:String, editable:Boolean = false) {
31                        super();
32                        this.editable = editable;
33                        this.componentId = componentId;
34                        styleName = StyleConstants.EXPANDING_COMPONENT;
35                }
36
37                protected override function createChildren():void {
38                        super.createChildren();
39                        var id:Label = new Label();
40                        id.text = componentId;
41                        id.addEventListener(MouseEvent.CLICK, handleClick);
42                        id.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
43                        id.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
44                        addChild(id);
45                }
46
47                private function handleClick(event:MouseEvent):void {
48                        if (isExpanded) {
49                                unexpand();
50                                isExpanded = false;
51                        } else {
52                                expand();
53                        }
54                }
55
56
57                private function unexpand():void {
58                        if (expanded != null) {
59                                removeChild(expanded);
60                        }
61                }
62
63                private function expand():void {
64                        var item:ItemDescription = ComponentListService.instance.lookUpDescription(componentId);
65                        if (item != null) {
66                                componentSrv.addEventListener(ComponentInfoService.COMPONENT_LOADED, handleComponentLoaded);
67                                componentSrv.load(item);
68                        } else {
69                                Alert.show("Error: component cannot be found");
70                        }
71                }
72
73                private function handleComponentLoaded(event:Event):void {
74                        var comp:Component = componentSrv.component;
75                        if (editable) {
76                                expanded = new CMDComponentXMLEditor();
77                        } else {
78                                expanded = new CMDComponentXMLBrowser();
79                        }
80                        (expanded as CMDSpecRenderer).cmdSpec = CMDModelFactory.createModel(comp.componentMD.xml, comp.description);
81                        addChild(expanded);
82                        isExpanded = true;
83                }
84
85
86                private function mouseOver(event:MouseEvent):void {
87                        event.currentTarget.setStyle("color", "0x0000FF");
88                        event.currentTarget.setStyle("textDecoration", "underline");
89                }
90
91                private function mouseOut(event:MouseEvent):void {
92                        event.currentTarget.setStyle("color", "0x000000");
93                        event.currentTarget.setStyle("textDecoration", "none");
94                }
95
96        }
97}
Note: See TracBrowser for help on using the repository browser.