Need to add properties to xml dynamically...

I have a datagrid which contains properties for  a component.
Here i able to show the properties of a component in xml tab. But i
want to modify the components and those changes should reflect in the
xml.
When i modify the components properties in datagrid those changes  are
not updating in the xml.

Also i need to do the same thing for the nodes which will be draggable
in to the compenent tab.
When we right click on the node it opens properties panel where we
provide node values.

When we modify both the component and node values it should reflect in
the xml tab.

Here i am able to display those properties values in the xml tab but
when i modify them it is not updating in the xml.

Below is my sample code.

CustomPanel.Mxml
-----------------------------
private function setDefaultProperties():void{
var retArray:ArrayCollection = new ArrayCollection();

 
retArray.additem((attributeHirachy:"ComponentTemplateDescriptor.Owner",attributeName:"Owner",attributeValue:"CN1829",type:"Text"));
retArray.additem((attributeHirachy:"ComponentTemplateDescriptor.Name",attributeName:"Name",attributeValue:this.componentName,type:"Text"));
retArray.additem((attributeHirachy:"ComponentTemplateDescriptor.Version",attributeName:"Version",attributeValue:"V1",type:"Text"));
retArray.additem((attributeHirachy:"InputPotList.PortName",attributeName:"InputPortList",attributeValue:"CN1829",type:"Label"));
retArray.additem((attributeHirachy:"OutPotList.PortName",attributeName:"OutPutPortList",attributeValue:"CN1829",type:"ComboButton"));

this.propertiesArray = retArray;
}


private function loadPropertiesFromComponent():void{
if(component !=null){

propertiesArray.setItemAt((attributeHirachy:"ComponentTemplateDescriptor.Owner",attributeName:"Owner",attributeValue:component.owner,type:"Text"),
0);
propertiesArray.setItemAt((attributeHirachy:"ComponentTemplateDescriptor.Name",attributeName:"Owner",attributeValue:component.name,type:"Text"),
1);
propertiesArray.setItemAt((attributeHirachy:"ComponentTemplateDescriptor.Version",attributeName:"Version",attributeValue:component.version,type:"Text"),
2);

}
}


private function convertPropertiesArrayToXML():XML{

var propArray:ArrayCollection=this.propertiesArray;
var retXML:XML=<AbstractComponentTemplate></
AbstractComponentTemplate>;
var xmlTempStr:String=" ";
var xmlTemp:XML;
for(var i=int=0;i<propArray.length;i++):
var key:String=propArray[i].attributeHirachy;
var val:String=propArray[i].attributeValue;
if(key == "ComponentTemplateDescriptor.Owner"){
xmlTempStr="<ComponentTemplateDescriptor><Owner>"+val+"</Owner>";
}else if(key == "ComponentTemplateDescriptor.Name"){
xmlTempStr +="<Name>"+val+</Name>";
}else if(key == "ComponentTemplateDescriptor.Version")
xmlTempStr +="<Version>"+val+"</Version></
ComponentTemplateDescriptor>";
xmlTemp = new XML(xmlTempStr);
retXML.appendChild(xmlTemp);

}else if(key == "InputPortList.PortName")
xmlTempStr +="<InputPortList><PortName>"+val+"</PortName></
InputPortList>";
xmlTemp = new XML(xmlTempStr);
retXML.appendChild(xmlTemp);
}
else if(key == "OutPortList.PortName")
xmlTempStr +="<OutPortList><PortName>"+val+"/PortName></
OutPortList><";
xmlTemp = new XML(xmlTempStr);
retXML.appendChild(xmlTemp);
}
}

private function updateCompNameFromProperties():String{
var propArray:ArrayCollection = this.propertiesArray;
var tempStr:String = " ";

for(var i:int=0; i<propArray[i].length;i++)
var key:String=propArray[i].attributeHirachy;
var val:String=propArray[i].attributeValue;

if(key == "ComponentTemplateDescriptor.Owner"){
tempStr = val;
}else if(key == "ComponentTemplateDescriptor.Name"){
tempStr +="."+val;

}else if(key == "OutputPortList.PortName" && val.length>0){
tempStr +="."+val;
}else if(key == "ComponentTemplateDescriptor.Version"){
tempStr +="."+val;
}
}
this.label=tempStr;
this.componentName=tempStr;
return tempStr;
}

Cellfield.as
----------------
package myComponents
{
import flash.display.DisplayObject;
import flash.events.MouseEvent;

import mx.containers.canvas;
import mx.controls.*;
import mx.core.Application;
import mx.events.CloseEvent;
import mx.managers.PopUpManager;

public class CellField extends canvas
{

private var compType:String;
private var compValue:Object;

public var updatedValue:String;

public function CellField(){
super();
}
override protected function createChildren():void{
super.createChildren();
}
override protected function commitProperties():void{
}
override protected function set data(value:Object):void{
try{
if(value!=null)
{
compType=value.type;
compType=value.attributeValue;

var w:int=125;
this.removeAllChildren();
if(compType=="Text"){
var txt:TextInput = new TextInput();
txt.width=w;
txt.text=compvalue.toString();
updatedValue=txt.text;
this.addChild(txt);
}
if(compType=="Label"){
var lbl:Label = new Label();
lbl.width=w;
lbl.text=compvalue.toString();
updatedValue=lbl.text;
this.addChild(lbl);
}if(compType=="ComboButton"){
var lbl2:Label = new Label();
lbl2.width=w/1.5;
lbl2.text=compvalue.toString();

this.addChild(lbl);
var btn:Button = new Button();
btn.addEventListener(MouseEvent.CLICK,clickButton);
btn.label="...";
btn.width=w/3;
btn.x=lbl2.width+5;
}
catch(err:Errror){
Alert.show("----");
}
}
public function clickButton(event:MouseEvent):void{
var myPop:Window=PopUpmanager.createPopUp(Application.application as
DisplayObject,window,true) as Window;
PopUpManager.centerPopUp(myPop);

}
}

}

Main.mxml
----------------

<mx:DataGrid id="dgProp" editable="true">

<mx:Columns>

<mx:DataGridColumn dataField="attributeName" headerText="Property"
editable="false"/>

<mx:DataGridColumn dataField="attributeValue" headerText="value"
editable="true"/>

</mx:Columns>

</mx:DataGrid>




-- 
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to flex_india@googlegroups.com.
To unsubscribe from this group, send email to 
flex_india+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en.

Reply via email to