boolean expandOccurred = false;
public void handleEvent(final Event e) {
if (e.type == SWT.DefaultSelection) {
SelectionEvent event = new SelectionEvent(e);
fireDefaultSelectionEvent(event);
if (CURRENT_METHOD == DOUBLE_CLICK) {
fireOpenEvent(event);
} else {
if (enterKeyDown) {
fireOpenEvent(event);
enterKeyDown = false;
defaultSelectionPendent = null;
} else {
defaultSelectionPendent = event;
}
}
return;
}
switch (e.type) {
case SWT.MouseEnter:
case SWT.MouseExit:
mouseUpEvent = null;
mouseMoveEvent = null;
selectionPendent = null;
break;
case SWT.MouseMove:
if ((CURRENT_METHOD & SELECT_ON_HOVER) == 0) {
return;
}
if (e.stateMask != 0) {
return;
}
if (e.widget.getDisplay().getFocusControl() != e.widget) {
return;
}
mouseMoveEvent = e;
final Runnable runnable[] = new Runnable[1];
runnable[0] = new Runnable() {
public void run() {
long time = System.currentTimeMillis();
int diff = (int) (time - startTime);
if (diff <= TIME) {
display.timerExec(diff * 2 / 3, runnable[0]);
} else {
timerStarted = false;
setSelection(mouseMoveEvent);
}
}
};
startTime = System.currentTimeMillis();
if (!timerStarted) {
timerStarted = true;
display.timerExec(TIME * 2 / 3, runnable[0]);
}
break;
case SWT.MouseDown:
mouseUpEvent = null;
arrowKeyDown = false;
break;
case SWT.Expand:
expandOccurred = true;
break;
case SWT.Collapse:
collapseOccurred = true;
break;
case SWT.MouseUp:
mouseMoveEvent = null;
if ((e.button != 1) || ((e.stateMask & ~SWT.BUTTON1) != 0)) {
return;
}
if (selectionPendent != null
&& !(collapseOccurred || expandOccurred)) {
mouseSelectItem(selectionPendent);
} else {
mouseUpEvent = e;
collapseOccurred = false;
expandOccurred = false;
}
break;
case SWT.KeyDown:
mouseMoveEvent = null;
mouseUpEvent = null;
arrowKeyDown = ((e.keyCode == SWT.ARROW_UP) || (e.keyCode == SWT.ARROW_DOWN))
&& e.stateMask == 0;
if (e.character == SWT.CR) {
if (defaultSelectionPendent != null) {
fireOpenEvent(new SelectionEvent(e));
enterKeyDown = false;
defaultSelectionPendent = null;
} else {
enterKeyDown = true;
}
}
break;
case SWT.Selection:
SelectionEvent event = new SelectionEvent(e);
fireSelectionEvent(event);
mouseMoveEvent = null;
if (mouseUpEvent != null) {
mouseSelectItem(event);
} else {
selectionPendent = event;
}
count[0]++;
final int id = count[0];
// In the case of arrowUp/arrowDown when in the arrowKeysOpen mode, we
// want to delay any selection until the last arrowDown/Up occurs. This
// handles the case where the user presses arrowDown/Up successively.
// We only want to open an editor for the last selected item.
display.asyncExec(new Runnable() {
public void run() {
if (arrowKeyDown) {
display.timerExec(TIME, new Runnable() {
public void run() {
if (id == count[0]) {
firePostSelectionEvent(new SelectionEvent(
e));
if ((CURRENT_METHOD & ARROW_KEYS_OPEN) != 0) {
fireOpenEvent(new SelectionEvent(
e));
}
}
}
});
} else {
firePostSelectionEvent(new SelectionEvent(e));
}
}
});
break;
}
}
void mouseSelectItem(SelectionEvent e) {
if ((CURRENT_METHOD & SINGLE_CLICK) != 0) {
fireOpenEvent(e);
}
mouseUpEvent = null;
selectionPendent = null;
}
void setSelection(Event e) {
if (e == null) {
return;
}
Widget w = e.widget;
if (w.isDisposed()) {
return;
}
SelectionEvent selEvent = new SelectionEvent(e);
/*ISSUE: May have to create a interface with method:
setSelection(Point p) so that user's custom widgets
can use this class. If we keep this option. */
if (w instanceof Tree) {