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

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

Introduction

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

Prototype

@Override
public void setValue(Boolean value) 

Source Link

Document

Checks or unchecks the check box.

Usage

From source file:com.vaadin.terminal.gwt.client.ui.VOptionGroup.java

License:Open Source License

@Override
protected void buildOptions(UIDL uidl) {
    panel.clear();/*from w w  w  .j  a  v a 2  s. c  om*/
    for (final Iterator<?> it = uidl.getChildIterator(); it.hasNext();) {
        final UIDL opUidl = (UIDL) it.next();
        CheckBox op;

        String itemHtml = opUidl.getStringAttribute("caption");
        if (!htmlContentAllowed) {
            itemHtml = Util.escapeHTML(itemHtml);
        }

        String icon = opUidl.getStringAttribute("icon");
        if (icon != null && icon.length() != 0) {
            String iconUrl = client.translateVaadinUri(icon);
            itemHtml = "<img src=\"" + iconUrl + "\" class=\"" + Icon.CLASSNAME + "\" alt=\"\" />" + itemHtml;
        }

        if (isMultiselect()) {
            op = new VCheckBox();
            op.setHTML(itemHtml);
        } else {
            op = new RadioButton(id, itemHtml, true);
            op.setStyleName("v-radiobutton");
        }

        if (icon != null && icon.length() != 0) {
            Util.sinkOnloadForImages(op.getElement());
            op.addHandler(iconLoadHandler, LoadEvent.getType());
        }

        op.addStyleName(CLASSNAME_OPTION);
        op.setValue(opUidl.getBooleanAttribute("selected"));
        boolean enabled = !opUidl.getBooleanAttribute("disabled") && !isReadonly() && !isDisabled();
        op.setEnabled(enabled);
        setStyleName(op.getElement(), ApplicationConnection.DISABLED_CLASSNAME, !enabled);
        op.addClickHandler(this);
        optionsToKeys.put(op, opUidl.getStringAttribute("key"));
        panel.add(op);
    }
}

From source file:com.vaadin.v7.client.ui.VOptionGroup.java

License:Apache License

@Override
public void buildOptions(UIDL uidl) {
    /*//from w w  w.ja  v a 2 s .  co  m
     * In order to retain focus, we need to update values rather than
     * recreate panel from scratch (#10451). However, the panel will be
     * rebuilt (losing focus) if number of elements or their order is
     * changed.
     */
    HashMap<String, CheckBox> keysToOptions = new HashMap<>();
    for (Map.Entry<CheckBox, String> entry : optionsToKeys.entrySet()) {
        keysToOptions.put(entry.getValue(), entry.getKey());
    }
    ArrayList<Widget> existingwidgets = new ArrayList<>();
    ArrayList<Widget> newwidgets = new ArrayList<>();

    // Get current order of elements
    for (Widget wid : panel) {
        existingwidgets.add(wid);
    }

    optionsEnabled.clear();

    if (isMultiselect()) {
        Roles.getGroupRole().set(getElement());
    } else {
        Roles.getRadiogroupRole().set(getElement());
    }

    for (final Iterator<?> it = uidl.getChildIterator(); it.hasNext();) {
        final UIDL opUidl = (UIDL) it.next();

        String itemHtml = opUidl.getStringAttribute("caption");
        if (!isHtmlContentAllowed()) {
            itemHtml = WidgetUtil.escapeHTML(itemHtml);
        }

        String iconUrl = opUidl.getStringAttribute("icon");
        if (iconUrl != null && iconUrl.length() != 0) {
            Icon icon = client.getIcon(iconUrl);
            itemHtml = icon.getElement().getString() + itemHtml;
        }

        String key = opUidl.getStringAttribute("key");
        CheckBox op = keysToOptions.get(key);

        // Need to recreate object if isMultiselect is changed (#10451)
        // OR if htmlContentAllowed changed due to Safari 5 issue
        if ((op == null) || (isHtmlContentAllowed() != wasHtmlContentAllowed)
                || (isMultiselect() != wasMultiselect)) {
            // Create a new element
            if (isMultiselect()) {
                op = new VCheckBox();
            } else {
                op = new RadioButton(paintableId);
                op.setStyleName("v-radiobutton");
            }
            if (iconUrl != null && iconUrl.length() != 0) {
                WidgetUtil.sinkOnloadForImages(op.getElement());
                op.addHandler(iconLoadHandler, LoadEvent.getType());
            }

            op.addStyleName(CLASSNAME_OPTION);
            op.addClickHandler(this);

            optionsToKeys.put(op, key);
        }

        op.setHTML(itemHtml);
        op.setValue(opUidl.getBooleanAttribute("selected"));
        boolean optionEnabled = !opUidl.getBooleanAttribute(OptionGroupConstants.ATTRIBUTE_OPTION_DISABLED);
        boolean enabled = optionEnabled && !isReadonly() && isEnabled();
        op.setEnabled(enabled);
        optionsEnabled.put(op, optionEnabled);

        setStyleName(op.getElement(), StyleConstants.DISABLED, !(optionEnabled && isEnabled()));

        newwidgets.add(op);
    }

    if (!newwidgets.equals(existingwidgets)) {
        // Rebuild the panel, losing focus
        panel.clear();
        for (Widget wid : newwidgets) {
            panel.add(wid);
        }
    }

    wasHtmlContentAllowed = isHtmlContentAllowed();
    wasMultiselect = isMultiselect();
}

