1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.dnd;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
class TreeDragUnderEffect extends DragUnderEffect {
private Tree tree;
private TreeItem currentItem = null;
private int currentEffect = DND.FEEDBACK_NONE;
private TreeItem[] selection = new TreeItem[0];
TreeDragUnderEffect(Tree tree) {
this.tree = tree;
}
void show(int effect, int x, int y) {
TreeItem item = null;
if (effect != DND.FEEDBACK_NONE) item = findItem(x, y);
if (item == null) effect = DND.FEEDBACK_NONE;
if (currentEffect != effect && currentEffect == DND.FEEDBACK_NONE) {
selection = tree.getSelection();
tree.setSelection(new TreeItem[0]);
}
boolean restoreSelection = currentEffect != effect && effect == DND.FEEDBACK_NONE;
setDragUnderEffect(effect, item);
if (restoreSelection) {
tree.setSelection(selection);
selection = new TreeItem[0];
}
}
private TreeItem findItem(int x , int y){
Point coordinates = new Point(x, y);
coordinates = tree.toControl(coordinates);
return tree.getItem(coordinates);
}
private void setDragUnderEffect(int effect, TreeItem item) {
switch (effect) {
case DND.FEEDBACK_SELECT:
if (currentEffect == DND.FEEDBACK_INSERT_AFTER ||
currentEffect == DND.FEEDBACK_INSERT_BEFORE) {
setInsertMark(null, false);
currentEffect = DND.FEEDBACK_NONE;
currentItem = null;
}
if (currentEffect != effect || currentItem != item) {
setDropSelection(item);
currentEffect = DND.FEEDBACK_SELECT;
currentItem = item;
}
break;
case DND.FEEDBACK_INSERT_AFTER:
case DND.FEEDBACK_INSERT_BEFORE:
if (currentEffect == DND.FEEDBACK_SELECT) {
setDropSelection(null);
currentEffect = DND.FEEDBACK_NONE;
currentItem = null;
}
if (currentEffect != effect || currentItem != item) {
setInsertMark(item, effect == DND.FEEDBACK_INSERT_AFTER);
currentEffect = effect;
currentItem = item;
}
break;
default :
if (currentEffect == DND.FEEDBACK_INSERT_AFTER ||
currentEffect == DND.FEEDBACK_INSERT_BEFORE) {
setInsertMark(null, false);
}
if (currentEffect == DND.FEEDBACK_SELECT) {
setDropSelection(null);
}
currentEffect = DND.FEEDBACK_NONE;
currentItem = null;
break;
}
}
private void setDropSelection (TreeItem item) {
if (item == null) {
tree.setSelection(new TreeItem[0]);
} else {
tree.setSelection(new TreeItem[]{item});
}
}
private void setInsertMark (TreeItem item, boolean after) {
// not currently implemented
}
}
|