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