Search in sources :

Example 1 with FieldConfigBoolean

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

the class FieldConfigBooleanTest method testUndoAction.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigBoolean#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigBoolean#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    boolean valueOnly = true;
    FieldConfigBoolean field = new FieldConfigBoolean(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly));
    field.undoAction(null);
    field.redoAction(null);
    field.createUI();
    field.populateField(Boolean.TRUE);
    field.populateField(Boolean.FALSE);
    assertFalse(field.getBooleanValue());
    UndoManager.getInstance().undo();
    assertTrue(field.getBooleanValue());
    UndoManager.getInstance().redo();
    assertFalse(field.getBooleanValue());
    field.setTestValue(null, true);
    assertTrue(field.getBooleanValue());
    assertTrue(field.getStringValue().toLowerCase().compareTo("true") == 0);
    // Increase the code coverage
    field.undoAction(null);
    field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
    field.redoAction(null);
    field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) UndoEvent(com.sldeditor.common.undo.UndoEvent) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean) Test(org.junit.Test)

Example 2 with FieldConfigBoolean

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

the class FieldConfigBooleanTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigBoolean#generateExpression()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    FieldConfigBoolean field = new FieldConfigBoolean(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly));
    field.setTestValue(null, true);
    field.populateField((Boolean) null);
    field.populateField(Boolean.TRUE);
    field.populateExpression(null);
    field.createUI();
    field.createUI();
    field.populateField(Boolean.TRUE);
    assertTrue(field.getBooleanValue());
    field.populateExpression(Boolean.FALSE);
    assertFalse(field.getBooleanValue());
    field.setTestValue(null, true);
    assertTrue(field.getBooleanValue());
    assertTrue(field.getStringValue().toLowerCase().compareTo("true") == 0);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean) Test(org.junit.Test)

Example 3 with FieldConfigBoolean

use of com.sldeditor.ui.detail.config.FieldConfigBoolean 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 FieldConfigBoolean

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

the class VOGeoServerLabelling method includeValue.

/**
 * Find out whether to include value based on the value of another field.
 *
 * @param field the field
 * @return true, if successful
 */
