use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class AddNodeTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
final CyNetwork net = view.getModel();
final CyNode n = net.addNode();
// set the name attribute for the new node
final String nodeName = "Node " + new_node_index;
new_node_index++;
final CyRow nodeRow = net.getRow(n);
nodeRow.set(CyNetwork.NAME, nodeName);
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.flushPayloadEvents();
View<CyNode> nv = view.getNodeView(n);
nv.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, xformPt.getX());
nv.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, xformPt.getY());
// Apply visual style
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
VisualStyle vs = vmMgr.getVisualStyle(view);
vs.apply(net.getRow(n), nv);
view.updateView();
}
use of org.cytoscape.event.CyEventHelper in project clusterMaker2 by RBVI.
the class ClusterManagerImpl method linkNetworkSelection.
public void linkNetworkSelection(CyNetwork network) {
if (isLinked(network))
return;
CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
CyEventHelper helper = serviceRegistrar.getService(CyEventHelper.class);
NetworkSelectionLinker linker = new NetworkSelectionLinker(rootNetwork, helper, this);
registerService(linker, RowsSetListener.class, new Properties());
linkedNetworks.put(rootNetwork, linker);
}
use of org.cytoscape.event.CyEventHelper in project clusterMaker2 by RBVI.
the class ViewUtils method createView.
public static CyNetworkView createView(ClusterManager manager, CyNetwork newNetwork, boolean register) {
// Create the view
CyNetworkView view = manager.getService(CyNetworkViewFactory.class).createNetworkView(newNetwork);
if (register)
registerView(manager, view);
// Make sure we flush our events before we try to do anything else
CyEventHelper eventHelper = manager.getService(CyEventHelper.class);
eventHelper.flushPayloadEvents();
return view;
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method setCurrentSession.
@Override
public void setCurrentSession(CySession sess, final String fileName) {
// Always remove the current session first
if (!disposed)
disposeCurrentSession();
if (sess == null) {
logger.debug("Creating empty session...");
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
final Set<VisualStyle> styles = vmMgr.getAllVisualStyles();
final Set<CyProperty<?>> props = getAllProperties();
sess = new CySession.Builder().properties(props).visualStyles(styles).build();
} else {
logger.debug("Restoring the session...");
// Save the selected networks first, so the selection state can be restored later.
final List<CyNetwork> selectedNetworks = new ArrayList<>();
final Set<CyNetwork> networks = sess.getNetworks();
for (CyNetwork n : networks) {
final Boolean selected = n.getDefaultNetworkTable().getRow(n.getSUID()).get(CyNetwork.SELECTED, Boolean.class);
if (Boolean.TRUE.equals(selected))
selectedNetworks.add(n);
}
restoreProperties(sess);
restoreNetworks(sess);
restoreTables(sess);
restoreNetworkViews(sess, selectedNetworks);
restoreNetworkSelection(sess, selectedNetworks);
restoreVisualStyles(sess);
restoreCurrentVisualStyle();
}
currentFileName = fileName;
disposed = false;
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.fireEvent(new SessionLoadedEvent(this, sess, getCurrentSessionFileName()));
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method restoreNetworkViews.
private void restoreNetworkViews(final CySession sess, List<CyNetwork> selectedNetworks) {
logger.debug("Restoring network views...");
Set<CyNetworkView> netViews = sess.getNetworkViews();
List<CyNetworkView> selectedViews = new ArrayList<>();
for (CyNetworkView nv : netViews) {
CyNetwork network = nv.getModel();
if (selectedNetworks.contains(network)) {
selectedViews.add(nv);
}
}
Map<CyNetworkView, Map<VisualProperty<?>, Object>> viewVPMap = new HashMap<>();
if (netViews != null) {
final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
for (CyNetworkView nv : netViews) {
if (nv != null) {
// Save the original values of these visual properties,
// because we will have to set them again after the views are rendered
Map<VisualProperty<?>, Object> vpMap = new HashMap<>();
viewVPMap.put(nv, vpMap);
vpMap.put(BasicVisualLexicon.NETWORK_HEIGHT, nv.getVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT));
vpMap.put(BasicVisualLexicon.NETWORK_WIDTH, nv.getVisualProperty(BasicVisualLexicon.NETWORK_WIDTH));
nvMgr.addNetworkView(nv, false);
}
}
}
// Let's guarantee the network views are rendered
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.flushPayloadEvents();
// Set the saved visual properties again, because the renderer may have overwritten the original values
for (Entry<CyNetworkView, Map<VisualProperty<?>, Object>> entry1 : viewVPMap.entrySet()) {
CyNetworkView nv = entry1.getKey();
for (Entry<VisualProperty<?>, Object> entry2 : entry1.getValue().entrySet()) nv.setVisualProperty(entry2.getKey(), entry2.getValue());
}
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
if (!selectedViews.isEmpty())
appMgr.setCurrentNetworkView(selectedViews.get(0));
appMgr.setSelectedNetworkViews(selectedViews);
}
Aggregations