GWT: CellBrowser isn't displayed in a composite

262 views Asked by At

Please I need your help. I've created a CellBrowser with UiBinder that I populate from a database. The problem is that I can't display it using the InitWidget method. But if I attach it directely to the RootPanel (using the instruction: RootPanel.get().add(cellBrowser);), it gets displayed, but over the other coponents that are attached to the composite (it becomes a real mess :/ ). I've put it in a HTMLPanel but it doesn't work.

How can I attach it to the composite and get it displayed with the other widgets? (I've tried other panels, but it didn't work :/ ).

Here's my code:

The UiBinder file:

        <!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> 

The view:

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

The TreeViewModel class:

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

I hope it's clear and thank you very much.

1

There are 1 answers

0
Kiwi On

Well, I found the answer. It was the width and height that must be in pixel (200px and 630px). Hope it will help someone :)