private boolean includeValue(FieldIdEnum field) {
    DefaultOverride override = overrideMap.get(field);
    if (override != null) {
        String value = null;
        FieldConfigBase fieldConfig = fieldConfigManager.get(override.getField());
        if (fieldConfig instanceof FieldConfigBoolean) {
            value = String.valueOf(fieldConfigVisitor.getBoolean(override.getField()));
        } else if (fieldConfig instanceof FieldConfigInteger) {
            value = String.valueOf(fieldConfigVisitor.getInteger(override.getField()));
        } else if (fieldConfig instanceof FieldConfigDouble) {
            value = String.valueOf(fieldConfigVisitor.getDouble(override.getField()));
        } else if (fieldConfig instanceof FieldConfigEnum) {
            value = String.valueOf(fieldConfigVisitor.getComboBox(override.getField()));
        } else {
            ConsoleManager.getInstance().error(this, "Unsupported field type : " + field + " " + fieldConfig.getClass().getName());
        }
        if (value != null) {
            for (String legalValue : override.getLegalValues()) {
                if (value.compareToIgnoreCase(legalValue) == 0) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) FieldConfigEnum(com.sldeditor.ui.detail.config.FieldConfigEnum) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean)

Example 5 with FieldConfigBoolean

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

the class FilterManager method convertParameters.

/**
 * Convert function parameters to ui components.
 *
 * @param panelId the panel id
 * @param functionName the function name
 * @return the list of ui components to display
 */
@Override
public List<GroupConfigInterface> convertParameters(Class<?> panelId, FunctionName functionName) {
    List<GroupConfigInterface> groupConfigList = new ArrayList<GroupConfigInterface>();
    if (functionName != null) {
        GroupConfig groupConfig = new GroupConfig();
        StringBuilder funcPrototypeStringBuilder = new StringBuilder();
        funcPrototypeStringBuilder.append(functionName.getName());
        funcPrototypeStringBuilder.append("(");
        int argCount = functionName.getArgumentCount();
        if (functionName.getArgumentCount() < 0) {
            argCount *= -1;
        }
        for (int index = 0; index < argCount; index++) {
            int argIndex = index;
            if (argIndex >= functionName.getArguments().size()) {
                argIndex = functionName.getArguments().size() - 1;
            }
            String label = functionName.getArgumentNames().get(argIndex);
            Parameter<?> parameterType = functionName.getArguments().get(argIndex);
            boolean valueOnly = false;
            FieldIdEnum id = FieldIdEnum.UNKNOWN;
            if (index > 0) {
                funcPrototypeStringBuilder.append(", ");
            }
            Class<?> type = parameterType.getType();
            funcPrototypeStringBuilder.append(type.getSimpleName());
            FieldConfigBase fieldConfig = null;
            FieldConfigCommonData commonData = new FieldConfigCommonData(panelId, id, label, valueOnly);
            if (type == java.lang.Number.class) {
                fieldConfig = new FieldConfigDouble(commonData);
            } else if (type == Double.class) {
                fieldConfig = new FieldConfigDouble(commonData);
            } else if (type == Float.class) {
                fieldConfig = new FieldConfigDouble(commonData);
            } else if (type == Integer.class) {
                fieldConfig = new FieldConfigInteger(commonData);
            } else if (type == Long.class) {
                fieldConfig = new FieldConfigInteger(commonData);
            } else if (type == String.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Object.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Boolean.class) {
                fieldConfig = new FieldConfigBoolean(commonData);
            } else if (type == Geometry.class) {
                fieldConfig = new FieldConfigGeometry(commonData, null);
            } else if (type == org.opengis.geometry.Geometry.class) {
                fieldConfig = new FieldConfigGeometry(commonData, null);
            } else if (type == LineString.class) {
                fieldConfig = new FieldConfigGeometry(commonData, null);
            } else if (type == Date.class) {
                fieldConfig = new FieldConfigDate(commonData);
            } else if (type == Class.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Classifier.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Unit.class) {
                fieldConfig = new FieldConfigMapUnits(commonData);
            } else if (type == Comparable.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Color.class) {
                fieldConfig = new FieldConfigColour(commonData);
            } else {
                ConsoleManager.getInstance().error(this, Localisation.getField(ExpressionPanelv2.class, "FilterManager.error1") + type.getName());
            }
            groupConfig.addField(fieldConfig);
        }
        funcPrototypeStringBuilder.append(")");
        groupConfig.setLabel(funcPrototypeStringBuilder.toString());
        groupConfigList.add(groupConfig);
    }
    return groupConfigList;
}
Also used : FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) ArrayList(java.util.ArrayList) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) LineString(com.vividsolutions.jts.geom.LineString) Classifier(org.geotools.filter.function.Classifier) RangedClassifier(org.geotools.filter.function.RangedClassifier) FieldConfigMapUnits(com.sldeditor.ui.detail.config.FieldConfigMapUnits) GroupConfig(com.sldeditor.ui.detail.config.base.GroupConfig) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) Point(com.vividsolutions.jts.geom.Point) Disjoint(com.sldeditor.filter.v2.function.geometry.Disjoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Date(java.util.Date) FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum)

Aggregations

FieldConfigBoolean (com.sldeditor.ui.detail.config.FieldConfigBoolean)10 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)9 Geometry (com.vividsolutions.jts.geom.Geometry)9 Test (org.junit.Test)8 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)2 FieldConfigInteger (com.sldeditor.ui.detail.config.FieldConfigInteger)2 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 Disjoint (com.sldeditor.filter.v2.function.geometry.Disjoint)1 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)1 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)1 FieldConfigDate (com.sldeditor.ui.detail.config.FieldConfigDate)1 FieldConfigEnum (com.sldeditor.ui.detail.config.FieldConfigEnum)1 FieldConfigGeometry (com.sldeditor.ui.detail.config.FieldConfigGeometry)1 FieldConfigMapUnits (com.sldeditor.ui.detail.config.FieldConfigMapUnits)1 FieldConfigPopulation (com.sldeditor.ui.detail.config.FieldConfigPopulation)1 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)1 GroupConfig (com.sldeditor.ui.detail.config.base.GroupConfig)1 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)1