PDA

View Full Version : OnbrowserEvent problem



saurabhsingh
6 Jul 2009, 7:19 AM
Hi,
I am trying to catch the onBrowser event in my code,
I want to capture the doubleclick on any of my treeNodes to process something on it,
I am generating the treeNodes dynamically by onClick event,
so when one clicks on the parent, then only the child gets loaded.
Now i want to capture the onBrowserEvent to do some more processing

Please help , i am not able to get the onBrowserEvent

my code snippet is like this,

public class MyFrame extends Widget implements EntryPoint{

public void onModuleLoad() {

initial();

RootPanel.get().add(flxData);
flxData.setWidget(0,0,myLayout());

} // end of onModuleLoad()


@Override
public void onBrowserEvent(Event be) {
// System.out.println("Double clickicked on "+ be.item.getText());
DOM.eventCancelBubble(be, true);
DOM.eventPreventDefault(be);
int eventType = DOM.eventGetType(be);
if (eventType == Event.ONDBLCLICK){
System.out.println("double clickicked on ");
}
Window.alert("onBrowserEvent invoked");
super.onBrowserEvent(be);
}

public void initial(){
flxData = new FlexTable();

flxTree = new FlexTable();
}

public Widget myLayout(){

HorizontalPanel hpnl= new HorizontalPanel();

ContentPanel east = new ContentPanel();
ContentPanel west = new ContentPanel();

populateTree();
hpnl.add(west);
west.add(scrollPanel);

populateGrid();
hpnl.add(east);
east.add(grid);
}

}

sven
6 Jul 2009, 3:01 PM
To listen to a doubleclickevent you have to sink that event first.

saurabhsingh
6 Jul 2009, 3:04 PM
Hi,
Thank you so much for the reply,

i added this as well to the constructor: sinkEvents(Event.ONDBLCLICK);
but still i am unable to capture the event

saurabhsingh
6 Jul 2009, 3:07 PM
HI,

I am building the iniatial tree as:

binder = new TreeBinder(tree,tStore);
binder.setAutoLoad(true);
binder.init();
flxTree.setWidth("150%");
flxTree.setWidget(0, 1, tree);
flxTree.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);

scrollPanel.add(flxTree);

scrollPanel.setSize("500", "600");

and then set the scroll panel to the contentpanle to be show

sven
6 Jul 2009, 3:32 PM
Please post a proper example of your code. Also please post code always in code tags. With the lines you posted it is quite hard to understand what you are doing

saurabhsingh
6 Jul 2009, 3:40 PM
Hi,

Here is the code snippet with all the major function i use to build the tree
i am new to postin to forums , please bear with me, it would be kind of you


