Search in sources :

Example 61 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class VirtualColumnAdder method handleEvent.

public void handleEvent(ColumnCreatedEvent e) {
    CyTable src = e.getSource();
    List<CyTable> targets;
    synchronized (lock) {
        targets = tables.get(src);
    }
    String srcName = e.getColumnName();
    CyColumn srcCol = src.getColumn(srcName);
    for (CyTable tgt : targets) tgt.addVirtualColumn(srcName, srcName, src, CyIdentifiable.SUID, srcCol.isImmutable());
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn)

Example 62 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class CyTableImpl method setListX.

private final void setListX(final Object key, final String columnName, final Object value) {
    Object newValue;
    final Object rawValue;
    synchronized (lock) {
        final String normalizedColName = normalizeColumnName(columnName);
        final CyColumn column = types.get(normalizedColName);
        CyRow row = rows.get(key);
        final Class<?> type = column.getListElementType();
        if (value instanceof CyListImpl) {
            rawValue = value;
        } else if (value instanceof List) {
            final List list = (List) value;
            if (!list.isEmpty())
                checkType(list.get(0));
            List<?> listData = columnFactory.createList(type, list);
            rawValue = new CyListImpl(type, listData, eventHelper, row, column, this);
        } else if (!(value instanceof Equation)) {
            throw new IllegalArgumentException("value is a " + value.getClass().getName() + " and not a List for column '" + columnName + "'.");
        } else if (!EqnSupport.listEquationIsCompatible((Equation) value, type)) {
            throw new IllegalArgumentException("value is not a List equation of a compatible type for column '" + columnName + "'.");
        } else {
            rawValue = value;
        }
        final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
        if (virtColumn != null) {
            virtColumn.setValue(key, rawValue);
            newValue = virtColumn.getListValue(key);
        } else {
            ColumnData keyToValueMap = attributes.get(normalizedColName);
            // TODO this is an implicit addRow - not sure if we want to refactor this or not
            keyToValueMap.put(key, rawValue);
            if (rawValue instanceof Equation) {
                final StringBuilder errorMsg = new StringBuilder();
                newValue = EqnSupport.evalEquation((Equation) rawValue, suid, interpreter, currentlyActiveAttributes, columnName, errorMsg, this);
                lastInternalError = errorMsg.toString();
            } else {
                newValue = rawValue;
            }
        }
    }
    if (fireEvents)
        eventHelper.addEventPayload((CyTable) this, new RowSetRecord(getRow(key), columnName, newValue, rawValue), RowsSetEvent.class);
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyColumn(org.cytoscape.model.CyColumn) Equation(org.cytoscape.equations.Equation) ColumnData(org.cytoscape.model.internal.column.ColumnData) CyRow(org.cytoscape.model.CyRow) RowsSetEvent(org.cytoscape.model.events.RowsSetEvent) CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) List(java.util.List)

Example 63 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class ControlPanel method handleEvent.

