Example usage for com.google.gwt.dom.client InputElement setChecked

List of usage examples for com.google.gwt.dom.client InputElement setChecked

Introduction

In this page you can find the example usage for com.google.gwt.dom.client InputElement setChecked.

Prototype

public void setChecked(boolean checked) 

Source Link

Document

When the type attribute of the element has the value "radio" or "checkbox", this represents the current state of the form control, in an interactive user agent.

Usage

From source file:com.agnie.gwt.common.client.rpc.MultiSelectEventTranslator.java

License:Open Source License

@Override
public SelectAction translateSelectionEvent(CellPreviewEvent<T> event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    if ("click".equals(nativeEvent.getType())) {

        // Determine if we clicked on a checkbox.
        Element target = nativeEvent.getEventTarget().cast();
        if ("input".equals(target.getTagName().toLowerCase())) {
            final InputElement input = target.cast();
            if ("checkbox".equals(input.getType().toLowerCase())) {
                // Synchronize the checkbox with the current selection state.
                input.setChecked(event.getDisplay().getSelectionModel().isSelected(event.getValue()));
                return SelectAction.TOGGLE;
            }//from   www  . ja v a2  s.c  o  m
        } else if (cmd != null) {
            cmd.setSelected(event.getValue());
            Scheduler.get().scheduleDeferred(cmd);
        }
    }
    return SelectAction.IGNORE;
}

From source file:com.ephesoft.gxt.admin.client.view.fuzzymapping.FuzzyDBMappingGridView.java

License:Open Source License

public void actionForColumnCells() {
    CheckBoxCell multilineAnchorCell = new CheckBoxCell() {

        @Override//from w w  w .j ava  2s  . c  om
        public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event,
                ValueUpdater<Boolean> valueUpdater) {

            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            final InputElement input = getInputElement(parent);
            if (null != event.getType() && "click".equals(event.getType())) {
                FuzzyDBMappingDTO currentSelectedModel = indexFieldMappingGrid.getCurrentSelectedModel();
                if (indexFieldMappingGrid.isGridValidated()) {
                    presenter.setSaveModelInDTO(currentSelectedModel);
                    presenter.getController().getSelectedBatchClass().setDirty(true);
                    currentSelectedModel.setNew(true);
                }
                presenter.getController().getSelectedBatchClass().setDirty(true);
                if (!presenter.validateSearchableRows()) {
                    input.setChecked(true);
                    if (null != currentSelectedModel) {
                        currentSelectedModel.setSearchable(true);
                        indexFieldMappingGrid.reLoad();
                    }
                }
            } else {
                super.onBrowserEvent(context, parent, value, event, valueUpdater);
            }
        }
    };
    indexFieldMappingGrid.setCell(FuzzyDBMappingProperties.INSTANCE.searchable(), multilineAnchorCell);
}

From source file:com.extjs.gxt.ui.client.widget.CheckBoxListView.java

License:sencha.com license

/**
 * Selects a specific item in the view/*from w ww.j a v a  2  s .  c  om*/
 * 
 * @param m the modeldata that should be checked
 * @param checked true to check
 */
public void setChecked(M m, boolean checked) {
    if (rendered) {
        NodeList<Element> nodes = el().select(checkBoxSelector);
        int index = store.indexOf(m);
        if (index != -1) {
            Element e = nodes.getItem(index);
            if (InputElement.is(e)) {
                InputElement i = InputElement.as(e);
                i.setChecked(checked);
            }
        }
    } else {
        if (checkedPreRender == null) {
            checkedPreRender = new ArrayList<M>();
        }
        if (checked) {
            if (!checkedPreRender.contains(m)) {
                checkedPreRender.add(m);
            }
        } else {
            checkedPreRender.remove(m);
        }
    }
}

From source file:com.geocento.webapps.eobroker.customer.client.widgets.MaterialCheckBoxCell.java

License:Apache License

@Override
public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event,
        ValueUpdater<Boolean> valueUpdater) {
    String type = event.getType();

    boolean enterPressed = (BrowserEvents.KEYDOWN.equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER);

    if (BrowserEvents.CHANGE.equals(type) || enterPressed) {
        InputElement input = parent.getFirstChild().getFirstChild().cast();
        Boolean isChecked = input.isChecked();

        /*/*from  w  w w . j  a  v a2 s  .  com*/
         * Toggle the value if the enter key was pressed and the cell handles selection or doesn't depend on selection. If the cell depends on selection but doesn't handle selection, then ignore
         * the enter key and let the SelectionEventManager determine which keys will trigger a change.
         */
        if (enterPressed && (handlesSelection() || !dependsOnSelection())) {
            isChecked = !isChecked;
            input.setChecked(isChecked);
        }

        /*
         * Save the new value. However, if the cell depends on the selection, then do not save the value because we can get into an inconsistent state.
         */
        if (value != isChecked && !dependsOnSelection()) {
            setViewData(context.getKey(), isChecked);
        } else {
            clearViewData(context.getKey());
        }

        if (valueUpdater != null) {
            valueUpdater.update(isChecked);
        }
    }
}

