try {
if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
if (dtde.getTransferable().isDataFlavorSupported(MyDoggyTransferable.TOOL_WINDOW_ID_DF)) {
try {
Transferable transferable = dtde.getTransferable();
ToolWindow toolWindow = toolWindowManager.getToolWindow(
dtde.getTransferable().getTransferData(MyDoggyTransferable.TOOL_WINDOW_ID_DF)
);
if (toolWindow != null) {
// Move tool to another anchor
// Chech if it was a tab
if (transferable.isDataFlavorSupported(MyDoggyTransferable.TOOL_WINDOW_TAB_ID_DF)) {
// Remove from tab
ToolWindowTab tab = (ToolWindowTab) toolWindowManager.lookupDockable(
transferable.getTransferData(MyDoggyTransferable.TOOL_WINDOW_TAB_ID_DF)
);
tab.getOwner().removeToolWindowTab(tab);
toolWindow = (ToolWindow) tab.getDockableDelegator();
}
if (toolWindow == onToolWindow)
return;
boolean oldAggregateMode = toolWindow.isAggregateMode();
toolWindow.setAggregateMode(true);
try {
if (dragAnchor == null && onToolWindow != null && toolWindow != onToolWindow) {
if (!SwingUtil.getBoolean("drag.toolwindow.asTab", true)) {
// Choose drag anchor ...
switch (onToolWindow.getAnchor()) {
case LEFT:
case RIGHT:
dragAnchor = ToolWindowAnchor.TOP;
break;
case TOP:
case BOTTOM:
dragAnchor = ToolWindowAnchor.LEFT;
break;
}
}
}
if (dragAnchor != null) {
switch (dragAnchor) {
case LEFT:
if (onToolWindow != null) {
toolWindow.aggregate(onToolWindow, AggregationPosition.LEFT);
} else {
if (checkCondition(toolWindow)) {
toolWindow.aggregateByReference(floatingWindow.getDockable(), AggregationPosition.LEFT);
}
}
break;
case RIGHT:
if (onToolWindow != null) {
toolWindow.aggregate(onToolWindow, AggregationPosition.RIGHT);
} else {
if (checkCondition(toolWindow)) {
toolWindow.aggregateByReference(floatingWindow.getDockable(), AggregationPosition.RIGHT);
}
}
break;
case BOTTOM:
if (onToolWindow != null) {
toolWindow.aggregate(onToolWindow, AggregationPosition.BOTTOM);
} else {
if (checkCondition(toolWindow)) {
toolWindow.aggregateByReference(floatingWindow.getDockable(), AggregationPosition.BOTTOM);
}
}
break;
case TOP:
if (onToolWindow != null) {
toolWindow.aggregate(onToolWindow, AggregationPosition.TOP);
} else {
if (checkCondition(toolWindow)) {
toolWindow.aggregateByReference(floatingWindow.getDockable(), AggregationPosition.TOP);
}
}
break;
}
toolWindow.setActive(true);
} else {
if (onToolWindow != null && toolWindow != onToolWindow) {
onToolWindow.addToolWindowTab(toolWindow).setSelected(true);
onToolWindow.setActive(true);
} else {
toolWindow.aggregateByReference(floatingWindow.getDockable(), AggregationPosition.DEFAULT);
toolWindow.setActive(true);
}
}
} finally {
toolWindow.setAggregateMode(oldAggregateMode);
}
dtde.dropComplete(true);
} else
dtde.dropComplete(false);