Commit 31aedc36 authored by Jay Jay Billings's avatar Jay Jay Billings
Browse files

Added initial prototype files.


Signed-off-by: default avatarJay Jay Billings <billingsjj@ornl.gov>
parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gov.ornl.rse.renderer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gov.ornl.rse.renderer</groupId>
<artifactId>gov.ornl.rse.renderer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Renderer Prototype</name>
<description>This is a prototype rendering utility for Eclipse ICE 3.0 and other projects.</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package gov.ornl.rse.renderer;
import com.google.inject.AbstractModule;
public class BasicModule extends AbstractModule {
@Override
protected void configure() {
bind(RendererRunner.class).toInstance(new RendererRunner());;
}
}
/**
*
*/
package gov.ornl.rse.renderer;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* @author Jay Jay Billings
*
*/
public class DataElement<T> {
T data;
private String description;
private String name;
public T getData() {
return data;
}
public void setData(final T value) {
data = value;
}
@Override
public String toString() {
String value = null;
// Convert to json using Jackson
ObjectMapper mapper = new ObjectMapper();
try {
value = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return value;
// .convertValue(this, new TypeReference<Map<String, Object>>() {
// }).toString();
}
public void fromString(final String value) {
// The question here is can we load the data value from json?
// 1.) Jackson needs to know the class type of "data", but otherwise it can load everything else fine.
// 2.) Probably need to do a two step process:
// a.) Pull DataElement properties from json and set directly - strings are strings after all
// b.) Use Jackson ObjectMapper.convertValue() to convert data member of type T from json - How to get .class?
ObjectMapper mapper = new ObjectMapper();
try {
System.out.println("value = " + value);
JsonNode rootNode = mapper.readTree(value);
System.out.println(rootNode);
System.out.println("data = " + rootNode.get("data"));
JsonNode dataNode = rootNode.get("data");
data = (T) mapper.treeToValue(dataNode, data.getClass());
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Validator getValidator() {
return null;
}
public void setValidator(Validator validator) {
}
public String getDescription() {
return description;
}
public void setDescription(final String desc) {
description = desc;
}
public String getName() {
return name;
}
public void setName(final String elemName) {
name = elemName;
}
}
/**
*
*/
package gov.ornl.rse.renderer;
/**
* @author Jay Jay Billings
*
*/
public class DataFile extends DataElement<String> {
}
package gov.ornl.rse.renderer;
public class HTMLView {
public HTMLView() {
}
public void draw(DataElement data) {
String content = "<html><head><title>Hello World!</title></head><body>Hello World! " +
data.toString() + "</body></html>";
System.out.println(content);
return;
}
}
package gov.ornl.rse.renderer;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class Launcher {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new BasicModule());
RendererRunner runner = injector.getInstance(RendererRunner.class);
runner.run();
}
}
/**
*
*/
package gov.ornl.rse.renderer;
/**
* @author Jay Jay Billings
*
*/
public class Offset {
private boolean inUse;
private double offsetValue;
public Offset() {}
public double getValue() {
return offsetValue;
}
public void setValue(double value) {
offsetValue = value;
}
public boolean getUsed() {
return inUse;
}
public void setUsed(boolean value) {
inUse = value;
}
@Override
public String toString() {
return inUse + ", " + offsetValue;
}
}
/**
*
*/
package gov.ornl.rse.renderer;
import java.util.function.BiConsumer;
import javax.inject.Inject;
/**
* @author Jay Jay Billings
*
*/
public class Renderer<T, V> {
@Inject
private T viewer;
@Inject
private DataElement<V> dataElement;
private BiConsumer<T, DataElement<V>> drawMethod;
public void setViewer(T view) {
viewer = view;
}
public void setDataElement(DataElement<V> data) {
dataElement = data;
}
public void setDrawMethod(BiConsumer<T,DataElement<V>> drawFunction) {
drawMethod = drawFunction;
}
public void render() {
drawMethod.accept(viewer,dataElement);
}
}
/**
*
*/
package gov.ornl.rse.renderer;
import java.util.ArrayList;
import java.util.function.BiConsumer;
import javax.inject.Inject;
/**
* @author Jay Jay Billings
*
*/
public class RendererRunner {
@Inject
DataElement<Boolean> data;
@Inject
DataElement<String> dataString;
@Inject
DataElement<Offset> sampleOffset;
@Inject
Renderer<HTMLView, Boolean> renderer;
@Inject
Renderer<HTMLView, String> stringRenderer;
@Inject
Renderer<HTMLView, Offset> osRenderer;
/**
* @param args
*/
public void run() {
// Configure a basic data element with a boolean value
data.setName("Injected.");
data.setData(true);
System.out.println("Data = " + data);
// Create a handler to tell the renderer how to draw to the screen
BiConsumer<HTMLView, DataElement<Boolean>> drawViewFunc = (v, w) -> v.draw(w);
BiConsumer<HTMLView, DataElement<String>> stringViewFunc = (v, w) -> v.draw(w);
BiConsumer<HTMLView, DataElement<Offset>> offsetViewFunc = (v, w) -> v.draw(w);
// Setup some test values and test some stuff
testSomeStuff();
// Setup the renderer
renderer.setDataElement(data);
renderer.setDrawMethod(drawViewFunc);
// Draw the render
renderer.render();
// Configure another basic data element with a string value that is the same as
// the last
dataString.setData("true");
stringRenderer.setDataElement(dataString);
stringRenderer.setDrawMethod(stringViewFunc);
stringRenderer.render();
// Configure one with Pojo data
osRenderer.setDrawMethod(offsetViewFunc);
osRenderer.setDataElement(sampleOffset);
osRenderer.render();
/**
*/
/**
* -----Ross likes the generic types and wants me to look into generics for
* LitElement
*
* I wrote DataElement to give a json string when toString() is called. This can
* be passed directly to a LitElement component using .setProperty().
*
* I need to try out the DataElements class with LitElement and Vaadin. *
* How about dynamic updates?
*
* -----Ross wants me to see about reflection too
*
* I got data elements working with a tiny bit of reflection. Things we need:
* *DataElement<T> needs to know the Class of the instance of T. This could be
* done on set. *How should DataElement<T> handle null setting? *We need some a
* test to make sure that Jackson reads T in for different types, including the
* Boxed types as well as Pojos.
*
* -----Can we use dependency injection too?
*
* I have tested this with Google Guice. It works fine with javax.* annotations
* and I was able to remove the factory classes entirely. The code is much nicer
* now.
*
* -----Can I show some examples of HTMLView subclasses?
*
* Maybe do it with the LitElement work above.
*
*/
}
private void testSomeStuff() {
// Decorated property - description
sampleOffset.setDescription("Sample Offset in mm");
// Data property - use
sampleOffset.setData(new Offset());
// System.out.println("Offset");
sampleOffset.getData().setUsed(true);
// System.out.println(sampleOffset);
String offset = sampleOffset.toString();
sampleOffset.getData().setValue(5.0);
sampleOffset.getData().setUsed(false);
System.out.println(sampleOffset);
System.out.println("----- From String -----");
sampleOffset.fromString(offset);
System.out.println("----- -----");
System.out.println(sampleOffset.toString());
// Read in and configure defaults
DataElement<Double> scaleFactor = new DataElement<Double>();
scaleFactor.setData(1.0);
scaleFactor.setDescription("Absolute Scale Factor");
scaleFactor.setName(scaleFactor.getDescription());
DataElement<Double> apertureSize = new DataElement<Double>();
apertureSize.setData(1.0);
DataElement<String> binType = new DataElement<String>();
binType.setData("1");
DataElement<Integer> OneDNumberOfBins = new DataElement<Integer>();
OneDNumberOfBins.setData(1);
DataElement<Integer> TwoDNumberOfBins = new DataElement<Integer>();
TwoDNumberOfBins.setData(1);
// Load data model
ArrayList<DataElement> dataModel = new ArrayList<DataElement>();
dataModel.add(scaleFactor);
dataModel.add(apertureSize);
dataModel.add(binType);
dataModel.add(OneDNumberOfBins);
dataModel.add(TwoDNumberOfBins);
// System.out.println(dataModel);
// System.out.println(dataModel.get(4));
DataElement<Integer> gpSANSTwoDNumberOfBins = new DataElement<Integer>();
gpSANSTwoDNumberOfBins.setData(8);
dataModel.set(4, gpSANSTwoDNumberOfBins);
// System.out.println(dataModel);
// dataRenderer.render(model);
}
}
package gov.ornl.rse.renderer;
public class Validator {
}
/target/
.idea/
.settings
.project
.classpath
*.iml
.DS_Store
# The following files are generated/updated by vaadin-maven-plugin
node_modules/
# Browser drivers for local integration tests
drivers/
# Error screenshots generated by TestBench for failed integration tests
error-screenshots/
webpack.generated.js
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>
# Project Base for Vaadin and Spring Boot
This project can be used as a starting point to create your own Vaadin application with Spring Boot.
It contains all the necessary configuration and some placeholder files to get you started.
The best way to create your own project based on this starter is [start.vaadin.com](https://start.vaadin.com/) - you can get only the necessary parts and choose the package naming you want to use.
## Running the Application
Import the project to the IDE of your choosing as a Maven project.
Run the application using `mvn spring-boot:run` or by running the `Application` class directly from your IDE.
Open http://localhost:8080/ in your browser.
If you want to run the application locally in the production mode, run `mvn spring-boot:run -Pproduction`.
To run Integration Tests, execute `mvn verify -Pintegration-tests`.
## More Information
- [Vaadin Flow](https://vaadin.com/flow) documentation
- [Using Vaadin and Spring](https://vaadin.com/docs/v14/flow/spring/tutorial-spring-basic.html) article
Place your Vaadin Designer or hand written templates in this folder.
import {css, customElement, html, LitElement, property} from 'lit-element';
import '@vaadin/vaadin-text-field';
export class DataElement