PDA

View Full Version : OnMouseDown in nested components



user4
26 Jan 2009, 7:42 AM
Hi,
I have a LayoutContainer that contains multiple FormPanel. I need to get a OnMouseDown event on both LayoutContainer and on FormPanels: if the user clicks on the Form Panel - the formPanel OnMouseDown event is executed; if the user clicks on the LayoutContainer(between the FormPanels) - LayoutContainer OnMouseDown event is executed.
I can get the event on ether LayoutContainer or on FormPanel. How do i get it on both?

publicclass FormContainer extends LayoutContainer {
private Vector<FormPanel> selectedElements = new Vector<FormPanel>();
public FormContainer(){
setLayoutOnChange(true);
setStyleAttribute("background", "white");
//sinkEvents(Events.OnMouseDown);
addListener(Events.OnMouseDown, new Listener<ComponentEvent>() {
publicvoid handleEvent(ComponentEvent be) {
for(int i = 0; i<selectedElements.size(); i++){
selectedElements.elementAt(i).setStyleAttribute("background", "transparent");
}
selectedElements.clear();
GWT.log("[Events.OnMouseDown] LayoutContainer" , null);
}
});
FormPanel simple = new FormPanel();
simple.setFrame(true);
simple.setWidth(350);
simple.setBorders(false);
simple.setBodyBorder(false);
simple.setStyleAttribute("border", "0px");
simple.setFrame(false);
simple.setHeaderVisible(false);
Draggable d = new Draggable(simple);
simple.sinkEvents(Events.OnMouseDown);
simple.addListener(Events.OnMouseDown, new Listener<ComponentEvent>() {
publicvoid handleEvent(ComponentEvent be) {
FormPanel fp = (FormPanel)be.component;
fp.setStyleAttribute("background", "#E1EDFC");
GWT.log("[Events.OnMouseDown]" , null);

if(!selectedElements.contains(fp)){
fp.setStyleAttribute("background", "#E1EDFC");
selectedElements.add(fp);
}
else{
fp.setStyleAttribute("background", "transparent");
selectedElements.remove(fp);
}
}
});
TextField<String> inputField = new TextField<String>();
simple.add(inputField);
this.add(simple);
}
}

user4
28 Jan 2009, 11:21 AM
Any suggestions?