Posts

Vaadin JPA Container Example

Simple example showing how to use a Vaadin JPA Container The scenario is a Customer entity in a database. You have a use case which requires the retrieval of a customer record by Name and By Number. 1) Set up a Entity Manager private final EntityManager em; 2) Create the Entity Manager from the persistence unit em = JPAContainerFactory.createEntityManagerForPersistenceUnit(< name of persistence unit >); 3) Get Customer By Number - returns a JPA Container which is useful for Vaadin Tables public JPAContainer getCustomerByNumber(String aCustomerNumber) { JPAContainer customer = JPAContainerFactory.make(Customer.class, em); Container.Filter filter = new Compare.Equal("number", aCustomerNumber); customer.addContainerFilter(filter); return customer; } 4) Get Customer By Name - uses JPA named query public Customer getCustomerByName(String aCustomerName) { Query queryCustomerByName = em.createN...

Have Software Components finally arrived

Image
Introduction In April 2013 Dr Dobbs editorial piece summoned a long held vision for software components and reuse. It proclaimed : “After 40 years in the desert of incompatibility and limited reuse, we have crossed the river Jordan.” It was a romantic notion and it provides a sign post for a vision about software components that stretches back to 1968. 1968 Software Engineering NATO Conference Components became part of the software engineering discipline in the very first Software Engineering conference in 1968. Sponsored by NATO, the conference brought together the leading researchers at the time. In a presentation provided by M. D. McIlroy, titled,  “Mass Produced Software Components”, McIlory set out the fundamental principles by which a industry based on the production of software components could be founded. “My thesis is that the software industry is weakly founded, and that one aspect of this weakness is the absence of a software components subindu...

Vaadin - GRID Component

Image
Introduction Vaadin 7.4 was recently released and it includes a new component called the GRID . It represents a 'Spreadsheet" type model from a UI perspective, however I think it lacks a lot of features you would expect from this type of component. Maybe this component will evolve over time and it will begin to have the functions that you expect from a spreadsheet. ( note: there is a commercial add on called the Spreadsheet from Vaadin ) Use Case The use case I am demonstrating below is a simple grid showing projected sales of Widgets over a five year period. Creation Creating a Grid is very simple and you have numerous options for sizing on the page. In the example below I setting it across the page. The Grid rows can be selected for editing, you can select single or multiple rows in a single action. myGrid = new Grid(); myGrid.setSizeFull(); myGrid.setSelectionMode(SelectionMode.SINGLE); Container Backing Similar to many other Vaadin componen...

Google Guava HashBasedTable Example

Image
A simple example showing how to establish a Google Guava Hash Based Table. Notes A class called Board represents a Sudoku Board Create a Hash Based Table which contains a Cell Class Create the Hash Based Table in the constructor Load the board using a int array Print a simple representation of the board Cell class below shows a simple way to represent a cell on a Sudoku Board

Jersey Rest Basics

Image
I use the Jersey Rest API  and I always deploy to Tomcat. There are some basic things you need to do to make this work. There are few examples around the internet which are very good, but they seem to be focused on some very old versions of the framework. Number 1, make sure your web xml contains this configuration. Number 2, I use Maven , so this is my Pom File, this example includes the dependency for using JSON processing. Number 3, write some code. That's for another blog entry.

Web Cam and Vaadin

A very interesting Web Cam Add On is available from the Vaadin Add On site . Here is a simple recipe for making it work. Create a split panel and add the Web Cam to the left hand side of the panel. splitPanel = new HorizontalSplitPanel(); splitPanel.setSizeFull(); VerticalLayout detailsLayout = new VerticalLayout(); detailsLayout.setSpacing(true); detailsLayout.setSizeFull(); // Create the webcam and assign a receiver. final Webcam webcam = new Webcam(); webcam.setWidth("600px"); detailsLayout.addComponent(webcam); detailsLayout.setComponentAlignment(webcam, Alignment.TOP_LEFT); Create a receiver which creates a temporary file with a jpeg extension. webcam.setReceiver(new Upload.Receiver() { @Override public OutputStream receiveUpload(String filename, String mimeType) { try { targetFile = File.createTemp...

Java and KML Files

What is a KML file.? A Keyhole Markup Language File (KML) is a markup language to describe geographic data. How does it relate to Java.? An API exists ( which appears quite old ) which can process KML files. Either producing them or turning the KML files into Java objects. ( Marshalling or Unmarshalling ) Problem ? I recently downloaded some geographic data from a public dataset which was expressed as a KML file. Its my intention to use that data in a sample application. However I had a huge problem getting the API to un-marshall the data. It had a major problem with the namespace in the dataset. This namespace causes the API major problems. <kml xmlns="http://earth.google.com/kml/2.1"> After numerous hours I found this worked. ( so I replaced the above with the below ) <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom=...