Grid and dynamically update progress bar


I have a DB table which holds amongst others status field.
I use an SQLContainer to display it in a grid.
When background process starts, I want to be able to show this progress on the grid for relevant row.
If status is eg “Idle” - I don’t want to show the progress bar at all.
Because of that I thought the easiest way of doing that would be using Component Renderer addon.
However I am having problems in doing so. What happens is:

  1. I create generated property for progress and put that in a map mapped to BB table’s ID and make it invisible.
  2. Status gets update in a background thread - directly on DB so no changes shown on the grid
  3. If I call refresh() on container - status gets displayed properly but the progress bar never gets shown
  4. If I don’t call refresh on the container the progress bar gets shown
public Component getValue(Item item, Object itemId, Object propertyId) {
   ProgressBar pb = new ProgressBar();
   progressBars.put((Long) item.getItemProperty("id").getValue(), pb);
   return pb;

Then event handling:

public void handleProgressEvent(final MyProgressEvent event) {
   Long id = event.getActivitiTaskDefinition().getId();
   final ProgressBar pb = progressBars.get(id);
   UI.getCurrent().access(new Runnable() {

      public void run() {
         if (!event.getFinished() && !pb.isVisible()) {
         } else if (!event.getFinished() && pb.isVisible()) {
         } else if (event.getFinished()) {

So with the commented out refresh I do get progress bar as expected but no updates for status from DB as expected.
With refresh in place (comment removed) I do get the updates from DB for status (UI set to poll every 5s) but the progress bar never even appears. I would have thought that on refresh the progress bar components gets recreated and put back to the map but somehow it does not work …

Is the an elegant way of doing that ?

Many thanks for any suggestions.


Ok - I know what is happening:

  1. The event handling was wrong it should get the progress bar after refresh
  2. Even then - the refresh is happening after the event handle finishes so it looses the progress bar (the one which it updates with visibility or progress get replaced after event handler call due to refresh being called in there).

I can fix it now but it does not seem an elegant solution - any example of how to do it nicely ?


So what I did is instead of putting to map progress bar objects associated with a DB table ID I put the event associated with the DB table ID. And now when I generate the progress bar I check for existing event for the ID and update it accordingly. In the event handler I only call refresh on the SQL container and it all works.

I still feel like it is quite an ugly way of doing that.

Is there a proven and an elegant way of generating progress bar in grid / table and update it dynamically from a background thread (or in general any component that needs to be updated dynamically) ?