Search in sources :

Example 11 with DialogTaskManager

use of org.cytoscape.work.swing.DialogTaskManager in project cytoscape-impl by cytoscape.

the class LayoutMenuPopulator method menuSelected.

@Override
public void menuSelected(MenuEvent e) {
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final DialogTaskManager tm = serviceRegistrar.getService(DialogTaskManager.class);
    CyNetworkView view = appMgr.getCurrentNetworkView();
    CyNetwork network = appMgr.getCurrentNetwork();
    // Figure out if we have anything selected
    boolean someSelected = false;
    if (network != null)
        someSelected = network.getDefaultNodeTable().countMatchingRows(CyNetwork.SELECTED, true) > 0;
    boolean enableMenuItem = checkEnabled();
    // Get all of the algorithms
    for (CyLayoutAlgorithm layout : algorithmMap.keySet()) {
        Map props = algorithmMap.get(layout);
        double gravity = 1000.0;
        if (props.get(MENU_GRAVITY) != null)
            gravity = Double.parseDouble((String) props.get(MENU_GRAVITY));
        boolean separatorAfter = false;
        if (props.get(INSERT_SEPARATOR_AFTER) != null)
            separatorAfter = Boolean.parseBoolean((String) props.get(INSERT_SEPARATOR_AFTER));
        boolean separatorBefore = false;
        if (props.get(INSERT_SEPARATOR_BEFORE) != null)
            separatorBefore = Boolean.parseBoolean((String) props.get(INSERT_SEPARATOR_BEFORE));
        // Remove the old menu
        if (menuMap.containsKey(layout)) {
            layoutMenu.remove(menuMap.remove(layout));
        }
        boolean usesNodeAttrs = false;
        if (network != null)
            usesNodeAttrs = hasValidAttributes(layout.getSupportedNodeAttributeTypes(), network.getDefaultNodeTable());
        boolean usesEdgeAttrs = false;
        if (network != null)
            usesEdgeAttrs = hasValidAttributes(layout.getSupportedEdgeAttributeTypes(), network.getDefaultEdgeTable());
        boolean usesSelected = (layout.getSupportsSelectedOnly() && someSelected);
        if (usesNodeAttrs || usesEdgeAttrs || usesSelected) {
            JMenu newMenu = new DynamicLayoutMenu(layout, network, enableMenuItem, appMgr, tm, usesNodeAttrs, usesEdgeAttrs, usesSelected);
            menuMap.put(layout, newMenu);
            gravityTracker.addMenu(newMenu, gravity);
        } else {
            JMenuItem newMenu = new StaticLayoutMenu(layout, enableMenuItem, appMgr, tm);
            menuMap.put(layout, newMenu);
            gravityTracker.addMenuItem(newMenu, gravity);
        }
        if (separatorAfter && !separatorMap.containsKey(layout)) {
            gravityTracker.addMenuSeparator(gravity + 0.0001);
            separatorMap.put(layout, Boolean.TRUE);
        } else if (separatorBefore && !separatorMap.containsKey(layout)) {
            gravityTracker.addMenuSeparator(gravity - 0.0001);
            separatorMap.put(layout, Boolean.TRUE);
        }
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNetwork(org.cytoscape.model.CyNetwork) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) JMenuItem(javax.swing.JMenuItem) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashMap(java.util.HashMap) Map(java.util.Map) JMenu(javax.swing.JMenu)

Example 12 with DialogTaskManager

use of org.cytoscape.work.swing.DialogTaskManager in project cytoscape-impl by cytoscape.

the class ImportDefaultVisualStylesCommand method execute.

@Override
public void execute(final INotification notification) {
    final TaskIterator iterator = new TaskIterator(new ImportDefaultVizmapTask(servicesUtil));
    final DialogTaskManager taskManager = servicesUtil.get(DialogTaskManager.class);
    final VizMapperProxy proxy = (VizMapperProxy) getFacade().retrieveProxy(VizMapperProxy.NAME);
    proxy.setIgnoreStyleEvents(true);
    taskManager.execute(iterator, new TaskObserver() {

        @Override
        public void taskFinished(ObservableTask task) {
        }

        @Override
        public void allFinished(FinishStatus finishStatus) {
            proxy.setIgnoreStyleEvents(false);
            proxy.loadVisualStyles();
            proxy.setCurrentVisualStyle(servicesUtil.get(VisualMappingManager.class).getDefaultVisualStyle());
        }
    });
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) VizMapperProxy(org.cytoscape.view.vizmap.gui.internal.model.VizMapperProxy) TaskIterator(org.cytoscape.work.TaskIterator) FinishStatus(org.cytoscape.work.FinishStatus) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) ImportDefaultVizmapTask(org.cytoscape.view.vizmap.gui.internal.task.ImportDefaultVizmapTask)

