Search in sources :

Example 31 with CyTable

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

the class InvertSelectedNodesTaskTest method testRun.

@Test
public void testRun() throws Exception {
    final CyTable nodeTable = mock(CyTable.class);
    when(net.getDefaultNodeTable()).thenReturn(nodeTable);
    UndoSupport undoSupport = mock(UndoSupport.class);
    // more setup
    when(r3.get("selected", Boolean.class)).thenReturn(false);
    when(r4.get("selected", Boolean.class)).thenReturn(true);
    final CyEventHelper eventHelper = mock(CyEventHelper.class);
    // run the task
    Task t = new InvertSelectedNodesTask(undoSupport, net, networkViewManager, eventHelper);
    t.run(tm);
    // check that the expected rows were set
    verify(r3, times(1)).set("selected", true);
    verify(r4, times(1)).set("selected", false);
}
Also used : CyTable(org.cytoscape.model.CyTable) CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) UndoSupport(org.cytoscape.work.undo.UndoSupport) Test(org.junit.Test)

Example 32 with CyTable

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

the class InvertSelectedEdgesTaskTest method testRun.

@Test
public void testRun() throws Exception {
    final CyTable edgeTable = mock(CyTable.class);
    when(net.getDefaultEdgeTable()).thenReturn(edgeTable);
    UndoSupport undoSupport = mock(UndoSupport.class);
    // more setup
    when(r1.get("selected", Boolean.class)).thenReturn(false);
    when(r2.get("selected", Boolean.class)).thenReturn(true);
    // run the task
    Task t = new InvertSelectedEdgesTask(undoSupport, net, networkViewManager, eventHelper);
    t.run(tm);
    // check that the expected rows were set
    verify(r1, times(1)).set("selected", true);
    verify(r2, times(1)).set("selected", false);
}
Also used : CyTable(org.cytoscape.model.CyTable) Task(org.cytoscape.work.Task) UndoSupport(org.cytoscape.work.undo.UndoSupport) Test(org.junit.Test)

Example 33 with CyTable

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

the class FilterMainPanel method getCyAttributesList.

/**
 * Get the list of attribute names for either "node" or "edge". The attribute names will be
 * prefixed either with "node." or "edge.". Those attributes whose data type is neither
 * "String" nor "numeric" will be excluded
 */
private List<String> getCyAttributesList(final CyNetwork network, final String pType) {
    final Vector<String> attributeList = new Vector<String>();
    CyTable table = null;
    if (pType.equalsIgnoreCase("node") && network.getNodeCount() > 0) {
        table = network.getDefaultNodeTable();
    } else if (pType.equalsIgnoreCase("edge") && network.getEdgeCount() > 0) {
        table = network.getDefaultEdgeTable();
    }
    if (table != null) {
        final Collection<CyColumn> columns = new HashSet<CyColumn>(table.getColumns());
        for (final CyColumn column : columns) {
            if (column != null) {
                // Show all attributes, with type of String or Number
                final Class<?> type = column.getType();
                // only show user visible attributes,with type = Number/String/List
                if (type == Integer.class || type == Double.class || type == Boolean.class || type == String.class || type == List.class) {
                    attributeList.add(pType + "." + column.getName());
                }
            }
        }
        // Alphabetical sort
        final Collator collator = Collator.getInstance(Locale.getDefault());
        Collections.sort(attributeList, collator);
    }
    return attributeList;
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) List(java.util.List) JList(javax.swing.JList) Vector(java.util.Vector) HashSet(java.util.HashSet) Collator(java.text.Collator)

Example 34 with CyTable

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

the class EnhancedSearchIndex method createDocument.

/**
 * Make a Document object with an un-indexed identifier field and indexed
 * attribute fields
 */
