Commit 03f77b23 authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Propagate setSelected calls using parameters observers.

parent 459d7b8e
......@@ -142,10 +142,8 @@ public class ParameterDriver {
/** Change the name of this parameter driver.
* @param name new name
* @exception OrekitException if an observer throws one
*/
public void setName(final String name)
throws OrekitException {
public void setName(final String name) {
final String previousName = this.name;
this.name = name;
for (final ParameterObserver observer : observers) {
......@@ -223,10 +221,9 @@ public class ParameterDriver {
/** Set reference date.
* @param newReferenceDate new reference date
* @exception OrekitException if an observer throws one
* @since 9.0
*/
public void setReferenceDate(final AbsoluteDate newReferenceDate) throws OrekitException {
public void setReferenceDate(final AbsoluteDate newReferenceDate) {
final AbsoluteDate previousReferenceDate = getReferenceDate();
referenceDate = newReferenceDate;
for (final ParameterObserver observer : observers) {
......@@ -268,7 +265,11 @@ public class ParameterDriver {
* otherwise it will be fixed
*/
public void setSelected(final boolean selected) {
final boolean previousSelection = isSelected();
this.selected = selected;
for (final ParameterObserver observer : observers) {
observer.selectionChanged(previousSelection, this);
}
}
/** Check if parameter is selected.
......
......@@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.List;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitExceptionWrapper;
import org.orekit.time.AbsoluteDate;
......@@ -196,15 +197,6 @@ public class ParameterDriversList {
}
/** {@inheritDoc} */
@Override
public void setSelected(final boolean selected) {
super.setSelected(selected);
for (final ParameterDriver driver : drivers) {
driver.setSelected(selected);
}
}
/** Get the raw drivers to which this one delegates.
* <p>
* These raw drivers all manage the same parameter name.
......@@ -228,30 +220,42 @@ public class ParameterDriversList {
@Override
public void valueChanged(final double previousValue, final ParameterDriver driver)
throws OrekitException {
updateAll(driver, d -> d.setValue(driver.getValue()));
try {
updateAll(driver, d -> {
try {
d.setValue(driver.getValue());
} catch (OrekitException oe) {
throw new OrekitExceptionWrapper(oe);
}
});
} catch (OrekitExceptionWrapper oew) {
throw oew.getException();
}
}
/** {@inheritDoc} */
@Override
public void referenceDateChanged(final AbsoluteDate previousReferenceDate, final ParameterDriver driver)
throws OrekitException {
public void referenceDateChanged(final AbsoluteDate previousReferenceDate, final ParameterDriver driver) {
updateAll(driver, d -> d.setReferenceDate(driver.getReferenceDate()));
}
/** {@inheritDoc} */
@Override
public void nameChanged(final String previousName, final ParameterDriver driver)
throws OrekitException {
public void nameChanged(final String previousName, final ParameterDriver driver) {
updateAll(driver, d -> d.setName(driver.getName()));
}
/** {@inheritDoc} */
@Override
public void selectionChanged(final boolean previousSelection, final ParameterDriver driver) {
updateAll(driver, d -> d.setSelected(driver.isSelected()));
}
/** Update all bound parameters.
* @param driver driver triggering the update
* @param updater updater to use
* @throws OrekitException if the update fails
*/
private void updateAll(final ParameterDriver driver, final Updater updater)
throws OrekitException {
private void updateAll(final ParameterDriver driver, final Updater updater) {
final boolean firstCall = depth++ == 0;
if (firstCall) {
......@@ -286,9 +290,8 @@ public class ParameterDriversList {
private interface Updater {
/** Update a driver.
* @param driver driver to update
* @throws OrekitException if the update fails
*/
void update(ParameterDriver driver) throws OrekitException;
void update(ParameterDriver driver);
}
}
......@@ -41,11 +41,9 @@ public interface ParameterObserver {
* @param previousReferenceDate previous date (null if it is the first time
* the reference date is changed)
* @param driver parameter driver that has been changed
* @exception OrekitException if date is invalid for the driven model
* @since 9.0
*/
default void referenceDateChanged(final AbsoluteDate previousReferenceDate, final ParameterDriver driver)
throws OrekitException {
default void referenceDateChanged(final AbsoluteDate previousReferenceDate, final ParameterDriver driver) {
// nothing by default
}
......@@ -55,11 +53,21 @@ public interface ParameterObserver {
* </p>
* @param previousName previous name
* @param driver parameter driver that has been changed
* @exception OrekitException if name is invalid for the driven model
* @since 9.0
*/
default void nameChanged(final String previousName, final ParameterDriver driver)
throws OrekitException {
default void nameChanged(final String previousName, final ParameterDriver driver) {
// nothing by default
}
/** Notify that a parameter selection status has been changed.
* <p>
* The default implementation does nothing
* </p>
* @param previousSelection previous selection
* @param driver parameter driver that has been changed
* @since 9.0
*/
default void selectionChanged(final boolean previousSelection, final ParameterDriver driver) {
// nothing by default
}
......
Supports Markdown
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