Search in sources :

Example 1 with ViewData

use of org.gwtproject.cell.client.EditTextCell.ViewData in project gwtproject by treblereel.

the class EditTextCellTest method testViewData.

public void testViewData() {
    // Start in edit mode.
    ViewData viewData = new ViewData("originalValue");
    assertEquals("originalValue", viewData.getOriginal());
    assertEquals("originalValue", viewData.getText());
    assertTrue(viewData.isEditing());
    assertFalse(viewData.isEditingAgain());
    // Change the text.
    viewData.setText("newValue");
    assertEquals("originalValue", viewData.getOriginal());
    assertEquals("newValue", viewData.getText());
    assertTrue(viewData.isEditing());
    assertFalse(viewData.isEditingAgain());
    // Stop editing.
    viewData.setEditing(false);
    assertEquals("originalValue", viewData.getOriginal());
    assertEquals("newValue", viewData.getText());
    assertFalse(viewData.isEditing());
    assertFalse(viewData.isEditingAgain());
    // Edit again.
    viewData.setEditing(true);
    assertEquals("newValue", viewData.getOriginal());
    assertEquals("newValue", viewData.getText());
    assertTrue(viewData.isEditing());
    assertTrue(viewData.isEditingAgain());
}
Also used : ViewData(org.gwtproject.cell.client.EditTextCell.ViewData)

Example 2 with ViewData

use of org.gwtproject.cell.client.EditTextCell.ViewData in project gwtproject by treblereel.

the class EditTextCellTest method testOnBrowserEventCancel.

/**
 * Cancel and switch to read only mode.
 */
public void testOnBrowserEventCancel() {
    NativeEvent event = Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_ESCAPE);
    ViewData viewData = new ViewData("originalValue");
    viewData.setText("newValue");
    Element parent = testOnBrowserEvent("<input type='text' value='newValue'></input>", event, "originalValue", viewData, null, null);
    // Verify the input element is gone.
    assertEquals("originalValue", parent.getInnerHTML());
}
Also used : ViewData(org.gwtproject.cell.client.EditTextCell.ViewData) InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 3 with ViewData

use of org.gwtproject.cell.client.EditTextCell.ViewData in project gwtproject by treblereel.

the class EditTextCellTest method testOnBrowserEventCommit.

/**
 * Commit and switch to read only mode.
 */
public void testOnBrowserEventCommit() {
    NativeEvent event = Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_ENTER);
    ViewData viewData = new ViewData("originalValue");
    viewData.setText("newValue");
    assertTrue(viewData.isEditing());
    Element parent = testOnBrowserEvent("<input type='text' value='newValue'></input>", event, "originalValue", viewData, "newValue", viewData);
    assertFalse(viewData.isEditing());
    // Verify the input element is gone.
    assertEquals("newValue", parent.getInnerHTML());
}
Also used : ViewData(org.gwtproject.cell.client.EditTextCell.ViewData) InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 4 with ViewData

use of org.gwtproject.cell.client.EditTextCell.ViewData 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 ViewData

use of org.gwtproject.cell.client.EditTextCell.ViewData 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

ViewData (org.gwtproject.cell.client.EditTextCell.ViewData)8 Element (org.gwtproject.dom.client.Element)5 InputElement (org.gwtproject.dom.client.InputElement)5 NativeEvent (org.gwtproject.dom.client.NativeEvent)4 Context (org.gwtproject.cell.client.Cell.Context)3 SafeHtmlBuilder (org.gwtproject.safehtml.shared.SafeHtmlBuilder)2