...
 
Commits (17)
......@@ -6,6 +6,11 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
......
3.1.1
3.1.10 DD/MM/YYYY
------
3.1.9 12/10/2018
-----
* Change HashMap to TreeMap so that controller and property combo in generic command boxes are sorted.
3.1.8 DD/MM/YYYY
-----
* Remove deprecated code (since Java 10).
3.1.7 30/08/2018
-----
* Modifications for dynamic properties management.
3.1.6 06/04/2018
-----
* Added more control on the subscriber termination in survey.
3.1.5 06/04/2018
-----
* Do not call logoutAll in login. The call is made in the main application (NomadGUI, etc.).
3.1.4 13/03/2018
-----
* Avoid a NullPointerException when ConfigurationException.controllerName is null.
* Fix bug: Bad initialisation of a for loop command box while launching Nomad while the command zone already contains a for loop command box.
3.1.3 09/01/2018
-----
* 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...
* Moved ParameterizableScan1D related classes to GUI special modules.
3.1.2 11/12/2017
-----
* Add methods for getting controller and family icon keys map from server (needed for tablette client).
* Replaced protocol buffers array encoding with Xavier training's project to speed up the transfers.
3.1.1 19/10/2017
-----
* Catch exception thrown when trying to format a invalid float value (avoid a client crash : see brisp 03 nov 2016).
* Replaced Corba with Cameo.
......
......@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.ill.ics</groupId>
<artifactId>nomadcommandsystem</artifactId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<name>NomadCommandSystem</name>
<description>Java bridge for the communication with the Nomad server</description>
<scm>
......@@ -54,14 +54,25 @@
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-api-java-jzmq</artifactId>
<version>0.1.2-SNAPSHOT</version>
<artifactId>protobuf-lite</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-api</artifactId>
<version>0.1.4</version>
<exclusions>
<exclusion>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-com-jeromq</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-com-jzmq</artifactId>
<version>0.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
......@@ -159,6 +170,11 @@
<arg line="${protoFlags} ${protoDir}/CommandLineRequests.proto" />
</exec>
<echo message="Generating VariableManagerRequests.java" />
<exec executable="protoc">
<arg line="${protoFlags} ${protoDir}/VariableManagerRequests.proto" />
</exec>
<echo message="Generating ConditionManagerRequests.java" />
<exec executable="protoc">
<arg line="${protoFlags} ${protoDir}/ConditionManagerRequests.proto" />
......
......@@ -25,7 +25,7 @@ import java.util.Map.Entry;
import fr.ill.ics.nscclient.log.LogSubscriber;
import fr.ill.ics.nscclient.notification.DataNotificationClient;
import fr.ill.ics.nscclient.notification.commandzone.CommandZoneEventClient;
import fr.ill.ics.nscclient.survey.SurveySubcriberImpl;
import fr.ill.ics.nscclient.survey.SurveySubscriberImpl;
public class ChangeManager {
......@@ -56,10 +56,10 @@ public class ChangeManager {
}
// Iterating the map of survey subscribers
Map<String, SurveySubcriberImpl> surveySubscriberMap = SurveySubcriberImpl.getInstances();
Iterator<Entry<String, SurveySubcriberImpl>> it2 = surveySubscriberMap.entrySet().iterator();
Map<String, SurveySubscriberImpl> surveySubscriberMap = SurveySubscriberImpl.getInstances();
Iterator<Entry<String, SurveySubscriberImpl>> it2 = surveySubscriberMap.entrySet().iterator();
while (it2.hasNext()) {
SurveySubcriberImpl surveySubscriber = it2.next().getValue();
SurveySubscriberImpl surveySubscriber = it2.next().getValue();
surveySubscriber.readAndDispatch();
}
}
......
......@@ -41,30 +41,30 @@ import fr.ill.ics.util.exception.ControllerNotFoundException;
public class ControllerManager implements ServerConfigurationChangeListener {
private String serverId;
private HashMap<String, LinkedHashSet<String>> visibleControllerNamesByType; // KEY=controller type VALUE=list of matching controller names
private HashMap<String, LinkedHashSet<String>> allControllerNamesByType; // KEY=controller type VALUE=list of matching controller names
private static ControllerManager instance = null;
public static ControllerManager getInstance() {
return instance;
}
public static void initInstance(String serverId) {
instance = new ControllerManager(serverId);
instance.init();
}
public static void resetInstance() {
instance = null;
}
public static ControllerManager getInstance() {
return instance;
}
public static void initInstance(String serverId) {
instance = new ControllerManager(serverId);
instance.init();
}
public static void resetInstance() {
instance = null;
}
public void addConfigurationChangeListener(ServerConfigurationChangeListener listener) {
DataNotificationClient.getInstance().addConfigurationChangeListener(listener);
}
public ControllerManager(String serverId) {
this.serverId = serverId;
......@@ -81,7 +81,7 @@ public class ControllerManager implements ServerConfigurationChangeListener {
protected void reset() {
try {
ServantManagerAccessor.getInstance(serverId).updateWholeConfiguration();
} catch (LoadConfigurationFailure e) {
System.err.println("Unable to update the whole configuration");
}
......@@ -92,16 +92,17 @@ public class ControllerManager implements ServerConfigurationChangeListener {
/**
*
*/
public ControllerServant getController(String controllerName) {
public ControllerServant getController(String controllerName) throws ControllerNotFoundException {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
ControllerServant controller = ServantManagerAccessor.getInstance(serverId).getController(descriptor);
return controller;
}
ControllerNotFoundException cnfe = new ControllerNotFoundException(controllerName, "", getClass().getCanonicalName(), "getController");
return null;
throw cnfe;
}
public ControllerServant cloneController(String controllerName) throws ControllerNotFoundException {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
......@@ -126,8 +127,8 @@ public class ControllerManager implements ServerConfigurationChangeListener {
public Set<String> getControllersOfType(String type, boolean onlyVisibleOnes) {
return ServantDatabase.getInstance().getControllersOfType(type, onlyVisibleOnes);
}
public Set<String> getControllerTypes() {
return ServantDatabase.getInstance().getControllerTypes();
}
......@@ -138,11 +139,11 @@ public class ControllerManager implements ServerConfigurationChangeListener {
}
public HashMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric() {
public TreeMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric() {
return ServantManagerAccessor.getInstance(serverId).getPropertiesForGeneric();
}
public String getType(String controllerName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
......@@ -150,26 +151,26 @@ public class ControllerManager implements ServerConfigurationChangeListener {
}
return null;
}
private Map<String, Map<String, List<String>>> getInstalledControllers(boolean testCommand) {
Map<String, Map<String, List<String>>> installedControllers = new TreeMap<String, Map<String, List<String>>>();
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getControllers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
boolean testCommandOk = true;
if (testCommand && !descriptor.isCommand()) {
testCommandOk = false;
}
if (testCommandOk && descriptor.isEnabled() && descriptor.isVisible()) {
String family = descriptor.getFamily();
String subfamily = descriptor.getSubfamily();
Map<String, List<String>> familyMembers = installedControllers.get(family);
if (familyMembers == null) {
familyMembers = new TreeMap<String, List<String>>();
......@@ -177,23 +178,23 @@ public class ControllerManager implements ServerConfigurationChangeListener {
}
if (subfamily.equals("none")) {
familyMembers.put(descriptor.getName(), new ArrayList<String>());
} else {
List<String> subfamilyMembers = familyMembers.get(subfamily);
if (subfamilyMembers == null) {
subfamilyMembers = new ArrayList<String>();
familyMembers.put(subfamily, subfamilyMembers);
}
subfamilyMembers.add(descriptor.getName());
}
}
}
return installedControllers;
}
......@@ -201,7 +202,7 @@ public class ControllerManager implements ServerConfigurationChangeListener {
public Map<String, Map<String, List<String>>> getInstalledControllers() {
return getInstalledControllers(false);
}
public Map<String, Map<String, List<String>>> getInstalledCommands() {
return getInstalledControllers(true);
}
......@@ -246,13 +247,17 @@ public class ControllerManager implements ServerConfigurationChangeListener {
public Set getStartedControllers() {
Set startedCommands = new HashSet();
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getControllers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
ControllerServant controller = getController(descriptor.getName());
if (controller.isStarted()) {
startedCommands.add(controller);
try {
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getControllers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
ControllerServant controller = getController(descriptor.getName());
if (controller.isStarted()) {
startedCommands.add(controller);
}
}
} catch (ControllerNotFoundException e) {
e.printStackTrace();
}
return startedCommands;
}
......@@ -278,7 +283,7 @@ public class ControllerManager implements ServerConfigurationChangeListener {
}
return null;
}
public String getSubfamily(String controllerName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
......@@ -302,13 +307,17 @@ public class ControllerManager implements ServerConfigurationChangeListener {
}
public void configurationChanged(int servantID, ClientEnableState enable) {
// the reload of controllers is not made here but in the CommandsSelectionPlugin
// and SettingsSelectionPlugin classes
ServantManagerAccessor.getInstance(serverId).updateDynamicProperties(servantID);
public void configurationChanged(int servantID, ClientConfigurationState enable) {
// The reloading of controllers is not made here but in the CommandsSelectionPlugin
// and SettingsSelectionPlugin classes.
if (enable == ClientConfigurationState.PROPERTY) {
ServantManagerAccessor.getInstance(serverId).updateDynamicProperties(servantID);
System.out.println("ServantManagerAccessor updateDynamicProperties " + servantID);
}
}
public void reloadControllers() {
// reset controller information
reset();
......@@ -318,11 +327,11 @@ public class ControllerManager implements ServerConfigurationChangeListener {
ControllerServant controller = (ControllerServant)servant;
return ServantManagerAccessor.getInstance(serverId).getControllerNameWithRole(controller.getId(), role);
}
public HashMap<String, String> getServantPropertiesValue(int databaseID, int servantID) {
return ServantManagerAccessor.getInstance(serverId).getServantPropertiesValue(databaseID, servantID);
}
public HashMap<String, Integer> getServantCommandStates(int databaseID, int servantID) {
return ServantManagerAccessor.getInstance(serverId).getServantCommandStates(databaseID, servantID);
}
......
......@@ -152,4 +152,9 @@ public class DriverManager {
ServantManagerAccessor.getInstance(serverId).reconnectDriver(driver.getDatabaseId(), driver.getId());
}
}
public Set<String> getDriverTypes() {
return ServantDatabase.getInstance().getDriverTypes();
}
}
\ No newline at end of file
......@@ -19,6 +19,8 @@
package fr.ill.ics.bridge;
import java.util.HashMap;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor;
import fr.ill.ics.nscclient.servant.ResourceNotFoundException;
......@@ -85,7 +87,7 @@ public class ResourceManager {
public void setFileContent(String controllerType, String fileName, String content) {
System.out.println("H.ORTIZ: call to writeResourceFile commented .................................................." + fileName);
//System.out.println("H.ORTIZ: call to writeResourceFile commented .................................................." + fileName);
//ServantManagerAccessor.getInstance(serverId).writeResourceFile(controllerType, fileName, content);
......@@ -104,4 +106,13 @@ public class ResourceManager {
}
*/
}
public HashMap<String, String> getFamilyImageKeys() {
return ServantManagerAccessor.getInstance(serverId).getFamilyImageKeys();
}
public HashMap<String, String> getControllerIconKeys() {
return ServantManagerAccessor.getInstance(serverId).getControllerIconKeys();
}
}
......@@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import fr.ill.ics.bridge.listeners.ServerSurveyXMLListener;
import fr.ill.ics.nscclient.survey.SurveySubcriberImpl;
import fr.ill.ics.nscclient.survey.SurveySubscriberImpl;
public class SurveyEventSender {
......@@ -47,11 +47,11 @@ public class SurveyEventSender {
* @param listener
*/
public void addSurveyXMLListener(ServerSurveyXMLListener listener) {
SurveySubcriberImpl.getInstance(serverId).addSurveyXMLListener(listener);
SurveySubscriberImpl.getInstance(serverId).addSurveyXMLListener(listener);
}
public void removeSurveyXMLListener(ServerSurveyXMLListener listener) {
SurveySubcriberImpl.getInstance(serverId).removeSurveyXMLListener(listener);
SurveySubscriberImpl.getInstance(serverId).removeSurveyXMLListener(listener);
}
}
\ No newline at end of file
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.bridge.events;
/**
*
* @author ortizh
*
*/
public class ServerVariableStateChangeEvent {
private String variableName;
private VariableState state;
public enum VariableState {DISABLED, ENABLED}
public ServerVariableStateChangeEvent(String variableName) {
this.variableName = variableName;
}
public String getVariableName() {
return variableName;
}
public void setVariableName(String variableName) {
this.variableName = variableName;
}
public VariableState getState() {
return state;
}
public void setState(VariableState state) {
this.state = state;
};
public boolean isEnabled() {
return (state == VariableState.ENABLED);
}
public boolean isDisabled() {
return (state == VariableState.DISABLED);
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.bridge.events;
/**
*
* @author ortizh
*
*/
public class ServerVariableValueChangeEvent {
private String variableName;
private double variableValue;
public ServerVariableValueChangeEvent(String variableName, double variableValue) {
this.variableName = variableName;
this.variableValue = variableValue;
}
public String getVariableName() {
return variableName;
}
public void setVariableName(String variableName) {
this.variableName = variableName;
}
public double getVariableValue() {
return variableValue;
}
public void setVariableValue(double variableValue) {
this.variableValue = variableValue;
}
}
......@@ -21,8 +21,8 @@ package fr.ill.ics.bridge.listeners;
public interface ServerConfigurationChangeListener {
public enum ClientEnableState {ENABLED, DISABLED, NO_CHANGE};
public enum ClientConfigurationState {ENABLED, DISABLED, TREE, PROPERTY};
void configurationChanged(int servantID, ClientEnableState enable);
void configurationChanged(int servantID, ClientConfigurationState enable);
}
\ No newline at end of file
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.bridge.listeners;
import fr.ill.ics.bridge.events.ServerVariableStateChangeEvent;
import fr.ill.ics.bridge.events.ServerVariableValueChangeEvent;
/**
*
* @author ortizh
*
*/
public interface ServerVariableValueChangeListener {
public void variableValueChanged(ServerVariableValueChangeEvent variableValueChangeEvent);
public void variableStateChanged(ServerVariableStateChangeEvent variableStateChangeEvent);
}
\ No newline at end of file
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.bridge.scan;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import fr.ill.ics.core.property.Property;
public interface IParameterizableScan1D {
public final static String NO_OPTIMIZATION = "none";
public final static String MULTI_GAUSSIAN_FIT = "multi gaussian fit";
public final static String POLYNOMIAL_FIT = "polynomial fit";
public final static String CENTER_OF_MASS = "center of mass";
public final static String GAUSSIAN_FIT = "gaussian fit";
public final static String BEST_FIT = "best fit";
public final static String NO_ACTION = "none";
public final static String GOTO_ACTION = "goto";
public final static String OFFSET_ACTION = "offset";
/**
* Class to pass data from Nomad to the bridge.
* Same content than ParameterizableScan1DLine in Nomad project
* @author legoc
*
*/
public static class Variable {
public final static int MODE_INTERVAL = 0;
public final static int MODE_DELTA = 1;
public final static int MODE_FLIP = 2;
public final static int MODE_EXPLICIT_VALUES = 3;
public final static int MODE_DELTA_INTERVAL = 4;
public int modeType = MODE_INTERVAL;
public final static int DELTA_MIN = 0;
public final static int DELTA_MAX = 1;
public final static int DELTA_CENTER = 2;
public int deltaType = DELTA_MIN;
public String controllerName;
public String wantedPropertyName;
public String value1 = "0";
public String value2 = "0";
public String value3 = "0";
public double currentValue;
public String values = "";
public String toString() {
return "Variable controller = " + controllerName + ", property = " + wantedPropertyName + ", mode = " + modeType + ", delta = " + deltaType + ", value1 = " + value1 + ", value2 = " + value2 + ", nb steps = " + value3 + ", current = " + currentValue + ", values = " + values;
}
};
public static class ActualProperties {
public LinkedList<Property> steps = new LinkedList<Property>();
public LinkedList<Property> values = new LinkedList<Property>();
}
public static class OptimizationParameters {
public String optimizationType;
public String fitOrder;
public String actionType;
public String toString() {
return "Optimization parameters type = " + optimizationType + ", fit order = " + fitOrder + ", action = " + actionType;
}
}
public ActualProperties getServerVariables(Map<String, Property> properties, Map<String, Property> realDynamicProperties, List<Variable> variables, OptimizationParameters optimizationParameters, boolean isInForLoop);
public ActualProperties setServerVariables(Map<String, Property> properties, Map<String, Property> realDynamicProperties, List<Variable> variables, OptimizationParameters optimizationParameters, boolean isInForLoop);
public void setOptimization(Map<String, Property> map, String value);
public void setAction(Map<String, Property> properties, String value);
public void setFitOrder(Map<String, Property> properties, String value);
public void setMoment(Map<String, Property> properties, String value);
public String getOptimization(Map<String, Property> properties);
public String getAction(Map<String, Property> properties);
public String getFitOrder(Map<String, Property> properties);
public String getMoment(Map<String, Property> properties);
public void loadVariable(String role, String propertyName, String value, List<Variable> variables, OptimizationParameters optimizationParameters);
public void setRole(String newRole);
}
\ No newline at end of file
......@@ -26,11 +26,9 @@ import java.util.Set;
import fr.ill.ics.bridge.Controller;
import fr.ill.ics.bridge.ControllerManager;
import fr.ill.ics.bridge.command.AtomicCommandWrapper;
import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nscclient.dataprovider.CommandDatabase;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientCommandState;
import fr.ill.ics.nscclient.servant.Servant;
import fr.ill.ics.util.ConfigManager;
import fr.ill.ics.util.exception.CommandNotFoundException;
import fr.ill.ics.util.exception.ConfigurationException.PluginType;
......
......@@ -58,6 +58,10 @@ public abstract class ArrayProperty extends Property {
}
}
}
public boolean isConstant(String value) {
return true;
}
/**
* For array properties the getServerValue has no meaning and shouldn't be used.
......@@ -67,12 +71,20 @@ public abstract class ArrayProperty extends Property {
public String getServerValue() {
return "Array Property";
}
public GetExpressionResult getServerExpression() {
return new GetExpressionResult("Array Expression", ExpressionStatus.VALID_CONSTANT);
}
public ExpressionResult checkServerValue(String value) {
return new ExpressionResult(ExpressionStatus.VALID_CONSTANT);
}
/**
* SetServerValue has no meaning for array properties. Do nothing.
*/
public boolean setServerValue(String value) {
return true;
public ExpressionResult setServerValue(String value) {
return new ExpressionResult(ExpressionStatus.VALID_CONSTANT);
}
/**
......@@ -141,11 +153,13 @@ public abstract class ArrayProperty extends Property {
return 100;
}
public Property cloneAsString(boolean isTrueString) {
// don't clone array as string
return this;
@Override
protected String getPropertyValueFromDatabase() {
return "array";
}
protected boolean setPropertyValueInDatabase(String value) {
return false;
}
public abstract float getMinValue();
......
......@@ -18,7 +18,6 @@
package fr.ill.ics.core.property;
import fr.ill.ics.nscclient.command.CommandZoneAccessor;
import fr.ill.ics.nscclient.dataprovider.DataAccessor;
public class BooleanProperty extends Property {
......@@ -27,38 +26,21 @@ public class BooleanProperty extends Property {
super(containerId, id, isCommandBox);
}
public void setPVerifyListener() {
}
public String getServerValue() {
// Don't use format for the moment. The value can only be "true" or "false"
if (isCommandBox) {
return Boolean.toString(CommandZoneAccessor.getInstance(serverId).getBooleanValue(containerId, id));
} else {
return Boolean.toString(DataAccessor.getInstance(serverId).getBooleanValue(containerId, id));
public boolean isConstant(String value) {
try {
Boolean.parseBoolean(value);
return true;
}
}
public boolean setServerValue(String value) {
// don't check value matches conditions: we only have a choice of "true" or "false"
//try {
boolean ok = true;
if (isCommandBox) {
ok = CommandZoneAccessor.getInstance(serverId).setBooleanValue(containerId, id, Boolean.valueOf(value).booleanValue());
} else {
ok = DataAccessor.getInstance(serverId).setBooleanValue(containerId, id, Boolean.valueOf(value).booleanValue());
if (!ok) {
sendPropertyChangedEvent();
}
catch (NumberFormatException e) {
return false;
}
showSettingPropertyMessage(value);
return ok;
//} catch (CannotSetValueException e) {
// // if the value is refused then update all widgets with the true value.
// sendPropertyChangedEvent();
//}
}
public void setPVerifyListener() {
}
public boolean propertyAcceptsValue(String value, boolean isFinalValue) {
if (value.trim().toLowerCase().equals("true") || value.trim().toLowerCase().equals("false")) {
return true;
......@@ -78,4 +60,14 @@ public class BooleanProperty extends Property {
public String getType() {
return "boolean";
}
@Override
protected String getPropertyValueFromDatabase() {
return Boolean.toString(DataAccessor.getInstance(serverId).getBooleanValue(containerId, id));
}
@Override
protected boolean setPropertyValueInDatabase(String value) {
return DataAccessor.getInstance(serverId).setBooleanValue(containerId, id, Boolean.valueOf(this.propertyFormat.unformat(value)).booleanValue());
}
}
\ No newline at end of file
......@@ -18,9 +18,7 @@
package fr.ill.ics.core.property;
import fr.ill.ics.nscclient.command.CommandZoneAccessor;
import fr.ill.ics.nscclient.dataprovider.DataAccessor;
import fr.ill.ics.util.ConfigManager;
public class Float64Property extends FloatProperty {
......@@ -28,44 +26,28 @@ public class Float64Property extends FloatProperty {
super(containerId, id, isCommandBox);
}
public String getServerValue() {
try {
if (isCommandBox) {
return this.propertyFormat.formatForDisplay(new Double(CommandZoneAccessor.getInstance(serverId).getFloat64Value(containerId, id)).toString());
} else {
return this.propertyFormat.formatForDisplay(new Double(DataAccessor.getInstance(serverId).getFloat64Value(containerId, id)).toString());
}
} catch (Exception e) {
System.err.println("Exception while getting value for property " + getName());
ConfigManager.CONFIGURATION_ERROR = true;
return "";
}
}
public boolean isConstant(String value) {
public boolean setServerValue(String value) {
try {
String serverValue = this.propertyFormat.unformat(value);
boolean ok = isOk(serverValue);
if (ok) {
if (isCommandBox) {
ok = CommandZoneAccessor.getInstance(serverId).setFloat64Value(containerId, id, new Double(serverValue).doubleValue());
} else {
ok = DataAccessor.getInstance(serverId).setFloat64Value(containerId, id, new Double(serverValue).doubleValue());
if (!ok) {
sendPropertyChangedEvent();
}
}
showSettingPropertyMessage(value);
}
return ok;
} catch (NumberFormatException nfe) {
System.err.println("Number format exception while setting property " + getName() + " to " + value);
ConfigManager.CONFIGURATION_ERROR = true;
Double.parseDouble(value);
return true;
}
catch (NumberFormatException e) {
return false;
}
}
}
public String getType() {
return "float64";
}
@Override
protected String getPropertyValueFromDatabase() {
return Double.valueOf(DataAccessor.getInstance(serverId).getFloat64Value(containerId, id)).toString();
}
@Override
protected boolean setPropertyValueInDatabase(String value) {
return DataAccessor.getInstance(serverId).setFloat64Value(containerId, id, Double.valueOf(this.propertyFormat.unformat(value)));
}
}
\ No newline at end of file
......@@ -18,9 +18,7 @@
package fr.ill.ics.core.property;
import fr.ill.ics.nscclient.command.CommandZoneAccessor;
import fr.ill.ics.nscclient.dataprovider.DataAccessor;
import fr.ill.ics.util.ConfigManager;
public class Int32Property extends IntegerProperty {
......@@ -28,39 +26,28 @@ public class Int32Property extends IntegerProperty {
super(containerId, id, isCommandBox);
}
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.formatForDisplay(new Integer(CommandZoneAccessor.getInstance(serverId).getInt32Value(containerId, id)).toString());
} else {
return this.propertyFormat.formatForDisplay(new Integer(DataAccessor.getInstance(serverId).getInt32Value(containerId, id)).toString());
}
}
public boolean setServerValue(String value) {
public boolean isConstant(String value) {
try {
String serverValue = this.propertyFormat.unformat(value);
boolean ok = isOk(serverValue);
if (ok) {
if (isCommandBox) {
ok = CommandZoneAccessor.getInstance(serverId).setInt32Value(containerId, id, new Integer(serverValue).intValue());
} else {
ok = DataAccessor.getInstance(serverId).setInt32Value(containerId, id, new Integer(serverValue).intValue());
if (!ok) {
sendPropertyChangedEvent();
}
}
showSettingPropertyMessage(value);
}
return ok;
} catch (NumberFormatException nfe) {
System.err.println("Number format exception while setting property " + getName() + " to " + value);
ConfigManager.CONFIGURATION_ERROR = true;
Integer.parseInt(value);
return true;
}
catch (NumberFormatException e) {
return false;
}
}
public String getType() {
return "int32";
}
@Override
protected String getPropertyValueFromDatabase() {
return Integer.valueOf(DataAccessor.getInstance(serverId).getInt32Value(containerId, id)).toString();
}
@Override
protected boolean setPropertyValueInDatabase(String value) {
return DataAccessor.getInstance(serverId).setInt32Value(containerId, id, Integer.valueOf(this.propertyFormat.unformat(value)));
}
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ public abstract class IntegerProperty extends Property {
// String serverValue = this.propertyFormat.unformat(value);
// if (isOk(serverValue)) {
// try {
// abstractController.setValueByLong(name, new Integer(serverValue).intValue());
// abstractController.setValueByLong(name, Integer.valueOf(serverValue));
// showSettingPropertyMessage(value);
// } catch (CannotSetValueException e) {
// // if the value is refused then update all widgets with the true value.
......
......@@ -345,55 +345,14 @@ public class PropertyFactory {
// max length
clone.setMaxLength(property.getMaxLength());
//System.out.println("cloning " + property + " " + property.isCommandBox());
// add conditions
if (property.getConditions() != null) {
clone.setConditions(new ArrayList<IPropertyCondition>(property.getConditions()));
}
return clone;
}
/**
*
* @param property
* @return
*/
public StringProperty clonePropertyAsString(Property property) {
StringProperty clone = new StringProperty(property.getContainerID(), property.getPropertyID(), property.isCommandBox);
clone.setUndoable();
clone.setMaxLength(property.getMaxLength());
clone.setMaxLengthOnlyForTextFieldSize(true);
// what is this for ?!
// if (!isTrueString) { // ???
// clone.setValue(property.getValue());
// }
if (property.getPropertyFormat() != null) {
if (property.getPropertyFormat() instanceof UnitFormat) {
clone.setPropertyFormat(new UnitFormat());
}
}
return clone;
}
/**
*
* @param property
* @return
*/
public StringProperty clonePropertyAsStringForEditor(Property property) {
StringProperty clone = new StringProperty(property.getContainerID(), property.getPropertyID(), property.isCommandBox);
clone.setUndoable();
clone.setMaxLength(property.getMaxLength());
clone.setMaxLengthOnlyForTextFieldSize(true);
clone.setValue(property.getValue());
if (property.getPropertyFormat() != null) {
if (property.getPropertyFormat() instanceof UnitFormat) {
clone.setPropertyFormat(new UnitFormat());
}
}
return clone;
}
}
......@@ -20,7 +20,6 @@ package fr.ill.ics.core.property;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
......@@ -54,6 +53,7 @@ import fr.ill.ics.util.ConfigManager;
import fr.ill.ics.util.FileHelper;
import fr.ill.ics.util.exception.ConfigurationException;
import fr.ill.ics.util.exception.ConfigurationException.PluginType;
import fr.ill.ics.util.exception.ControllerNotFoundException;
import fr.ill.ics.util.exception.PropertyNotFoundException;
public class PropertyManager {
......@@ -119,70 +119,78 @@ public class PropertyManager {
* Get all controllers installed in the server. For each one create all necessary properties
*/
private void createAllProperties() {
// Drivers
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getDrivers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
boolean clientFilesExist = readPropertiesClientFilesFor(descriptor.getType());
if (clientFilesExist) {
Controller controller = DriverManager.getInstance().getDriver(descriptor.getName());
createPropertiesForController((Servant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((Servant)controller).getType())) {
createDynamicPropertiesForController((Servant)controller);
try {
// Drivers
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getDrivers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
boolean clientFilesExist = readPropertiesClientFilesFor(descriptor.getType());
if (clientFilesExist) {
Controller controller = DriverManager.getInstance().getDriver(descriptor.getName());
createPropertiesForController((Servant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((Servant)controller).getType())) {
createDynamicPropertiesForController((Servant)controller);
}
}
}
}
// Controllers
it = ServantDatabase.getInstance().getControllers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
boolean clientFilesExist = readPropertiesClientFilesFor(descriptor.getType());
if (clientFilesExist) {
Controller controller = ControllerManager.getInstance().getController(descriptor.getName());
createPropertiesForController((Servant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((Servant)controller).getType())) {
createDynamicPropertiesForController((Servant)controller);
// Controllers
it = ServantDatabase.getInstance().getControllers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
boolean clientFilesExist = readPropertiesClientFilesFor(descriptor.getType());
if (clientFilesExist) {
Controller controller = ControllerManager.getInstance().getController(descriptor.getName());
createPropertiesForController((Servant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((Servant)controller).getType())) {
createDynamicPropertiesForController((Servant)controller);
}
}
}
} catch (ControllerNotFoundException e) {
e.printStackTrace();
}
}
public void createInheritedProperties(String type, String superType) {
if (!propertiesByControllerType.containsKey(superType)) {
initialiseControllerTypeProperties(superType);
}
if (propertiesByControllerType.containsKey(superType)) {
propertiesByControllerType.put(type, propertiesByControllerType.get(superType));
clientFilesFoundPerControllerType.put(type, true);
}
try {
if (!propertiesByControllerType.containsKey(superType)) {
initialiseControllerTypeProperties(superType);
}
if (propertiesByControllerType.containsKey(superType)) {
propertiesByControllerType.put(type, propertiesByControllerType.get(superType));
clientFilesFoundPerControllerType.put(type, true);
}
if (dynamicPropertiesByControllerType.containsKey(superType)) {
dynamicPropertiesByControllerType.put(type, dynamicPropertiesByControllerType.get(superType));
clientFilesFoundPerControllerType.put(type, true);
}
Set<String> drivers = ServantDatabase.getInstance().getDriversOfType(type, false);
if (drivers != null && !drivers.isEmpty()) {
for (String driverName : drivers) {
Controller controller = DriverManager.getInstance().getDriver(driverName);
createPropertiesForController((Servant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((Servant)controller).getType())) {
createDynamicPropertiesForController((Servant)controller);
}
if (dynamicPropertiesByControllerType.containsKey(superType)) {
dynamicPropertiesByControllerType.put(type, dynamicPropertiesByControllerType.get(superType));
clientFilesFoundPerControllerType.put(type, true);
}
}
Set<String> controllers = ControllerManager.getInstance().getControllersOfType(type, false);
if (controllers != null && !controllers.isEmpty()) {
for (String controllerName : controllers) {
Controller controller = ControllerManager.getInstance().getController(controllerName);
createPropertiesForController((Servant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((Servant)controller).getType())) {
createDynamicPropertiesForController((Servant)controller);
Set<String> drivers = ServantDatabase.getInstance().getDriversOfType(type, false);
if (drivers != null && !drivers.isEmpty()) {
for (String driverName : drivers) {
Controller controller = DriverManager.getInstance().getDriver(driverName);
createPropertiesForController((Servant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((Servant)controller).getType())) {
createDynamicPropertiesForController((Servant)controller);
}
}
}
Set<String> controllers = ControllerManager.getInstance().getControllersOfType(type, false);
if (controllers != null && !controllers.isEmpty()) {
for (String controllerName : controllers) {
Controller controller = ControllerManager.getInstance().getController(controllerName);
createPropertiesForController((Servant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((Servant)controller).getType())) {
createDynamicPropertiesForController((Servant)controller);
}
}
}
} catch (ControllerNotFoundException e) {
e.printStackTrace();
}
}
......@@ -284,12 +292,8 @@ public class PropertyManager {
}
/**
*
* @param controller
*/
public void deleteDynamicPropertyFromController(Servant servant, String propertyName) {
HashMap<String, DynamicProperty> dynamicProperties = dynamicPropertyMap.get(servant.getId());
public void deleteDynamicPropertyFromController(Controller controller, String propertyName) {
HashMap<String, DynamicProperty> dynamicProperties = dynamicPropertyMap.get(controller.getDatabaseId());
if (dynamicProperties != null) {
dynamicProperties.remove(propertyName);
}
......@@ -696,7 +700,7 @@ public class PropertyManager {
}
return property;
}
/**
* Search dynamic property
*/
......@@ -899,45 +903,6 @@ public class PropertyManager {
propertiesByControllerType.put(controllerType, properties);
}
/**
*
* @param controller
* @param property
* @param isTrueString
*/
public void changeToString(Controller controller, Property property, boolean isTrueString) {
if (controller instanceof AtomicCommandWrapper) {
AtomicCommandWrapper command = (AtomicCommandWrapper)controller;
CommandBoxKey key = new CommandBoxKey(command.getServerId(), command.getId());
Map<String, Property> properties = commandBoxPropertyMap.get(key);
Property clone = property.cloneAsString(isTrueString);
clone.setServerId(command.getServerId());
properties.put(property.getName(), clone);
}
}
/**
*
* @param controller
* @param property
* @param isTrueString
*/
public void changeDynamicToString(Controller controller, Property property, boolean isTrueString) {
if (controller instanceof AtomicCommandWrapper) {
AtomicCommandWrapper command = (AtomicCommandWrapper)controller;
CommandBoxKey key = new CommandBoxKey(command.getServerId(), command.getId());
Map<String, Property> properties = commandBoxDynamicPropertyMap.get(key);
Property clone = property.cloneAsString(isTrueString);
clone.setServerId(command.getServerId());
properties.put(property.getName(), clone);
properties = commandBoxDynamicPropertyMap.get(key);
}
}
/**
* Returns a sorted set containing all property names for given controller type.
* @param controllerType controller type
......@@ -1149,9 +1114,9 @@ public class PropertyManager {
return exists;
}
public Collection<String> getChildrenOfAllDynamicProperties(String controllerName) {
Set<String> dynamicProperties = new HashSet<String>();
public TreeSet<String> getChildrenOfAllDynamicProperties(String controllerName) {
Set<String> properties = new HashSet<String>();
TreeSet<String> dynamicProperties = new TreeSet<String>();
Iterator<String> it = PropertyManager.getInstance().getDynamicPropertiesForController(controllerName).iterator();
String controllerType = ControllerManager.getInstance().getType(controllerName);
......
......@@ -19,43 +19,59 @@
package fr.ill.ics.core.property;
import fr.ill.ics.nscclient.command.CommandZoneAccessor;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.GetPropertyExpressionResult;
import fr.ill.ics.nscclient.dataprovider.DataAccessor;
import fr.ill.ics.util.ConfigManager;
public class StringProperty extends Property {
public StringProperty(int containerId, int id, boolean isCommandBox) {
super(containerId, id, isCommandBox);
}
public boolean isConstant(String value) {
return true;
}
public GetExpressionResult getServerExpression() {
try {
if (isCommandBox) {
// Get the expression.
GetPropertyExpressionResult result = CommandZoneAccessor.getInstance(serverId).getPropertyExpression(containerId, id);
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.formatForDisplay(CommandZoneAccessor.getInstance(serverId).getStringValue(containerId, id));
} else {
return this.propertyFormat.formatForDisplay(DataAccessor.getInstance(serverId).getStringValue(containerId, id));
// Check if we need to do something.
return new GetExpressionResult(result.getExpression(), ExpressionStatus.VALID_CONSTANT);
}
else {
// Get the value from the database and format it.
return new GetExpressionResult(this.propertyFormat.formatForDisplay(DataAccessor.getInstance(serverId).getStringValue(containerId, id)), ExpressionStatus.VALID_CONSTANT);
}
} catch (Exception e) {
System.err.println("Exception while getting value for property " + getName());
ConfigManager.CONFIGURATION_ERROR = true;
return new GetExpressionResult("", ExpressionStatus.INVALID_CONSTANT, ExpressionError.NO_ERROR, "Exception while getting value");
}
}
public ExpressionResult checkServerValue(String value) {
if (isCommandBox) {
// First check the expression without setting it.
CommandZoneAccessor.ExpressionResult result = CommandZoneAccessor.getInstance(serverId).checkPropertyExpression(containerId, id, value);
public boolean setServerValue(String value) {
String serverValue = this.propertyFormat.unformat(value);
boolean ok = isOk(serverValue);
if (ok) {
// try {
if (isCommandBox) {
ok = CommandZoneAccessor.getInstance(serverId).setStringValue(containerId, id, serverValue);
} else {
ok = DataAccessor.getInstance(serverId).setStringValue(containerId, id, serverValue);
if (!ok) {
sendPropertyChangedEvent();
}
if (result.getStatus() == CommandZoneAccessor.ExpressionStatus.INVALID_EXPRESSION) {
return new ExpressionResult(ExpressionStatus.INVALID_EXPRESSION, ExpressionResult.convertExpressionError(result.getError()), result.getMessage());
}
else {
return new ExpressionResult(ExpressionStatus.VALID_EXPRESSION);
}
showSettingPropertyMessage(value);
// } catch (CannotSetValueException e) {
// // if the value is refused then update all widgets with the true value.
// sendPropertyChangedEvent();
// }
}
return ok;
return new ExpressionResult(ExpressionStatus.VALID_CONSTANT);
}
public void setPVerifyListener() {
// no verify listener needed
......@@ -77,4 +93,14 @@ public class StringProperty extends Property {
public String getType() {
return "string";
}
@Override
protected String getPropertyValueFromDatabase() {
return DataAccessor.getInstance(serverId).getStringValue(containerId, id);
}
@Override
protected boolean setPropertyValueInDatabase(String value) {
return DataAccessor.getInstance(serverId).setStringValue(containerId, id, this.propertyFormat.unformat(value));
}
}
\ No newline at end of file
......@@ -31,7 +31,7 @@ public class GreaterThanPropertyCondition implements IPropertyCondition {
public boolean isOk(String valueToBeTested) {
try {
boolean isOk = (new Double(valueToBeTested).doubleValue() >= value);
boolean isOk = (Double.valueOf(valueToBeTested) >= value);
return isOk;
} catch (NumberFormatException e) {
return false;
......
......@@ -31,7 +31,7 @@ public class LowerThanPropertyCondition implements IPropertyCondition {
public boolean isOk(String valueToBeTested) {
try {
boolean isOk = (new Double(valueToBeTested).doubleValue() <= this.value);
boolean isOk = (Double.valueOf(valueToBeTested) <= this.value);
return isOk;
} catch (NumberFormatException e) {
return false;
......
......@@ -25,7 +25,7 @@ public class PositivePropertyCondition implements IPropertyCondition {
public boolean isOk(String valueToBeTested) {
try {
boolean isOk = (new Double(valueToBeTested).doubleValue() >= 0);
boolean isOk = (Double.valueOf(valueToBeTested) >= 0);
return isOk;
} catch (NumberFormatException e) {
return false;
......