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();
}
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);
});
}
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();
}
}
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);
}
}
}
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);
}
Aggregations