Search in sources :

Example 1 with FunctionName

use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.

the class FieldConfigBaseTest method testFunctionUpdated.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigBase#functionUpdated(org.opengis.filter.expression.Expression)}.
 */
@Test
public void testFunctionUpdated() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field = new TestFieldConfigBase(new FieldConfigCommonData(String.class, expectedFieldId, expectedLabel, false));
    TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
    field.addDataChangedListener(listener);
    assertFalse(listener.hasBeenCalled());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    FunctionName functionName = null;
    for (FunctionName func : functionFactory.getFunctionNames()) {
        if (func.getName() == "greaterThan") {
            functionName = func;
            break;
        }
    }
    assertNotNull(functionName);
    Expression testExpression = ff.function(functionName.getFunctionName(), ff.literal(1), ff.literal(2));
    field.functionUpdated(testExpression);
    assertTrue(listener.hasBeenCalled());
    assertEquals(ExpressionTypeEnum.E_FUNCTION, field.getExpressionType());
    Expression expression = field.getExpression();
    assertTrue(expression.toString().startsWith(functionName.getName()));
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) Expression(org.opengis.filter.expression.Expression) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 2 with FunctionName

use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.

the class ExpressionNode method setExpression.

/**
 * Sets the expression.
 *
 * @param expression the expression to set
 */
public void setExpression(Expression expression) {
    this.expression = expression;
    if (expression instanceof LiteralExpressionImpl) {
        Object value = ((LiteralExpressionImpl) expression).getValue();
        if (value instanceof AttributeExpressionImpl) {
            this.expression = (AttributeExpressionImpl) value;
        }
    }
    setDisplayString();
    this.removeAllChildren();
    if (this.expression instanceof EnvFunction) {
        EnvFunction envVarExpression = (EnvFunction) this.expression;
        ExpressionNode childNode = new ExpressionNode();
        childNode.setExpressionType(ExpressionTypeEnum.ENVVAR);
        Expression envVarLiteral = envVarExpression.getParameters().get(0);
        Class<?> dataType = Object.class;
        if (envMgr != null) {
            dataType = envMgr.getDataType(envVarLiteral);
        }
        childNode.setType(dataType);
        childNode.setName(Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.envVar"));
        childNode.setExpression(envVarLiteral);
        this.insert(childNode, this.getChildCount());
    } else if (this.expression instanceof FunctionExpression) {
        FunctionExpression functionExpression = (FunctionExpression) this.expression;
        FunctionName functionName = functionExpression.getFunctionName();
        TypeManager.getInstance().setDataType(functionName.getReturn().getType());
        int argCount = functionName.getArgumentCount();
        if (functionName.getArgumentCount() < 0) {
            argCount *= -1;
        }
        for (int index = 0; index < argCount; index++) {
            ExpressionNode childNode = new ExpressionNode();
            Parameter<?> parameter = functionName.getArguments().get(index);
            childNode.setType(parameter.getType());
            childNode.setName(parameter.getName());
            if (index < functionExpression.getParameters().size()) {
                childNode.setExpression(functionExpression.getParameters().get(index));
            }
            this.insert(childNode, this.getChildCount());
        }
    } else if (this.expression instanceof FunctionImpl) {
        FunctionImpl functionExpression = (FunctionImpl) this.expression;
        FunctionName functionName = functionExpression.getFunctionName();
        TypeManager.getInstance().setDataType(functionName.getReturn().getType());
        int maxArgument = Math.abs(functionName.getArgumentCount());
        for (int index = 0; index < maxArgument; index++) {
            ExpressionNode childNode = new ExpressionNode();
            Parameter<?> parameter = functionName.getArguments().get(0);
            childNode.setType(parameter.getType());
            childNode.setName(parameter.getName());
            if (index < functionExpression.getParameters().size()) {
                childNode.setExpression(functionExpression.getParameters().get(index));
            }
            this.insert(childNode, this.getChildCount());
        }
    } else if (expression instanceof MathExpressionImpl) {
        MathExpressionImpl mathsExpression = (MathExpressionImpl) expression;
        String expressionText = Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.expression");
        ExpressionNode childNode1 = new ExpressionNode();
        childNode1.setType(Number.class);
        childNode1.setName(expressionText + " 1");
        childNode1.setExpression(mathsExpression.getExpression1());
        this.insert(childNode1, this.getChildCount());
        ExpressionNode childNode2 = new ExpressionNode();
        childNode2.setType(Number.class);
        childNode2.setName(expressionText + " 2");
        childNode2.setExpression(mathsExpression.getExpression2());
        this.insert(childNode2, this.getChildCount());
    } else if (expression instanceof AttributeExpressionImpl) {
        @SuppressWarnings("unused") AttributeExpressionImpl property = (AttributeExpressionImpl) expression;
    // TypeManager.getInstance().setLiteralType(literal.getValue().getClass());
    } else if (expression instanceof LiteralExpressionImpl) {
        LiteralExpressionImpl literal = (LiteralExpressionImpl) expression;
        if (literal.getValue() != null) {
            TypeManager.getInstance().setDataType(literal.getValue().getClass());
        }
    }
}
Also used : EnvFunction(org.geotools.filter.function.EnvFunction) MathExpressionImpl(org.geotools.filter.MathExpressionImpl) FunctionName(org.opengis.filter.capability.FunctionName) FunctionExpression(org.geotools.filter.FunctionExpression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) Expression(org.opengis.filter.expression.Expression) FunctionExpression(org.geotools.filter.FunctionExpression) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) FunctionImpl(org.geotools.filter.FunctionImpl) Parameter(org.opengis.parameter.Parameter)

