use of org.cytoscape.model.CyNetworkTableManager in project cytoscape-impl by cytoscape.
the class CellEditorEventHandler method switchColumn.
@SuppressWarnings("unchecked")
private VisualMappingFunction<?, ?> switchColumn(final VisualMappingFunctionFactory factory, final AttributeComboBoxPropertyEditor editor, final VizMapperProperty<?, ?, ?> prop, final String columnName, final PropertySheetPanel propertySheetPanel) {
final VisualStyle currentStyle = servicesUtil.get(VisualMappingManager.class).getCurrentVisualStyle();
final VisualProperty<?> vp = (VisualProperty<?>) prop.getKey();
VisualMappingFunction<?, ?> mapping = currentStyle.getVisualMappingFunction(vp);
// Ignore if not compatible.
final CyNetworkTableManager netTblMgr = servicesUtil.get(CyNetworkTableManager.class);
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
Class<? extends CyIdentifiable> type = (Class<? extends CyIdentifiable>) editor.getTargetObjectType();
final CyTable table = netTblMgr.getTable(appMgr.getCurrentNetwork(), type, CyNetwork.DEFAULT_ATTRS);
final CyColumn column = table.getColumn(columnName);
if (column == null) {
JOptionPane.showMessageDialog(null, "The current table does not have the selected column (\"" + columnName + "\").\nPlease select another column.", "Invalid Column.", JOptionPane.WARNING_MESSAGE);
prop.setValue(mapping != null ? mapping.getMappingColumnName() : null);
return mapping;
}
final Class<?> dataType = column.getType();
if (factory != null && (mapping == null || !columnName.equals(mapping.getMappingColumnName()))) {
// Need to create new mapping function
if (ContinuousMapping.class.isAssignableFrom(factory.getMappingFunctionType()) && !Number.class.isAssignableFrom(dataType)) {
JOptionPane.showMessageDialog(null, "Continuous Mapper can be used with numbers only.\nPlease select a numerical column type.", "Incompatible Mapping Type.", JOptionPane.INFORMATION_MESSAGE);
prop.setValue(mapping != null ? mapping.getMappingColumnName() : null);
return mapping;
}
return switchMappingType(prop, vp, factory, factory, columnName, propertySheetPanel);
}
return mapping;
}
use of org.cytoscape.model.CyNetworkTableManager in project cytoscape-impl by cytoscape.
the class DefaultTableBrowser method handleEvent.
@Override
public void handleEvent(final TableAddedEvent e) {
final CyTable newTable = e.getTable();
if (newTable.isPublic() || showPrivateTables()) {
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
final CyNetworkTableManager netTableManager = serviceRegistrar.getService(CyNetworkTableManager.class);
final CyNetwork curNet = applicationManager.getCurrentNetwork();
if (curNet != null && netTableManager.getTables(curNet, objType).containsValue(newTable)) {
invokeOnEDT(() -> {
if (((DefaultComboBoxModel<CyTable>) getTableChooser().getModel()).getIndexOf(newTable) < 0) {
getTableChooser().addItem(newTable);
getToolBar().updateEnableState(getTableChooser());
}
});
}
}
}
use of org.cytoscape.model.CyNetworkTableManager in project cytoscape-impl by cytoscape.
the class NetworkViewMediator method handleEvent.
@Override
public void handleEvent(final RowsSetEvent e) {
if (loadingSession || getNetworkViewMainPanel().isEmpty())
return;
final CyTable tbl = e.getSource();
final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
final CyNetwork net = netTblMgr.getNetworkForTable(tbl);
final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
// And if there is no related view, nothing needs to be done
if (net != null && netViewMgr.viewExists(net)) {
// Update Network View Title
final Collection<RowSetRecord> nameRecords = e.getColumnRecords(CyNetwork.NAME);
if (!nameRecords.isEmpty())
updateNetworkViewTitle(nameRecords, tbl);
if (tbl.equals(net.getDefaultNodeTable()) || tbl.equals(net.getDefaultEdgeTable())) {
final Collection<CyNetworkView> networkViews = netViewMgr.getNetworkViews(net);
// Update node/edge selection info
final Collection<RowSetRecord> selectedRecords = e.getColumnRecords(CyNetwork.SELECTED);
if (!selectedRecords.isEmpty()) {
for (final CyNetworkView view : networkViews) getNetworkViewMainPanel().updateSelectionInfo(view);
}
// Update views with styles affected by this RowsSetEvent
final Set<CyNetworkView> viewsToUpdate = new HashSet<>();
for (String columnName : e.getColumns()) {
// Reapply locked values that map to changed columns
final boolean lockedValuesApplyed = reapplyLockedValues(columnName, networkViews);
if (lockedValuesApplyed)
viewsToUpdate.addAll(networkViews);
// Find views that had their styles affected by the RowsSetEvent
final Set<VisualStyle> styles = findStylesWithMappedColumn(columnName);
viewsToUpdate.addAll(findNetworkViewsWithStyles(styles));
}
// Update views
for (final CyNetworkView view : viewsToUpdate) updateView(view, null);
}
}
}
use of org.cytoscape.model.CyNetworkTableManager in project cytoscape-impl by cytoscape.
the class ReadCache method getNetworkTables.
/**
* @return All network tables, except DEFAULT_ATTRS and SHARED_DEFAULT_ATTRS ones.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public Set<CyTable> getNetworkTables() {
final Set<CyTable> tables = new HashSet<>();
final Set<CyNetwork> networks = new HashSet<>();
final Class<?>[] types = new Class[] { CyNetwork.class, CyNode.class, CyEdge.class };
if (networkByIdMap.values() != null)
networks.addAll(networkByIdMap.values());
final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
for (final CyNetwork n : networks) {
for (final Class t : types) {
Map<String, CyTable> tblMap = new HashMap<>(netTblMgr.getTables(n, t));
tblMap.remove(CyNetwork.DEFAULT_ATTRS);
if (tblMap != null)
tables.addAll(tblMap.values());
if (n instanceof CySubNetwork) {
// Don't forget the root-network tables.
tblMap = new HashMap<String, CyTable>(netTblMgr.getTables(((CySubNetwork) n).getRootNetwork(), t));
tblMap.remove(CyRootNetwork.DEFAULT_ATTRS);
tblMap.remove(CyRootNetwork.SHARED_DEFAULT_ATTRS);
if (tblMap != null)
tables.addAll(tblMap.values());
}
}
}
return tables;
}
Aggregations