use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class EquationParserImpl method registerFunctionService.
// Listeners for function services
public void registerFunctionService(final Function function, final Map<?, ?> props) {
if (function != null) {
registerFunctionInternal(function);
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.addEventPayload(this, function, EquationFunctionAddedEvent.class);
logger.info("New Function Registered: " + function.getName());
}
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CyGroupManagerImpl method destroyGroup.
@Override
public void destroyGroup(CyGroup group) {
synchronized (lock) {
if (!groupSet.contains(group))
return;
}
final CyEventHelper cyEventHelper = getService(CyEventHelper.class);
cyEventHelper.fireEvent(new GroupAboutToBeDestroyedEvent(CyGroupManagerImpl.this, group));
synchronized (lock) {
if (rootMap.containsKey(group.getRootNetwork()))
rootMap.get(group.getRootNetwork()).remove(group);
groupSet.remove(group);
}
((CyGroupImpl) group).destroyGroup();
// updateGroupAttribute(group);
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CyGroupManagerImpl method addGroup.
@Override
public void addGroup(final CyGroup group) {
synchronized (lock) {
if (groupSet.contains(group)) {
return;
} else {
groupSet.add(group);
addGroupToRootMap(group);
// updateGroupAttribute(group);
}
}
final CyEventHelper cyEventHelper = getService(CyEventHelper.class);
cyEventHelper.fireEvent(new GroupAddedEvent(CyGroupManagerImpl.this, group));
}
use of org.cytoscape.event.CyEventHelper 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.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class NodeChangeListener method updateNodeLocation.
private void updateNodeLocation(CyNetworkView networkView, View<CyNode> nodeView) {
// double groupY = nodeView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
if (nodeView == null)
return;
CyNode node = nodeView.getModel();
CyGroup group = node2GroupMap.get(networkView).get(node);
if (group == null) {
// System.out.println("Lost group: "+node);
group = getGroupForNode(node, networkView);
if (group == null)
return;
else
node2GroupMap.get(networkView).put(node, group);
}
if (cyStyleManager == null)
cyStyleManager = cyGroupManager.getService(VisualMappingManager.class);
boolean lastIgnoreChanges = ignoreChanges;
ignoreChanges = true;
ViewUtils.styleCompoundNode(group, networkView, cyGroupManager, cyStyleManager, cyGroupSettings.getGroupViewType(group));
final CyEventHelper cyEventHelper = cyGroupManager.getService(CyEventHelper.class);
cyEventHelper.flushPayloadEvents();
// OK, a little trickery here. If our group is itself a node in another group, we
// won't restyle appropriately because we were ignoring changes. Deal with it here,
// but only if our group is also a node in another group
CyGroup g = getGroupForNode(group.getGroupNode(), networkView);
if (g != null) {
View<CyNode> nv = networkView.getNodeView(group.getGroupNode());
if (nv != null) {
updateNodeLocation(networkView, nv);
// ViewUtils.styleCompoundNode(g, networkView, cyGroupManager, cyStyleManager,
// cyGroupSettings.getGroupViewType(group));
cyEventHelper.flushPayloadEvents();
}
}
ignoreChanges = lastIgnoreChanges;
}
Aggregations