Search in sources :

Example 1 with TimePeriod

use of com.sldeditor.filter.v2.function.temporal.TimePeriod in project sldeditor by robward-scisys.

the class FieldConfigTimePeriodTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#generateExpression()}. Test
 * method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#populateField(com.sldeditor.filter.v2.function.temporal.TimePeriod)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    class TestFieldConfigTimePeriod extends FieldConfigTimePeriod {

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

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }
    TestFieldConfigTimePeriod field = new TestFieldConfigTimePeriod(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, null, valueOnly));
    Expression actualExpression = field.callGenerateExpression();
    assertNotNull(actualExpression);
    // Try string values - erroneous
    field.createUI();
    field.createUI();
    String expectedValue = "test string value";
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
    actualExpression = field.callGenerateExpression();
    assertNotNull(actualExpression);
    expectedValue = "test string value as expression";
    field.populateExpression(expectedValue);
    actualExpression = field.callGenerateExpression();
    assertNotNull(actualExpression);
    // Time period values
    String timePeriod = "07-07-2016T17:42:27Z / 08-07-2016T17:42:27Z";
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.setTestValue(FieldIdEnum.UNKNOWN, timePeriod);
    actualExpression = field.callGenerateExpression();
    assertTrue(timePeriod.compareTo(actualExpression.toString()) == 0);
    TimePeriod period = new TimePeriod();
    Duration start = new Duration();
    start.setDuration(0, 0, 1, 0, 32, 9);
    period.setStart(start);
    field.populateField((TimePeriod) null);
    field.populateField(period);
    actualExpression = field.callGenerateExpression();
    String expectedPeriod = period.getString();
    assertTrue(expectedPeriod.compareTo(actualExpression.toString()) == 0);
    TimePeriod timePeriodObj = new TimePeriod();
    timePeriodObj.decode(timePeriod);
    DefaultPeriod defaultPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(timePeriodObj.getStart().getDate())), new DefaultInstant(new DefaultPosition(timePeriodObj.getEnd().getDate())));
    field.populateExpression(defaultPeriod);
    actualExpression = field.callGenerateExpression();
    assertTrue(timePeriod.compareTo(actualExpression.toString()) == 0);
}
Also used : Expression(org.opengis.filter.expression.Expression) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) FieldConfigTimePeriod(com.sldeditor.ui.detail.config.FieldConfigTimePeriod) TimePeriod(com.sldeditor.filter.v2.function.temporal.TimePeriod) FieldConfigTimePeriod(com.sldeditor.ui.detail.config.FieldConfigTimePeriod) DefaultPosition(org.geotools.temporal.object.DefaultPosition) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Duration(com.sldeditor.filter.v2.function.temporal.Duration) Test(org.junit.Test)

Example 2 with TimePeriod

use of com.sldeditor.filter.v2.function.temporal.TimePeriod in project sldeditor by robward-scisys.

the class FieldConfigTimePeriodTest method testUndoAction.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    FieldConfigTimePeriod field = new FieldConfigTimePeriod(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, null, true));
    field.undoAction(null);
    field.redoAction(null);
    field.createUI();
    // Time period values
    String timePeriod1 = "07-07-2016T17:42:27Z / 07-07-2016T17:42:27Z";
    TimePeriod period1 = new TimePeriod();
    period1.decode(timePeriod1);
    // CHECKSTYLE:OFF
    String expectedPeriod1 = period1.getString();
    // CHECKSTYLE:ON
    field.populateField(period1);
    String timePeriod2 = "P 1 D 32 M 9 S / 08-07-2016T09:42:06Z";
    TimePeriod period2 = new TimePeriod();
    period2.decode(timePeriod2);
    // CHECKSTYLE:OFF
    String expectedPeriod2 = period2.getString();
    // CHECKSTYLE:ON
    field.populateField(period2);
    UndoManager.getInstance().undo();
    String actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo(expectedPeriod1) == 0);
    UndoManager.getInstance().redo();
    actualValue = field.getStringValue();
    assertTrue(actualValue.replace(" ", "").compareTo(expectedPeriod2.replace(" ", "")) == 0);
}
Also used : FieldConfigTimePeriod(com.sldeditor.ui.detail.config.FieldConfigTimePeriod) TimePeriod(com.sldeditor.filter.v2.function.temporal.TimePeriod) FieldConfigTimePeriod(com.sldeditor.ui.detail.config.FieldConfigTimePeriod) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Example 3 with TimePeriod

use of com.sldeditor.filter.v2.function.temporal.TimePeriod in project sldeditor by robward-scisys.

the class FieldConfigTimePeriod method redoAction.

/**
 * Redo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@Override
public void redoAction(UndoInterface undoRedoObject) {
    if (undoRedoObject != null) {
        if (undoRedoObject.getNewValue() instanceof TimePeriod) {
            TimePeriod newValue = (TimePeriod) undoRedoObject.getNewValue();
            populateDuration(start, newValue.getStart());
            populateDuration(end, newValue.getEnd());
        }
    }
}
Also used : TimePeriod(com.sldeditor.filter.v2.function.temporal.TimePeriod)

Example 4 with TimePeriod

use of com.sldeditor.filter.v2.function.temporal.TimePeriod in project sldeditor by robward-scisys.

the class FieldConfigTimePeriod method getStringValue.

/**
 * Gets the string value.
 *
 * @return the string value
 */
@Override
public String getStringValue() {
    TimePeriod timePeriod = new TimePeriod();
    timePeriod.setStart(getDuration(start));
    timePeriod.setEnd(getDuration(end));
    return timePeriod.getString();
}
Also used : TimePeriod(com.sldeditor.filter.v2.function.temporal.TimePeriod)

Example 5 with TimePeriod

use of com.sldeditor.filter.v2.function.temporal.TimePeriod in project sldeditor by robward-scisys.

the class FieldConfigTimePeriod method revertToDefaultValue.

/**
 * Revert to default value.
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.detail.config.FieldConfigBase#revertToDefaultValue()
     */
@Override
public void revertToDefaultValue() {
    TimePeriod timePeriod = new TimePeriod();
    populateField(timePeriod);
}
Also used : TimePeriod(com.sldeditor.filter.v2.function.temporal.TimePeriod)

Aggregations

TimePeriod (com.sldeditor.filter.v2.function.temporal.TimePeriod)8 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)2 FieldConfigTimePeriod (com.sldeditor.ui.detail.config.FieldConfigTimePeriod)2 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)2 Test (org.junit.Test)2 Duration (com.sldeditor.filter.v2.function.temporal.Duration)1 DefaultInstant (org.geotools.temporal.object.DefaultInstant)1 DefaultPosition (org.geotools.temporal.object.DefaultPosition)1 Expression (org.opengis.filter.expression.Expression)1