use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.
the class CreateFilterTaskTest method testCreateColumnFilterBoolean.
@Test
public void testCreateColumnFilterBoolean() {
CreateFilterTask task = new CreateFilterTask(serviceRegistrar, "MyFilter");
task.jsonTunable.json = "{ \"id\" : \"ColumnFilter\", \"parameters\" : { \"criterion\" : false, \"columnName\" : \"name\", \"predicate\" : \"IS\"} }";
TaskMonitor tm = mock(TaskMonitor.class);
task.run(tm);
verify(tm, times(0)).showMessage(any(), any());
NamedTransformer<CyNetwork, CyIdentifiable> transformer = transformerContainer.getNamedTransformer(task.name);
assertNotNull(transformer);
ColumnFilter columnFilter = (ColumnFilter) transformer.getTransformers().get(0);
assertEquals(Predicate.IS, columnFilter.getPredicate());
assertEquals(false, columnFilter.getCriterion());
assertEquals("name", columnFilter.getColumnName());
}
use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.
the class CreateFilterTaskTest method testCreateColumnFilterString.
@Test
public void testCreateColumnFilterString() {
CreateFilterTask task = new CreateFilterTask(serviceRegistrar, "MyFilter");
task.jsonTunable.json = "{ \"id\" : \"ColumnFilter\", \"parameters\" : { \"criterion\" : \"1\", \"columnName\" : \"name\", \"predicate\" : \"CONTAINS\"} }";
TaskMonitor tm = mock(TaskMonitor.class);
task.run(tm);
verify(tm, times(0)).showMessage(any(), any());
NamedTransformer<CyNetwork, CyIdentifiable> transformer = transformerContainer.getNamedTransformer(task.name);
assertNotNull(transformer);
ColumnFilter columnFilter = (ColumnFilter) transformer.getTransformers().get(0);
assertEquals(Predicate.CONTAINS, columnFilter.getPredicate());
assertEquals("1", columnFilter.getCriterion());
assertEquals("name", columnFilter.getColumnName());
}
use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.
the class CreateFilterTaskTest method testCreateCompositeFilter.
@Test
public void testCreateCompositeFilter() {
CreateFilterTask task = new CreateFilterTask(serviceRegistrar, "MyFilter");
String subFilterJson = "{ \"id\" : \"ColumnFilter\", \"parameters\" : { \"criterion\" : \"1\", \"columnName\" : \"name\", \"predicate\" : \"CONTAINS\"} }";
task.jsonTunable.json = "{ \"id\" : \"org.cytoscape.CompositeFilter\", \"parameters\" : { \"type\" : \"ALL\" }, \"transformers\" : [ " + subFilterJson + " ] }";
TaskMonitor tm = mock(TaskMonitor.class);
task.run(tm);
verify(tm, times(0)).showMessage(any(), any());
NamedTransformer<CyNetwork, CyIdentifiable> transformer = transformerContainer.getNamedTransformer(task.name);
assertNotNull(transformer);
@SuppressWarnings("rawtypes") CompositeFilter compositeFilter = (CompositeFilter) transformer.getTransformers().get(0);
assertEquals(CompositeFilter.Type.ALL, compositeFilter.getType());
assertEquals(1, compositeFilter.getLength());
ColumnFilter columnFilter = (ColumnFilter) compositeFilter.get(0);
assertEquals(Predicate.CONTAINS, columnFilter.getPredicate());
assertEquals("1", columnFilter.getCriterion());
assertEquals("name", columnFilter.getColumnName());
}
use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.
the class ModelMonitor method updateColumnSliders.
private void updateColumnSliders() {
for (ColumnFilterController controller : columnViews.values()) {
ColumnFilter filter = controller.getFilter();
Class<? extends CyIdentifiable> columnType = filter.getTableType();
Number[] range;
String name = filter.getColumnName();
if (name == null) {
continue;
}
CyTable table;
if (CyNode.class.equals(columnType)) {
table = network.getDefaultNodeTable();
range = getColumnRange(table, name, nodeColumnRanges);
} else if (CyEdge.class.equals(columnType)) {
table = network.getDefaultEdgeTable();
range = getColumnRange(table, name, edgeColumnRanges);
} else {
continue;
}
CyColumn column = table.getColumn(name);
if (column == null) {
continue;
}
Class<?> type = column.getType();
if (List.class.equals(type)) {
type = column.getListElementType();
}
if (Integer.class.equals(type) || Long.class.equals(type)) {
controller.setSliderBounds(range[0].longValue(), range[1].longValue());
} else {
controller.setSliderBounds(range[0].doubleValue(), range[1].doubleValue());
}
}
}
use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.
the class CompositeFilterTest method testCompositeFilterString.
@Test
public void testCompositeFilterString() {
NetworkTestSupport networkSupport = new NetworkTestSupport();
CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
network.getDefaultNodeTable().createColumn("s", String.class, false);
CyNode n1 = network.addNode();
CyNode n2 = network.addNode();
CyNode n3 = network.addNode();
CyNode n4 = network.addNode();
network.getRow(n1).set("s", "abc");
network.getRow(n2).set("s", "def");
network.getRow(n3).set("s", "aa");
ColumnFilter filterForA = new ColumnFilter("s", Predicate.CONTAINS, "a");
ColumnFilter filterForB = new ColumnFilter("s", Predicate.CONTAINS, "b");
ColumnFilter filterForC = new ColumnFilter("s", Predicate.CONTAINS, "c");
CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<>(CyNetwork.class, CyIdentifiable.class);
composite.append(filterForA);
composite.append(filterForB);
composite.append(filterForC);
composite.setType(Type.ANY);
assertTrue(composite.accepts(network, n1));
assertFalse(composite.accepts(network, n2));
assertTrue(composite.accepts(network, n3));
assertFalse(composite.accepts(network, n4));
composite.setType(Type.ALL);
assertTrue(composite.accepts(network, n1));
assertFalse(composite.accepts(network, n2));
assertFalse(composite.accepts(network, n3));
assertFalse(composite.accepts(network, n4));
}
Aggregations