use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CyNetworkManagerImpl method addNetwork.
@Override
public void addNetwork(final CyNetwork network, final boolean setCurrent) {
if (network == null)
throw new NullPointerException("Network is null");
synchronized (lock) {
logger.debug("Adding new Network Model: Model ID = " + network.getSUID());
// Make sure the network has a name
final CyRow row = network.getRow(network);
final String name = row.get(CyNetwork.NAME, String.class);
final String sharedName = row.get(CyRootNetwork.SHARED_NAME, String.class);
if (name != null && !name.trim().isEmpty() && (sharedName == null || sharedName.trim().isEmpty())) {
row.set(CyRootNetwork.SHARED_NAME, name);
} else if (sharedName != null && !sharedName.trim().isEmpty() && (name == null || name.trim().isEmpty())) {
row.set(CyNetwork.NAME, sharedName);
} else if ((sharedName == null || sharedName.trim().isEmpty()) && (name == null || name.trim().isEmpty())) {
final CyNetworkNaming namingUtil = serviceRegistrar.getService(CyNetworkNaming.class);
final String newName = namingUtil.getSuggestedNetworkTitle("Network");
row.set(CyNetwork.NAME, newName);
row.set(CyRootNetwork.SHARED_NAME, newName);
}
// Add the new network to the internal map
networkMap.put(network.getSUID(), network);
}
final CyEventHelper cyEventHelper = serviceRegistrar.getService(CyEventHelper.class);
cyEventHelper.fireEvent(new NetworkAddedEvent(CyNetworkManagerImpl.this, network));
if (setCurrent) {
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
if (// It may be null when running unit tests
applicationManager != null)
applicationManager.setCurrentNetwork(network);
}
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CyNetworkManagerImpl method destroyNetwork.
@Override
public void destroyNetwork(final CyNetwork network) {
if (network == null)
throw new NullPointerException("Network is null");
final Long networkId = network.getSUID();
synchronized (lock) {
if (!networkMap.containsKey(networkId))
throw new IllegalArgumentException("network is not recognized by this NetworkManager");
}
final CyEventHelper cyEventHelper = serviceRegistrar.getService(CyEventHelper.class);
// let everyone know!
cyEventHelper.fireEvent(new NetworkAboutToBeDestroyedEvent(CyNetworkManagerImpl.this, network));
synchronized (lock) {
// check again within the lock in case something has changed
if (!networkMap.containsKey(networkId))
throw new IllegalArgumentException("network is not recognized by this NetworkManager");
for (CyNode n : network.getNodeList()) network.getRow(n).set(CyNetwork.SELECTED, false);
for (CyEdge e : network.getEdgeList()) network.getRow(e).set(CyNetwork.SELECTED, false);
networkMap.remove(networkId);
}
if (network instanceof CySubNetwork) {
final CySubNetwork subNetwork = (CySubNetwork) network;
final CyRootNetwork rootNetwork = subNetwork.getRootNetwork();
final CySubNetwork baseNetwork = rootNetwork.getBaseNetwork();
if (!subNetwork.equals(baseNetwork) || rootNetwork.getSubNetworkList().size() > 1) {
rootNetwork.removeSubNetwork(subNetwork);
network.dispose();
}
if (!hasRegisteredNetworks(rootNetwork))
rootNetwork.dispose();
} else {
network.dispose();
}
// let everyone know that some network is gone
cyEventHelper.fireEvent(new NetworkDestroyedEvent(CyNetworkManagerImpl.this));
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CytoPanelImpl method notifyListeners.
private void notifyListeners(int notificationType) {
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
// determine what event to fire
switch(notificationType) {
case NOTIFICATION_STATE_CHANGE:
eventHelper.fireEvent(new CytoPanelStateChangedEvent(this, this, cytoPanelState));
break;
case NOTIFICATION_COMPONENT_SELECTED:
int selectedIndex = getTabbedPane().getSelectedIndex();
eventHelper.fireEvent(new CytoPanelComponentSelectedEvent(this, this, selectedIndex));
break;
case NOTIFICATION_COMPONENT_ADDED:
break;
case NOTIFICATION_COMPONENT_REMOVED:
break;
}
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class VisualMappingManagerImpl method removeVisualStyle.
/**
* Remove a {@linkplain VisualStyle} from this manager. This will be called through OSGi service mechanism.
*/
@Override
public void removeVisualStyle(VisualStyle vs) {
if (vs == null)
throw new NullPointerException("Visual Style is null.");
if (vs == defaultStyle)
throw new IllegalArgumentException("Cannot remove default visual style.");
logger.info("Visual Style about to be removed from VMM: " + vs.getTitle());
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.fireEvent(new VisualStyleAboutToBeRemovedEvent(this, vs));
synchronized (lock) {
visualStyles.remove(vs);
}
// Change current style, if it is the deleted one
if (currentStyle == vs)
setCurrentVisualStyle(getDefaultVisualStyle());
// Use default for all views using this vs.
HashSet<CyNetworkView> viewsToUpdate = new HashSet<>();
synchronized (lock) {
if (network2VisualStyleMap.values().contains(vs)) {
for (final CyNetworkView view : network2VisualStyleMap.keySet()) {
if (network2VisualStyleMap.get(view).equals(vs))
viewsToUpdate.add(view);
}
}
}
for (CyNetworkView view : viewsToUpdate) {
setVisualStyle(defaultStyle, view);
}
logger.info("Total Number of VS in VMM after remove = " + visualStyles.size());
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class VisualMappingManagerImpl method addVisualStyle.
/**
* Add a new VisualStyle to this manager. This will be called through OSGi service mechanism.
*
* @param vs new Visual Style to be added.
*/
@Override
public void addVisualStyle(final VisualStyle vs) {
if (vs == null) {
logger.warn("Tried to add null to VMM.");
return;
}
if (hasDuplicatedTitle(vs)) {
String newTitle = getSuggestedTitle(vs.getTitle());
// Update the title
vs.setTitle(newTitle);
}
synchronized (lock) {
this.visualStyles.add(vs);
}
logger.info("New visual Style registered to VMM: " + vs.getTitle());
logger.info("Total Number of VS in VMM = " + visualStyles.size());
if (vs.getTitle() != null && vs.getTitle().equals(DEFAULT_STYLE_NAME))
defaultStyle = vs;
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.fireEvent(new VisualStyleAddedEvent(this, vs));
}
Aggregations