PDA

View Full Version : Dynamic context menu on tree not allowed?



sgolla
28 Jun 2009, 8:17 AM
It looks like TreePanel of GXT allows to set the context menu at tree level. If i want my context menu to be different for my root level items, and further to be different for my child items, it seems there is no easy or direct way of doing it!?!?

If any one can give any help on how to construct menu dynamically for tree nodes using EXT GWT 2.0, it would be really helpful.

Thank you all
-Sreekanth.

sven
28 Jun 2009, 8:19 AM
You can listen to the Event.ConextMenu event and change your contextmenu in that event.

sureace
10 Jul 2009, 1:08 AM
Hi,
I am also working on that part. can u give some small example on how to do this.

with Regards
sureace

sureace
10 Jul 2009, 2:21 AM
I had done it.
This is what i had done in my code.
listeners: {
contextmenu: function(node, e) {
node.select();
//alert(node.attributes.cls);
if(node.id=="root"){
var c = node.getOwnerTree().contextMenu;
c.items.get("crsite").show();
c.items.get("crsrvwebapp").show();
c.items.get("crinstance").hide();
c.items.get("editItem").hide();
c.items.get("editApp").hide();
c.items.get("delsite").hide();
c.items.get("delapp").hide();
c.items.get("CsyncApp").hide();
c.contextNode = node;
c.showAt(e.getXY());
}else if(node.attributes.cls=="account"){
var c = node.getOwnerTree().contextMenu;
//console.dir(c);
c.items.get("crinstance").show();
c.items.get("crsrvwebapp").show();
c.items.get("editItem").show();
c.items.get("delsite").show();
c.items.get("delapp").hide();
c.items.get("crsite").hide();
c.items.get("editApp").hide();
c.items.get("CsyncApp").hide();
c.contextNode = node;
c.showAt(e.getXY());
}else if(node.attributes.cls=="app"){
var c = node.getOwnerTree().contextMenu;
c.items.get("editApp").show();
c.items.get("CsyncApp").show();
c.items.get("delapp").show();
c.items.get("crinstance").hide();
c.items.get("crsrvwebapp").hide();
c.items.get("editItem").hide();
c.items.get("delsite").hide();
c.items.get("crsite").hide();
c.contextNode = node;
c.showAt(e.getXY());
}else{
var c = node.getOwnerTree().contextMenu;
//console.dir(c);
c.items.get("editApp").hide();
c.items.get("CsyncApp").hide();
c.items.get("delapp").hide();
c.items.get("crinstance").hide();
c.items.get("crsrvwebapp").hide();
c.items.get("editItem").hide();
c.items.get("delsite").hide();
c.items.get("crsite").hide();
c.contextNode = node;
c.showAt(e.getXY());
}
}

with Regards
suresh

micgala
10 Jul 2009, 5:37 AM
Suresh, this is GXT forum...
I guess he was asking about how to do that in GXT.

I have one suggestion.
You may listen to the BeforeShow on your Menu.
Then, you can hide your items as you want...

This way you can have your dynamic menu.

Regards,
Michel.

sgolla
11 Jul 2009, 1:27 AM
tree.addListener(Events.ContextMenu, new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent be) {
//show / hide necessary items in your context menu from here and it will work
}
}

In this case my tree is a TreePanel object of EXT GWT 2.0