@Override public void drop(DnDEvent aEvent) { Object attached = aEvent.getAttachedObject(); if (!(attached instanceof ChangeListDragBean)) return; final ChangeListDragBean dragBean = (ChangeListDragBean) attached; final ChangesBrowserNode changesBrowserNode = dragBean.getTargetNode(); if (changesBrowserNode != null) { changesBrowserNode.acceptDrop(myDragOwner, dragBean); } }
@Override public void acceptDrop(final ChangeListOwner dragOwner, final ChangeListDragBean dragBean) { if (!(userObject instanceof LocalChangeList)) { return; } final LocalChangeList dropList = (LocalChangeList) getUserObject(); dragOwner.moveChangesTo(dropList, dragBean.getChanges()); final List<VirtualFile> toUpdate = new ArrayList<VirtualFile>(); addIfNotNull(toUpdate, dragBean.getUnversionedFiles()); addIfNotNull(toUpdate, dragBean.getIgnoredFiles()); if (!toUpdate.isEmpty()) { dragOwner.addUnversionedFiles(dropList, toUpdate); } }
@Override public boolean canAcceptDrop(final ChangeListDragBean dragBean) { final Change[] changes = dragBean.getChanges(); for (Change change : getUserObject().getChanges()) { for (Change incomingChange : changes) { if (change == incomingChange) return false; } } return true; }
@Override public boolean update(DnDEvent aEvent) { aEvent.hideHighlighter(); aEvent.setDropPossible(false, ""); Object attached = aEvent.getAttachedObject(); if (!(attached instanceof ChangeListDragBean)) return false; final ChangeListDragBean dragBean = (ChangeListDragBean) attached; if (dragBean.getSourceComponent() != ChangesListView.this) return false; dragBean.setTargetNode(null); RelativePoint dropPoint = aEvent.getRelativePoint(); Point onTree = dropPoint.getPoint(ChangesListView.this); final TreePath dropPath = getPathForLocation(onTree.x, onTree.y); if (dropPath == null) return false; ChangesBrowserNode dropNode = (ChangesBrowserNode) dropPath.getLastPathComponent(); while (!((ChangesBrowserNode) dropNode.getParent()).isRoot()) { dropNode = (ChangesBrowserNode) dropNode.getParent(); } if (!dropNode.canAcceptDrop(dragBean)) { return false; } final Rectangle tableCellRect = getPathBounds(new TreePath(dropNode.getPath())); if (fitsInBounds(tableCellRect)) { aEvent.setHighlighting( new RelativeRectangle(ChangesListView.this, tableCellRect), DnDEvent.DropTargetHighlightingType.RECTANGLE); } aEvent.setDropPossible(true); dragBean.setTargetNode(dropNode); return false; }