Search in sources :

Example 11 with EquationCompiler

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));
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) CyNetworkManagerImpl(org.cytoscape.model.internal.CyNetworkManagerImpl) CyNetworkTableManagerImpl(org.cytoscape.model.internal.CyNetworkTableManagerImpl) TableAddedEvent(org.cytoscape.model.events.TableAddedEvent) EquationCompiler(org.cytoscape.equations.EquationCompiler) CyTableManagerImpl(org.cytoscape.model.internal.CyTableManagerImpl) CyTableImpl(org.cytoscape.model.internal.CyTableImpl) Before(org.junit.Before)

Example 12 with EquationCompiler

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;
}
Also used : EquationCompiler(org.cytoscape.equations.EquationCompiler) Properties(java.util.Properties)

Example 13 with EquationCompiler

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;
}
Also used : HashMap(java.util.HashMap) Equation(org.cytoscape.equations.Equation) IOException(java.io.IOException) CyRow(org.cytoscape.model.CyRow) IOException(java.io.IOException) CyTableFactory(org.cytoscape.model.CyTableFactory) CyTable(org.cytoscape.model.CyTable) EquationCompiler(org.cytoscape.equations.EquationCompiler)

Aggregations

EquationCompiler (org.cytoscape.equations.EquationCompiler)13 CyTable (org.cytoscape.model.CyTable)5 Equation (org.cytoscape.equations.Equation)4 EquationCompilerImpl (org.cytoscape.equations.internal.EquationCompilerImpl)4 EquationParserImpl (org.cytoscape.equations.internal.EquationParserImpl)4 CyRow (org.cytoscape.model.CyRow)4 Before (org.junit.Before)4 HashMap (java.util.HashMap)3 Interpreter (org.cytoscape.equations.Interpreter)3 InterpreterImpl (org.cytoscape.equations.internal.interpreter.InterpreterImpl)3 CyNetworkManagerImpl (org.cytoscape.model.internal.CyNetworkManagerImpl)3 CyNetworkTableManagerImpl (org.cytoscape.model.internal.CyNetworkTableManagerImpl)3 CyTableManagerImpl (org.cytoscape.model.internal.CyTableManagerImpl)3 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)3 Map (java.util.Map)2 DummyCyEventHelper (org.cytoscape.event.DummyCyEventHelper)2 CyColumn (org.cytoscape.model.CyColumn)2 CyTableFactoryImpl (org.cytoscape.model.internal.CyTableFactoryImpl)2 Font (java.awt.Font)1 ActionEvent (java.awt.event.ActionEvent)1