GP-4066: Drag and drop fix

This commit is contained in:
Ryan Kurtz 2023-11-22 14:29:16 -05:00
parent f31445fd7f
commit d5cc4050c7
6 changed files with 23 additions and 10 deletions

View file

@ -42,9 +42,13 @@ public final class JavaFileListHandler extends AbstractFileListFlavorHandler {
@Override
// This is for the DataFlavorHandler interface for handling OS files dropped onto a DataTree
public void handle(PluginTool tool, DataTree dataTree, GTreeNode destinationNode,
public boolean handle(PluginTool tool, DataTree dataTree, GTreeNode destinationNode,
Object transferData, int dropAction) {
List<File> fileList = CollectionUtils.asList((List<?>) transferData, File.class);
if (fileList.isEmpty()) {
return false;
}
doImport(getDomainFolder(destinationNode), fileList, tool, dataTree);
return true;
}
}

View file

@ -51,10 +51,14 @@ public final class LinuxFileUrlHandler extends AbstractFileListFlavorHandler {
@Override
// This is for the DataFlavorHandler interface for handling node drops in DataTrees
public void handle(PluginTool tool, DataTree dataTree, GTreeNode destinationNode,
public boolean handle(PluginTool tool, DataTree dataTree, GTreeNode destinationNode,
Object transferData, int dropAction) {
List<File> files = toFiles(transferData);
if (files.isEmpty()) {
return false;
}
doImport(getDomainFolder(destinationNode), files, tool, dataTree);
return true;
}
private List<File> toFiles(Object transferData) {

View file

@ -78,19 +78,19 @@ public class DataTreeDragNDropHandler implements GTreeDragNDropHandler {
DataFlavor[] transferDataFlavors = transferable.getTransferDataFlavors();
for (DataFlavor dataFlavor : transferDataFlavors) {
DataTreeFlavorHandler flavorHandler = getFlavorHandler(dataFlavor);
if (flavorHandler != null) {
handleDrop(destination, transferable, dropAction, dataFlavor, flavorHandler);
if (flavorHandler != null &&
handleDrop(destination, transferable, dropAction, dataFlavor, flavorHandler)) {
return;
}
}
}
private void handleDrop(GTreeNode destination, Transferable transferable, int dropAction,
private boolean handleDrop(GTreeNode destination, Transferable transferable, int dropAction,
DataFlavor dataFlavor, DataTreeFlavorHandler flavorHandler) {
try {
Object transferData = transferable.getTransferData(dataFlavor);
flavorHandler.handle(tool, tree, destination, transferData, dropAction);
return flavorHandler.handle(tool, tree, destination, transferData, dropAction);
}
catch (UnsupportedFlavorException e) {
throw new AssertException("Got unsupported flavor from using a supported flavor");
@ -98,6 +98,7 @@ public class DataTreeDragNDropHandler implements GTreeDragNDropHandler {
catch (IOException e) {
Msg.showError(this, null, "IO Error", "Error during drop", e);
}
return false;
}
private DataTreeFlavorHandler getFlavorHandler(DataFlavor flavor) {

View file

@ -22,6 +22,6 @@ import ghidra.framework.plugintool.PluginTool;
* Interface for classes that will handle drop actions for {@link DataTree}s.
*/
public interface DataTreeFlavorHandler {
public void handle(PluginTool tool, DataTree dataTree, GTreeNode destinationNode,
public boolean handle(PluginTool tool, DataTree dataTree, GTreeNode destinationNode,
Object transferData, int dropAction);
}

View file

@ -63,7 +63,7 @@ public final class LocalTreeNodeHandler
@Override
@SuppressWarnings("unchecked")
public void handle(PluginTool tool, DataTree tree, GTreeNode destinationNode,
public boolean handle(PluginTool tool, DataTree tree, GTreeNode destinationNode,
Object transferData, int dropAction) {
this.dataTree = tree;
@ -71,7 +71,7 @@ public final class LocalTreeNodeHandler
List<GTreeNode> list = (List<GTreeNode>) transferData;
if (list.size() == 0) {
return;
return false;
}
CopyAllTask task = new CopyAllTask(list, destinationNode, dropAction);
@ -83,6 +83,8 @@ public final class LocalTreeNodeHandler
dataTree.restoreTreeState(treeState);
});
}
return true;
}
private void add(GTreeNode destNode, GTreeNode draggedNode, int dropAction,

View file

@ -51,7 +51,7 @@ public final class LocalVersionInfoHandler
}
@Override
public void handle(PluginTool tool, DataTree dataTree, GTreeNode destinationNode,
public boolean handle(PluginTool tool, DataTree dataTree, GTreeNode destinationNode,
Object transferData, int dropAction) {
DomainFolder folder = getDomainFolder(destinationNode);
@ -65,6 +65,7 @@ public final class LocalVersionInfoHandler
if (file != null) {
new TaskLauncher(new CopyFileVersionTask(file, info.getVersionNumber(), folder),
dataTree, 500);
return true;
}
}
catch (NotConnectedException exc) {
@ -73,6 +74,7 @@ public final class LocalVersionInfoHandler
catch (IOException exc) {
ClientUtil.handleException(rep, exc, "Repository Connection", tool.getToolFrame());
}
return false;
}
private DomainFolder getDomainFolder(GTreeNode destinationNode) {