use of org.cytoscape.group.CyGroupSettingsManager.GroupViewType 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.CyGroupSettingsManager.GroupViewType 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);
}
}
use of org.cytoscape.group.CyGroupSettingsManager.GroupViewType in project cytoscape-impl by cytoscape.
the class GroupViewCollapseHandler method handleEvent.
/**
* If a group is destroyed, and it's a compound node, we need to fix up a
* bunch of things.
*/
@Override
public void handleEvent(GroupAboutToBeDestroyedEvent e) {
getServices();
CyGroup group = e.getGroup();
GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
if (groupViewType.equals(GroupViewType.COMPOUND)) {
removeCompoundNode(group);
return;
}
// for this group
if (cyGroupSettings.getUseNestedNetworks(group)) {
// First, we need to make sure the group is expanded
for (CyNetwork net : group.getNetworkSet()) {
group.expand(net);
}
CyNetwork nn = group.getGroupNetwork();
if (cyNetworkViewManager.viewExists(nn)) {
// Destroy the view(s)
for (CyNetworkView v : cyNetworkViewManager.getNetworkViews(nn)) {
cyNetworkViewManager.destroyNetworkView(v);
}
}
// Now, remove the network
cyNetworkManager.destroyNetwork(nn);
group.getGroupNode().setNetworkPointer(null);
}
}
use of org.cytoscape.group.CyGroupSettingsManager.GroupViewType in project cytoscape-impl by cytoscape.
the class GroupViewCollapseHandler method handleEvent.
@Override
public void handleEvent(GroupAddedEvent e) {
getServices();
CyGroup group = e.getGroup();
GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
try {
// of the group visually immediately
if (groupViewType.equals(GroupViewType.COMPOUND) || groupViewType.equals(GroupViewType.SINGLENODE)) {
Set<CyNetwork> networkSet = group.getNetworkSet();
if (networkSet == null || networkSet.size() == 0)
return;
for (CyNetwork network : networkSet) {
((CyGroupImpl) group).setGroupNodeShown(network, true);
GroupCollapsedEvent ev = new GroupCollapsedEvent(group, network, false);
handleEvent(ev);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return;
}
use of org.cytoscape.group.CyGroupSettingsManager.GroupViewType 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();
}
Aggregations