Example usage for com.google.gwt.user.client.ui CheckBox getFormValue

List of usage examples for com.google.gwt.user.client.ui CheckBox getFormValue

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui CheckBox getFormValue.

Prototype

public String getFormValue() 

Source Link

Document

Returns the value property of the input element that backs this widget.

Usage

From source file:net.cbtltd.client.field.StackField.java

/**
 * Renders the field from the specified map of available key-option(s) into the field.
 *
 * @param map the map of available key-option(s).
 *//*from  w  w w  .ja v a 2s .c  o m*/
private void setItems(HashMap<NameId, ArrayList<NameId>> map) {
    if (map == null) {
        return;
    }
    field.clear();
    ArrayList<NameId> keys = new ArrayList<NameId>(map.keySet());
    Collections.sort(keys);
    for (NameId key : keys) {
        ArrayList<NameId> values = map.get(key);
        VerticalPanel options = new VerticalPanel();
        options.setTitle(key.getId());
        field.add(options,
                "<img src='" + BUNDLE.open().getURL() + "' style='padding: 1px;'</img>" + key.getName(), true);
        //         field.add(options, key.getName());
        for (NameId value : values) {
            CheckBox cb = new CheckBox(value.getName());
            cb.setFormValue(value.getId());
            cb.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    CheckBox cb = (CheckBox) event.getSource();
                    if (isUniquekey(cb.getFormValue())) {
                        deselect(cb.getFormValue());
                        cb.setValue(true);
                    }
                }
            });
            options.add(cb);
        }
    }
}

From source file:net.cbtltd.client.field.StackField.java

/**
 * Sets the selected options in the field from the specified map of selected key-option(s).
 *
 * @param value the map of selected key-option(s).
 *//*  www .  j av  a2  s  .co  m*/
public void setValue(HashMap<String, ArrayList<String>> value) {
    for (int index = 0; index < field.getWidgetCount(); index++) {
        VerticalPanel options = (VerticalPanel) field.getWidget(index);
        String key = options.getTitle();
        for (int row = 0; row < options.getWidgetCount(); row++) {
            CheckBox cb = (CheckBox) options.getWidget(row);
            if (cb == null) {
                Window.alert("setValue " + row);
            }
            String id = cb.getFormValue();
            if (value == null) {
                cb.setValue(false);
            } else if (value.containsKey(key)) {
                cb.setValue(value.get(key).contains(id));
            }
        }
    }
    super.setChanged();
}

From source file:net.cbtltd.client.field.StackField.java

/**
 * Gets the selected options of the field.
 *
 * @return map the map of selected key-option(s).
 *///from   ww w .  j  ava2s. c  o  m
public HashMap<String, ArrayList<String>> getValue() {
    ArrayList<String> item = null;
    HashMap<String, ArrayList<String>> value = new HashMap<String, ArrayList<String>>();
    for (int index = 0; index < field.getWidgetCount(); index++) {
        VerticalPanel options = (VerticalPanel) field.getWidget(index);
        String key = options.getTitle();
        for (int row = 0; row < options.getWidgetCount(); row++) {
            CheckBox cb = (CheckBox) options.getWidget(row);
            if (cb == null) {
                Window.alert("StackField getValue " + row);
            }
            String id = cb.getFormValue();
            if (cb.getValue()) {
                if (!value.containsKey(key)) {
                    item = new ArrayList<String>();
                    value.put(key, item);
                }
                item.add(id);
            }
        }
    }
    return value;
}

From source file:net.cbtltd.client.form.OrganizationForm.java

License:Open Source License

