You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by ttboy_01 <be...@googlemail.com> on 2012/05/09 17:59:59 UTC
SwingTree to WicketTree + Drag Drop + Different Objects
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: SwingTree to WicketTree + Drag Drop + Different Objects
Posted by ttboy_01 <be...@googlemail.com>.
Hi Sven,
I already have seen the examples of wicket tree but I don't know how to
solve the problem with the different classes / types within the tree. Could
you give me a hint for this problem?
The structure is simple:
// these are my roots
class X {
private Set<Y> y;
}
// these are my nodes
class Y {
private String foo;
}
Erik
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/SwingTree-to-WicketTree-Drag-Drop-Different-Objects-tp4620927p4622725.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: SwingTree to WicketTree + Drag Drop + Different Objects
Posted by Sven Meier <sv...@meiers.net>.
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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org