From source file:cz.incad.kramerius.editor.client.view.SaveViewImpl.java

License:Open Source License

private Widget createSaveableCheckBox(T saveable) {
    CheckBox widget = new CheckBox(this.renderer.render(saveable));
    widget.setTitle(this.renderer.renderTitle(saveable));
    widget.setValue(true);
    return widget;
}

From source file:de.metanome.frontend.client.datasources.FileInputEditForm.java

License:Apache License

/**
 * Create the CheckBox that triggers the display/hiding of advanced CSV configuration parameters
 *
 * @return the CheckBox with the mentioned behavior
 *///from  w w w . j  a  v  a  2s. co  m
protected CheckBox createAdvancedCheckbox() {
    CheckBox checkbox = new CheckBox("Use Advanced Configuration");
    checkbox.setValue(false);
    checkbox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            advancedTable.setVisible(advancedCheckbox.getValue());
        }
    });

    return checkbox;
}

From source file:de.swm.commons.mobile.client.widgets.CheckBoxGroup.java

License:Apache License

@Override
public void onClick(ClickEvent e) {
    final EventTarget target = e.getNativeEvent().getEventTarget();
    String targetTagName = ((Element) target.cast()).getTagName().toUpperCase();
    LOGGER.info("onClick target " + targetTagName);
    if (targetTagName.equals("LABEL") || targetTagName.equals("IMG")) {
        return; // if check box label or image is clicked, another (simulated) click event with
                // check box INPUT as target will fire after this one. So this click event
                // must be ignored.
    }/*from  www .j  av a2s  .  c  o m*/
    Element div = Element.as(target);
    while (!div.getNodeName().toUpperCase().equals("SPAN") || div.getParentElement() != this.getElement()) {
        div = div.getParentElement();
        if (div == null) {
            LOGGER.info("CheckBoxGroup onClick: span not found");
            return;
        }
    }
    final int index = DOM.getChildIndex(this.getElement(), (com.google.gwt.user.client.Element) div);
    com.google.gwt.user.client.ui.CheckBox checkbox = (com.google.gwt.user.client.ui.CheckBox) myFlowPanel
            .getWidget(index);
    LOGGER.info("onClick " + checkbox.getValue());
    if (targetTagName.equals("INPUT")) {
        LOGGER.info("onClick value changed");
        checkbox.setValue(checkbox.getValue()); // if target is check box INPUT, check box value is
        // already changed when click event is fired.
        // just need to set its current value back to the check box
        // to update style.
    } else {
        checkbox.setValue(!checkbox.getValue());
    }

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(index, target);
            fireEvent(selectionChangedEvent);
        }
    });
}

From source file:edu.caltech.ipac.firefly.ui.GwtUtil.java

public static CheckBox makeCheckBox(String text, String tip, boolean selected, boolean forceNowrap) {
    CheckBox cb = new CheckBox();
    cb.addStyleName("gwtutil-checkbox");
    cb.setValue(selected);
    cb.setHTML(text);//from  w  w w  .  j a v a2s  .  c  o  m
    cb.setTitle(tip);
    if (forceNowrap) {
        setStyle(cb, "whiteSpace", "nowrap");

    }
    return cb;
}

