use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class CyGroupImpl method updateMetaEdges.
/**
* This method is the central method for the creation and maintenance of a
* meta-node. Essentially, it is responsible for creating all of the meta-edges
* that connect this meta-node to external nodes.
*
* Basic approach:
* for each external edge:
* add a meta-edge to the parter
* if the partner is a group and the group is in our network:
* add ourselves to the group's outer edges list (recursively)
* add ourselves to the partner's meta edge list
* if the partner is in a group:
* add ourselves to the group's meta edge list
*/
private void updateMetaEdges(boolean ignoreMetaEdges) {
synchronized (lock) {
metaEdges = new HashMap<CyEdge, CyEdge>();
Set<CyGroup> partnersSeen = new HashSet<CyGroup>();
// System.out.println("Updating metaEdges: ignoreMetaEdges = "+ignoreMetaEdges);
// long simpleMeta = 0L;
// long recursiveMeta1 = 0L;
// long recursiveMeta2 = 0L;
// System.out.println(this.toString()+" updating meta edges");
// We need to use a list iterator because we might need to add new
// edges to our outer edge list and we want to add them to the
// iterator to re-examine them
ListIterator<CyEdge> iterator = (new ArrayList<CyEdge>(externalEdges)).listIterator();
while (iterator.hasNext()) {
// long timeStamp = System.currentTimeMillis();
CyEdge edge = iterator.next();
CyNode node = getPartner(edge);
if (ignoreMetaEdges && isMeta(edge)) {
this.addMetaEdge(edge, edge);
continue;
}
// If the edge is already on our group node, don't create a metaedge for it
if (edge.getSource() == groupNode || edge.getTarget() == groupNode)
continue;
// but there you have it...
if (rootNetwork.containsEdge(edge.getSource(), groupNode) && metaAlreadyExists(edge.getSource(), groupNode)) {
this.addMetaEdge(edge, getMetaEdge(edge.getSource(), groupNode));
continue;
}
if (rootNetwork.containsEdge(groupNode, edge.getTarget()) && metaAlreadyExists(groupNode, edge.getTarget())) {
this.addMetaEdge(edge, getMetaEdge(groupNode, edge.getTarget()));
continue;
}
// Create the meta-edge to the external node, but maintain the directionality
// of the original edge
CyEdge metaEdge = createMetaEdge(edge, node, groupNode);
if (metaEdge == null)
continue;
// System.out.println("MetaEdge: "+metaEdge);
this.addMetaEdge(edge, metaEdge);
for (CyNetwork net : networkSet) {
// timeStamp = System.currentTimeMillis();
if (net.equals(rootNetwork))
continue;
// Is the partner a group?
CyGroup metaPartner = mgr.getGroup(node, net);
if (metaPartner != null && !partnersSeen.contains(metaPartner)) {
// Recursively add links to the appropriate children
// System.out.println("Adding partner edges for "+metaPartner);
addPartnerEdges(metaPartner, net, partnersSeen);
((CyGroupImpl) metaPartner).addMetaEdge(edge, metaEdge);
}
// recursiveMeta1 += System.currentTimeMillis()-timeStamp;
// timeStamp = System.currentTimeMillis();
/*
// Now, handle the case where the partner is a member of one or more groups
List<CyGroup> nodeGroups = mgr.getGroupsForNode(node);
if (nodeGroups != null && nodeGroups.size() > 0) {
// TODO: Should we skip this and handle this at collapse/expand time?
addPartnerMetaEdges(net, edge, nodeGroups, metaEdge);
}
*/
// recursiveMeta2 += System.currentTimeMillis()-timeStamp;
}
}
// System.out.println("Simple Meta processing took: "+simpleMeta+"ms");
// System.out.println("Recursive (partner edge) processing took: "+recursiveMeta1+"ms");
// System.out.println("Recursive (partner meta edge) processing took: "+recursiveMeta2+"ms");
}
}
use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class GroupViewDoubleClickListener method isReady.
public boolean isReady(View<CyNode> nodeView, CyNetworkView networkView) {
CyNode node = nodeView.getModel();
CyNetwork net = networkView.getModel();
// Do we care about this double-click?
if (cyGroupManager.isGroup(node, net)) {
return true;
} else {
List<CyGroup> groups = cyGroupManager.getGroupsForNode(node);
for (CyGroup g : groups) {
// Make sure we're in the right network
if (cyGroupManager.isGroup(g.getGroupNode(), net)) {
return true;
}
}
}
return false;
}
use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class GroupViewDoubleClickListener method createTaskIterator.
@Override
public TaskIterator createTaskIterator(View<CyNode> nodeView, CyNetworkView networkView) {
CyNode node = nodeView.getModel();
CyNetwork net = networkView.getModel();
CyGroup group = null;
// Get the double click action for this group
if (cyGroupManager.isGroup(node, net))
group = cyGroupManager.getGroup(node, net);
else {
List<CyGroup> groups = cyGroupManager.getGroupsForNode(node);
for (CyGroup g : groups) {
// Make sure we're in the right network
if (cyGroupManager.isGroup(g.getGroupNode(), net)) {
group = g;
break;
}
}
}
DoubleClickAction action = cyGroupSettings.getDoubleClickAction(group);
if (action == DoubleClickAction.EXPANDCONTRACT) {
// that group.
return new TaskIterator(new CollapseGroupTask(nodeView, networkView));
} else if (action == DoubleClickAction.SELECT) {
// If all members of the group are selected, deselect that group
return new TaskIterator(new SelectGroupTask(nodeView, networkView));
} else {
return new TaskIterator(new NullTask());
}
}
use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class GroupViewCollapseHandler method handleEvent.
/**
* We need to do some fixup after we load the session for compound nodes.
* When the session gets loaded, we don't (yet) have a view. We need to
* go through and kick update things to work properly if we have a view
* after the session gets loaded.
*/
@Override
public void handleEvent(SessionLoadedEvent e) {
getServices();
// System.out.println("SessionLoadedEvent");
try {
// For each network
for (CyNetworkView networkView : e.getLoadedSession().getNetworkViews()) {
CyNetwork network = networkView.getModel();
// For each group
for (CyGroup group : cyGroupManager.getGroupSet(network)) {
GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
// If the group is a compound node and if it is expanded,
if (groupViewType.equals(GroupViewType.COMPOUND) || groupViewType.equals(GroupViewType.SINGLENODE)) {
// If it's really collapsed, all of our children will
// be absent from the network. Check that first
boolean haveChildren = true;
for (CyNode node : group.getNodeList()) {
if (!network.containsNode(node)) {
haveChildren = false;
break;
}
}
if (haveChildren && network.containsNode(group.getGroupNode())) {
// At this point, because of the way we create the
// group, it will think it's collapsed. Change
// that.
((CyGroupImpl) group).setCollapsed(network, false);
((CyGroupImpl) group).setGroupNodeShown(network, true);
try {
// OK, now activate the group
activateCompoundNode(group, networkView);
} catch (Exception rtree) {
// We may get an RTree exception under rare
// circumstances.
rtree.printStackTrace();
}
}
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class GroupViewCollapseHandler method handleEvent.
@Override
public void handleEvent(GroupAboutToCollapseEvent e) {
getServices();
CyNetwork network = e.getNetwork();
CyGroup group = e.getSource();
CyRootNetwork rootNetwork = group.getRootNetwork();
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;
GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
if (e.collapsing()) {
// Calculate the center position of all of the
// member nodes
Dimension center = ViewUtils.calculateCenter(view, group.getNodeList());
if (center != null) {
// Save it in the groupNode attribute
ViewUtils.updateGroupLocation(network, group, center);
// save it in the node's attribute
for (CyNode node : group.getNodeList()) {
if (!network.containsNode(node))
continue;
Dimension offset = ViewUtils.calculateOffset(center, view, node);
ViewUtils.updateNodeOffset(network, group, node, offset);
}
}
} else {
// Get the current position of the groupNode
View<CyNode> nView = view.getNodeView(group.getGroupNode());
if (nView == null)
return;
double x = nView.getVisualProperty(xLoc);
double y = nView.getVisualProperty(yLoc);
// Save it in the groupNode attribute
ViewUtils.updateGroupLocation(network, group, x, y);
}
}
Aggregations