Commit 61908342 authored by Nico Mack's avatar Nico Mack

Changes entailed by changes to Scriptable interface

parent bbf22f38
......@@ -172,8 +172,8 @@ public abstract class Variable<V> implements Cloneable {
/**
* Simple getter method for the value held by the {@link Variable} instance. Reading the value will
* reset the modified flag.
* Simple getter method for the value held by the {@link Variable} instance. Reading the value
* will reset the modified flag.
*
* @return The value held by the {@link Variable} instance.
*/
......@@ -185,7 +185,8 @@ public abstract class Variable<V> implements Cloneable {
/**
* checks whether this variable was modified since it was read for the last time. *
*
* @return <code>true</code> if variable was modified since last read, <code>false</code> otherwise.
* @return <code>true</code> if variable was modified since last read, <code>false</code>
* otherwise.
*/
public boolean wasModified(boolean reset) {
......@@ -348,8 +349,8 @@ public abstract class Variable<V> implements Cloneable {
/**
* Method invoked to add a {@link InputChangeListener} to the {@link Vector} of listeners to notify
* on tick.
* Method invoked to add a {@link InputChangeListener} to the {@link Vector} of listeners to
* notify on tick.
*
* @param listener
* The {@link InputChangeListener} to add.
......@@ -367,12 +368,12 @@ public abstract class Variable<V> implements Cloneable {
}
/**
* Sets the suspendNotification flag for InputChangeListeners. When suspend, InputChangeListeners
* will not be notified on value changes.
* Sets the suspendNotification flag for InputChangeListeners. When suspend,
* InputChangeListeners will not be notified on value changes.
*
* @param suspend
* specify <code>true</true> to suspend listener notification, <code>false</code> to enable
* notification of InputChangeListerners on value change.
* specify <code>true</true> to suspend listener notification, <code>false</code> to
* enable notification of InputChangeListerners on value change.
* @see #consolidateListeners
*/
public synchronized void suspendListenerNotification(boolean suspend) {
......@@ -392,12 +393,12 @@ public abstract class Variable<V> implements Cloneable {
}
/**
* Causes this variable to add its InputChangeListeners to the specified HashMap. HashMap ensures
* that no duplicate listeners will be added to consolidated list.
* Causes this variable to add its InputChangeListeners to the specified HashMap. HashMap
* ensures that no duplicate listeners will be added to consolidated list.
*
* @param consolidated
* specifies the HashMap to add this variables' listeners to. Note that key-value pair with
* identical listener key will be replaced by entry inserted by this call.
* specifies the HashMap to add this variables' listeners to. Note that key-value pair
* with identical listener key will be replaced by entry inserted by this call.
* @return specified HashMap enriched by this variables' listeners.
*/
......@@ -412,8 +413,8 @@ public abstract class Variable<V> implements Cloneable {
}
/**
* Invokes inputChanged method of each registered InputChangeListener unless consolidated flag is
* raised
* Invokes inputChanged method of each registered InputChangeListener unless consolidated flag
* is raised
*
* @param event
* specifies the event to be passed to each listeners inputChanged method.
......@@ -448,6 +449,19 @@ public abstract class Variable<V> implements Cloneable {
}
@SuppressWarnings("unchecked")
public static <V, T> T castValueTo(V value, Class<T> clazz) {
T casted = null;
if (value.getClass().isAssignableFrom(clazz)) {
casted = (T) value;
} else {
LOGGER.error("Value of type {} could not be cast to {}!", value.getClass().getSimpleName(), clazz.getName()); //$NON-NLS-1$
}
return casted;
}
/** {@inheritDoc} */
@Override
public abstract Variable<V> clone();
......
......@@ -25,8 +25,6 @@ import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.TextVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.event.conditional.ScriptableCondition;
import lu.list.itis.dkd.tui.feature.scripting.Script;
import lu.list.itis.dkd.tui.feature.scripting.Scriptable;
import lu.list.itis.dkd.tui.feature.scripting.builder.BaseVariableScriptBuilder;
import org.slf4j.Logger;
......@@ -117,7 +115,8 @@ public class VariableScript extends Script implements VariableBased, InputChange
// ---------------------------------------------------------------------------
private Variable<?> instantiateVariableForField(Field field) {
private Variable<?> instantiateVariableForField(ScriptableProperty property) {
Field field = property.getField();
Class<?> variableClass = FIELD_VARIABLE_LOOKUP.get(field.getType());
Variable<?> variable = null;
......
......@@ -6,8 +6,6 @@ import lu.list.itis.dkd.tui.cps.InputEvent;
import lu.list.itis.dkd.tui.cps.system.VariableBased;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.feature.scripting.Script;
import lu.list.itis.dkd.tui.feature.scripting.VariableScript;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseValueCoronaBuilder;
import org.python.google.common.base.Preconditions;
......@@ -126,14 +124,19 @@ public class ValueCorona extends SelectableCorona implements InformationReceiver
connected.addAll(handler.connectWithSystemVariables(systemVariables));
}
if ((this.scripts != null) && !this.scripts.isEmpty()) {
for (Script script : this.scripts) {
if (script instanceof VariableScript) {
connected.addAll(((VariableScript) script).connectWithSystemVariables(systemVariables));
}
}
List<VariableBased> variableScripts = this.getScripts(VariableBased.class);
for (VariableBased script : variableScripts) {
connected.addAll(script.connectWithSystemVariables(systemVariables));
}
// if ((this.scripts != null) && !this.scripts.isEmpty()) {
// for (Script script : this.scripts) {
// if (script instanceof VariableScript) {
// connected.addAll(((VariableScript) script).connectWithSystemVariables(systemVariables));
// }
// }
// }
return connected;
}
......
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