List of usage examples for org.apache.wicket.extensions.markup.html.repeater.tree DefaultNestedTree DefaultNestedTree
public DefaultNestedTree(String id, ITreeProvider<T> provider)
From source file:wicketdnd.examples.TreeExample.java
License:Apache License
public TreeExample(String id) { super(id);/*from w w w . j ava 2 s . c om*/ final FooTreeProvider provider = new FooTreeProvider(); final NestedTree<Foo> tree = new DefaultNestedTree<Foo>("tree", provider) { @Override protected Component newContentComponent(String arg0, IModel<Foo> arg1) { Component component = super.newContentComponent(arg0, arg1); component.setOutputMarkupId(true); return component; } }; tree.add(new DragSource() { @Override public Set<Operation> getOperations() { return dragOperations(); } @Override public String[] getTypes() { return types(); } @Override public void onAfterDrop(AjaxRequestTarget target, Transfer transfer) { if (transfer.getOperation() == Operation.MOVE) { Foo foo = transfer.getData(); provider.remove(foo); foo.remove(); target.add(tree); } } }.drag("span.tree-content")); tree.add(new DropTarget() { @Override public Set<Operation> getOperations() { return dropOperations(); } @Override public String[] getTypes() { return types(); } @Override public void onDrag(AjaxRequestTarget target, Location location) { if (location.getComponent() != tree) { Foo foo = location.getModelObject(); if (tree.getState(foo) == State.COLLAPSED) { tree.expand(foo); } } } @Override public void onDrop(AjaxRequestTarget target, Transfer transfer, Location location) throws Reject { if (location.getComponent() == tree) { provider.add(operate(transfer)); } else { Foo foo = location.getModelObject(); if (foo.isAncestor(transfer.getData())) { transfer.reject(); } switch (location.getAnchor()) { case CENTER: if (foo == transfer.getData()) { transfer.reject(); } provider.add(operate(transfer), foo); tree.expand(foo); break; case TOP: provider.addBefore(operate(transfer), foo); break; case BOTTOM: provider.addAfter(operate(transfer), foo); break; default: transfer.reject(); } } target.add(tree); } }.dropCenter("span.tree-content, div.treeContainer").dropTopAndBottom("div.tree-branch")); tree.setOutputMarkupId(true); content.add(tree); }