Changeset 206


Ignore:
Timestamp:
03/03/10 12:01:16 (14 years ago)
Author:
patdui
Message:
  • added as3httpclient for doing http DELETE commands etc...
  • implemented editor
  • Using Basic Header security to authorize POST and DELETEs
  • renamed Register to Importer
Location:
ComponentRegistry/trunk/ComponentBrowserGui
Files:
19 added
2 deleted
18 edited
1 copied
3 moved

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentBrowserGui/pom.xml

    r168 r206  
    1111        <properties>
    1212          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     13          <targetPlayer>10.0.0</targetPlayer>
    1314        </properties>
    1415
     
    1718      <groupId>com.adobe.flex.framework</groupId>
    1819      <artifactId>flex-framework</artifactId>
    19       <version>3.2.0.3958</version>
     20      <version>3.5.0.12683</version>
    2021      <type>pom</type>
     22          <exclusions>
     23                <exclusion>
     24                  <groupId>com.adobe.flex.framework</groupId>
     25                  <artifactId>playerglobal</artifactId>
     26                </exclusion>
     27          </exclusions>     
    2128    </dependency>       
     29    <dependency>
     30      <groupId>com.adobe.flex.framework</groupId>
     31      <artifactId>playerglobal</artifactId>
     32      <version>3.5.0.12683</version>
     33      <classifier>10</classifier>
     34      <type>swc</type>
     35    </dependency>       
     36    <dependency>
     37      <groupId>org.httpclient</groupId>
     38      <artifactId>as3httpclientlib</artifactId>
     39      <version>1.0.6</version>
     40      <type>swc</type>
     41    </dependency>     
     42    <dependency>
     43      <groupId>com.adobe</groupId>
     44      <artifactId>as3corelib</artifactId>
     45      <version>0.92.1</version>
     46      <type>swc</type>
     47    </dependency>   
     48    <dependency>
     49      <groupId>com.hurlant</groupId>
     50      <artifactId>as3crypto</artifactId>
     51      <version>1.3</version>
     52      <type>swc</type>
     53    </dependency>   
    2254        </dependencies>
    2355
     
    2860                        <groupId>org.sonatype.flexmojos</groupId>
    2961                        <artifactId>flexmojos-maven-plugin</artifactId>
     62                        <version>3.5.0</version>
    3063                        <extensions>true</extensions>
    3164                        <configuration>
    3265                          <debug>true</debug>
    3366                        </configuration>
     67                <dependencies>
     68                  <dependency>
     69                <groupId>com.adobe.flex</groupId>
     70                    <artifactId>compiler</artifactId>
     71                <version>3.5.0.12683</version>
     72                    <type>pom</type>
     73              </dependency>
     74                </dependencies>
    3475                  </plugin>
    3576        </plugins>
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/Browse.mxml

    r134 r206  
    33                   xmlns:local="clarin.cmdi.componentregistry.services.*"
    44                   xmlns:browser="clarin.cmdi.componentregistry.browser.*"
     5                   initialize="init()"
    56                   creationComplete="refresh()"
    67                   width="100%"
    78                   height="100%"
    8                    label="Browse..."
    9                    >
     9                   label="Browse...">
    1010
    1111        <mx:Script>
    1212                <![CDATA[
    13                     import clarin.cmdi.componentregistry.services.ComponentListService;
     13                    import clarin.cmdi.componentregistry.common.components.RegistryViewStack;
     14                        import clarin.cmdi.componentregistry.common.components.BrowseContextMenu;
     15                        import clarin.cmdi.componentregistry.services.DeleteService;
     16                        import clarin.cmdi.componentregistry.services.ComponentListService;
    1417                        import clarin.cmdi.componentregistry.common.ItemDescription;
    1518                        import mx.controls.Alert;
    1619                        import clarin.cmdi.componentregistry.browser.BrowserSelectionEvent;
    1720                        import clarin.cmdi.componentregistry.common.Profile;
    18                        
     21
    1922                        [Bindable]
    2023                        private var componentsSrv:ComponentListService = ComponentListService.instance;
     24                        private var deleteSrv:DeleteService = new DeleteService();
     25                        [Bindable]
     26                        private var browseMenu:BrowseContextMenu
     27
     28                        public function init():void {
     29                            browseMenu = new BrowseContextMenu();
     30                                browseMenu.viewStack = this.parent as RegistryViewStack;
     31                                browseMenu.deleteService = deleteSrv;
     32                                deleteSrv.addEventListener(DeleteService.ITEM_DELETED, handleItemDeleted);
     33                        }
    2134
    2235                        public function refresh():void {
     
    3447
    3548                        public function setSelectedDescription(desc:ItemDescription):void {
    36                             if (desc.isProfile) {
    37                                 tabnav.selectedIndex = 0;
    38                             } else {
    39                                 tabnav.selectedIndex = 1; 
    40                             }
    41                             //Need to select the correct item, can't get it to highlight at the mo
    42                             //profilesOverview.dataGrid.selectedIndex=2;
    43                             //profilesOverview.dataGrid.validateNow();
    44                 //profilesOverview.dataGrid.scrollToIndex(2);
     49                                if (desc.isProfile) {
     50                                        tabnav.selectedIndex = 0;
     51                                } else {
     52                                        tabnav.selectedIndex = 1;
     53                                }
     54                                //Need to select the correct item, can't get it to highlight at the mo
     55                                //profilesOverview.dataGrid.selectedIndex=2;
     56                                //profilesOverview.dataGrid.validateNow();
     57                                //profilesOverview.dataGrid.scrollToIndex(2);
     58                        }
     59
     60                        private function handleItemDeleted(event:Event):void {
     61                                refresh();
    4562                        }
    4663                ]]>
     
    6279                                                 height="100%"
    6380                                                 color="0x323232"
    64                                                  y="59" borderStyle="outset">
     81                                                 y="59"
     82                                                 borderStyle="outset">
    6583                        <mx:VDividedBox label="Profiles"
    6684                                                        width="100%">
    6785                                <browser:BrowserOverviewList id="profilesOverview"
    68                                                                                   browserDataProvider="{profilesSrv.itemDescriptions}"
    69                                                                                   browserItemSelected="{loadProfileInfoPage(event)}"
    70                                                                                   browserColumns="{browserColumns.getProfileColumns()}"
    71                                                                                   width="100%"
    72                                                                                   height="70%"/>
     86                                                                                         browserDataProvider="{profilesSrv.itemDescriptions}"
     87                                                                                         browserItemSelected="{loadProfileInfoPage(event)}"
     88                                                                                         browserColumns="{browserColumns.getProfileColumns()}"
     89                                                                                         width="100%"
     90                                                                                         height="70%"
     91                                                                                         browseMenu="{browseMenu}"/>
    7392                                <browser:ProfileInfoPage id="profileInfoPage"
    74                                                                           profile="{profileSrv.profile}"
    75                                                                           width="100%"
    76                                                                           height="50%"/>
     93                                                                                profile="{profileSrv.profile}"
     94                                                                                width="100%"
     95                                                                                height="50%"/>
    7796                        </mx:VDividedBox>
    7897
     
    8099                                                        width="100%">
    81100                                <browser:BrowserOverviewList id="componentsOverview"
    82                                                                                   browserDataProvider="{componentsSrv.itemDescriptions}"
    83                                                                                   browserItemSelected="{loadComponentInfoPage(event)}"
    84                                                                                   browserColumns="{browserColumns.getComponentColumns()}"
    85                                                                                   width="100%"
    86                                                                                   height="50%"/>
     101                                                                                         browserDataProvider="{componentsSrv.itemDescriptions}"
     102                                                                                         browserItemSelected="{loadComponentInfoPage(event)}"
     103                                                                                         browserColumns="{browserColumns.getComponentColumns()}"
     104                                                                                         width="100%"
     105                                                                                         height="50%"
     106                                                                                         browseMenu="{browseMenu}"/>
    87107                                <browser:ComponentInfoPage id="componentInfoPage"
    88                                                                                 component="{componentSrv.component}"
    89                                                                                 width="100%"
    90                                                                                 height="50%"/>
     108                                                                                   component="{componentSrv.component}"
     109                                                                                   width="100%"
     110                                                                                   height="50%"/>
    91111
    92112                        </mx:VDividedBox>
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/BrowserOverviewList.mxml

    r161 r206  
    1616        <mx:Script>
    1717                <![CDATA[
     18                    import clarin.cmdi.componentregistry.common.components.BrowseContextMenu;
    1819                    import mx.collections.ArrayCollection;
    1920                        import mx.events.CollectionEvent;
     
    2223
    2324                        private var currentSelectedItem:ItemDescription;
    24 
     25                        [Bindable]
     26            private var menu:BrowseContextMenu;
    2527           
    2628                        private function dispatchBrowserSelectionEvent():void {
     
    3436                                }
    3537                        }
     38                       
     39                        public function set browseMenu(browseMenu:BrowseContextMenu):void {
     40                            this.menu = browseMenu;
     41                            menu.dataGrid= dataGrid;
     42                        }
     43                       
     44                        private function handleKeyUp(event:KeyboardEvent):void {
     45                            if (event.keyCode == Keyboard.DELETE) {
     46                                menu.deleteSelectedItems();
     47                            }
     48                        }
    3649                ]]>
    3750        </mx:Script>
    3851
    39         <comp:DownloadMenu id="menu"
    40                                            dataGrid="{dataGrid}" viewStack="{this.parentApplication.viewStack}"/>
    4152        <mx:HBox horizontalAlign="center"
    4253                         verticalAlign="middle"
     
    4758
    4859        <comp:FilteringDataGrid id="dataGrid"
    49                                  x="0"
    50                                  y="112"
    51                                  width="100%"
    52                                  height="100%"
    53                                  click="{dispatchBrowserSelectionEvent()}"
    54                                  dataProvider="{browserDataProvider}"
    55                                  columns="{browserColumns}"
    56                                  contextMenu="{menu.cm}"
    57                                  allowMultipleSelection="false"
    58                                  searchInput="{searchBox}"
    59                                 >
     60                                                        x="0"
     61                                                        y="112"
     62                                                        width="100%"
     63                                                        height="100%"
     64                                                        click="dispatchBrowserSelectionEvent()"
     65                                                        dataProvider="{browserDataProvider}"
     66                                                        columns="{browserColumns}"
     67                                                        contextMenu="{menu.cm}"
     68                                                        allowMultipleSelection="true"
     69                                                        searchInput="{searchBox}"
     70                                                        keyUp="handleKeyUp(event)">
    6071        </comp:FilteringDataGrid>
    6172</mx:VBox>
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/infoPage.mxml

    r161 r206  
    1010                         verticalAlign="middle"
    1111                         width="100%">
    12                 <mx:Label id="header"
     12                <mx:Label id="header"               
    1313                                  text="{headerLabel}"
    1414                                  fontWeight="bold"
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/xmlBrowsePanel.mxml

    r161 r206  
    22<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
    33                 xmlns:comp="clarin.cmdi.componentregistry.common.components.*" >
    4 
    5 <mx:Script>
    6     <![CDATA[
    7         // seting focus manually when a user clicks, this is the best I can do at the moment.
    8             //A form handles focus differently then for instance a list or a TextArea so scrolling using keys is a bit inconsistent among the different view at the moment.
    9                 private function setFocusOnClick(event:MouseEvent):void {
    10             setFocus();
    11                 }
    12     ]]>
    13 </mx:Script>
     4        <mx:Script>
     5            <![CDATA[
     6                import clarin.cmdi.componentregistry.editor.model.CMDModelFactory;
     7            ]]>
     8        </mx:Script>
    149
    1510        <mx:XML id="cmdComponent"/>
    1611        <comp:CMDComponentXMLBrowser id="xmlBrowse"
    17                                                                  xml="{cmdComponent}"
     12                                                                 cmdSpec="{CMDModelFactory.createModel(cmdComponent)}"
    1813                                                                 width="100%"
    1914                                                                 height="100%"
    20                                                                  click="setFocusOnClick(event);"
    2115                                                                 />
    2216</mx:Canvas>
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/ComponentMD.as

    r134 r206  
    2020            public static const ATTRIBUTE:String = "Attribute";
    2121            public static const ATTRIBUTE_LIST:String = "AttributeList";
     22            public static const DESCRIPTION:String = "Description";
    2223        //Attribute Names
    2324        public static const APP_INFO:String = "AppInfo";
     
    2526
    2627                public var name:String;
    27                 public var attributeList:XMLList;
    28                 public var cmdElements:Array = new Array();
    2928
    3029
     
    4241                }
    4342        }
    44 
     43   
    4544}
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/Profile.as

    r120 r206  
    66           
    77                public var description:ItemDescription;
    8                 public var components:ArrayCollection;
     8                public var components:ArrayCollection;//ComponentMD
    99                public var nrOfComponents:int;
    1010                public var profileSource:XML;
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/StyleConstants.as

    r161 r206  
    77                public static const XMLBROWSER_FIELD_VALUE:String = "xmlBrowserValueLabel";
    88                public static const XMLBROWSER_HEADER:String = "xmlBrowserHeader";
    9                 public static const XMLBROWSER_HEADER_CMD_ELEMENT:String = "xmlBrowserHeaderCmdelement";
     9                public static const XMLBROWSER_HEADER_SMALL:String = "xmlBrowserHeaderSmall";
    1010                public static const XMLEDITOR_EDIT_FIELD:String = "xmlEditorFieldEditField";
    1111                public static const EXPANDING_COMPONENT:String = "borderStyles";
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/components/BrowseContextMenu.as

    r121 r206  
    11package clarin.cmdi.componentregistry.common.components {
    22        import clarin.cmdi.componentregistry.common.ItemDescription;
    3         import clarin.cmdi.componentregistry.common.components.RegistryViewStack;
     3        import clarin.cmdi.componentregistry.services.DeleteService;
    44
    55        import flash.events.ContextMenuEvent;
     6        import flash.events.Event;
    67        import flash.events.MouseEvent;
    78        import flash.ui.ContextMenu;
    89        import flash.ui.ContextMenuItem;
    910
     11        import mx.controls.Alert;
    1012        import mx.controls.DataGrid;
    1113        import mx.events.ListEvent;
    1214
    1315
    14         public class DownloadMenu {
     16        public class BrowseContextMenu {
    1517
    1618                [Bindable]
     
    1921                [Bindable]
    2022                public var viewStack:RegistryViewStack;
     23                [Bindable]
     24                public var deleteService:DeleteService;
    2125
    2226                [Bindable]
     
    2630                private var saveItemDialog:SaveItemDialog = new SaveItemDialog();
    2731
    28                 public function DownloadMenu() {
     32                public function BrowseContextMenu() {
    2933                        cm = new ContextMenu();
    3034                        cm.hideBuiltInItems();
     
    4347                        cmi = new ContextMenuItem("Create New Profile...");
    4448                        cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, createNewProfile);
     49                        result.push(cmi);
     50                        cmi = new ContextMenuItem("Delete...");
     51                        cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleDelete);
    4552                        result.push(cmi);
    4653
     
    7784                }
    7885
     86                private function handleDelete(event:ContextMenuEvent):void {
     87                    deleteSelectedItems();
     88                }
     89               
     90                public function deleteSelectedItems():void {
     91                        for each (var item:ItemDescription in _dataGrid.selectedItems) {
     92                                deleteService.deleteItem(item);
     93                        }
     94                }
     95
    7996        }
    8097}
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/components/CMDComponentXMLBrowser.as

    r134 r206  
    55        import flash.display.DisplayObject;
    66
    7         import mx.containers.FormItem;
     7        import mx.collections.XMLListCollection;
    88        import mx.controls.ComboBox;
    99
     
    1515
    1616                public function CMDComponentXMLBrowser() {
     17                    super();
    1718                        styleName = StyleConstants.XMLBROWSER;
    1819                }
    1920
    20                 protected override function handleCMDAttributeList(atributeList:XML):void {
    21                         for each (var cmdAttribute:XML in atributeList.descendants(ComponentMD.ATTRIBUTE)) {
    22                                 handleCMDAttributes(cmdAttribute.elements());
    23                         }
    24                 }
    25 
    26                 private function handleCMDAttributes(cmdAttribute:XMLList):void {
    27                         var name:FormItem = createFormItem(cmdAttribute[0].name(), cmdAttribute[0].text()); //The name
    28                         addFormChild(name);
    29                         var item:FormItem = createFormItem(cmdAttribute[1].name(), cmdAttribute[1].text(), cmdAttribute[1]); //type or valueScheme
    30                         addFormChild(item);
    31                 }
    32 
    33                 protected override function createFormItemFieldValue(name:String, value:String, xmlElement:XML = null):DisplayObject {
    34                         if (name == ComponentMD.CONCEPTLINK) {
     21                protected override function createFormItemFieldValue(name:String, value:String):DisplayObject {
     22                        if (name == CONCEPTLINK) {
    3523                                return createConceptLinkLabel(value);
    36                         } else if (name == ComponentMD.COMPONENTID) {
     24                        } else if (name == COMPONENT_ID) {
    3725                                return createComponentIdLabel(value);
    38                         } else if (name == ComponentMD.VALUE_SCHEME && xmlElement != null) {
    39                             if (xmlElement.hasOwnProperty(ComponentMD.ENUMERATION)) {
    40                                     return createEnumeration(xmlElement.elements(ComponentMD.ENUMERATION));
    41                             } else {
    42                                 return super.createFormItemFieldValue(name, xmlElement.elements(ComponentMD.PATTERN)[0].text());
    43                             }
    4426                        } else {
    4527                                return super.createFormItemFieldValue(name, value);
     
    6042                }
    6143
    62 
    63                 private function createEnumeration(enumeration:XMLList):DisplayObject {
    64                         var result:ComboBox = new ComboBox();
    65                         result.dataProvider = enumeration.item;
    66                         result.labelFunction = function(item:Object):String {
    67                                 var xmlItem:XML = item as XML;
    68                                 if (item..hasOwnProperty("@" + ComponentMD.APP_INFO)) {
    69                                         return xmlItem.attribute(ComponentMD.APP_INFO) + " - " + xmlItem.text();
    70                                 } else {
    71                                         return xmlItem.text();
    72                                 }
    73                         };
    74                         return result;
    75                 }
    76 
    7744        }
    7845}
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/components/CMDComponentXMLEditor.as

    r134 r206  
    11package clarin.cmdi.componentregistry.common.components {
    2         import clarin.cmdi.componentregistry.common.ComponentMD;
     2        import clarin.cmdi.componentregistry.editor.CMDSpecRenderer;
     3        import clarin.cmdi.componentregistry.common.ItemDescription;
    34        import clarin.cmdi.componentregistry.common.StyleConstants;
     5        import clarin.cmdi.componentregistry.editor.ComponentEdit;
     6        import clarin.cmdi.componentregistry.editor.FormItemInputLine;
     7        import clarin.cmdi.componentregistry.editor.FormItemInputText;
     8        import clarin.cmdi.componentregistry.editor.model.CMDComponent;
     9        import clarin.cmdi.componentregistry.editor.model.CMDSpec;
    410       
    511        import flash.display.DisplayObject;
     12        import flash.events.Event;
     13        import flash.events.MouseEvent;
     14        import flash.utils.getTimer;
    615       
     16        import mx.collections.ArrayCollection;
     17        import mx.containers.Form;
    718        import mx.containers.FormItem;
    8 
    9         public class CMDComponentXMLEditor extends XMLBrowser {
    10 
     19        import mx.controls.Button;
     20        import mx.core.Container;
     21        import mx.core.UIComponent;
     22        import mx.events.ChildExistenceChangedEvent;
     23        import mx.events.DragEvent;
     24        import mx.managers.DragManager;
     25        import mx.managers.IFocusManagerComponent;
     26
     27    [Event(name="editorChange", type="flash.events.Event")]
     28        public class CMDComponentXMLEditor extends Form implements IFocusManagerComponent, CMDSpecRenderer {
     29
     30        public static const EDITOR_CHANGE_EVENT:String = "editorChange";
     31                private var _spec:CMDSpec;
    1132
    1233                public function CMDComponentXMLEditor() {
     34                        super();
     35                        focusEnabled = true;
     36                        tabEnabled = true;
    1337                        styleName = StyleConstants.XMLBROWSER;
    14                 }
    15 
    16                 protected override function createFormItem(name:String, value:String = null, xmlElement:XML = null):FormItem {
    17                         var component:FormItem;
    18                         if (name == ComponentMD.COMPONENTID) {
    19                                 component = createComponentIdLabel(name, value);
     38                        addEventListener(DragEvent.DRAG_ENTER, dragEnterHandler);
     39                        addEventListener(DragEvent.DRAG_OVER, dragOverHandler);
     40                        addEventListener(DragEvent.DRAG_DROP, dragDropHandler);
     41                        addEventListener(ChildExistenceChangedEvent.CHILD_ADD, dispatchEditorChangeEvent);
     42                        addEventListener(ChildExistenceChangedEvent.CHILD_REMOVE, dispatchEditorChangeEvent);
     43                }
     44
     45                private function dragEnterHandler(event:DragEvent):void {
     46                        DragManager.acceptDragDrop(event.currentTarget as UIComponent);
     47                        UIComponent(event.currentTarget).drawFocus(true);
     48                }
     49
     50                private function dragOverHandler(event:DragEvent):void {
     51                        if (event.dragSource.hasFormat("items")) {
     52                                DragManager.showFeedback(DragManager.COPY);
     53                        }
     54                }
     55
     56                private function dragDropHandler(event:DragEvent):void {
     57                        var items:Array = event.dragSource.dataForFormat("items") as Array;
     58                        for each (var item:ItemDescription in items) {
     59                                var comp:CMDComponent = new CMDComponent();
     60                                comp.componentId = item.id;
     61                                _spec.cmdComponents.addItem(comp);
     62                                addComponent(comp);
     63                        }
     64                }
     65
     66                public function set cmdSpec(cmdSpec:CMDSpec):void {
     67                        _spec = cmdSpec;
     68                        createNewBrowser();
     69                        dispatchEditorChangeEvent();
     70                }
     71               
     72                private function dispatchEditorChangeEvent(event:Event=null):void {
     73                    dispatchEvent(new Event(EDITOR_CHANGE_EVENT));
     74                }
     75
     76                [Bindable]
     77                public function get cmdSpec():CMDSpec {
     78                        return _spec;
     79                }
     80
     81                private function createNewBrowser():void {
     82                        var start:int = getTimer();
     83                        removeAllChildren()
     84                        handleHeader(_spec);
     85                        handleComponents(_spec.cmdComponents);
     86                        trace("Created browser2 view in " + (getTimer() - start) + " ms.");
     87                }
     88
     89                private function handleHeader(spec:CMDSpec):void {
     90                        addChild(createHeading());
     91                        addChild(new FormItemInputLine("Name", spec.headerName, function(val:String):void {
     92                                        spec.headerName = val;
     93                                }));
     94                        addChild(new FormItemInputLine("Id", spec.headerId, function(val:String):void {
     95                                        spec.headerId = val;
     96                                }));
     97                        addChild(new FormItemInputText(XMLBrowser.DESCRIPTION, spec.headerDescription, function(val:String):void {
     98                                        spec.headerDescription = val;
     99                                }));
     100                }
     101
     102                private function createHeading():FormItem {
     103                        var heading:FormItem = new FormItem();
     104                        heading.label = "Header";
     105                        heading.styleName = StyleConstants.XMLBROWSER_HEADER;
     106                        return heading;
     107                }
     108
     109                private function handleComponents(components:ArrayCollection):void {
     110                        for each (var component:CMDComponent in components) {
     111                                addComponent(component);
     112                        }
     113                        var btn:Button = new Button();
     114                        btn.label = "add Component";
     115                        btn.addEventListener(MouseEvent.CLICK, handleAddComponentClick);
     116                        btn.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void {drawFocus(true);});
     117                        btn.addEventListener(MouseEvent.MOUSE_OUT, function(event:MouseEvent):void {drawFocus(false);});
     118                        addChild(btn);
     119                }
     120               
     121                private function handleAddComponentClick(event:MouseEvent):void {
     122                        var comp:CMDComponent = new CMDComponent();
     123                        _spec.cmdComponents.addItem(comp);
     124                        var index:int = getChildIndex(event.currentTarget as DisplayObject);
     125                        addComponent(comp, index);
     126                }
     127               
     128
     129               
     130                public function addComponent(component:CMDComponent, index:int=-1):void {
     131                        var comp:Container = new ComponentEdit(component, this);
     132                        comp.addEventListener(ComponentEdit.REMOVE_COMPONENT_EVENT, removeComponent);
     133                        if (index == -1) {
     134                            addChild(comp);
    20135                        } else {
    21                                 component = createDefaultEditField(name, value, xmlElement);
    22                         }
    23                         return component;
    24                 }
    25 
    26 
    27                 private function createDefaultEditField(name:String, value:String, xmlElement:XML):FormItem {
    28                         var field:XMLEditorField = new XMLEditorField(xmlElement, name);
    29                         field.label = name;
    30                         field.styleName = StyleConstants.XMLBROWSER_FIELD;
    31                         field.editField = value;
    32                         return field;
    33                 }
    34 
    35                 private function createComponentIdLabel(name:String, value:String):FormItem {
    36                         var fi:FormItem = new FormItem();
    37                         fi.label = name;
    38                         fi.styleName = StyleConstants.XMLBROWSER_FIELD;
    39                         var componentLabel:ExpandingComponentLabel = new ExpandingComponentLabel(value, true);
    40                         fi.addChild(componentLabel);
    41                         return fi;
    42                 }
    43 
     136                            addChildAt(comp, index);
     137                        }
     138                }
     139
     140        private function removeComponent(event:Event):void {
     141            var comp:CMDComponent = ComponentEdit(event.currentTarget).component;
     142            _spec.removeComponent(comp);
     143            removeChild(event.currentTarget as DisplayObject);
     144        }
     145       
     146//              protected override function createFormHeading(name:String):UIComponent {
     147//                      var heading:UIComponent = super.createFormHeading(name);
     148//                      if (name == COMPONENT) {
     149//                              var editBar:HBox = new HBox();
     150//                              editBar.addChild(heading);
     151//                              editBar.percentWidth = 100;
     152//                              var spacer:Spacer = new Spacer();
     153//                              spacer.percentWidth = 90;
     154//                              editBar.addChild(spacer);
     155//                              var removeButton:Button = new Button();
     156//                              removeButton.height = 20;
     157//                              removeButton.label = "X";
     158//                              removeButton.addEventListener(MouseEvent.CLICK, removeComponent);
     159//                              editBar.addChild(removeButton);
     160//                              return editBar;
     161//                      } else {
     162//                              return heading;
     163//                      }
     164//              }
     165//
     166//              protected override function createAndAddFormChild(name:String, value:String, bindingFunction:Function = null):void {
     167//                      addFormChild(createFormItem(name, value, bindingFunction)); //Always add all children so they can be edited
     168//              }
     169//
     170//              private function removeComponent(event:MouseEvent):void {
     171//                      Alert.show("Fire remove!");
     172//              }
     173//
     174//              protected override function createFormItemFieldValue(name:String, value:String, bindingFunction:Function = null):DisplayObject {
     175//                      if (name == COMPONENT_ID) {
     176//                              return createComponentIdLabel(value);
     177//                      } else {
     178//                              return createDefaultEditField(name, value, bindingFunction);
     179//                      }
     180//              }
     181//
     182//              private function createDefaultEditField(name:String, value:String, bindingFunction:Function = null):UIComponent {
     183//                      var result:UIComponent;
     184//                      if (name == DESCRIPTION) {
     185//                              var editArea:TextArea = new TextArea();
     186//                              editArea.text = value;
     187//                              editArea.styleName = StyleConstants.XMLEDITOR_EDIT_FIELD;
     188//                              editArea.width = 400;
     189//                              result = editArea;
     190//                      } else {
     191//                              var editField:TextInput = new TextInput();
     192//                              editField.text = value;
     193//                              editField.styleName = StyleConstants.XMLEDITOR_EDIT_FIELD;
     194//                              editField.width = 400;
     195//                              result = editField;
     196//                              BindingUtils.bindSetter(bindingFunction, editField, "text");
     197//                      }
     198//                      return result;
     199//              }
     200//
     201//              private function createComponentIdLabel(value:String):ExpandingComponentLabel {
     202//                      var componentLabel:ExpandingComponentLabel = new ExpandingComponentLabel(value, true);
     203//                      return componentLabel;
     204//              }
     205//
    44206        }
    45207
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/components/ExpandingComponentLabel.as

    r161 r206  
    11package clarin.cmdi.componentregistry.common.components {
     2        import clarin.cmdi.componentregistry.editor.CMDSpecRenderer;
    23        import clarin.cmdi.componentregistry.common.Component;
    34        import clarin.cmdi.componentregistry.common.ItemDescription;
    45        import clarin.cmdi.componentregistry.common.StyleConstants;
     6        import clarin.cmdi.componentregistry.editor.model.CMDModelFactory;
    57        import clarin.cmdi.componentregistry.services.ComponentInfoService;
    68        import clarin.cmdi.componentregistry.services.ComponentListService;
     
    2729                        super();
    2830                        this.editable = editable;
     31                        this.componentId = componentId;
     32                        styleName = StyleConstants.EXPANDING_COMPONENT;
     33                }
     34               
     35                protected override function createChildren():void {
     36            super.createChildren();
    2937                        var id:Label = new Label();
    3038                        id.text = componentId;
    31                         this.componentId = componentId;
    32                         addChild(id);
    3339                        id.addEventListener(MouseEvent.CLICK, handleClick);
    3440                        id.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
    3541                        id.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
    36                         styleName = StyleConstants.EXPANDING_COMPONENT;
     42                    addChild(id);
    3743                }
    38 
     44               
    3945                private function handleClick(event:MouseEvent):void {
    4046                        if (isExpanded) {
     
    4854
    4955                private function unexpand():void {
    50                     if (expanded != null) {
    51                             removeChild(expanded);
     56                        if (expanded != null) {
     57                                removeChild(expanded);
    5258                        }
    5359                }
     
    5662                        var item:ItemDescription = ComponentListService.instance.lookUpDescription(componentId);
    5763                        if (item != null) {
    58                             componentSrv.addEventListener(ComponentInfoService.COMPONENT_LOADED, handleComponentLoaded);
    59                             componentSrv.load(item);
     64                                componentSrv.addEventListener(ComponentInfoService.COMPONENT_LOADED, handleComponentLoaded);
     65                                componentSrv.load(item);
    6066                        } else {
    61                             Alert.show("Error: component cannot be found");
     67                                Alert.show("Error: component cannot be found");
    6268                        }
    6369                }
     
    6571                private function handleComponentLoaded(event:Event):void {
    6672                        var comp:Component = componentSrv.component;
    67                         var expandedComponent:XMLBrowser;
    6873                        if (editable) {
    69                                 expandedComponent = new CMDComponentXMLEditor();
     74                                expanded = new CMDComponentXMLEditor();
    7075                        } else {
    71                                 expandedComponent = new CMDComponentXMLBrowser();
     76                                expanded = new CMDComponentXMLBrowser();
    7277                        }
    73                         expandedComponent.xml = comp.componentMD.xml;
    74                         expanded = expandedComponent;
     78                        (expanded as CMDSpecRenderer).cmdSpec = CMDModelFactory.createModel(comp.componentMD.xml);
    7579                        addChild(expanded);
    7680                        isExpanded = true;
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/components/RegistryViewStack.as

    r134 r206  
    44        import clarin.cmdi.componentregistry.common.Login;
    55        import clarin.cmdi.componentregistry.editor.Editor;
    6         import clarin.cmdi.componentregistry.register.Register;
    7 
     6        import clarin.cmdi.componentregistry.importer.Importer;
     7       
    88        import flash.display.DisplayObject;
    99        import flash.events.Event;
    10 
     10       
    1111        import mx.containers.ViewStack;
    12         import mx.events.FlexEvent;
    1312
    1413        public class RegistryViewStack extends ViewStack {
    1514                private var browse:Browse = new Browse();
    16                 private var register:Register = new Register();
     15                private var importer:Importer = new Importer();
    1716                private var editor:Editor = new Editor();
    1817
     
    2625                        addChild(browse); //everyone can browse
    2726
    28                         register.addEventListener(FlexEvent.SHOW, checkLogin);
    29                         addChild(register);
     27                        //register.addEventListener(FlexEvent.SHOW, checkLogin);
     28                        addChild(importer);
    3029
    31                         editor.addEventListener(FlexEvent.SHOW, checkLogin);
     30//                      editor.addEventListener(FlexEvent.SHOW, checkLogin);
    3231                        addChild(editor);
    3332                }
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/editor/Editor.mxml

    r134 r206  
    77                   height="100%"
    88                   label="Editor..."
    9                    creationComplete="{init();}">
     9                   creationComplete="init()">
    1010
    1111        <mx:Script source="EditorAS.as"/>
     
    1919                                           label="createEmptyProfile"
    2020                                           click="createEmptyProfile()"/>
     21                        <mx:Button id="saveBtn"
     22                                           label="save"
     23                                           click="saveProfile()"/>
    2124                </mx:HBox>
     25        <mx:Text id="errorMessageField"
     26                                         text="{uploadService.message}" visible='{uploadService.message != ""}' includeInLayout='{uploadService.message != ""}' />
     27                <mx:ProgressBar id="uploadProgress"
     28                                                        label=""
     29                                                        mode="manual"
     30                                                        visible="false"
     31                                                        includeInLayout="false"/>
    2232
    23                 <mx:HBox width="100%"
     33                <mx:VBox width="100%"
    2434                                 height="80%">
    2535                        <comp:CMDComponentXMLEditor id="xmlEditor"
    26                                                                                 xml="{cmdComponent}"
     36                                                                                cmdSpec="{cmdSpec}"
    2737                                                                                width="50%"
    28                                                                                 dragEnter="{dragEnterHandler(event)}"
    29                                                                                 dragOver="{dragOverHandler(event)}"
    30                                                                                 dragDrop="{dragDropHandler(event)}"
    31                                                                                 toolTip="drag components from list to add..."/>
     38                                                                                toolTip="drag components from list to add..." editorChange="handleEditorChange(event)" />
    3239                        <mx:DataGrid id="dataGrid"
    33                                                  width="100%"
     40                                                 width="50%"
    3441                                                 dragEnabled="true"
    3542                                                 dataProvider="{componentsSrv.itemDescriptions}"
     
    3744                                                 allowMultipleSelection="true"/>
    3845
    39                 </mx:HBox>
    40                 <!--<mx:HBox width="100%"
     46                </mx:VBox>
     47                <mx:HBox width="100%"
    4148                                 height="300">
    42                         <comp:XMLTextArea id="textView"
    43                                                           styleName="xmlTextArea"
    44                                                           editable="true"
    45                                                           xmlData="{cmdComponent}"
    46                                                           width="50%"
    47                                                           height="300"/>
    4849                        <comp:ScrollableTextArea id="infoTextArea"
    4950                                                                         styleName="xmlTextArea"
    5051                                                                         editable="false"
    51                                                                          text="{cmdComponent}"
     52                                                                         text="{cmdSpec.toXml()}"
    5253                                                                         width="50%"
    5354                                                                         height="300"/>
    54                 </mx:HBox>-->
     55                </mx:HBox>
    5556        </mx:VBox>
    5657
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/editor/EditorAS.as

    r134 r206  
    22import clarin.cmdi.componentregistry.browser.BrowserColumns;
    33import clarin.cmdi.componentregistry.common.ItemDescription;
     4import clarin.cmdi.componentregistry.editor.model.CMDModelFactory;
     5import clarin.cmdi.componentregistry.editor.model.CMDSpec;
     6import clarin.cmdi.componentregistry.importer.UploadCompleteEvent;
    47import clarin.cmdi.componentregistry.services.ComponentInfoService;
    58import clarin.cmdi.componentregistry.services.ComponentListService;
    69import clarin.cmdi.componentregistry.services.ProfileInfoService;
     10import clarin.cmdi.componentregistry.services.UploadService;
    711
    812import flash.events.Event;
     13import flash.net.FileReference;
    914
    10 import mx.core.UIComponent;
    11 import mx.events.DragEvent;
    12 import mx.managers.DragManager;
    1315
    1416private var currentDescription:ItemDescription;
     
    1921private var componentsSrv:ComponentListService = ComponentListService.instance;
    2022
    21 
    22 private static const emptyProfile:XML = <CMD_ComponentSpec isProfile="true">
    23                 <Header>
    24                         <ID>p_1234</ID>
    25                         <Name>Profile1</Name>
    26                         <Description>MyDesc</Description>
    27                 </Header>
    28         </CMD_ComponentSpec>;
    29 
     23[Bindable]
     24public var cmdComponent:XML;
    3025
    3126[Bindable]
    32 public var cmdComponent:XML = emptyProfile;
     27private var cmdSpec:CMDSpec = new CMDSpec(true);
    3328
    3429[Bindable]
    3530private var browserColumns:BrowserColumns = new BrowserColumns();
     31
     32[Bindable]
     33private var uploadService:UploadService = new UploadService();
    3634
    3735
     
    3937        profileSrv.addEventListener(ProfileInfoService.PROFILE_LOADED, profileLoaded);
    4038        componentsSrv.load();
    41 }
    42 
    43 private function dragEnterHandler(event:DragEvent):void {
    44         DragManager.acceptDragDrop(event.currentTarget as UIComponent);
    45 }
    46 
    47 private function dragOverHandler(event:DragEvent):void {
    48         if (event.dragSource.hasFormat("items")) {
    49                 DragManager.showFeedback(DragManager.COPY);
    50         }
    51 }
    52 
    53 private function dragDropHandler(event:DragEvent):void {
    54         var items:Array = event.dragSource.dataForFormat("items") as Array;
    55         addComponents(items);
     39        uploadService.init(uploadProgress);
    5640}
    5741
    5842private function profileLoaded(event:Event):void {
    59         cmdComponent = profileSrv.profile.profileSource;
     43        var cmdComponent:XML = profileSrv.profile.profileSource;
     44        this.cmdSpec = CMDModelFactory.createModel(cmdComponent);
    6045}
    6146
     
    6853
    6954public function createEmptyProfile():void {
    70         cmdComponent = <CMD_ComponentSpec isProfile="true">
    71                         <Header>
    72                                 <ID>p_1</ID>
    73                                 <Name>Profile1</Name>
    74                                 <Description>MyDesc</Description>
    75                         </Header>
    76                 </CMD_ComponentSpec>;
     55        this.cmdSpec = new CMDSpec(true);
    7756}
    7857
    79 public function addComponents(items:Array):void {
    80         var temp:XML = xmlEditor.xml.copy();
    81         for each (var item:ItemDescription in items) {
    82             var comp:XML =<CMD_Component ComponentId={item.id}/>
    83                 temp.appendChild(comp);
    84         }
    85         cmdComponent = temp;
     58private var ref:FileReference = new FileReference();
     59
     60private function saveProfile():void {
     61        //Alert.show(xmlEditor.cmdSpec.toXml());
     62        var item:ItemDescription = new ItemDescription();
     63        item.description = xmlEditor.cmdSpec.headerDescription;
     64        item.name = xmlEditor.cmdSpec.headerName;
     65        item.isProfile = xmlEditor.cmdSpec.isProfile;
     66        uploadService.addEventListener(UploadCompleteEvent.UPLOAD_COMPLETE, handleSaveComplete);
     67        uploadService.submitProfile(item, xmlEditor.cmdSpec.toXml());
     68}
     69
     70private function handleSaveComplete(event:UploadCompleteEvent):void {
     71        parentApplication.viewStack.switchToBrowse(event.itemDescription);
     72}
     73
     74private function handleEditorChange(event:Event):void {
     75        errorMessageField.text = "";
     76        uploadProgress.visible = false;
     77        uploadProgress.includeInLayout = false;
    8678}
    8779
    8880
    8981
    90 
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/editor/model/CMDComponentElement.as

    r134 r206  
    1 package clarin.cmdi.componentregistry.common {
     1package clarin.cmdi.componentregistry.editor.model {
     2        import clarin.cmdi.componentregistry.common.XmlAble;
     3
     4        import mx.collections.ArrayCollection;
    25        import mx.collections.XMLListCollection;
    36
    4         [Bindable]
    5         public class ComponentElement {
     7        public class CMDComponentElement implements XmlAble {
    68
     9                //Attributes
    710                public var name:String;
    8                 public var valueScheme:Object;
    911                public var conceptLink:String;
     12                public var valueSchemeSimple:String;
     13                public var cardinalityMin:String = "1";
     14                public var cardinalityMax:String = "1";
    1015
    11                 public function ComponentElement() {
     16
     17                //elements
     18                public var attributeList:ArrayCollection = new ArrayCollection();
     19                public var valueSchemeComplex:XMLListCollection;
     20
     21                public function CMDComponentElement() {
    1222                }
    1323
    14                 private static function setValueScheme(value:XML, item:ComponentElement):void {
    15                         if (value.hasOwnProperty(ComponentMD.VALUE_SCHEME)) {
    16                                 if (value.ValueScheme.hasOwnProperty(ComponentMD.PATTERN)) {
    17                                         var d:Object = value.ValueScheme.pattern
    18                                         item.valueScheme = d.name() + "(" + d.text().toXMLString() + ")";
    19                                 } else if (value.ValueScheme.hasOwnProperty(ComponentMD.ENUMERATION)) {
    20                                         item.valueScheme = new XMLListCollection(value.ValueScheme.enumeration.*);
    21                                 }
    22                         } else if (value.hasOwnProperty("@"+ComponentMD.VALUE_SCHEME)) {
    23                                 item.valueScheme = value.@ValueScheme;
    24                         } else if (value.hasOwnProperty(ComponentMD.TYPE)) {
    25                                 item.valueScheme = value.Type;
    26                         }
    27                 }
    2824
    29                 public static function createAttributeItem(attribute:XML):ComponentElement {
    30                         var item:ComponentElement = new ComponentElement();
    31                         item.name = attribute.Name;
    32                         item.valueScheme = attribute.Type;
    33                         return item;
    34                 }
    3525
    36                 public static function createElementItem(element:XML):ComponentElement {
    37                         var item:ComponentElement = new ComponentElement();
    38                         item.name = element.@name;
    39                         setValueScheme(element, item);
    40                         item.conceptLink = element.@ConceptLink;
    41                         return item;
     26                public function toXml():XML {
     27                        return <CMD_Element></CMD_Element>;//TODO PD implement
    4228                }
    4329
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/importer/Importer.mxml

    r117 r206  
    44                   width="100%"
    55                   height="100%"
    6                    label="Register...">
     6                   label="Import...">
    77
    88        <mx:Script>
     
    1010                        import clarin.cmdi.componentregistry.common.ItemDescription;
    1111
    12                         private static const BTN_PROFILE_LABEL:String = "Select profile xml..";
    13                         private static const BTN_COMPONENT_LABEL:String = "Select component xml..";
     12                        private static const BTN_PROFILE_LABEL:String = "Select profile xml...";
     13                        private static const BTN_COMPONENT_LABEL:String = "Select component xml...";
    1414
    1515                        [Bindable]
     
    2121                                var item:ItemDescription = new ItemDescription();
    2222                                item.description = description.text;
    23                                 item.creatorName = creatorName.text;
    2423                                item.name = nameInput.text;
    2524                                item.isProfile = isProfile;
     
    5251                <mx:Form>
    5352                        <mx:HBox>
    54                                 <mx:FormHeading label="Register"/>
    55                                 <mx:RadioButton groupName="registerType"
     53                                <mx:FormHeading label="Import"/>
     54                                <mx:RadioButton groupName="importType"
    5655                                                                id="profileType"
    5756                                                                label="Profile"
    5857                                                                click="setIsProfile(true)"
    5958                                                                selected="true"/>
    60                                 <mx:RadioButton groupName="registerType"
     59                                <mx:RadioButton groupName="importType"
    6160                                                                id="componentType"
    6261                                                                label="Component"
     
    7877                        </mx:FormItem>
    7978                        <mx:FormItem label="Creator Name">
    80                                 <mx:TextInput id="creatorName"/>
     79                                <mx:Text id="creatorName" text="loginName"/>
    8180                        </mx:FormItem>
    8281                        <mx:FormItem label="Group Name"
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/importer/UploadCompleteEvent.as

    r117 r206  
    1 package clarin.cmdi.componentregistry.register {
     1package clarin.cmdi.componentregistry.importer {
    22        import clarin.cmdi.componentregistry.common.ItemDescription;
    33
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/ProfileInfoService.as

    r121 r206  
    33        import clarin.cmdi.componentregistry.common.ItemDescription;
    44        import clarin.cmdi.componentregistry.common.Profile;
    5 
     5       
    66        import flash.events.Event;
    7 
     7        import flash.events.EventDispatcher;
     8       
    89        import mx.collections.ArrayCollection;
    910        import mx.messaging.messages.HTTPRequestMessage;
     
    1617
    1718        [Event(name="ProfileLoaded", type="flash.events.Event")]
    18         public class ProfileInfoService {
     19        public class ProfileInfoService  extends EventDispatcher {
    1920                public static const PROFILE_LOADED:String = "ProfileLoaded";
    2021
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/UploadService.as

    r117 r206  
    11package clarin.cmdi.componentregistry.services {
    22        import clarin.cmdi.componentregistry.common.ItemDescription;
    3         import clarin.cmdi.componentregistry.register.UploadCompleteEvent;
     3        import clarin.cmdi.componentregistry.importer.UploadCompleteEvent;
     4
     5        import com.adobe.net.URI;
     6        import com.hurlant.util.Base64;
    47
    58        import flash.events.DataEvent;
    69        import flash.events.Event;
    710        import flash.events.HTTPStatusEvent;
     11        import flash.events.IOErrorEvent;
    812        import flash.events.ProgressEvent;
     13        import flash.events.SecurityErrorEvent;
    914        import flash.net.FileFilter;
    1015        import flash.net.FileReference;
    1116        import flash.net.URLRequest;
    12         import flash.net.URLRequestMethod;
    1317        import flash.net.URLVariables;
    1418
    1519        import mx.controls.ProgressBar;
    16         import mx.core.UIComponent;
    17 
    18         [Event(name="uploadComplete", type="clarin.cmdi.componentregistry.register.UploadCompleteEvent")]
    19         public class UploadService  {
     20
     21        import org.httpclient.HttpClient;
     22        import org.httpclient.events.HttpDataEvent;
     23        import org.httpclient.events.HttpErrorEvent;
     24        import org.httpclient.events.HttpStatusEvent;
     25        import org.httpclient.http.Post;
     26        import org.httpclient.http.multipart.Multipart;
     27        import org.httpclient.http.multipart.Part;
     28
     29        [Event(name="uploadComplete", type="clarin.cmdi.componentregistry.importer.UploadCompleteEvent")]
     30        public class UploadService {
    2031
    2132                public function UploadService() {
     
    2839
    2940                private var fileRef:FileReference;
     41                private var httpClient:HttpClient;
    3042                private var request:URLRequest;
    3143                private var pb:ProgressBar;
     
    3345                public function init(progressBar:ProgressBar):void {
    3446                        pb = progressBar;
     47                }
     48
     49                private function createAndInitRequest(url:String):void {
     50                        request = new URLRequest(url);
     51                        httpClient = new HttpClient();
     52                        httpClient.listener.onError = httpclientErrorHandler;
     53                        httpClient.listener.onData = httpclientDataHandler;
     54                        httpClient.listener.onStatus = httpclientStatusHandler;
     55                }
     56
     57                private function createAndInitFileReference():void {
    3558                        fileRef = new FileReference();
    3659                        fileRef.addEventListener(Event.SELECT, selectHandler);
    37                         fileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS, errorHandler);
    3860                        fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, responseHandler);
    3961                        fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    40                         fileRef.addEventListener(Event.OPEN, startUploadHandler);
    41                 }
    42 
    43                 public function submitProfile(description:ItemDescription):void {
    44                         request = new URLRequest(Config.instance.uploadProfileUrl);
     62                        fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
     63                        fileRef.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
     64
     65                }
     66
     67                /**
     68                 * submits a profile, data parameter can be null which implies a file was selected using selectXmlFile();
     69                 */
     70                public function submitProfile(description:ItemDescription, data:String = null):void {
     71                        createAndInitRequest(Config.instance.uploadProfileUrl);
    4572                        var params:URLVariables = new URLVariables();
    46                         submit(description, params);
    47                 }
    48 
    49                 public function submitComponent(description:ItemDescription):void {
    50                         request = new URLRequest(Config.instance.uploadComponentUrl);
     73                        submit(description, params, data);
     74                }
     75
     76                /**
     77                 * submits a component, data parameter can be null which implies a file was selected using selectXmlFile();
     78                 */
     79                public function submitComponent(description:ItemDescription, data:String = null):void {
     80                        createAndInitRequest(Config.instance.uploadComponentUrl);
    5181                        var params:URLVariables = new URLVariables();
    5282                        params.group = description.groupName;
    53                         submit(description, params);
    54                 }
    55 
    56                 public function submit(description:ItemDescription, params:URLVariables):void {
     83                        submit(description, params, data);
     84                }
     85
     86                private function getCredentials():String {
     87                        return Base64.encode("tomcat:tomcat");
     88                }
     89
     90                private function submit(description:ItemDescription, params:URLVariables, data:String = null):void {
    5791                        message = "";
    5892                        try {
    59                                 request.method = URLRequestMethod.POST;
    60                                 params.creatorName = description.creatorName;
    61                                 params.description = description.description;
    62                                 params.name = description.name;
    63                                 request.data = params;
    64                                 fileRef.upload(request, "data");
     93                                if (data != null) {
     94                                        var parts:Array = new Array();
     95                                        parts.push(new Part("description", description.description));
     96                                        parts.push(new Part("name", description.name));
     97                                        parts.push(new Part("data", data, "application/octet-stream", [{name: "filename", value: description.name + ".xml"}]));
     98
     99                                        var multipart:Multipart = new Multipart(parts);
     100                                        var uri:URI = new URI(Config.instance.uploadProfileUrl);
     101                                        startUploadHandler();
     102                                        var post:Post = new Post();
     103                                        post.addHeader("Authorization", "BASIC " + getCredentials());
     104                                        post.setMultipart(multipart);
     105                                        httpClient.request(uri, post);
     106                                } else {
     107                                        // Cannot sent credentials with FileReference.upload so just load the data and then submit through HttpClient
     108                                        startUploadHandler();
     109                                        if (fileRef.data == null) {
     110                                                //only load if not loaded before otherwise sent the already loaded file. You can only force a reload of the file by selecting it again (it is a flash thingy).
     111                                                fileRef.addEventListener(Event.COMPLETE, function(event:Event):void {
     112                                                                submit(description, params, new String(fileRef.data));
     113                                                        });
     114                                                fileRef.load();
     115                                        } else {
     116                                                submit(description, params, new String(fileRef.data));
     117                                        }
     118                                }
    65119                        } catch (error:Error) {
    66                                 trace("Unable to upload file.");
    67                         }
    68                 }
     120                                trace("Unable to upload file. Error: " + error);
     121                                throw error;
     122                        }
     123                }
     124
    69125
    70126                public function selectXmlFile(event:Event):void {
     127                        createAndInitFileReference();
    71128                        var filter:FileFilter = new FileFilter("Xml Files (*.xml)", "*.xml");
    72129                        fileRef.browse(new Array(filter));
     
    76133                        selectedFile = fileRef.name;
    77134                        message = "";
    78                         pb.visible=false;
    79                 }
    80 
    81                 private function errorHandler(event:HTTPStatusEvent):void {
    82                         message = "Server Failed to handle registration. Unexpected error, try again later. (httpstatus code was: " + event.status + ")";
     135                        pb.visible = false;
     136                }
     137
     138                private function httpclientStatusHandler(event:HttpStatusEvent):void {
     139                        if (event.code != "200") {
     140                                addToMessage("Server Failed to handle registration. Unexpected error, try again later. (httpstatus code was: " + event.code + ")\n");
     141                        }
     142                }
     143
     144                private function httpclientDataHandler(event:HttpDataEvent):void {
     145                        uploadComplete();
     146                        var response:XML = new XML(event.bytes);
     147                        handleResponse(response);
     148                }
     149
     150                private function httpclientErrorHandler(event:HttpErrorEvent):void {
     151                        addToMessage("Server Failed to handle registration. Unexpected error, try again later. (error: " + event.text + ")\n");
     152                }
     153
     154                private function securityErrorHandler(event:SecurityErrorEvent):void {
     155                        addToMessage("Server Failed to handle registration. Unexpected error, try again later. (error: " + event.text + ")\n");
     156                }
     157
     158                private function ioErrorHandler(event:IOErrorEvent):void {
     159                        addToMessage("Unable to load file. (error: " + event.text + ")\n");
    83160                }
    84161
     
    88165                }
    89166
    90                 private function startUploadHandler(event:Event):void {
     167
     168                private function responseHandler(event:DataEvent):void {
     169                        uploadComplete();
     170                        var response:XML = new XML(event.data);
     171                        handleResponse(response);
     172                }
     173
     174                private function startUploadHandler():void {
    91175                        trace("uploading start");
    92176                        pb.label = "uploading %3%%";
    93                         pb.visible=true;
    94                 }
    95 
    96 
    97                 private function responseHandler(event:DataEvent):void {
    98                         pb.label = "Upload complete";
    99                         var response:XML = new XML(event.data);
     177                        pb.visible = true;
     178                        pb.includeInLayout = true;
     179                }
     180
     181                private function handleResponse(response:XML):void {
    100182                        if (response.@registered == true) {
    101183                                var item:ItemDescription = new ItemDescription();
     
    109191                                createErrorMessage(response);
    110192                        }
     193
     194                }
     195
     196                private function uploadComplete():void {
     197                        pb.label = "Upload complete";
     198                        pb.setProgress(100, 100);
    111199                }
    112200
    113201                private function createErrorMessage(response:XML):void {
    114                         message = "Failed to register:";
     202                        addToMessage("Failed to register:");
    115203                        var errors:XMLList = response.errors.error;
    116204                        for each (var error:XML in errors) {
     
    118206                        }
    119207                }
     208
     209                private function addToMessage(text:String):void {
     210                        message += text;
     211                }
     212
    120213        }
    121214}
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/resources/assets/css/main.css

    r161 r206  
    3232
    3333.xmlBrowserHeader {
    34     labelWidth: 50;
     34    fontWeight: bold;
     35    fontSize: 12;
    3536}
    3637
    37 .xmlBrowserHeaderCmdelement {
    38     labelWidth: 70;
     38.xmlBrowserHeaderSmall {
     39    fontWeight: bold;
    3940}
    4041
Note: See TracChangeset for help on using the changeset viewer.