Commit 08517080 authored by Cristina Cocho's avatar Cristina Cocho
Browse files

Modifications in both NomadGUI and NomadCommandSystem related to multiplot management

parent 6c799374
...@@ -27,6 +27,7 @@ import java.util.LinkedHashSet; ...@@ -27,6 +27,7 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -48,8 +49,6 @@ import fr.ill.ics.nscclient.dataprovider.PropertyDatabase; ...@@ -48,8 +49,6 @@ import fr.ill.ics.nscclient.dataprovider.PropertyDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase; import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
import fr.ill.ics.nscclient.servant.DynamicPropertyDescriptor; import fr.ill.ics.nscclient.servant.DynamicPropertyDescriptor;
public class PropertyFactory { public class PropertyFactory {
private static final Logger LOGGER = Logger.getLogger(PropertyFactory.class.getName()); private static final Logger LOGGER = Logger.getLogger(PropertyFactory.class.getName());
...@@ -64,15 +63,15 @@ public class PropertyFactory { ...@@ -64,15 +63,15 @@ public class PropertyFactory {
} }
public Property createProperty(int containerId, int id, String type, boolean isCommandBox) { public Property createProperty(int containerId, int id, String type, boolean isCommandBox) {
Property property = null; Property property = null;
//String type = propertyDescriptor.getPropertyType().toLowerCase(); // String type = propertyDescriptor.getPropertyType().toLowerCase();
if (type.equals("unknown")) { if (type.equals("unknown")) {
// Get property type directly from the controller // Get property type directly from the controller
type = PropertyDatabase.getInstance().getPropertyType(id); type = PropertyDatabase.getInstance().getPropertyType(id);
} }
if (type == null) { if (type == null) {
type = "string"; type = "string";
LOGGER.log(Level.WARNING, "Unable to find type for property " + id); LOGGER.log(Level.WARNING, "Unable to find type for property " + id);
...@@ -103,10 +102,10 @@ public class PropertyFactory { ...@@ -103,10 +102,10 @@ public class PropertyFactory {
} else if (type.equals("string") || type.equals("String")) { } else if (type.equals("string") || type.equals("String")) {
property = new StringProperty(containerId, id, isCommandBox); property = new StringProperty(containerId, id, isCommandBox);
} else if (type.equals("int8array") ) { } else if (type.equals("int8array")) {
property = new Int8ArrayProperty(containerId, id, isCommandBox); property = new Int8ArrayProperty(containerId, id, isCommandBox);
} else if (type.equals("int16array") ) { } else if (type.equals("int16array")) {
property = new Int16ArrayProperty(containerId, id, isCommandBox); property = new Int16ArrayProperty(containerId, id, isCommandBox);
} else if (type.equals("int32array") || type.equals("longarray")) { } else if (type.equals("int32array") || type.equals("longarray")) {
...@@ -125,25 +124,24 @@ public class PropertyFactory { ...@@ -125,25 +124,24 @@ public class PropertyFactory {
property = new StringProperty(containerId, id, isCommandBox); property = new StringProperty(containerId, id, isCommandBox);
LOGGER.log(Level.WARNING, "Unable to manage type " + type + " for property " + id); LOGGER.log(Level.WARNING, "Unable to manage type " + type + " for property " + id);
} }
return property; return property;
} }
public Property configureProperty(Property property, XMLPropertyDescriptor propertyDescriptor) { public Property configureProperty(Property property, XMLPropertyDescriptor propertyDescriptor) {
// Create basic property // Create basic property
String type = propertyDescriptor.getPropertyType().toLowerCase(); String type = propertyDescriptor.getPropertyType().toLowerCase();
int id = property.getPropertyID(); int id = property.getPropertyID();
if (type.equals("float32")) { if (type.equals("float32")) {
property.setPropertyFormat(new DecimalFormat(propertyDescriptor, id, false)); property.setPropertyFormat(new DecimalFormat(propertyDescriptor, id, false));
} else if (type.equals("float64") || type.equals("double")) { } else if (type.equals("float64") || type.equals("double")) {
property.setPropertyFormat(new DecimalFormat(propertyDescriptor, id, false)); property.setPropertyFormat(new DecimalFormat(propertyDescriptor, id, false));
} }
// add format // add format
if (propertyDescriptor.getFormat().equals(PropertyParser.TAG_DECIMAL_FORMAT)) { if (propertyDescriptor.getFormat().equals(PropertyParser.TAG_DECIMAL_FORMAT)) {
property.setPropertyFormat(new DecimalFormat(propertyDescriptor, id, false)); property.setPropertyFormat(new DecimalFormat(propertyDescriptor, id, false));
...@@ -198,10 +196,10 @@ public class PropertyFactory { ...@@ -198,10 +196,10 @@ public class PropertyFactory {
public Property createProperty(int containerId, int id, XMLPropertyDescriptor propertyDescriptor, boolean isCommandBox) { public Property createProperty(int containerId, int id, XMLPropertyDescriptor propertyDescriptor, boolean isCommandBox) {
// Create basic property // Create basic property
String type = propertyDescriptor.getPropertyType().toLowerCase(); String type = propertyDescriptor.getPropertyType().toLowerCase();
Property property = createProperty(containerId, id, type, isCommandBox); Property property = createProperty(containerId, id, type, isCommandBox);
configureProperty(property, propertyDescriptor); configureProperty(property, propertyDescriptor);
return property; return property;
} }
...@@ -217,7 +215,6 @@ public class PropertyFactory { ...@@ -217,7 +215,6 @@ public class PropertyFactory {
return new DynamicProperty(containerId, id, isCommandBox); return new DynamicProperty(containerId, id, isCommandBox);
} }
/** /**
* <p>Walks through the propertyDescriptors map to create Property instances for the given controller id from PropertyDescriptor ones.<br/> * <p>Walks through the propertyDescriptors map to create Property instances for the given controller id from PropertyDescriptor ones.<br/>
* Property instances are stored as values as the returned map (property names as keys).</p> * Property instances are stored as values as the returned map (property names as keys).</p>
...@@ -240,7 +237,6 @@ public class PropertyFactory { ...@@ -240,7 +237,6 @@ public class PropertyFactory {
return properties; return properties;
} }
/** /**
* *
* @param databaseId * @param databaseId
...@@ -271,10 +267,29 @@ public class PropertyFactory { ...@@ -271,10 +267,29 @@ public class PropertyFactory {
} else { } else {
// trying with "double" dynamic properties // trying with "double" dynamic properties
String genericPropertyName = xmlDynamicPropertyDescriptor.getPropertyName(); String genericPropertyName = xmlDynamicPropertyDescriptor.getPropertyName();
int index = 0; Set<DynamicPropertyDescriptor> doubleDynamicPropertyDescriptors = PropertyDatabase.getInstance().getDoubleDynamicPropertyDescriptor(servantId, genericPropertyName);
boolean hasNext = true; if (doubleDynamicPropertyDescriptors != null) {
while (hasNext) { Iterator<DynamicPropertyDescriptor> iter = doubleDynamicPropertyDescriptors.iterator();
while (iter.hasNext()) {
DynamicPropertyDescriptor descriptor = iter.next();
String dynamicPropertyName = descriptor.getName();
LinkedHashSet<Property> childProperties = new LinkedHashSet<Property>();
DynamicProperty dynamicProperty = new DynamicProperty(databaseId, descriptor.getId(), false);
List<Integer> ids = descriptor.getIds();
for (int i = 0; i < ids.size(); i++) {
childProperties.add(createProperty(databaseId, ids.get(i), xmlDynamicPropertyDescriptor, false));
}
dynamicProperty.setProperties(childProperties);
dynamicProperties.put(dynamicPropertyName, dynamicProperty);
}
}
/*
String genericPropertyName = xmlDynamicPropertyDescriptor.getPropertyName();
int index = 0;
boolean hasNext = true;
while (hasNext) {
String indexPropertyName = genericPropertyName + "." + index; String indexPropertyName = genericPropertyName + "." + index;
dynamicPropertyDescriptor = PropertyDatabase.getInstance().getDynamicPropertyDescriptor(servantId, indexPropertyName); dynamicPropertyDescriptor = PropertyDatabase.getInstance().getDynamicPropertyDescriptor(servantId, indexPropertyName);
...@@ -297,14 +312,14 @@ public class PropertyFactory { ...@@ -297,14 +312,14 @@ public class PropertyFactory {
} else { } else {
hasNext = false; hasNext = false;
/*
if (index == 0) { if (index == 0) {
System.err.println("Dynamic property " + genericPropertyName + " from " + servantId + " not found in server"); System.err.println("Dynamic property " + genericPropertyName + " from " + servantId + " not found in server");
} else { } else {
//System.out.println("Dynamic property " + indexPropertyName + " added from " + servantId); //System.out.println("Dynamic property " + indexPropertyName + " added from " + servantId);
}*/ }
} }
} }*/
} }
} }
...@@ -313,7 +328,6 @@ public class PropertyFactory { ...@@ -313,7 +328,6 @@ public class PropertyFactory {
return null; return null;
} }
/** /**
* Clones given property. * Clones given property.
* @param property * @param property
...@@ -327,7 +341,7 @@ public class PropertyFactory { ...@@ -327,7 +341,7 @@ public class PropertyFactory {
int id = property.getPropertyID(); int id = property.getPropertyID();
int databaseId = property.getContainerID(); int databaseId = property.getContainerID();
boolean isCommandBox = property.isCommandBox; boolean isCommandBox = property.isCommandBox;
if (type.equals("int8")) { if (type.equals("int8")) {
clone = new Int8Property(databaseId, id, isCommandBox); clone = new Int8Property(databaseId, id, isCommandBox);
} else if (type.equals("int16")) { } else if (type.equals("int16")) {
...@@ -378,7 +392,6 @@ public class PropertyFactory { ...@@ -378,7 +392,6 @@ public class PropertyFactory {
return clone; return clone;
} }
/** /**
* *
* @param property * @param property
...@@ -390,9 +403,9 @@ public class PropertyFactory { ...@@ -390,9 +403,9 @@ public class PropertyFactory {
clone.setMaxLength(property.getMaxLength()); clone.setMaxLength(property.getMaxLength());
clone.setMaxLengthOnlyForTextFieldSize(true); clone.setMaxLengthOnlyForTextFieldSize(true);
// what is this for ?! // what is this for ?!
//if (!isTrueString) { // ??? // if (!isTrueString) { // ???
// clone.setValue(property.getValue()); // clone.setValue(property.getValue());
//} // }
if (property.getPropertyFormat() != null) { if (property.getPropertyFormat() != null) {
if (property.getPropertyFormat() instanceof UnitFormat) { if (property.getPropertyFormat() instanceof UnitFormat) {
...@@ -401,7 +414,7 @@ public class PropertyFactory { ...@@ -401,7 +414,7 @@ public class PropertyFactory {
} }
return clone; return clone;
} }
/** /**
* *
* @param property * @param property
...@@ -412,7 +425,7 @@ public class PropertyFactory { ...@@ -412,7 +425,7 @@ public class PropertyFactory {
clone.setUndoable(); clone.setUndoable();
clone.setMaxLength(property.getMaxLength()); clone.setMaxLength(property.getMaxLength());
clone.setMaxLengthOnlyForTextFieldSize(true); clone.setMaxLengthOnlyForTextFieldSize(true);
clone.setValue(property.getValue()); clone.setValue(property.getValue());
if (property.getPropertyFormat() != null) { if (property.getPropertyFormat() != null) {
......
...@@ -369,6 +369,29 @@ public class PropertyDatabase { ...@@ -369,6 +369,29 @@ public class PropertyDatabase {
return null; return null;
} }
/**
* Get all "double dynamic" properties that have the same "genericPropertyName"
* Important detail: for a double dynamic property, the name of the propertyDescriptor contains the father index, that is, it is sth like: nameOfDoubleDynamicProperty.i
* @param servantId
* @param genericPropertyName
* @return
*/
public Set<DynamicPropertyDescriptor> getDoubleDynamicPropertyDescriptor(int servantId, String genericPropertyName) {
//Iterate through dynamicPropertiesbyServant to find all the properties that has the same genericPropertyName
Set<DynamicPropertyDescriptor> descriptors = dynamicPropertiesByServant.get(servantId);
Set<DynamicPropertyDescriptor> doubleDynamicDescriptors = new HashSet<DynamicPropertyDescriptor>();
if (descriptors != null) {
Iterator<DynamicPropertyDescriptor> it = descriptors.iterator();
while (it.hasNext()) {
DynamicPropertyDescriptor descriptor = it.next();
if (descriptor.getName().contains(".") && descriptor.getName().contains(genericPropertyName)) {
doubleDynamicDescriptors.add(descriptor);
}
}
}
return doubleDynamicDescriptors;
}
/** /**
* *
......
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