From source file:edu.caltech.ipac.firefly.ui.input.CheckBoxGroupInputField.java

public CheckBoxGroupInputField(EnumFieldDef fieldDef) {
    _fieldDef = fieldDef;/*from ww w.j a  va2 s .  co m*/

    if (fieldDef.getOrientation().equals(EnumFieldDef.Orientation.Vertical)) {
        _panel = new VerticalPanel();
        _fieldWidgetPanel = new VerticalPanel();
    } else {
        _panel = new HorizontalPanel();
        _fieldWidgetPanel = new HorizontalPanel();
    }
    initWidget(_fieldWidgetPanel);
    _panel.setSpacing(5);
    _panel.setTitle(_fieldDef.getShortDesc());

    //list box setup
    _items = ((EnumFieldDef) _fieldDef).getEnumValues();
    _cbs = new ArrayList<CheckBox>(_items.size());
    CheckBox cb;
    int idx = 0;
    for (EnumFieldDef.Item item : _items) {
        cb = new CheckBox(" " + item.getTitle(), true);
        _cbs.add(cb);
        _panel.add(cb);
        if (item.getName().equals(ALL)) {
            _idxOfAll = idx;
        }
        idx++;
    }

    // add warning area
    _warningArea.setWidth("16px");
    _warningArea.setHeight("16px");
    DOM.setStyleAttribute(_warningArea.getElement(), "padding", "3px");
    ErrorHandler eh = new ErrorHandler();
    _warningArea.addFocusHandler(eh);
    _warningArea.addBlurHandler(eh);
    _warningArea.addMouseDownHandler(eh);
    _warningArea.addMouseOverHandler(eh);
    _warningArea.addMouseOutHandler(eh);
    _fieldWidgetPanel.add(_panel);
    _fieldWidgetPanel.add(_warningArea);
    _fieldWidgetPanel.setCellHorizontalAlignment(_warningArea, HasHorizontalAlignment.ALIGN_CENTER);
    _fieldWidgetPanel.setCellVerticalAlignment(_warningArea, HasVerticalAlignment.ALIGN_MIDDLE);

    // add click listeners
    for (idx = 0; idx < _cbs.size(); idx++) {
        final CheckBox current = _cbs.get(idx);
        final int currentIdx = idx;
        current.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent ev) {
                if ((currentIdx == _idxOfAll) && current.getValue()) {
                    //uncheck all other
                    for (int i = 0; i < _cbs.size(); i++) {
                        if (i != _idxOfAll) {
                            _cbs.get(i).setValue(true);
                        }
                    }
                } else if ((currentIdx == _idxOfAll) && !current.getValue()) {
                    //all is unchecked so uncheck all that were checked
                    for (int i = 0; i < _cbs.size(); i++) {
                        if (i != _idxOfAll) {
                            _cbs.get(i).setValue(false);
                        }
                    }
                } else if (_idxOfAll >= 0) {
                    // uncheck _all_ unless all other checkboxes are checked
                    CheckBox all = null;
                    int nChecked = 0;
                    for (int i = 0; i < _cbs.size(); i++) {
                        if (i == _idxOfAll) {
                            all = _cbs.get(i);
                        } else {
                            if (_cbs.get(i).getValue()) {
                                nChecked++;
                            }
                        }
                    }

                    assert (all != null);
                    // all checkboxes are checked
                    if (nChecked == _cbs.size() - 1) {
                        all.setValue(true);
                        for (int i = 0; i < _cbs.size(); i++) {
                            if (i != _idxOfAll) {
                                _cbs.get(i).setValue(true);
                            }
                        }
                    } else {
                        all.setValue(false);
                    }
                }
                ValueChangeEvent.fire(CheckBoxGroupInputField.this, getValue());
            }
        });

    }
    reset();

    addValueChangeHandler(new ValueChangeHandler<String>() {
        public void onValueChange(ValueChangeEvent valueChangeEvent) {
            if (validate()) {

            }
        }
    });

    // label setup
}

From source file:edu.caltech.ipac.firefly.ui.input.CheckBoxGroupInputField.java

