use of org.cytoscape.equations.EquationCompiler in project cytoscape-impl by cytoscape.
the class TableTestSupportTest method setUp.
@Before
public void setUp() {
eventHelper = support.getDummyCyEventHelper();
EquationCompiler compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
table = factory.createTable(Integer.toString(rand.nextInt(10000)), CyIdentifiable.SUID, Long.class, false, true);
table2 = factory.createTable(Integer.toString(rand.nextInt(10000)), CyIdentifiable.SUID, Long.class, false, true);
attrs = table.getRow(1l);
CyTableManagerImpl tblMgr = new CyTableManagerImpl(new CyNetworkTableManagerImpl(), new CyNetworkManagerImpl(serviceRegistrar), serviceRegistrar);
tblMgr.addTable(table);
((CyTableImpl) table).handleEvent(new TableAddedEvent(tblMgr, table));
tblMgr.addTable(table2);
((CyTableImpl) table2).handleEvent(new TableAddedEvent(tblMgr, table2));
}
use of org.cytoscape.equations.EquationCompiler in project cytoscape-impl by cytoscape.
the class AbstractTableBrowser method createBrowserTable.
private BrowserTable createBrowserTable() {
BrowserTable browserTable;
final EquationCompiler compiler = serviceRegistrar.getService(EquationCompiler.class);
browserTable = new BrowserTable(compiler, popupMenuHelper, serviceRegistrar);
BrowserTableModel model = new BrowserTableModel(currentTable, currentTableType, compiler);
browserTable.setModel(model);
synchronized (lock) {
browserTables.put(currentTable, browserTable);
}
serviceRegistrar.registerAllServices(browserTable, new Properties());
serviceRegistrar.registerAllServices(model, new Properties());
browserTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
browserTable.setModel(model);
// move and hide SUID and selected by default
final List<String> attrList = model.getAllAttributeNames();
BrowserTableColumnModel columnModel = (BrowserTableColumnModel) browserTable.getColumnModel();
if (attrList.contains(CyNetwork.SUID))
columnModel.moveColumn(browserTable.convertColumnIndexToView(model.mapColumnNameToColumnIndex(CyNetwork.SUID)), 0);
if (attrList.contains(CyNetwork.SELECTED))
columnModel.moveColumn(browserTable.convertColumnIndexToView(model.mapColumnNameToColumnIndex(CyNetwork.SELECTED)), 1);
attrList.remove(CyNetwork.SUID);
attrList.remove(CyNetwork.SELECTED);
browserTable.setVisibleAttributeNames(attrList);
// So the drop event can go straight through the table to the drop target associated with this panel
if (browserTable.getDropTarget() != null)
browserTable.getDropTarget().setActive(false);
ColumnResizer.adjustColumnPreferredWidths(browserTable, false);
update();
return browserTable;
}
use of org.cytoscape.equations.EquationCompiler in project cytoscape-impl by cytoscape.
the class CSVCyReader method createTable.
CyTable createTable(CSVReader reader, TableInfo info) throws IOException, SecurityException {
final ColumnInfo[] columns = info.getColumns();
final CyTableFactory tableFactory = serviceRegistrar.getService(CyTableFactory.class);
final CyTable table = tableFactory.createTable(info.getTitle(), columns[0].getName(), columns[0].getType(), info.isPublic(), true);
final Map<String, Class<?>> variableNameToTypeMap = new HashMap<>();
for (final ColumnInfo colInfo : columns) variableNameToTypeMap.put(colInfo.getName(), colInfo.getType() == Integer.class ? Long.class : colInfo.getType());
for (int i = 1; i < columns.length; i++) {
ColumnInfo column = columns[i];
Class<?> type = column.getType();
if (type.equals(List.class)) {
table.createListColumn(column.getName(), column.getListElementType(), !column.isMutable());
} else {
table.createColumn(column.getName(), type, !column.isMutable());
}
}
final EquationCompiler compiler = serviceRegistrar.getService(EquationCompiler.class);
String[] values = reader.readNext();
while (values != null) {
if (isCanceled)
return null;
Object key = parseValue(columns[0].getType(), null, values[0]);
CyRow row = table.getRow(key);
for (int i = 1; i < values.length; i++) {
ColumnInfo column = columns[i];
String name = column.getName();
final Class<?> columnType = column.getType();
final Class<?> columnListElementType = column.getListElementType();
if (handleEquations && values[i].startsWith("=")) {
final Class<?> expectedType = variableNameToTypeMap.remove(name);
try {
final Equation equation;
final Class<?> eqnType;
if (compiler.compile(values[i], variableNameToTypeMap)) {
eqnType = compiler.getEquation().getType();
if (EquationUtil.eqnTypeIsCompatible(columnType, columnListElementType, eqnType))
equation = compiler.getEquation();
else {
final String errorMsg = "Equation result type is " + EquationUtil.getUnqualifiedName(eqnType) + ", column type is " + EquationUtil.getUnqualifiedName(columnType) + ".";
equation = compiler.getErrorEquation(values[i], expectedType, errorMsg);
}
} else {
equation = compiler.getErrorEquation(values[i], expectedType, compiler.getLastErrorMsg());
}
row.set(name, equation);
} catch (final Exception e) {
throw new IOException(e.getMessage(), e.getCause());
}
variableNameToTypeMap.put(name, expectedType);
} else {
Object value = parseValue(columnType, columnListElementType, values[i]);
if (value != null)
row.set(name, value);
}
}
values = reader.readNext();
}
return table;
}
Aggregations