Search in sources :

Example 1 with Context

use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.

the class DefaultSelectionEventManagerTest method testHandleSelectionEventToggle.

public void testHandleSelectionEventToggle() {
    org.gwtproject.view.client.SingleSelectionModel<String> model = new SingleSelectionModel<String>();
    display.setSelectionModel(model);
    model.setSelected("test 0", true);
    // Toggle a different value.
    NativeEvent nativeEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
    org.gwtproject.view.client.CellPreviewEvent<String> event = new CellPreviewEvent<String>(nativeEvent, display, new Context(1, 0, null), "test 1", false, false);
    manager.handleSelectionEvent(event, SelectAction.TOGGLE, model);
    assertEquals("test 1", model.getSelectedObject());
    // Toggle the same value.
    manager.handleSelectionEvent(event, SelectAction.TOGGLE, model);
    assertNull(model.getSelectedObject());
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 2 with Context

use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.

the class DefaultSelectionEventManagerTest method testHandleSelectionEventSelect.

public void testHandleSelectionEventSelect() {
    org.gwtproject.view.client.SingleSelectionModel<String> model = new org.gwtproject.view.client.SingleSelectionModel<String>();
    display.setSelectionModel(model);
    model.setSelected("test 0", true);
    // Select the same value.
    NativeEvent nativeEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
    org.gwtproject.view.client.CellPreviewEvent<String> event = new org.gwtproject.view.client.CellPreviewEvent<String>(nativeEvent, display, new Context(0, 0, null), "test 0", false, false);
    manager.handleSelectionEvent(event, SelectAction.SELECT, model);
    assertEquals("test 0", model.getSelectedObject());
    // Select a different value.
    event = new org.gwtproject.view.client.CellPreviewEvent<String>(nativeEvent, display, new Context(1, 0, null), "test 1", false, false);
    manager.handleSelectionEvent(event, SelectAction.SELECT, model);
    assertEquals("test 1", model.getSelectedObject());
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 3 with Context

use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.

the class DefaultSelectionEventManagerTest method testHandleSelectionEventIgnore.

public void testHandleSelectionEventIgnore() {
    org.gwtproject.view.client.SingleSelectionModel<String> model = new org.gwtproject.view.client.SingleSelectionModel<String>();
    display.setSelectionModel(model);
    model.setSelected("test 0", true);
    NativeEvent nativeEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
    org.gwtproject.view.client.CellPreviewEvent<String> event = new org.gwtproject.view.client.CellPreviewEvent<String>(nativeEvent, display, new Context(3, 0, null), "test 3", false, false);
    manager.handleSelectionEvent(event, SelectAction.IGNORE, model);
    assertEquals("test 0", model.getSelectedObject());
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 4 with Context

use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.

the class EditTextCellTest method testEdit.

public void testEdit() {
    EditTextCell cell = createCell();
    Element parent = Document.get().createDivElement();
    parent.setInnerHTML("<input type='text' value='editing'></input>");
    ViewData viewData = new ViewData("originalValue");
    viewData.setText("newValue");
    cell.setViewData(DEFAULT_KEY, viewData);
    Context context = new Context(0, 0, DEFAULT_KEY);
    cell.edit(context, parent, "originalValue");
    // Verify the input element.
    Element child = parent.getFirstChildElement();
    assertTrue(InputElement.is(child));
    InputElement input = child.cast();
    assertEquals("newValue", input.getValue());
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) ViewData(org.gwtproject.cell.client.EditTextCell.ViewData) InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element) InputElement(org.gwtproject.dom.client.InputElement)

Example 5 with Context

use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.

the class EditTextCellTest method testRenderViewDataDoneEditing.

/**
 * Test rendering the cell with a valid value and view data, but without
 * editing.
 */
public void testRenderViewDataDoneEditing() {
    EditTextCell cell = createCell();
    ViewData viewData = new ViewData("originalValue");
    viewData.setText("newValue");
    viewData.setEditing(false);
    cell.setViewData(DEFAULT_KEY, viewData);
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    Context context = new Context(0, 0, DEFAULT_KEY);
    cell.render(context, "originalValue", sb);
    assertEquals("newValue", sb.toSafeHtml().asString());
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) ViewData(org.gwtproject.cell.client.EditTextCell.ViewData) SafeHtmlBuilder(org.gwtproject.safehtml.shared.SafeHtmlBuilder)

Aggregations

Context (org.gwtproject.cell.client.Cell.Context)33 Element (org.gwtproject.dom.client.Element)14 SafeHtmlBuilder (org.gwtproject.safehtml.shared.SafeHtmlBuilder)13 NativeEvent (org.gwtproject.dom.client.NativeEvent)9 ViewData (org.gwtproject.cell.client.EditTextCell.ViewData)3 ValueUpdater (org.gwtproject.cell.client.ValueUpdater)3 TableCellBuilder (org.gwtproject.dom.builder.shared.TableCellBuilder)2 DivElement (org.gwtproject.dom.client.DivElement)2 EventTarget (org.gwtproject.dom.client.EventTarget)2 ImageElement (org.gwtproject.dom.client.ImageElement)2 TableCellElement (org.gwtproject.dom.client.TableCellElement)2 TableElement (org.gwtproject.dom.client.TableElement)2 TableRowElement (org.gwtproject.dom.client.TableRowElement)2 TableSectionElement (org.gwtproject.dom.client.TableSectionElement)2 HorizontalAlignmentConstant (org.gwtproject.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant)2 VerticalAlignmentConstant (org.gwtproject.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant)2 HasCell (org.gwtproject.cell.client.HasCell)1 TextCell (org.gwtproject.cell.client.TextCell)1 Scheduler (org.gwtproject.core.client.Scheduler)1 DivBuilder (org.gwtproject.dom.builder.shared.DivBuilder)1