public void setValue(String value) {

    if (!getValue().equals(value)) {
        String[] checked;// w  ww .j a  v  a 2s  .  c o  m
        if (value.equals(NONE)) {
            // uncheck all
            for (CheckBox cb : _cbs) {
                cb.setValue(false);
            }
        } else if (value.contains(ALL)) {
            // check all
            for (CheckBox cb : _cbs) {
                cb.setValue(true);
            }
        } else {
            checked = value.split(MULTI_FIELD_SEPARATOR);
            String name;
            boolean shouldBeSelected;
            int idx = 0;
            for (EnumFieldDef.Item item : _items) {
                name = item.getName();
                shouldBeSelected = false;
                for (String n : checked) {
                    if (n.equals(name)) {
                        shouldBeSelected = true;
                    }
                }
                _cbs.get(idx).setValue(shouldBeSelected);
                idx++;
            }
        }
        ValueChangeEvent.fire(CheckBoxGroupInputField.this, value);
    }
}

From source file:edu.caltech.ipac.firefly.ui.table.TableOptions.java

private ScrollTable makeColsTable(final BasicPagingTable table) {

    final FixedWidthFlexTable header = new FixedWidthFlexTable();
    header.setHTML(0, 0, "Column");
    header.setWidget(0, 1, selectAllCheckBox);
    selectAllCheckBox.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent ev) {
            boolean hasSel = false;
            for (Map.Entry<ColDef, CheckBox> entry : checkBoxes.entrySet()) {
                if (entry.getValue().getValue()) {
                    hasSel = true;//  ww w. ja  v a2s  .  c om
                    break;
                }
            }

            if (selectAllCheckBox.getValue() && !hasSel) {
                for (Map.Entry<ColDef, CheckBox> entry : checkBoxes.entrySet()) {
                    entry.getValue().setValue(true);
                }
            } else {
                for (Map.Entry<ColDef, CheckBox> entry : checkBoxes.entrySet()) {
                    entry.getValue().setValue(false);
                }
                selectAllCheckBox.setValue(false);
            }
            applyChanges();
        }
    });

    //        final SortableGrid.ColumnSorter[] origSorter = new SortableGrid.ColumnSorter[1];
    @SuppressWarnings("deprecation")
    final FixedWidthGrid data = new FixedWidthGrid(0, 2);
    data.unsinkEvents(Event.ONMOUSEOVER);
    data.setSelectionEnabled(false);

    final ScrollTable view = new ScrollTable(data, header, new BasicTable.Images());
    FlexTable.FlexCellFormatter formatter = header.getFlexCellFormatter();
    formatter.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    view.setMaximumColumnWidth(1, 35);
    view.setMinimumColumnWidth(1, 35);
    view.setColumnSortable(1, false);

    final DefaultTableDefinition<TableData.Row> tdef = (DefaultTableDefinition<TableData.Row>) table
            .getTableDefinition();
    int cRowIdx = 0;
    for (int i = 0; i < tdef.getColumnDefinitionCount(); i++) {
        final ColDef col = (ColDef) tdef.getColumnDefinition(i);
        if (!col.isImmutable()) {
            data.insertRow(cRowIdx);
            data.setHTML(cRowIdx, 0, col.getTitle());

            CheckBox cb = new CheckBox();
            cb.setValue(tdef.isColumnVisible(col));
            checkBoxes.put(col, cb);
            data.setWidget(cRowIdx, 1, cb);
            data.getCellFormatter().setAlignment(cRowIdx, 1, HasHorizontalAlignment.ALIGN_CENTER,
                    HasVerticalAlignment.ALIGN_MIDDLE);
            cRowIdx++;

            cb.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    applyChanges();
                }
            });
        }
    }

    return view;
}

From source file:edu.caltech.ipac.firefly.ui.table.TableOptions.java

public void syncOptions() {
    // sync table's column with option's checkboxes
    DefaultTableDefinition<TableData.Row> tdef = (DefaultTableDefinition<TableData.Row>) table.getTable()
            .getTableDefinition();/*from  w  w  w. ja v  a  2s. c  o  m*/
    for (ColDef col : checkBoxes.keySet()) {
        CheckBox cb = checkBoxes.get(col);
        cb.setValue(tdef.isColumnVisible(col));
    }
    pageSize.setValue(String.valueOf(table.getDataModel().getPageSize()));

}