Search in sources :

Example 16 with CyNetworkTableManager

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;
}
Also used : CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) CyColumn(org.cytoscape.model.CyColumn) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 17 with CyNetworkTableManager

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());
                }
            });
        }
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) CyNetwork(org.cytoscape.model.CyNetwork)

Example 18 with CyNetworkTableManager

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);
        }
    }
}
Also used : CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyNetwork(org.cytoscape.model.CyNetwork) CyTable(org.cytoscape.model.CyTable) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 19 with CyNetworkTableManager

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;
}
Also used : CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) CyTable(org.cytoscape.model.CyTable) CyNode(org.cytoscape.model.CyNode) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) HashSet(java.util.HashSet)

Aggregations

CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)19 CyNetwork (org.cytoscape.model.CyNetwork)15 CyTable (org.cytoscape.model.CyTable)13 CyApplicationManager (org.cytoscape.application.CyApplicationManager)8 HashSet (java.util.HashSet)7 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)6 CyIdentifiable (org.cytoscape.model.CyIdentifiable)5 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)4 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)4 ContinuousMapping (org.cytoscape.view.vizmap.mappings.ContinuousMapping)4 RowSetRecord (org.cytoscape.model.events.RowSetRecord)3 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)3 CyNetworkView (org.cytoscape.view.model.CyNetworkView)3 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 WeakHashMap (java.util.WeakHashMap)2 CyGroupFactory (org.cytoscape.group.CyGroupFactory)2 CyGroupManager (org.cytoscape.group.CyGroupManager)2 CyColumn (org.cytoscape.model.CyColumn)2