Search in sources :

Example 71 with CyTable

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

the class LoadMultipleNetworksTask method getTargetColumns.

private final ListSingleSelection<String> getTargetColumns(final CyNetwork network) {
    final CyTable selectedTable = network.getTable(CyNode.class, CyRootNetwork.SHARED_ATTRS);
    final List<String> colNames = new ArrayList<>();
    for (CyColumn col : selectedTable.getColumns()) {
        // Exclude SUID from the mapping key list
        if (!col.getName().equalsIgnoreCase(CyIdentifiable.SUID) && !col.getName().endsWith(".SUID") && (col.getType() == String.class || col.getType() == Integer.class || col.getType() == Long.class))
            colNames.add(col.getName());
    }
    if (colNames.isEmpty() || (colNames.size() == 1 && colNames.contains(CyRootNetwork.SHARED_NAME)))
        return new ListSingleSelection<>();
    sort(colNames);
    return new ListSingleSelection<>(colNames);
}
Also used : CyTable(org.cytoscape.model.CyTable) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn)

Example 72 with CyTable

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

the class ModelMonitor method checkType.

public boolean checkType(String name, Class<?> columnType, Class<?> targetType) {
    synchronized (lock) {
        if (network == null) {
            return false;
        }
        CyTable table = getTable(columnType);
        if (table == null) {
            return false;
        }
        CyColumn column = table.getColumn(name);
        if (column == null) {
            return false;
        }
        Class<?> type = column.getType();
        if (List.class.equals(type)) {
            return targetType.equals(column.getListElementType());
        }
        return targetType.equals(type);
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn)

Example 73 with CyTable

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

the class ModelMonitor method updateColumnSliders.

private void updateColumnSliders() {
    for (ColumnFilterController controller : columnViews.values()) {
        ColumnFilter filter = controller.getFilter();
        Class<? extends CyIdentifiable> columnType = filter.getTableType();
        Number[] range;
        String name = filter.getColumnName();
        if (name == null) {
            continue;
        }
        CyTable table;
        if (CyNode.class.equals(columnType)) {
            table = network.getDefaultNodeTable();
            range = getColumnRange(table, name, nodeColumnRanges);
        } else if (CyEdge.class.equals(columnType)) {
            table = network.getDefaultEdgeTable();
            range = getColumnRange(table, name, edgeColumnRanges);
        } else {
            continue;
        }
        CyColumn column = table.getColumn(name);
        if (column == null) {
            continue;
        }
        Class<?> type = column.getType();
        if (List.class.equals(type)) {
            type = column.getListElementType();
        }
        if (Integer.class.equals(type) || Long.class.equals(type)) {
            controller.setSliderBounds(range[0].longValue(), range[1].longValue());
        } else {
            controller.setSliderBounds(range[0].doubleValue(), range[1].doubleValue());
        }
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) ColumnFilterController(org.cytoscape.filter.internal.filters.column.ColumnFilterController) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) CyEdge(org.cytoscape.model.CyEdge)

Example 74 with CyTable

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

the class ModelMonitor method handleEvent.

@Override
public void handleEvent(ColumnNameChangedEvent event) {
    synchronized (lock) {
        if (network == null) {
            return;
        }
        CyTable nodeTable = network.getDefaultNodeTable();
        CyTable edgeTable = network.getDefaultEdgeTable();
        CyTable table = event.getSource();
        CyColumn column = table.getColumn(event.getNewColumnName());
        Class<?> type;
        if (table == nodeTable) {
            type = CyNode.class;
        } else if (table == edgeTable) {
            type = CyEdge.class;
        } else {
            return;
        }
        for (int i = 0; i < columnNames.size(); i++) {
            ColumnElement element = columnNames.get(i);
            if (element.getName().equals(event.getOldColumnName()) && type.equals(element.getTableType())) {
                columnNames.remove(i);
                columnNames.add(new ColumnElement(element.getTableType(), column));
                break;
            }
        }
        Collections.sort(columnNames);
        updateColumnViews();
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) ColumnElement(org.cytoscape.filter.internal.filters.column.ColumnElement) CyEdge(org.cytoscape.model.CyEdge)

Example 75 with CyTable

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

the class ColumnFilter method validate.

@Override
public List<ValidationWarning> validate(CyNetwork context) {
    if (context == null)
        return Collections.emptyList();
    CyTable table;
    String tableType;
    Class<?> type = getTableType();
    if (CyNode.class.equals(type)) {
        table = context.getDefaultNodeTable();
        tableType = "Node";
    } else if (CyEdge.class.equals(type)) {
        table = context.getDefaultEdgeTable();
        tableType = "Edge";
    } else {
        return Collections.emptyList();
    }
    if (columnName != null) {
        CyColumn column = table.getColumn(columnName);
        if (column == null) {
            return warn(tableType + " table does not have column <b>\"" + columnName + "\"</b>");
        }
    }
    if (rawCriterion == null || predicate == null) {
        // This filter is incomplete.
        return Collections.emptyList();
    }
    CyColumn column = table.getColumn(columnName);
    Class<?> columnType = column.getType();
    if (columnType.equals(List.class)) {
        columnType = column.getListElementType();
    }
    if (String.class.equals(columnType) && stringCriterion == null) {
        return warn("Column <b>\"" + columnName + "\"</b> in " + tableType + " table is not a String column");
    } else if (Number.class.isAssignableFrom(columnType) && (lowerBound == null || upperBound == null)) {
        return warn("Column <b>\"" + columnName + "\"</b> in " + tableType + " table is not a Numeric column");
    } else if (Boolean.class.equals(columnType) && booleanCriterion == null) {
        return warn("Column <b>\"" + columnName + "\"</b> in " + tableType + " table is not a Boolean column");
    }
    return Collections.emptyList();
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) CyEdge(org.cytoscape.model.CyEdge)

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