case SWT.MouseUp:
drag = false;
if(curPosition.y < tabComposite.getBounds().y
- || curPosition.y > tabComposite.getBounds().height) {
+ || curPosition.y > tabComposite.getBounds().height
+ || sourceButtonIndex == getButtons().size()) {
return;
}
}else{
targetButtonIndex = curPosition.x / tabWidth;
}
-
// check whether the tab button has clicked or moved
if (targetButtonIndex == sourceButtonIndex) {
//click
return tabButton;
}
+ // positioning of the tab button
private void setLayoutTabs(int leftTabIndex, int tabIndex) {
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
private void reArrangeTabs() {
if (sourceButtonIndex < targetButtonIndex) { // move forward
+ // source
+ setLayoutTabs(targetButtonIndex, sourceButtonIndex);
if (sourceButtonIndex == 0) { // source == first tab
- // source
- setLayoutTabs(targetButtonIndex, sourceButtonIndex);
// source+1
setLayoutTabs(-1, (sourceButtonIndex + 1));
- // target+1
- if (targetButtonIndex != getButtons().size()-1) {
- setLayoutTabs(sourceButtonIndex, (targetButtonIndex+1));
- }
- Collections.rotate(getButtons().subList(sourceButtonIndex, targetButtonIndex + 1), -1);
- Collections.rotate(getTabChildren().subList(sourceButtonIndex, targetButtonIndex + 1), -1);
} else {
- // source
- setLayoutTabs(targetButtonIndex, sourceButtonIndex);
// source+1
setLayoutTabs((sourceButtonIndex - 1), (sourceButtonIndex + 1));
- // target+1
- if (targetButtonIndex != getButtons().size()-1) {
- setLayoutTabs(sourceButtonIndex, (targetButtonIndex + 1));
- }
- Collections.rotate(getButtons().subList(sourceButtonIndex, targetButtonIndex + 1), -1);
- Collections.rotate(getTabChildren().subList(sourceButtonIndex, targetButtonIndex + 1), -1);
}
+ // target+1
+ if (targetButtonIndex != getButtons().size()-1) {
+ setLayoutTabs(sourceButtonIndex, (targetButtonIndex + 1));
+ }
+ Collections.rotate(getButtons().subList(sourceButtonIndex, targetButtonIndex + 1), -1);
+ Collections.rotate(getTabChildren().subList(sourceButtonIndex, targetButtonIndex + 1), -1);
} else { // move backward
- if (sourceButtonIndex == getButtons().size() - 1) { // source == last tab
- // source
- if (targetButtonIndex != 0) {
- setLayoutTabs((targetButtonIndex - 1), sourceButtonIndex);
- } else {
- setLayoutTabs(-1, sourceButtonIndex);
- }
- // target
- setLayoutTabs(sourceButtonIndex, targetButtonIndex);
- Collections.rotate(getButtons().subList(targetButtonIndex, sourceButtonIndex + 1), 1);
- Collections.rotate(getTabChildren().subList(targetButtonIndex, sourceButtonIndex + 1), 1);
- } else {
- // source
- if (targetButtonIndex == 0) {
- setLayoutTabs(-1, sourceButtonIndex);
- } else {
- setLayoutTabs((targetButtonIndex - 1), sourceButtonIndex);
- }
- // source+1
+ // source
+ if (targetButtonIndex == 0) { // target == first tab
+ setLayoutTabs(-1, sourceButtonIndex);
+ } else {
+ setLayoutTabs((targetButtonIndex - 1), sourceButtonIndex);
+ }
+ if (sourceButtonIndex != getButtons().size() - 1) {
+ // source+1
setLayoutTabs((sourceButtonIndex - 1), (sourceButtonIndex + 1));
- // target
- setLayoutTabs(sourceButtonIndex, targetButtonIndex);
- Collections.rotate(getButtons().subList(targetButtonIndex, sourceButtonIndex + 1), 1);
- Collections.rotate(getTabChildren().subList(targetButtonIndex, sourceButtonIndex + 1), 1);
- }
+ }
+ // target
+ setLayoutTabs(sourceButtonIndex, targetButtonIndex);
+ Collections.rotate(getButtons().subList(targetButtonIndex, sourceButtonIndex + 1), 1);
+ Collections.rotate(getTabChildren().subList(targetButtonIndex, sourceButtonIndex + 1), 1);
}
}