Search in sources :

Example 1 with TextCell

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

the class DefaultNodeInfoTest method testSetDataDisplay.

public void testSetDataDisplay() {
    SelectionModel<String> model = new SingleSelectionModel<String>();
    org.gwtproject.view.client.DefaultSelectionEventManager<String> manager = DefaultSelectionEventManager.createDefaultManager();
    MockDataProvider<String> provider = new MockDataProvider<String>(null);
    DefaultNodeInfo<String> nodeInfo = new DefaultNodeInfo<String>(provider, new TextCell(), model, manager, null);
    MockHasData<String> display = new MockHasData<String>();
    display.setVisibleRange(0, 10);
    display.clearLastRowDataAndRange();
    assertEquals(0, display.getHandlerCount(org.gwtproject.view.client.CellPreviewEvent.getType()));
    // setDataDisplay.
    nodeInfo.setDataDisplay(display);
    assertEquals(1, display.getHandlerCount(org.gwtproject.view.client.CellPreviewEvent.getType()));
    provider.assertLastRangeChanged(display);
    provider.clearLastRangeChanged();
    display.setVisibleRange(0, 5);
    provider.assertLastRangeChanged(display);
    provider.clearLastRangeChanged();
    // unsetDataDisplay.
    nodeInfo.unsetDataDisplay();
    assertEquals(0, display.getHandlerCount(CellPreviewEvent.getType()));
    display.setVisibleRange(0, 5);
    provider.assertLastRangeChanged(null);
}
Also used : DefaultNodeInfo(org.gwtproject.view.client.TreeViewModel.DefaultNodeInfo) TextCell(org.gwtproject.cell.client.TextCell) MockDataProvider(org.gwtproject.view.client.AbstractDataProviderTest.MockDataProvider)

Example 2 with TextCell

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

the class AbstractCellTableTestBase method testSetColumnWidthMixed.

/**
 * Test that setting column widths using columns and column indexes works
 * correctly.
 */
public void testSetColumnWidthMixed() {
    AbstractCellTable<String> table = createAbstractHasData(new TextCell());
    Column<String, ?> col0 = new MockColumn<String, String>();
    Column<String, ?> col1 = new MockColumn<String, String>();
    Column<String, ?> col2 = new MockColumn<String, String>();
    // Column 0 set by Column.
    table.setColumnWidth(col0, "100px");
    // Column 1 set by Column and column index.
    table.setColumnWidth(col1, 200.0, Unit.EM);
    table.setColumnWidth(1, "210em");
    // Column 2 set by column index.
    table.setColumnWidth(2, "300px");
    assertEquals("100px", table.getColumnWidth(col0));
    assertEquals("300px", table.getColumnWidth(2));
    /*
     * Some browsers return 200.0, others 200. Column takes precendence over
     * column index.
     */
    assertTrue(table.getColumnWidth(col1).contains("200"));
    // Check a column that has not been set.
    assertNull(table.getColumnWidth(col2));
    // Check a column that has been cleared.
    table.clearColumnWidth(col0);
    assertNull(table.getColumnWidth(col0));
}
Also used : TextCell(org.gwtproject.cell.client.TextCell)

Example 3 with TextCell

use of org.gwtproject.cell.client.TextCell 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 4 with TextCell

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

the class ColumnSortEventTest method testListHandler.

