私は最終的に、2つのツリー間で物をドラッグアンドドロップするときに(特定の使用例のために)動作するものをハッキングしました。特定のキーインスタンスは重要ではなく、キー自身のパス - 主な部分は、addSubTreeの代わりにinsertを使用してツリーコンポーネントを個別に追加するためにappendModelを変更しているだけなので、実際にインスタンスを作成できるデータ型がありました。
誰かがもっと良い方法を見つけることができれば、私はそれを見たいと思います。
public class MyTreeDropTarget extends TreeDropTarget<FileSystemKey> {
public MyTreeDropTarget(Tree<FileSystemKey, ?> tree) {
super(tree);
}
private void InsertClone(FileSystemKey parent,
TreeStore.TreeNode<FileSystemKey> node, int index) {
FileSystemKey clone;
if (parent == null) { //root of the tree
clone = new FileSystemKey(node.getData());
clone.SetKey("/", null, "/" + clone.key2);
getWidget().getStore().insert(index, clone);
} else { //a child element
clone = new FileSystemKey(node.getData());
clone.SetKey(parent.key1 + parent.key2 + "/", null, parent.key1
+ parent.key2);
getWidget().getStore().insert(parent, index, clone);
}
//if this node had children,
//we then insert the children as children of this node
if (node.getChildren().size() > 0) {
//TODO: rewrite to preserve order
appendModel(clone, node.getChildren(), 0);
}
}
@Override
protected void appendModel(FileSystemKey p, List<?> items, int index) {
if (items.size() == 0)
return;
if (items.get(0) instanceof TreeStore.TreeNode) {
// @SuppressWarnings("unchecked")
List<TreeStore.TreeNode<FileSystemKey>> nodes = (List<TreeStore.TreeNode<FileSystemKey>>) items;
// TODO: replace clone with gets
for (TreeStore.TreeNode<FileSystemKey> key : nodes) {
InsertClone(p, key, index);
}
} else {// no changes here - maybe change
// this if you have non-homogenous key types
@SuppressWarnings("unchecked")
List<FileSystemKey> models = (List<FileSystemKey>) items;
if (p == null) {
getWidget().getStore().insert(index, models);
} else {
getWidget().getStore().insert(p, index, models);
}
}
}
}