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());
}
}
}
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();
}
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);
}
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"));
}
}
Aggregations