use of org.cytoscape.model.events.RowsDeletedEvent in project cytoscape-impl by cytoscape.
the class CyTableImpl method deleteRows.
@Override
public boolean deleteRows(final Collection<?> primaryKeys) {
boolean changed = false;
synchronized (lock) {
// collect the attribute maps for the columns, faster to normalize column names outside the main loop
Collection<CyColumn> columns = getColumns();
List<ColumnData> attributeMaps = new ArrayList<>(columns.size());
for (CyColumn col : columns) {
final String normalizedColName = normalizeColumnName(col.getName());
final ColumnData keyToValueMap = attributes.get(normalizedColName);
if (keyToValueMap != null) {
attributeMaps.add(keyToValueMap);
}
}
// batch remove from rowList for performance
Set<CyRow> rowsToRemoveFromList = new HashSet<>();
// main loop
for (Object key : primaryKeys) {
checkKey(key);
CyRow row = rows.remove(key);
if (row != null) {
rowsToRemoveFromList.add(row);
for (ColumnData keyToValueMap : attributeMaps) {
keyToValueMap.remove(key);
}
changed = true;
}
}
rowList.removeAll(rowsToRemoveFromList);
}
if (changed)
eventHelper.fireEvent(new RowsDeletedEvent(this, (Collection<Object>) primaryKeys));
return changed;
}
Aggregations