Search in sources :

Example 6 with GenericIndex

use of org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex in project cytoscape-impl by cytoscape.

the class QuickFindImpl method createIndex.

/**
 * Creates appropriate index, based on attribute type.
 * @param indexType             QuickFind.INDEX_NODES or QuickFind.INDEX_EDGES
 * @param attributeType         CyAttributes type.
 * @param controllingAttribute  Controlling attribute.
 * @return GenericIndex Object.
 */
private GenericIndex createIndex(int indexType, Class<?> attributeType, String controllingAttribute) {
    GenericIndex index;
    // If all the values for the controllingAttribute are NULL, return null
    String _type = "node";
    if (indexType == QuickFind.INDEX_EDGES) {
        _type = "edge";
    }
    // 
    if ((attributeType == Integer.class) || (attributeType == Double.class)) {
        index = IndexFactory.createDefaultNumberIndex(indexType);
    } else {
        index = IndexFactory.createDefaultTextIndex(indexType);
    }
    index.setControllingAttribute(controllingAttribute);
    return index;
}
Also used : GenericIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex)

Example 7 with GenericIndex

use of org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex in project cytoscape-impl by cytoscape.

the class QuickFindImpl method reindexNetwork.

@Override
public synchronized GenericIndex reindexNetwork(CyNetwork cyNetwork, int indexType, String controllingAttribute, TaskMonitor taskMonitor) {
    // If all the values for the controllingAttribute are NULL, return null
    CyTable table;
    if (indexType == QuickFind.INDEX_NODES) {
        if (cyNetwork.getNodeCount() == 0) {
            return null;
        }
        table = cyNetwork.getDefaultNodeTable();
    } else if (indexType == QuickFind.INDEX_EDGES) {
        if (cyNetwork.getEdgeCount() == 0) {
            return null;
        }
        table = cyNetwork.getDefaultEdgeTable();
    } else {
        return null;
    }
    if (controllingAttribute.equalsIgnoreCase(QuickFind.UNIQUE_IDENTIFIER) || controllingAttribute.equalsIgnoreCase(QuickFind.INDEX_ALL_ATTRIBUTES) || controllingAttribute.equalsIgnoreCase("biopax.node_label")) {
    // do nothing
    } else if (isNullAttribute(table, controllingAttribute)) {
        return null;
    }
    // 
    Date start = new Date();
    if ((indexType != QuickFind.INDEX_NODES) && (indexType != QuickFind.INDEX_EDGES)) {
        throw new IllegalArgumentException("indexType must be set to: " + "QuickFind.INDEX_NODES or QuickFind.INDEX_EDGES");
    }
    // Notify all listeners of index start event
    for (int i = 0; i < listenerList.size(); i++) {
        QuickFindListener listener = (QuickFindListener) listenerList.get(i);
        listener.indexingStarted(cyNetwork, indexType, controllingAttribute);
    }
    // Determine maxProgress
    currentProgress = 0;
    maxProgress = 0;
    if (controllingAttribute.equals(QuickFind.INDEX_ALL_ATTRIBUTES)) {
        for (final CyColumn column : table.getColumns()) maxProgress += getGraphObjectCount(cyNetwork, indexType);
    } else
        maxProgress = getGraphObjectCount(cyNetwork, indexType);
    GenericIndex index = null;
    if (controllingAttribute.equals(QuickFind.INDEX_ALL_ATTRIBUTES)) {
        // Option 1:  Index all attributes
        index = createIndex(indexType, String.class, controllingAttribute);
        for (final CyColumn column : table.getColumns()) {
            final String attributeName = column.getName();
            indexNetwork(cyNetwork, indexType, String.class, attributeName, index, taskMonitor);
        }
    } else {
        // Option 2:  Index single attribute.
        // Create appropriate index type, based on attribute type.
        CyColumn column = table.getColumn(controllingAttribute);
        Class<?> attributeType;
        if (column == null) {
            attributeType = String.class;
        } else {
            attributeType = column.getType();
        }
        index = createIndex(indexType, attributeType, controllingAttribute);
        indexNetwork(cyNetwork, indexType, attributeType, controllingAttribute, index, taskMonitor);
    }
    networkMap.put(cyNetwork, index);
    // Notify all listeners of index end event
    for (int i = 0; i < listenerList.size(); i++) {
        QuickFindListener listener = (QuickFindListener) listenerList.get(i);
        listener.indexingEnded();
    }
    Date stop = new Date();
    long duration = stop.getTime() - start.getTime();
    // System.out.println("Time to re-index:  " + duration + " ms");
    return index;
}
Also used : CyTable(org.cytoscape.model.CyTable) GenericIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex) CyColumn(org.cytoscape.model.CyColumn) Date(java.util.Date)

