3

I'm trying to implement an drag & drop in my project. I already managed, but now i want to distinguish the drag source.

I will have two widget from were i can drag lets call widget1 and widget2:

widget1.getElement().setDraggable(Element.DRAGGABLE_TRUE);
widget2.getElement().setDraggable(Element.DRAGGABLE_TRUE);

i made the handler for each one

widget1.addDragStartHandler(new DragStartHandler() {

        @Override
        public void onDragStart(DragStartEvent event) {
            // TODO Auto-generated method stub
            event.setData("text", "i am widget1");
            });

widget2.addDragStartHandler(new DragStartHandler() {

        @Override
        public void onDragStart(DragStartEvent event) {
            // TODO Auto-generated method stub
            event.setData("text", "the text is different i am widget2");

now i had two absolute panels one only can receive from widget 1 and the other from widget 2

pNorth.addDomHandler(new DropHandler() {            
      @Override
       public void onDrop(DropEvent event) {
         if(widget1){
           // Prevent the native text drop.
            event.preventDefault();
             // Get the data out of the event.
              String text= event.getData("text");                                  
             pNorth.getElement().getStyle().setBackgroundImage("url("+text+")");
           }}
         }, DropEvent.getType());

how can i manage to do that?

thanks for the help.

2 Answers 2

1

The drop event doesn't seem to carry information about the source element.

So you have to use event.setData("source", "some info about current widget"); to distinguish which element has been dragged. The info can be arbitrary, can be widget1.getClass().getName() or anything else allowing to distinguish what kind of widget has been dragged.

Note: the "source" tag is arbitrary, of course, you can use anything that suits you.

Sign up to request clarification or add additional context in comments.

Comments

0

I have recently worked on something called GWT DND (Drag & Drop). Its quite useful in these cases. Here is the link

http://code.google.com/p/gwt-dnd/

Demo

http://allen-sauer.com/com.allen_sauer.gwt.dnd.demo.DragDropDemo/DragDropDemo.html

4 Comments

thanks but that is to drag the widget imself and change is position i want to drag the info of the widget and then use is information.
Actually, you can use the same for your purpose also. The DND API can be used to drag elements inside the absolute panel you were mentioning.
Also, you can use JSNI methods over HTML5 Drag and Drop. w3schools.com/html5/html5_draganddrop.asp code.google.com/webtoolkit/doc/latest/…
but the problem maintains is not possible to prevent other widgets like text areas or other widgets with drop handler to receive the drag. Maybe i don't explain well my problem. This suggestions you make seems to be alternatives to what i make.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.