use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GroupViewCollapseHandler method handleEvent.
@Override
public void handleEvent(GroupCollapsedEvent e) {
getServices();
CyNetwork network = e.getNetwork();
CyGroup group = e.getSource();
final Collection<CyNetworkView> views = cyNetworkViewManager.getNetworkViews(network);
CyNetworkView view = null;
if (views.size() == 0) {
return;
}
for (CyNetworkView v : views) {
if (v.getRendererId().equals("org.cytoscape.ding")) {
view = v;
}
}
if (view == null)
return;
CyRootNetwork rootNetwork = group.getRootNetwork();
GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
if (e.collapsed()) {
// System.out.println("Got collapse event for "+group);
// Get the location to move the group node to
Dimension d = ViewUtils.getLocation(network, group);
if (d != null) {
// Move it.
ViewUtils.moveNode(view, group.getGroupNode(), d);
}
View<CyNode> nView = view.getNodeView(group.getGroupNode());
if (cyGroupSettings.getUseNestedNetworks(group)) {
// Now, if we're displaying the nested network, create it....
CyNetwork nn = group.getGroupNetwork();
CyNetworkView nnView = null;
// If we've already registered the network, don't do it again
if (!cyNetworkManager.networkExists(nn.getSUID())) {
cyNetworkManager.addNetwork(nn, false);
nnView = cyNetworkViewFactory.createNetworkView(nn);
cyNetworkViewManager.addNetworkView(nnView, false);
// Apply our current style to the nested network
VisualStyle style = cyStyleManager.getVisualStyle(view);
cyStyleManager.setVisualStyle(style, nnView);
style.apply(nnView);
} else if (cyNetworkViewManager.viewExists(nn)) {
nnView = cyNetworkViewManager.getNetworkViews(nn).iterator().next();
}
if (nnView != null) {
ViewUtils.moveNodes(group, nnView, d);
nnView.updateView();
// Allow the nested network image to be displayed
nView.clearValueLock(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE);
}
} else {
// Make sure the nested network image is not displayed
nView.setLockedValue(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE, Boolean.FALSE);
}
// If we were showing this as a compound node, we need to restyle
if (groupViewType.equals(GroupViewType.COMPOUND)) {
deActivateCompoundNode(group, view);
}
styleGroupNode(group, view, views);
} else {
// System.out.println("Got expand event for "+group);
CyNode groupNode = group.getGroupNode();
// Get the location of the group node before it went away
Dimension center = ViewUtils.getLocation(network, group);
if (center != null)
ViewUtils.moveNodes(group, view, center);
// If we're asked to, show the group node
if (!groupViewType.equals(GroupViewType.NONE)) {
CySubNetwork subnet = (CySubNetwork) network;
// Add the node back
subnet.addNode(group.getGroupNode());
// Add the group nodes's edges back
List<CyEdge> groupNodeEdges = rootNetwork.getAdjacentEdgeList(groupNode, CyEdge.Type.ANY);
for (CyEdge edge : groupNodeEdges) {
CyRow row = rootNetwork.getRow(edge, CyNetwork.HIDDEN_ATTRS);
// Only add non-meta edges
if (row != null && (!row.isSet(CyGroupImpl.ISMETA_EDGE_ATTR) || !row.get(CyGroupImpl.ISMETA_EDGE_ATTR, Boolean.class))) {
subnet.addEdge(edge);
} else if (subnet.containsEdge(edge) && row != null && row.isSet(CyGroupImpl.ISMETA_EDGE_ATTR) && row.get(CyGroupImpl.ISMETA_EDGE_ATTR, Boolean.class)) {
// Edge is a meta edge, but is still in the network. Remove it
subnet.removeEdges(Collections.singletonList(edge));
}
}
if (groupViewType.equals(GroupViewType.SHOWGROUPNODE)) {
// If this is the first time, we need to add our member
// edges in.
addMemberEdges(group, network);
// Style our member edges
styleGroupNode(group, view, views);
}
// Flush events so that the view hears about it
final CyEventHelper cyEventHelper = cyGroupManager.getService(CyEventHelper.class);
cyEventHelper.flushPayloadEvents();
// Now, call ourselves as if we had been collapsed
handleEvent(new GroupCollapsedEvent(group, network, true));
if (groupViewType.equals(GroupViewType.COMPOUND) || groupViewType.equals(GroupViewType.SINGLENODE)) {
// May be redundant, but just to make sure
((CyGroupImpl) group).setGroupNodeShown(network, true);
activateCompoundNode(group, view);
}
cyEventHelper.flushPayloadEvents();
view.updateView();
return;
}
final List<CyNode> nodeList = group.getNodeList();
// TODO: turn off stupid nested network thing
for (CyNode node : nodeList) {
if (!network.containsNode(node))
continue;
View<CyNode> nView = view.getNodeView(node);
if (node.getNetworkPointer() != null && cyGroupManager.isGroup(node, network)) {
if (!cyGroupSettings.getUseNestedNetworks(cyGroupManager.getGroup(node, network))) {
nView.setLockedValue(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE, Boolean.FALSE);
}
}
}
// Apply visual property to added graph elements
ViewUtils.applyStyle(nodeList, views, cyStyleManager);
ViewUtils.applyStyle(group.getInternalEdgeList(), views, cyStyleManager);
ViewUtils.applyStyle(group.getExternalEdgeList(), views, cyStyleManager);
}
view.updateView();
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class NetworkCollectionHelper method getRootNetwork.
// Return the rootNetwork based on user selection, if not existed yet, create a new one
public CyRootNetwork getRootNetwork() {
final CyRootNetwork rootNetwork;
final String rootNetName = rootNetworkList.getSelectedValue();
if (rootNetName == null || rootNetName.equalsIgnoreCase(CREATE_NEW_COLLECTION_STRING)) {
final CyNetwork newNet = serviceRegistrar.getService(CyNetworkFactory.class).createNetwork();
rootNetwork = serviceRegistrar.getService(CyRootNetworkManager.class).getRootNetwork(newNet);
} else {
rootNetwork = name2RootMap.get(rootNetName);
if (rootNetwork == null) {
throw new RuntimeException("Can't find a network collection named '" + rootNetName + "'");
}
}
return rootNetwork;
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class NetworkCollectionHelper method getRootNetworkMap.
private HashMap<String, CyRootNetwork> getRootNetworkMap() {
final HashMap<String, CyRootNetwork> name2RootMap = new HashMap<>();
final Set<CyNetwork> networkSet = serviceRegistrar.getService(CyNetworkManager.class).getNetworkSet();
final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
for (CyNetwork net : networkSet) {
final CyRootNetwork rootNet = rootNetworkManager.getRootNetwork(net);
if (!name2RootMap.containsValue(rootNet))
name2RootMap.put(rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class), rootNet);
}
return name2RootMap;
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class NetworkCollectionHelper method init.
void init() {
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final CyRootNetworkManager rootNetMgr = serviceRegistrar.getService(CyRootNetworkManager.class);
// initialize the network Collection
name2RootMap = getRootNetworkMap();
final List<String> rootNames = new ArrayList<>();
rootNames.addAll(name2RootMap.keySet());
if (!rootNames.isEmpty()) {
sort(rootNames);
rootNames.add(0, CREATE_NEW_COLLECTION_STRING);
}
rootNetworkList = new ListSingleSelection<>(rootNames);
final CyNetwork net = appMgr != null ? appMgr.getCurrentNetwork() : null;
final CyRootNetwork rootNet = net != null ? rootNetMgr.getRootNetwork(net) : null;
final String rootNetName = rootNet != null ? rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class) : CREATE_NEW_COLLECTION_STRING;
if (rootNames.contains(rootNetName))
rootNetworkList.setSelectedValue(rootNetName);
else if (rootNames.contains(CREATE_NEW_COLLECTION_STRING))
rootNetworkList.setSelectedValue(CREATE_NEW_COLLECTION_STRING);
if (rootNet != null)
targetColumnList = getTargetColumns(rootNet);
else
targetColumnList = new ListSingleSelection<>();
// initialize renderer list
final List<NetworkViewRenderer> renderers = new ArrayList<>();
final Set<NetworkViewRenderer> rendererSet = appMgr.getNetworkViewRendererSet();
// so the combo-box does not appear to the user, since there is nothing to select anyway.
if (rendererSet.size() > 1) {
renderers.addAll(rendererSet);
Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {
@Override
public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
return r1.toString().compareToIgnoreCase(r2.toString());
}
});
}
rendererList = new ListSingleSelection<>(renderers);
final NetworkViewRenderer defViewRenderer = appMgr.getDefaultNetworkViewRenderer();
if (defViewRenderer != null && renderers.contains(defViewRenderer))
rendererList.setSelectedValue(defViewRenderer);
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class SIFNetworkReader method readInput.
private void readInput(TaskMonitor tm) throws IOException {
this.parentTaskMonitor = tm;
tm.setProgress(0.0);
String line;
final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8").newDecoder()), 128 * 1024);
CyRootNetwork root = getRootNetwork();
final CySubNetwork newNetwork;
if (root != null)
newNetwork = root.addSubNetwork();
else
// Need to create new network with new root.
newNetwork = (CySubNetwork) cyNetworkFactory.createNetwork();
Map<Object, CyNode> nMap = getNodeMap();
tm.setProgress(0.1);
final String firstLine = br.readLine();
if (firstLine.contains(TAB))
delimiter = TAB;
createEdge(new Interaction(firstLine.trim(), delimiter), newNetwork, nMap);
tm.setProgress(0.15);
tm.setStatusMessage("Processing the interactions...");
int numInteractionsRead = 0;
while ((line = br.readLine()) != null) {
if (cancelled) {
// Cancel called. Clean up the garbage.
nMap.clear();
br.close();
return;
}
if (line.trim().length() <= 0)
continue;
try {
final Interaction itr = new Interaction(line, delimiter);
createEdge(itr, newNetwork, nMap);
} catch (Exception e) {
// Simply ignore invalid lines.
continue;
}
if ((++numInteractionsRead % 1000) == 0)
tm.setStatusMessage("Processed " + numInteractionsRead + " interactions so far.");
}
br.close();
tm.setStatusMessage("Processed " + numInteractionsRead + " interactions in total.");
nMap.clear();
nMap = null;
this.networks = new CyNetwork[] { newNetwork };
tm.setProgress(1.0);
}
Aggregations