private FlowPanel createWorkflow() {
    final FlowPanel panel = new FlowPanel();
    final HTML workflowText = new HTML(CONSTANTS.workflowText());
    panel.add(workflowText);/*from   w  w w.jav  a2  s .c  o m*/
    final String[] WORKFLOW_DATES = { Reservation.FROMDATE, Reservation.DATE, Reservation.TODATE };
    final ArrayList<NameId> DATENAMES = NameId.getList(CONSTANTS.workflowDates(), WORKFLOW_DATES);

    workflowGrid = new GridField<Workflow>(this, null, CONSTANTS.workflowHeaders(),
            Reservation.WORKFLOW_STATES.length, tab++) {

        @Override
        public void setRowValue(int row, Workflow value) {

            CheckBox enabledField = new CheckBox(getStatename(value.getState()));
            enabledField.setFormValue(value.getState());
            enabledField.setValue(value.getEnabled());
            enabledField.addStyleName(OrganizationForm.CSS.workflowState());
            workflowGrid.setWidget(row, 0, enabledField);

            IntegerField durationField = new IntegerField(this, null, null, 0);
            durationField.setValue(value.getDuration());
            durationField.setFieldStyle(OrganizationForm.CSS.workflowDuration());
            workflowGrid.setWidget(row, 1, durationField);

            workflowGrid.setText(row, 2, value.getUnit().toString());

            ToggleButton priorField = new ToggleButton(OrganizationForm.CONSTANTS.workflowLabelAfter(),
                    OrganizationForm.CONSTANTS.workflowLabelBefore());
            priorField.setDown(value.getPrior());
            priorField.addStyleName(OrganizationForm.CSS.workflowWhen());
            workflowGrid.setWidget(row, 3, priorField);

            ListField datenameField = new ListField(this, null, DATENAMES, null, false, 0);
            datenameField.setValue(value.getDatename());
            datenameField.setFieldStyle(OrganizationForm.CSS.workflowDatename());
            workflowGrid.setWidget(row, 4, datenameField);
        }

        @Override
        public Workflow getRowValue(int row) {
            CheckBox enabledField = (CheckBox) workflowGrid.getWidget(row, 0);
            IntegerField durationField = (IntegerField) workflowGrid.getWidget(row, 1);
            ToggleButton priorField = (ToggleButton) workflowGrid.getWidget(row, 3);
            ListField datenameField = (ListField) workflowGrid.getWidget(row, 4);
            Workflow value = new Workflow(organizationField.getId(), NameId.Type.Reservation.name(),
                    enabledField.getFormValue(), enabledField.getValue(), priorField.isDown(),
                    datenameField.getValue(), Time.DAY.name(), durationField.getValue());
            //Window.alert("getRowValue " + value);
            return value;
        }
    };

    ArrayList<Workflow> defaultValue = new ArrayList<Workflow>();
    defaultValue.add(new Workflow(organizationField.getId(), NameId.Type.Reservation.name(),
            Reservation.WORKFLOW_STATES[0], true, false, Reservation.DATE, Time.DAY.name(), 2));//RESERVED
    defaultValue.add(new Workflow(organizationField.getId(), NameId.Type.Reservation.name(),
            Reservation.WORKFLOW_STATES[1], true, false, Reservation.DATE, Time.DAY.name(), 3));//CONFIRMED
    defaultValue.add(new Workflow(organizationField.getId(), NameId.Type.Reservation.name(),
            Reservation.WORKFLOW_STATES[2], true, true, Reservation.FROMDATE, Time.DAY.name(), 35));//FULLYPAID
    defaultValue.add(new Workflow(organizationField.getId(), NameId.Type.Reservation.name(),
            Reservation.WORKFLOW_STATES[3], true, true, Reservation.FROMDATE, Time.DAY.name(), 7));//BRIEFED
    defaultValue.add(new Workflow(organizationField.getId(), NameId.Type.Reservation.name(),
            Reservation.WORKFLOW_STATES[4], true, true, Reservation.FROMDATE, Time.DAY.name(), 1));//ARRIVED
    defaultValue.add(new Workflow(organizationField.getId(), NameId.Type.Reservation.name(),
            Reservation.WORKFLOW_STATES[5], true, true, Reservation.TODATE, Time.DAY.name(), 2));//PREDEPARTED
    defaultValue.add(new Workflow(organizationField.getId(), NameId.Type.Reservation.name(),
            Reservation.WORKFLOW_STATES[6], true, true, Reservation.TODATE, Time.DAY.name(), 7));//DEPARTED
    //      defaultValue.add(new Workflow(organizationField.getId(), NameId.Type.Reservation.name(), Reservation.WORKFLOW_STATES[7], true, false, Reservation.TODATE, Time.DAY.name(), 7));//DEPARTED
    workflowGrid.setDefaultValue(defaultValue);

    panel.add(workflowGrid);
    return panel;
}

From source file:net.scran24.user.client.surveyscheme.MultipleChoiceCheckboxQuestion.java

@Override
public SimpleSurveyStageInterface getInterface(final Callback1<Survey> onComplete,
        Callback2<Survey, Boolean> onIntermediateStateChange) {
    final FlowPanel content = new FlowPanel();
    content.addStyleName("intake24-multiple-choice-question");
    content.addStyleName("intake24-survey-content-container");

    content.add(WidgetFactory.createPromptPanel(questionText));

    FlowPanel checkboxesDiv = new FlowPanel();
    checkboxesDiv.addStyleName("scran24-ready-meals-checkboxes-block");

    final ArrayList<CheckBox> checkBoxes = new ArrayList<CheckBox>();

    for (String option : options) {
        FlowPanel rowDiv = new FlowPanel();
        CheckBox checkBox = new CheckBox(SafeHtmlUtils.htmlEscape(option));
        checkBox.setFormValue(option);// ww  w. ja  v  a2 s .c  om
        checkBox.addStyleName("scran24-ready-meals-checkbox");
        checkBoxes.add(checkBox);
        rowDiv.add(checkBox);
        checkboxesDiv.add(rowDiv);
    }

    if (!otherOptionName.isEmpty()) {
        FlowPanel otherPanel = new FlowPanel();
        otherOption = new CheckBox(otherOptionName.getOrDie() + ": ");
        otherPanel.add(otherOption);
        otherBox = new TextBox();
        otherPanel.add(otherBox);
        checkboxesDiv.add(otherPanel);

        otherBox.addFocusHandler(new FocusHandler() {
            @Override
            public void onFocus(FocusEvent event) {
                otherOption.setValue(true);
            }
        });
    }

    content.add(checkboxesDiv);

    Button accept = WidgetFactory.createGreenButton(acceptText, new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {

            StringBuilder value = new StringBuilder();
            boolean first = true;

            for (CheckBox checkBox : checkBoxes)
                if (checkBox.getValue()) {
                    if (first)
                        first = false;
                    else
                        value.append(", ");

                    value.append(checkBox.getFormValue());
                }

            if (!otherOptionName.isEmpty()) {
                if (otherOption.getValue()) {
                    if (!first)
                        value.append(", ");
                    value.append(otherBox.getText());
                }
            }

            onComplete.call(state.withData(dataField, value.toString()));
        }
    });

    content.add(checkboxesDiv);
    content.add(accept);

    return new SimpleSurveyStageInterface(content);
}

