use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.
the class DGraphView method select.
public void select(Collection<? extends CyIdentifiable> nodesOrEdges, Class<? extends CyIdentifiable> type, boolean selected) {
if (nodesOrEdges.isEmpty())
return;
List<RowSetRecord> records = new ArrayList<>();
CyTable table = type.equals(CyNode.class) ? getModel().getDefaultNodeTable() : getModel().getDefaultEdgeTable();
// Disable events
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.silenceEventSource(table);
try {
for (final CyIdentifiable nodeOrEdge : nodesOrEdges) {
CyRow row = getModel().getRow(nodeOrEdge);
row.set(CyNetwork.SELECTED, selected);
// Add to paylod
records.add(new RowSetRecord(row, CyNetwork.SELECTED, selected, selected));
}
} finally {
eventHelper.unsilenceEventSource(table);
}
// Update the selection before firing the event to prevent race conditions
updateSelection(type, records);
// Only now it can fire the RowsSetEvent
fireRowsSetEvent(table, records, eventHelper);
}
use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.
the class CyTableTest method testSetWithANonEvaluableCompatibleEquation.
@Test
public void testSetWithANonEvaluableCompatibleEquation() {
table.createColumn("strings", String.class, false);
final Map<String, Class<?>> varnameToTypeMap = new HashMap<String, Class<?>>();
varnameToTypeMap.put("a", String.class);
compiler.compile("=$a&\"one\"", varnameToTypeMap);
final Equation eqn = compiler.getEquation();
attrs.set("strings", eqn);
Object last = eventHelper.getLastPayload();
assertNotNull(last);
assertTrue(last instanceof RowSetRecord);
}
use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.
the class CyTableImpl method fireVirtualColumnRowSetEvent.
private void fireVirtualColumnRowSetEvent(CyTableImpl table, Object key, String columnName, Object newValue, Object newRawValue, Set<VirtualColumnInfo> seen) {
// Fire an event for this table
CyRow row = table.getRowNoCreate(key);
if (row == null) {
return;
}
eventHelper.addEventPayload((CyTable) table, new RowSetRecord(row, columnName, newValue, newRawValue), RowsSetEvent.class);
// ...then fire events for all dependents
Set<CyColumn> columnDependents;
synchronized (lock) {
String normalizedColumnName = normalizeColumnName(columnName);
columnDependents = dependents.get(normalizedColumnName);
if (columnDependents == null) {
return;
}
}
for (CyColumn dependent : columnDependents) {
VirtualColumnInfo info = dependent.getVirtualColumnInfo();
if (seen.contains(info)) {
continue;
}
seen.add(info);
CyTableImpl table2 = (CyTableImpl) dependent.getTable();
String targetJoinKey = info.getTargetJoinKey();
if (targetJoinKey.equals(table2.getPrimaryKey().getName())) {
fireVirtualColumnRowSetEvent(table2, key, dependent.getName(), newValue, newRawValue, seen);
} else {
String normalizedTargetJoinKey = table2.normalizeColumnName(targetJoinKey);
ColumnData keyToValueMap = table2.attributes.get(normalizedTargetJoinKey);
if (keyToValueMap != null) {
for (Object key2 : keyToValueMap.keySet()) {
if (keyToValueMap.get(key2).equals(key)) {
fireVirtualColumnRowSetEvent(table2, key2, dependent.getName(), newValue, newRawValue, seen);
}
}
}
}
}
}
use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.
the class CyTableImpl method setListX.
private final void setListX(final Object key, final String columnName, final Object value) {
Object newValue;
final Object rawValue;
synchronized (lock) {
final String normalizedColName = normalizeColumnName(columnName);
final CyColumn column = types.get(normalizedColName);
CyRow row = rows.get(key);
final Class<?> type = column.getListElementType();
if (value instanceof CyListImpl) {
rawValue = value;
} else if (value instanceof List) {
final List list = (List) value;
if (!list.isEmpty())
checkType(list.get(0));
List<?> listData = columnFactory.createList(type, list);
rawValue = new CyListImpl(type, listData, eventHelper, row, column, this);
} else if (!(value instanceof Equation)) {
throw new IllegalArgumentException("value is a " + value.getClass().getName() + " and not a List for column '" + columnName + "'.");
} else if (!EqnSupport.listEquationIsCompatible((Equation) value, type)) {
throw new IllegalArgumentException("value is not a List equation of a compatible type for column '" + columnName + "'.");
} else {
rawValue = value;
}
final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
if (virtColumn != null) {
virtColumn.setValue(key, rawValue);
newValue = virtColumn.getListValue(key);
} else {
ColumnData keyToValueMap = attributes.get(normalizedColName);
// TODO this is an implicit addRow - not sure if we want to refactor this or not
keyToValueMap.put(key, rawValue);
if (rawValue instanceof Equation) {
final StringBuilder errorMsg = new StringBuilder();
newValue = EqnSupport.evalEquation((Equation) rawValue, suid, interpreter, currentlyActiveAttributes, columnName, errorMsg, this);
lastInternalError = errorMsg.toString();
} else {
newValue = rawValue;
}
}
}
if (fireEvents)
eventHelper.addEventPayload((CyTable) this, new RowSetRecord(getRow(key), columnName, newValue, rawValue), RowsSetEvent.class);
}
use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.
the class ControlPanel method handleEvent.
@Override
public void handleEvent(RowsSetEvent e) {
if (loadingSession)
return;
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final CyNetworkView currentView = appMgr.getCurrentNetworkView();
if (currentView == null)
return;
final CyTable tbl = e.getSource();
final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
final CyNetwork net = netTblMgr.getNetworkForTable(tbl);
if (net == null || !net.equals(currentView.getModel()) || !tbl.equals(net.getDefaultNodeTable()))
return;
final Collection<RowSetRecord> selectedRecords = e.getColumnRecords(CyNetwork.SELECTED);
if (!selectedRecords.isEmpty())
updatePanels();
}
Aggregations