Hi Erik,
since you're using wicket-dnd already, I'd strongly recommend to use
wicket-tree (http://code.google.com/p/wicket-tree/) instead of LinkTree.
Updating nodes works hassle-free with this new implementation. See
wicket-tree's examples.
Or do absolutely have to use a swing tree model?
Sven
On 05/09/2012 05:59 PM, ttboy_01 wrote:
Hi Community,
I've got a problem here with a (javax.swing.) tree in Wicket 1.5.4.
Everything is working fine, besides the update after drag&drop. Everything
according to the database is handled fine and if I recall the page the tree
(and its model) is fine.
Some theoretical:
I'd like to display the following tree
Object
- AnotherObject
- AnotherObject
Object
- AnotherObject
So I've got different classes within the tree based on the deep. My first
question is how to handle this with wicket-tree? Is this possible?
The other question is about the update of the tree. Here's some code:
public MyPage() {
releaseTree = new LinkTree("releaseTree", getReleaseTreeModel()) {
@Override
protected Component newNodeComponent(String id, IModel
model) {
WebMarkupContainer component =
(WebMarkupContainer)
super.newNodeComponent(id, model);
component.setOutputMarkupId(true);
return component;
}
...
}
releaseTree.setOutputMarkupId(true);
releaseTree.add(getDragBehavior());
releaseTree.add(getDropBehavior());
add(releaseTree);
}
private Behavior getDragBehavior() {
return new DragSource(Operation.MOVE) {
public void onAfterDrop(AjaxRequestTarget target,
Transfer transfer) {
target.add(releaseTree);
};
@Override
public void onBeforeDrop(Component drag, Transfer
transfer) throws Reject
{
Component parent = drag.getParent();
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)
parent.getDefaultModelObject();
Object object = node.getUserObject();
if (object instanceof Theme) {
transfer.setData(object);
} else {
transfer.reject();
}
}
}.drag("a");
}
private Behavior getDropBehavior() {
return new DropTarget(Operation.MOVE) {
@Override
public void onDrop(AjaxRequestTarget target, Transfer
transfer, Location
location) throws Reject {
Object object = transfer.getData();
if (object instanceof Theme) {
// Delete old relation
Release release =
Release.findReleaseByThemeId(((Theme)
object).getId());
release.getThemes().remove(object);
release.merge();
// create new relation
Component contentComponent =
location.getComponent();
Component parent =
contentComponent.getParent();
Object newRelease =
((DefaultMutableTreeNode)
parent.getDefaultModelObject()).getUserObject();
if (newRelease instanceof Release) {
((Release)
newRelease).getThemes().add((Theme) object);
((Release) newRelease).merge();
} else {
transfer.reject();
}
} else {
transfer.reject();
}
releaseTree.updateTree();
target.add(releaseTree);
}
}.dropCenter("a");
}
As i said - everything is fine except updating the tree after drop.
I hope you understand the problem.
Regards,
Erik
--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/SwingTree-to-WicketTree-Drag-Drop-Different-Objects-tp4620927.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org