Changeset 1255
- Timestamp:
- 04/28/11 13:19:50 (13 years ago)
- Location:
- ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/importer/Importer.mxml
r1254 r1255 9 9 <mx:Script> 10 10 <![CDATA[ 11 import clarin.cmdi.componentregistry.common.ComponentMD; 12 import clarin.cmdi.componentregistry.common.Profile; 11 13 import clarin.cmdi.componentregistry.services.Config; 12 14 import mx.events.ValidationResultEvent; … … 18 20 import mx.core.Application; 19 21 import clarin.cmdi.componentregistry.common.ItemDescription; 20 21 private static const BTN_PROFILE_LABEL:String = "Select profile xml..."; 22 private static const BTN_COMPONENT_LABEL:String = "Select component xml..."; 22 import mx.controls.Alert; 23 23 24 24 private var validators:ArrayCollection = new ArrayCollection(); … … 27 27 private var isProfile:Boolean = true; 28 28 [Bindable] 29 private var btnLabel:String = BTN_PROFILE_LABEL;29 private var importTypeString:String = ""; 30 30 31 31 private function submit(event:Event):void { … … 60 60 isProfile = isProfileValue; 61 61 if (isProfile) { 62 btnLabel = BTN_PROFILE_LABEL;62 importTypeString = "Profile"; 63 63 } else { 64 btnLabel = BTN_COMPONENT_LABEL;64 importTypeString = "Component"; 65 65 } 66 66 } … … 68 68 private function registryChange(event:UploadCompleteEvent):void { 69 69 parentApplication.viewStack.switchToBrowse(event.itemDescription); 70 } 71 72 private function fileLoaded(event:FileLoadedEvent):void { 73 var data:ByteArray = event.fileReference.data; 74 if (data && data.bytesAvailable) { 75 try { 76 var utfBytes:String = data.readUTFBytes(data.length); 77 var resultXml:XML = new XML(utfBytes); 78 79 // New file selected, clear all previous entries 80 clearForm(); 81 // Set import type (profile or component) from attribute in XML 82 setImportTypeFromFile(resultXml); 83 // Set name, description from values in XML 84 setFormFieldsFromFile(resultXml); 85 } catch (error:Error) { 86 Alert.show("Could not read the selected file. Not a valid XML file?", "Error"); 87 importTypeString = "Error"; 88 trace("Error while reading loaded file " + event.fileReference.name); 89 return; 90 } 91 } 92 } 93 94 private function setImportTypeFromFile(resultXml:XML):void { 95 if (resultXml.hasOwnProperty("@isProfile")) { 96 setIsProfile(("true" == resultXml.@isProfile)); 97 } else { 98 Alert.show("Unable to determine import type. Selected file may not be a valid component specification!", "Warning"); 99 importTypeString = "Unknown"; 100 } 101 } 102 103 private function setFormFieldsFromFile(resultXml:XML):void { 104 if (resultXml.hasOwnProperty("Header")) { 105 var nodes:XMLList = resultXml.Header; 106 if (nodes && nodes.length() > 0) { 107 var header:XML = nodes[0]; 108 nameInput.text = header.Name; 109 description.text = header.Description; 110 } 111 } 112 } 113 114 private function clearForm():void { 115 importTypeString = ""; 116 nameInput.text = ""; 117 description.text = ""; 118 groupName.text = ""; 119 domainName.selectedItem = null; 70 120 } 71 121 … … 97 147 98 148 <local:UploadService id="uploadSrv" 149 loadBeforeUploading="true" 150 fileLoaded="fileLoaded(event)" 99 151 uploadComplete="registryChange(event)"/> 100 152 <mx:VBox> 101 153 <mx:Form> 102 154 <mx:HBox> 103 <mx:FormHeading label="Import"/> 104 <mx:RadioButton groupName="importType" 105 id="profileType" 106 label="Profile" 107 click="setIsProfile(true)" 108 selected="true"/> 109 <mx:RadioButton groupName="importType" 110 id="componentType" 111 label="Component" 112 click="setIsProfile(false)"/> 113 </mx:HBox> 114 <mx:HBox> 115 <mx:Button label="{btnLabel}" 155 <mx:Button label="Select xml..." 116 156 id="btnSelect" 117 157 click="uploadSrv.selectXmlFile(event)" … … 121 161 </mx:HBox> 122 162 163 <mx:FormItem label="Type"> 164 <mx:Label id="importType" 165 text="{importTypeString}"/> 166 </mx:FormItem> 123 167 <mx:FormItem label="Name"> 124 168 <mx:TextInput id="nameInput" … … 140 184 </mx:FormItem> 141 185 <mx:FormItem label="Group Name"> 142 <mx:TextInput id="groupName" 143 creationComplete="registerIsRequiredValidator(event)"/> 186 <mx:TextInput id="groupName"/> 144 187 </mx:FormItem> 145 188 <mx:Button label="Submit" -
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/UploadService.as
r1086 r1255 1 1 package clarin.cmdi.componentregistry.services { 2 2 import clarin.cmdi.componentregistry.common.ItemDescription; 3 import clarin.cmdi.componentregistry.importer.FileLoadedEvent; 3 4 import clarin.cmdi.componentregistry.importer.UploadCompleteEvent; 4 5 … … 21 22 22 23 [Event(name="uploadComplete", type="clarin.cmdi.componentregistry.importer.UploadCompleteEvent")] 24 [Event(name="fileLoaded", type="clarin.cmdi.componentregistry.importer.FileLoadedEvent")] 23 25 public class UploadService { 24 26 … … 47 49 private var pb:ProgressBar; 48 50 private var ml:MultipartURLLoader; 51 private var _loadBeforeUploading:Boolean = false; 52 53 public function set loadBeforeUploading(lbu:Boolean):void { 54 _loadBeforeUploading = lbu; 55 } 49 56 50 57 public function init(progressBar:ProgressBar):void { … … 65 72 fileRef = new FileReference(); 66 73 fileRef.addEventListener(Event.SELECT, selectHandler); 67 //no uploads are done through FileRef only loads so this UPLOAD_COMPLETE_DATA event will not be thrown 68 //fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, responseHandler); 74 69 75 fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler); 70 76 fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 71 77 fileRef.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); 78 79 // If loading is enabled, register handler that will dispatch loadFile event 80 if (_loadBeforeUploading) { 81 fileRef.addEventListener(Event.COMPLETE, fileLoadedHandler); 82 } 72 83 } 73 84 … … 167 178 message = ""; 168 179 pb.visible = false; 180 if (_loadBeforeUploading) { 181 fileRef.load(); 182 } 183 } 184 185 private function fileLoadedHandler(event:Event):void { 186 dispatchEvent(new FileLoadedEvent(fileRef)); 169 187 } 170 188
Note: See TracChangeset
for help on using the changeset viewer.