创建由gin管理的类的新实例



Im使用GWTP,处理他们的选项卡面板示例。我的问题是,我需要演示使用一个搜索词,并在带有搜索结果的选项卡面板中添加一个新选项卡。所以如果我搜索5次,我就有5个标签。很简单,所以我想。

杜松子酒在GWTP中被广泛使用。所以我添加一个新标签的方法,应该像一样简单

tabPanel.addTab(new SearchDataGridView(), NameTokens.searchPage + 1);

由于SearchDataGridView类的构造函数而变得令人困惑

@Inject
    SearchDataGridView(Binder uiBinder) {
        employeeDataProvider = new ListDataProvider<Employee>();
        initSearchGrid();
        initWidget(uiBinder.createAndBindUi(this));
    }

是的,我知道我还没有通过搜索项,我还在努力打开标签。

我的杜松子酒配置是这个

bindPresenter(
                SearchDataGridPresenter.class,
                SearchDataGridPresenter.MyView.class,
                SearchDataGridView.class,
                SearchDataGridPresenter.MyProxy.class);

gwtp杜松子酒配置

@Override
    protected void configure() {
        // RestDispatchAsyncModule.Builder dispatchBuilder = new RestDispatchAsyncModule.Builder();
        // install(dispatchBuilder.build());
        // install(new RestDispatchAsyncModule.Builder().build());
        install(new DefaultModule(DefaultPlaceManager.class));
        install(new ApplicationModule());
        bind(CurrentUser.class).in(Singleton.class);
        bind(IsAdminGatekeeper.class).in(Singleton.class);
        // DefaultPlaceManager Constants
        bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.homeNewsPage);
        bindConstant().annotatedWith(ErrorPlace.class).to(NameTokens.homeNewsPage);
        bindConstant().annotatedWith(UnauthorizedPlace.class).to(NameTokens.homeNewsPage);
        bindConstant().annotatedWith(Names.named("rest")).to("http://localhost/services");
        // Google Analytics
        // bindConstant().annotatedWith(GaAccount.class).to("UA-8319339-6");
        // Load and inject CSS resources
        bind(ResourceLoader.class).asEagerSingleton();
    }

我该如何做到这一点?

感谢

通过下面的评论,sorta让它发挥了作用。问题是我无法显示选项卡的内容。我在SearchContainer类的setInSlot方法中添加了调试代码,并意识到每当我单击搜索选项卡时,它都会激发这个setInSlot的方法,但它是在我的默认页面呈现器列为内容时激发的。

@Override
    public void setInSlot(Object slot, IsWidget content) {
        Window.alert("fired setInSlot: " + slot.toString());
        Window.alert("fired setInSlot: " + content.toString());
        if (slot == ApplicationPresenter.TYPE_SetTabContent) {
            tabPanel.setPanelContent(content);
        } else {
            super.setInSlot(slot, content);
        }
    }

这就是我获取信息的方法。奇怪的是,选项卡显示正确,视图中内置的jsonRPC调用执行正确,只是没有显示。

我的主容器演示者的视图和代理由这个标识

public class ApplicationPresenter
        extends
        TabContainerPresenter<ApplicationPresenter.MyView, ApplicationPresenter.MyProxy> implements
        CurrentUserChangedHandler, AsyncCallStartHandler, AsyncCallFailHandler, AsyncCallSucceedHandler,
        ApplicationUiHandler {
    /**
     * {@link ApplicationPresenter}'s proxy.
     */
    @ProxyStandard
    public interface MyProxy extends Proxy<ApplicationPresenter> {
    }
    /**
     * {@link ApplicationPresenter}'s view.
     */
    public interface MyView extends TabView, HasUiHandlers<ApplicationUiHandler> {
        void refreshTabs();
        void setTopMessage(String string);
    }

我的问题可能是我的内容类型吗?以下是我为所有类型的定义的内容

/**
     * This will be the event sent to our "unknown" child presenters, in order for them to register their tabs.
     */
    @RequestTabs
    public static final Type<RequestTabsHandler> TYPE_RequestTabs = new Type<RequestTabsHandler>();
    /**
     * Fired by child proxie's when their tab content is changed.
     */
    @ChangeTab
    public static final Type<ChangeTabHandler> TYPE_ChangeTab = new Type<ChangeTabHandler>();
    /**
     * Use this in leaf presenters, inside their {@link #revealInParent} method.
     */
    @ContentSlot
    public static final Type<RevealContentHandler<?>> TYPE_SetTabContent = new Type<RevealContentHandler<?>>();
执行此操作的正确方法是使用PresenterWidgetProvider

在您的ClientModule中,您定义了:

bindPresenterWidget(SearchDataGridPresenter.class, SearchDataGridPresenter.MyView.class, SearchDataGridView.class);

在添加SearchDataGridViewPresenter中,注入Provider:

@Inject
public SeachContainerPresenter(final Provider<SearchDataGridPresenter> seachDataGridProvider) {
}

对于每次搜索,您都会在SearchContainerPresenter中调用addToSlot(TYPE_SetSearchDataGridContent,seachDataGridProvider.get())

SearchContainerView中,覆盖addToSlot()方法:

@Override
public void addToSlot(Object slot,Widget content) {
    if (slot == SeachContainerPresenter.TYPE_SetSearchDataGridContent) {
        tabPanel.addTab(content, NameTokens.searchPage + 1);
    }
    else {
        super.addToSlot(slot,content);
    } 
}

查看如何将所有内容绑定在一起。我认为您必须将演示者的AsyncProvider添加到yuor Gijector中。

AsyncProvider<SearchDataGridPresenter> getSearchDataGridPresenter();

您可以在GIN Injector中放入一个SearchDataGridView getSearchDataGridView()方法并调用它以获得SearchDataGridView实例。

相关内容

  • 没有找到相关文章

最新更新