use of org.cytoscape.equations.Equation 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.Equation 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.Equation in project cytoscape-impl by cytoscape.
the class CyTableTest method testGetColumnValuesWithEquations.
@Test
public void testGetColumnValuesWithEquations() {
table.createColumn("someLongs", Long.class, false);
final CyRow row1 = table.getRow(1L);
compiler.compile("=LEN(\"one\")", new HashMap<String, Class<?>>());
final Equation eqn = compiler.getEquation();
row1.set("someLongs", eqn);
final CyRow row2 = table.getRow(2L);
row2.set("someLongs", -27L);
final List<Long> values = table.getColumn("someLongs").getValues(Long.class);
assertTrue(values.size() == 2);
assertTrue(values.contains(3L));
assertTrue(values.contains(-27L));
}
use of org.cytoscape.equations.Equation in project cytoscape-impl by cytoscape.
the class CyTableTest method testSetListWithACompatibleEquation.
// @Test : TODO: We removed support for strongly typed lists so this test is
// now broken.
public void testSetListWithACompatibleEquation() {
table.createListColumn("stringList", String.class, false);
attrs.set("stringList", new StringList());
compiler.compile("=SLIST(\"one\",\"two\")", new HashMap<String, Class<?>>());
final Equation eqn = compiler.getEquation();
attrs.set("stringList", eqn);
final StringList expectedList = new StringList("one", "two");
assertEquals(attrs.getList("stringList", String.class), expectedList);
}
use of org.cytoscape.equations.Equation in project cytoscape-impl by cytoscape.
the class CyTableTest method testSetWithANonEvaluableCompatibleEquation.
@Test
public void testSetWithANonEvaluableCompatibleEquation() {
table.createColumn("strings", String.class, false);
final Map<String, Class<?>> varnameToTypeMap = new HashMap<String, Class<?>>();
varnameToTypeMap.put("a", String.class);
compiler.compile("=$a&\"one\"", varnameToTypeMap);
final Equation eqn = compiler.getEquation();
attrs.set("strings", eqn);
Object last = eventHelper.getLastPayload();
assertNotNull(last);
assertTrue(last instanceof RowSetRecord);
}
Aggregations