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++;
}
}
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);
}
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);
}
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);
}
}
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;
}
});
}
Aggregations