Search in sources :

Example 31 with ITable

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

the class JsonTableTest method testUserRowFilter_toJson.

/**
 * If toJson is called and a user filter is active, every row must be returned and not only the filtered ones
 */
@Test
public void testUserRowFilter_toJson() 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 row2 = table.getRow(2);
    List<ITableRow> filteredRows = new ArrayList<ITableRow>();
    filteredRows.add(row0);
    filteredRows.add(row2);
    table.getUIFacade().setFilteredRowsFromUI(filteredRows);
    jsonTable.toJson();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertEquals(3, table.getRowCount());
    assertEquals(2, table.getFilteredRowCount());
    assertEquals(3, jsonTable.tableRowIdsMap().size());
}
Also used : ArrayList(java.util.ArrayList) 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 32 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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 33 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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 34 with ITable

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

the class JsonTableFieldTest method testPreventTableDisposal2.

@Test
public void testPreventTableDisposal2() {
    // Create tablePage
    IPageWithTable<?> tablePage = createTablePageAndSelectNode();
    ITable tablePageTable = tablePage.getTable();
    JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, tablePage.getOutline(), null);
    Assert.assertNotNull(jsonOutline.getAdapter(tablePageTable));
    // Create table field which uses the table from the table page
    ITableField<ITable> tableField = new TableField<ITable>();
    JsonTableField<ITableField<?>> jsonTableField = UiSessionTestUtility.newJsonAdapter(m_uiSession, tableField, null);
    tableField.setTable(tablePageTable, true);
    // Switch table -> table must not be disposed because table page still needs it
    ITable table2 = new Table();
    tableField.setTable(table2, true);
    assertNotNull(jsonTableField.getAdapter(table2));
    assertTrue(jsonTableField.getAdapter(table2).isInitialized());
    assertNotNull(jsonOutline.getAdapter(tablePageTable));
    assertTrue(jsonOutline.getAdapter(tablePageTable).isInitialized());
}
Also used : ITableField(org.eclipse.scout.rt.client.ui.form.fields.tablefield.ITableField) Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IPageWithTable(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableField(org.eclipse.scout.rt.client.ui.form.fields.tablefield.ITableField) TableField(org.eclipse.scout.rt.ui.html.json.form.fields.tablefield.fixtures.TableField) Test(org.junit.Test)

Example 35 with ITable

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

the class JsonTableFieldTest method testTableDisposal.

@Test
public void testTableDisposal() {
    ITable table = new Table();
    ITableField<ITable> tableField = new TableField<ITable>(table);
    JsonTableField<ITableField<?>> jsonTableField = UiSessionTestUtility.newJsonAdapter(m_uiSession, tableField, null);
    assertNotNull(jsonTableField.getAdapter(table));
    jsonTableField.dispose();
    assertNull(jsonTableField.getAdapter(table));
}
Also used : ITableField(org.eclipse.scout.rt.client.ui.form.fields.tablefield.ITableField) Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IPageWithTable(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableField(org.eclipse.scout.rt.client.ui.form.fields.tablefield.ITableField) TableField(org.eclipse.scout.rt.ui.html.json.form.fields.tablefield.fixtures.TableField) Test(org.junit.Test)

Aggregations

ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)89 Test (org.junit.Test)64 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)45 TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)28 JSONObject (org.json.JSONObject)23 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)16 JSONArray (org.json.JSONArray)12 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)11 Table (org.eclipse.scout.rt.ui.html.json.table.fixtures.Table)10 ArrayList (java.util.ArrayList)9 ListBoxTable (org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable)8 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)6 AbstractTable (org.eclipse.scout.rt.client.ui.basic.table.AbstractTable)6 ITableField (org.eclipse.scout.rt.client.ui.form.fields.tablefield.ITableField)5 TableWithLongColumn (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn)5 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)4 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)4 IPageWithTable (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable)4 IProposalField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.IProposalField)4 OrderedCollection (org.eclipse.scout.rt.platform.util.collection.OrderedCollection)4