private static Document createDocument(CyNetwork network, CyIdentifiable graphObject, String graphObjectType, long index) {
    Document doc = new Document();
    String identifier = Long.toString(index);
    doc.add(new Field(EnhancedSearch.INDEX_FIELD, identifier, Field.Store.YES, Field.Index.ANALYZED));
    doc.add(new Field(EnhancedSearch.TYPE_FIELD, graphObjectType, Field.Store.YES, Field.Index.ANALYZED));
    CyRow cyRow = network.getRow(graphObject);
    CyTable cyDataTable = cyRow.getTable();
    Set<String> attributeNames = CyTableUtil.getColumnNames(cyDataTable);
    for (final String attrName : attributeNames) {
        // Handle whitespace characters and case in attribute names
        String attrIndexingName = EnhancedSearchUtils.replaceWhitespace(attrName);
        attrIndexingName = attrIndexingName.toLowerCase();
        // Determine type
        Class<?> valueType = cyDataTable.getColumn(attrName).getType();
        if (valueType == String.class) {
            String attrValue = network.getRow(graphObject).get(attrName, String.class);
            if (attrValue == null) {
                continue;
            }
            doc.add(new Field(attrIndexingName, attrValue, Field.Store.YES, Field.Index.ANALYZED));
        } else if (valueType == Integer.class) {
            if (network.getRow(graphObject).get(attrName, Integer.class) == null) {
                continue;
            }
            int attrValue = network.getRow(graphObject).get(attrName, Integer.class);
            NumericField field = new NumericField(attrIndexingName);
            field.setIntValue(attrValue);
            doc.add(field);
        } else if (valueType == Double.class) {
            if (network.getRow(graphObject).get(attrName, Double.class) == null) {
                continue;
            }
            double attrValue = network.getRow(graphObject).get(attrName, Double.class);
            NumericField field = new NumericField(attrIndexingName);
            field.setDoubleValue(attrValue);
            doc.add(field);
        } else if (valueType == Boolean.class) {
            if (network.getRow(graphObject).get(attrName, Boolean.class) != null) {
                String attrValue = network.getRow(graphObject).get(attrName, Boolean.class).toString();
                doc.add(new Field(attrIndexingName, attrValue, Field.Store.YES, Field.Index.ANALYZED));
            }
        } else if (valueType == List.class) {
            List attrValueList = network.getRow(graphObject).get(attrName, List.class);
            if (attrValueList != null) {
                for (int j = 0; j < attrValueList.size(); j++) {
                    String attrValue = attrValueList.get(j).toString();
                    doc.add(new Field(attrIndexingName, attrValue, Field.Store.YES, Field.Index.ANALYZED));
                }
            }
        }
    }
    return doc;
}
Also used : Document(org.apache.lucene.document.Document) CyRow(org.cytoscape.model.CyRow) Field(org.apache.lucene.document.Field) NumericField(org.apache.lucene.document.NumericField) CyTable(org.cytoscape.model.CyTable) NumericField(org.apache.lucene.document.NumericField) List(java.util.List)

Example 35 with CyTable

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

the class AttributeFields method initFields.

/**
 * Initialize this object with attribute fields names and their type.
 * Eventually, fields[i] will hold attribute field name and types[i] will hold its type.
 * fields[] and types[] contain both node and edge attributes.
 * ID (INDEX_FIELD) is treated as another attribute of type string.
 * There are probably better ways to do this, but there you go :)
 */
private void initFields(final CyNetwork network) {
    CyTable nodeCyDataTable = network.getDefaultNodeTable();
    for (final CyColumn column : nodeCyDataTable.getColumns()) columnTypeMap.put(EnhancedSearchUtils.replaceWhitespace(column.getName()).toLowerCase(), column.getType());
    CyTable edgeCyDataTable = network.getDefaultEdgeTable();
    for (final CyColumn column : edgeCyDataTable.getColumns()) columnTypeMap.put(EnhancedSearchUtils.replaceWhitespace(column.getName()).toLowerCase(), column.getType());
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn)

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