Search in sources :

Example 6 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.

the class DGraphView method select.

public void select(Collection<? extends CyIdentifiable> nodesOrEdges, Class<? extends CyIdentifiable> type, boolean selected) {
    if (nodesOrEdges.isEmpty())
        return;
    List<RowSetRecord> records = new ArrayList<>();
    CyTable table = type.equals(CyNode.class) ? getModel().getDefaultNodeTable() : getModel().getDefaultEdgeTable();
    // Disable events
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.silenceEventSource(table);
    try {
        for (final CyIdentifiable nodeOrEdge : nodesOrEdges) {
            CyRow row = getModel().getRow(nodeOrEdge);
            row.set(CyNetwork.SELECTED, selected);
            // Add to paylod
            records.add(new RowSetRecord(row, CyNetwork.SELECTED, selected, selected));
        }
    } finally {
        eventHelper.unsilenceEventSource(table);
    }
    // Update the selection before firing the event to prevent race conditions
    updateSelection(type, records);
    // Only now it can fire the RowsSetEvent
    fireRowsSetEvent(table, records, eventHelper);
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyTable(org.cytoscape.model.CyTable) CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 7 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.

the class CyTableTest method testSetWithANonEvaluableCompatibleEquation.

@Test
public void testSetWithANonEvaluableCompatibleEquation() {
    table.createColumn("strings", String.class, false);
    final Map<String, Class<?>> varnameToTypeMap = new HashMap<String, Class<?>>();
    varnameToTypeMap.put("a", String.class);
    compiler.compile("=$a&\"one\"", varnameToTypeMap);
    final Equation eqn = compiler.getEquation();
    attrs.set("strings", eqn);
    Object last = eventHelper.getLastPayload();
    assertNotNull(last);
    assertTrue(last instanceof RowSetRecord);
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) HashMap(java.util.HashMap) Equation(org.cytoscape.equations.Equation) Test(org.junit.Test)

Example 8 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.

the class CyTableImpl method fireVirtualColumnRowSetEvent.

private void fireVirtualColumnRowSetEvent(CyTableImpl table, Object key, String columnName, Object newValue, Object newRawValue, Set<VirtualColumnInfo> seen) {
    // Fire an event for this table
    CyRow row = table.getRowNoCreate(key);
    if (row == null) {
        return;
    }
    eventHelper.addEventPayload((CyTable) table, new RowSetRecord(row, columnName, newValue, newRawValue), RowsSetEvent.class);
    // ...then fire events for all dependents
    Set<CyColumn> columnDependents;
    synchronized (lock) {
        String normalizedColumnName = normalizeColumnName(columnName);
        columnDependents = dependents.get(normalizedColumnName);
        if (columnDependents == null) {
            return;
        }
    }
    for (CyColumn dependent : columnDependents) {
        VirtualColumnInfo info = dependent.getVirtualColumnInfo();
        if (seen.contains(info)) {
            continue;
        }
        seen.add(info);
        CyTableImpl table2 = (CyTableImpl) dependent.getTable();
        String targetJoinKey = info.getTargetJoinKey();
        if (targetJoinKey.equals(table2.getPrimaryKey().getName())) {
            fireVirtualColumnRowSetEvent(table2, key, dependent.getName(), newValue, newRawValue, seen);
        } else {
            String normalizedTargetJoinKey = table2.normalizeColumnName(targetJoinKey);
            ColumnData keyToValueMap = table2.attributes.get(normalizedTargetJoinKey);
            if (keyToValueMap != null) {
                for (Object key2 : keyToValueMap.keySet()) {
                    if (keyToValueMap.get(key2).equals(key)) {
                        fireVirtualColumnRowSetEvent(table2, key2, dependent.getName(), newValue, newRawValue, seen);
                    }
                }
            }
        }
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyColumn(org.cytoscape.model.CyColumn) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) ColumnData(org.cytoscape.model.internal.column.ColumnData) CyRow(org.cytoscape.model.CyRow)

Example 9 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord 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 10 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord 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)

Aggregations

RowSetRecord (org.cytoscape.model.events.RowSetRecord)26 CyTable (org.cytoscape.model.CyTable)11 CyNetwork (org.cytoscape.model.CyNetwork)8 ArrayList (java.util.ArrayList)6 CyRow (org.cytoscape.model.CyRow)6 RowsSetEvent (org.cytoscape.model.events.RowsSetEvent)6 Test (org.junit.Test)6 CyNode (org.cytoscape.model.CyNode)5 CyNetworkView (org.cytoscape.view.model.CyNetworkView)5 CyColumn (org.cytoscape.model.CyColumn)4 CyIdentifiable (org.cytoscape.model.CyIdentifiable)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Equation (org.cytoscape.equations.Equation)3 CyEdge (org.cytoscape.model.CyEdge)3 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)3 ColumnData (org.cytoscape.model.internal.column.ColumnData)3 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)3 List (java.util.List)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)2