gpt4 book ai didi

java - 如何使用 "external"包中的 GWT UI Binders

转载 作者:行者123 更新时间:2023-12-01 15:24:40 25 4
gpt4 key购买 nike

我正在使用 GWT 开发一个 Web 应用程序,并且正在修改它以使用 UiBinders 构建。

我有一个工作版本的多个绑定(bind)器包含在与引用它们的类相同的包中,但其中很多在整个应用程序中具有通用实用程序,我希望将它们分解到 uibinders 包中。

这里是一些工作代码片段

TableListPanel.ui.xml 文件:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel>
<div id="tableListPanel">
<g:HTMLPanel styleName="buttonPanel" ui:field="buttonPanel"></g:HTMLPanel>
<g:HTMLPanel styleName="tableList" ui:field="tableList"></g:HTMLPanel>
<table align="center"><tr>
<td align="center"><g:HTMLPanel styleName="tableMenu" ui:field="tableMenu"></g:HTMLPanel></td>
</tr></table>
</div>
</g:HTMLPanel>

</ui:UiBinder>

TableListPanelBinder java 文件:

public class TableListPanelBinder extends Composite implements HasText {

private static AuditPanelUiBinder uiBinder = GWT
.create(AuditPanelUiBinder.class);

interface AuditPanelUiBinder extends UiBinder<Widget, TableListPanelBinder> {
}

public TableListPanelBinder() {
initWidget(uiBinder.createAndBindUi(this));
}

@UiField
protected HTMLPanel buttonPanel;

@UiField
protected HTMLPanel tableList;

@UiField
protected HTMLPanel tableMenu;

public void bindUiElement(HTMLPanel container, Widget widjetObj) {
container.add(widjetObj);
}

最后在代码中调用将小部件绑定(bind)到上面的 ui:fields :

public AuditReportProfilesPanel() {
super();
this.setWidth("100%");
this.setSpacing(4);


this.parmSetsTable = createParmSetsTable();
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
pager.setDisplay(parmSetsTable);

TableListPanelBinder reportListBinder = new TableListPanelBinder();
this.add(reportListBinder);

// -START- Bind UI Elements -START-
reportListBinder.bindUiElement(reportListBinder.tableList, parmSetsTable);
reportListBinder.bindUiElement(reportListBinder.tableMenu, pager);
reportListBinder.bindUiElement(reportListBinder.buttonPanel, createActionBar());
//-END- Bind UI Elements -END-
}

我知道这可能不是最简洁的设置方式,但我正在边学习边学习。

我知道将 Binder 移动到不同的包意味着私有(private)/ protected 访问修饰符将阻止我访问代码,但将它们更改为公共(public)对我也没有任何好处。

任何修复建议将不胜感激。这个应用程序有几个不同的类包(本质上相当于应用程序中的不同页面),并且它们都使用类似的表设置,所以我想避免每个包中都有重复的代码;我只是不能 100% 确定实现这一目标的最佳方法。

在 Binders 包中创建抽象类,然后在各个应用程序包中扩展它们是否可以解决问题,还是我缺少什么?

最佳答案

  1. 写下您的通用名称 UiBinder和相应的类( WidgetView )位于指定的通用包中。我们称之为my.general.uibinders包。
  2. 在您的 UiBinder对应于具体页面(或 Place ),将此包导入为 xmlns ui:UiBinder 的属性标签位于 UiBinder 的头部。这样:

    <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" 
    xmlns:g="urn:import:com.google.gwt.user.client.ui"
    xmlns:c="urn:import:my.general.uibinders"> <!-- this is the addition -->
  3. 从现在开始,在这个UiBinder , c是对驻留在 my.general.uibinders 中的类的引用。假设您有一个名为 MyGeneralView 的类,按如下方式使用:<c:MyGeneralView .../>贯穿您的UiBinder .

关于java - 如何使用 "external"包中的 GWT UI Binders,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10341511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com