[Title] removed duplicate code in reArrangeTabs()
authorhyeran74.kim <hyeran74.kim@samsung.com>
Tue, 18 Mar 2014 07:35:42 +0000 (16:35 +0900)
committerhyeran74.kim <hyeran74.kim@samsung.com>
Tue, 18 Mar 2014 07:35:42 +0000 (16:35 +0900)
[Desc.]
[Issue]

Change-Id: Id55d1509208a7c6c7a8247ef715bc89ec63f29e0
Signed-off-by: hyeran74.kim <hyeran74.kim@samsung.com>
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/DATabComposite.java

index 5e57d74..8bcd82f 100644 (file)
@@ -199,7 +199,8 @@ public class DATabComposite extends DAView {
                                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;
                                        }
                                        
@@ -213,7 +214,6 @@ public class DATabComposite extends DAView {
                                        }else{
                                                targetButtonIndex = curPosition.x / tabWidth;
                                        }
-                                       
                                        // check whether the tab button has clicked or moved
                                        if (targetButtonIndex == sourceButtonIndex) {
                                                //click
@@ -288,6 +288,7 @@ public class DATabComposite extends DAView {
                return tabButton;
        }
 
+       // positioning of the tab button
        private void setLayoutTabs(int leftTabIndex, int tabIndex) {
                FormData data = new FormData();
                data.top = new FormAttachment(0, 0);
@@ -303,55 +304,36 @@ public class DATabComposite extends DAView {
        
        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);
                }
        }