Merging two database tables into a single Vaadin Treetable


TL;DR: How do I combine info from two database tables into a Vaadin Treetable (or, when Vaadin 7.5 is released, a heirarchical Grid)?


I have a Java Swing desktop application that does this currently, albeit probably very ineffeciently with ArrayLists of Java Beans that updates from the SQL Server every 30 seconds. Well, I’m now attempting to port this desktop app over to a Vaadin web app. The desktop app has login capabilities and I’ll eventually worry about doing the same for the web app, but for now, I just want to try and get the most basic part of this web app working: The Treetable. Or, hopefully soon, a heirarchical Grid.

To help illustrate what I’m aiming for, I’ll try and post an image I created that should show how the data from the two tables needs to merge into the treetable (using a partial screenshot of my existing desktop app):



I am well aware of how to use the
JOIN
command in SQL and I’ve briefly read about
Referencing Another SQLContainer
, but I’m still in the early stages of learning Vaadin and still trying to wrap my head around
SQLContainer
,
FreeformQuery
, and how I need to implement
FreeformStatementDelegate
for my project. Not to mention that I’ll need to implement checkboxes for each row, as you can see in that photo, so that it updates the database when they are clicked. And a semi-checked state for the checkbox would be necessary for Jobs that have more than one OrderDetail item wherein only some of those OrderDetail items are completed. To get that working for my Java Swing program, I had to lean on an expert Java developer who already had most of the code ready, and boy, is it super-complicated!

If anyone can give me a high-level view of how to accomplish this task along with some examples, I would be indebted. I totally understand that I’m asking for a great deal here, and I’m willing to take it slow, step-by-step, as long as you are. I really want to fully understand this so I’m not just copy-pasting code without thinking.

Haven’t try this yet, but if you use a TreeTable (and later Grid when it’ll suport hierarchical data) and you provide it with a Hierarchical data source container, it will work. Please note that TreeTable implements Hierarchical, JPAContainer implements Hierarchical, but SQLContainer doesn’t. You can find JPAContainer as addon:
https://vaadin.com/directory#!addon/vaadin-jpacontainer
.

The location in the book where you can read more about:
https://vaadin.com/book/-/page/jpacontainer.usage.html#jpacontainer.usage.hierarchical
.

Thank you for responding, Bogdan. Yes, I just recently discovered that I would either need to extend SQLContainer to implement Container.Hierarchical or just use JPAContainer instead. Since the former is probably beyond my abilities, I think I’ll choose to use JPAContainer. However, I need to figure out how to use JPA with Eclipse and our MS SQL Server first, and I’m not running into much success with that so far.

I think the
Dali Java Persistence Tools
plugin for Eclipse works quite well. It has a very useful editor for creating and annotating JPA entities. It also manages your persistence.xml file. There’s even a tool to reverse engineer the database tables into JPA annotated entities - it doesn’t always work exactly the way you want it to but it really helped me figure out the @OneToMany and @ManyToOne relationships that were defined in the database. If you go this route, I would also recommend using EclipseLink as your JPA persistence provider (as opposed to hibernate or OpenJpa) although I don’t think it’s mandatory to do that.

If you want to avoid using JPA you can use HierarchicalContainer. You only need to populate it with data from your undelying sql provider. It might not be the best option but it’s simple and you won’t get into technical issues like with JPA.

You can also have a look at the Sampler page for TreeTable:
http://demo.vaadin.com/sampler/#ui/grids-and-trees/tree-table
. In the top right corner of the page, there is an info (i) button. Click on it, then on Source, and you’ll see the source code used to build that TreeTable. That can be really useful to understand how to construct a HierarchicalContainer.

I’ve finally gotten some time now to turn at least some of my attention back to this project. I’m ready to start fresh and learn JPA. Fair warning, though: I’m only barely familiar with JDBC, so it might take some JPA tutorials to get me up to speed, if there are any. And, of course, I’ll gladly use Vaadin’s Treetable for now, at least until Grid supports hierarchical data.

Now, what’s the first step to getting started with JPA? Installing the Dali Java Persistence Tools plugin for Eclipse, as @darrelln09 suggested? And once I have done so, where’s a good place for learning how to use it with Microsoft SQL Server? Just taking this one step at a time…

Okay, so no help with JPA. That’s fine; I’m familiar enough with JDBC and storing the data in Java Beans, so I’ll just stick to that.

I’ll try your suggestion to use
HierarchicalContainer
, @Bogdan. However, the only documentation I can find on
HierarchicalContainer
in the Book of Vaadin has to do with
JPAContainer
. Is there a book or tutorial somewhere on how to properly use
HierarchicalContainer
(especially if you already have your data retrieved from a SQL Server and stored in Java Beans) without the dependency on
JPAContainer
?