Search in sources :

Example 1 with EnvFunction

use of org.geotools.filter.function.EnvFunction 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 2 with EnvFunction

use of org.geotools.filter.function.EnvFunction in project sldeditor by robward-scisys.

the class ExpressionSubPanel method displayExpression.

/**
 * Display expression.
 *
 * @param node the node
 */
private void displayExpression(ExpressionNode node) {
    if (panelLiteral.getComponentCount() == 2) {
        panelLiteral.remove(1);
    }
    if (node == null) {
        return;
    }
    fieldConfig = PanelField.getField(ExpressionPanelv2.class, "ExpressionSubPanel.value", node.getType());
    if (fieldConfig != null) {
        fieldConfig.createUI();
        fieldConfig.addDataChangedListener(new UpdateSymbolInterface() {

            @Override
            public void dataChanged(FieldIdEnum changedField) {
                buttonGroup.setSelected(rdbtnLiteral.getModel(), true);
                updateButtonState(true);
            }
        });
        panelLiteral.add(fieldConfig.getPanel());
        // Reset the fields
        dataSourceAttributePanel.setAttribute(null);
        functionPanel.setFunction(null);
        dataSourceAttributePanel.setDataType(node.getType());
        Expression expression = node.getExpression();
        if (expression instanceof AttributeExpressionImpl) {
            dataSourceAttributePanel.setAttribute(expression);
            buttonGroup.setSelected(rdbtnAttribute.getModel(), true);
        } else if (expression instanceof EnvFunction) {
            envVarField.setEnvironmentVariable(expression);
            buttonGroup.setSelected(rdbtnEnvVar.getModel(), true);
        } else if (expression instanceof FunctionExpressionImpl) {
            functionPanel.setFunction(expression);
            buttonGroup.setSelected(rdbtnFunction.getModel(), true);
        } else {
            fieldConfig.populate(expression);
            buttonGroup.setSelected(rdbtnLiteral.getModel(), true);
        }
    }
    Dimension boxSize = box.getPreferredSize();
    setPreferredSize(boxSize);
    revalidate();
}
Also used : EnvFunction(org.geotools.filter.function.EnvFunction) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) UpdateSymbolInterface(com.sldeditor.ui.iface.UpdateSymbolInterface) Dimension(java.awt.Dimension) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) FunctionExpressionImpl(org.geotools.filter.FunctionExpressionImpl)

Example 3 with EnvFunction

use of org.geotools.filter.function.EnvFunction in project sldeditor by robward-scisys.

the class ExpressionNodeTest method testSetExpression.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.expression.ExpressionNode#setExpression(org.opengis.filter.expression.Expression)}.
 */
@Test
public void testSetExpression() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ExpressionNode node = new ExpressionNode();
    // Test literal expression
    String expressionString = "Literalexpression";
    Expression literal = ff.literal(expressionString);
    node.setExpression(literal);
    String expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.literal") + " " + expressionString;
    String actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test attribute expression
    String propertyName = "testproperty";
    Expression attribute = ff.property(propertyName);
    node.setExpression(attribute);
    expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.attribute") + " [" + attribute + "]";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test attribute expression
    literal = ff.literal(ff.property(propertyName));
    node.setExpression(literal);
    expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.attribute") + " [" + attribute + "]";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test math expression
    Expression maths = ff.multiply(ff.literal(6), ff.literal(7));
    node.setExpression(maths);
    expected = "*";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test function
    FunctionImpl function = new ConcatenateFunction();
    List<Expression> params = new ArrayList<Expression>();
    params.add(ff.literal("world"));
    params.add(ff.literal("dog"));
    function.setParameters(params);
    node.setExpression(function);
    expected = "Concatenate([world], [dog])";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test function expression
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    String name = "strConcat";
    List<Expression> parameters = new ArrayList<Expression>();
    parameters.add(ff.literal("cat"));
    parameters.add(ff.literal("dog"));
    Function functionExpression = functionFactory.function(name, parameters, null);
    node.setExpression(functionExpression);
    expected = "strConcat([cat], [dog])";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test environment function
    EnvFunction envExpression = (EnvFunction) ff.function("env", ff.literal("foo"), ff.literal(0));
    node.setExpression(envExpression);
    expected = "env([foo], [0])";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
}
Also used : EnvFunction(org.geotools.filter.function.EnvFunction) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) Function(org.opengis.filter.expression.Function) EnvFunction(org.geotools.filter.function.EnvFunction) Expression(org.opengis.filter.expression.Expression) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) ExpressionNode(com.sldeditor.filter.v2.expression.ExpressionNode) FunctionImpl(org.geotools.filter.FunctionImpl) ArrayList(java.util.ArrayList) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 4 with EnvFunction

use of org.geotools.filter.function.EnvFunction in project sldeditor by robward-scisys.

the class EnvironmentVariableField method setEnvironmentVariable.

/**
 * Sets the environment variable.
 *
 * @param expression the new expression
 */
public void setEnvironmentVariable(Expression expression) {
    if (expression instanceof EnvFunction) {
        EnvFunction envFunction = (EnvFunction) expression;
        LiteralExpressionImpl literal = (LiteralExpressionImpl) envFunction.getParameters().get(0);
        oldValueObj = literal;
        envVarComboBox.setSelectedItem(literal.getValue());
    } else if (expression instanceof LiteralExpressionImpl) {
        LiteralExpressionImpl literal = (LiteralExpressionImpl) expression;
        oldValueObj = literal;
        envVarComboBox.setSelectedItem(literal.getValue());
    } else {
        ConsoleManager.getInstance().error(this, Localisation.getString(EnvironmentVariableField.class, "DataSourceAttributePanel.error1"));
    }
}
Also used : EnvFunction(org.geotools.filter.function.EnvFunction) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl)

Aggregations

EnvFunction (org.geotools.filter.function.EnvFunction)4 Expression (org.opengis.filter.expression.Expression)3 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)2 FunctionImpl (org.geotools.filter.FunctionImpl)2 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)2 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)1 ExpressionNode (com.sldeditor.filter.v2.expression.ExpressionNode)1 UpdateSymbolInterface (com.sldeditor.ui.iface.UpdateSymbolInterface)1 Dimension (java.awt.Dimension)1 ArrayList (java.util.ArrayList)1 FunctionExpression (org.geotools.filter.FunctionExpression)1 FunctionExpressionImpl (org.geotools.filter.FunctionExpressionImpl)1 MathExpressionImpl (org.geotools.filter.MathExpressionImpl)1 DefaultFunctionFactory (org.geotools.filter.function.DefaultFunctionFactory)1 ConcatenateFunction (org.geotools.filter.function.string.ConcatenateFunction)1 Test (org.junit.Test)1 FilterFactory (org.opengis.filter.FilterFactory)1 FunctionName (org.opengis.filter.capability.FunctionName)1 Function (org.opengis.filter.expression.Function)1 Parameter (org.opengis.parameter.Parameter)1