Search in sources :

Example 1 with TableWithLongColumn

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn in project scout.rt by eclipse.

the class JsonCellToJsonTest method testNullValueAndEmptyText.

/**
 * Send only empty text if both are empty
 */
@Test
public void testNullValueAndEmptyText() throws JSONException {
    TableWithLongColumn table = new TableWithLongColumn();
    table.initTable();
    ITableRow row = table.addRow(table.createRow());
    table.getColumn().setValue(row, null);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    JSONObject jsonObj = (JSONObject) jsonTable.cellToJson(row, table.getColumn());
    assertEquals("", jsonObj.get("text"));
    assertNull(jsonObj.opt("value"));
}
Also used : TableWithLongColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn) JSONObject(org.json.JSONObject) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 2 with TableWithLongColumn

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn in project scout.rt by eclipse.

the class JsonCellToJsonTest method testNullValue.

/**
 * Send {@link JSONObject#NULL} if value is null if value is required.
 */
@Test
public void testNullValue() throws JSONException {
    TableWithLongColumn table = new TableWithLongColumn();
    table.initTable();
    ITableRow row = table.addRow(table.createRow());
    table.getColumn().setValue(row, null);
    row.getCellForUpdate(table.getColumn()).setText("-empty-");
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    JSONObject jsonObj = (JSONObject) jsonTable.cellToJson(row, table.getColumn());
    assertEquals("-empty-", jsonObj.get("text"));
    assertEquals(JSONObject.NULL, jsonObj.get("value"));
}
Also used : TableWithLongColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn) JSONObject(org.json.JSONObject) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 3 with TableWithLongColumn

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn in project scout.rt by eclipse.

the class JsonCellToJsonTest method testLongColumn.

/**
 * Don't send value and text if they are equal.
 */
@Test
public void testLongColumn() throws JSONException {
    TableWithLongColumn table = new TableWithLongColumn();
    table.initTable();
    ITableRow row = table.addRow(table.createRow());
    table.getColumn().setValue(row, 15L);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    JSONObject jsonObj = (JSONObject) jsonTable.cellToJson(row, table.getColumn());
    Assert.assertEquals("15", jsonObj.get("text"));
    assertNull(jsonObj.opt("value"));
}
Also used : TableWithLongColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn) JSONObject(org.json.JSONObject) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 4 with TableWithLongColumn

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn in project scout.rt by eclipse.

the class JsonCellToJsonTest method testLongColumn_leftAlignment.

/**
 * Don't generate a cell object if text is the only property.
 */
@Test
public void testLongColumn_leftAlignment() throws JSONException {
    TableWithLongColumn table = new TableWithLongColumn();
    table.getColumn().setHorizontalAlignment(-1);
    table.initTable();
    ITableRow row = table.addRow(table.createRow());
    table.getColumn().setValue(row, 15L);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    Object jsonObj = jsonTable.cellToJson(row, table.getColumn());
    assertTrue(jsonObj instanceof String);
}
Also used : TableWithLongColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) JSONObject(org.json.JSONObject) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 5 with TableWithLongColumn

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn in project scout.rt by eclipse.

the class JsonCellToJsonTest method testNullValueAndEmptyText_leftAlignment.

/**
 * Send only empty text if both are empty
 */
@Test
public void testNullValueAndEmptyText_leftAlignment() throws JSONException {
    TableWithLongColumn table = new TableWithLongColumn();
    table.getColumn().setHorizontalAlignment(-1);
    table.initTable();
    ITableRow row = table.addRow(table.createRow());
    table.getColumn().setValue(row, null);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    Object jsonObj = jsonTable.cellToJson(row, table.getColumn());
    assertEquals("", jsonObj);
}
Also used : TableWithLongColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) JSONObject(org.json.JSONObject) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Aggregations

ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)5 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)5 TableWithLongColumn (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn)5 JSONObject (org.json.JSONObject)5 Test (org.junit.Test)5