Search in sources :

Example 1 with FieldConfigPopulation

use of com.sldeditor.ui.detail.config.FieldConfigPopulation in project sldeditor by robward-scisys.

the class ExtractGeometryFieldTest method testGetGeometryField.

/**
 * Test method for {@link com.sldeditor.ui.detail.ExtractGeometryField#getGeometryField(com.sldeditor.ui.detail.config.FieldConfigPopulation)}.
 */
@Test
public void testGetGeometryField() {
    assertNull(ExtractGeometryField.getGeometryField(null));
    FieldIdEnum fieldId = FieldIdEnum.GEOMETRY;
    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(Geometry.class);
    FieldConfigGeometry geometryField = new FieldConfigGeometry(new FieldConfigCommonData(Geometry.class, fieldId, "label", true), "button");
    geometryField.createUI();
    fieldConfigManager.add(fieldId, geometryField);
    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
    // Try valid geometry field name
    geometryField.populateField("ValidTestField");
    Expression actualExpression = ExtractGeometryField.getGeometryField(obj);
    assertNotNull(actualExpression);
    // Try invalid geometry field name
    geometryField.populateField("");
    actualExpression = ExtractGeometryField.getGeometryField(obj);
    assertNull(actualExpression);
    // Try invalid geometry field name
    geometryField.populateField("    ");
    actualExpression = ExtractGeometryField.getGeometryField(obj);
    assertNull(actualExpression);
    // Try when there is no geometry field
    obj = new FieldConfigPopulation(fieldConfigManager);
    actualExpression = ExtractGeometryField.getGeometryField(obj);
    assertNull(actualExpression);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) FieldConfigPopulation(com.sldeditor.ui.detail.config.FieldConfigPopulation) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) Expression(org.opengis.filter.expression.Expression) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Test(org.junit.Test)

Example 2 with FieldConfigPopulation

use of com.sldeditor.ui.detail.config.FieldConfigPopulation in project sldeditor by robward-scisys.

the class FieldConfigPopulationTest method testExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateField(com.sldeditor.ui.detail.config.FieldId, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateField(com.sldeditor.common.xml.ui.FieldIdEnum, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getExpression(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getExpression(com.sldeditor.common.xml.ui.FieldIdEnum)}.
 */
@Test
public void testExpression() {
    FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;
    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);
    FieldConfigInteger intField = new FieldConfigInteger(new FieldConfigCommonData(Geometry.class, fieldId, "label", true));
    intField.createUI();
    fieldConfigManager.add(fieldId, intField);
    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
    int expectedValue = 1256;
    StyleBuilder styleBuilder = new StyleBuilder();
    Expression expression = styleBuilder.literalExpression(expectedValue);
    obj.populateField(fieldId, expression);
    LiteralExpressionImpl actualValue = (LiteralExpressionImpl) obj.getExpression(fieldId);
    assertEquals(expectedValue, ((Integer) actualValue.getValue()).intValue());
    actualValue = (LiteralExpressionImpl) obj.getExpression(fieldId);
    assertEquals(expectedValue, ((Integer) actualValue.getValue()).intValue());
    // This shouldn't work as it does not know about the field
    FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
    obj.populateField(wrongFieldEnum, expression);
    assertNull(obj.getExpression(wrongFieldEnum));
    // Try with null
    obj.populateField(fieldId, null);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigPopulation(com.sldeditor.ui.detail.config.FieldConfigPopulation) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) Expression(org.opengis.filter.expression.Expression) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) FeatureTypeConstraint(org.geotools.styling.FeatureTypeConstraint) Test(org.junit.Test)

Example 3 with FieldConfigPopulation

use of com.sldeditor.ui.detail.config.FieldConfigPopulation in project sldeditor by robward-scisys.

the class FieldConfigPopulationTest method testBoolean.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateBooleanField(com.sldeditor.ui.detail.config.FieldId, java.lang.Boolean)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateBooleanField(com.sldeditor.common.xml.ui.FieldIdEnum, java.lang.Boolean)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getBoolean(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getBoolean(com.sldeditor.common.xml.ui.FieldIdEnum)}.
 */
@Test
public void testBoolean() {
    FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;
    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);
    FieldConfigBoolean booleanField = new FieldConfigBoolean(new FieldConfigCommonData(Geometry.class, fieldId, "label", true));
    booleanField.createUI();
    fieldConfigManager.add(fieldId, booleanField);
    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
    Boolean expectedValue = Boolean.TRUE;
    obj.populateBooleanField(fieldId, expectedValue);
    assertEquals(expectedValue.booleanValue(), obj.getBoolean(fieldId));
    // This shouldn't work as it does not know about the field
    FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
    assertFalse(obj.getBoolean(wrongFieldEnum));
    // Try with null - should revert to default value (false)
    obj.populateBooleanField(fieldId, null);
    assertFalse(obj.getBoolean(fieldId));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigPopulation(com.sldeditor.ui.detail.config.FieldConfigPopulation) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Test(org.junit.Test)

