tp = widget;
this.targetTab = targetTab;
}
public void onDrop(DragContext dragContext) {
WSTab sourceTab = (WSTab) dragContext.draggable;
/**
* The original position of the tab
*/
int sourceIdx = tp.getWidgetIndex(sourceTab.getWidgetRef());
/**
* The requested position of the tab
*/
int destIdx = tp.getWidgetIndex(targetTab.getWidgetRef());
if (sourceIdx < destIdx) {
// moving right
if (destIdx == (tp.getWidgetCount() - 1)) {
// the target is the right-most targetTab
tp.remove(sourceTab.getWidgetRef());
tp.remove(targetTab.getWidgetRef());
tp.add(targetTab.getWidgetRef(), targetTab);
tp.add(sourceTab.getWidgetRef(), sourceTab);
}
else {
tp.insert(sourceTab.getWidgetRef(), sourceTab, destIdx + 1);
}
}
else {
/**
* We're moving left
*/
tp.remove(sourceIdx);
if (tp.getWidgetCount() <= destIdx) {
tp.add(sourceTab.getWidgetRef(), sourceTab);
tp.add(targetTab.getWidgetRef(), targetTab);
}
else {
tp.insert(sourceTab.getWidgetRef(), sourceTab, destIdx);
tp.insert(targetTab.getWidgetRef(), targetTab, destIdx + 1);
}
}
tp.selectTab(destIdx);
sourceTab.reset();
targetTab.reset();
super.onDrop(dragContext);
}