use of org.geotools.filter.AttributeExpressionImpl in project sldeditor by robward-scisys.
the class FieldConfigBaseTest method testAttributeUpdated.
/**
* Test method for {@link
* com.sldeditor.ui.detail.config.FieldConfigBase#attributeUpdated(java.lang.String)}.
*/
@Test
public void testAttributeUpdated() {
FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
String expectedLabel = "test label";
TestFieldConfigBase field = new TestFieldConfigBase(new FieldConfigCommonData(String.class, expectedFieldId, expectedLabel, false, false));
TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
field.addDataChangedListener(listener);
String attributeName = "test attribute";
assertFalse(listener.hasBeenCalled());
field.attributeUpdated(attributeName);
assertTrue(listener.hasBeenCalled());
assertEquals(ExpressionTypeEnum.E_ATTRIBUTE, field.getExpressionType());
Expression expression = field.getExpression();
assertTrue(expression instanceof AttributeExpressionImpl);
assertTrue(attributeName.compareTo(expression.toString()) == 0);
}
use of org.geotools.filter.AttributeExpressionImpl in project sldeditor by robward-scisys.
the class FieldConfigBaseTest method testPopulateExpressionExpression.
/**
* Test method for {@link
* com.sldeditor.ui.detail.config.FieldConfigBase#populate(org.opengis.filter.expression.Expression)}.
* Test method for {@link
* com.sldeditor.ui.detail.config.FieldConfigBase#populate(org.opengis.filter.expression.Expression,
* org.opengis.filter.expression.Expression)}.
*/
@Test
public void testPopulateExpressionExpression() {
FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
String expectedLabel = "test label";
TestFieldConfigBase field = new TestFieldConfigBase(new FieldConfigCommonData(String.class, expectedFieldId, expectedLabel, false, false));
AttributeSelection attributeSelectionPanel = AttributeSelection.createAttributes(String.class, field, false);
field.testAttributeSelectionPanel(attributeSelectionPanel);
TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
field.addDataChangedListener(listener);
assertFalse(listener.hasBeenCalled());
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
// Test function
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.populate(testExpression);
// Updated because the attribute pulldown changed
assertTrue(listener.hasBeenCalled());
assertEquals(ExpressionTypeEnum.E_EXPRESSION, field.getExpressionType());
Expression expression = field.getExpression();
assertTrue(expression.toString().startsWith(functionName.getName()));
// Attribute expression wrapped in a literal expression
String testAttributeName = "test attribute";
NameImpl name = new NameImpl(testAttributeName);
AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl(name);
Expression literalExpression = ff.literal(attributeExpression);
field.populate(literalExpression);
assertEquals(ExpressionTypeEnum.E_ATTRIBUTE, field.getExpressionType());
// Process Function
// ProcessFunctionFactory factory = new ProcessFunctionFactory();
// FunctionTableModel functionParameterTableModel = new FunctionTableModel();
// ProcessFunction processFunction = functionParameterTableModel.getExpression(factory);
// field.populate(processFunction);
// assertEquals(ExpressionTypeEnum.E_VALUE, field.getExpressionType());
}
use of org.geotools.filter.AttributeExpressionImpl in project sldeditor by robward-scisys.
the class ExpressionPanelv2 method addExpression.
/**
* Adds the expression.
*
* @param node the node
* @return the expression
*/
private Expression addExpression(ExpressionNode node) {
Expression localExpression = node.getExpression();
if (localExpression instanceof LiteralExpressionImpl) {
return localExpression;
} else if (localExpression instanceof AttributeExpressionImpl) {
return localExpression;
} else if (localExpression instanceof FunctionExpressionImpl) {
FunctionExpressionImpl functionExpression = (FunctionExpressionImpl) localExpression;
List<Expression> parameterlist = new ArrayList<>();
for (int childIndex = 0; childIndex < node.getChildCount(); childIndex++) {
ExpressionNode childNode = (ExpressionNode) node.getChildAt(childIndex);
parameterlist.add(addExpression(childNode));
}
functionExpression.setParameters(parameterlist);
return functionExpression;
} else if (localExpression instanceof MathExpressionImpl) {
MathExpressionImpl mathExpression = (MathExpressionImpl) localExpression;
ExpressionNode leftChildNode = (ExpressionNode) node.getChildAt(0);
mathExpression.setExpression1(addExpression(leftChildNode));
ExpressionNode rightChildNode = (ExpressionNode) node.getChildAt(1);
mathExpression.setExpression2(addExpression(rightChildNode));
return mathExpression;
} else if (localExpression instanceof ConcatenateFunction) {
ConcatenateFunction concatenateExpression = (ConcatenateFunction) localExpression;
List<Expression> parameters = new ArrayList<>();
for (int index = 0; index < node.getChildCount(); index++) {
ExpressionNode expressionNode = (ExpressionNode) node.getChildAt(0);
parameters.add(addExpression(expressionNode));
}
concatenateExpression.setParameters(parameters);
return concatenateExpression;
}
return null;
}
use of org.geotools.filter.AttributeExpressionImpl in project sldeditor by robward-scisys.
the class DataSourceAttributePanel method setAttribute.
/**
* Sets the attribute.
*
* @param expression the new attribute
*/
public void setAttribute(Expression expression) {
String propertyName = null;
if (expression instanceof PropertyExistsFunction) {
Expression e = ((PropertyExistsFunction) expression).getParameters().get(0);
Object value = ((LiteralExpressionImpl) e).getValue();
propertyName = ((AttributeExpressionImpl) value).getPropertyName();
} else if (expression instanceof AttributeExpressionImpl) {
propertyName = ((AttributeExpressionImpl) expression).getPropertyName();
} else if (expression instanceof LiteralExpressionImpl) {
propertyName = AttributeUtils.extract((String) ((LiteralExpressionImpl) expression).getValue());
}
if (propertyName != null) {
oldValueObj = propertyName;
attributeComboBox.setSelectedItem(propertyName);
} else {
oldValueObj = propertyName;
attributeComboBox.setSelectedIndex(-1);
}
}
use of org.geotools.filter.AttributeExpressionImpl in project sldeditor by robward-scisys.
the class FieldConfigColourTest method testGenerateExpression.
/**
* Test method for {@link
* com.sldeditor.ui.detail.config.FieldConfigColour#generateExpression()}. Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigColour#populateExpression(java.lang.Object,
* org.opengis.filter.expression.Expression)}. Test method for {@link
* com.sldeditor.ui.detail.config.FieldConfigColour#setTestValue(com.sldeditor.ui.detail.config.FieldId,
* java.lang.String)}. Test method for {@link
* com.sldeditor.ui.detail.config.FieldConfigColour#getColourExpression()}. Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigColour#getColourOpacityExpression()}. Test
* method for {@link com.sldeditor.ui.detail.config.FieldConfigColour#getStringValue()}.
*/
@Test
public void testGenerateExpression() {
boolean valueOnly = true;
class TestFieldConfigColour extends FieldConfigColour {
public TestFieldConfigColour(FieldConfigCommonData commonData) {
super(commonData);
}
public Expression callGenerateExpression() {
return generateExpression();
}
}
TestFieldConfigColour field = new TestFieldConfigColour(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly, false));
Expression actualExpression = field.callGenerateExpression();
assertNull(actualExpression);
field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
field.populateExpression(null);
assertNull(field.getColourExpression());
assertNull(field.getColourOpacityExpression());
// Try string values - erroneous
field.createUI();
field.populateExpression("");
String actualValue = field.getStringValue();
assertTrue(actualValue.compareTo("#000000") == 0);
String colour1 = "#123456";
field.populateExpression(colour1);
actualValue = field.getStringValue();
assertTrue(colour1.compareTo(actualValue) == 0);
actualExpression = field.getColourExpression();
assertTrue(actualExpression instanceof LiteralExpressionImpl);
assertTrue(actualExpression.toString().compareTo(colour1) == 0);
String colour2 = "#AABBCC";
field.setTestValue(FieldIdEnum.UNKNOWN, colour2);
actualValue = field.getStringValue();
assertTrue(colour2.compareTo(actualValue) == 0);
actualExpression = field.getColourExpression();
assertTrue(actualExpression instanceof LiteralExpressionImpl);
assertTrue(actualExpression.toString().compareTo(colour2) == 0);
actualExpression = field.getColourOpacityExpression();
assertTrue(actualExpression instanceof LiteralExpressionImpl);
LiteralExpressionImpl literal = (LiteralExpressionImpl) actualExpression;
double opacity = (Double) literal.getValue();
double expectedOpacity = 1.0;
assertTrue(Math.abs(opacity - expectedOpacity) < 0.0001);
// Try using FieldConfigBase.populate(colour expression, opacity)
String colour3 = "#001122";
expectedOpacity = DefaultSymbols.defaultColourOpacity();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
field.populate(ff.literal(colour3));
actualValue = field.getStringValue();
assertTrue(colour3.compareTo(actualValue) == 0);
actualExpression = field.getColourExpression();
assertTrue(actualExpression instanceof LiteralExpressionImpl);
assertTrue(actualExpression.toString().compareTo(colour3) == 0);
actualExpression = field.getColourOpacityExpression();
assertTrue(actualExpression instanceof LiteralExpressionImpl);
literal = (LiteralExpressionImpl) actualExpression;
opacity = (Double) literal.getValue();
assertTrue(Math.abs(opacity - expectedOpacity) < 0.1);
AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl("colour");
field.populate(attributeExpression);
actualExpression = field.getColourExpression();
assertTrue(actualExpression instanceof AttributeExpressionImpl);
assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
actualExpression = field.getColourOpacityExpression();
assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
}
Aggregations