Search in sources :

Example 76 with ITableRow

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

the class JsonTable method preprocessBufferedEvents.

protected void preprocessBufferedEvents() {
    List<TableEvent> bufferInternal = m_eventBuffer.getBufferInternal();
    for (int i = 0; i < bufferInternal.size(); i++) {
        TableEvent event = bufferInternal.get(i);
        if (event.getType() != TableEvent.TYPE_ROW_FILTER_CHANGED) {
            continue;
        }
        // Convert the "filter changed" event to a ROWS_DELETED and a ROWS_INSERTED event. This prevents sending unnecessary
        // data to the UI. We convert the event before adding it to the event buffer to allow coalescing on UI-level.
        // NOTE: This may lead to a temporary inconsistent situation, where row events exist in the buffer after the
        // row itself is deleted. This is because the row is not really deleted from the model. However, when processing
        // the buffered events, the "wrong" events will be ignored and everything is fixed again.
        List<ITableRow> rowsToInsert = new ArrayList<>();
        List<ITableRow> rowsToDelete = new ArrayList<>();
        for (ITableRow row : getModel().getRows()) {
            String existingRowId = getTableRowId(row);
            if (row.isFilterAccepted()) {
                if (existingRowId == null) {
                    // Row is not filtered but JsonTable does not know it yet --> handle as insertion event
                    rowsToInsert.add(row);
                }
            } else if (!row.isRejectedByUser() && existingRowId != null) {
                // Row is filtered, but JsonTable has it in its list --> handle as deletion event
                rowsToDelete.add(row);
            }
        }
        // Put at the same position as the row_filter_changed event (replace it) to keep the order of multiple insert events
        bufferInternal.set(i, new TableEvent(getModel(), TableEvent.TYPE_ROWS_INSERTED, rowsToInsert));
        if (!rowsToInsert.isEmpty()) {
            // Generate an artificial "row order changed" event so that the inserted rows are at the correct position in the UI
            bufferInternal.add(i + 1, new TableEvent(getModel(), TableEvent.TYPE_ROW_ORDER_CHANGED, getModel().getRows()));
        }
        // Make sure no previous event contains the newly inserted rows
        for (int j = i - 1; j >= 0; j--) {
            bufferInternal.get(j).removeRows(rowsToInsert);
        }
        // Put at the beginning to make sure no subsequent event contains the deleted row
        bufferInternal.add(0, new TableEvent(getModel(), TableEvent.TYPE_ROWS_DELETED, rowsToDelete));
        // NOSONAR
        i++;
    }
}
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 77 with ITableRow

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

the class JsonTable method handleModelRowsDeleted.

protected void handleModelRowsDeleted(Collection<ITableRow> modelRows) {
    if (modelRows.isEmpty()) {
        return;
    }
    if (getFilteredRowCount() == 0) {
        handleModelAllRowsDeleted();
        return;
    }
    JSONArray jsonRowIds = new JSONArray();
    for (ITableRow row : modelRows) {
        String rowId = getTableRowId(row);
        if (rowId == null) {
            // Ignore rows that are not yet sent to the UI (may happen when a filtered row is deleted)
            continue;
        }
        jsonRowIds.put(rowId);
        disposeRow(row);
    }
    if (jsonRowIds.length() == 0) {
        return;
    }
    JSONObject jsonEvent = new JSONObject();
    jsonEvent.put(PROP_ROW_IDS, jsonRowIds);
    addActionEvent(EVENT_ROWS_DELETED, jsonEvent);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 78 with ITableRow

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

the class JsonTable method handleModelRowOrderChanged.

protected void handleModelRowOrderChanged(Collection<ITableRow> modelRows) {
    JSONArray jsonRowIds = new JSONArray();
    List<String> rowIds = new ArrayList<>();
    for (ITableRow row : modelRows) {
        if (isRowAccepted(row)) {
            String rowId = getTableRowId(row);
            jsonRowIds.put(rowId);
            rowIds.add(rowId);
        }
    }
    if (jsonRowIds.length() < m_tableRows.size()) {
        // Append missing rows to the end, otherwise the UI cannot not update the order.
        // This may happen if rows are deleted after a row order change.
        // In that case rows are deleted anyway so it is fine if they are not ordered correctly
        List<String> missingRowIds = new ArrayList<String>(m_tableRows.keySet());
        missingRowIds.removeAll(rowIds);
        for (String id : missingRowIds) {
            jsonRowIds.put(id);
        }
    }
    if (jsonRowIds.length() == 0) {
        return;
    }
    JSONObject jsonEvent = new JSONObject();
    putProperty(jsonEvent, PROP_ROW_IDS, jsonRowIds);
    addActionEvent("rowOrderChanged", jsonEvent);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 79 with ITableRow

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

the class JsonTable method consumeBinaryResource.

@Override
public void consumeBinaryResource(List<BinaryResource> binaryResources, Map<String, String> uploadProperties) {
    if ((getModel().getDropType() & IDNDSupport.TYPE_FILE_TRANSFER) == IDNDSupport.TYPE_FILE_TRANSFER) {
        ResourceListTransferObject transferObject = new ResourceListTransferObject(binaryResources);
        ITableRow row = null;
        if (uploadProperties != null && uploadProperties.containsKey("rowId")) {
            String rowId = uploadProperties.get("rowId");
            if (!StringUtility.isNullOrEmpty(rowId)) {
                row = getTableRow(rowId);
            }
        }
        getModel().getUIFacade().fireRowDropActionFromUI(row, transferObject);
    }
}
Also used : ResourceListTransferObject(org.eclipse.scout.rt.client.ui.dnd.ResourceListTransferObject) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 80 with ITableRow

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

the class TableContextMenu method calculateEnableState.

/**
 * @param ownerValue
 */
protected void calculateEnableState(List<? extends ITableRow> ownerValue) {
    boolean enabled = getContainer().isEnabled();
    if (enabled) {
        for (ITableRow row : ownerValue) {
            if (!row.isEnabled()) {
                enabled = false;
                break;
            }
        }
    }
    final boolean inheritedEnability = enabled;
    acceptVisitor(new IActionVisitor() {

        @Override
        public int visit(IAction action) {
            if (action instanceof IMenu) {
                IMenu menu = (IMenu) action;
                if (!menu.hasChildActions() && menu.isInheritAccessibility()) {
                    menu.setEnabledInheritAccessibility(inheritedEnability);
                }
            }
            return CONTINUE;
        }
    });
}
Also used : IActionVisitor(org.eclipse.scout.rt.client.ui.action.IActionVisitor) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction) 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