Search in sources :

Example 1 with FieldConfigEnum

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

the class FieldConfigEnumTest method testCreateCopy.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigEnum#createCopy(com.sldeditor.ui.detail.config.FieldConfigBase)}.
 */
@Test
public void testCreateCopy() {
    boolean valueOnly = true;
    class TestFieldConfigEnum extends FieldConfigEnum {

        public TestFieldConfigEnum(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public FieldConfigPopulate callCreateCopy(FieldConfigBase fieldConfigBase) {
            return createCopy(fieldConfigBase);
        }
    }
    TestFieldConfigEnum field = new TestFieldConfigEnum(new FieldConfigCommonData(Integer.class, FieldIdEnum.NAME, "label", valueOnly));
    FieldConfigEnum copy = (FieldConfigEnum) field.callCreateCopy(null);
    assertNull(copy);
    copy = (FieldConfigEnum) field.callCreateCopy(field);
    assertEquals(field.getFieldId(), copy.getFieldId());
    assertTrue(field.getLabel().compareTo(copy.getLabel()) == 0);
    assertEquals(field.isValueOnly(), copy.isValueOnly());
}
Also used : FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigEnum(com.sldeditor.ui.detail.config.FieldConfigEnum) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Example 2 with FieldConfigEnum

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

the class FieldConfigEnumTest method testGetFieldEnableState.

/**
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigEnum#getFieldEnableState()}.
 */
@Test
public void testGetFieldEnableState() {
    UndoManager.getInstance().setPopulationCheck(Controller.getInstance());
    SymbolTypeConfig s1 = new SymbolTypeConfig(Integer.class);
    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);
    List<SymbolTypeConfig> configList = new ArrayList<SymbolTypeConfig>();
    configList.add(s1);
    boolean valueOnly = true;
    FieldConfigEnum field = new FieldConfigEnum(new FieldConfigCommonData(Integer.class, FieldIdEnum.NAME, "label", valueOnly));
    field.addConfig(configList);
    // Now create the ui
    field.createUI();
    field.populateField("key3");
    Map<FieldIdEnum, Boolean> actualMap = field.getFieldEnableState();
    assertEquals(actualMap.get(FieldIdEnum.ANCHOR_POINT_H), Boolean.TRUE);
    assertEquals(actualMap.get(FieldIdEnum.ANCHOR_POINT_V), Boolean.FALSE);
    UndoManager.getInstance().setPopulationCheck(null);
}
Also used : FieldConfigEnum(com.sldeditor.ui.detail.config.FieldConfigEnum) ArrayList(java.util.ArrayList) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) SymbolTypeConfig(com.sldeditor.ui.detail.config.symboltype.SymbolTypeConfig) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) Test(org.junit.Test)

Example 3 with FieldConfigEnum

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

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

the class BasePanel method handleFieldState.

/**
 * Handle field state for a specific combo box field.
 *
 * @param fieldId the field id
 */
protected void handleFieldState(FieldIdEnum fieldId) {
    FieldConfigBase fieldConfig = fieldConfigManager.get(fieldId);
    if (fieldConfig != null) {
        if (fieldConfig instanceof FieldConfigEnum) {
            FieldConfigEnum fieldEnum = (FieldConfigEnum) fieldConfig;
            Map<FieldIdEnum, Boolean> stateMap = fieldEnum.getFieldEnableState();
            if (stateMap != null) {
                for (FieldIdEnum fieldKey : stateMap.keySet()) {
                    enableField(fieldKey, stateMap.get(fieldKey));
                }
            }
        }
    } else {
        ConsoleManager.getInstance().error(this, String.format("handleFieldState - %s : %s", Localisation.getString(StandardPanel.class, "StandardPanel.unknownField"), fieldId));
    }
}
Also used : FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigEnum(com.sldeditor.ui.detail.config.FieldConfigEnum) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum)

Example 5 with FieldConfigEnum

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

the class BasePanel method handleFieldState.

/**
 * Handle field state for all combo box fields.
 */
protected void handleFieldState() {
    List<FieldConfigBase> fieldList = fieldConfigManager.getFields(FieldConfigEnum.class);
    for (FieldConfigBase field : fieldList) {
        FieldConfigEnum fieldEnum = (FieldConfigEnum) field;
        Map<FieldIdEnum, Boolean> stateMap = fieldEnum.getFieldEnableState();
        if (stateMap != null) {
            for (FieldIdEnum fieldKey : stateMap.keySet()) {
                enableField(fieldKey, stateMap.get(fieldKey));
            }
        }
    }
}
Also used : FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigEnum(com.sldeditor.ui.detail.config.FieldConfigEnum) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum)

Aggregations

FieldConfigEnum (com.sldeditor.ui.detail.config.FieldConfigEnum)14 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)9 Test (org.junit.Test)9 SymbolTypeConfig (com.sldeditor.ui.detail.config.symboltype.SymbolTypeConfig)6 ArrayList (java.util.ArrayList)6 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)4 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)4 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)2 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)1 FieldConfigBoolean (com.sldeditor.ui.detail.config.FieldConfigBoolean)1 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)1 FieldConfigInteger (com.sldeditor.ui.detail.config.FieldConfigInteger)1 FieldConfigPopulation (com.sldeditor.ui.detail.config.FieldConfigPopulation)1 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)1 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)1 Geometry (com.vividsolutions.jts.geom.Geometry)1