My seqnums are persistently stored,
when items are retrieved so the seqnum.
I used models to pass and get item data:

@Override
public void populateItem(final Item<ItemData> item) {
    final ItemData itemData = item.getModelObject();
    item.add(new MyLink("title", new DraggableModel<ItemData>(itemData) {
        @Override
        public String getObject() {
            return itemData.getTitle();
        }
        @Override
        public DraggableModel<?> onDrop(AjaxRequestTarget target,
DroppableModel<?> droppableModel) {
            // check where the item was dropped (my items can be dropped in
more containers)
            if (droppableModel.getType() == Droppable.RESEQUENCER) {
                // clip D&D-ed into clip seqnum updater
                Integer newSeqnum = (Integer) (droppableModel.getMobject());
                if (newSeqnum.equals(itemData.getSeqnum())) {
                    return null;
                }
                // update your data in persistent store
                return null;
            } // else (if any)
        }
    }
    add(new DraggableBehavior() {
        {
            setName(Draggable.PRODUCT.name());
            setRevert(DraggableBehavior.DragRevertMode.ALWAYS);
            setRevertDuration(0);
            setHelper(DragHelperMode.CLONE);
            setOpacity(Opacity.LOW);
        }
    });
    add(new DroppableBehavior() {
        {
            setHoverClass("resequencerHover");
            setTolerance(DropTolerance.POINTER);
            setDraggablesAcceptedByDroppable(new
DraggablesAcceptedByDroppable(Draggable.PRODUCT.name()));
        }
        @Override
        protected void onDrop(AjaxRequestTarget target, final Component
component, final SpecialKeys keys) {
            DraggableModel<ItemData> model = (DraggableModel<ItemData>)
component.getDefaultModel();
            // the container invokes the onDrop() callback of item, passing
container's data, so that
            // the item can figure out where was dropped
            model.onDrop(target, new
DroppableModel<Integer>(Droppable.RESEQUENCER, itemData.getSeqnum()));
        }
    });
    add(new AttributeAppender("class", true, new
AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            return "resequencer";
        }
    }, " "));
}
public abstract class DraggableModel<T> extends
AbstractReadOnlyModel<String> {
    protected Draggable type;
    protected T mobject;
    public DraggableModel(Draggable type) {
        this.type = type;
    }
    public DraggableModel(T object) {
        this.mobject = object;
    }
    public DraggableModel(Draggable type, T object) {
        this.type = type;
        this.mobject = object;
    }
    public final T getMobject() {
        return mobject;
    }
    public Draggable getType() {
        return type;
    }
    @Override
    public String getObject() {
        return null;
    }
    /**
     * Callback, invoked by 'droppable' when it accepts this draggable.
     * Implementers should call droppable's onDrop() if droppable is not
null.
     * @param target
     * @param droppableModel
     * @return
     */
    public abstract DraggableModel<?> onDrop(AjaxRequestTarget target,
            DroppableModel<?> droppableModel);
}
public class DroppableModel<T> extends AbstractReadOnlyModel<String> {
    protected Droppable type;
    protected T mobject;
    public DroppableModel(Droppable type) {
        this.type = type;
    }
    public DroppableModel(T object) {
        this.mobject = object;
    }
    public DroppableModel(Droppable type, T object) {
        this.type = type;
        this.mobject = object;
    }
    public DroppableModel() {
        throw new UnsupportedOperationException("Type required");
    }
    public final T getMobject() {
        return mobject;
    }
    public Droppable getType() {
        return type;
    }
    @Override
    public String getObject() {
        return null;
    }
    /**
     * Callback, invoked by 'draggable' after this droppable invoked
draggable's onDrop().
     * Implementers should call draggable's onDrop() if draggable is not
null.
     * @param target
     * @param draggableModel
     * @return
     */
    public DroppableModel<?> onDrop(AjaxRequestTarget target,
DraggableModel<?> draggableModel) {
        return null;
    }
}
public enum Droppable {
    TRASH, RESEQUENCER /* etc */;
}
public enum Draggable {
    PRODUCT, USER /* etc */;
}

Hoping that copy&paste&adjustments are OK,

Istvan

On Mon, Jun 7, 2010 at 3:02 PM, DerBernd <beha...@web.de> wrote:

>
> Ok,
> I think I understood, but how do you get the seqnum?
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/drag-and-drop-tp1881857p2245847.html
> Sent from the Wicket - User 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
>
>

Reply via email to