Example 8 with GenericIndex

use of org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex in project cytoscape-impl by cytoscape.

the class QuickFindImpl method addNetwork.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void addNetwork(CyNetwork network, TaskMonitor taskMonitor) {
    // check args - short circuit if necessary
    if (network.getNodeCount() == 0)
        return;
    // Use default index specified by network, if available.
    // Otherwise, index by UNIQUE_IDENTIFIER.
    String controllingAttribute = network.getRow(network).get(QuickFind.DEFAULT_INDEX, String.class);
    CyTable nodeTable = network.getDefaultNodeTable();
    if (controllingAttribute == null) {
        if (nodeTable.getColumn("bioPax.node_label") != null)
            controllingAttribute = "biopax.node_label";
        else
            controllingAttribute = QuickFind.UNIQUE_IDENTIFIER;
    }
    if (controllingAttribute.equalsIgnoreCase(QuickFind.UNIQUE_IDENTIFIER) || controllingAttribute.equalsIgnoreCase(QuickFind.INDEX_ALL_ATTRIBUTES) || controllingAttribute.equalsIgnoreCase("biopax.node_label"))
        /* Do nothing. */
        ;
    else if (isNullAttribute(nodeTable, controllingAttribute))
        return;
    // Determine maxProgress
    currentProgress = 0;
    maxProgress = getGraphObjectCount(network, QuickFind.INDEX_NODES);
    // Notify all listeners of add event
    for (int i = 0; i < listenerList.size(); i++) {
        QuickFindListener listener = (QuickFindListener) listenerList.get(i);
        listener.networkAddedToIndex(network);
    }
    // Notify all listeners of index start event
    for (int i = 0; i < listenerList.size(); i++) {
        QuickFindListener listener = (QuickFindListener) listenerList.get(i);
        listener.indexingStarted(network, QuickFind.INDEX_NODES, controllingAttribute);
    }
    // Create Appropriate Index Type, based on attribute type.
    CyColumn column = nodeTable.getColumn(controllingAttribute);
    Class<?> attributeType;
    if (column == null) {
        attributeType = String.class;
    } else {
        attributeType = column.getType();
    }
    GenericIndex index = createIndex(QuickFind.INDEX_NODES, attributeType, controllingAttribute);
    indexNetwork(network, QuickFind.INDEX_NODES, attributeType, controllingAttribute, index, taskMonitor);
    networkMap.put(network, index);
    // Notify all listeners of end index event
    for (int i = 0; i < listenerList.size(); i++) {
        QuickFindListener listener = (QuickFindListener) listenerList.get(i);
        listener.indexingEnded();
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) GenericIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex) CyColumn(org.cytoscape.model.CyColumn)

Aggregations

GenericIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex)8 NumberIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex)3 CyNetwork (org.cytoscape.model.CyNetwork)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TaskMonitorBase (org.cytoscape.filter.internal.quickfind.util.TaskMonitorBase)2 CyColumn (org.cytoscape.model.CyColumn)2 CyTable (org.cytoscape.model.CyTable)2 Date (java.util.Date)1 NumberRangeModel (org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNode (org.cytoscape.model.CyNode)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 View (org.cytoscape.view.model.View)1 VisualLexicon (org.cytoscape.view.model.VisualLexicon)1 RenderingEngine (org.cytoscape.view.presentation.RenderingEngine)1 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)1