Example usage for com.google.gwt.event.logical.shared ValueChangeEvent ValueChangeEvent

List of usage examples for com.google.gwt.event.logical.shared ValueChangeEvent ValueChangeEvent

Introduction

In this page you can find the example usage for com.google.gwt.event.logical.shared ValueChangeEvent ValueChangeEvent.

Prototype

protected ValueChangeEvent(T value) 

Source Link

Document

Creates a value change event.

Usage

From source file:org.onesocialweb.gwt.client.ui.widget.ListSelector.java

License:Apache License

public void addCheckbox(String list, Boolean value) {

    final CheckBox checkbox = new CheckBox(list);
    StyledFlowPanel fix = new StyledFlowPanel("fix");
    checkbox.addStyleName("checkbox");

    // manage checks and unchecks
    checkbox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override//  ww  w .  j a  v a  2s  .  com
        public void onValueChange(ValueChangeEvent<Boolean> event) {

            // is the item is checked?
            if (event.getValue() == true && !listed.contains(checkbox.getText()) && checkbox.getText() != null
                    && checkbox.getText().length() != 0) {
                // set the values
                listed.add(checkbox.getText());
                rosterItem.setGroups(listed);
                // disable during processing
                checkbox.setEnabled(false);

                // show task
                final DefaultTaskInfo task = new DefaultTaskInfo("Adding person to the list", false);
                TaskMonitor.getInstance().addTask(task);

                // save new state
                rosterItem.save(new RequestCallback<RosterItem>() {

                    @Override
                    public void onFailure() {
                        // return to original state and notify user
                        checkbox.setEnabled(true);
                        checkbox.setValue(true);
                        task.complete("Could not add person to list.", Status.failure);
                    }

                    @Override
                    public void onSuccess(RosterItem result) {
                        // enable the checkbox again
                        checkbox.setEnabled(true);
                        task.complete("", Status.succes);
                    }

                });
            } else if (event.getValue() == false && listed.contains(checkbox.getText())) {
                // set the values
                listed.remove(checkbox.getText());
                rosterItem.setGroups(listed);
                // disable during processing
                checkbox.setEnabled(false);

                // show task
                final DefaultTaskInfo task = new DefaultTaskInfo("Removing person from the list", false);
                TaskMonitor.getInstance().addTask(task);

                // save new state
                rosterItem.save(new RequestCallback<RosterItem>() {

                    @Override
                    public void onFailure() {
                        // return to original state and notify user
                        checkbox.setEnabled(true);
                        checkbox.setValue(true);
                        task.complete("Could not remove person from the list.", Status.failure);
                    }

                    @Override
                    public void onSuccess(RosterItem result) {
                        // enable the checkbox again
                        checkbox.setEnabled(true);
                        task.complete("", Status.succes);
                    }

                });
            }
        }

    });

    // if this person is already on the list make sure the checkbox is
    // checked
    if (listed != null && list.length() > 0 && listed.contains(list)) {
        checkbox.setValue(true);
    } else if (value == true) {
        // if a new checkbox is added automatically check it and fire a
        // change event
        checkbox.setValue(true);
        checkbox.fireEvent(new ValueChangeEvent<Boolean>(true) {
        });
    }
    if (checkbox.getText() != null && checkbox.getText().length() != 0) {
        wrapper.add(checkbox);
        wrapper.add(fix);
    }

}