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.widget.client;
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 public class VerticalDraggableTrackPanel extends Composite implements TrackPanel {
43
44 private class MyDragController extends PickupDragController {
45 public MyDragController(AbsolutePanel boundaryPanel, boolean allowDroppingOnBoundaryPanel) {
46 super(boundaryPanel, allowDroppingOnBoundaryPanel);
47 }
48
49 @Override
50 public void dragStart() {
51 Style.overflowHidden(absolutePanel);
52 super.dragStart();
53 }
54
55 @Override
56 public void dragEnd() {
57 Style.overflowAuto(absolutePanel);
58 super.dragEnd();
59 }
60 }
61
62 public static final String TABLE_STYLE = "dg-table";
63
64 private AbsolutePanel absolutePanel = new AbsolutePanel();
65 private VerticalPanel verticalPanel = new VerticalPanel();
66
67 private MyDragController widgetDragController;
68 private IndexedDropController widgetDropController;
69
70 public VerticalDraggableTrackPanel() {
71
72 initWidget(absolutePanel);
73 drawWidget();
74
75 widgetDragController = new MyDragController(absolutePanel, false);
76 widgetDropController = new IndexedDropController(verticalPanel);
77
78 widgetDragController.setBehaviorConstrainedToBoundaryPanel(false);
79 widgetDragController.registerDropController(widgetDropController);
80
81 }
82
83 public void setSpacing(int spacing) {
84 verticalPanel.setSpacing(0);
85 }
86
87 public void setBorderWidth(int borderWidth) {
88 verticalPanel.setBorderWidth(0);
89 }
90
91 protected void drawWidget() {
92 Style.fullSize(absolutePanel);
93 Style.overflowAuto(absolutePanel);
94 absolutePanel.add(verticalPanel);
95 }
96
97
98
99
100
101
102 public void add(Widget w) {
103 if (w instanceof TrackFrame) {
104 TrackFrame frame = (TrackFrame) w;
105 add(frame, frame.getDraggableWidget());
106 }
107 else
108 verticalPanel.add(w);
109 }
110
111
112
113
114
115
116
117 public int getIndex(Widget w) {
118 return verticalPanel.getWidgetIndex(w);
119 }
120
121
122
123
124
125
126
127
128 public void insert(Widget w, Widget dragHandle, int beforeIndex) {
129 widgetDragController.makeDraggable(w, dragHandle);
130 verticalPanel.insert(w, beforeIndex);
131 }
132
133
134
135
136
137
138
139
140 public void add(Widget w, Widget dragHandle) {
141 widgetDragController.makeDraggable(w, dragHandle);
142 verticalPanel.add(w);
143 }
144
145 public Iterator<Widget> iterator() {
146 return verticalPanel.iterator();
147 }
148
149 public boolean remove(Widget w) {
150 return verticalPanel.remove(w);
151 }
152
153 public boolean empty() {
154 return verticalPanel.getWidgetCount() == 0;
155 }
156
157 public void clear() {
158 verticalPanel.clear();
159 }
160
161 }