public class MyFrame extends Widget implements EntryPoint{

public MyFrame(){

dataService = (DataServiceAsync) GWT.create(DataService.class);
ServiceDefTarget endpoint = ( ServiceDefTarget )dataService;
String moduleRelativeURL = GWT.getModuleBaseURL()+"data";
endpoint.setServiceEntryPoint( moduleRelativeURL );

}

public void onModuleLoad() {

initial();

RootPanel.get().add(flxData);
flxData.setWidget(0,0,myLayout());

} // end of onModuleLoad()


@Override
public void onBrowserEvent(Event be) {

DOM.eventCancelBubble(be, true);
DOM.eventPreventDefault(be);
int eventType = DOM.eventGetType(be);
if (eventType == Event.ONDBLCLICK){
System.out.println("double clickicked on ");
}
Window.alert("onBrowserEvent invoked");
super.onBrowserEvent(be);
}

public void initial(){
flxData = new FlexTable();

flxTree = new FlexTable();
}

public Widget myLayout(){

HorizontalPanel hpnl= new HorizontalPanel();

ContentPanel east = new ContentPanel();
ContentPanel west = new ContentPanel();

populateTree();
hpnl.add(west);
west.add(scrollPanel);

populateGrid();
hpnl.add(east);
east.add(grid);
}

public void populateTree(){

tree = new Tree();

tree.getStyle().setLeafIconStyle("myIcon");
flxData.sinkEvents(Event.ONDBLCLICK); // iI ALSO TRIED SINKIN THE TREE.sinkEvnt
tree.addListener(Events.OnClick, new Listener<TreeEvent>() {
loadChild();


}
public void loadChild(){
for (int row = 0,y=0 ; itt.hasNext(); row++,y++){


nodeStore.add(new TreeNodes(((UserTree)itt.next()).toString(),oLoadChild.get(row).getItemID(),oLoadChild.get(row).getItemType(),oLoadChild.get(row).getParentID(),oLoadChild.get(row).getIsStructured()));


}// end of iterator


tStore.remove((BaseTreeModel<TreeModel>) mParent,(BaseTreeModel<TreeModel>) treeRoot);
tStore.insert((BaseTreeModel<TreeModel>) mParent,nodeStore, index, true);
tStore.update((BaseTreeModel<TreeModel>) mParent);
}

sven
6 Jul 2009, 3:45 PM
You need to sink it on that component where you want to listen to it.

saurabhsingh
6 Jul 2009, 3:47 PM
I want to listen the double click on the tree node,
I tried writing the tree.sinkEvents(event.DBLCLICK), but still i was unable to capture the event??
the place where i am trying to sink is ok ?

sven
6 Jul 2009, 3:50 PM
You listen to the event on a differentplace where you sink it. Sink it on the same component where you override onBrowserEvent

saurabhsingh
6 Jul 2009, 4:03 PM
hey,
But since i am defining my tree in the populateTree() onSuccess method, if i write tree.sinkEvents out of that, gives me null pointer exeption , and if i try to write the onBrowser method in the onsuccess method its an error,
so how to write it then??

this is the entire code flow
please help me out of it, i am really very new to this style of coding and this is my first proj in gxt


public MyFrame(){

dataService = (DataServiceAsync) GWT.create(DataService.class);
ServiceDefTarget endpoint = ( ServiceDefTarget )dataService;
String moduleRelativeURL = GWT.getModuleBaseURL()+"data";
endpoint.setServiceEntryPoint( moduleRelativeURL );

}

public void onModuleLoad() {

initial();

RootPanel.get().add(flxData);
flxData.setWidget(0,0,myLayout());

} // end of onModuleLoad()

public void onBrowserEvent(Event be) {

int eventType = DOM.eventGetType(be);
if (eventType == Event.ONDBLCLICK){
System.out.println("double clickicked on ");
}
Window.alert("onBrowserEvent invoked");
System.out.println("onBrowserEvent invoked ");
super.onBrowserEvent(be);
}
public void populateTree(){

System.out.println("Into populate Tree Method");

dataService.getTree(new AsyncCallback(){

@Override
public void onFailure(Throwable arg0) {
System.out.println("Failed in tree model method");

}

@Override
public void onSuccess(Object result) {

System.out.println("Into populate populate Tree success Method");

oParentTree = (ArrayList<UserTree>)result;

oChildTree= new ArrayList<UserTree>();
oChildTree.add(new UserTree("a","b","c","d",true));
oChildTree.add(new UserTree("1.","2.","3.","4.",true));

storeTree= new ArrayList<BaseTreeModel<TreeModel>>();

tree = new Tree();

tree.getStyle().setLeafIconStyle("myIcon");
tree.sinkEvents(Event.ONDBLCLICK);

tree.addListener(Events.OnClick, new Listener<TreeEvent>() {

@Override
public void handleEvent(TreeEvent be) {
TreeNodes nodeClicked = (TreeNodes) be.item.getModel();
dataService.getChild(strCatId,strSeqNo,strParentId,strItemType,isStruct,new AsyncCallback(){

@Override
public void onFailure(Throwable arg0) {

System.out.println("Failed in getChild");
}

@Override
public void onSuccess(Object result) {

oLoadChild= (ArrayList<UserTree>) result;

loadChild();

}
}); // end of dataService call

}

}); // end of onClickListner


tStore.add(getTreeModel(oChildTree), true);
binder = new TreeBinder(tree,tStore);
binder.setAutoLoad(true);
// binder.setDisplayProperty("node");
binder.init();
flxTree.setWidth("150%");
flxTree.setWidget(0, 1, tree);
flxTree.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);

scrollPanel.add(flxTree);

scrollPanel.setSize("500", "600");
}

});// end of dataservice call
public void loadChild(){

System.out.println("Into success of getChild");
try {

TreeNodes nodeStore = null;
Iterator itt = oLoadChild.iterator();

if(strParentName.equalsIgnoreCase("root")){

TreeItem ritem = (TreeItem) tree.getSelectionModel().getSelectedItem();


TreeItem parent = ritem.getParentItem();
System.out.println("parent selected "+ ritem.getParentItem().getModel());
TreeModel treeRoot = (TreeModel) ritem.getModel();
TreeModel mParent= (TreeModel)parent.getModel();
strParent = treeRoot.toString();
int index = mParent.indexOf(treeRoot);
if(strCatName.equals(strParent)){

nodeStore =(TreeNodes)treeRoot;
nodeStore.removeAll();

for (int row = 0,y=0 ; itt.hasNext(); row++,y++){


nodeStore.add(new TreeNodes(((UserTree)itt.next()).toString(),oLoadChild.get(row).getItemID(),oLoadChild.get(row).getItemType(),oLoadChild.get(row).getParentID(),oLoadChild.get(row).getIsStructured()));


}// end of iterator


tStore.remove((BaseTreeModel<TreeModel>) mParent,(BaseTreeModel<TreeModel>) treeRoot);
tStore.insert((BaseTreeModel<TreeModel>) mParent,nodeStore, index, true);
tStore.update((BaseTreeModel<TreeModel>) mParent);



} // end of if
//root.remove(i);


}// end of if , chk for root elements

danh2000
6 Jul 2009, 4:17 PM
Please do not send private messages to people randomly - you are receiving help already.

Be patient and wait for a response on the forum. =;

PS. I don't even use GXT.

saurabhsingh
6 Jul 2009, 4:38 PM
Hi dan,
Sorry about that, ....
please dont mind....

thanks

saurabhsingh
6 Jul 2009, 4:40 PM
Hi, Sven,

it would be reallly helpfull of u , if you could please give me a code snippet out of my code just in the format you are saying it should be...

i tried couple of variation but it din work........i think i am messing up with the place to code in the right places...

thnx

saurabhsingh
7 Jul 2009, 6:12 AM
Hi Sven,

I was able to catch the onBrowser event, but my problem remains the same even after that.
Actually when the tree initially loads , i have inserted dummy childrens for my initial parent nodes.
Then when i click on any of the parent nodes, i fire onclick event to loads its child using RPC,
and thn i keep adding the childrens to the parent node by onclick event.
I am able to sense the browser event on the dummy childrends i loaded intially, but once the dynamic childrens are loaded i cannot sense them using any listner or onBrowser event?
please suggest me some way to implement the doubleClick on the childnodes which are dynamically generated
Please help i am stuck on same scenario again

thnx

saurabhsingh
16 Jul 2009, 1:48 PM
Hi,
I am having problem in tree.expand(path).
I load the children in my tree async, that is i load the child onClick event of the parent Item.
so i want to expand that node after the children has been added in it.
Right now the child items are getting added but then i have to click on the arrow icon to open that node, so i want to expand the node at the time child are loaded?
nodeStore is my own Class...
Please help i am really stuck with it....
the code for it is.



TreeItem ritem = (TreeItem) tree.getSelectionModel().getSelectedItem();


String path = ritem.getPath();
TreeItem parent = ritem.getParentItem();

if ( ritem.getParentItem() != null )

TreeModel treeRoot = (TreeModel) ritem.getModel();
TreeModel mParent= (TreeModel)parent.getModel();

parentNode = (TreeNodes) treeRoot;
strMainCatSeqNo = parentNode.getSeqNo();
strParent = treeRoot.toString();
int index = mParent.indexOf(treeRoot);

if(strCatName.equals(strParent)){

nodeStore =(TreeNodes)treeRoot;
nodeStore.removeAll();

for (int row = 0,y=0 ; itt.hasNext(); row++,y++){


nodeStore.add
(new TreeNodes(((UserTree)itt.next()).toString(),oLoadChild.get(row).getItemID(),
oLoadChild.get(row).getStructItemsId(),
oLoadChild.get(row).getStructCatId(),oLoadChild.get(row).getItemType(),
oLoadChild.get(row).getParentID(),oLoadChild.get(row).getTriggerFlag(),
oLoadChild.get(row).getNodeLevel(),oLoadChild.get(row).getType(),
oLoadChild.get(row).getMultiSelect(),strMainCatSeqNo,oLoadChild.get(row).getIsStructured()));

}// end of iterator


tStore.remove((BaseTreeModel<TreeModel>) mParent, (BaseTreeModel<TreeModel>) treeRoot);
tStore.insert((BaseTreeModel<TreeModel>) mParent,nodeStore, index, true);

tree.expandPath(path);

saurabhsingh
20 Jul 2009, 4:04 PM
Hi sven,

I tried the way the fast tree handles the expansion on nodes.
basically i channged my onClick to before expand event: its works fine but the thing is the older node stays there in the tree, if i try to remove it and then on top of it add my node its throws null pointer....
this entire code is inside the BeforeExpand event method and earlier with the onClick event this peice of code used to work fine.
can you please help me with it ,
I am attaching the code snippet, i pass this ritem from the event , its of type TreeItem
and nodeStore is my list of modeldata to be added to the tree
if i delete the tSore.remove stmt , it works good but then the older node stays there
plz help


TreeModel treeRoot = (TreeModel) ritem.getModel();
TreeItem parent = ritem.getParentItem();
TreeModel mParent= (TreeModel)parent.getModel();

tStore.remove((BaseTreeModel<TreeModel>) mParent,(BaseTreeModel<TreeModel>) treeRoot);
tStore.insert((BaseTreeModel<TreeModel>) mParent,nodeStore, index, true);

please let me know if you need any more info