From e36e5dbecdab60c86a6d120058693b2be6cf62f2 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 19 Jan 2012 13:16:53 +0100 Subject: [PATCH] IDEA-73527 IOOBE at com.intellij.ui.tabs.FileColorSettingsTable$ModelAdapter.exchangeRows --- .../com/intellij/ui/TableRowsDnDSupport.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/TableRowsDnDSupport.java b/platform/platform-api/src/com/intellij/ui/TableRowsDnDSupport.java index 71079c808617..d199d2694e61 100644 --- a/platform/platform-api/src/com/intellij/ui/TableRowsDnDSupport.java +++ b/platform/platform-api/src/com/intellij/ui/TableRowsDnDSupport.java @@ -43,7 +43,15 @@ public class TableRowsDnDSupport { if (cellEditor != null) { cellEditor.stopCellEditing(); } - return new DnDDragStartBean(Integer.valueOf(table.rowAtPoint(p))); + return new DnDDragStartBean(new TableRowDragInfo(table, Integer.valueOf(table.rowAtPoint(p)))); + } + }) + .setTargetChecker(new DnDTargetChecker() { + @Override + public boolean update(DnDEvent event) { + final Object o = event.getAttachedObject(); + event.setDropPossible(o instanceof TableRowDragInfo && ((TableRowDragInfo)o).table == table); + return false; } }) .setDropHandler(new DnDDropHandler() { @@ -51,8 +59,8 @@ public class TableRowsDnDSupport { public void drop(DnDEvent event) { final Object o = event.getAttachedObject(); final Point p = event.getPoint(); - if (o instanceof Integer) { - int oldIndex = ((Integer)o).intValue(); + if (o instanceof TableRowDragInfo && ((TableRowDragInfo)o).table == table) { + int oldIndex = ((TableRowDragInfo)o).row; if (oldIndex == -1) return; int newIndex = table.rowAtPoint(p); if (newIndex == -1) { @@ -66,7 +74,8 @@ public class TableRowsDnDSupport { min++; } table.getSelectionModel().setSelectionInterval(min, min); - } else { + } + else { while (max > min) { model.exchangeRows(max, max - 1); max--; @@ -77,4 +86,14 @@ public class TableRowsDnDSupport { } }).install(); } + + static class TableRowDragInfo { + public final JTable table; + public final int row; + + TableRowDragInfo(JTable table, int row) { + this.table = table; + this.row = row; + } + } }