Took me a while to figure this out:
If you have a CheckboxTableViewer and want to set the initial state of the table contents as (un)checked, you
cannot do the initialization in the LabelProvider. It seemed like the most logical place, and the viewer does enter the code for setChecked(element, true), but nothing is displayed. Turns you have to let the table draw first (I don't understand why):
public void update() {
// inputs the same
tableViewer.setInput("");
tableViewer.refresh();
List weapons = WeaponHome.inst.findAll();
for (DAO weapon : weapons) {
if (Ctx.getChar().weapons.contains(weapon)) {
((CheckboxTableViewer) tableViewer).setChecked(weapon, true);
}
}
}
For the record, this is the code that
does not work:
public String getColumnText(Object element, int columnIndex) {
String value = "";
Weapon weapon = (Weapon) element;
if (isEditable()) {
if (Ctx.getChar().weapons.contains(weapon)) {
((CheckboxTableViewer) tableViewer).setChecked(element, true);
}
}