Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
NomadCommandSystem
Commits
2ad3a039
Commit
2ad3a039
authored
Jul 10, 2017
by
Cristina Cocho
Browse files
Added possibility to use dynamic properties to define the property range
of another dynamic property.
parent
f2c650ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
2ad3a039
...
...
@@ -2,6 +2,7 @@
-----
* Catch exception thrown when trying to format a invalid float value (avoid a client crash : see brisp 03 nov 2016).
* Replaced Corba with Cameo.
* Added possibility to use dynamic properties to define a property range ("min_property" and "max_property") of a dynamic property.
3.0.4
-----
...
...
src/main/java/fr/ill/ics/core/property/condition/RangePropertyDependentCondition.java
View file @
2ad3a039
...
...
@@ -18,26 +18,30 @@
package
fr.ill.ics.core.property.condition
;
import
fr.ill.ics.bridge.Controller
;
import
fr.ill.ics.bridge.ControllerManager
;
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.util.ConfigManager
;
import
fr.ill.ics.util.exception.PropertyNotFoundException
;
public
class
RangePropertyDependentCondition
implements
IPropertyCondition
{
private
String
minPropertyName
;
private
String
maxPropertyName
;
private
Property
property
;
private
Property
minProperty
;
private
Property
maxProperty
;
private
boolean
minPropertyExcluded
;
private
boolean
maxPropertyExcluded
;
private
boolean
isDynamic
;
// concerns main property (the one stored in "property" attribute)
private
int
index
;
public
RangePropertyDependentCondition
(
Property
property
,
ConditionDescriptor
conditionDescriptor
,
boolean
isDynamic
)
{
this
.
property
=
property
;
...
...
@@ -46,10 +50,17 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
this
.
minPropertyExcluded
=
conditionDescriptor
.
getMinPropertyExcluded
();
this
.
maxPropertyExcluded
=
conditionDescriptor
.
getMaxPropertyExcluded
();
this
.
isDynamic
=
isDynamic
;
if
(
isDynamic
)
{
try
{
this
.
index
=
Integer
.
valueOf
(
property
.
getName
().
substring
(
property
.
getName
().
indexOf
(
"."
)+
1
));
}
catch
(
Exception
e
)
{
this
.
index
=
-
1
;
}
}
}
public
boolean
isOk
(
String
valueToBeTested
)
{
try
{
if
(
minProperty
==
null
&&
maxProperty
==
null
)
{
int
servantId
=
-
1
;
...
...
@@ -59,20 +70,42 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
servantId
=
PropertyDatabase
.
getInstance
().
getServantIdForProperty
(
property
.
getPropertyID
());
}
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
);
}
}
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
);
}
}
catch
(
PropertyNotFoundException
e
)
{
// not a real problem...
}
}
}
}
if
(
minProperty
!=
null
&&
maxProperty
!=
null
)
{
double
minValue
=
new
Double
(
minProperty
.
getValue
()).
doubleValue
();
double
maxValue
=
new
Double
(
maxProperty
.
getValue
()).
doubleValue
();
double
valueToTest
=
new
Double
(
valueToBeTested
).
doubleValue
();
if
(
minPropertyExcluded
&&
maxPropertyExcluded
)
{
return
(
valueToTest
>
minValue
&&
valueToTest
<
maxValue
);
}
...
...
@@ -92,17 +125,17 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
}
public
String
getErrorMessage
(
String
propertyName
)
{
String
minComparator
=
" >= "
;
String
maxComparator
=
" <= "
;
if
(
minPropertyExcluded
)
{
minComparator
=
" > "
;
}
if
(
maxPropertyExcluded
)
{
maxComparator
=
" < "
;
}
return
propertyName
+
" "
+
ConfigManager
.
getInstance
().
getString
(
"rangeErrorMessage1"
)
+
minComparator
+
minProperty
.
getValue
()
+
" "
+
ConfigManager
.
getInstance
().
getString
(
"rangeErrorMessage2"
)
+
maxComparator
+
maxProperty
.
getValue
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment