PDA

View Full Version : Retrieving data from tree (java)



jeanke2
6 Dec 2007, 6:16 AM
Hallo,

I have two treepanels with drag and drop. The goal now is to retrieve data from the second treepanel when submitting the form in my java action class. The treepanel is displayed on a jsp. Does anyone has any idea how to get these values put in my second tree?
tnx.

my tree looks like this:




Ext.onReady(function(){
//ext test function:
//Ext.MessageBox.alert('Hallo', 'Ext is now ready for your first tree!');

Ext.BLANK_IMAGE_URL = "http://extjs.com/s.gif";
Ext.QuickTips.init();

var Tree = Ext.tree;

var myTree = new Tree.TreePanel('contactDiv', {
loader: new Tree.TreeLoader(),
containerScroll: true,
animate:true,
rootVisible:true,
hlColor : 'FF0000',
enableDD:true,
split: true,
ddAppendOnly: false,
lines:true,
dropConfig:{
allowContainerDrop:true,
onContainerDrop:function(source, e, data){
myTree.root.appendChild(data.node);
return true;
},
onContainerOver:function(source, e, data){
//Ext.Msg.alert('Drop Tree', 'onContainerOver');
return this.dropAllowed;
}
}
});

/* preventing ctrl/shift clicked block */
myTree.on('click', function(node, e) {
node.select();
if (e.ctrlKey || e.shiftKey) {
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = false;
//e.stopPropagation works only in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return false;
}
}, this
);
/* end ctrl/shift block*/

// add a tree sorter in folder mode
new Tree.TreeSorter(myTree, {folderSort:true});

var Rroot = new Tree.AsyncTreeNode(
{
text: 'Contacts',
id:'contacts',
allowDrop: false,
draggable:false,
children: [ here i place my childre nodes
]}
]

});

myTree.setRootNode(Rroot);
myTree.render();
Rroot.expand(false,/* no anim */false);
myTree.dropZone.setPadding(0,0,130,0);
// Expand folders by default
//myTree.expandAll();

myTree.on('contextmenu', prepareMenu);
// show id (test function) (normally not used, just testing)
//myTree.on('click', alertID);
function alertID(node){
if(myTree.getSelectionModel().isSelected(node)){
if (node.isLeaf()){
alert('Node ID is ' + node.id + ' leaf: true');
} else {
alert('Node ID is : ' + node.id + ' leaf: false');
}
}
};

// menu on right click nodes
// handler => function to call
//cls => css class
var Menu = new Ext.menu.Menu({
id:'menu',
items: [{
id:'expand',
handler:expandAll,
cls:'expand',
text:'Expand'
},{
id:'collapse',
handler:collapseAll,
cls:'collapse',
text:'Collapse'
}]
});


var sm = myTree.getSelectionModel();
// functions menu
function prepareMenu(node, e){
node.select();
Menu.showAt(e.getXY());
}
function collapseAll(){
Menu.hide();
setTimeout(function(){
Rroot.eachChild(function(n){
n.collapse(false, false);
});
}, 10);
}
function expandAll(){
Menu.hide();
setTimeout(function(){
Rroot.eachChild(function(n){
n.expand(false, false);
});
}, 10);
}

// our Second DIV where our contacts will be dropped to
var dropTree = new Tree.TreePanel( 'contactDropdiv',{
animate:true,
enableDD:true,
width: 500,
height: 500,
split: true,
//region: 'contactDropdiv',
containerScroll: true,
ddAppendOnly: false,
lines:true,
dropConfig:{
allowContainerDrop:true,
onContainerDrop:function(source, e, data){
dropTree.root.appendChild(data.node);
return true;
},
onContainerOver:function(source, e, data){
//Ext.Msg.alert('Drop Tree', 'onContainerOver');
return this.dropAllowed;
}
}
});

// add a tree sorter in folder mode
new Tree.TreeSorter(dropTree, {folderSort:true});

var dropRoot = new Tree.TreeNode({
allowDrag:false,
allowDrop:false,
id:'dRoot',
text:'Contacts scheduler'
});

dropTree.setRootNode(dropRoot);
dropTree.render();
dropRoot.expand(false, /*no anim */ false);
// div as dropzone
dropTree.dropZone.setPadding(0,0,130,0);

dropTree.on('beforenodedrop', function(e){
var n = e.dropNode;
var copy = new Tree.TreeNode(Ext.apply({}, n.attributes));
e.dropNode = copy;
return true;
});

// menu right DIV onclick menu to remove
// is called by : dropTree.on('contextmenu', prepareMenu2);
var Menu2 = new Ext.menu.Menu({
id:'menu2',
items: [{
id:'expand',
handler:expandAll2,
cls:'expand',
text:'Expand'
},{
id:'collapse',
handler:collapseAll2,
cls:'collapse',
text:'Collapse'
}]
});

var sm2 = dropTree.getSelectionModel();
function prepareMenu2(node, e){
node.select();
//Menu2.items.get('remove')
//[node.attributes.allowDelete ? 'enable' : 'disable']();
Menu2.showAt(e.getXY());
}
function collapseAll2(){
Menu.hide();
setTimeout(function(){
dropRoot.eachChild(function(n){
n.collapse(false, false);
});
}, 10);
}
function expandAll2(){
Menu.hide();
setTimeout(function(){
dropRoot.eachChild(function(n){
n.expand(false, false);
});
}, 10);
}
function removeNode(){
var n = sm2.getSelectedNode();
if(n && n.attributes.allowDelete){
dropTree.getSelectionModel().selectPrevious();
n.parentNode.removeChild(n);
}
}

dropTree.on('contextmenu', prepareMenu2);

});