Search in sources :

Example 1 with ValueUpdater

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

the class ColumnTest method testOnBrowserEventWithoutFieldUpdater.

public void testOnBrowserEventWithoutFieldUpdater() {
    final Element theElem = Document.get().createDivElement();
    final NativeEvent theEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
    final MockEditableCell cell = new MockEditableCell() {

        @Override
        public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) {
            assertEquals(theElem, parent);
            assertEquals("test", value);
            assertEquals("oldViewData", getViewData("test"));
            assertEquals(theEvent, event);
            assertNull(valueUpdater);
            setViewData("test", "newViewData");
        }
    };
    Column<String, String> column = new IdentityColumn<String>(cell);
    cell.setViewData("test", "oldViewData");
    Context context = new Context(3, 0, null);
    column.onBrowserEvent(context, theElem, "test", theEvent);
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) ValueUpdater(org.gwtproject.cell.client.ValueUpdater) Element(org.gwtproject.dom.client.Element) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 2 with ValueUpdater

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

the class ColumnTest method testOnBrowserEventWithFieldUpdater.

public void testOnBrowserEventWithFieldUpdater() {
    final Element theElem = Document.get().createDivElement();
    final NativeEvent theEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
    final MockEditableCell cell = new MockEditableCell() {

        @Override
        public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) {
            assertEquals(theElem, parent);
            assertEquals("test", value);
            assertEquals("oldViewData", getViewData("test"));
            assertEquals(theEvent, event);
            assertNotNull(valueUpdater);
            setViewData("test", "newViewData");
            valueUpdater.update("newValue");
        }
    };
    final Column<String, String> column = new IdentityColumn<String>(cell);
    final MockFieldUpdater<String, String> fieldUpdater = new MockFieldUpdater<String, String>() {

        @Override
        public void update(int index, String object, String value) {
            // The new view data should already be set.
            assertEquals("newViewData", cell.getViewData("test"));
            super.update(index, object, value);
        }
    };
    column.setFieldUpdater(fieldUpdater);
    cell.setViewData("test", "oldViewData");
    Context context = new Context(3, 0, null);
    column.onBrowserEvent(context, theElem, "test", theEvent);
    fieldUpdater.assertUpdateCalled(true);
    fieldUpdater.assertIndex(3);
    fieldUpdater.assertObject("test");
    fieldUpdater.assertValue("newValue");
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) ValueUpdater(org.gwtproject.cell.client.ValueUpdater) Element(org.gwtproject.dom.client.Element) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 3 with ValueUpdater

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

the class ColumnTest method testDelayedValueUpdaer.

/**
 * Test that a cell can hold onto the {@link ValueUpdater} and update it
 * later.
 */
public void testDelayedValueUpdaer() {
    final Element theElem = Document.get().createDivElement();
    final NativeEvent theEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
    final MockEditableCell cell = new MockEditableCell() {

        @Override
        public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, final ValueUpdater<String> valueUpdater) {
            setViewData("test", "newViewData");
            new Timer() {

                @Override
                public void run() {
                    valueUpdater.update("newValue");
                }
            }.schedule(200);
        }
    };
    final Column<String, String> column = new IdentityColumn<>(cell);
    final MockFieldUpdater<String, String> fieldUpdater = new MockFieldUpdater<String, String>() {

        @Override
        public void update(int index, String object, String value) {
            assertEquals("newViewData", cell.getViewData("test"));
            super.update(index, object, value);
            finishTest();
        }
    };
    column.setFieldUpdater(fieldUpdater);
    // Fire the event to the cell.
    delayTestFinish(5000);
    cell.setViewData("test", "oldViewData");
    Context context = new Context(3, 0, null);
    column.onBrowserEvent(context, theElem, "test", theEvent);
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) Timer(org.gwtproject.timer.client.Timer) ValueUpdater(org.gwtproject.cell.client.ValueUpdater) Element(org.gwtproject.dom.client.Element) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 4 with ValueUpdater

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

the class DefaultNodeInfoTest method testAccessors.

public void testAccessors() {
    org.gwtproject.view.client.ListDataProvider<String> provider = new ListDataProvider<String>();
    TextCell cell = new TextCell();
    org.gwtproject.view.client.SingleSelectionModel<String> selectionModel = new org.gwtproject.view.client.SingleSelectionModel<String>(null);
    ValueUpdater<String> valueUpdater = new ValueUpdater<String>() {

        @Override
        public void update(String value) {
        }
    };
    DefaultNodeInfo<String> nodeInfo = new DefaultNodeInfo<String>(provider, cell, selectionModel, valueUpdater);
    assertEquals(provider, nodeInfo.getProvidesKey());
    assertEquals(cell, nodeInfo.getCell());
    assertEquals(selectionModel, nodeInfo.getSelectionModel());
    assertEquals(valueUpdater, nodeInfo.getValueUpdater());
}
Also used : DefaultNodeInfo(org.gwtproject.view.client.TreeViewModel.DefaultNodeInfo) TextCell(org.gwtproject.cell.client.TextCell) ValueUpdater(org.gwtproject.cell.client.ValueUpdater)

Aggregations

ValueUpdater (org.gwtproject.cell.client.ValueUpdater)4 Context (org.gwtproject.cell.client.Cell.Context)3 Element (org.gwtproject.dom.client.Element)3 NativeEvent (org.gwtproject.dom.client.NativeEvent)3 TextCell (org.gwtproject.cell.client.TextCell)1 Timer (org.gwtproject.timer.client.Timer)1 DefaultNodeInfo (org.gwtproject.view.client.TreeViewModel.DefaultNodeInfo)1