Search in sources :

Example 1 with AbstractCell

use of org.gwtproject.cell.client.AbstractCell in project gwtproject by treblereel.

the class CellTreeTest method testRenderSameContent.

/**
 * Test that CellTree handles rendering the same content, but with a different
 * underlying value.
 */
public void testRenderSameContent() {
    final AbstractCell<Integer> intCell = new AbstractCell<Integer>() {

        @Override
        public void render(Context context, Integer value, SafeHtmlBuilder sb) {
            // Render the units digit only.
            sb.append(value % 10);
        }
    };
    // Create a data provider for the root node.
    final ListDataProvider<Integer> root = new ListDataProvider<Integer>();
    for (int i = 0; i < 9; i++) {
        root.getList().add(i);
    }
    TreeViewModel model = new TreeViewModel() {

        @Override
        public NodeInfo<?> getNodeInfo(Object value) {
            if (value == null) {
                // Return the root node.
                return new DefaultNodeInfo<Integer>(root, intCell);
            } else {
                // Return a child node.
                return new DefaultNodeInfo<String>(new ListDataProvider<String>(), new TextCell());
            }
        }

        @Override
        public boolean isLeaf(Object value) {
            return false;
        }
    };
    CellTree tree = createAbstractCellTree(model, null);
    RootPanel.get().add(tree);
    tree.rootNode.listView.presenter.flush();
    // Open the first child.
    TreeNode rootNode = tree.getRootTreeNode();
    assertEquals(1, rootNode.getChildValue(1));
    TreeNode child1 = rootNode.setChildOpen(1, true);
    assertFalse(child1.isDestroyed());
    assertTrue(rootNode.isChildOpen(1));
    // Replace all values in the list.
    List<Integer> oldData = root.getList();
    List<Integer> newData = new ArrayList<Integer>();
    for (int l : oldData) {
        // renders the same as the current value.
        newData.add(l + 100);
    }
    root.setList(newData);
    root.flush();
    tree.rootNode.listView.presenter.flush();
    // Child1 is closed and destroyed.
    assertFalse(rootNode.isChildOpen(1));
    assertTrue(child1.isDestroyed());
    RootPanel.get().remove(tree);
}
Also used : ListDataProvider(org.gwtproject.view.client.ListDataProvider) ArrayList(java.util.ArrayList) SafeHtmlBuilder(org.gwtproject.safehtml.shared.SafeHtmlBuilder) TextCell(org.gwtproject.cell.client.TextCell) AbstractCell(org.gwtproject.cell.client.AbstractCell) TreeViewModel(org.gwtproject.view.client.TreeViewModel)

Example 2 with AbstractCell

use of org.gwtproject.cell.client.AbstractCell in project gwtproject by treblereel.

the class CellWidgetTest method testRedrawWithMultipleInnerChildren.

/**
 * Test that a cell that defines an HTML elment can be rendered.
 */
public void testRedrawWithMultipleInnerChildren() {
    Cell<String> cell = new AbstractCell<String>() {

        @Override
        public void render(Cell.Context context, String value, SafeHtmlBuilder sb) {
            if (value != null) {
                sb.appendHtmlConstant("<div>").appendEscaped(value).appendHtmlConstant("</div>");
                sb.appendHtmlConstant("<div>child2</div>");
            }
        }
    };
    CellWidget<String> cw = new CellWidget<String>(cell);
    // Set value without redrawing.
    cw.setValue("test123", false, false);
    assertEquals("", cw.getElement().getInnerText());
    // Redraw.
    cw.redraw();
    assertTrue(cw.getElement().getInnerText().contains("test123"));
    Style firstChildStyle = cw.getElement().getFirstChildElement().getStyle();
    assertFalse(firstChildStyle.getHeight().matches("100(.0)?%"));
    assertFalse(firstChildStyle.getWidth().matches("100(.0)?%"));
}
Also used : AbstractCell(org.gwtproject.cell.client.AbstractCell) Style(org.gwtproject.dom.client.Style) SafeHtmlBuilder(org.gwtproject.safehtml.shared.SafeHtmlBuilder)

Aggregations

AbstractCell (org.gwtproject.cell.client.AbstractCell)2 SafeHtmlBuilder (org.gwtproject.safehtml.shared.SafeHtmlBuilder)2 ArrayList (java.util.ArrayList)1 TextCell (org.gwtproject.cell.client.TextCell)1 Style (org.gwtproject.dom.client.Style)1 ListDataProvider (org.gwtproject.view.client.ListDataProvider)1 TreeViewModel (org.gwtproject.view.client.TreeViewModel)1