Example 13 with DialogTaskManager

use of org.cytoscape.work.swing.DialogTaskManager in project cytoscape-impl by cytoscape.

the class RemoveLockedValuesCommand method execute.

@Override
public void execute(final INotification notification) {
    final LockedValuesVO vo = (LockedValuesVO) notification.getBody();
    final Set<VisualProperty<?>> visualProperties = vo.getVisualProperties();
    if (visualProperties == null)
        return;
    CyNetworkView netView = vo.getNetworkView();
    Set<View<? extends CyIdentifiable>> views = vo.getViews();
    final VizMapperProxy vmProxy = (VizMapperProxy) getFacade().retrieveProxy(VizMapperProxy.NAME);
    if (netView == null)
        netView = vmProxy.getCurrentNetworkView();
    if (netView != null && views == null) {
        // Get the selected views
        final Set<Class<? extends CyIdentifiable>> targetDataTypes = new HashSet<Class<? extends CyIdentifiable>>();
        for (final VisualProperty<?> vp : visualProperties) targetDataTypes.add(vp.getTargetDataType());
        views = new HashSet<View<? extends CyIdentifiable>>();
        if (targetDataTypes.contains(CyNode.class))
            views.addAll(vmProxy.getSelectedNodeViews(netView));
        if (targetDataTypes.contains(CyEdge.class))
            views.addAll(vmProxy.getSelectedEdgeViews(netView));
        if (targetDataTypes.contains(CyNetwork.class))
            views.add(netView);
    }
    if (views != null) {
        final TaskIterator iterator = new TaskIterator(new RemoveLockedValuesTask(visualProperties, views, netView, servicesUtil));
        final DialogTaskManager taskManager = servicesUtil.get(DialogTaskManager.class);
        taskManager.execute(iterator);
    }
}
Also used : DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) VizMapperProxy(org.cytoscape.view.vizmap.gui.internal.model.VizMapperProxy) RemoveLockedValuesTask(org.cytoscape.view.vizmap.gui.internal.task.RemoveLockedValuesTask) TaskIterator(org.cytoscape.work.TaskIterator) LockedValuesVO(org.cytoscape.view.vizmap.gui.internal.model.LockedValuesVO) VisualProperty(org.cytoscape.view.model.VisualProperty) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable) HashSet(java.util.HashSet)

Example 14 with DialogTaskManager

use of org.cytoscape.work.swing.DialogTaskManager in project cytoscape-impl by cytoscape.

the class SetLockedValuesCommand method execute.

