Search in sources :

Example 36 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class JsonTableTest method testClearSelectionEvent.

/**
 * Tests whether the model rows get correctly unselected
 */
@Test
public void testClearSelectionEvent() throws JSONException {
    Table table = createTableFixture(5);
    ITableRow row1 = table.getRow(1);
    table.selectRow(row1);
    assertTrue(row1.isSelected());
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    JsonEvent event = createJsonRowsSelectedEvent(null);
    jsonTable.handleUiEvent(event);
    assertTrue(table.getSelectedRows().size() == 0);
}
Also used : Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ListBoxTable(org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) 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 37 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class JsonListBoxTest method testReloadAndRowFilterChange.

/**
 * Usecase:
 * <p>
 * Listbox has a filter.<br>
 * 1. Reload the listbox -> generates rowsUpdated and rowOrderChanged events<br>
 * 2. Add a new filter -> generates rowFilterChanged which are converted into rowsDeleted or rowsInserted Asserts that
 * rowOrderChanged event contains the correct rows.
 */
@Test
public void testReloadAndRowFilterChange() throws Exception {
    ListBox listBox = new ListBox();
    ITable table = listBox.getTable();
    listBox.initField();
    JsonListBox<Long, IListBox<Long>> jsonListBox = m_uiSession.createJsonAdapter(listBox, null);
    JsonTable<ITable> jsonTable = jsonListBox.getAdapter(table);
    // Filter the first row
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow row) {
            Long key = (Long) row.getKeyValues().get(0);
            if (key.equals(0L)) {
                return false;
            }
            return true;
        }
    });
    assertEquals(3, table.getRowCount());
    assertEquals(2, table.getFilteredRowCount());
    // "Send" listbox to UI
    jsonListBox.toJson();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JsonTestUtility.endRequest(m_uiSession);
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // Load listbox BEFORE adding a new filter -> generates rowOrderChanged before the filter events
    listBox.loadListBoxData();
    // Filter second row as well
    String row1Id = jsonTable.getTableRowId(table.findRowByKey(Arrays.asList(1L)));
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow row) {
            Long key = (Long) row.getKeyValues().get(0);
            if (key.equals(1L)) {
                return false;
            }
            return true;
        }
    });
    assertEquals(1, table.getFilteredRowCount());
    JsonTestUtility.processBufferedEvents(m_uiSession);
    List<JsonEvent> eventList = m_uiSession.currentJsonResponse().getEventList();
    JsonEvent jsonEvent = eventList.get(0);
    assertEquals("rowsDeleted", jsonEvent.getType());
    assertEquals(1, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).length());
    assertEquals(row1Id, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).get(0));
    // eventList.get(1) is the rows_updated event, not of interest here
    jsonEvent = eventList.get(2);
    assertEquals("rowOrderChanged", jsonEvent.getType());
    JSONArray jsonRowIds = jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS);
    assertEquals(1, jsonRowIds.length());
}
Also used : IListBox(org.eclipse.scout.rt.client.ui.form.fields.listbox.IListBox) JSONArray(org.json.JSONArray) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) ITableRowFilter(org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IListBox(org.eclipse.scout.rt.client.ui.form.fields.listbox.IListBox) AbstractListBox(org.eclipse.scout.rt.client.ui.form.fields.listbox.AbstractListBox) Test(org.junit.Test)

Example 38 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class JsonTableTest method testRowFilter_nop.

/**
 * Usecase:
 * <p>
 * 1. Add filter to table<br>
 * 2. Remove same filter so that no rows are removed<br>
 * Assert that no events are generated, especially no rowsDeleted event
 */
@Test
public void testRowFilter_nop() throws JSONException {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(3);
    table.initTable();
    JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
    ITableRow row0 = table.getRow(0);
    ITableRow row1 = table.getRow(1);
    ITableRow row2 = table.getRow(2);
    jsonTable.toJson();
    assertNotNull(jsonTable.tableRowIdsMap().get(row0));
    assertNotNull(jsonTable.tableRowIdsMap().get(row1));
    assertNotNull(jsonTable.tableRowIdsMap().get(row2));
    ITableRowFilter filter = new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide first row
            return r.getRowIndex() > 0;
        }
    };
    table.addRowFilter(filter);
    assertEquals(2, table.getFilteredRowCount());
    // Remove the just added filter -> Must not create any request
    table.removeRowFilter(filter);
    assertEquals(3, table.getFilteredRowCount());
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertNotNull(jsonTable.tableRowIdsMap().get(row1));
    assertNotNull(jsonTable.tableRowIdsMap().get(row1));
    assertNotNull(jsonTable.tableRowIdsMap().get(row2));
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
}
Also used : ITableRowFilter(org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) 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 39 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class AbstractTableField method execMarkSaved.

@Override
protected void execMarkSaved() {
    super.execMarkSaved();
    if (m_table != null && !m_tableExternallyManaged) {
        try {
            m_table.setTableChanging(true);
            // 
            for (int i = 0; i < m_table.getRowCount(); i++) {
                ITableRow row = m_table.getRow(i);
                if (!row.isStatusNonchanged()) {
                    row.setStatusNonchanged();
                }
            }
            m_table.discardAllDeletedRows();
        } finally {
            m_table.setTableChanging(false);
        }
    }
}
Also used : ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 40 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class AbstractTableField method importFormFieldData.

@Override
public void importFormFieldData(AbstractFormFieldData source, boolean valueChangeTriggersEnabled) {
    Assertions.assertNotNull(source);
    if (source.isValueSet() && m_table != null) {
        try {
            if (!valueChangeTriggersEnabled) {
                setValueChangeTriggerEnabled(false);
            }
            if (source instanceof AbstractTableFieldBeanData) {
                AbstractTableFieldBeanData tableBeanData = (AbstractTableFieldBeanData) source;
                m_table.importFromTableBeanData(tableBeanData);
            }
            if (m_table.isCheckable() && m_table.getCheckableColumn() != null) {
                for (ITableRow row : m_table.getRows()) {
                    row.setChecked(BooleanUtility.nvl(m_table.getCheckableColumn().getValue(row)));
                }
            }
        } finally {
            if (!valueChangeTriggersEnabled) {
                setValueChangeTriggerEnabled(true);
            }
        }
    }
}
Also used : AbstractTableFieldBeanData(org.eclipse.scout.rt.shared.data.form.fields.tablefield.AbstractTableFieldBeanData) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Aggregations

ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)127 Test (org.junit.Test)77 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)47 ArrayList (java.util.ArrayList)23 JSONObject (org.json.JSONObject)22 TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)16 JSONArray (org.json.JSONArray)13 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)12 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)11 AbstractTable (org.eclipse.scout.rt.client.ui.basic.table.AbstractTable)7 IProposalField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.IProposalField)7 ListBoxTable (org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable)6 IMixedSmartField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.IMixedSmartField)5 Table (org.eclipse.scout.rt.ui.html.json.table.fixtures.Table)5 TableWithLongColumn (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn)5 DecimalFormat (java.text.DecimalFormat)4 List (java.util.List)4 Cell (org.eclipse.scout.rt.client.ui.basic.cell.Cell)4 ICell (org.eclipse.scout.rt.client.ui.basic.cell.ICell)4 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)4