Are you using Fred Sauer's gwt-dnd? If you are using it, this could
help you.

Fist at all follow Fred's example: 
http://code.google.com/p/gwt-dnd/wiki/GettingStarted

Now you must make a change to your widgets, first your widget class
must implement HasDragHandle. And second i guess that you want to have
some information, like an id, attached to your widget.

Take a look at this:

public class DraggableCategory extends Composite implements
HasDragHandle {
        private String categoryId;
        private Image image;

        public DraggableCategory(Category category){
                super();
                this.categoryId = category.getId();
                image = new Image(category.getThumbnail());
                image.setWidth("60px");
                image.setHeight("60px");

                initWidget(image);
        }

        public String getCategoryId() {
                return categoryId;
        }

        public Image getImage() {
                return image;
        }

        /* this is the important part */
        public Widget getDragHandle() {
                return this.image;
        }
}

Now your widget is draggable and in your DropController you can access
to your id, for example, create your own DropController and do this:

public void onDrop(DragContext context) {
                for (Widget widget : context.selectedWidgets) {
                        if (widget instanceof DraggableCategory) {
                                DraggableCategory draggableCategory =
(DraggableCategory) widget;
 
Window.alert(draggableCategory.getId());
                        }
                 }
}

Of course, dont forget to register your own DropController to the
DragController and make your widget draggable:

DraggableCategory draggableCategory = new DraggableCategory(category);

PickupDragController myDragController = new
PickupDragController(RootPanel.get(), false);
MyDropController myDropController = new
MyDropController(RootPanel.get());

/* register your dropController */
myDragController.registerDropController(myDropController);

/* make draggable your widget */
myDragController.makeDraggable(draggableCategory);

I think i didn't forget anything, I hope this could help you.



On 23 jul, 09:13, rlebosse <rlebo...@gmail.com> wrote:
> Hi everybody,
>
> I've lots of widgets (extends Composite) that I would like to be able
> to drag in the displayed web page?
> How can I do that?
>
> Thanks for your help,
> Romain

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to