use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CyNetworkAutoDeleteTest method testUndoDeletedNodeAndEdge.
@Test
public void testUndoDeletedNodeAndEdge() {
final String TEST_COLUMN = "testColumn";
CyNetwork network1 = TestCyNetworkFactory.getInstance();
CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
CyNode n1 = network1.addNode();
CyNode n2 = network1.addNode();
CyNode n3 = network1.addNode();
CyEdge e1 = network1.addEdge(n1, n2, false);
CyEdge e2 = network1.addEdge(n2, n3, false);
CyTable defaultNodeTable = network1.getDefaultNodeTable();
defaultNodeTable.createColumn(TEST_COLUMN, String.class, false);
CyTable defaultEdgeTable = network1.getDefaultEdgeTable();
defaultEdgeTable.createColumn(TEST_COLUMN, String.class, false);
network1.getRow(n1).set(TEST_COLUMN, "my node 1");
network1.getRow(e1).set(TEST_COLUMN, "my edge 1");
CyNetwork network2 = rootNetwork.addSubNetwork(Arrays.asList(n1, n2, n3), Arrays.asList(e1, e2));
network1.removeNodes(Collections.singleton(n1));
network2.removeNodes(Collections.singleton(n1));
assertFalse(rootNetwork.containsNode(n1));
assertFalse(network1.containsNode(n1));
assertFalse(network2.containsNode(n1));
assertFalse(rootNetwork.containsEdge(e1));
assertFalse(network1.containsEdge(e1));
assertFalse(network2.containsEdge(e1));
// restore the node to network1
((CySubNetwork) network1).addNode(n1);
assertTrue(rootNetwork.containsNode(n1));
assertTrue(network1.containsNode(n1));
assertFalse(network2.containsNode(n1));
assertFalse(rootNetwork.containsEdge(e1));
assertFalse(network1.containsEdge(e1));
assertFalse(network2.containsEdge(e1));
((CySubNetwork) network1).addEdge(e1);
assertTrue(rootNetwork.containsNode(n1));
assertTrue(network1.containsNode(n1));
assertFalse(network2.containsNode(n1));
assertTrue(rootNetwork.containsEdge(e1));
assertTrue(network1.containsEdge(e1));
assertFalse(network2.containsEdge(e1));
// test that the attributes are restored
assertEquals("my node 1", rootNetwork.getRow(n1).get(TEST_COLUMN, String.class));
assertEquals("my edge 1", rootNetwork.getRow(e1).get(TEST_COLUMN, String.class));
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CyNetworkAutoDeleteTest method testRestoreBug3838_1.
@Test
public void testRestoreBug3838_1() {
CyNetwork network1 = TestCyNetworkFactory.getInstance();
CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
CyNode n1 = network1.addNode();
CyNode n2 = network1.addNode();
CyEdge e1 = network1.addEdge(n1, n2, false);
network1.removeEdges(Arrays.asList(e1));
assertTrue(rootNetwork.containsNode(n1));
assertTrue(rootNetwork.containsNode(n2));
assertFalse(rootNetwork.containsEdge(e1));
assertTrue(network1.containsNode(n1));
assertTrue(network1.containsNode(n2));
assertFalse(network1.containsEdge(e1));
rootNetwork.restoreEdge(e1);
assertTrue(rootNetwork.containsNode(n1));
assertTrue(rootNetwork.containsNode(n2));
assertTrue(rootNetwork.containsEdge(e1));
assertTrue(network1.containsNode(n1));
assertTrue(network1.containsNode(n2));
assertFalse(network1.containsEdge(e1));
network1.removeNodes(Arrays.asList(n1));
assertFalse(rootNetwork.containsNode(n1));
assertTrue(rootNetwork.containsNode(n2));
assertFalse(rootNetwork.containsEdge(e1));
assertFalse(network1.containsNode(n1));
assertTrue(network1.containsNode(n2));
assertFalse(network1.containsEdge(e1));
rootNetwork.restoreEdge(e1);
assertTrue(rootNetwork.containsEdge(e1));
assertTrue(rootNetwork.containsNode(n1));
assertTrue(rootNetwork.containsNode(n2));
assertFalse(network1.containsNode(n1));
assertTrue(network1.containsNode(n2));
assertFalse(network1.containsEdge(e1));
CyRow row = rootNetwork.getDefaultEdgeTable().getRow(e1.getSUID());
assertNotNull(row);
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class TableBrowserToolBar method createNewAttribute.
private void createNewAttribute(final String type, boolean isShared) {
try {
final String[] existingAttrs = getAttributeArray();
String newAttribName = null;
do {
newAttribName = JOptionPane.showInputDialog(this, "Column Name: ", "Create New " + type + " Column", JOptionPane.QUESTION_MESSAGE);
if (newAttribName == null)
return;
newAttribName = newAttribName.trim();
if (newAttribName.isEmpty()) {
JOptionPane.showMessageDialog(null, "Column name must not be blank.", "Error", JOptionPane.ERROR_MESSAGE);
newAttribName = null;
} else if (Arrays.binarySearch(existingAttrs, newAttribName) >= 0) {
JOptionPane.showMessageDialog(null, "Column " + newAttribName + " already exists.", "Error", JOptionPane.ERROR_MESSAGE);
newAttribName = null;
}
} while (newAttribName == null);
final CyTable attrs;
if (isShared) {
final CyNetwork network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
if (network instanceof CySubNetwork) {
final CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
CyTable sharedTable = null;
if (this.objType == CyNode.class)
sharedTable = rootNetwork.getSharedNodeTable();
else if (this.objType == CyEdge.class)
sharedTable = rootNetwork.getSharedEdgeTable();
else if (this.objType == CyNetwork.class)
sharedTable = rootNetwork.getSharedNetworkTable();
else
throw new IllegalStateException("Object type is not valid. This should not happen.");
attrs = sharedTable;
} else {
throw new IllegalArgumentException("This is not a CySubNetwork and there is no shared table.");
}
} else {
attrs = browserTableModel.getDataTable();
}
if (type.equals("String"))
attrs.createColumn(newAttribName, String.class, false);
else if (type.equals("Floating Point"))
attrs.createColumn(newAttribName, Double.class, false);
else if (type.equals("Integer"))
attrs.createColumn(newAttribName, Integer.class, false);
else if (type.equals("Long Integer"))
attrs.createColumn(newAttribName, Long.class, false);
else if (type.equals("Boolean"))
attrs.createColumn(newAttribName, Boolean.class, false);
else if (type.equals("String List"))
attrs.createListColumn(newAttribName, String.class, false);
else if (type.equals("Floating Point List"))
attrs.createListColumn(newAttribName, Double.class, false);
else if (type.equals("Integer List"))
attrs.createListColumn(newAttribName, Integer.class, false);
else if (type.equals("Long Integer List"))
attrs.createListColumn(newAttribName, Long.class, false);
else if (type.equals("Boolean List"))
attrs.createListColumn(newAttribName, Boolean.class, false);
else
throw new IllegalArgumentException("unknown column type \"" + type + "\".");
} catch (IllegalArgumentException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CyRootNetworkImpl method removeNodes.
@Override
public boolean removeNodes(final Collection<CyNode> nodes) {
synchronized (lock) {
boolean removed = false;
for (CySubNetwork sub : subNetworks) {
removed |= sub.removeNodes(nodes);
if (nodes != null && sub instanceof CySubNetworkImpl)
((CySubNetworkImpl) sub).removeRows(nodes, CyNode.class);
}
// Explicitly removing from the root network removes from the cache
if (nodes != null) {
for (CyNode node : nodes) {
removedAttributesCache.evict(node);
}
}
// Do we want to do this????? (MK: yes I think so)
this.removeRows(nodes, CyNode.class);
removed |= removeNodesInternal(nodes);
return removed;
}
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CyTableManagerImpl method getLocalTables.
@Override
public Set<CyTable> getLocalTables(final Class<? extends CyIdentifiable> type) {
final Set<CyTable> localTables = new HashSet<CyTable>();
final Set<CyNetwork> networks = networkManager.getNetworkSet();
for (final CyNetwork network : networks) {
final Map<String, CyTable> objTables = networkTableManager.getTables(network, type);
if (network instanceof CySubNetwork) {
final CyTable shared = networkTableManager.getTable(((CySubNetwork) network).getRootNetwork(), type, CyRootNetwork.SHARED_ATTRS);
localTables.add(shared);
}
localTables.addAll(objTables.values());
}
return localTables;
}
Aggregations