如何在GWT dnd中制作可拖动的小部件

时间:2013-07-08 09:55:27

标签: gwt drag-and-drop composite

想要让我的Widget可拖动.. 使用GWT和d& d。这是我的代码,但它不起作用..

@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

}


    }

和我的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);

我想我已经完成了所有允许我拖延的步骤。删除我的小部件..但它不起作用..

1 个答案:

答案 0 :(得分:1)

我解决了这个问题。您必须实现HasAllMouseHandlers和HasClickHandlers。在实现中给出一些类似的东西 -

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