Search in sources :

Example 46 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class IndexAndSearchTask method updateView.

/**
 * If view(s) exists for the current network, update them.
 */
private void updateView() {
    final CyNetworkViewManager viewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
    final CyApplicationManager appManager = serviceRegistrar.getService(CyApplicationManager.class);
    final Collection<CyNetworkView> views = viewManager.getNetworkViews(network);
    CyNetworkView targetView = null;
    if (views.size() != 0)
        targetView = views.iterator().next();
    if (targetView != null)
        targetView.updateView();
    final CyNetworkView view = appManager.getCurrentNetworkView();
    if (view != null)
        view.updateView();
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 47 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class SessionHandler method setSessionNetworks.

/**
 * @param netOrder Maps CyNetwork SUID to the network position
 */
private void setSessionNetworks(final Map<Long, Integer> netOrder) {
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    final List<CySubNetwork> sortedNetworks = new ArrayList<>();
    for (CyNetwork n : netMgr.getNetworkSet()) {
        if (n instanceof CySubNetwork && netMgr.networkExists(n.getSUID()))
            sortedNetworks.add((CySubNetwork) n);
    }
    Collections.sort(sortedNetworks, new Comparator<CySubNetwork>() {

        @Override
        public int compare(final CySubNetwork n1, final CySubNetwork n2) {
            try {
                Integer o1 = netOrder.get(n1.getSUID());
                Integer o2 = netOrder.get(n2.getSUID());
                if (o1 == null)
                    o1 = -1;
                if (o2 == null)
                    o2 = -1;
                return o1.compareTo(o2);
            } catch (final Exception e) {
                logger.error("Cannot sort networks", e);
            }
            return 0;
        }
    });
    final CyApplicationManager applicationMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    final List<CyNetwork> selectedNetworks = applicationMgr.getSelectedNetworks();
    final List<CyNetworkView> selectedViews = applicationMgr.getSelectedNetworkViews();
    invokeOnEDT(() -> {
        netPanel.setNetworks(sortedNetworks);
        for (SubNetworkPanel snp : netPanel.getAllSubNetworkItems()) {
            final int count = netViewMgr.getNetworkViews(snp.getModel().getNetwork()).size();
            snp.getModel().setViewCount(count);
        }
        netPanel.setSelectedNetworks(selectedNetworks);
        netViewMediator.getNetworkViewMainPanel().setSelectedNetworkViews(selectedViews);
    });
}
Also used : CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkManager(org.cytoscape.model.CyNetworkManager) SubNetworkPanel(org.cytoscape.internal.view.SubNetworkPanel) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 48 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class BrowserTable method selectFromTable.

private void selectFromTable() {
    final TableModel model = this.getModel();
    if (model instanceof BrowserTableModel == false)
        return;
    final BrowserTableModel btModel = (BrowserTableModel) model;
    if (btModel.getViewMode() != BrowserTableModel.ViewMode.ALL)
        return;
    final CyTable table = btModel.getDataTable();
    final CyColumn pKey = table.getPrimaryKey();
    final String pKeyName = pKey.getName();
    final int[] rowsSelected = getSelectedRows();
    if (rowsSelected.length == 0)
        return;
    final int selectedRowCount = getSelectedRowCount();
    final Set<CyRow> targetRows = new HashSet<CyRow>();
    for (int i = 0; i < selectedRowCount; i++) {
        // getting the row from data table solves the problem with hidden or
        // moved SUID column. However, since the rows might be sorted we
        // need to convert the index to model
        final ValidatedObjectAndEditString selected = (ValidatedObjectAndEditString) btModel.getValueAt(convertRowIndexToModel(rowsSelected[i]), pKeyName);
        targetRows.add(btModel.getRow(selected.getValidatedObject()));
    }
    // Clear selection for non-global table
    final CyTableManager tableManager = serviceRegistrar.getService(CyTableManager.class);
    if (tableManager.getGlobalTables().contains(table) == false) {
        List<CyRow> allRows = btModel.getDataTable().getAllRows();
        try {
            ignoreRowSetEvents = true;
            for (CyRow row : allRows) {
                final Boolean val = row.get(CyNetwork.SELECTED, Boolean.class);
                if (targetRows.contains(row)) {
                    row.set(CyNetwork.SELECTED, true);
                    continue;
                }
                if (val != null && (val == true))
                    row.set(CyNetwork.SELECTED, false);
            }
            final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
            final CyNetworkView curView = applicationManager.getCurrentNetworkView();
            if (curView != null) {
                final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
                eventHelper.flushPayloadEvents();
                curView.updateView();
            }
        } finally {
            ignoreRowSetEvents = false;
        }
        repaint();
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyColumn(org.cytoscape.model.CyColumn) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyRow(org.cytoscape.model.CyRow) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyTableManager(org.cytoscape.model.CyTableManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) TableModel(javax.swing.table.TableModel) HashSet(java.util.HashSet)

Example 49 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager 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 50 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class CyNetworkViewManagerTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    CyApplicationManager applicationManager = mock(CyApplicationManager.class);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) Before(org.junit.Before)

Aggregations

CyApplicationManager (org.cytoscape.application.CyApplicationManager)80 CyNetwork (org.cytoscape.model.CyNetwork)40 CyNetworkView (org.cytoscape.view.model.CyNetworkView)30 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)18 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)16 CyNetworkManager (org.cytoscape.model.CyNetworkManager)14 CyEventHelper (org.cytoscape.event.CyEventHelper)12 CyTable (org.cytoscape.model.CyTable)12 ArrayList (java.util.ArrayList)11 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)10 CyNode (org.cytoscape.model.CyNode)9 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)9 Test (org.junit.Test)9 HashSet (java.util.HashSet)8 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)8 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 HashMap (java.util.HashMap)7 CyGroupManager (org.cytoscape.group.CyGroupManager)7 CyTableManager (org.cytoscape.model.CyTableManager)7