use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.
the class LayoutEdgeTest method testLayoutEdgeConstructor2.
@Test
public void testLayoutEdgeConstructor2() {
CyNetworkFactory nFactory = support.getNetworkFactory();
CyNetwork newNetwork = nFactory.createNetwork();
CyNode s = newNetwork.addNode();
CyNode t = newNetwork.addNode();
CyEdge e = newNetwork.addEdge(s, t, true);
final CyNetworkViewFactory viewFactory = support.getNetworkViewFactory();
CyNetworkView newView = viewFactory.createNetworkView(newNetwork);
final View<CyNode> sourceView = newView.getNodeView(s);
final View<CyNode> targetView = newView.getNodeView(t);
assertNotNull(sourceView);
assertNotNull(targetView);
CyRow sRow = newNetwork.getRow(s);
CyRow tRow = newNetwork.getRow(t);
final LayoutNode layoutNodeS = new LayoutNode(sourceView, 0, sRow);
final LayoutNode layoutNodeT = new LayoutNode(targetView, 1, tRow);
final LayoutEdge layoutEdge2 = new LayoutEdge(e, layoutNodeS, layoutNodeT, newNetwork.getRow(e));
assertNotNull(layoutEdge2);
}
use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.
the class PartitionUtilTest method testPartition.
@Test
public void testPartition() {
NetworkViewTestSupport networkSupport = new NetworkViewTestSupport();
CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
{
// Partition 1
CyNode n1 = network.addNode();
CyNode n2 = network.addNode();
CyNode n3 = network.addNode();
CyNode n4 = network.addNode();
network.addEdge(n1, n2, false);
network.addEdge(n2, n3, false);
network.addEdge(n3, n4, false);
}
{
// Partition 2
CyNode n1 = network.addNode();
CyNode n2 = network.addNode();
CyNode n3 = network.addNode();
CyNode n4 = network.addNode();
network.addEdge(n1, n2, false);
network.addEdge(n2, n3, false);
network.addEdge(n3, n4, false);
// cycle
network.addEdge(n4, n1, false);
}
{
// Partition 3
CyNode n1 = network.addNode();
CyNode n2 = network.addNode();
CyNode n3 = network.addNode();
CyNode n4 = network.addNode();
network.addEdge(n1, n2, true);
network.addEdge(n1, n3, true);
network.addEdge(n1, n4, true);
network.addEdge(n2, n3, true);
network.addEdge(n3, n4, true);
network.addEdge(n4, n1, true);
}
CyNetworkView networkView = networkSupport.getNetworkViewFactory().createNetworkView(network);
EdgeWeighter edgeWeighter = new EdgeWeighter();
List<LayoutPartition> result = PartitionUtil.partition(networkView, false, edgeWeighter);
assertNotNull(result);
assertEquals(3, result.size());
}
use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.
the class ImportTablePanel method attributeRadioButtonActionPerformed.
private void attributeRadioButtonActionPerformed(ActionEvent evt) {
final CyNetwork network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
if (nodeRadioButton.isSelected()) {
if (network != null)
selectedAttributes = network.getDefaultNodeTable();
objType = NODE;
} else if (edgeRadioButton.isSelected()) {
if (network != null)
selectedAttributes = network.getDefaultEdgeTable();
objType = EDGE;
} else {
logger.info("\nNote: ImportTextTableFDialog.attributeRadioButtonActionPerformed():Import network table not implemented yet!\n");
objType = NETWORK;
}
updateMappingAttributeComboBox();
setKeyList();
}
use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.
the class PopupMenuHelper method selectElementsFromSelectedRows.
private void selectElementsFromSelectedRows(final JTable table, final Class<? extends CyIdentifiable> tableType) {
final Thread t = new Thread() {
@Override
public void run() {
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
final CyNetwork net = applicationManager.getCurrentNetwork();
if (net != null) {
final BrowserTableModel tableModel = (BrowserTableModel) table.getModel();
final int[] selectedRows = table.getSelectedRows();
final Set<CyRow> targetRows = new HashSet<CyRow>();
for (final int rowIndex : selectedRows) {
// Getting the row from data table solves the problem with hidden or moved SUID column.
// However, since the rows might be sorted we need to convert the index to model.
final ValidatedObjectAndEditString selected = (ValidatedObjectAndEditString) tableModel.getValueAt(table.convertRowIndexToModel(rowIndex), CyNetwork.SUID);
targetRows.add(tableModel.getRow(selected.getValidatedObject()));
}
final CyTable cyTable = tableType == CyNode.class ? net.getDefaultNodeTable() : net.getDefaultEdgeTable();
for (final CyRow cyRow : cyTable.getAllRows()) cyRow.set(CyNetwork.SELECTED, targetRows.contains(cyRow));
final CyNetworkView view = applicationManager.getCurrentNetworkView();
if (view != null) {
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.flushPayloadEvents();
view.updateView();
}
}
}
};
t.start();
}
use of org.cytoscape.model.CyNetwork 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);
}
}
Aggregations