Search in sources :

Example 1 with EquationCompiler

use of org.cytoscape.equations.EquationCompiler in project cytoscape-impl by cytoscape.

the class Cy3SessionReaderImpl method restoreEquations.

private void restoreEquations() {
    final EquationCompiler compiler = serviceRegistrar.getService(EquationCompiler.class);
    for (CyNetwork network : networkLookup.values()) {
        EquationUtil.refreshEquations(network.getDefaultNetworkTable(), compiler);
        EquationUtil.refreshEquations(network.getDefaultNodeTable(), compiler);
        EquationUtil.refreshEquations(network.getDefaultEdgeTable(), compiler);
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) EquationCompiler(org.cytoscape.equations.EquationCompiler)

Example 2 with EquationCompiler

use of org.cytoscape.equations.EquationCompiler in project cytoscape-impl by cytoscape.

the class ClearErrorsEdit method run.

@Override
public void run(final TaskMonitor tm) throws Exception {
    final CyTable table = column.getTable();
    final EquationCompiler compiler = serviceRegistrar.getService(EquationCompiler.class);
    final List<ErrorEquation> errorEquations = new ArrayList<>();
    for (CyRow row : table.getAllRows()) {
        if (cancelled)
            return;
        final Object raw = row.getRaw(column.getName());
        if (raw instanceof Equation) {
            final Equation eq = (Equation) raw;
            final boolean success = compiler.compile(eq.toString(), TableBrowserUtil.getAttNameToTypeMap(table, null));
            // TODO: success is incorrectly set to yes on broken equations [=ABS(String)]
            if (!success || row.get(column.getName(), column.getType()) == null)
                errorEquations.add(new ErrorEquation(row, column.getName(), eq));
        }
    }
    for (ErrorEquation err : errorEquations) {
        if (cancelled) {
            restoreDeletedEquations();
            return;
        }
        deletedEquations.add(err);
        err.clear();
    }
    if (!deletedEquations.isEmpty()) {
        final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
        undoSupport.postEdit(new ClearErrorsEdit(column.getName(), deletedEquations));
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) Equation(org.cytoscape.equations.Equation) EquationCompiler(org.cytoscape.equations.EquationCompiler) CyRow(org.cytoscape.model.CyRow) UndoSupport(org.cytoscape.work.undo.UndoSupport)

Example 3 with EquationCompiler

use of org.cytoscape.equations.EquationCompiler in project cytoscape-impl by cytoscape.

the class ClearAllErrorsTaskFactory method isReady.

@Override
public boolean isReady(final CyColumn column) {
    final CyTable table = column.getTable();
    final EquationCompiler compiler = serviceRegistrar.getService(EquationCompiler.class);
    for (CyRow row : table.getAllRows()) {
        final Object raw = row.getRaw(column.getName());
        if (raw instanceof Equation) {
            final Equation eq = (Equation) raw;
            final boolean success = compiler.compile(eq.toString(), TableBrowserUtil.getAttNameToTypeMap(table, null));
            // TODO: success is incorrectly set to yes on broken equations [=ABS(String)]
            if (!success || row.get(column.getName(), column.getType()) == null)
                return true;
        }
    }
    return false;
}
Also used : CyTable(org.cytoscape.model.CyTable) Equation(org.cytoscape.equations.Equation) EquationCompiler(org.cytoscape.equations.EquationCompiler) CyRow(org.cytoscape.model.CyRow)

Example 4 with EquationCompiler

use of org.cytoscape.equations.EquationCompiler in project cytoscape-impl by cytoscape.

the class CySubNetworkCyTableManagerTest method setUp.

@Before
public void setUp() {
    final CyEventHelper eh = new DummyCyEventHelper();
    final CyNetworkNaming namingUtil = mock(CyNetworkNaming.class);
    final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    final EquationCompiler compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
    final Interpreter interpreter = new InterpreterImpl();
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eh);
    when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
    when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
    when(serviceRegistrar.getService(Interpreter.class)).thenReturn(interpreter);
    networkTableMgr = new CyNetworkTableManagerImpl();
    networkManager = new CyNetworkManagerImpl(serviceRegistrar);
    mgr = new CyTableManagerImpl(networkTableMgr, networkManager, serviceRegistrar);
    CyTableFactoryImpl tableFactory = new CyTableFactoryImpl(eh, serviceRegistrar);
    CyRootNetworkImpl baseNet = new CyRootNetworkImpl(eh, (CyTableManagerImpl) mgr, networkTableMgr, tableFactory, serviceRegistrar, true, SavePolicy.DO_NOT_SAVE);
    // This is a different subnetwork and not "baseNetwork" in ArrayGraph.
    goodNetwork = baseNet.addSubNetwork();
    globalTable = tableFactory.createTable("test table", CyIdentifiable.SUID, Long.class, true, true);
    networkManager.addNetwork(goodNetwork);
    assertNotNull(globalTable);
    assertNotNull(goodNetwork);
    assertEquals(1, networkManager.getNetworkSet().size());
}
Also used : DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) CyEventHelper(org.cytoscape.event.CyEventHelper) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) CyNetworkManagerImpl(org.cytoscape.model.internal.CyNetworkManagerImpl) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) CyTableManagerImpl(org.cytoscape.model.internal.CyTableManagerImpl) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) CyTableFactoryImpl(org.cytoscape.model.internal.CyTableFactoryImpl) CyNetworkTableManagerImpl(org.cytoscape.model.internal.CyNetworkTableManagerImpl) CyRootNetworkImpl(org.cytoscape.model.internal.CyRootNetworkImpl) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) EquationCompiler(org.cytoscape.equations.EquationCompiler) Before(org.junit.Before)

