拜托我需要你的帮忙。我使用从数据库填充的 UiBinder 创建了一个 CellBrowser。问题是我无法使用 InitWidget 方法显示它。但是,如果我将它直接附加到 RootPanel(使用指令:RootPanel.get().add(cellBrowser);),它会显示出来,但会显示在附加到复合材料的其他成分上(它会变得一团糟:/ )。我把它放在 HTMLPanel 中,但它不起作用。
如何将其附加到复合材料并使其与其他小部件一起显示?(我尝试过其他面板,但没有成功:/)。
这是我的代码:
UiBinder 文件:
<!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" xmlns:c='urn:import:com.google.gwt.user.cellview.client'>
<ui:style>
#errors {
color: red;
}
#success {
color: green;
}
.arrondie {
border: 1px solid black;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
background-color: #FFFFCC;
}
</ui:style>
<g:HorizontalPanel>
<g:HTMLPanel>
<table align="center" id="arrondie">
<tr>
<td colspan="3" align="center">
<div id="errors" align="center"></div>
<br />
<div id="success" align="center"></div>
</td>
</tr>
<tr>
<td>
<g:Label text="Unit's family:" />
</td>
<td colspan="2">
<g:TextBox width="15em" ui:field="familyName" />
</td>
</tr>
<tr>
<td>
<g:Label text="Unit:" />
</td>
<td>
<g:TextBox width="15em" ui:field="unitName" />
</td>
<td>
<g:Button ui:field="addUnit" text="Add unit" />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<g:Button ui:field="submit" text="Submit" />
</td>
</tr>
</table>
</g:HTMLPanel>
<g:HTMLPanel>
<c:CellBrowser defaultColumnWidth='300' ui:field='cellBrowser' />
</g:HTMLPanel>
</g:HorizontalPanel>
</ui:UiBinder>
风景:
public class UniteViewImpl extends Composite implements UniteView {
private Presenter presenter;
private static UniteViewImplUiBinder uiBinder = GWT.create(UniteViewImplUiBinder.class);
private ListDataProvider<FamilleUniteProxy> dataProvider;
interface UniteViewImplUiBinder extends UiBinder<Widget, UniteViewImpl> {
}
@SuppressWarnings("deprecation")
public UniteViewImpl() {
dataProvider = new ListDataProvider<FamilleUniteProxy>(
new ArrayList<FamilleUniteProxy>());
TreeViewModel model = new CustomTreeModel(dataProvider);
cellBrowser = new CellBrowser(model, null);
cellBrowser.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
cellBrowser.setHeight("200");
cellBrowser.setWidth("630");
RootPanel.get().add(cellBrowser); // If I delete this line, the cellBrowser is not displayed
initWidget(uiBinder.createAndBindUi(this));
}
@UiField
TextBox familyName;
@UiField
TextBox unitName;
@UiField
Button addUnit;
@UiField
Button submit;
@UiField(provided = true)
CellBrowser cellBrowser;
public UniteViewImpl(String firstName) {
initWidget(uiBinder.createAndBindUi(this));
}
@Override
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
}
public void updateProvider(List<FamilleUniteProxy> familles) {
dataProvider.setList(familles);
dataProvider.refresh();
}
@UiFactory
public CellBrowser getCellBrowser() {
return cellBrowser;
}
}
树视图模型类:
class CustomTreeModel implements TreeViewModel {
private ListDataProvider<FamilleUniteProxy> dataProvider ;
public CustomTreeModel(ListDataProvider<FamilleUniteProxy> dataProvider) {
this.dataProvider = dataProvider;
}
public <T> NodeInfo<?> getNodeInfo(T value) {
if (value == null) {
Cell<FamilleUniteProxy> cell = new AbstractCell<FamilleUniteProxy>() {
@Override
public void render(Context context, FamilleUniteProxy value,
SafeHtmlBuilder sb) {
sb.appendEscaped(value.getIntituleFamilleUnite());
}
};
return new DefaultNodeInfo<FamilleUniteProxy>(dataProvider, cell);
} else if (value instanceof FamilleUniteProxy) {
ListDataProvider<UniteProxy> dataProvider = new ListDataProvider<UniteProxy>(
((FamilleUniteProxy) value).getUnites());
Cell<UniteProxy> cell = new AbstractCell<UniteProxy>() {
@Override
public void render(Context context, UniteProxy value,
SafeHtmlBuilder sb) {
if (value != null) {
sb.appendEscaped(value.getIntituleUnite());
}
}
};
return new DefaultNodeInfo<UniteProxy>(dataProvider, cell);
}
return null;
}
public boolean isLeaf(Object value) {
if (value instanceof UniteProxy) {
return true;
}
return false;
}
}
我希望它很清楚,非常感谢你。