Commit 29f4cc1a authored by fipps's avatar fipps

Fix bug: when getting servant for a property, Nomad searches among

controllers without checking before that the servant is really a
controller and not a driver...
parent 0377c7fa
......@@ -52,10 +52,10 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
protected PropertyFormat propertyFormat;
private UndoState undoState;
protected List conditions;
protected List<IPropertyCondition> conditions;
private Set<IPropertyChangeListener> propertyChangeListeners;
private List propertyErrorListeners;
private List lockListeners;
private List<IPropertyErrorListener> propertyErrorListeners;
private List<ILockChangedListener> lockListeners;
protected PropertyVerifyListener pVerifyListener;
private boolean isLocked = false;
......@@ -91,7 +91,7 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
// Set property change listeners initial size to 2
this.propertyChangeListeners = new HashSet<IPropertyChangeListener>(1);
this.propertyErrorListeners = new ArrayList(2);
this.propertyErrorListeners = new ArrayList<IPropertyErrorListener>(2);
this.undoState = new AutoApplyState(this);
......@@ -174,13 +174,12 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
boolean isOk = true;
if (isCheckable) {
IPropertyCondition condition;
if (!acceptsValue(value, true)) {
isOk = false;
}
if (conditions != null) {
for (Iterator iter = this.conditions.iterator(); iter.hasNext();) {
condition = (IPropertyCondition) iter.next();
for (Iterator<IPropertyCondition> iter = this.conditions.iterator(); iter.hasNext();) {
IPropertyCondition condition = iter.next();
if (!condition.isOk(value)) {
setErrorMessageAndTitle(condition.getErrorMessage(getName()), "invalidValueTitle");
sendPropertyErrorEvent();
......@@ -222,7 +221,7 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
if (conditions == null) {
// For a load factor of 0.75 and a max size of 6, we need to set the capacity to 8
// There are 6 different types of conditions but in practice, two maximum for the same property
this.conditions = new ArrayList(2);
this.conditions = new ArrayList<IPropertyCondition>(2);
}
this.conditions.add(condition);
......@@ -348,9 +347,9 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
synchronized (propertyErrorListeners) {
// Iterate over listeners and send the notification of property error
Iterator listenerIterator = propertyErrorListeners.iterator();
Iterator<IPropertyErrorListener> listenerIterator = propertyErrorListeners.iterator();
while (listenerIterator.hasNext()) {
IPropertyErrorListener propertyErrorListener = (IPropertyErrorListener)(listenerIterator.next());
IPropertyErrorListener propertyErrorListener = listenerIterator.next();
if (propertyErrorListener.isVisible()) {
// H.ORTIZ 18 JUL 2016: here we have to check if the widget linked with current property is visible, because it can be
// in a hidden part of the screen (in a switchable composite)
......@@ -407,7 +406,7 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
public void addLockListener(ILockChangedListener lockListener) {
if (lockListeners == null) {
// Set lock listeners initial size to 2 (created at the same time as property changed listeners)
this.lockListeners = new ArrayList(2);
this.lockListeners = new ArrayList<ILockChangedListener>(2);
}
synchronized (lockListeners) {
......@@ -442,7 +441,7 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
public void sendLockChangedEvent() {
if (lockListeners != null) {
synchronized (lockListeners) {
Iterator listenerIterator = lockListeners.iterator();
Iterator<ILockChangedListener> listenerIterator = lockListeners.iterator();
while (listenerIterator.hasNext()) {
((ILockChangedListener) (listenerIterator.next())).lockChanged(new LockEvent(this, isLocked));
}
......@@ -669,22 +668,34 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
return containerId;
}
public List getConditions() {
public List<IPropertyCondition> getConditions() {
return conditions;
}
public void setConditions(ArrayList conditions) {
conditions = new ArrayList();
public void setConditions(ArrayList<IPropertyCondition> conditions) {
conditions = new ArrayList<IPropertyCondition>();
conditions.addAll(conditions);
}
public String getControllerName() {
return ServantDatabase.getInstance().getControllerName(PropertyDatabase.getInstance().getServantIdForProperty(id));
int servantId = PropertyDatabase.getInstance().getServantIdForProperty(id);
return getServantName(servantId);
}
public String getControllerNameForDynamic() {
return ServantDatabase.getInstance().getControllerName(PropertyDatabase.getInstance().getServantIdForDynamicProperty(id));
int servantId = PropertyDatabase.getInstance().getServantIdForDynamicProperty(id);
return getServantName(servantId);
}
private String getServantName(int servantId) {
if (ServantDatabase.getInstance().isController(servantId)) {
return ServantDatabase.getInstance().getControllerName(servantId);
} else {
return ServantDatabase.getInstance().getDriverName(servantId);
}
}
public void removeFromPropertyNotification() {
......
......@@ -20,10 +20,12 @@ package fr.ill.ics.core.property.condition;
import fr.ill.ics.bridge.Controller;
import fr.ill.ics.bridge.ControllerManager;
import fr.ill.ics.bridge.DriverManager;
import fr.ill.ics.core.property.Property;
import fr.ill.ics.core.property.PropertyManager;
import fr.ill.ics.core.property.parser.descriptor.ConditionDescriptor;
import fr.ill.ics.nscclient.dataprovider.PropertyDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
import fr.ill.ics.util.ConfigManager;
import fr.ill.ics.util.exception.PropertyNotFoundException;
......@@ -71,28 +73,34 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
}
if (servantId != -1) {
int minPropertyId = PropertyDatabase.getInstance().getPropertyIdForServant(servantId, minPropertyName);
minProperty = PropertyManager.getInstance().getProperty(servantId, minPropertyName);
if (minProperty == null) {
try {
if (index != -1) {
Controller controller = ControllerManager.getInstance().getController(property.getControllerNameForDynamic());
minProperty = PropertyManager.getInstance().getDynamicProperty(controller, minPropertyName+"."+index);
Controller servant;
if (ServantDatabase.getInstance().isController(servantId)) {
servant = ControllerManager.getInstance().getController(property.getControllerNameForDynamic());
} else {
servant = DriverManager.getInstance().getDriver(property.getControllerNameForDynamic());
}
minProperty = PropertyManager.getInstance().getDynamicProperty(servant, minPropertyName+"."+index);
}
} catch (PropertyNotFoundException e) {
// not a real problem...
}
}
int maxPropertyId = PropertyDatabase.getInstance().getPropertyIdForServant(servantId, maxPropertyName);
maxProperty = PropertyManager.getInstance().getProperty(servantId, maxPropertyName);
if (maxProperty == null) {
try {
if (index != -1) {
Controller controller = ControllerManager.getInstance().getController(property.getControllerNameForDynamic());
maxProperty = PropertyManager.getInstance().getDynamicProperty(controller, maxPropertyName+"."+index);
Controller servant;
if (ServantDatabase.getInstance().isController(servantId)) {
servant = ControllerManager.getInstance().getController(property.getControllerNameForDynamic());
} else {
servant = DriverManager.getInstance().getDriver(property.getControllerNameForDynamic());
}
maxProperty = PropertyManager.getInstance().getDynamicProperty(servant, maxPropertyName+"."+index);
}
} catch (PropertyNotFoundException e) {
// not a real problem...
......@@ -138,31 +146,4 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
return propertyName + " " + ConfigManager.getInstance().getString("rangeErrorMessage1") + minComparator + minProperty.getValue() + " " + ConfigManager.getInstance().getString("rangeErrorMessage2") + maxComparator + maxProperty.getValue();
}
}
}
\ No newline at end of file
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