prevent event layoutClickEvent

Hi,

is there a way to prevent a layoutclickevent to rise if the event is already managed?

for instance:
one verticalLayout that contain an image.

Add a layoutClickListener to the layout and a clickListener to the image.

When a click is done on the image, the click has not to be rised to the layout.

May be i have to manage the structure in a different manner ?

Thanks

Hi,

one way around it would be just to use some kind of flag to signal that you don’t want to handle the event in the beginning of the block, like follows:

boolean layoutClickDisabled = false;
// ...
layout.addLayoutClickListener(event -> {
    if (!layoutClickDisabled) {
      // do layout click handling
    }
});
// ...

image.addClickListener(event -> {
    layoutClickDisabled = true;
   // do image click handling 
});

-Olli

Hi,

Thanks for the answer,

In my case a can not use a flag because i have also to receive the events from the LayoutClickListener,

the case is a layout that contains one or more layout that contain one image when a click is done on the image than i need to intercept the click , when the click is done outside the images area but on the layout area then i need to intercept the click on the layout.

May be i can use a flag but just to identify that the of the event is from the image element and reset it after the event is managed on the layout trigger.

something like this:

boolean imageClickOrigin = false;
// ...
layout.addLayoutClickListener(event -> {
    if (!imageClickOrigin) {
      // do layout click handling
    }
     
    imageClickOrigin = false;

});
// ...

image.addClickListener(event -> {
    imageClickOrigin = true;
   // do image click handling 
});

Thanks for the help.

Giovanni

Yeah, that sounds like it’ll work.

-Olli

Thanks a lot.

Bye