Search in sources :

Example 31 with CyEventHelper

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);
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyEventHelper(org.cytoscape.event.CyEventHelper) NetworkAddedEvent(org.cytoscape.model.events.NetworkAddedEvent) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyRow(org.cytoscape.model.CyRow)

Example 32 with CyEventHelper

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));
}
Also used : NetworkDestroyedEvent(org.cytoscape.model.events.NetworkDestroyedEvent) CyEventHelper(org.cytoscape.event.CyEventHelper) NetworkAboutToBeDestroyedEvent(org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 33 with CyEventHelper

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;
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CytoPanelStateChangedEvent(org.cytoscape.application.swing.events.CytoPanelStateChangedEvent) CytoPanelComponentSelectedEvent(org.cytoscape.application.swing.events.CytoPanelComponentSelectedEvent)

Example 34 with CyEventHelper

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());
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) VisualStyleAboutToBeRemovedEvent(org.cytoscape.view.vizmap.events.VisualStyleAboutToBeRemovedEvent) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 35 with CyEventHelper

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));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) VisualStyleAddedEvent(org.cytoscape.view.vizmap.events.VisualStyleAddedEvent)

Aggregations

CyEventHelper (org.cytoscape.event.CyEventHelper)63 CyNetworkView (org.cytoscape.view.model.CyNetworkView)19 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)19 CyNode (org.cytoscape.model.CyNode)15 UndoSupport (org.cytoscape.work.undo.UndoSupport)14 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)13 ArrayList (java.util.ArrayList)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetwork (org.cytoscape.model.CyNetwork)10 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)10 Test (org.junit.Test)10 Task (org.cytoscape.work.Task)9 CyTable (org.cytoscape.model.CyTable)8 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 CyEdge (org.cytoscape.model.CyEdge)7 CyRow (org.cytoscape.model.CyRow)7 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)5