use of org.cytoscape.model.events.NetworkAddedEvent in project cytoscape-impl by cytoscape.
the class MergeDataTableTaskTest method mappingToAllNetworksWithSubNetwork.
@Test
public void mappingToAllNetworksWithSubNetwork() throws Exception {
// set up tunable mutator
stm.addTunableHandlerFactory(syncTunableHandlerFactory, syncFactoryProp);
CyNetwork net1;
CyNetwork subnet1;
CyNetwork subnet2;
String node1Name = "node1";
String node2Name = "node2";
String row1Name = "node1";
String row2Name = "node2";
CyTableImpl table1;
CyTableImpl table2;
CyTableImpl table3;
CyTableImpl table4;
String table1sCol = "col1";
String table2sCol = "col2";
String table3sCol = "col3";
String table4sCol = "col4";
String table1sRow1 = "col1 row1";
String table1sRow2 = "col1 row2";
String table2sRow1 = "col2 row1";
String table2sRow2 = "col2 row2";
String table3sRow1 = "col3 row1";
String table3sRow2 = "col3 row2";
String table4sRow1 = "col4 row1";
String table4sRow2 = "col4 row2";
// creating first network with 2 nodes
net1 = support.getNetwork();
net1.getRow(net1).set(CyNetwork.NAME, "net1");
final CyNode node1 = net1.addNode();
final CyNode node2 = net1.addNode();
net1.addEdge(node1, node2, true);
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.NAME, node1Name);
net1.getDefaultNodeTable().getRow(node2.getSUID()).set(CyNetwork.NAME, node2Name);
netMgr.addNetwork(net1);
((CySubNetworkImpl) net1).handleEvent(new NetworkAddedEvent(netMgr, net1));
List<CyNetwork> firstnetlist = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
// creating a table for mapping to all networks
table1 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table1.createColumn(table1sCol, String.class, false);
CyRow row1 = table1.getRow(node1Name);
row1.set(table1sCol, table1sRow1);
CyRow row2 = table1.getRow(node2Name);
row2.set(table1sCol, table1sRow2);
root = rootNetMgr.getRootNetwork(net1);
List<String> listCols = new ArrayList<String>();
listCols.add(table1sCol);
mapping(table1, listCols, "ID", true, net1, root, root.getDefaultNodeTable().getColumn(CyRootNetwork.SHARED_NAME), false);
// check the mapping by task
assertNotNull(net1.getDefaultNodeTable().getColumn(table1sCol));
assertEquals(table1sRow1, net1.getDefaultNodeTable().getRow(node1.getSUID()).get(table1sCol, String.class));
// creating a sub network to check if gets updated or not
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.SELECTED, true);
net1.getDefaultNodeTable().getRow(node2.getSUID()).set(CyNetwork.SELECTED, true);
NewNetworkSelectedNodesOnlyTask newNetTask = new NewNetworkSelectedNodesOnlyTask(mock(UndoSupport.class), net1, support.getRootNetworkFactory(), viewSupport.getNetworkViewFactory(), netMgr, mock(CyNetworkViewManager.class), mock(CyNetworkNaming.class), mock(VisualMappingManager.class), mock(CyApplicationManager.class), eventHelper, groupMgr, renderingEngineManager, mock(CyServiceRegistrar.class));
assertNotNull(newNetTask);
newNetTask.setTaskIterator(new TaskIterator(newNetTask));
newNetTask.run(mock(TaskMonitor.class));
List<CyNetwork> secondNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
secondNetList.removeAll(firstnetlist);
assertEquals(1, secondNetList.size());
subnet1 = secondNetList.get(0);
secondNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
((CySubNetworkImpl) subnet1).handleEvent(new NetworkAddedEvent(netMgr, subnet1));
assertEquals(2, subnet1.getNodeList().size());
assertNotNull(subnet1.getDefaultNodeTable().getColumn(table1sCol));
// these two tests are failing because the required table update when creating the subnetwork is not handled
// hence the nodes are there but the related rows in the table are empty
assertEquals(table1sRow1, subnet1.getRow(node1).get(table1sCol, String.class));
// creating another table to map to the net1 only
table2 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table2.createColumn(table2sCol, String.class, false);
CyRow row3 = table2.getRow(node1Name);
row3.set(table2sCol, table2sRow1);
CyRow row4 = table2.getRow(node2Name);
row4.set(table2sCol, table2sRow2);
root = rootNetMgr.getRootNetwork(net1);
listCols = new ArrayList<String>();
listCols.add(table2sCol);
mapping(table2, listCols, "ID", true, net1, root, root.getDefaultNodeTable().getColumn(CyRootNetwork.SHARED_NAME), true);
// check the mapping by task
assertNotNull(net1.getDefaultNodeTable().getColumn(table2sCol));
assertEquals(table2sRow1, net1.getDefaultNodeTable().getRow(node1.getSUID()).get(table2sCol, String.class));
// subnet1 should not be mapped
assertNull(subnet1.getDefaultNodeTable().getColumn(table2sCol));
// creating another subnetwork (subnet2) to check that bot virtual columns will be added
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.SELECTED, true);
NewNetworkSelectedNodesOnlyTask newNetTask2 = new NewNetworkSelectedNodesOnlyTask(mock(UndoSupport.class), net1, support.getRootNetworkFactory(), viewSupport.getNetworkViewFactory(), netMgr, mock(CyNetworkViewManager.class), mock(CyNetworkNaming.class), mock(VisualMappingManager.class), mock(CyApplicationManager.class), eventHelper, groupMgr, renderingEngineManager, mock(CyServiceRegistrar.class));
assertNotNull(newNetTask2);
newNetTask2.setTaskIterator(new TaskIterator(newNetTask2));
newNetTask2.run(mock(TaskMonitor.class));
List<CyNetwork> thirdNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
thirdNetList.removeAll(secondNetList);
assertEquals(1, thirdNetList.size());
subnet2 = thirdNetList.get(0);
((CySubNetworkImpl) subnet2).handleEvent(new NetworkAddedEvent(netMgr, subnet2));
assertEquals(2, subnet2.getNodeList().size());
// check that the new subnetwork has both columns
assertNotNull(subnet2.getDefaultNodeTable().getColumn(table1sCol));
assertNotNull(subnet2.getDefaultNodeTable().getColumn(table2sCol));
// these two tests are failing because the required table update when creating the subnetwork is not handled
// hence the nodes are there but the related rows in the table are empty
assertEquals(table1sRow1, subnet2.getRow(node1).get(table1sCol, String.class));
assertEquals(table2sRow1, subnet2.getRow(node1).get(table2sCol, String.class));
// creating another table to map to the net1 only
table3 = new CyTableImpl("dummy table 3", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table3.createColumn(table2sCol, String.class, false);
table3.createColumn(table3sCol, String.class, false);
CyRow rowTemp;
rowTemp = table3.getRow(row1Name);
rowTemp.set(table2sCol, table2sRow1);
rowTemp.set(table3sCol, table3sRow1);
rowTemp = table3.getRow(row2Name);
rowTemp.set(table2sCol, table2sRow2);
rowTemp.set(table3sCol, table3sRow2);
table4 = new CyTableImpl("dummy table 4", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table4.createColumn(table2sCol, String.class, false);
table4.createColumn(table4sCol, String.class, false);
rowTemp = table4.getRow(row1Name);
rowTemp.set(table2sCol, table2sRow1);
rowTemp.set(table4sCol, table4sRow1);
rowTemp = table4.getRow(row2Name);
rowTemp.set(table2sCol, table2sRow2);
rowTemp.set(table4sCol, table4sRow2);
tableMgr.addTable(table3);
tableMgr.addTable(table4);
List<String> listCols2 = new ArrayList<String>();
listCols2.add(table3sCol);
mappingGlobalTable(table3, table4, listCols2, table2sCol, false, null, null, table4.getColumn(table2sCol), false);
assertEquals(table3sRow1, table4.getRow(row1Name).get(table3sCol, String.class));
assertEquals(table3sRow2, table4.getRow(row2Name).get(table3sCol, String.class));
}
use of org.cytoscape.model.events.NetworkAddedEvent in project cytoscape-impl by cytoscape.
the class CySubNetworkTest method testAddExistingNodeEventAfterNetworkAdd.
@Test
public void testAddExistingNodeEventAfterNetworkAdd() {
CyNode rn1 = root.addNode();
CySubNetwork sub = root.addSubNetwork();
((CySubNetworkImpl) sub).handleEvent(new NetworkAddedEvent(mock(CyNetworkManager.class), sub));
sub.addNode(rn1);
Object payload = deh.getLastPayload();
assertNotNull(payload);
}
use of org.cytoscape.model.events.NetworkAddedEvent in project cytoscape-impl by cytoscape.
the class MappingIntegrationTest method mappingToAllNetworksWithSubNetwork.
@Test
public void mappingToAllNetworksWithSubNetwork() throws Exception {
// set up tunable mutator
stm.addTunableHandlerFactory(syncTunableHandlerFactory, syncFactoryProp);
CyNetwork net1;
CyNetwork subnet1;
CyNetwork subnet2;
String node1Name = "node1";
String node2Name = "node2";
CyTableImpl table1;
CyTableImpl table2;
String table1sCol = "col1";
String table2sCol = "col2";
String table1sRow1 = "col1 row1";
String table1sRow2 = "col1 row2";
String table2sRow1 = "col2 row2";
String table2sRow2 = "col2 row2";
// creating first network with 2 nodes
net1 = support.getNetwork();
net1.getRow(net1).set(CyNetwork.NAME, "net1");
final CyNode node1 = net1.addNode();
final CyNode node2 = net1.addNode();
net1.addEdge(node1, node2, true);
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.NAME, node1Name);
net1.getDefaultNodeTable().getRow(node2.getSUID()).set(CyNetwork.NAME, node2Name);
netMgr.addNetwork(net1);
((CySubNetworkImpl) net1).handleEvent(new NetworkAddedEvent(netMgr, net1));
List<CyNetwork> firstnetlist = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
// creating a table for mapping to all networks
table1 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table1.createColumn(table1sCol, String.class, false);
CyRow row1 = table1.getRow(node1Name);
row1.set(table1sCol, table1sRow1);
CyRow row2 = table1.getRow(node2Name);
row2.set(table1sCol, table1sRow2);
root = rootNetMgr.getRootNetwork(net1);
mapping(table1, net1, root, root.getDefaultNodeTable().getColumn(CyRootNetwork.SHARED_NAME), false);
// check the mapping by task
assertNotNull(net1.getDefaultNodeTable().getColumn(table1sCol));
assertEquals(table1sRow1, net1.getDefaultNodeTable().getRow(node1.getSUID()).get(table1sCol, String.class));
// creating a sub network to check if gets updated or not
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.SELECTED, true);
net1.getDefaultNodeTable().getRow(node2.getSUID()).set(CyNetwork.SELECTED, true);
NewNetworkSelectedNodesOnlyTask newNetTask = new NewNetworkSelectedNodesOnlyTask(mock(UndoSupport.class), net1, support.getRootNetworkFactory(), viewSupport.getNetworkViewFactory(), netMgr, mock(CyNetworkViewManager.class), mock(CyNetworkNaming.class), mock(VisualMappingManager.class), mock(CyApplicationManager.class), eventHelper, groupMgr, renderingEngineManager, mock(CyServiceRegistrar.class));
assertNotNull(newNetTask);
newNetTask.setTaskIterator(new TaskIterator(newNetTask));
newNetTask.run(mock(TaskMonitor.class));
List<CyNetwork> secondNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
secondNetList.removeAll(firstnetlist);
assertEquals(1, secondNetList.size());
subnet1 = secondNetList.get(0);
secondNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
((CySubNetworkImpl) subnet1).handleEvent(new NetworkAddedEvent(netMgr, subnet1));
assertEquals(2, subnet1.getNodeList().size());
assertNotNull(subnet1.getDefaultNodeTable().getColumn(table1sCol));
// these two tests are failing because the required table update when creating the subnetwork is not handled
// hence the nodes are there but the related rows in the table are empty
assertEquals(table1sRow1, subnet1.getRow(node1).get(table1sCol, String.class));
// creating another table to map to the net1 only
table2 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table2.createColumn(table2sCol, String.class, false);
CyRow row3 = table2.getRow(node1Name);
row3.set(table2sCol, table2sRow1);
CyRow row4 = table2.getRow(node2Name);
row4.set(table2sCol, table2sRow2);
root = rootNetMgr.getRootNetwork(net1);
mapping(table2, net1, root, root.getDefaultNodeTable().getColumn(CyRootNetwork.SHARED_NAME), true);
// check the mapping by task
assertNotNull(net1.getDefaultNodeTable().getColumn(table2sCol));
assertEquals(table2sRow1, net1.getDefaultNodeTable().getRow(node1.getSUID()).get(table2sCol, String.class));
// subnet1 should not be mapped
assertNull(subnet1.getDefaultNodeTable().getColumn(table2sCol));
// creating another subnetwork (subnet2) to check that bot virtual columns will be added
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.SELECTED, true);
NewNetworkSelectedNodesOnlyTask newNetTask2 = new NewNetworkSelectedNodesOnlyTask(mock(UndoSupport.class), net1, support.getRootNetworkFactory(), viewSupport.getNetworkViewFactory(), netMgr, mock(CyNetworkViewManager.class), mock(CyNetworkNaming.class), mock(VisualMappingManager.class), mock(CyApplicationManager.class), eventHelper, groupMgr, renderingEngineManager, mock(CyServiceRegistrar.class));
assertNotNull(newNetTask2);
newNetTask2.setTaskIterator(new TaskIterator(newNetTask2));
newNetTask2.run(mock(TaskMonitor.class));
List<CyNetwork> thirdNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
thirdNetList.removeAll(secondNetList);
assertEquals(1, thirdNetList.size());
subnet2 = thirdNetList.get(0);
((CySubNetworkImpl) subnet2).handleEvent(new NetworkAddedEvent(netMgr, subnet2));
assertEquals(2, subnet2.getNodeList().size());
// check that the new subnetwork has both columns
assertNotNull(subnet2.getDefaultNodeTable().getColumn(table1sCol));
assertNotNull(subnet2.getDefaultNodeTable().getColumn(table2sCol));
// these two tests are failing because the required table update when creating the subnetwork is not handled
// hence the nodes are there but the related rows in the table are empty
assertEquals(table1sRow1, subnet2.getRow(node1).get(table1sCol, String.class));
assertEquals(table2sRow1, subnet2.getRow(node1).get(table2sCol, String.class));
}
use of org.cytoscape.model.events.NetworkAddedEvent in project cytoscape-impl by cytoscape.
the class CyNetworkManagerImpl method addNetwork.
@Override
public void addNetwork(final CyNetwork network, final boolean setCurrent) {
if (network == null)
throw new NullPointerException("Network is null");
synchronized (lock) {
logger.debug("Adding new Network Model: Model ID = " + network.getSUID());
// Make sure the network has a name
final CyRow row = network.getRow(network);
final String name = row.get(CyNetwork.NAME, String.class);
final String sharedName = row.get(CyRootNetwork.SHARED_NAME, String.class);
if (name != null && !name.trim().isEmpty() && (sharedName == null || sharedName.trim().isEmpty())) {
row.set(CyRootNetwork.SHARED_NAME, name);
} else if (sharedName != null && !sharedName.trim().isEmpty() && (name == null || name.trim().isEmpty())) {
row.set(CyNetwork.NAME, sharedName);
} else if ((sharedName == null || sharedName.trim().isEmpty()) && (name == null || name.trim().isEmpty())) {
final CyNetworkNaming namingUtil = serviceRegistrar.getService(CyNetworkNaming.class);
final String newName = namingUtil.getSuggestedNetworkTitle("Network");
row.set(CyNetwork.NAME, newName);
row.set(CyRootNetwork.SHARED_NAME, newName);
}
// Add the new network to the internal map
networkMap.put(network.getSUID(), network);
}
final CyEventHelper cyEventHelper = serviceRegistrar.getService(CyEventHelper.class);
cyEventHelper.fireEvent(new NetworkAddedEvent(CyNetworkManagerImpl.this, network));
if (setCurrent) {
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
if (// It may be null when running unit tests
applicationManager != null)
applicationManager.setCurrentNetwork(network);
}
}
use of org.cytoscape.model.events.NetworkAddedEvent in project cytoscape-impl by cytoscape.
the class CySubNetworkTest method testAddExistingEdgeEventAfterNetworkAdd.
@Test
public void testAddExistingEdgeEventAfterNetworkAdd() {
CyNode nx1 = root.addNode();
CyNode nx2 = root.addNode();
CyEdge ex1 = root.addEdge(nx1, nx2, false);
CySubNetwork sub = root.addSubNetwork();
sub.addNode(nx1);
sub.addNode(nx2);
((CySubNetworkImpl) sub).handleEvent(new NetworkAddedEvent(mock(CyNetworkManager.class), sub));
sub.addEdge(ex1);
Object payload = deh.getLastPayload();
assertNotNull(payload);
}
Aggregations