Mouse Event handling problem [message #1237668] |
Thu, 30 January 2014 09:35 |
|
Hey!
We have a slight problem with context menus in our application. We have debugged this a lot, and now finally discovered what is the problem. Maybe you have a solution
We have a double click handler on the left mouse button and a single click handler on the right mouse button. Now when clicking left on a row (to select it) and immediately clicking right (to open the context menu), nothing happens... this is due to the fact that the current mode handler (for the left button) is waiting for the second left click for a double click
Would it be possible to switch modes as soon as the mouse button for the current and the initial event differ, or something like that?
Hope that was clear enough
Cheers,
Markus
|
|
|
|
|
Re: Mouse Event handling problem [message #1237725 is a reply to message #1237720] |
Thu, 30 January 2014 12:28 |
|
This issue is a serious problem for our application. Could you give us as a rough estimation (1 day, 1 week, 1 month) on when you could have a look?
If you think that you will NOT have the time we would need to fix it in our private version. We anyhow have it because of the singleton editor stuff...
Regards,
Michael
|
|
|
|
|
Re: Mouse Event handling problem [message #1237743 is a reply to message #1237735] |
Thu, 30 January 2014 13:25 |
Dirk Fauth Messages: 2903 Registered: July 2012 |
Senior Member |
|
|
As you already have your "private" version. Could you please try to add the following code to MouseModeEventHandler and test if it fixes your issue?
And more important, test that it doesn't has impact on existing functionality?
private boolean skipProcessing = false;
@Override
public void mouseUp(final MouseEvent event) {
mouseDown = false;
doubleClick = false;
if (singleClickAction != null) {
//convert/validate/commit/close possible open editor
//needed in case of conversion/validation errors to cancel any action
if (EditUtils.commitAndCloseActiveEditor()) {
if (doubleClickAction != null &&
(isActionExclusive(singleClickAction) || isActionExclusive(doubleClickAction))) {
//If a doubleClick action is registered and either the single click or the double
//click action is exclusive, wait to see if this mouseUp is part of a doubleClick or not.
event.display.timerExec(event.display.getDoubleClickTime(), new Runnable() {
@Override
public void run() {
if (!doubleClick && !skipProcessing) {
executeClickAction(singleClickAction, event);
}
}
});
} else {
executeClickAction(singleClickAction, event);
}
}
}
else if (doubleClickAction == null) {
//No single or double click action registered when mouseUp detected. Switch back to normal mode.
switchMode(Mode.NORMAL_MODE);
}
}
@Override
public void mouseDown(MouseEvent event) {
//another mouse click was performed than initial
//This handling is necessary to react correctly e.g. if an action is registered
//for left double click and an action for right single click. Performing a left
//and right click in short sequence, nothing will happen without this handling
if (event.button != this.initialMouseDownEvent.button) {
//ensure the double click runnable is not executed and process single click immediately
this.skipProcessing = true;
executeClickAction(singleClickAction, event);
//reset to the parent mode
switchMode(Mode.NORMAL_MODE);
//start the mouse event processing for the new button
getModeSupport().mouseDown(event);
}
}
If everything works as intended, I will commit it to core.
Greez,
Dirk
|
|
|
|
|
|
Re: Mouse Event handling problem [message #1239060 is a reply to message #1238115] |
Mon, 03 February 2014 08:47 |
|
Hehe I found something related to the original issue. when i select a cell and press CTRL+A, it does not do anything (provided i didn't move the mouse after the double click timeout). The problem is again with the mouse mode handler: it has an empty keyPressed, so all key presses are lost...
I see two simple solutions, but don't know about the impact:
1) move logic from configurable mode handler to abstract
2) make mouse mode handler extend the configurable handler
any ideas?
|
|
|
Re: Mouse Event handling problem [message #1239083 is a reply to message #1239060] |
Mon, 03 February 2014 10:10 |
Dirk Fauth Messages: 2903 Registered: July 2012 |
Senior Member |
|
|
Both solutions doesn't work for me.
1) move logic from configurable to abstract
the AbstractModeEventHandler doesn't know about the NatTable instance and I don't want to introduce that dependency
2) make mouse extend configurable
also not a good idea, as we would need to ensure that we correctly override every method
Also in case of the MouseModeEventHandler we not only need to execute the key action, we also need to ensure the click handling is executed, e.g. you also have a single click handler that should be executed exclusively, also got a double click handler, and while waiting for the second click, the key action is triggered, which means to execute the single click before the key action, but avoid the double click. Too much dependencies to simply solve it via inheritance.
BTW, as you mentioned key modifiers I noticed that the initial issue would also appear if you click without modifier and soon after clicking again with pressing for example the CTRL key.
And I also noticed that the wrong event is executed for single click execution in mouseDown.
Please try to add this snippet to your codebase and test if it works for and does not have any impact on other use cases.
@Override
public void mouseDown(MouseEvent event) {
//another mouse click was performed than initial
//This handling is necessary to react correctly e.g. if an action is registered
//for left double click and an action for right single click. Performing a left
//and right click in short sequence, nothing will happen without this handling.
//This is also true in case a click is performed without modifier key pressed
//and performing a mouse click with modifier key pressed shortly after.
if ((event.button != this.initialMouseDownEvent.button)
|| (event.stateMask != this.initialMouseDownEvent.stateMask)) {
//ensure the double click runnable is not executed and process single click immediately
this.skipProcessing = true;
executeClickAction(singleClickAction, this.initialMouseDownEvent);
//reset to the parent mode
switchMode(Mode.NORMAL_MODE);
//start the mouse event processing for the new button
getModeSupport().mouseDown(event);
}
}
@Override
public void keyPressed(KeyEvent event) {
//ensure the double click runnable is not executed and process single click immediately
this.skipProcessing = true;
executeClickAction(singleClickAction, this.initialMouseDownEvent);
//reset to the parent mode
switchMode(Mode.NORMAL_MODE);
//start the key event processing
getModeSupport().keyPressed(event);
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04205 seconds