From source file:com.sencha.gxt.cell.core.client.form.CheckBoxCell.java

License:sencha.com license

private void updateCheckBoxValue(Element parent, NativeEvent event, Boolean value,
        ValueUpdater<Boolean> valueUpdater) {
    // if disabled, return immediately
    if (isDisabled()) {
        event.preventDefault();/*from   w  w w.j av a2  s . c  o  m*/
        event.stopPropagation();
        return;
    }

    String eventType = event.getType();

    // on macs and chrome windows, the checkboxes blur on click which causes issues with inline editing as edit
    // is cancelled
    if ((GXT.isChrome() || GXT.isMac()) && "mousedown".equals(eventType)) {
        ignoreNextBlur = true;
    }

    final Element target = event.getEventTarget().cast();
    final InputElement input = getInputElement(parent);
    Boolean checked = input.isChecked();

    boolean label = "LABEL".equals(target.getTagName());
    boolean enterPressed = "keydown".equals(eventType) && event.getKeyCode() == KeyCodes.KEY_ENTER;

    // TODO this should be changed to remove reference to known subclass
    boolean radio = this instanceof RadioCell;

    if (label || enterPressed) {
        event.preventDefault();

        if (checked && radio) {
            return;
        }

        // input will NOT have been updated for label clicks
        checked = !checked;
        input.setChecked(checked);

    } else if (radio && value) {
        // no action required if value is already true and this is a radio
        return;
    }

    if (valueUpdater != null && checked != value) {
        valueUpdater.update(checked);
    }

    if (ignoreNextBlur) {
        ignoreNextBlur = false;
        input.focus();
    }
}

From source file:de.gsv.idm.client.view.widgets.form.InstanceCheckBoxCell.java

License:sencha.com license

@Override
public void onBrowserEvent(Context context, Element parent, T value, NativeEvent event,
        ValueUpdater<T> valueUpdater) {
    Element target = event.getEventTarget().cast();
    if (!parent.isOrHasChild(target)) {
        return;/* w  ww  . j a v  a  2 s  . c  o  m*/
    }
    super.onBrowserEvent(context, parent, value, event, valueUpdater);

    String type = event.getType();

    if ("click".equals(type) && isReadOnly()) {
        event.preventDefault();
        event.stopPropagation();
        return;
    }

    boolean enterPressed = "keydown".equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER;

    if ("click".equals(type) || enterPressed) {
        event.stopPropagation();

        InputElement input = getInputElement(parent);
        Boolean checked = input.isChecked();

        boolean label = "LABEL".equals(target.getTagName());

        if (label || enterPressed) {
            event.preventDefault();

            // input will NOT have been updated for label clicks
            checked = !checked;
            input.setChecked(checked);
        }

        if (valueUpdater != null && checked != getBooleanValue(value)) {
            setBooleanValue(value, checked);
            valueUpdater.update(value);
        }
    }
}

From source file:gwt.material.design.client.base.MaterialCheckBoxCell.java

License:Apache License

@Override
public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event,
        ValueUpdater<Boolean> valueUpdater) {
    String type = event.getType();

    boolean enterPressed = (BrowserEvents.KEYDOWN.equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER)
            || event.getType().equals(BrowserEvents.CLICK);

    if (BrowserEvents.CHANGE.equals(type) || enterPressed) {
        InputElement input = parent.getFirstChild().cast();
        Boolean isChecked = input.isChecked();

        /*//from   w w w  .ja va 2  s .co m
         * Toggle the value if the enter key was pressed and the cell handles selection or doesn't depend on selection. If the cell depends on selection but doesn't handle selection, then ignore
         * the enter key and let the SelectionEventManager determine which keys will trigger a change.
         */
        if (enterPressed && (handlesSelection() || !dependsOnSelection())) {
            isChecked = !isChecked;
            input.setChecked(isChecked);
        }

        /*
         * Save the new value. However, if the cell depends on the selection, then do not save the value because we can get into an inconsistent state.
         */
        if (value != isChecked && !dependsOnSelection()) {
            setViewData(context.getKey(), isChecked);
        } else {
            clearViewData(context.getKey());
        }

        if (valueUpdater != null) {
            valueUpdater.update(isChecked);
        }
    }
}