Example 3 with FunctionName

use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.

the class ExtractAttributes method extractAttribute.

/**
 * Extract attribute.
 *
 * @param attributeType the attribute type
 * @param expression the expression
 * @param foundList the found list
 * @return the class
 */
protected Class<?> extractAttribute(Class<?> attributeType, Expression expression, List<String> foundList) {
    Class<?> returnType = String.class;
    if (expression instanceof AttributeExpressionImpl) {
        AttributeExpressionImpl attribute = (AttributeExpressionImpl) expression;
        // Determine if attribute is a geometry
        if ((GeometryTypeMapping.getGeometryType(attributeType) != GeometryTypeEnum.UNKNOWN) || (attributeType == Geometry.class)) {
            if (!geometryFieldList.contains(attribute.getPropertyName())) {
                geometryFieldList.add(attribute.getPropertyName());
            }
        } else {
            if (!fieldList.containsKey(attribute.getPropertyName()) && (attribute.getPropertyName() != null)) {
                DataSourceAttributeData field = new DataSourceAttributeData(attribute.getPropertyName(), attributeType, null);
                processedFieldList.add(field);
                fieldList.put(attribute.getPropertyName(), field);
                foundList.add(attribute.getPropertyName());
            }
        }
    } else if (expression instanceof FunctionExpression) {
        FunctionExpression function = (FunctionExpression) expression;
        FunctionName functionName = function.getFunctionName();
        List<Parameter<?>> argumentList = functionName.getArguments();
        int index = 0;
        for (Expression parameterExpression : function.getParameters()) {
            Parameter<?> parameter = argumentList.get(index);
            extractAttribute(parameter.getType(), parameterExpression, foundList);
            index++;
        }
        returnType = functionName.getReturn().getType();
    } else if (expression instanceof LiteralExpressionImpl) {
        LiteralExpressionImpl literal = (LiteralExpressionImpl) expression;
        try {
            Geometry geometry = reader.read(literal.toString());
            if (geometry != null) {
                returnType = Geometry.class;
            }
        } catch (ParseException e1) {
        // Ignore
        }
        if (returnType == String.class) {
            try {
                @SuppressWarnings("unused") int integer = Integer.valueOf(literal.toString());
                returnType = Integer.class;
            } catch (NumberFormatException e) {
            // Ignore
            }
        }
        if (returnType == String.class) {
            try {
                @SuppressWarnings("unused") double doubleValue = Double.valueOf(literal.toString());
                returnType = Double.class;
            } catch (NumberFormatException e) {
            // Ignore
            }
        }
    }
    return returnType;
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) LineString(com.vividsolutions.jts.geom.LineString) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) FunctionName(org.opengis.filter.capability.FunctionName) FunctionExpression(org.geotools.filter.FunctionExpression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) FunctionExpression(org.geotools.filter.FunctionExpression) Expression(org.opengis.filter.expression.Expression) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Parameter(org.opengis.parameter.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(com.vividsolutions.jts.io.ParseException)

Example 4 with FunctionName

use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.

the class FunctionField method getExpression.

/**
 * Gets the expression.
 *
 * @return the expression
 */
public Expression getExpression() {
    String functionNameString = (String) functionComboBox.getSelectedItem();
    FunctionName functionName = functionNameMap.get(functionNameString);
    Expression newExpression = functionNameMgr.createExpression(functionName);
    if (newExpression instanceof FunctionExpression) {
        FunctionExpression expression = (FunctionExpression) newExpression;
        if (expression != null) {
            List<Expression> params = new ArrayList<Expression>();
            boolean validSymbolFlag = (params.size() == functionName.getArgumentCount());
            if (validSymbolFlag) {
                expression.setParameters(params);
            }
        }
    } else if (newExpression instanceof FunctionImpl) {
        FunctionImpl expression = (FunctionImpl) newExpression;
        if (expression != null) {
        // List<Expression> params = new ArrayList<Expression>();
        // List<FieldConfigBase> functionFields = field.getFunctionFields();
        // if(functionFields != null)
        // {
        // for(FieldConfigBase functionField : functionFields)
        // {
        // Expression functionFieldExpression = functionField.getExpression();
        // 
        // if(functionFieldExpression != null)
        // {
        // params.add(functionFieldExpression);
        // }
        // }
        // }
        // 
        // boolean validSymbolFlag = (params.size() == functionName.getArgumentCount());
        // if(validSymbolFlag)
        // {
        // expression.setParameters(params);
        // }
        // 
        // String key = String.format("%s@%s", field.getClass().getName(),
        // Integer.toHexString(field.hashCode()));
        // SelectedSymbol.getInstance().setValidSymbol(key, validSymbolFlag);
        }
    }
    return newExpression;
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) FunctionExpression(org.geotools.filter.FunctionExpression) FunctionExpression(org.geotools.filter.FunctionExpression) Expression(org.opengis.filter.expression.Expression) FunctionImpl(org.geotools.filter.FunctionImpl) ArrayList(java.util.ArrayList)

Example 5 with FunctionName

use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.

the class FunctionField method setFunction.

/**
 * Sets the function.
 *
 * @param expression the new attribute
 */
public void setFunction(Expression expression) {
    if (expression == null) {
        functionComboBox.setSelectedIndex(-1);
    } else {
        if (expression instanceof FunctionExpressionImpl) {
            FunctionExpressionImpl functionExpression = (FunctionExpressionImpl) expression;
            FunctionName function = functionExpression.getFunctionName();
            String functionName = function.getName();
            oldValueObj = functionName;
            functionComboBox.setSelectedItem(functionName);
        } else {
            ConsoleManager.getInstance().error(this, Localisation.getString(FunctionField.class, "DataSourceAttributePanel.error1"));
        }
    }
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) FunctionExpressionImpl(org.geotools.filter.FunctionExpressionImpl)

Aggregations

FunctionName (org.opengis.filter.capability.FunctionName)21 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 Expression (org.opengis.filter.expression.Expression)7 DefaultFunctionFactory (org.geotools.filter.function.DefaultFunctionFactory)6 FunctionNameFilterInterface (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface)5 FunctionExpression (org.geotools.filter.FunctionExpression)5 FunctionNameFilterAll (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll)4 ProcessFunctionFactory (org.geotools.process.function.ProcessFunctionFactory)4 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)3 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 FunctionNameFilterRaster (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterRaster)2 BuiltInProcessFunction (com.sldeditor.rendertransformation.BuiltInProcessFunction)2 ProcessFunctionParameterValue (com.sldeditor.rendertransformation.ProcessFunctionParameterValue)2 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)2 LineString (com.vividsolutions.jts.geom.LineString)2 Point (com.vividsolutions.jts.geom.Point)2 FunctionImpl (org.geotools.filter.FunctionImpl)2 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)2