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;
}
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;
}
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();
}
}
Aggregations