Uitableview 如何在GWT中单击鼠标右键创建下拉列表

Uitableview 如何在GWT中单击鼠标右键创建下拉列表,uitableview,gwt,contextmenu,handler,celltable,Uitableview,Gwt,Contextmenu,Handler,Celltable,我正在创建一个下拉列表,其中应该有创建,删除,提交一个表中的特定行。有人能帮我在GWT中创建一个吗 table.addCellPreviewHandler(new Handler<RequestDto>() { @Override public void onCellPreview(CellPreviewEvent<RequestDto> event) { if (event.getN

我正在创建一个下拉列表,其中应该有创建,删除,提交一个表中的特定行。有人能帮我在GWT中创建一个吗

   table.addCellPreviewHandler(new Handler<RequestDto>()
    {

        @Override
        public void onCellPreview(CellPreviewEvent<RequestDto> event)
        {
            if (event.getNativeEvent().getButton() == NativeEvent.BUTTON_RIGHT)
            {


                MenuBar options = new MenuBar();
                MenuBar gwtPop = new MenuBar();
                options.addItem("Create", gwtPop);
                options.addItem("Submit", gwtPop);
                MenuItem Import = new MenuItem(new SafeHtmlBuilder().appendEscaped("Import").toSafeHtml());
                Import.setScheduledCommand(new ScheduledCommand()
                {

                    @Override
                    public void execute()
                    {
                        Window.alert("hello");
                    }
                });
            final DialogBox menuWrapper = new DialogBox(true);
                menuWrapper.add(options);
                gwtPop.addItem(Import);

首先,不要在onCellPreview方法中构造菜单。无需在每次单击时反复构建相同的小部件

您可以这样做:

int clickedRow = -1;
...
// build your menu here
// use clickedRow where necessary, for example:

deleteMenuItem.setScheduledCommand(new ScheduledCommand() {

    @Override
    public void execute() {
        Window.alert("hello, I am about to delete row " + clickedRow);
    }
});
...
myTable.addCellPreviewHandler(new Handler<MyObject>() {

    @Override
    public void onCellPreview(CellPreviewEvent<MyObject> event) {
        if (event.getNativeEvent().getButton() == NativeEvent.BUTTON_RIGHT) {
            event.getNativeEvent().stopPropagation();
            clickedRow = event.getIndex();
            // show your menu - no need to construct it again 
    }
}