Search in sources :

Example 6 with ITableRow

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

the class JsonTable method handleModelRequestFocusInCell.

protected void handleModelRequestFocusInCell(TableEvent event) {
    final ITableRow row = CollectionUtility.firstElement(event.getRows());
    if (row == null || !isRowAccepted(row)) {
        return;
    }
    JSONObject jsonEvent = new JSONObject();
    putProperty(jsonEvent, PROP_ROW_ID, getOrCreateRowId(row));
    putProperty(jsonEvent, PROP_COLUMN_ID, getColumnId(CollectionUtility.firstElement(event.getColumns())));
    addActionEvent(EVENT_REQUEST_FOCUS_IN_CELL, jsonEvent).protect();
}
Also used : JSONObject(org.json.JSONObject) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 7 with ITableRow

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

the class JsonTable method rowIdsToJson.

protected JSONArray rowIdsToJson(Collection<ITableRow> modelRows) {
    JSONArray jsonRowIds = new JSONArray();
    for (ITableRow row : modelRows) {
        if (!isRowAccepted(row)) {
            continue;
        }
        String rowId = getTableRowId(row);
        if (rowId == null) {
            // Ignore rows that are not yet sent to the UI
            continue;
        }
        jsonRowIds.put(rowId);
    }
    return jsonRowIds;
}
Also used : JSONArray(org.json.JSONArray) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 8 with ITableRow

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

the class TableEventFilter method filter.

@Override
public TableEvent filter(TableEvent event) {
    for (TableEventFilterCondition condition : getConditions()) {
        if (condition.getType() == event.getType()) {
            if (condition.checkRows()) {
                List<ITableRow> rows = new ArrayList<>(event.getRows());
                rows.removeAll(condition.getRows());
                if (rows.size() == 0) {
                    // Ignore event if no nodes remain (or if the event contained no nodes at all)
                    return null;
                }
                TableEvent newEvent = new TableEvent(m_jsonTable.getModel(), event.getType(), rows);
                return newEvent;
            }
            if (condition.checkCheckedRows()) {
                List<ITableRow> rows = new ArrayList<>(event.getRows());
                List<ITableRow> checkedRows = new ArrayList<>();
                List<ITableRow> uncheckedRows = new ArrayList<>();
                for (ITableRow row : rows) {
                    if (row.isChecked()) {
                        checkedRows.add(row);
                    } else {
                        uncheckedRows.add(row);
                    }
                }
                if (CollectionUtility.equalsCollection(checkedRows, condition.getCheckedRows()) && CollectionUtility.equalsCollection(uncheckedRows, condition.getUncheckedRows())) {
                    // Ignore event if the checked and the unchecked rows have not changes
                    return null;
                }
                // Otherwise, send rows that a different checked state than before
                checkedRows.removeAll(condition.getCheckedRows());
                uncheckedRows.removeAll(condition.getUncheckedRows());
                rows = CollectionUtility.combine(checkedRows, uncheckedRows);
                TableEvent newEvent = new TableEvent(m_jsonTable.getModel(), event.getType(), rows);
                return newEvent;
            }
            if (condition.checkColumns()) {
                // Columns are not delivered by the event itself (at least not with COLUMN_ORDER_CHANGED) -> grab from table
                if (CollectionUtility.equalsCollection(m_jsonTable.getColumnsInViewOrder(), condition.getColumns())) {
                    return null;
                }
                // Don't ignore if columns are different
                return event;
            }
            if (condition.checkUserFilter()) {
                if (condition.getUserFilter().equals(event.getUserFilter())) {
                    return null;
                }
                // Don't ignore if filters are different
                return event;
            }
            // Ignore event if only type should be checked
            return null;
        }
    }
    return event;
}
Also used : TableEvent(org.eclipse.scout.rt.client.ui.basic.table.TableEvent) ArrayList(java.util.ArrayList) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 9 with ITableRow

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

the class JsonTable method extractTableRows.

protected List<ITableRow> extractTableRows(JSONObject json) {
    JSONArray rowIds = json.getJSONArray(PROP_ROW_IDS);
    List<ITableRow> rows = new ArrayList<>(rowIds.length());
    for (int i = 0; i < rowIds.length(); i++) {
        ITableRow tableRow = optTableRow((String) rowIds.get(i));
        if (tableRow != null) {
            rows.add(tableRow);
        }
    }
    return rows;
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 10 with ITableRow

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

the class JsonTable method handleUiRowClick.

protected void handleUiRowClick(JsonEvent event) {
    ITableRow tableRow = extractTableRow(event.getData());
    if (tableRow == null) {
        LOG.info("Requested table-row doesn't exist anymore -> skip rowClicked event");
        return;
    }
    ArrayList<ITableRow> rows = new ArrayList<ITableRow>();
    rows.add(tableRow);
    MouseButton mouseButton = extractMouseButton(event.getData());
    getModel().getUIFacade().fireRowClickFromUI(tableRow, mouseButton);
}
Also used : ArrayList(java.util.ArrayList) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) MouseButton(org.eclipse.scout.rt.client.ui.MouseButton)

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