From source file:jetbrains.jetpad.mapper.gwt.DomUtil.java

License:Apache License

public static Property<Boolean> checkbox(final InputElement element) {
    return new Property<Boolean>() {
        private Registration myTimerRegistration;
        private Listeners<EventHandler<? super PropertyChangeEvent<Boolean>>> myListeners = new Listeners<>();

        @Override//from w  w  w. ja  v a  2s.c om
        public Boolean get() {
            return element.isChecked();
        }

        @Override
        public void set(Boolean value) {
            element.setChecked(value);
        }

        @Override
        public Registration addHandler(final EventHandler<? super PropertyChangeEvent<Boolean>> handler) {
            if (myListeners.isEmpty()) {
                final Value<Boolean> value = new Value<>(element.isChecked());
                final Timer timer = new Timer() {
                    @Override
                    public void run() {
                        final boolean currentValue = element.isChecked();
                        if (currentValue != value.get()) {
                            myListeners.fire(
                                    new ListenerCaller<EventHandler<? super PropertyChangeEvent<Boolean>>>() {
                                        @Override
                                        public void call(EventHandler<? super PropertyChangeEvent<Boolean>> l) {
                                            l.onEvent(new PropertyChangeEvent<>(value.get(), currentValue));
                                        }
                                    });
                            value.set(currentValue);
                        }
                    }
                };
                timer.scheduleRepeating(100);
                myTimerRegistration = new Registration() {
                    @Override
                    protected void doRemove() {
                        timer.cancel();
                    }
                };
            }
            final Registration reg = myListeners.add(handler);
            return new Registration() {
                @Override
                protected void doRemove() {
                    reg.remove();
                    if (myListeners.isEmpty()) {
                        myTimerRegistration.remove();
                        myTimerRegistration = null;
                    }
                }
            };
        }

        @Override
        public String getPropExpr() {
            return "checkbox(" + element + ")";
        }
    };
}

From source file:org.drools.guvnor.client.widgets.decoratedgrid.CheckboxCellImpl.java

License:Apache License

@Override
public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event,
        ValueUpdater<Boolean> valueUpdater) {
    String type = event.getType();

    boolean enterPressed = "keydown".equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER;
    if ("change".equals(type) || enterPressed) {
        InputElement input = parent.getFirstChild().cast();
        Boolean isChecked = input.isChecked();

        /*// ww  w  . jav a  2  s  .  c o  m
         * Toggle the value if the enter key was pressed and the cell handles
         * selection or doesn't depend on selection. If the cell depends on
         * selection but doesn't handle selection, then ignore the enter key and
         * let the SelectionEventManager determine which keys will trigger a
         * change.
         */
        if (enterPressed) {
            isChecked = !isChecked;
            input.setChecked(isChecked);
        }

        /*
         * Save the new value. However, if the cell depends on the selection, then
         * do not save the value because we can get into an inconsistent state.
         */
        if (value != isChecked) {
            setViewData(context.getKey(), isChecked);
        }

        if (valueUpdater != null) {
            valueUpdater.update(isChecked);
        }
    }
}

From source file:org.drools.guvnor.client.widgets.decoratedgrid.CheckboxCellImplIE.java

License:Apache License

@Override
public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event,
        ValueUpdater<Boolean> valueUpdater) {
    String type = event.getType();

    boolean enterPressed = "keydown".equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER;
    if ("click".equals(type) || enterPressed) {
        InputElement input = parent.getFirstChild().cast();
        Boolean isChecked = input.isChecked();

        /*/*from  w  w w  . ja v a 2 s. c  o m*/
         * Toggle the value if the enter key was pressed and the cell handles
         * selection or doesn't depend on selection. If the cell depends on
         * selection but doesn't handle selection, then ignore the enter key and
         * let the SelectionEventManager determine which keys will trigger a
         * change.
         */
        if (enterPressed) {
            isChecked = !isChecked;
            input.setChecked(isChecked);
        }

        /*
         * Save the new value. However, if the cell depends on the selection, then
         * do not save the value because we can get into an inconsistent state.
         */
        if (value != isChecked) {
            setViewData(context.getKey(), isChecked);
        }

        if (valueUpdater != null) {
            valueUpdater.update(isChecked);
        }
    }
}