This site has been permanently archived. This is a static copy provided by the University of Southampton.
/**
@author guicec
Extending/depending on:
~ = modified function (when updating from SVN be sure to check these for changes, especially to Ext.tree.TreeNodeUI.render() )
+ = added function
Ext.tree.TreeNodeUI: ~onClick(), ~onDblClick()
Ext.tree.TreePanel : ~expandPath(),
+getChecked(), +someChildOrParentIsChecked(), +checkDisjointWidth(),
+isSomeChildChecked(), +isSomeChildCheckedOrStatus()
Ext.tree.TreeNode: +checkDisjointness(), +checkNodeReferences()
Neologism.TermsTree: +addObserver(), +notifyObservers(), +findNodeByText(), +computeInverses(),
+findChildInNode(), +traverse(), +getXSDDatatype()
*/
/**
* Override TreePanel onClick and onDblClick events
* @param {Object} e
*/
Ext.override(Ext.tree.TreeNodeUI, {
onClick : function(e) { //debugger;
if ( this.dropping ) {
e.stopEvent();
return;
}
if ( this.fireEvent("beforeclick", this.node, e) !== false ) {
var a = e.getTarget('a');
if ( !this.disabled && this.node.attributes.href && a ){
this.fireEvent("click", this.node, e);
return;
} else {
if ( a && e.ctrlKey ) {
e.stopEvent();
}
}
e.preventDefault();
if (this.disabled) {
return;
}
if ( this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes() ) {
//this.node.expand();
//this.node.toggle();
}
this.fireEvent("click", this.node, e);
} else {
e.stopEvent();
}
}
});
Ext.override(Ext.tree.TreeNodeUI, {
onDblClick : function(e){ //debugger;
e.preventDefault();
if ( this.disabled ){
return;
}
if ( this.checkbox ){
return;
// cancel the toggleCheck when dblclick
//this.toggleCheck();
}
if ( this.animating && this.node.hasChildNodes() ){
//this.node.toggle();
//this.node.expand();
}
this.fireEvent("dblclick", this.node, e);
},
//private
onCheckChange : function(){
//alert('onCheckChange');
var checked = this.checkbox.checked;
// fix for IE6
this.checkbox.defaultChecked = checked;
this.node.attributes.checked = checked;
this.fireEvent('checkchange', this.node, checked);
}
});
Ext.override(Ext.tree.TreePanel, {
expandPath : function(path, attr, callback){
attr = attr || 'id';
var keys = path.split(this.pathSeparator);
var curNode = this.root;
if(curNode.attributes[attr] != keys[1]){ // invalid root
if(callback){
callback(false, null);
}
return;
}
var index = 1;
var f = function(){
if(++index == keys.length){
if(callback){
callback(true, curNode);
}
return;
}
var c = curNode.findChild(attr, keys[index]);
if(!c){
if(callback){
callback(false, curNode);
}
return;
}
curNode = c;
c.expand(false, false, f);
};
curNode.expand(false, false, f);
return curNode;
}
});
/*
Ext.override(Ext.tree.TreeNodeUI, {
toggleCheck : function(value) {
var cb = this.checkbox;
if(cb){
var checkvalue = (value === undefined ? !cb.checked : value);
cb.checked = checkvalue;
this.node.attributes.checked = checkvalue;
}
}
});
*/
/**
* Retrieve an array of ids of checked nodes
* @return {Array} array of ids of checked nodes
*/
Ext.tree.TreePanel.prototype.getChecked = function(node){
var checked = [], i;
if( typeof node == 'undefined' ) {
node = this.rootVisible ? this.getRootNode() : this.getRootNode().firstChild;
}
if( node.attributes.checked ) {
checked.push(node.id);
if( !node.isLeaf() ) {
for( i = 0; i < node.childNodes.length; i++ ) {
checked = checked.concat( this.getChecked(node.childNodes[i]) );
}
}
}
return checked;
};
//-------------------------------------------------------
// especifies methods for TermsTree
/**
* Note: we are working with node.text becuase the id could be modified or had not the right value
*/
Ext.tree.TreePanel.prototype.someChildOrParentIsChecked = function(node, fn) {
var someoneChecked = false;
if (!node.parentNode.isRoot) {
// search for someone checked
var someoneChecked = false;
node.bubble( function() {
if ( node.text != this.text ) {
this.eachChild( function(currentNode) {
currentNode.cascade( function() {
//var cid = ( this.attributes.realid !== undefined ) ? this.attributes.realid : this.id;
if ( this.getUI().checkbox.checked == true ) {
someoneChecked = true;
return false;
}
}, null);
});
/*
if ( !someoneChecked ) {
if(fn.call() === false){
// break;
}
//this.getUI().checkbox.disabled = false;
}
*/
}
if ( this.parentNode.isRoot ) {
return false;
}
});
}
};
Ext.tree.TreePanel.nodeStatus = {
NORMAL: 0,
IMPLICIT: 1,
INCONSISTENT: 2,
BLOCKED: 3,
BLOCKED_AND_INCONSISTENT: 4
};
Ext.tree.TreePanel.prototype.checkDisjointWith = function(node){
var disjointwith = [];
var checked = node.getUI().checkbox.checked;
if( node.attributes.disjointwith.length > 0 ) {
disjointwith = disjointwith.concat(node.attributes.disjointwith);
}
// traverse children
/*
node.eachChild( function(currentNode) {
currentNode.cascade(function() {
console.log(this.text);
console.log(this.ui);
console.log(this.getUI().nodeClass);
if( this.getUI().nodeClass != 'class-disabled' && this.attributes.disjointwith.length > 0 ) {
disjointwith = disjointwith.concat(this.attributes.disjointwith);
}
}, null);
});
*/
//console.log(disjointwith);
var len = disjointwith.length;
if( len > 0 ) {
// get the root node
var rootnode = node.getOwnerTree().getRootNode();
// traverse the tree
rootnode.eachChild( function(currentNode) {
currentNode.cascade( function() {
for ( var i = 0; i < len; i++ ) {
if ( this.text == disjointwith[i] ) {
if( checked ) {
if( this.attributes.nodeStatus == Ext.tree.TreePanel.nodeStatus.BLOCKED ) {
this.attributes.nodeStatus = Ext.tree.TreePanel.nodeStatus.BLOCKED_AND_INCONSISTENT;
this.getUI().removeClass('class-bloked');
} else {
this.attributes.nodeStatus = Ext.tree.TreePanel.nodeStatus.INCONSISTENT;
}
this.getUI().addClass('class-inconsistent');
}
else {
if( this.attributes.nodeStatus == Ext.tree.TreePanel.nodeStatus.BLOCKED_AND_INCONSISTENT ) {
this.attributes.nodeStatus = Ext.tree.TreePanel.nodeStatus.BLOCKED;
this.getUI().addClass('class-bloked');
} else {
this.attributes.nodeStatus = Ext.tree.TreePanel.nodeStatus.NORMAL;
}
this.getUI().removeClass('class-inconsistent');
}
this.getUI().checkbox.disabled = (this.attributes.nodeStatus != Ext.tree.TreePanel.nodeStatus.NORMAL);
// all child also are disjoint
this.eachChild( function(currentNode) {
currentNode.cascade( function() {
if( checked ) {
if( this.attributes.nodeStatus == Ext.tree.TreePanel.nodeStatus.BLOCKED ) {
this.attributes.nodeStatus = Ext.tree.TreePanel.nodeStatus.BLOCKED_AND_INCONSISTENT;
this.getUI().removeClass('class-bloked');
} else {
this.attributes.nodeStatus = Ext.tree.TreePanel.nodeStatus.INCONSISTENT;
}
this.getUI().addClass('class-inconsistent');
}
else {
if( this.attributes.nodeStatus == Ext.tree.TreePanel.nodeStatus.BLOCKED_AND_INCONSISTENT ) {
this.attributes.nodeStatus = Ext.tree.TreePanel.nodeStatus.BLOCKED;
this.getUI().addClass('class-bloked');
} else {
this.attributes.nodeStatus = Ext.tree.TreePanel.nodeStatus.NORMAL;
}
this.getUI().removeClass('class-inconsistent');
}
this.getUI().checkbox.disabled = (this.attributes.nodeStatus != Ext.tree.TreePanel.nodeStatus.NORMAL);
}, null);
});
}
}
}, null);
});
}
};
Ext.tree.TreePanel.prototype.isSomeChildChecked = function(node){
var someoneChecked = false;
node.eachChild( function(currentNode) {
//currentNode.cascade( function() {
var cid = ( currentNode.attributes.realid !== undefined ) ? currentNode.attributes.realid : currentNode.id;
if ( currentNode.getUI().checkbox.checked == true ) {
someoneChecked = true;
return false;
}
// }, null);
});
return someoneChecked;
};
Ext.tree.TreePanel.prototype.isSomeChildCheckedOrStatus = function(node, status){
var someoneChecked = false;
node.eachChild( function(currentNode) {
//currentNode.cascade( function() {
var cid = ( currentNode.attributes.realid !== undefined ) ? currentNode.attributes.realid : currentNode.id;
if ( currentNode.getUI().checkbox.checked == true || currentNode.attributes.nodeStatus == status ) {
someoneChecked = true;
return false;
}
// }, null);
});
return someoneChecked;
};
Ext.tree.TreeNode.prototype.checkDisjointness = function(/*TreeNode*/node, /*string*/editingNodeValue, /*Mutidimensional array*/parentPaths) {
// if some node comes checked is because it is a real disjointwith
if (node.getUI().isChecked())
return;
if (Neologism.util.in_array(editingNodeValue, node.attributes.disjointwith)) {
node.getUI().toggleCheck(true);
node.disable();
}
else if (node.attributes.inferred_disjointwith != undefined) {
for (var i = 0; i < parentPaths.length; i++) {
for (var tindex = 1; tindex < parentPaths[i].length; tindex++) {
//console.log(parentPaths[i][tindex]);
if (Neologism.util.in_array(parentPaths[i][tindex], node.attributes.inferred_disjointwith)) {
node.disable();
return;
}
}
}
}
},
Ext.tree.TreeNode.prototype.checkInverses = function(/*TreeNode*/node, /*string*/editingNodeValue) {
// if some node comes checked is because it is a real disjointwith
if (node.getUI().isChecked())
return;
if (Neologism.util.in_array(editingNodeValue, node.attributes.inverses)) {
node.getUI().toggleCheck(true);
node.disable();
}
// else if (node.attributes.inferred_inverses != undefined) {
// for (var i = 0; i < parentPaths.length; i++) {
// for (var tindex = 1; tindex < parentPaths[i].length; tindex++) {
// //console.log(parentPaths[i][tindex]);
// if (Neologism.util.in_array(parentPaths[i][tindex], node.attributes.inferred_disjointwith)) {
// node.disable();
// return;
// }
// }
// }
// }
},
/**
* Check for possible references to a node. The references are stored in the first node of the tree.
* @param node Node to check for possible references.
* @return
*/
Ext.tree.TreeNode.prototype.checkNodeReferences = function(checked) {
var nodeTocheck = this;
var tree = nodeTocheck.getOwnerTree();
var rootNode = tree.getRootNode();
if ( rootNode.childNodes[0].attributes.references != undefined ) {
var references = rootNode.childNodes[0].attributes.references;
if (references[nodeTocheck.text] != undefined && references[nodeTocheck.text].references > 0) {
var reference = references[nodeTocheck.text];
for ( var p = 0; p < reference.paths.length; p++ ) {
var rnode = tree.expandPath(reference.paths[p]);
if ( rnode != undefined ) {
if (rnode.attributes.checked != checked) {
rnode.getUI().toggleCheck(checked);
}
}
}
}
}
};
//Ext.extend(Ext.tree.CheckboxNodeUI, Ext.tree.TreeNodeUI, {
/*
render : function(bulkRender){
var n = this.node;
var targetNode = n.parentNode ?
n.parentNode.ui.getContainer() : n.ownerTree.container.dom; // in later svn builds this changes to n.ownerTree.innerCt.dom
if(!this.rendered){
this.rendered = true;
var a = n.attributes;
// add some indent caching, this helps performance when rendering a large tree
this.indentMarkup = "";
if(n.parentNode){
this.indentMarkup = n.parentNode.ui.getChildIndent();
}
// modification: added checkbox
var buf = ['