Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Mouse Event handling problem
Mouse Event handling problem [message #1237668] Thu, 30 January 2014 09:35 Go to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
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 Smile

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 Sad

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 Smile

Cheers,
Markus
Re: Mouse Event handling problem [message #1237699 is a reply to message #1237668] Thu, 30 January 2014 11:10 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi,

yes it was clear enough. Smile

With the current architecture I'm not yet sure on how to solve that without re-writing the mouse event handling in NatTable.

To understand why, here is what happens internally in your use case:
1. left click -> the ConfigurableModeEventHandler searches for actions registered for single and double left click and activates a MouseModeEventHandler that only knows about those two actions
2. right click -> the current active MouseModeEventHandler receives the right click. The issue here is that it does not know about the action that should be executed on right click, as it was activated for the left click. And as there is no action registered for single left click, and it is no double click, nothing happens.

Because of that, your proposed solution wouldn't work. At least not without modifications to the handling itself. One idea would be to extend the MouseModeEventHandler to know about the mouse button that was clicked AND to know the ConfigurableModeEventHandler (which is something I don't like much). And in your case the mouse event needs to be handled by the parent. Not sure if this would really solve the issue and if it would have other effects.

Please create a ticket for this. Maybe I am able to work on it before freezing the 1.x architecture.

Greez,
Dirk
Re: Mouse Event handling problem [message #1237720 is a reply to message #1237699] Thu, 30 January 2014 12:12 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
this was actually what i was thinking of:
- MouseModeEventHandler knows it's "parent" (you don't like it, i read Wink)
- If a mouseDown occurs with a button different from the initial event's button, re-route the event to the parent instead of handling itself.

i opened a bug for the issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=426987
Re: Mouse Event handling problem [message #1237725 is a reply to message #1237720] Thu, 30 January 2014 12:28 Go to previous messageGo to next message
Michael Heiss is currently offline Michael HeissFriend
Messages: 20
Registered: November 2013
Location: Graz, Austria
Junior Member
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 #1237733 is a reply to message #1237725] Thu, 30 January 2014 12:58 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quote:
we would need to fix it in our private version


If it is that important and you have a fix, why don't you contribute back? I also still wait for the modification of the editor stuff so I can add it into core.

BTW, I'm a consultant and if you need better support, there are ways to achieve this! Wink
Re: Mouse Event handling problem [message #1237735 is a reply to message #1237733] Thu, 30 January 2014 13:04 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
you mean we owe you a coffee? Very Happy

joke aside - we'll come up with something Wink

[Updated on: Thu, 30 January 2014 13:05]

Report message to a moderator

Re: Mouse Event handling problem [message #1237743 is a reply to message #1237735] Thu, 30 January 2014 13:25 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
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 #1238036 is a reply to message #1237743] Fri, 31 January 2014 08:16 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
will trigger michael to test build this ASAP, thanks a lot
Re: Mouse Event handling problem [message #1238085 is a reply to message #1238036] Fri, 31 January 2014 11:03 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
works as expected, no negative issues i can see.
Re: Mouse Event handling problem [message #1238115 is a reply to message #1238085] Fri, 31 January 2014 12:31 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Ok great, I pushed the fix to our repo. If an issue comes up with this change, hopefully we find it before the 1.1 release.

Hope to get an update to the editor stuff soon!

Greez,
Dirk

BTW, now you owe me a coffee! Wink
Re: Mouse Event handling problem [message #1239060 is a reply to message #1238115] Mon, 03 February 2014 08:47 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
Hehe Smile 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? Smile
Re: Mouse Event handling problem [message #1239083 is a reply to message #1239060] Mon, 03 February 2014 10:10 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
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);
	}
Re: Mouse Event handling problem [message #1239193 is a reply to message #1239083] Mon, 03 February 2014 15:53 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
looks promising. will check thoroughly tomorrow Smile but from a first few clicks and presses everything works.
Re: Mouse Event handling problem [message #1239417 is a reply to message #1239193] Tue, 04 February 2014 06:32 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
everything ok AFAICT. nothing (we use) broke Smile thanks (again). soon it will be a whole coffeepot Wink
Re: Mouse Event handling problem [message #1239451 is a reply to message #1239417] Tue, 04 February 2014 08:29 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Thanks for testing. I pushed the modification to our repository. Hopefully there are more people involved in testing the current development snapshot so we are able to identify issues with that solution early.
Previous Topic:Retreive the resulting POJO list after filtering the nattable
Next Topic:NatTable scroll bar appears all time when event list is cleared
Goto Forum:
  


Current Time: Thu Mar 28 20:51:55 GMT 2024

Powered by FUDForum. Page generated in 0.05018 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top