GWTP + Gxt:在两个单独的页面插槽中使用相同的演示者窗口小部件时出现异常

时间:2014-02-19 09:58:09

标签: gwt gxt gwt-platform

我有一个页面边框布局和为边框布局的每个区域定义的插槽(例如,EAST,WEST,NORTH,CENTER ......)。

我希望通过在页面上面的两个插槽中显示它来重复使用演示者窗口小部件。 我成功地在其中一个插槽上显示了演示者窗口小部件,但每当我尝试在两个单独的插槽中添加演示者窗口小部件时,我都会收到此错误:

Exception caught: notifyReveal() called on a visible Presenter!

任何人都可以告诉我这是怎么做的。

以下是我的代码。

HomeView.java

@UiField
ContentPanel centerPanel;

@UiField
ContentPanel westPanel;

@Override
public void setInSlot(Object slot, Widget content) {

    if (slot == HomePresenter.SLOT_EAST) {
        if (content != null) {
            eastPanel.add(content);
        }
    } else if (slot == HomePresenter.SLOT_WEST) {
        if (content != null) {
            westPanel.add(content);
        }
    } else if (slot == HomePresenter.SLOT_CENTER) {
        if (content != null) {
            centerPanel.add(content);
        }
    } else {
        super.setInSlot(slot, content);
    }
}

@Override
public void addToSlot(Object slot, Widget content) {
    if (slot == HomePresenter.SLOT_EAST) {
        if (content != null) {
            eastPanel.add(content);
        }
    } else if (slot == HomePresenter.SLOT_WEST) {
        if (content != null) {
            westPanel.add(content);
        }
    } else if (slot == HomePresenter.SLOT_CENTER) {
        if (content != null) {
            centerPanel.add(content);
        }
    } else {
        super.addToSlot(slot, content);
    }
}

HomePresenter.java:

public static final Object SLOT_WEST = new Object();

public static final Object SLOT_CENTER = new Object();

@Override
protected void revealInParent() {
    RevealRootContentEvent.fire(this, this); //Getting error over here
}

@Override
protected void onReset() {
    super.onReset();

    setInSlot(SLOT_WEST, null);
    setInSlot(SLOT_CENTER, null);

    indirectProvider.get(new AsyncCallback<LeftPanelPresenter>() {

        @Override
        public void onSuccess(LeftPanelPresenter result) {
            addToSlot(SLOT_WEST, result);
            addToSlot(SLOT_CENTER, result);
        }

        @Override
        public void onFailure(Throwable caught) {
            // TODO Auto-generated method stub
            System.out.println("Not added to the slot");
        }
    });
}

1 个答案:

答案 0 :(得分:0)

提供者的目的是为每个要放置它的地方创建每个PresenterWidget的新实例。

我认为使用相同的addToSlot()对象调用result两次会导致错误,因为该实例已经被揭示。

您可以使用循环为每个插槽创建一个新实例:

// create an array of the slots
List<Object> slots = new ArrayList<Object>();
slots.add(SLOT_WEST);
slots.add(SLOT_CENTER);

// call provider.get() on each slot in turn
for(Object slot : slots)
{
    indirectProvider.get(new AsyncCallback<LeftPanelPresenter>()
    {
        @Override
        public void onSuccess(LeftPanelPresenter result)
        {
            addToSlot(slot, result);
        }

        @Override
        public void onFailure(Throwable caught)
        {
            // TODO Auto-generated method stub
            System.out.println("Not added to the slot");
        }
    });
}