...
 
Commits (156)
*.metadata
*.classpath
CPS/target
\ No newline at end of file
CPS/target
/.DS_Store
......@@ -5,11 +5,21 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.fusesource.ide.project.RiderProjectBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
......@@ -17,7 +27,9 @@
</buildCommand>
</buildSpec>
<natures>
<nature>org.fusesource.ide.project.RiderProjectNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}/python</path>
</pydev_pathproperty>
</pydev_project>
......@@ -15,9 +15,11 @@ org.eclipse.jdt.core.compiler.annotation.nonnull=lu.tudor.ssi.kiss.dbc.annotatio
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nullable=lu.tudor.ssi.kiss.dbc.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
......@@ -26,6 +28,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
......
ABOVE_ELEMENT=above
BACKGROUND_NODE=background
BELOW_ELEMENT=below
BLINK_ON_OUT_OF_RANGE_NODE=blinkOnOutOfRange
CAPPED_DISPLAY_NODE=cappedDisplay
COLOUR_SCALE_NODE=colourScale
DECIMALS_ATTRIBUTE=decimals
FACE_IS_TOUCHABLE_NODE=faceIsTouchable
FOREGROUND_NODE=foreground
ITEMS_VARIABLE_NODE=itemsVariable
HTML_TEMPLATE_NODE=htmlTemplate
LABEL_NODE=label
LABEL_ANGLE_NODE=labelAngle
LABEL_TRANSLATION_NODE=labelTranslation
LANDING_LINE_LENGTH_NODE=landingLineLength
LEADER_COLOUR_NODE=leaderColour
LEADER_LINE_LENGTH_NODE=leaderLineLength
LEADER_STROKE_WIDTH_NODE=leaderStrokeWidth
LOWER_BOUND_RADIUS_NODE=lowerBoundRadius
LOWER_BOUND_VARIABLE_NODE=lowerBoundVariable
LOWER_STOP_ANGLE_NODE=lowerStopAngle
MAPPING_NODE=mapping
MAPPINGS_NODE=mappings
MAINTAIN_ASPECT_RATIO_NODE=maintainAspectRatio
MAXIMUM_VALUE_NODE=maximumValue
MINIMUM_VALUE_NODE=minimumValue
MODIFY_VALUE_ON_ROTATION_NODE=modifyValueOnRotation
MODIFY_VALUE_ON_TRANSLATION_NODE=modifyValueOnTranslation
MULTITURN_NODE=multiTurn
POSITIONS_NODE=positions
RANGE_SEPARATOR_ATTRIBUTE=rangeSeparator
REFERENCE_NODE=reference
RELATIVE_NODE=relative
ROTATION_NODE=rotation
SCALES_NODE=scales
SELECTED_ITEMS_VARIABLE_NODE=selectedItemsVariable
SELECTED_RADIUS_NODE=selectedRadius
STEP_SIZE_NODE=stepSize
STRETCH_TO_FIT_NODE=stretchToFit
TRACK_ROTATION_CONTINUOUSLY_NODE=trackRotationContinuously
TRACK_TRANSLATION_CONTINUOUSLY_NODE=trackTranslationContinuously
TRANSLATION_NODE=translation
UPPER_BOUND_RADIUS_NODE=upperBoundRadius
UPPER_BOUND_VARIABLE_NODE=upperBoundVariable
UPPER_STOP_ANGLE_NODE=upperStopAngle
VARIABLE_NODE=variable
VARIABLES_NODE=variables
VERBOSE_NODE=verbose
\ No newline at end of file
ON_POSITION_CHANGED=positionChanged
\ No newline at end of file
CONNECTOR_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.cps.system.connector.builder
CONNECTOR_BUILDER_POSTFIX=Connector
URL_ELEMENT=url
DRIVER_CLASS_ELEMENT=driverClass
USER_NAME_ELEMENT=username
PASSWORD_ELEMENT=password
AUTO_COMMIT_ELEMENT=autoCommit
EXECUTOR_CLASS=executor.class
NUMERIC_VARIABLE_CLASS=numeric.variable.class
LOGIC_VARIABLE_CLASS=logic.variable.class
TEXT_VARIABLE_CLASS=text.variable.class
SPATIAL_VARIABLE_CLASS=spatial.variable.class
VECTOR_VARIABLE_CLASS=vector.variable.class
MAP_VARIABLE_CLASS=map.variable.class
EXECUTOR_NAMESPACE=lu.list.itis.dkd.tui.cps.system.executor
NAMESPACE_SEPARATOR=.
EXECUTOR_POSTFIX=Executor
CONNECTORS_ELEMENT=connectors
CONNECTOR_ELEMENT=connector
EQUATIONS_ELEMENT=equations
EQUATION_ELEMENT=equation
MODE_ATTRIBUTE=mode
INVOKE_ELEMENT=invoke
INDEX_ATTRIBUTE=index
FORMAT_ATTRIBUTE=format
FIELD_ATTRIBUTE=field
KEY_ATTRIBUTE=key
VALUE_ATTRIBUTE=value
INVOKE_ELEMENT=invoke
INVOKING_ATTRIBUTE=invoking
EPSILON_ATTRIBUTE=epsilon
EXECUTOR_ATTRIBUTE=executor
NAME_ATTRIBUTE=name
OUTPUTS_ELEMENT=outputs
OUTPUT_ELEMENT=output
PARAMETER_ELEMENT=parameter
DISPLAY_NAME_ATTRIBUTE=displayName
TYPE_ATTRIBUTE=type
INITIAL_ATTRIBUTE=initial
MINIMUM_ATTRIBUTE=minimum
......@@ -17,6 +38,7 @@ SCALE_ATTRIBUTE=scale
DECIMALS_ATTRIBUTE=decimals
PARAMETERS_ELEMENT=parameters
PERIODIC_ATTRIBUTE=periodic
PRIORITY_ATTRIBUTE=priority
RESULT_ELEMENT=result
EQUATE_ATTRIBUTE=equate
RESULTS_ELEMENT=results
......@@ -25,4 +47,5 @@ IMPORT_ELEMENT=import
FUNCTION_ATTRIBUTE=function
FROM_ATTRIBUTE=from
SYSTEM_ELEMENT=system
UNIT_ATTRIBUTE=unit
\ No newline at end of file
UNIT_ATTRIBUTE=unit
TYPE_NODE=type
\ No newline at end of file
......@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip-cps</artifactId>
<version>1.4.0</version>
<version>1.6.0</version>
<name>TULIP Complex Problem Solving</name>
<licenses>
......@@ -21,6 +21,11 @@
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>config</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
......@@ -30,6 +35,73 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
<timestampPropertyName>build.date</timestampPropertyName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<implementation-version>${project.version}</implementation-version>
<implementation-build>${buildNumber}</implementation-build>
<build-date>${build.date}</build-date>
</manifestEntries>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>lu.list.itis.dkd.tui.TulipCps</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
......@@ -39,15 +111,11 @@
<artifactId>dbc-annotation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip</artifactId>
<version>2.4.0</version>
<version>2.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>maven2.dk.ange</groupId>
......@@ -67,29 +135,89 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8</version>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8</version>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>com.github.lucarosellini.rJava</groupId>
<artifactId>JRI</artifactId>
<version>0.9-7</version>
</dependency>
<dependency>
<groupId>com.github.lucarosellini.rJava</groupId>
<artifactId>REngine</artifactId>
<version>0.9-7</version>
</dependency>
<dependency>
<groupId>com.github.lucarosellini.rJava</groupId>
<artifactId>JRIEngine</artifactId>
<version>0.9-7</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>Kenai</id>
<name>Kenai</name>
<url>https://svn.kenai.com/svn/javaoctave~maven-repository</url>
</repository>
</repositories>
<repository>
<id>LIST</id>
<name>Artifacts</name>
<url>https://artefacts.list.lu/libs-release-local</url>
</repository>
</repositories>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.9</version>
<reportSets>
<reportSet>
<reports>
<report>dependencies</report>
<report>license</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
<scm>
<url>scm:git:https://git.list.lu/nui/TULIP-CPS.git</url>
<connection>scm:git:https://git.list.lu/nui/TULIP-CPS.git</connection>
</scm>
</project>
\ No newline at end of file
/Spatial$py.class
/Text$py.class
/Map$py.class
/Vector$py.class
'''
Created on Jan 5, 2018
@author: mack
'''
def ManipulateMap (M):
A = M
A["intField"]+=10
A["doubleField"]*=2
A["booleanField"] = not A["booleanField"]
A["stringField"] += " had a very big fall"
A["listField"].append(17)
A["listField"].append(19)
A["listField"].append(23)
'''print A["intField"]
print A["doubleField"]
print A["booleanField"]
print A["stringField"]
print A["listField"]'''
return A
'''
Created on Aug 16, 2017
@author: mack
'''
def AddPoints (A, B):
C = {}
C['x'] = A['x'] + B['x']
C['y'] = A['y'] + B['y']
C['a'] = A['a'] + B['a']
return C
\ No newline at end of file
'''
Created on Jan 2, 2018
@author: mack
'''
def ConcatText (A, B):
C = A + B
return C
\ No newline at end of file
'''
Created on Jan 8, 2018
@author: mack
'''
def ManipulateVector (V):
R = V
R[3] = 2
return R
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2018.
* 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;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public class TulipCps extends TulipCore {
}
/**
* 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.bootstrapping;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Templating;
import lu.list.itis.dkd.tui.widget.BaseWidget;
import com.google.common.base.Strings;
import com.jgoodies.common.base.Preconditions;
import org.jdom2.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 1.5
* @version 1.5.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class BundleBasedCallback implements BootstrapCallback {
private Integer widgetId;
private boolean repeating;
private Map<String, BootstrapCallback> bundleCallbacks;
private BootstrapCallback callback;
private BootstrapCallback defaultCallback;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(BundleBasedCallback.class.getName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public BundleBasedCallback(Integer widgetId, Map<String, BootstrapCallback> callbacks) throws BuildException {
this.widgetId = widgetId;
this.bundleCallbacks = new ConcurrentHashMap<>();
this.bundleCallbacks.putAll(callbacks);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public List<BaseWidget> buildWidgets(Element template, BootstrapContext context) throws BuildException {
Preconditions.checkArgument(context != null, "Context MUST not be null!"); //$NON-NLS-1$
assert context != null;
List<BaseWidget> widgets = null;
context.setProperty(Templating.HANDLE_ID_PROPERTY, widgetId);
for (Entry<String, BootstrapCallback> callbackEntry : this.bundleCallbacks.entrySet()) {
context.setProperty(callbackEntry.getKey(), callbackEntry.getValue());
}
widgets = TangibleObjectBootstrapper.buildWidgetFromTemplate(template, context, this);
return widgets;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext initialize(Element node, BootstrapContext context) {
try {
this.callback = null;
repeating = BootstrappingUtils.getAttributeAsBoolean(node, Externalization.REPEAT_ATTRIBUTE, BootstrappingUtils.OPTIONAL, false);
String callbackAttribute = BootstrappingUtils.getAttributeAsString(node, Externalization.CALLBACK_ATTRIBUTE, BootstrappingUtils.OPTIONAL, null);
if (repeating) {
if (!Strings.isNullOrEmpty(callbackAttribute)) {
if (context.hasProperty(callbackAttribute)) {
this.callback = (BootstrapCallback) context.getProperty(callbackAttribute);
} else {
LOGGER.error("Required callback {} was not found in available callbacks!", callbackAttribute); //$NON-NLS-1$
}
}
}
} catch (BuildException exception) {
LOGGER.error("An error occured while trying to retrieve {} attribute!", Externalization.CALLBACK_ATTRIBUTE, exception); //$NON-NLS-1$
}
if (this.callback != null) {
context = this.callback.initialize(node, context);
}
return context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext preInstantiation(Element node, BootstrapContext context) {
return (this.callback != null) ? this.callback.preInstantiation(node, context) : context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext postInstantiation(Element node, BootstrapContext context) {
return (this.callback != null) ? this.callback.postInstantiation(node, context) : context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext next(BootstrapContext context) {
return (this.callback != null) ? this.callback.next(context) : context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext reset(BootstrapContext context) {
return (this.callback != null) ? this.callback.reset(context) : context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public BootstrapContext finalize(BootstrapContext context) {
if (this.callback != null) {
context = this.callback.finalize(context);
this.callback = null;
}
return context;
}
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.bootstrapping;
import lu.list.itis.dkd.tui.cps.system.connector.Connector;
import lu.list.itis.dkd.tui.cps.system.connector.builder.BaseConnectorBuilder;
import lu.list.itis.dkd.tui.cps.system.connector.utility.ConnectorBundle;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import org.eclipse.swt.internal.C;
import org.jdom2.Element;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.2
* @version 2.3.0
*/
public class CpsConnectorBootstrapper {
/**
* Method used to determine the appropriate builder for a given object and then issue a build call.
*
* @param bootstrapContext
* @param callback
*
* @param connectorNode
* The node from a larger document that contains, as children, all the necessary information
* to resolve the correct builder and build the final tether.
* @return The final tether as defined by the children of the element node.
* @throws ClassNotFoundException
* Thrown when the class of the builder for the widget or those of the nested corona
* builder(s) could not be found.
* @throws SecurityException
* Thrown when the constructor cannot be retrieved due to some security constraints.
* @throws NoSuchMethodException
* Thrown when no constructor with the given parameter type is available.
* @throws InvocationTargetException
* Thrown if the invocation of any constructor through reflection throws an exception.
* @throws IllegalArgumentException
* Thrown when the provided argument is not eligible for the builder's constructor.
* @throws IllegalAccessException
* Thrown if this Constructor object is enforcing Java language access control and the
* underlying constructor is inaccessible.
* @throws InstantiationException
* Thrown if the class that declares the underlying constructor represents an abstract
* class.
* @throws BuildException
*/
@SuppressWarnings("unchecked")
public static Connector<C> buildConnectorFromElement(Element connectorNode, BootstrapContext bootstrapContext, BootstrapCallback callback) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, BuildException {
Connector<C> instance = null;
Element type = connectorNode.getChild(Externalization.TYPE_NODE);
Class<?> builder = Class.forName(ConnectorBundle.CONNECTOR_BUILDER_NAMESPACE + Externalization.NAMESPACE_SEPARATOR + type.getValue() + ConnectorBundle.CONNECTOR_BUILDER_POSTFIX + Externalization.BUILDER_CLASS_POSTFIX);
if ((bootstrapContext == null) || (bootstrapContext.size() == 0)) {
Constructor<BaseConnectorBuilder<?>> constructor = (Constructor<BaseConnectorBuilder<?>>) builder.getConstructor(new Class[] {Element.class});
instance = constructor.newInstance(new Object[] {connectorNode}).build();
} else {
Constructor<BaseConnectorBuilder<?>> constructor = (Constructor<BaseConnectorBuilder<?>>) builder.getConstructor(new Class[] {Element.class, BootstrapContext.class, BootstrapCallback.class});
instance = constructor.newInstance(new Object[] {connectorNode, bootstrapContext, callback}).build();
}
return instance;
}
}
\ No newline at end of file
/**
* 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.bootstrapping;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Templating;
import lu.list.itis.dkd.tui.widget.BaseWidget;
import com.jgoodies.common.base.Preconditions;
import org.jdom2.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 1.5
* @version 1.5.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class StackedCallback implements BootstrapCallback {
private Integer widgetId;
private boolean repeating;
private List<BootstrapCallback> stackedCallbacks;
private Iterator<BootstrapCallback> callbackIterator;
private BootstrapCallback callback;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(StackedCallback.class.getName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public StackedCallback(Integer widgetId, List<BootstrapCallback> callbacks) throws BuildException {
this.widgetId = widgetId;
this.stackedCallbacks = new ArrayList<>();
this.stackedCallbacks.addAll(callbacks);
this.callbackIterator = this.stackedCallbacks.iterator();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public List<BaseWidget> buildWidgets(Element template, BootstrapContext context) throws BuildException {
Preconditions.checkArgument(context != null, "Context MUST not be null!"); //$NON-NLS-1$
assert context != null;
List<BaseWidget> widgets = null;
context.setProperty(Templating.HANDLE_ID_PROPERTY, widgetId);
widgets = TangibleObjectBootstrapper.buildWidgetFromTemplate(template, context, this);
return widgets;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext initialize(Element node, BootstrapContext context) {
try {
this.callback = null;
repeating = BootstrappingUtils.getAttributeAsBoolean(node, Externalization.REPEAT_ATTRIBUTE, BootstrappingUtils.OPTIONAL, false);
if (repeating) {
if (this.callbackIterator.hasNext()) {
this.callback = this.callbackIterator.next();
} else {
LOGGER.error("Ran out of callbacks!"); //$NON-NLS-1$
}
}
} catch (BuildException exception) {
LOGGER.error("An error occured while trying to retrieve {} attribute!", Externalization.CALLBACK_ATTRIBUTE, exception); //$NON-NLS-1$
}
if (this.callback != null) {
context = this.callback.initialize(node, context);
}
return context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext preInstantiation(Element node, BootstrapContext context) {
return (this.callback != null) ? this.callback.preInstantiation(node, context) : context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext postInstantiation(Element node, BootstrapContext context) {
return (this.callback != null) ? this.callback.postInstantiation(node, context) : context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext next(BootstrapContext context) {
return (this.callback != null) ? this.callback.next(context) : context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public BootstrapContext reset(BootstrapContext context) {
return (this.callback != null) ? this.callback.reset(context) : context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public BootstrapContext finalize(BootstrapContext context) {
if (this.callback != null) {
context = this.callback.finalize(context);
this.callback = null;
}
return context;
}
}
/**
* 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.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 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.Map;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class VariableBasedCallback implements BootstrapCallback {
private List<Variable<?>> variables;
private Iterator<Variable<?>> variableIterator;
private Variable<?> variable;
private List<Color> variableColours;
private Integer index;
private Integer widgetId;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(VariableBasedCallback.class.getName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public VariableBasedCallback(Integer widgetId, List<Variable<?>> variables) {
this.widgetId = widgetId;
this.variables = variables;
this.variableColours = ColorFactory.makeRainbowColours(variables.size());
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public List<BaseWidget> buildWidgets(Element template, BootstrapContext context, BootstrapCallback callback) throws BuildException {
List<BaseWidget> widgets = null;
Map<String, Variable<?>> systemVariables = new HashMap<>();
this.initialize(null, context);
for (Variable<?> systemVariable : variables) {
systemVariables.put(systemVariable.getName(), systemVariable);
}
widgets = TangibleObjectBootstrapper.buildWidgetFromTemplate(template, context, this);
for (BaseWidget widget : widgets) {
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);
}
}
}
return widgets;
}
// ---------------------------------------------------------------------------
@Override
public BootstrapContext initialize(Element node, BootstrapContext context) {
index = 0;
context.setProperty(Templating.HANDLE_ID_PROPERTY, widgetId);
context.setProperty(Templating.NUMBER_OF_VARIABLES_PROPERTY, variables.size());
variableIterator = variables.iterator();
if (variableIterator.hasNext()) {
this.variable = variableIterator.next();
} else {
LOGGER.warn("Encountered a Widget without any variables. Won't build Widget! ID of offending Widget is {}", widgetId); //$NON-NLS-1$
}
return context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public BootstrapContext preInstantiation(Element node, BootstrapContext context) {
context.setProperty(Templating.VARIABLE_NAME_PROPERTY, variable.getName());
context.setProperty(Templating.VARIABLE_DISPLAY_NAME_PROPERTY, variable.getDisplayName());
context.setProperty(Templating.VARIABLE_UNIT_PROPERTY, variable.getUnit());
context.setProperty(Templating.VARIABLE_VALUE_PROPERTY, variable.getValue());
if (variable instanceof NumericalVariable) {
NumericalVariable numerical = (NumericalVariable) variable;
context.setProperty(Templating.VARIABLE_MINVALUE_PROPERTY, numerical.getMinValue());
context.setProperty(Templating.VARIABLE_MAXVALUE_PROPERTY, numerical.getMaxValue());
context.setProperty(Templating.VARIABLE_SCALE_PROPERTY, numerical.getScale());
}
Color colour = variableColours.get(index);
context.setProperty(Templating.VARIABLE_COLOUR_PROPERTY, colour.getRGB());
return context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public BootstrapContext postInstantiation(Element node, BootstrapContext context) {
return context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public BootstrapContext next(BootstrapContext context) {
if (variableIterator.hasNext()) {
this.variable = variableIterator.next();
this.index++;
}
return context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public BootstrapContext reset(BootstrapContext context) {
this.index = 0;
variableIterator = variables.iterator();
if (variableIterator.hasNext()) {
this.variable = variableIterator.next();
}
return context;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public BootstrapContext finalize(BootstrapContext context) {
return reset(context);
}
}
/**
* 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.bootstrapping;
import lu.list.itis.dkd.tui.cps.utility.EquationSystemBundle;
import lu.list.itis.dkd.tui.cps.variable.BooleanVariable;
import lu.list.itis.dkd.tui.cps.variable.MapVariable;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.SpatialVariable;
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 lu.list.itis.dkd.tui.utility.CoordinateState;
import lu.list.itis.dkd.tui.utility.Point;
import org.jdom2.Element;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public class VariableBootstrapper {
public static Variable<?> buildVariableFromElement(Element variableNode, BootstrapContext context, BootstrapCallback callback) throws BuildException {
Variable<?> variable = null;
if (variableNode == null)
return null;
String name = BootstrappingUtils.getContentAsString(variableNode, EquationSystemBundle.NAME_ATTRIBUTE, BootstrappingUtils.MANDATORY, null, context);
String type = BootstrappingUtils.getContentAsString(variableNode, EquationSystemBundle.TYPE_NODE, BootstrappingUtils.MANDATORY, null, context);
switch (type) {
case EquationSystemBundle.NUMERIC_TYPE:
String unit = BootstrappingUtils.getContentAsString(variableNode, EquationSystemBundle.UNIT_ATTRIBUTE, BootstrappingUtils.OPTIONAL, EquationSystemBundle.EMPTY_STRING, context);
double minValue = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.MINIMUM_ATTRIBUTE, BootstrappingUtils.OPTIONAL, -Double.MAX_VALUE, context);
double maxValue = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.MAXIMUM_ATTRIBUTE, BootstrappingUtils.OPTIONAL, Double.MAX_VALUE, context);
double initialValue = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.INITIAL_ATTRIBUTE, BootstrappingUtils.OPTIONAL, Double.NaN, context);
double scale = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.SCALE_ATTRIBUTE, BootstrappingUtils.OPTIONAL, 1.0, context);
double numericValue = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.INITIAL_ATTRIBUTE, BootstrappingUtils.OPTIONAL, 0.0, context);
int decimals = BootstrappingUtils.getContentAsInteger(variableNode, EquationSystemBundle.DECIMALS_ATTRIBUTE, BootstrappingUtils.OPTIONAL, -1, context);
NumericalVariable numerical = new NumericalVariable(name, unit, numericValue);
numerical.setMinValue(minValue);
numerical.setMaxValue(maxValue);
numerical.setInitialValue(initialValue);
numerical.setScale(scale);
if (decimals >= 0) {
numerical.setNumberOfDecimals(decimals);
}
variable = numerical;
break;
case EquationSystemBundle.MAP_TYPE:
MapVariable<?, ?> mapVariable = new MapVariable<>(name);
variable = mapVariable;
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);
BooleanVariable booleanVariable = new BooleanVariable(name, booleanValue);
variable = booleanVariable;
break;
case EquationSystemBundle.TEXT_TYPE:
String textValue = BootstrappingUtils.getContentAsString(variableNode, EquationSystemBundle.INITIAL_ATTRIBUTE, BootstrappingUtils.OPTIONAL, EquationSystemBundle.EMPTY_STRING, context);
TextVariable textVariable = new TextVariable(name, textValue);
variable = textVariable;
break;
case EquationSystemBundle.SPATIAL_TYPE:
SpatialVariable spatialVariable = new SpatialVariable(name);
Point initialPosition;
Element initialNode = variableNode.getChild(EquationSystemBundle.INITIAL_ATTRIBUTE);
if (initialNode != null) {
initialPosition = new Point(initialNode, context, callback);
} else {
CoordinateState state = CoordinateStateBootstrapper.getCoordinateState(variableNode, new Point(), context, callback);
initialPosition = new Point(state.getClass());
}
spatialVariable.setValue(initialPosition);
variable = spatialVariable;
break;
default:
throw new BuildException("Don't know how to build a Variable of type " + type); //$NON-NLS-1$
}
return variable;
}
}
/**
* 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.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.Variable;
import lu.list.itis.dkd.tui.cps.variable.VectorVariable;
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 org.jdom2.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Color;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 1.5
* @version 1.5.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class VectorBasedCallback implements BootstrapCallback {
private Integer widgetId;
private List<VectorVariable<?>> variables;
private List<Color> indexColours;
private Integer index;
private Integer size;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(VectorBasedCallback.class.getName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public VectorBasedCallback(Integer widgetId, List<VectorVariable<?>> variables) {
size = -1;
this.widgetId = widgetId;
this.variables = variables;
for (VectorVariable<?> variable : variables) {
if (size < 0)
size = variable.size();
if (variable.size() != size) {
LOGGER.error("Size of vector {} is {} and differs from size of other vectors which is {}!", variable.getName(), variable.size(), size); //$NON-NLS-1$
}
}
this.indexColours = ColorFactory.makeRainbowColours(size);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public List<BaseWidget> buildWidgets(Element template, 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.SIZE_OF_VECTORS_PROPERTY, size);
*/
this.initialize(null, context);
for (Variable<?> systemVariable : variables) {
systemVariables.put(systemVariable.getName(), systemVariable);
}
if (size > 0) {
widgets