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 package org.utgenome.gwt.utgb.client.ui;
26
27 import java.util.Iterator;
28
29 import com.allen_sauer.gwt.dnd.client.PickupDragController;
30 import com.allen_sauer.gwt.dnd.client.drop.IndexedDropController;
31 import com.google.gwt.user.client.ui.AbsolutePanel;
32 import com.google.gwt.user.client.ui.Composite;
33 import com.google.gwt.user.client.ui.VerticalPanel;
34 import com.google.gwt.user.client.ui.Widget;
35
36
37
38
39
40
41
42
43
44 public class DraggableTable extends Composite {
45 public static final String TABLE_STYLE = "dg-table";
46
47 private AbsolutePanel _boundaryPanel = new AbsolutePanel();
48 private VerticalPanel _verticalPanel = new VerticalPanel();
49
50 private PickupDragController widgetDragController;
51 private IndexedDropController widgetDropController;
52
53 public DraggableTable() {
54 _boundaryPanel.setSize("100%", "100%");
55 _boundaryPanel.add(_verticalPanel);
56 _verticalPanel.setStyleName(TABLE_STYLE);
57
58
59 widgetDragController = new PickupDragController(_boundaryPanel, false);
60 widgetDropController = new IndexedDropController(_verticalPanel);
61
62 widgetDragController.setBehaviorConstrainedToBoundaryPanel(false);
63 widgetDragController.registerDropController(widgetDropController);
64
65 initWidget(_boundaryPanel);
66 }
67
68
69
70
71
72
73
74 public void add(Widget w) {
75 widgetDragController.makeDraggable(w);
76 _verticalPanel.add(w);
77 }
78
79
80
81
82
83
84
85 public int getIndex(Widget w) {
86 return _verticalPanel.getWidgetIndex(w);
87 }
88
89
90
91
92
93
94
95
96 public void insert(Widget w, Widget dragHandle, int beforeIndex) {
97 widgetDragController.makeDraggable(w, dragHandle);
98 _verticalPanel.insert(w, beforeIndex);
99 }
100
101
102
103
104
105
106
107
108 public void add(Widget w, Widget dragHandle) {
109 widgetDragController.makeDraggable(w, dragHandle);
110 _verticalPanel.add(w);
111 }
112
113 public Iterator<Widget> iterator() {
114 return _verticalPanel.iterator();
115 }
116
117 public void remove(Widget w) {
118 _verticalPanel.remove(w);
119 }
120
121 public boolean empty() {
122 return _verticalPanel.getWidgetCount() == 0;
123 }
124
125 public void clear() {
126 _verticalPanel.clear();
127 }
128
129 }