public void testListHandler() {
    // Create some unsorted values.
    List<String> values = new ArrayList<String>();
    values.add("b");
    values.add("a");
    values.add("c");
    // Create a handler for the list of values.
    ListHandler<String> handler = new ListHandler<String>(values);
    IdentityColumn<String> col0 = new IdentityColumn<String>(new TextCell());
    Comparator<String> col0Comparator = new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    };
    handler.setComparator(col0, col0Comparator);
    IdentityColumn<String> col1 = new IdentityColumn<String>(new TextCell());
    handler.setComparator(col1, null);
    // Sort ascending.
    ColumnSortList sortList = new ColumnSortList();
    sortList.push(col0);
    handler.onColumnSort(new ColumnSortEvent(sortList));
    assertEquals("a", values.get(0));
    assertEquals("b", values.get(1));
    assertEquals("c", values.get(2));
    // Sort descending.
    // Switches sort to descending.
    sortList.push(col0);
    handler.onColumnSort(new ColumnSortEvent(sortList));
    assertEquals("c", values.get(0));
    assertEquals("b", values.get(1));
    assertEquals("a", values.get(2));
    // Null comparator.
    sortList.push(col1);
    assertEquals("c", values.get(0));
    assertEquals("b", values.get(1));
    assertEquals("a", values.get(2));
    // Retrieve the comparators.
    assertEquals(col0Comparator, handler.getComparator(col0));
    assertNull(handler.getComparator(col1));
    assertNull(handler.getComparator(new IdentityColumn<String>(new TextCell())));
    // Create some new unsorted values.
    List<String> newValues = new ArrayList<String>();
    newValues.add("e");
    newValues.add("d");
    newValues.add("f");
    // Update the handler to be for the new list of values.
    handler.setList(newValues);
    // Sort the new list in ascending order.
    sortList.push(col0);
    handler.onColumnSort(new ColumnSortEvent(sortList));
    // The new values, sorted in ascending order.
    assertEquals("d", newValues.get(0));
    assertEquals("e", newValues.get(1));
    assertEquals("f", newValues.get(2));
    // The old values, still sorted in descending order.
    assertEquals("c", values.get(0));
    assertEquals("b", values.get(1));
    assertEquals("a", values.get(2));
}
Also used : ListHandler(org.gwtproject.user.cellview.client.ColumnSortEvent.ListHandler) ArrayList(java.util.ArrayList) TextCell(org.gwtproject.cell.client.TextCell) Comparator(java.util.Comparator)

Example 5 with TextCell

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

the class ColumnSortInfoTest method testEquals.

public void testEquals() {
    // Test equals.
    Column<String, String> column0 = new IdentityColumn<String>(new TextCell());
    ColumnSortInfo info0a = new ColumnSortInfo(column0, true);
    ColumnSortInfo info0b = new ColumnSortInfo(column0, true);
    assertTrue(info0a.equals(info0b));
    assertTrue(info0b.equals(info0a));
    assertEquals(info0a.hashCode(), info0b.hashCode());
    // Test null.
    assertFalse(info0a.equals(null));
    // Test different object.
    assertFalse(info0a.equals("not a ColumnSortInfo"));
    // Test different sort order.
    ColumnSortInfo info0desc = new ColumnSortInfo(column0, false);
    assertFalse(info0a.equals(info0desc));
    assertFalse(info0desc.equals(info0a));
    assertTrue(info0a.hashCode() != info0desc.hashCode());
    // Test different column.
    Column<String, String> column1 = new IdentityColumn<String>(new TextCell());
    ColumnSortInfo info1 = new ColumnSortInfo(column1, true);
    assertFalse(info0a.equals(info1));
    assertFalse(info1.equals(info0a));
    assertTrue(info0a.hashCode() != info1.hashCode());
}
Also used : ColumnSortInfo(org.gwtproject.user.cellview.client.ColumnSortList.ColumnSortInfo) TextCell(org.gwtproject.cell.client.TextCell)

Aggregations

TextCell (org.gwtproject.cell.client.TextCell)41 TableSectionElement (org.gwtproject.dom.client.TableSectionElement)6 ColumnSortInfo (org.gwtproject.user.cellview.client.ColumnSortList.ColumnSortInfo)5 ListDataProvider (org.gwtproject.view.client.ListDataProvider)5 ArrayList (java.util.ArrayList)4 TableCellElement (org.gwtproject.dom.client.TableCellElement)4 Label (org.gwtproject.user.client.ui.Label)4 TableRowBuilder (org.gwtproject.dom.builder.shared.TableRowBuilder)3 Element (org.gwtproject.dom.client.Element)3 TableElement (org.gwtproject.dom.client.TableElement)3 TableRowElement (org.gwtproject.dom.client.TableRowElement)3 SafeHtmlBuilder (org.gwtproject.safehtml.shared.SafeHtmlBuilder)2 Handler (org.gwtproject.user.cellview.client.AbstractHasData.RedrawEvent.Handler)2 TreeViewModel (org.gwtproject.view.client.TreeViewModel)2 DefaultNodeInfo (org.gwtproject.view.client.TreeViewModel.DefaultNodeInfo)2 Comparator (java.util.Comparator)1 AbstractCell (org.gwtproject.cell.client.AbstractCell)1 Context (org.gwtproject.cell.client.Cell.Context)1 ValueUpdater (org.gwtproject.cell.client.ValueUpdater)1 NativeEvent (org.gwtproject.dom.client.NativeEvent)1