Hi,
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:
- I create generated property for progress and put that in a map mapped to BB table’s ID and make it invisible.
- Status gets update in a background thread - directly on DB so no changes shown on the grid
- If I call refresh() on container - status gets displayed properly but the progress bar never gets shown
- If I don’t call refresh on the container the progress bar gets shown
@Override
public Component getValue(Item item, Object itemId, Object propertyId) {
ProgressBar pb = new ProgressBar();
pb.setWidth("100.0%");
pb.setVisible(false);
progressBars.put((Long) item.getItemProperty("id").getValue(), pb);
return pb;
}
Then event handling:
@Override
public void handleProgressEvent(final MyProgressEvent event) {
Long id = event.getActivitiTaskDefinition().getId();
final ProgressBar pb = progressBars.get(id);
UI.getCurrent().access(new Runnable() {
@Override
public void run() {
if (!event.getFinished() && !pb.isVisible()) {
//container.refresh();
pb.setVisible(true);
} else if (!event.getFinished() && pb.isVisible()) {
pb.setValue(event.getProgress());
} else if (event.getFinished()) {
pb.setVisible(false);
}
}
});
}
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.
Adrian