]>
git.argeo.org Git - gpl/argeo-slc.git/blob - server/org.argeo.slc.ria/src/argeo-ria-lib/jcr/class/org/argeo/jcr/ria/model/Node.js
1 qx
.Class
.define("org.argeo.jcr.ria.model.Node", {
2 extend
: org
.argeo
.jcr
.ria
.model
.AbstractItem
,
5 "clear" : "qx.event.type.Event",
6 "childNodeAdded" : "qx.event.type.Data",
7 "childNodeRemoved" : "qx.event.type.Data",
8 "childrenChanged" : "qx.event.type.Data",
10 "propertyAdded" : "qx.event.type.Data",
11 "propertyRemoved" : "qx.event.type.Data",
12 "propertiesChanged" : "qx.event.type.Data"
17 init
: "empty", // Can be "empty" => "loading" => "loaded"
18 event
: "changeLoadState"
21 check
: "org.argeo.jcr.ria.provider.INodeProvider"
25 construct : function(nodeName
, isRoot
){
28 this._properties
= {};
29 this.setName(nodeName
);
41 this.getNodeProvider().loadNode(this);
45 if(this.itemIsRoot()) return;
46 this.getParent().removeChild(this.getName());
49 fromXmlString : function(xmlString
){
50 var domDocument
= qx
.xml
.Document
.fromString(xmlString
);
51 var root
= domDocument
.documentElement
;
52 this.fromDomElement(root
);
55 fromDomElement : function(domElement
){
56 if(domElement
.nodeType
!= 1) return;
57 for(var i
=0;i
<domElement
.attributes
.length
;i
++){
58 var att
= domElement
.attributes
[i
];
59 var property
= new org
.argeo
.jcr
.ria
.model
.Property(att
.nodeName
);
60 this.addProperty(property
);
61 property
.fromDomElement(att
);
63 for(var i
=0;i
<domElement
.childNodes
.length
;i
++){
64 var child
= domElement
.childNodes
[i
];
65 if(child
.nodeType
!= 1) continue;
66 var jcrChild
= new org
.argeo
.jcr
.ria
.model
.Node(child
.nodeName
);
67 this.addChild(jcrChild
);
68 jcrChild
.fromDomElement(child
);
70 this.setLoadState("loaded");
73 toXmlString : function(recurse
, childrenWriter
){
74 var string
= "<"+this.getName();
75 var props
= this.getProperties();
76 for(var i
=0;i
<props
.length
;i
++){
77 string
+= " " + props
[i
].toXmlString();
81 var childs
= this.getChildren();
82 var childrenString
= "";
83 for(var j
=0;j
<childs
.length
;j
++){
84 childrenString
+= childs
[j
].toXmlString(recurse
, childrenWriter
);
87 string
+= childrenWriter(childrenString
);
89 string
+= childrenString
;
92 string
+= "</"+this.getName()+">";
96 getChild : function(childName
){
97 return this._children
[childName
];
99 getProperty : function(propertyName
){
100 return this._properties
[propertyName
];
102 addChild : function(childNode
){
103 this._children
[childNode
.getName()] = childNode
;
105 childNode
.setParent(this);
106 childNode
.setRoot(this.getRoot());
107 childNode
.setPath(this.getPath() + "/" + childNode
.getName());
109 this.fireDataEvent("childNodeAdded", childNode
);
110 this.fireDataEvent("childNodeChanged");
112 removeChild : function(childName
){
113 delete(this._children
[childName
]);
114 this.fireDataEvent("childNodeRemoved", childName
);
115 this.fireDataEvent("childNodeChanged");
117 addProperty : function(property
){
118 this._properties
[property
.getName()] = property
;
120 property
.setParent(this);
121 property
.setRoot(this.getRoot());
122 property
.setPath(this.getPath() + "/" + property
.getName());
124 this.fireDataEvent("propertyAdded", property
);
125 this.fireDataEvent("propertiesChanged");
127 removeProperty : function(propertyName
){
128 delete(this._properties
[propertyName
]);
129 this.fireDataEvent("propertyRemoved", propertyName
);
130 this.fireDataEvent("propertiesChanged");
132 getChildren : function(){
133 return qx
.lang
.Object
.getValues(this._children
);
135 getProperties : function(){
136 return qx
.lang
.Object
.getValues(this._properties
);
138 getChildrenCount : function(){
139 return qx
.lang
.Object
.getLength(this._children
);
141 getPropertiesCount : function(){
142 return qx
.lang
.Object
.getLength(this._properties
);