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