1 11 package org.eclipse.ui.internal.presentations.util; 12 13 import org.eclipse.jface.util.Geometry; 14 import org.eclipse.swt.graphics.Point; 15 import org.eclipse.swt.graphics.Rectangle; 16 import org.eclipse.swt.widgets.Control; 17 import org.eclipse.ui.internal.dnd.DragUtil; 18 import org.eclipse.ui.presentations.StackDropResult; 19 20 23 public class ReplaceDragHandler extends TabDragHandler { 24 25 private final class DragCookie { 26 int insertPosition; 27 28 public DragCookie(int pos) { 29 insertPosition = pos; 30 } 31 } 32 33 private AbstractTabFolder tabFolder; 34 35 public ReplaceDragHandler(AbstractTabFolder folder) { 36 this.tabFolder = folder; 37 } 38 39 42 public StackDropResult dragOver(Control currentControl, Point location, 43 int dragStart) { 44 45 48 AbstractTabItem tabUnderPointer = tabFolder.getItem(location); 49 50 if (tabUnderPointer == null) { 53 Rectangle titleArea = tabFolder.getTabArea(); 54 55 if (titleArea.contains(location) && tabFolder.getItemCount() > 0) { 58 int dragOverIndex = tabFolder.getItemCount(); 59 AbstractTabItem lastTab = tabFolder.getItem(dragOverIndex - 1); 60 61 if (!lastTab.isShowing()) { 63 return null; 64 } 65 66 Rectangle lastTabBounds = lastTab.getBounds(); 68 if (lastTabBounds.isEmpty()) { 69 return null; 70 } 71 72 if (dragStart >= 0) { 73 dragOverIndex--; 74 75 return new StackDropResult(lastTabBounds, new Integer ( 76 dragOverIndex)); 77 } 78 79 Rectangle dropRectangle = titleArea; 83 84 dropRectangle.x = lastTabBounds.x + lastTabBounds.width; 85 dropRectangle.width = 3 * dropRectangle.height; 86 return new StackDropResult(dropRectangle, new Integer ( 87 dragOverIndex)); 88 89 } else { 90 Rectangle displayBounds = DragUtil.getDisplayBounds(tabFolder.getControl()); 93 int closestSide = Geometry.getClosestSide(displayBounds, location); 94 if (closestSide == tabFolder.getTabPosition()) { 95 return new StackDropResult(displayBounds, null); 96 } 97 98 return null; 99 } 100 } 101 102 if (!tabUnderPointer.isShowing()) { 103 return null; 104 } 105 106 Rectangle tabBounds = tabUnderPointer.getBounds(); 107 108 if (tabBounds.isEmpty()) { 109 return null; 110 } 111 112 return new StackDropResult(tabBounds, new DragCookie(tabFolder 113 .indexOf(tabUnderPointer))); 114 } 115 116 119 public int getInsertionPosition(Object cookie) { 120 if (cookie instanceof DragCookie) { 121 return Math.min(tabFolder.getItemCount(), 122 ((DragCookie) cookie).insertPosition); 123 } 124 125 return tabFolder.getItemCount(); 126 } 127 128 } 129 | Popular Tags |