use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.
the class RowsSetViewUpdater method updateView.
private final void updateView(final RowsSetEvent e) {
boolean refreshView = false;
boolean refreshOtherViews = false;
// Acquire services once to avoid performance overhead of repeated lookup
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
final CyColumnIdentifierFactory columnIdentifierFactory = serviceRegistrar.getService(CyColumnIdentifierFactory.class);
final CyNetworkViewManager networkViewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
final VisualMappingManager visualMappingManager = serviceRegistrar.getService(VisualMappingManager.class);
final RenderingEngine<CyNetwork> renderer = applicationManager.getCurrentRenderingEngine();
final CyNetwork network = applicationManager.getCurrentNetwork();
if (network == null)
return;
// 1: Update current network view
final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network);
CyNetworkView networkView = null;
if (views.isEmpty())
return;
else
networkView = views.iterator().next();
final VisualStyle vs = visualMappingManager.getVisualStyle(networkView);
Map<CyRow, View<? extends CyIdentifiable>> rowViewMap = tracker.getRowViewMap(networkView);
for (final RowSetRecord record : e.getPayloadCollection()) {
final CyRow row = record.getRow();
final String columnName = record.getColumn();
final CyColumn column = row.getTable().getColumn(columnName);
if (column == null)
continue;
final VirtualColumnInfo virtualColInfo = column.getVirtualColumnInfo();
final boolean virtual = virtualColInfo.isVirtual();
final View<? extends CyIdentifiable> v = rowViewMap.get(row);
if (v == null)
continue;
if (v.getModel() instanceof CyNode) {
final CyNode node = (CyNode) v.getModel();
if (network.containsNode(node) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
vs.apply(row, v);
refreshView = false;
}
} else if (v.getModel() instanceof CyEdge) {
final CyEdge edge = (CyEdge) v.getModel();
if (network.containsEdge(edge) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
vs.apply(row, v);
refreshView = false;
}
}
// If virtual, it may be used in other networks.
if (refreshView && virtual)
refreshOtherViews = true;
// if (refreshView)
// vs.apply(record.getRow(), (View<? extends CyIdentifiable>) v);
}
if (refreshView) {
vs.apply(networkView);
networkView.updateView();
if (refreshOtherViews) {
// Check other views. If update is required, set the flag.
for (final CyNetworkView view : networkViewManager.getNetworkViewSet()) {
if (view == networkView)
continue;
final VisualStyle style = visualMappingManager.getVisualStyle(view);
if (style == vs) {
// Same style is in use. Need to apply.
netViewMediator.setUpdateFlag(view);
}
}
}
}
}
use of org.cytoscape.model.events.RowSetRecord in project clusterMaker2 by RBVI.
the class TreeView method handleEvent.
public void handleEvent(RowsSetEvent e) {
if (!e.containsColumn(CyNetwork.SELECTED))
return;
if (ignoreSelection) {
return;
}
// System.out.println("Got selection event");
CyTable table = e.getSource();
CyNetwork net = networkTableManager.getNetworkForTable(table);
Class<?> type = networkTableManager.getTableType(table);
if (pendingSelections == null)
pendingSelections = new HashSet<CyIdentifiable>();
if (type.equals(CyNode.class)) {
// if (dataModel.isSymmetrical()) return;
for (RowSetRecord record : e.getColumnRecords(CyNetwork.SELECTED)) {
Long nodeSUID = record.getRow().get(CyIdentifiable.SUID, Long.class);
CyNode node = net.getNode(nodeSUID);
if ((Boolean) record.getValue()) {
if (node != null)
pendingSelections.add(node);
} else if (pendingSelections.contains(node)) {
pendingSelections.remove(node);
}
}
/*
List<CyNode> selectedNodes = CyTableUtil.getNodesInState(net, CyNetwork.SELECTED, true);
setNodeSelection(selectedNodes, true);
*/
} else if (type.equals(CyEdge.class) && dataModel.isSymmetrical()) {
// System.out.println("Edge selection");
for (RowSetRecord record : e.getColumnRecords(CyNetwork.SELECTED)) {
Long edgeSUID = record.getRow().get(CyIdentifiable.SUID, Long.class);
CyEdge edge = net.getEdge(edgeSUID);
if ((Boolean) record.getValue()) {
if (edge != null)
pendingSelections.add(edge);
} else if (pendingSelections.contains(edge)) {
pendingSelections.remove(edge);
}
}
// List<CyEdge> selectedEdges = CyTableUtil.getEdgesInState(net, CyNetwork.SELECTED, true);
// setEdgeSelection(selectedEdges, true);
}
if (selectionTimer == null) {
selectionTimer = new Timer(200, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// System.out.println("Selection Timer fired");
List<CyEdge> edges = new ArrayList<CyEdge>();
List<CyNode> nodes = new ArrayList<CyNode>();
for (CyIdentifiable id : pendingSelections) {
if (CyEdge.class.isAssignableFrom(id.getClass())) {
edges.add((CyEdge) id);
} else if (CyNode.class.isAssignableFrom(id.getClass())) {
nodes.add((CyNode) id);
}
}
if (edges.size() > 0) {
setEdgeSelection(edges, true);
// System.out.println("Selecting "+edges.size()+" edges");
} else {
setNodeSelection(nodes, true);
// System.out.println("Selecting "+nodes.size()+" nodes");
}
// pendingSelections.clear();
}
});
selectionTimer.setCoalesce(true);
selectionTimer.setRepeats(false);
selectionTimer.start();
} else if (selectionTimer.isRunning()) {
// Don't do anything
} else {
selectionTimer.restart();
}
}
use of org.cytoscape.model.events.RowSetRecord in project clusterMaker2 by RBVI.
the class NetworkSelectionLinker method handleEvent.
public void handleEvent(RowsSetEvent e) {
if (!e.containsColumn(CyNetwork.SELECTED) || ignoreSelection)
return;
// System.out.println("Select");
CyNetworkView currentNetworkView = clusterManager.getNetworkView();
ignoreSelection = true;
Map<CyNetwork, Boolean> stateMap = new HashMap<CyNetwork, Boolean>();
for (CySubNetwork subNetwork : rootNetwork.getSubNetworkList()) {
if (e.getSource().equals(subNetwork.getTable(CyNode.class, CyNetwork.LOCAL_ATTRS))) {
for (RowSetRecord record : e.getColumnRecords(CyNetwork.SELECTED)) {
Long suid = record.getRow().get(CyIdentifiable.SUID, Long.class);
Boolean value = (Boolean) record.getValue();
for (CySubNetwork sub2 : rootNetwork.getSubNetworkList()) {
if (subNetwork.equals(sub2) || sub2.getDefaultNodeTable().getRow(suid) == null)
continue;
// System.out.println("Selecting row "+suid);
sub2.getDefaultNodeTable().getRow(suid).set(CyNetwork.SELECTED, value);
}
}
}
if (viewManager.viewExists(subNetwork)) {
for (CyNetworkView view : viewManager.getNetworkViews(subNetwork)) {
if (!view.equals(currentNetworkView)) {
view.updateView();
}
}
}
}
eventHelper.flushPayloadEvents();
ignoreSelection = false;
}
use of org.cytoscape.model.events.RowSetRecord in project cytoscape-api by cytoscape.
the class AbstractViewUpdaterTest method testHandleEvent.
@Test
public void testHandleEvent() {
rows = new ArrayList<RowSetRecord>();
RowSetRecord rec1 = new RowSetRecord(row, "test", value, rawValue);
rows.add(rec1);
RowsSetEvent event = new RowsSetEvent(source, rows);
updater.handleEvent(event);
verify(row, times(0)).getAllValues();
}
use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.
the class CyTableImpl method unSetX.
private void unSetX(final Object key, final String columnName) {
synchronized (lock) {
final String normalizedColName = normalizeColumnName(columnName);
final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
if (virtColumn != null)
virtColumn.setValue(key, null);
else {
final ColumnData keyToValueMap = attributes.get(normalizedColName);
if (!types.containsKey(normalizedColName) || keyToValueMap == null)
throw new IllegalArgumentException("column: '" + columnName + "' does not yet exist.");
final Object value = keyToValueMap.get(key);
if (value == null)
return;
keyToValueMap.remove(key);
}
}
if (fireEvents)
eventHelper.addEventPayload((CyTable) this, new RowSetRecord(getRow(key), columnName, null, null), RowsSetEvent.class);
}
Aggregations