i have a problem with the mouse selection in a tree. i can add a single and double click listener to the three with no problem. the problem i have is that when i double click an item it runs through both listener. Through the mouse down listener twice (first event with one click, second event with count = 2) and then again through the double click listener. However I want to execute different actions depending on the clicks, but since there seems to be always a single click involved this makes it kinda impossible. Is there a way to differ between the clicks, so that the mouse down (single click) listener only reacts when the user really clicked just once?
And how would you know the first click from a 'series of clicks'? You cannot. You simply have to wait if further clicks happen. When there's only one click in a span of time it's a single click. When there're more than one click in that time span, it's a not-single-click. Are you sure you need both actions (click and double-click) in the way you described?
Censorship is the younger of two shameful sisters, the older one bears the name inquisition. -- Johann Nepomuk Nestroy
Like mentioned, you have to handle single *and* double clicks. In most applications, double-clicking on something is an extension of single-clicking on that same thing, so it usually ends up okay. Here's some code:
I encoutered similar issue last time. Although, MouseEvent has count property, the SWT.MouseDown event is always called first before the SWT.MouseDoubleClick. So the workaround is to wait till the SWT.MouseDoubleClick has been fired, then check the flag which event was fired. The code is something like below.
SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4