use of org.cytoscape.filter.model.SubFilterTransformer in project cytoscape-impl by cytoscape.
the class CyTransformerReaderImpl method readTransformer.
private Transformer<?, ?> readTransformer(JsonParser parser) throws IOException {
JsonToken firstToken = parser.nextToken();
if (firstToken == JsonToken.END_ARRAY) {
return null;
}
if (firstToken != JsonToken.START_OBJECT) {
throw new IOException("Expected: " + JsonToken.START_OBJECT + ". Got: " + firstToken);
}
assertField(parser, FilterIO.ID_FIELD);
String id = parser.nextTextValue();
assertField(parser, FilterIO.PARAMETERS_FIELD);
assertNextToken(parser, JsonToken.START_OBJECT);
Transformer<?, ?> transformer = transformerManager.createTransformer(id);
if (transformer == null && !id.contains(".")) {
transformer = transformerManager.createTransformer("org.cytoscape." + id);
}
if (transformer == null) {
throw new IOException("Unrecognized id: '" + id + "'");
}
Map<String, Object> parameters = readParameters(parser);
assertEquals(JsonToken.END_OBJECT, parser.getCurrentToken());
FilterIO.applyParameters(parameters, transformer);
if (transformer instanceof CompositeFilter) {
readCompositeFilter(parser, (CompositeFilter<?, ?>) transformer);
} else if (transformer instanceof SubFilterTransformer) {
SubFilterTransformer<?, ?> sft = (SubFilterTransformer<?, ?>) transformer;
readCompositeFilter(parser, sft.getCompositeFilter());
} else {
assertNextToken(parser, JsonToken.END_OBJECT);
}
return transformer;
}
use of org.cytoscape.filter.model.SubFilterTransformer in project cytoscape-impl by cytoscape.
the class TransformerPanelController method createView.
@Override
public JComponent createView(TransformerPanel parent, Transformer<CyNetwork, CyIdentifiable> transformer, int depth) {
// CompositeFilterImpl needs a CompositeFilterPanel but the top is blank so view will be null
JComponent view = transformerViewManager.createView(transformer);
if (transformer instanceof SubFilterTransformer || transformer instanceof CompositeFilter) {
String addButtonTT = transformerViewManager.getAddButtonTooltip(transformer);
CompositeFilterController controller = CompositeFilterController.createFor(view, addButtonTT);
CompositeFilter<CyNetwork, CyIdentifiable> compositeFilter;
if (transformer instanceof SubFilterTransformer)
compositeFilter = ((SubFilterTransformer<CyNetwork, CyIdentifiable>) transformer).getCompositeFilter();
else
compositeFilter = (CompositeFilter<CyNetwork, CyIdentifiable>) transformer;
return new CompositeFilterPanel<TransformerPanel>(parent, this, controller, compositeFilter, depth);
}
if (view == null)
throw new IllegalArgumentException("view could not be created for: " + transformer.getId());
return view;
}
use of org.cytoscape.filter.model.SubFilterTransformer in project cytoscape-impl by cytoscape.
the class CyTransformerWriterImpl method write.
private void write(JsonGenerator generator, Transformer<?, ?> transformer) throws IOException {
generator.writeStartObject();
try {
generator.writeStringField(FilterIO.ID_FIELD, transformer.getId());
generator.writeObjectFieldStart(FilterIO.PARAMETERS_FIELD);
try {
Map<String, Object> parameters = FilterIO.getParameters(transformer);
for (Entry<String, Object> entry : parameters.entrySet()) {
String name = entry.getKey();
Object value = entry.getValue();
writeField(generator, name, value);
}
} catch (IntrospectionException e) {
throw new IOException(e);
} finally {
generator.writeEndObject();
}
if (transformer instanceof CompositeFilter || transformer instanceof SubFilterTransformer) {
CompositeFilter<?, ?> composite;
if (transformer instanceof SubFilterTransformer)
composite = ((SubFilterTransformer<?, ?>) transformer).getCompositeFilter();
else
composite = (CompositeFilter<?, ?>) transformer;
generator.writeArrayFieldStart(FilterIO.TRANSFORMERS_FIELD);
try {
for (int i = 0; i < composite.getLength(); i++) {
write(generator, composite.get(i));
}
} finally {
generator.writeEndArray();
}
}
} finally {
generator.writeEndObject();
}
}
Aggregations