Commit 4a9921c5 authored by yannick legoc's avatar yannick legoc

Re-added the client check of a property value in the AutoApplyState

parent 3b5924a4
......@@ -317,16 +317,14 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
}
/**
* This method is the same for Int32Property, Float64Property and BooleanProperty.
* For StringProperty and ArrayProperty, it is overrided.
* Checks the server value.
* @param value
* @return
*/
public ExpressionResult checkServerValue(String value) {
boolean constant = isConstant(value);
public ExpressionResult checkServerValue(boolean constant, String value) {
// Test the validity of the expression by the server even for constant expression (a constant can be accepted by the client check but not the server so we check both).
CommandZoneAccessor.ExpressionResult result = null;
if (isCommandBox) {
......@@ -344,6 +342,17 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
return new ExpressionResult(ExpressionStatus.INVALID_EXPRESSION, ExpressionResult.convertExpressionError(result.getError()), result.getMessage());
}
}
// The expression is valid.
return new ExpressionResult(ExpressionStatus.VALID_EXPRESSION);
}
/**
* Checks the client value.
* @param value
* @return
*/
public ExpressionResult checkClientValue(boolean constant, String value) {
// Check the client conditions in case of a constant.
if (constant) {
......@@ -364,7 +373,6 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
return new ExpressionResult(ExpressionStatus.VALID_EXPRESSION);
}
}
public String getServerValue() {
try {
......
......@@ -19,6 +19,8 @@
package fr.ill.ics.core.property.undo;
import fr.ill.ics.core.property.Property;
import fr.ill.ics.core.property.Property.ExpressionResult;
import fr.ill.ics.core.property.Property.ExpressionStatus;
import fr.ill.ics.core.property.array.Array;
public class AutoApplyArrayState extends UndoArrayState {
......@@ -54,4 +56,9 @@ public class AutoApplyArrayState extends UndoArrayState {
public void setAutoApply() {
// do nothing
}
@Override
protected ExpressionResult checkPropertyValue(boolean constant, String value) {
return new ExpressionResult(ExpressionStatus.VALID_EXPRESSION);
}
}
\ No newline at end of file
......@@ -19,6 +19,8 @@
package fr.ill.ics.core.property.undo;
import fr.ill.ics.core.property.Property;
import fr.ill.ics.core.property.Property.ExpressionResult;
import fr.ill.ics.core.property.Property.ExpressionStatus;
import fr.ill.ics.core.property.Property.GetExpressionResult;
/**
......@@ -44,16 +46,23 @@ public class AutoApplyState extends UndoState {
return property.getServerExpression();
}
protected ExpressionResult checkPropertyValue(boolean constant, String value) {
// Only check the value by the client.
return property.checkClientValue(constant, value);
}
/**
* Sets server value
*/
public boolean setValue(String value) {
// Do not check the value by the server as it is done in the UndoableState.
// Otherwise setting an hexadecimal value is not possible because the value is verified as an expression by the server.
// Only set the server value.
return property.setServerValue(value).isValid();
boolean ok = checkValue(value);
if (ok) {
return property.setServerValue(value).isValid();
}
return false;
}
/**
......
......@@ -59,16 +59,29 @@ public abstract class UndoState {
*/
public abstract GetExpressionResult getExpression();
/**
* Checks the property value. Implemented in UndoableState (client and server check) and AutoApplyState (client check).
* @param constant
* @param value
* @return
*/
protected abstract ExpressionResult checkPropertyValue(boolean constant, String value);
/**
* Checks the value.
* @param value
* @return
*/
protected boolean checkValue(String value) {
// Result.
boolean ok = true;
// Factorise the call to isConstant.
boolean constant = property.isConstant(value);
// First check the value by the server.
ExpressionResult result = property.checkServerValue(value);
ExpressionResult result = checkPropertyValue(constant, value);
if (result.getStatus() == ExpressionStatus.INVALID_EXPRESSION) {
if (result.getError() == ExpressionError.PARSER_ERROR || result.getError() == ExpressionError.UNDEFINED_VARIABLE_ERROR) {
......
......@@ -19,6 +19,8 @@
package fr.ill.ics.core.property.undo;
import fr.ill.ics.core.property.Property;
import fr.ill.ics.core.property.Property.ExpressionResult;
import fr.ill.ics.core.property.Property.ExpressionStatus;
import fr.ill.ics.core.property.array.Array;
public class UndoableArrayState extends UndoArrayState {
......@@ -56,4 +58,9 @@ public class UndoableArrayState extends UndoArrayState {
public void setAutoApply() {
property.setUndoState(new UndoableArrayState(property));
}
@Override
protected ExpressionResult checkPropertyValue(boolean constant, String value) {
return new ExpressionResult(ExpressionStatus.VALID_EXPRESSION);
}
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ package fr.ill.ics.core.property.undo;
import java.util.LinkedList;
import fr.ill.ics.core.property.Property;
import fr.ill.ics.core.property.Property.ExpressionResult;
import fr.ill.ics.core.property.Property.ExpressionStatus;
import fr.ill.ics.core.property.Property.GetExpressionResult;
......@@ -65,6 +66,18 @@ public class UndoableState extends UndoState {
return new GetExpressionResult(getValue(), status);
}
protected ExpressionResult checkPropertyValue(boolean constant, String value) {
// First check the value by the client.
ExpressionResult result = property.checkClientValue(constant, value);
if (result.getStatus() == ExpressionStatus.INVALID_CONSTANT || result.getStatus() == ExpressionStatus.INVALID_EXPRESSION) {
return result;
}
// Then check the value by the server if the client value is ok.
return property.checkServerValue(constant, value);
}
/**
* Store the new local modification in the linked list.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment