Commit b03432de authored by Nico Mack's avatar Nico Mack

Changes required by move of CPS related Externalization entries into

dedicated CpsNamespace package. 
Cleanup of system variable binding through VariableBased interface
Intitial commit of ItemFan corona and ListWidget
parent e7b303ef
ABOVE_ELEMENT=above
BELOW_ELEMENT=below
CAPPED_DISPLAY_NODE=cappedDisplay
ITEMS_VARIABLE_NODE=itemsVariable
LOWER_BOUND_VARIABLE_NODE=lowerBoundVariable
LOWER_STOP_ANGLE_NODE=lowerStopAngle
MAXIMUM_VALUE_NODE=maximumValue
MINIMUM_VALUE_NODE=minimumValue
MODIFY_VALUE_ON_ROTATION_NODE=modifyValueOnRotation
REFERENCE_NODE=reference
RELATIVE_NODE=relative
SELECTED_ITEMS_VARIABLE_NODE=selectedItemsVariable
SELECTED_RADIUS_NODE=selectedRadius
STEP_SIZE_NODE=stepSize
UPPER_BOUND_VARIABLE_NODE=upperBoundVariable
UPPER_STOP_ANGLE_NODE=upperStopAngle
VARIABLE_NODE=variable
VARIABLES_NODE=variables
\ No newline at end of file
......@@ -13,23 +13,24 @@
*/
package lu.list.itis.dkd.tui.bootstrapping;
import lu.list.itis.dkd.tui.cps.InputChangeListener;
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.exception.BuildException;
import lu.list.itis.dkd.tui.utility.ColorFactory;
import lu.list.itis.dkd.tui.utility.Templating;
import lu.list.itis.dkd.tui.widget.BaseWidget;
import lu.list.itis.dkd.tui.widget.DisplayWidget;
import org.jdom2.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Color;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.Map;
/**
* @author mack
......@@ -45,7 +46,7 @@ public class DisplayWidgetBootstrapper implements BootstrapCallback {
private List<Variable<?>> variables;
private Iterator<Variable<?>> variableIterator;
private Variable<?> variable;
private Vector<Color> variableColours;
private List<Color> variableColours;
private Integer index;
// ***************************************************************************
......@@ -73,11 +74,16 @@ public class DisplayWidgetBootstrapper implements BootstrapCallback {
public List<BaseWidget> buildWidgetsFromVariables(Element template, Integer widgetId, BootstrapContext context, BootstrapCallback callback) throws BuildException {
List<BaseWidget> widgets = null;
Map<String, Variable<?>> systemVariables = new HashMap<>();
index = 0;
context.setProperty(Templating.HANDLE_ID_PROPERTY, widgetId);
context.setProperty(Templating.NUMBER_OF_VARIABLES_PROPERTY, variables.size());
for (Variable<?> systemVariable : variables) {
systemVariables.put(systemVariable.getName(), systemVariable);
}
variableIterator = variables.iterator();
if (variableIterator.hasNext()) {
this.variable = variableIterator.next();
......@@ -85,12 +91,16 @@ public class DisplayWidgetBootstrapper implements BootstrapCallback {
widgets = TangibleObjectBootstrapper.buildWidgetFromTemplate(template, context, this);
for (BaseWidget widget : widgets) {
if (widget.getClass().isAssignableFrom(DisplayWidget.class)) {
DisplayWidget display = (DisplayWidget) widget;
display.setVariables(this.variables);
for (Variable<?> displayVariable : variables)
displayVariable.addListener(display);
List<Variable<?>> connected;
if (widget.getClass().isAssignableFrom(VariableBased.class)) {
VariableBased display = (VariableBased) widget;
connected = display.connectWithSystemVariables(systemVariables);
if (widget.getClass().isAssignableFrom(InputChangeListener.class)) {
InputChangeListener listener = (InputChangeListener) widget;
for (Variable<?> connectedVariable : connected)
connectedVariable.addListener(listener);
}
}
}
} else {
......
......@@ -18,6 +18,7 @@ import lu.list.itis.dkd.tui.cps.variable.BooleanVariable;
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.cps.variable.VectorVariable;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.Element;
......@@ -49,6 +50,13 @@ public class VariableBootstrapper {
numerical.setScale(scale);
variable = numerical;
break;
case EquationSystemBundle.VECTOR_TYPE:
unit = BootstrappingUtils.getContentAsString(variableNode, EquationSystemBundle.UNIT_ATTRIBUTE, BootstrappingUtils.OPTIONAL, EquationSystemBundle.EMPTY_STRING, context);
VectorVariable<?> vectorVariable = new VectorVariable<>(name, unit);
variable = vectorVariable;
break;
case EquationSystemBundle.LOGIC_TYPE:
boolean booleanValue = BootstrappingUtils.getContentAsBoolean(variableNode, EquationSystemBundle.INITIAL_ATTRIBUTE, BootstrappingUtils.OPTIONAL, false, context);
......
......@@ -15,6 +15,7 @@ package lu.list.itis.dkd.tui.cps.system;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import java.util.List;
import java.util.Map;
/**
......@@ -24,5 +25,5 @@ import java.util.Map;
*/
public interface VariableBased {
public void connectWithSystemVariables(Map<String, Variable<?>> systemVariables);
public List<Variable<?>> connectWithSystemVariables(Map<String, Variable<?>> systemVariables);
}
package lu.list.itis.dkd.tui.marker;
import lu.list.itis.dkd.tui.cps.InputChangeListener;
import lu.list.itis.dkd.tui.cps.InputEvent;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.marker.builder.BaseDisplayMarkerBuilder;
import lu.list.itis.dkd.tui.widget.corona.ValueCorona;
import org.python.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
@SuppressWarnings("rawtypes")
public class DisplayMarker extends InfoMarker implements InputChangeListener {
private HashMap<String, NumericalVariable> variables;
HashMap<String, ValueCorona> dispatcher;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static Logger LOGGER = LoggerFactory.getLogger(DisplayMarker.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public DisplayMarker(BaseDisplayMarkerBuilder<?> builder) {
super(builder);
if (builder.variables != null) {
this.setVariables(builder.variables);
}
this.dispatcher = new HashMap<String, ValueCorona>();
List<ValueCorona> displays = this.getCoronas(ValueCorona.class);
for (ValueCorona display : displays) {
Variable<?> variable = display.getVariable();
if (variable != null) {
dispatcher.put(variable.getName(), display);
}
}
// TODO Auto-generated constructor stub
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public void setVariables(Collection<Variable<?>> newVariables) {
Preconditions.checkArgument(variables == null, "Set of variables can't be null!"); //$NON-NLS-1$
this.variables = new HashMap<String, NumericalVariable>();
for (Variable<?> variable : newVariables) {
this.variables.put(variable.getName(), (NumericalVariable) variable);
}
List<ValueCorona> displays = this.getCoronas(ValueCorona.class);
for (ValueCorona display : displays) {
Variable<?> variable = display.getVariable();
if (variable != null) {
String variableName = variable.getName();
if (this.variables.containsKey(variableName)) {
display.setVariable(this.variables.get(variableName));
} else {
LOGGER.warn("Corona requires variable {} unkown to display widget!", variableName); //$NON-NLS-1$
}
}
}
}
// ---------------------------------------------------------------------------
public Collection<Variable<?>> getVariables() {
Collection<Variable<?>> variables = new ArrayList<>();
List<ValueCorona> displays = this.getCoronas(ValueCorona.class);
for (ValueCorona display : displays) {
Variable<?> variable = display.getVariable();
if (variable != null) {
variables.add(variable);
}
}
return variables;
}
// ---------------------------------------------------------------------------
@Override
public void paint(Graphics2D canvas) {
super.paint(canvas);
}
// ---------------------------------------------------------------------------
@Override
public void inputChanged(InputEvent input) {
String variableName = input.getSource().getName();
ValueCorona display = dispatcher.get(variableName);
NumericalVariable variable = display.getVariable();
if (variable != null) {
display.setInformation(variable.getValue());
} else {
LOGGER.warn("Corona requires variable {} unkown to display marker!", variableName); //$NON-NLS-1$
}
}
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import lu.list.itis.dkd.tui.content.InformationProvider;
import lu.list.itis.dkd.tui.content.InformationReceiver;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.marker.builder.BaseInfoMarkerBuilder;
import lu.list.itis.dkd.tui.marker.builder.InfoMarkerBuilder;
import lu.list.itis.dkd.tui.utility.Point;
//***************************************************************************
//* Class Definition and Members *
//***************************************************************************
public class InfoMarker<T> extends TetherableMarker implements InformationReceiver<T>, InformationProvider<T> {
private T information;
private Variable<T> variable;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// private static Logger LOGGER = LoggerFactory.getLogger(InfoMarker.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public InfoMarker(BaseInfoMarkerBuilder<InfoMarkerBuilder> builder) {
super(builder);
this.information = (T) builder.information;
this.variable = (Variable<T>) builder.variable;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public T getInformation(Point position) {
return this.getInformation();
}
// ---------------------------------------------------------------------------
@Override
public T getInformation() {
if (this.variable != null) {
return this.variable.getValue();
} else {
return this.information;
}
}
// ---------------------------------------------------------------------------
@Override
public void setInformation(T information) {
if (this.variable != null) {
this.variable.setValue(information);
} else {
this.information = information;
}
}
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker.builder;
import java.util.Collection;
import java.util.Vector;
import org.jdom2.Element;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.DisplayMarker;
//***************************************************************************
//* Class Definition and Members *
//***************************************************************************
public abstract class BaseDisplayMarkerBuilder<B extends BaseDisplayMarkerBuilder<B>> extends BaseInfoMarkerBuilder<B> {
public Collection<Variable<?>> variables;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
protected BaseDisplayMarkerBuilder() {}
// ---------------------------------------------------------------------------
protected BaseDisplayMarkerBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
public BaseDisplayMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public B withVariables(Collection<Variable<?>> variables) {
this.variables = new Vector<Variable<?>>();
this.variables.addAll(variables);
return (B) this;
}
// ---------------------------------------------------------------------------
@Override
public abstract DisplayMarker build();
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.bootstrapping.VariableBootstrapper;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.InfoMarker;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.utility.Externalization;
import org.jdom2.Element;
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class BaseInfoMarkerBuilder<B extends BaseInfoMarkerBuilder<B>> extends BaseTetherableMarkerBuilder<B> {
public Object information;
public Variable<?> variable;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
protected BaseInfoMarkerBuilder() {}
// ---------------------------------------------------------------------------
protected BaseInfoMarkerBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
protected BaseInfoMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
protected void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super.buildFromBootstrap(rootElement, context, callback);
Element informationElement = rootElement.getChild(Externalization.INFORMATION);
if (informationElement != null) {
Element variableElement = informationElement.getChild(CpsNamespace.VARIABLE_NODE);
if (variableElement != null) {
variable = VariableBootstrapper.buildVariableFromElement(variableElement, context, callback);
}
} else {
this.information = BootstrappingUtils.getContentAsString(informationElement, null, BootstrappingUtils.OPTIONAL, null, context);
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public abstract InfoMarker<?> build();
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker.builder;
import org.jdom2.Element;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.DisplayMarker;
public class DisplayMarkerBuilder extends BaseDisplayMarkerBuilder<DisplayMarkerBuilder> {
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
public DisplayMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public DisplayMarker build() {
return new DisplayMarker(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker.builder;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.InfoMarker;
import org.jdom2.Element;
public class InfoMarkerBuilder extends BaseInfoMarkerBuilder<InfoMarkerBuilder> {
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
public InfoMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public InfoMarker<?> build() {
return new InfoMarker(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.utility;
import org.eclipse.osgi.util.NLS;
/**
* Auto-generated class for string externalization to be used to bundle all node names.
*