Search in sources :

Example 1 with ToggleModel

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);
    }
}
Also used : ChangeEvent(org.eclipse.draw2d.ChangeEvent) Toggle(org.eclipse.draw2d.Toggle) ToggleModel(org.eclipse.draw2d.ToggleModel) ChangeListener(org.eclipse.draw2d.ChangeListener)

Aggregations

ChangeEvent (org.eclipse.draw2d.ChangeEvent)1 ChangeListener (org.eclipse.draw2d.ChangeListener)1 Toggle (org.eclipse.draw2d.Toggle)1 ToggleModel (org.eclipse.draw2d.ToggleModel)1