From source file:org.activityinfo.ui.client.component.form.field.CheckBoxFieldWidget.java

License:Open Source License

private ReferenceValue updatedValue() {
    final Set<ResourceId> value = Sets.newHashSet();
    for (CheckBox control : controls) {
        if (control.getValue()) {
            value.add(ResourceId.valueOf(control.getFormValue()));
        }/* w w w.  jav  a  2s. c  o m*/
    }
    return new ReferenceValue(value);
}

From source file:org.activityinfo.ui.client.component.form.field.CheckBoxFieldWidget.java

License:Open Source License

@Override
public Promise<Void> setValue(ReferenceValue value) {
    Set<ResourceId> ids = value.getResourceIds();
    for (CheckBox entry : controls) {
        ResourceId resourceId = ResourceId.valueOf(entry.getFormValue());
        entry.setValue(ids.contains(resourceId));
    }/*  w w w.j a va2s  .com*/
    return Promise.done();
}

From source file:org.bonitasoft.forms.client.view.widget.CheckboxGroupWidget.java

License:Open Source License

/**
 * @return the List of String value of the slected checkboxes of the group
 *///from   w w w .  j a  v  a2  s.c  o  m
public List<String> getValue() {

    final List<String> values = new ArrayList<String>();

    final Iterator<Widget> iterator = groupWidgets.iterator();
    while (iterator.hasNext()) {
        final CheckBox checkBox = (CheckBox) iterator.next();
        if (checkBox.getValue()) {
            values.add(checkBox.getFormValue());
        }
    }
    return values;
}

From source file:org.bonitasoft.forms.client.view.widget.CheckboxGroupWidget.java

License:Open Source License

/**
 * Set the value of the widget//w  w  w  .  j a  v  a  2  s . c om
 * 
 * @param value
 */
public void setValue(final Collection<String> values, boolean fireEvents) {
    final List<String> oldValues = getValue();
    if (values != null && oldValues.containsAll(values) && values.containsAll(oldValues)) {
        fireEvents = false;
    }
    for (final CheckBox checkbox : checkboxes) {
        if (values != null && values.contains(checkbox.getFormValue())) {
            checkbox.setValue(true);
        } else {
            checkbox.setValue(false);
        }
    }
    if (fireEvents) {
        ValueChangeEvent.fire(this, true);
    }
}

From source file:org.calontir.marshallate.falcon.client.ui.fighterform.AuthorizationsField.java

public AuthorizationsField(final Fighter fighter, final boolean edit) {
    Panel dataBody = new FlowPanel();
    dataBody.setStyleName("dataBody");
    if (edit) {//from w  w  w  . java  2  s.co  m
        for (AuthType at : lookupController.getAuthType()) {
            final CheckBox cb = new CheckBox(at.getCode());
            cb.setFormValue(at.getCode());
            cb.setName("authorization");
            if (fighter.getAuthorization() != null) {
                for (Authorization a : fighter.getAuthorization()) {
                    if (a.getCode().equals(at.getCode())) {
                        cb.setValue(true);
                        break;
                    }
                }
            }
            cb.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                @Override
                public void onValueChange(ValueChangeEvent<Boolean> event) {
                    List<Authorization> auths = fighter.getAuthorization();
                    if (auths == null) {
                        auths = new ArrayList<Authorization>();
                        fighter.setAuthorization(auths);
                    }
                    Authorization a = new Authorization();
                    a.setCode(cb.getFormValue());
                    if (auths.contains(a)) {
                        if (event.getValue()) {
                            auths.add(a);
                        } else {
                            auths.remove(a);
                        }
                    } else {
                        if (event.getValue()) {
                            auths.add(a);
                        }
                    }
                }
            });
            dataBody.add(cb);
        }
    } else {
        Label auths = new Label();
        auths.setText(getAuthsAsString(fighter.getAuthorization()));
        dataBody.add(auths);
    }
    initWidget(dataBody);
}