Search in sources :

Example 6 with FieldConfigGeometry

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

Example 7 with FieldConfigGeometry

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

the class FieldConfigGeometryTest method testUndoAction.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigGeometry#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigGeometry#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    FieldConfigGeometry field = new FieldConfigGeometry(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", false), "button text");
    field.undoAction(null);
    field.redoAction(null);
    field.createUI();
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateField((String) null);
    field.populateExpression((String) null);
    String wktPoint = "POINT( 48.44 -123.37)";
    field.populateField(wktPoint);
    String actualValue = field.getStringValue();
    assertTrue(wktPoint.compareTo(actualValue) == 0);
    String wktPolygon = "POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))";
    field.populateField(wktPolygon);
    actualValue = field.getStringValue();
    assertTrue(wktPolygon.compareTo(actualValue) == 0);
    String wktLine = "LINESTRING(0 2, 2 0, 8 6)";
    field.populateExpression(wktLine);
    actualValue = field.getStringValue();
    assertTrue(wktLine.compareTo(actualValue) == 0);
    UndoManager.getInstance().undo();
    actualValue = field.getStringValue();
    assertTrue(wktPolygon.compareTo(actualValue) == 0);
    UndoManager.getInstance().redo();
    actualValue = field.getStringValue();
    assertTrue(wktLine.compareTo(actualValue) == 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 : FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) UndoEvent(com.sldeditor.common.undo.UndoEvent) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Example 8 with FieldConfigGeometry

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

the class FieldConfigGeometryTest method testAttributeSelection.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigGeometry#attributeSelection(java.lang.String)}.
 */
@Test
public void testAttributeSelection() {
    boolean valueOnly = true;
    FieldConfigGeometry field = new FieldConfigGeometry(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly), "button text");
    field.attributeSelection(null);
// Does nothing
}
Also used : FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Example 9 with FieldConfigGeometry

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

the class FieldConfigGeometryTest method testSetEnabled.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigGeometry#internal_setEnabled(boolean)}. Test
 * method for {@link com.sldeditor.ui.detail.config.FieldConfigGeometry#isEnabled()}.
 */
@Test
public void testSetEnabled() {
    // Value only, no attribute/expression dropdown
    boolean valueOnly = true;
    FieldConfigGeometry field = new FieldConfigGeometry(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly), "button text");
    // Text field will not have been created
    boolean expectedValue = true;
    field.internal_setEnabled(expectedValue);
    assertFalse(field.isEnabled());
    // Create text field
    field.createUI();
    assertEquals(expectedValue, field.isEnabled());
    expectedValue = false;
    field.internal_setEnabled(expectedValue);
    assertEquals(expectedValue, field.isEnabled());
    // Has attribute/expression dropdown
    valueOnly = false;
    FieldConfigGeometry field2 = new FieldConfigGeometry(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly), "button text");
    // Text field will not have been created
    expectedValue = true;
    field2.internal_setEnabled(expectedValue);
    assertFalse(field2.isEnabled());
    // Create text field
    field2.createUI();
    assertEquals(expectedValue, field2.isEnabled());
    expectedValue = false;
    field2.internal_setEnabled(expectedValue);
    // Actual value is coming from the attribute panel, not the text field
    assertEquals(!expectedValue, field2.isEnabled());
}
Also used : FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Example 10 with FieldConfigGeometry

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

the class FieldConfigGeometryTest method testAddButtonPressedListener.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigGeometry#addButtonPressedListener(com.sldeditor.ui.detail.config.FieldConfigStringButtonInterface)}.
 */
@Test
public void testAddButtonPressedListener() {
    boolean valueOnly = true;
    FieldConfigGeometry field = new FieldConfigGeometry(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly), "button text");
    field.addButtonPressedListener(null);
}
Also used : FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Aggregations

FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)10 FieldConfigGeometry (com.sldeditor.ui.detail.config.FieldConfigGeometry)10 Geometry (com.vividsolutions.jts.geom.Geometry)10 Test (org.junit.Test)9 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)2 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 Disjoint (com.sldeditor.filter.v2.function.geometry.Disjoint)1 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)1 FieldConfigBoolean (com.sldeditor.ui.detail.config.FieldConfigBoolean)1 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)1 FieldConfigDate (com.sldeditor.ui.detail.config.FieldConfigDate)1 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)1 FieldConfigInteger (com.sldeditor.ui.detail.config.FieldConfigInteger)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 LineString (com.vividsolutions.jts.geom.LineString)1