gpt4 book ai didi

java - 如何通过拖放将 TreePanel 的根节点添加到另一个 TreePanel 中?

转载 作者:行者123 更新时间:2023-11-30 11:48:19 25 4
gpt4 key购买 nike

我想使用拖放操作将一棵树的根节点添加到另一棵树中。我用于此任务的示例位于以下 URL 中:

http://gwt-ext.com/demo/#twoTrees

请尽快帮助我。

最佳答案

在同一个链接中。给出了代码。

public class TwoTreesSample implements EntryPoint {  

public void onModuleLoad() {
Panel panel = new Panel();
panel.setBorder(false);
panel.setPaddings(15);

//create form for nody drop style
FormPanel formPanel = new FormPanel();
formPanel.setBorder(false);
formPanel.setHideLabels(true);

FieldSet fieldSet = new FieldSet("Drop style");
fieldSet.setWidth(420);
formPanel.add(fieldSet);

final Radio moveRadio = new Radio();
moveRadio.setName("dropstyle");
moveRadio.setBoxLabel("Move");
moveRadio.setChecked(true);
fieldSet.add(moveRadio);

final Radio copyRadio = new Radio();
copyRadio.setName("dropstyle");
copyRadio.setBoxLabel("Copy");
fieldSet.add(copyRadio);

//create source countries tree
final TreePanel treePanel = new TreePanel();
treePanel.setTitle("Countries");
treePanel.setAnimate(true);
treePanel.setEnableDD(true);
treePanel.setContainerScroll(true);
treePanel.setRootVisible(true);
treePanel.setWidth(200);
treePanel.setHeight(400);
treePanel.setSelectionModel(new MultiSelectionModel());

final XMLTreeLoader loader = new XMLTreeLoader();
loader.setDataUrl("data/countries-grouped.xml");
loader.setMethod(Connection.GET);
loader.setRootTag("countries");
loader.setFolderTitleMapping("@title");
loader.setFolderTag("continent");
loader.setLeafTitleMapping("@title");
loader.setLeafTag("country");
loader.setQtipMapping("@qtip");
loader.setIconMapping("@icon");

AsyncTreeNode root = new AsyncTreeNode("Countries", loader);
treePanel.setRootNode(root);
root.expand();
treePanel.expandAll();

//create target vacation tree
final TreePanel tripTreePanel = new TreePanel();
tripTreePanel.setTitle("Trip Planner");
tripTreePanel.setAnimate(true);
tripTreePanel.setEnableDD(true);
tripTreePanel.setContainerScroll(true);
tripTreePanel.setRootVisible(true);
tripTreePanel.setWidth(200);
tripTreePanel.setHeight(400);

final XMLTreeLoader tripLoader = new XMLTreeLoader();
tripLoader.setDataUrl("data/trip.xml");
tripLoader.setMethod(Connection.GET);
tripLoader.setRootTag("vacations");
tripLoader.setFolderIdMapping("@title");
tripLoader.setFolderTag("trip");
tripLoader.setQtipMapping("@qtip");
tripLoader.setIconMapping("@icon");
tripLoader.setAttributeMappings(new String[]{"@trip"});

final AsyncTreeNode tripRoot = new AsyncTreeNode("Places to Visit", tripLoader);

tripTreePanel.setRootNode(tripRoot);

//add trip tree listener that handles move / copy logic
tripTreePanel.addListener(new TreePanelListenerAdapter() {
public void onRender(Component component) {
tripRoot.expand();
tripTreePanel.expandAll();
}

public boolean doBeforeNodeDrop(TreePanel treePanel, TreeNode target, DragData dragData,
String point, DragDrop source, TreeNode dropNode,
DropNodeCallback dropDropNodeCallback) {
if ("true".equals(target.getAttribute("trip"))) {
if (copyRadio.getValue()) {
TreeNode copyNode = dropNode.cloneNode();
Node[] children = copyNode.getChildNodes();
for (int i = 0; i < children.length; i++) {
Node child = children[i];
copyNode.removeChild(child);
}
dropDropNodeCallback.setDropNode(copyNode);
}
}
return true;
}
});

Panel horizontalPanel = new Panel();
horizontalPanel.setLayout(new HorizontalLayout(20));
horizontalPanel.add(treePanel);
horizontalPanel.add(tripTreePanel);

Panel verticalPanel = new Panel();
verticalPanel.setLayout(new VerticalLayout(15));

verticalPanel.add(formPanel);
verticalPanel.add(horizontalPanel);

panel.add(verticalPanel);

RootPanel.get().add(panel);
}
}

关于java - 如何通过拖放将 TreePanel 的根节点添加到另一个 TreePanel 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8882629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com