GWT:CellBrowser没有显示在复合材料中

时间:2014-06-13 23:46:59

标签: java gwt uibinder cellbrowser

我需要你的帮助。我用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;
        }
    }

TreeViewModel类:

    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;
        }
    }

我希望它很清楚,非常感谢你。

1 个答案:

答案 0 :(得分:0)

好吧,我找到了答案。宽度和高度必须以像素为单位(200px和630px)。希望它会帮助某人:)