source: ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/editor/EditorAS.as @ 242

Last change on this file since 242 was 242, checked in by patdui, 14 years ago
  • added editing of components.
  • fixed bug in sharing of contextmenus in browser.
File size: 4.2 KB
Line 
1// ActionScript file
2import clarin.cmdi.componentregistry.browser.BrowserColumns;
3import clarin.cmdi.componentregistry.common.ItemDescription;
4import clarin.cmdi.componentregistry.editor.model.CMDAttribute;
5import clarin.cmdi.componentregistry.editor.model.CMDComponent;
6import clarin.cmdi.componentregistry.editor.model.CMDComponentElement;
7import clarin.cmdi.componentregistry.editor.model.CMDModelFactory;
8import clarin.cmdi.componentregistry.editor.model.CMDSpec;
9import clarin.cmdi.componentregistry.importer.UploadCompleteEvent;
10import clarin.cmdi.componentregistry.services.ComponentInfoService;
11import clarin.cmdi.componentregistry.services.ComponentListService;
12import clarin.cmdi.componentregistry.services.ProfileInfoService;
13import clarin.cmdi.componentregistry.services.UploadService;
14
15import flash.events.Event;
16import flash.net.FileReference;
17
18import mx.controls.Alert;
19import mx.core.DragSource;
20import mx.core.UIComponent;
21import mx.managers.DragManager;
22
23
24private var currentDescription:ItemDescription;
25private var profileSrv:ProfileInfoService = new ProfileInfoService();
26private var componentSrv:ComponentInfoService = new ComponentInfoService();
27
28[Bindable]
29private var componentsSrv:ComponentListService = new ComponentListService(); //Don't create an instance we need a new one
30
31[Bindable]
32public var cmdComponent:XML;
33
34[Bindable]
35private var cmdSpec:CMDSpec = new CMDSpec(true);
36
37[Bindable]
38private var browserColumns:BrowserColumns = new BrowserColumns();
39
40[Bindable]
41private var uploadService:UploadService = new UploadService();
42
43
44public function init():void {
45        profileSrv.addEventListener(ProfileInfoService.PROFILE_LOADED, profileLoaded);
46        componentsSrv.load();
47        uploadService.init(uploadProgress);
48}
49
50private function profileLoaded(event:Event):void {
51        var cmdComponent:XML = profileSrv.profile.profileSource;
52        this.cmdSpec = CMDModelFactory.createModel(cmdComponent);
53}
54
55public function setDescription(itemDescription:ItemDescription):void {
56        this.currentDescription = itemDescription;
57        if (currentDescription.isProfile) {
58                profileSrv.load(currentDescription);
59        }
60}
61
62public function clearEditor():void {
63        this.cmdSpec = new CMDSpec(true);
64}
65
66private var ref:FileReference = new FileReference();
67
68private function saveSpec():void {
69//      Alert.show(xmlEditor.cmdSpec.toXml());
70        var item:ItemDescription = new ItemDescription();
71        item.description = xmlEditor.cmdSpec.headerDescription;
72        item.name = xmlEditor.cmdSpec.headerName;
73        item.isProfile = xmlEditor.cmdSpec.isProfile;
74        item.groupName = xmlEditor.cmdSpec.groupName;
75        uploadService.addEventListener(UploadCompleteEvent.UPLOAD_COMPLETE, handleSaveComplete);
76        if (item.isProfile) {
77            uploadService.submitProfile(item, xmlEditor.cmdSpec.toXml());
78        } else {
79            uploadService.submitComponent(item, xmlEditor.cmdSpec.toXml());
80        }
81}
82
83private function handleSaveComplete(event:UploadCompleteEvent):void {
84        parentApplication.viewStack.switchToBrowse(event.itemDescription);
85}
86
87private function handleEditorChange(event:Event):void {
88        errorMessageField.text = "";
89        uploadProgress.visible = false;
90        uploadProgress.includeInLayout = false;
91}
92
93
94private function enableComponentDrag(event:MouseEvent):void {
95        var ds:DragSource = new DragSource();
96        ds.addHandler(function():CMDComponent {
97                        return new CMDComponent();
98                }, CMDComponentXMLEditor.DRAG_NEW_COMPONENT);
99        DragManager.doDrag(UIComponent(event.currentTarget), ds, event);
100}
101
102private function enableElementDrag(event:MouseEvent):void {
103        var ds:DragSource = new DragSource();
104        ds.addHandler(function():CMDComponentElement {
105                        return new CMDComponentElement();
106                }, CMDComponentXMLEditor.DRAG_NEW_ELEMENT);
107        DragManager.doDrag(UIComponent(event.currentTarget), ds, event);
108}
109
110private function enableAttributeDrag(event:MouseEvent):void {
111        var ds:DragSource = new DragSource();
112        ds.addHandler(function():CMDAttribute {
113                        return new CMDAttribute();
114                }, CMDComponentXMLEditor.DRAG_NEW_ATTRIBUTE);
115        DragManager.doDrag(UIComponent(event.currentTarget), ds, event);
116}
117
118private function initPaletteOverview():void {
119        componentsPaletteOverview.dataGrid.dragEnabled = true;
120        componentsPaletteOverview.dataGrid.allowMultipleSelection = true;
121        componentsPaletteOverview.dataGrid.horizontalScrollPolicy = "auto";
122        componentsPaletteOverview.dataGrid.resizableColumns = true;
123}
124
Note: See TracBrowser for help on using the repository browser.