Search code examples
gwtdrag-and-dropcomposite

How to make dragable widget in GWT dnd


A want to make my Widget dragable.. A use GWT and d&d. It's my code, but it isn't work..

@SuppressWarnings("deprecation")
public class StickWidget extends Composite implements SourcesMouseEvents  {

private static StickWidgetUiBinder uiBinder = GWT
        .create(StickWidgetUiBinder.class);
@UiField Label title;
@UiField HTML content;

interface StickWidgetUiBinder extends UiBinder<Widget, StickWidget> {
}

public StickWidget(String title, String content, String width, String height) {

    super();
    initWidget(uiBinder.createAndBindUi(this));

    this.content.setText(content);
    this.title.setText(title);
    this.setWidth(width);
    this.setHeight(height);
}

public StickWidget(String title, String content) {

    initWidget(uiBinder.createAndBindUi(this));

    this.content.setText(content);
    this.title.setText(title);

}

@Override
public void addMouseListener(MouseListener listener) {
    // TODO Auto-generated method stub

}

@Override
public void removeMouseListener(MouseListener listener) {
    // TODO Auto-generated method stub

}


    }

and fragment of my EntryPoint:

StickWidget a = new StickWidget("gg", "gg", "20px", "200px");
DropTargetStick dropT = new DropTargetStick(new Label("fdgf"));
PickupDragController dragController = new PickupDragController (RootPanel.get(), false);
dragController.registerDropController(dropT);
dragController.makeDraggable(a);

I think I done all steps which allow me to drag & drop My widget.. But it doesn't work..


Solution

  • I solve this problem. You must implement HasAllMouseHandlers and HasClickHandlers. And in implementation give somelike this -

    @Override
        public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
            // TODO Auto-generated method stub
            return addDomHandler(handler, MouseUpEvent.getType());
        }