Example 4 with FieldConfigPopulation

use of com.sldeditor.ui.detail.config.FieldConfigPopulation in project sldeditor by robward-scisys.

the class FieldConfigPopulationTest method testComboBox.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateComboBoxField(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateComboBoxField(com.sldeditor.common.xml.ui.FieldIdEnum, java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getComboBox(com.sldeditor.common.xml.ui.FieldIdEnum)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getComboBox(com.sldeditor.ui.detail.config.FieldId)}.
 */
@Test
public void testComboBox() {
    SymbolTypeConfig s1 = new SymbolTypeConfig(null);
    s1.addOption("key1", "Value 1");
    s1.addOption("key2", "Value 2");
    s1.addOption("key3", "Value 3");
    s1.addField(FieldIdEnum.ANCHOR_POINT_H, true);
    s1.addField(FieldIdEnum.ANCHOR_POINT_V, false);
    FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;
    List<SymbolTypeConfig> configList = new ArrayList<SymbolTypeConfig>();
    configList.add(s1);
    FieldConfigEnum enumField = new FieldConfigEnum(new FieldConfigCommonData(Geometry.class, fieldId, "label", true));
    enumField.addConfig(configList);
    enumField.createUI();
    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);
    fieldConfigManager.add(fieldId, enumField);
    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
    String expectedValue = "key2";
    obj.populateComboBoxField(fieldId, expectedValue);
    assertTrue(expectedValue.compareTo(obj.getComboBox(fieldId).getKey()) == 0);
    // This shouldn't work as it does not know about the field
    FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
    assertNull(obj.getComboBox(wrongFieldEnum));
    // Try with null - should revert to default value (first enum item)
    obj.populateComboBoxField(fieldId, null);
    expectedValue = "key1";
    assertTrue(expectedValue.compareTo(obj.getComboBox(fieldId).getKey()) == 0);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigPopulation(com.sldeditor.ui.detail.config.FieldConfigPopulation) FieldConfigEnum(com.sldeditor.ui.detail.config.FieldConfigEnum) ArrayList(java.util.ArrayList) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) SymbolTypeConfig(com.sldeditor.ui.detail.config.symboltype.SymbolTypeConfig) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Test(org.junit.Test)

Example 5 with FieldConfigPopulation

use of com.sldeditor.ui.detail.config.FieldConfigPopulation in project sldeditor by robward-scisys.

the class FieldConfigPopulationTest method testGetFieldConfig.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getFieldConfig(com.sldeditor.ui.detail.config.FieldId)}.
 */
@Test
public void testGetFieldConfig() {
    FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;
    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);
    FieldConfigInteger intField = new FieldConfigInteger(new FieldConfigCommonData(Geometry.class, fieldId, "label", true));
    intField.createUI();
    fieldConfigManager.add(fieldId, intField);
    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
    assertNotNull(obj.getFieldConfig(fieldId));
    FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
    assertNull(obj.getFieldConfig(wrongFieldEnum));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigPopulation(com.sldeditor.ui.detail.config.FieldConfigPopulation) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Test(org.junit.Test)

Aggregations

FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)13 FieldConfigPopulation (com.sldeditor.ui.detail.config.FieldConfigPopulation)13 Test (org.junit.Test)13 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)12 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)12 Geometry (com.vividsolutions.jts.geom.Geometry)12 StyleBuilder (org.geotools.styling.StyleBuilder)4 FieldConfigInteger (com.sldeditor.ui.detail.config.FieldConfigInteger)3 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)3 FeatureTypeConstraint (org.geotools.styling.FeatureTypeConstraint)3 Expression (org.opengis.filter.expression.Expression)3 FieldConfigBoolean (com.sldeditor.ui.detail.config.FieldConfigBoolean)1 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)1 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)1 FieldConfigEnum (com.sldeditor.ui.detail.config.FieldConfigEnum)1 FieldConfigGeometry (com.sldeditor.ui.detail.config.FieldConfigGeometry)1 FieldConfigColourMap (com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap)1 FieldConfigFont (com.sldeditor.ui.detail.config.font.FieldConfigFont)1 SymbolTypeConfig (com.sldeditor.ui.detail.config.symboltype.SymbolTypeConfig)1 ArrayList (java.util.ArrayList)1