@Override
public void handleEvent(RowsSetEvent e) {
    if (loadingSession)
        return;
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final CyNetworkView currentView = appMgr.getCurrentNetworkView();
    if (currentView == null)
        return;
    final CyTable tbl = e.getSource();
    final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
    final CyNetwork net = netTblMgr.getNetworkForTable(tbl);
    if (net == null || !net.equals(currentView.getModel()) || !tbl.equals(net.getDefaultNodeTable()))
        return;
    final Collection<RowSetRecord> selectedRecords = e.getColumnRecords(CyNetwork.SELECTED);
    if (!selectedRecords.isEmpty())
        updatePanels();
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 64 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class FitLabelMappingGenerator method generateMap.

@Override
public <T> Map<T, V> generateMap(final Set<T> tableValues) {
    // Generate map for the current network view.
    final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
    final CyNetworkView networkView = appMgr.getCurrentNetworkView();
    // If current view is not available, simply return empty map.
    if (networkView == null)
        return Collections.emptyMap();
    // If given set is empty, return empty map.
    if (tableValues == null || tableValues.isEmpty())
        return Collections.emptyMap();
    // This only works with NAME column.
    final T testName = tableValues.iterator().next();
    if (testName instanceof String == false)
        throw new IllegalArgumentException("This generator only works with 'name' column.");
    final CyNetwork network = networkView.getModel();
    final CyTable nodeTable = networkView.getModel().getDefaultNodeTable();
    final VisualMappingManager vmMgr = servicesUtil.get(VisualMappingManager.class);
    final VisualStyle style = vmMgr.getCurrentVisualStyle();
    // Check label size mapping exists or not
    final VisualMappingFunction<?, Integer> fontSizeMapping = style.getVisualMappingFunction(BasicVisualLexicon.NODE_LABEL_FONT_SIZE);
    // Use default label width for checking.  TODO: should we use mapping?
    final Double maxLabelWidth = style.getDefaultValue(BasicVisualLexicon.NODE_LABEL_WIDTH);
    final Map<T, V> valueMap = new HashMap<T, V>();
    for (final T attrVal : tableValues) {
        final Collection<CyRow> rows = nodeTable.getMatchingRows(CyNetwork.NAME, attrVal);
        CyRow row = null;
        if (rows.isEmpty() == false)
            row = rows.iterator().next();
        else
            continue;
        final Long suid = row.get(CyIdentifiable.SUID, Long.class);
        final View<CyNode> nodeView = networkView.getNodeView(network.getNode(suid));
        if (nodeView == null)
            continue;
        final String labelText = nodeView.getVisualProperty(BasicVisualLexicon.NODE_LABEL);
        final int textLen = labelText.length();
        final int fontSize;
        if (fontSizeMapping == null)
            fontSize = style.getDefaultValue(BasicVisualLexicon.NODE_LABEL_FONT_SIZE);
        else
            fontSize = nodeView.getVisualProperty(BasicVisualLexicon.NODE_LABEL_FONT_SIZE);
        final Double width = fontSize * textLen * 0.7;
        if (maxLabelWidth > width)
            valueMap.put(attrVal, (V) width);
        else
            valueMap.put(attrVal, (V) maxLabelWidth);
    }
    return valueMap;
}
Also used : HashMap(java.util.HashMap) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 65 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class C2CEditor method setValue.

@Override
@SuppressWarnings("unchecked")
public void setValue(final Object value) {
    if (value instanceof ContinuousMapping == false)
        throw new IllegalArgumentException("Value should be ContinuousMapping: this is " + value);
    final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
    final CyNetwork currentNetwork = appMgr.getCurrentNetwork();
    if (currentNetwork == null)
        return;
    mapping = (ContinuousMapping<K, V>) value;
    Class<? extends CyIdentifiable> type = (Class<? extends CyIdentifiable>) mapping.getVisualProperty().getTargetDataType();
    final CyNetworkTableManager netTblMgr = servicesUtil.get(CyNetworkTableManager.class);
    final CyTable attr = netTblMgr.getTable(appMgr.getCurrentNetwork(), type, CyNetwork.DEFAULT_ATTRS);
    final VisualMappingManager vmMgr = servicesUtil.get(VisualMappingManager.class);
    editorPanel = new C2CMappingEditorPanel<K, V>(vmMgr.getCurrentVisualStyle(), mapping, attr, servicesUtil);
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Aggregations

CyTable (org.cytoscape.model.CyTable)282 CyNetwork (org.cytoscape.model.CyNetwork)79 CyRow (org.cytoscape.model.CyRow)73 CyColumn (org.cytoscape.model.CyColumn)71 ArrayList (java.util.ArrayList)55 CyNode (org.cytoscape.model.CyNode)43 CyEdge (org.cytoscape.model.CyEdge)35 Test (org.junit.Test)29 List (java.util.List)26 HashMap (java.util.HashMap)24 CyApplicationManager (org.cytoscape.application.CyApplicationManager)19 HashSet (java.util.HashSet)18 CyIdentifiable (org.cytoscape.model.CyIdentifiable)14 CyNetworkView (org.cytoscape.view.model.CyNetworkView)14 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)13 RowSetRecord (org.cytoscape.model.events.RowSetRecord)11 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)11 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)11 CyEventHelper (org.cytoscape.event.CyEventHelper)10 CyTableManager (org.cytoscape.model.CyTableManager)10