Search in sources :

Example 1 with SubFilterTransformer

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;
}
Also used : CompositeFilter(org.cytoscape.filter.model.CompositeFilter) JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) SubFilterTransformer(org.cytoscape.filter.model.SubFilterTransformer)

Example 2 with SubFilterTransformer

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;
}
Also used : CompositeFilter(org.cytoscape.filter.model.CompositeFilter) JComponent(javax.swing.JComponent) CyNetwork(org.cytoscape.model.CyNetwork) CompositeFilterController(org.cytoscape.filter.internal.filters.composite.CompositeFilterController) CompositeFilterPanel(org.cytoscape.filter.internal.filters.composite.CompositeFilterPanel) SubFilterTransformer(org.cytoscape.filter.model.SubFilterTransformer) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 3 with SubFilterTransformer

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();
    }
}
Also used : CompositeFilter(org.cytoscape.filter.model.CompositeFilter) IntrospectionException(java.beans.IntrospectionException) IOException(java.io.IOException) SubFilterTransformer(org.cytoscape.filter.model.SubFilterTransformer)

Aggregations

CompositeFilter (org.cytoscape.filter.model.CompositeFilter)3 SubFilterTransformer (org.cytoscape.filter.model.SubFilterTransformer)3 IOException (java.io.IOException)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 IntrospectionException (java.beans.IntrospectionException)1 JComponent (javax.swing.JComponent)1 CompositeFilterController (org.cytoscape.filter.internal.filters.composite.CompositeFilterController)1 CompositeFilterPanel (org.cytoscape.filter.internal.filters.composite.CompositeFilterPanel)1 CyIdentifiable (org.cytoscape.model.CyIdentifiable)1 CyNetwork (org.cytoscape.model.CyNetwork)1