Search in sources :

Example 1 with VisualStyleAboutToBeRemovedEvent

use of org.cytoscape.view.vizmap.events.VisualStyleAboutToBeRemovedEvent in project cytoscape-api by cytoscape.

the class VizmapEventsTest method testVisualStyleDestroyedEvent.

@Test
public void testVisualStyleDestroyedEvent() {
    final VisualStyleAboutToBeRemovedEvent event = new VisualStyleAboutToBeRemovedEvent(manager, style);
    assertEquals(style, event.getVisualStyleToBeRemoved());
}
Also used : VisualStyleAboutToBeRemovedEvent(org.cytoscape.view.vizmap.events.VisualStyleAboutToBeRemovedEvent) Test(org.junit.Test)

Example 2 with VisualStyleAboutToBeRemovedEvent

use of org.cytoscape.view.vizmap.events.VisualStyleAboutToBeRemovedEvent 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)

Aggregations

VisualStyleAboutToBeRemovedEvent (org.cytoscape.view.vizmap.events.VisualStyleAboutToBeRemovedEvent)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 CyEventHelper (org.cytoscape.event.CyEventHelper)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 Test (org.junit.Test)1