@Override
public void execute(final INotification notification) {
    final LockedValuesVO vo = (LockedValuesVO) notification.getBody();
    final Map<VisualProperty<?>, Object> values = vo.getValues();
    if (values == null)
        return;
    CyNetworkView netView = vo.getNetworkView();
    Set<View<? extends CyIdentifiable>> views = vo.getViews();
    final VizMapperProxy vmProxy = (VizMapperProxy) getFacade().retrieveProxy(VizMapperProxy.NAME);
    if (netView == null)
        netView = vmProxy.getCurrentNetworkView();
    if (netView != null && views == null) {
        // Get the selected views
        final Set<Class<? extends CyIdentifiable>> targetDataTypes = new HashSet<Class<? extends CyIdentifiable>>();
        for (final VisualProperty<?> vp : values.keySet()) targetDataTypes.add(vp.getTargetDataType());
        views = new HashSet<View<? extends CyIdentifiable>>();
        if (targetDataTypes.contains(CyNode.class))
            views.addAll(vmProxy.getSelectedNodeViews(netView));
        if (targetDataTypes.contains(CyEdge.class))
            views.addAll(vmProxy.getSelectedEdgeViews(netView));
        if (targetDataTypes.contains(CyNetwork.class))
            views.add(netView);
    }
    if (views != null) {
        final TaskIterator iterator = new TaskIterator(new SetLockedValuesTask(values, views, netView, servicesUtil));
        final DialogTaskManager taskManager = servicesUtil.get(DialogTaskManager.class);
        taskManager.execute(iterator);
    }
}
Also used : SetLockedValuesTask(org.cytoscape.view.vizmap.gui.internal.task.SetLockedValuesTask) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) VizMapperProxy(org.cytoscape.view.vizmap.gui.internal.model.VizMapperProxy) TaskIterator(org.cytoscape.work.TaskIterator) LockedValuesVO(org.cytoscape.view.vizmap.gui.internal.model.LockedValuesVO) VisualProperty(org.cytoscape.view.model.VisualProperty) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable) HashSet(java.util.HashSet)

Example 15 with DialogTaskManager

use of org.cytoscape.work.swing.DialogTaskManager in project cytoscape-impl by cytoscape.

the class RemoveVisualMappingsCommand method execute.

@Override
@SuppressWarnings("unchecked")
public void execute(final INotification notification) {
    final Set<VisualMappingFunction<?, ?>> set = (Set<VisualMappingFunction<?, ?>>) notification.getBody();
    final VizMapperProxy proxy = (VizMapperProxy) getFacade().retrieveProxy(VizMapperProxy.NAME);
    final VisualStyle style = proxy.getCurrentVisualStyle();
    final TaskIterator iterator = new TaskIterator(new RemoveVisualMappingsTask(set, style, servicesUtil));
    final DialogTaskManager taskManager = servicesUtil.get(DialogTaskManager.class);
    taskManager.execute(iterator);
}
Also used : VizMapperProxy(org.cytoscape.view.vizmap.gui.internal.model.VizMapperProxy) Set(java.util.Set) TaskIterator(org.cytoscape.work.TaskIterator) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) RemoveVisualMappingsTask(org.cytoscape.view.vizmap.gui.internal.task.RemoveVisualMappingsTask) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager)

Aggregations

DialogTaskManager (org.cytoscape.work.swing.DialogTaskManager)22 CyNetworkView (org.cytoscape.view.model.CyNetworkView)7 CyNetwork (org.cytoscape.model.CyNetwork)6 HashSet (java.util.HashSet)4 CyApplicationManager (org.cytoscape.application.CyApplicationManager)4 CreateNetworkViewTaskFactory (org.cytoscape.task.create.CreateNetworkViewTaskFactory)4 VizMapperProxy (org.cytoscape.view.vizmap.gui.internal.model.VizMapperProxy)4 TaskIterator (org.cytoscape.work.TaskIterator)4 DestroyNetworkViewTaskFactory (org.cytoscape.task.destroy.DestroyNetworkViewTaskFactory)3 BorderLayout (java.awt.BorderLayout)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JPopupMenu (javax.swing.JPopupMenu)2 CyIdentifiable (org.cytoscape.model.CyIdentifiable)2 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)2 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)2 DeleteTableTaskFactory (org.cytoscape.task.destroy.DeleteTableTaskFactory)2 DestroyNetworkTaskFactory (org.cytoscape.task.destroy.DestroyNetworkTaskFactory)2