Example 5 with EquationCompiler

use of org.cytoscape.equations.EquationCompiler in project cytoscape-impl by cytoscape.

the class TableBrowserToolBar method getFnBuilderButton.

private JButton getFnBuilderButton() {
    if (fnBuilderButton == null) {
        fnBuilderButton = new JButton("f(x)");
        fnBuilderButton.setToolTipText("Function Builder");
        Font iconFont = null;
        try {
            iconFont = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/fonts/jsMath-cmti10.ttf"));
        } catch (Exception e) {
            throw new RuntimeException("Error loading font", e);
        }
        styleButton(fnBuilderButton, iconFont.deriveFont(18.0f));
        final JFrame rootFrame = (JFrame) SwingUtilities.getRoot(this);
        fnBuilderButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                // Do not allow opening of the formula builder dialog while a cell is being edited!
                if (browserTableModel == null || browserTable.getCellEditor() != null)
                    return;
                final int cellRow = browserTable.getSelectedRow();
                final int cellColumn = browserTable.getSelectedColumn();
                int colIndex = -1;
                // Map the screen index of column to internal index of the table model
                if (cellRow >= 0 && cellColumn >= 0) {
                    String colName = browserTable.getColumnName(cellColumn);
                    colIndex = browserTableModel.mapColumnNameToColumnIndex(colName);
                }
                if (cellRow == -1 || cellColumn == -1 || !browserTableModel.isCellEditable(cellRow, colIndex)) {
                    JOptionPane.showMessageDialog(rootFrame, "Can't enter a formula w/o a selected cell.", "Information", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    final String attrName = getAttribName(cellRow, cellColumn);
                    final Map<String, Class<?>> attribNameToTypeMap = new HashMap<>();
                    final CyTable dataTable = browserTableModel.getDataTable();
                    initAttribNameToTypeMap(dataTable, attrName, attribNameToTypeMap);
                    final EquationCompiler compiler = serviceRegistrar.getService(EquationCompiler.class);
                    final FormulaBuilderDialog formulaBuilderDialog = new FormulaBuilderDialog(compiler, browserTable, rootFrame, attrName);
                    formulaBuilderDialog.setLocationRelativeTo(rootFrame);
                    formulaBuilderDialog.setVisible(true);
                }
            }

            private void initAttribNameToTypeMap(final CyTable dataTable, final String attrName, final Map<String, Class<?>> attribNameToTypeMap) {
                for (final CyColumn column : dataTable.getColumns()) attribNameToTypeMap.put(column.getName(), column.getType());
                attribNameToTypeMap.remove(attrName);
            }
        });
    }
    return fnBuilderButton;
}
Also used : ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) CyColumn(org.cytoscape.model.CyColumn) Font(java.awt.Font) CyTable(org.cytoscape.model.CyTable) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) EquationCompiler(org.cytoscape.equations.EquationCompiler) Map(java.util.Map) HashMap(java.util.HashMap)

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