Reputation: 711
Basically, this program is a 9x9 matrix where each cell need to be updated with certains numbers. I have a table for the matrix. Initialized it to be 0's. Program is working but the table is getting updated only one after everything is done. (a solution is found).
Table cells are not getting updated as the data is changing behind the scene. The entire table is getting updated at the end of execution of the program. But I want to see each number change real time as I assign a value to each cell. Any code help is really appreciated.
I tried this with not having a container too. but that didn't update the table either. The research I did tells me that setImmediate(true) need to be set on the table. But I have that already.
Also, the forums are saying
Item itt = container.getItem(cell.getRowIndex() + 1);
Property<Integer> rrr = itt.getItemProperty(cell.getColumnIndex() + 1);
rrr.setValue(num);
The above lines should be sufficient to reflect the numbers changing in the UI. But its not happening. I also tried
table.refreshRowCache();
table.setCacheRate(0.1);
But didnt work.
I have also read in the forum to use a valuechangelistner. But, I was not able to find a good example which shows me how to do this, iff this is the only way to go
private Container container = new IndexedContainer();
public class MyVaadinUI extends UI {
@Override
protected void init(VaadinRequest request) {
...
for (int i = 1; i <= 9; i++) {
container.addContainerProperty(i, Integer.class, 0);
}
for (int i = 1; i <= 9; i++) {
container.addItem(i);
}
...
table.setContainerDataSource(container);
table.setImmediate(true);
...
...
/ * this is filling the table correctly with all 0's */
populate.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
...
for (int i = 1; i <= 9; i++) {
Item item = container.getItem(i);
int rowIndex = i - 1;
for (int j = 1; j <= 9; j++) {
Property<Integer> nameProperty = item.getItemProperty(j);
int columnIndex = j - 1;
nameProperty.setValue(uploadReceiver.getMatrix()[rowIndex][columnIndex]);
}
}
}
});
solveButton.addClickListener(new ClickListener() {
private boolean solveSudoko() {
...
for (int num = 1; num <= 9; num++) {
// check if no conflicts then
if (!AreThereConflicts(num, cell.getRowIndex(), cell.getColumnIndex())) {
uploadReceiver.getMatrix()[cell.getRowIndex()][cell.getColumnIndex()] = num;
// Item row = container.getItem(cell.getRowIndex() + 1);
// Property<Integer> col =
// row.getItemProperty(cell.getColumnIndex() + 1);
// col.setValue(num);
Property prop = container.getItem(cell.getRowIndex() + 1).getItemProperty(cell.getColumnIndex() + 1);
prop.setValue(num);
table.setContainerDataSource(container);
/* Table is not getting updated here ???? */
...
uploadReceiver.getMatrix()[cell.getRowIndex()][cell.getColumnIndex()] = 0; // unassign
// Item itt = container.getItem(cell.getRowIndex() + 1);
// Property<Integer> rrr =
// itt.getItemProperty(cell.getColumnIndex() + 1);
// rrr.setValue(num);
Property prop2 = container.getItem(cell.getRowIndex() + 1).getItemProperty(cell.getColumnIndex() + 1);
prop2.setValue(num);
table.setContainerDataSource(container);
/* Table is not getting updated here ???? */
}
}
return false;
}
Upvotes: 2
Views: 6628
Reputation: 3155
At a quick glance, it seems that all of the "changing-the-cells" logic happens within a single clickListener (i.e. within solveSoduku).
All of the code within the event listener will happen within a single request/response cycle, meaning that UI will not be updated until the method completes : this is a fundamental part of the Vaadin architecture.
If you want to "see" the intermediate updates, you'll have to create a background thread to do the solving, and then use a "Push" solution to update the table as you go along. Vaadin 7.1.0 (recently released) has push built in, otherwise see this thread on the Vaadin forums.
Upvotes: 2