0

Tree rows and columns drag and drop

asked 2013-10-11 11:46:49 +0800

cocoes gravatar image cocoes flag of Spain
94 6

Hi,

I'm trying to allow drag and drop on tree rows and columns, but I failed on the first one and have no idea on the second one.

On drag and drop dynamically generated rows , and updated in realtime by a different thread, I've added the following code:

DefaultTreeNode treeNode = (DefaultTreeNode) data;
treeItem.setValue(treeNode);
Treerow tr;
if (treeItem.getTreerow() == null) {
    tr = new Treerow();
    tr.setParent(treeItem);
} else {
    tr = treeItem.getTreerow();
    tr.getChildren().clear();
}

MyRowInfo row = (MyRowInfo)treeNode.getData();
if (!row.isLeaf() ) {
tr.setDraggable("true");
tr.setDroppable("true");
tr.addEventListener(Events.ON_DROP, new EventListener<Event>() {
         @SuppressWarnings("unchecked")
         @Override
         public void onEvent(Event event) throws Exception {
              Treeitem draggedItem = (Treeitem) ((DropEvent) event).getDragged().getParent();
              Treeitem targetItem = (Treeitem) ((DropEvent) event).getTarget().getParent();
              draggedItem.getParent().removeChild(draggedItem);
              targetItem.getParent().insertBefore(draggedItem, targetItem);
          }
     });
... some more stuff

But it sometimes duplicate some rows, and sometimes it gets blocked.

So my question is if my code is the best solution to move tree rows considering that the tree rows can have child nodes.

And regarding the columns drag and drop, I've added the following code to each treecol on zul file:

draggable="true" droppable="true" onDrop="move(event.dragged)"

, but have no idea about moving columns code. Any idea?

Many thanx

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-10-14 11:46:47 +0800

cor3000 gravatar image cor3000
6280 2 7

Hi,

hi I created a small example that shows how row, and column drag and drop can be implemented.

I am not sure about the separate thread you are talking about. So if this is not sufficient let me know.

Robert

link publish delete flag offensive edit

Comments

Hi Robert, many thanks. I've tested your sample for rows Drag&Drop, modified for MVC, and it works, but I have the problem that tree rows are constantly updated in the background, and if I'm moving a row that has been updated an exception is raised:

cocoes ( 2013-10-14 15:41:24 +0800 )edit

16:26:00,236 SEVERE [zkoss] >>org.zkoss.zk.ui.ComponentNotFoundException: Component not found: dGEP333 >> at org.zkoss.zk.ui.impl.DesktopImpl.getComponentByUuid(DesktopImpl.java:519) >> at org.zkoss.zk.ui.event.DropEvent.getDropEvent(DropEvent.java:42)

cocoes ( 2013-10-14 15:41:51 +0800 )edit

>> at org.zkoss.zk.ui.HtmlBasedComponent.service(HtmlBasedComponent.java:634) >> at org.zkoss.zk.ui.impl.DesktopImpl.service(DesktopImpl.java:708) >> at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1204)

cocoes ( 2013-10-14 15:42:53 +0800 )edit

It seems like when a tree row is rendered, a new uuid is generated, and the target or dragged row reference is lost.

cocoes ( 2013-10-14 15:44:27 +0800 )edit

yes it depends on what you update and how you update it ... if the whole treerow is replaced, it's uuid will be a new one... if you only update the tree cells the rows will stay the same. or better only set the values of the labels inside the tree cells, then their UUID will not change either.

cor3000 ( 2013-10-16 04:47:20 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2013-10-11 11:46:49 +0800

Seen: 43 times

Last updated: Oct 14 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More