use of org.eclipse.draw2d.ToggleModel in project yamcs-studio by yamcs.
the class AbstractChoiceFigure method setStates.
/**
* Set all the state string values.
*
* @param states
* the states
*/
public void setStates(List<String> states) {
this.states = states;
removeAll();
for (Object model : buttonGroup.getElements().toArray()) {
buttonGroup.remove((ToggleModel) model);
}
toggles.clear();
models.clear();
int i = 0;
for (final String state : states) {
final int index = i++;
ToggleModel toggleModel = new ToggleModel();
final Toggle toggle = createToggle(state);
if (!runMode)
toggle.setEventHandler(null);
toggleModel.addChangeListener(new ChangeListener() {
@Override
public void handleStateChanged(ChangeEvent event) {
if (event.getPropertyName().equals(ToggleModel.SELECTED_PROPERTY) && toggle.isSelected()) {
if (fromSetState)
fromSetState = false;
else
fireButtonPressed(index, state);
}
}
});
buttonGroup.add(toggleModel);
toggle.setModel(toggleModel);
toggle.setEnabled(isEnabled());
toggles.add(toggle);
models.add(toggleModel);
add(toggle);
}
}
Aggregations