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

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

Introduction

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

Prototype

public boolean isChecked() 

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.ephesoft.gxt.admin.client.view.tablecolumnextraction.ColumnExtractionRuleGridView.java

License:Open Source License

/**
 * Action for column combo./*  w  w w . j  a  v  a 2  s. co  m*/
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void actionForColumnCells() {

    LabelProvider<String> comboLabelProvider = new LabelProvider<String>() {

        @Override
        public String getLabel(String item) {
            return item;
        }
    };

    final SimpleComboBox columnCombo = new SimpleComboBox<String>(comboLabelProvider);
    columnCombo.addTriggerClickHandler(new TriggerClickHandler() {

        @Override
        public void onTriggerClick(TriggerClickEvent event) {
            columnCombo.getStore().clear();
            columnCombo.setUseQueryCache(false);
            columnCombo.redraw();
            presenter.setColumnValues(columnCombo);
            columnCombo.setTriggerAction(TriggerAction.ALL);
        }
    });
    columnCombo.addSelectionHandler(new SelectionHandler<String>() {

        @Override
        public void onSelection(final SelectionEvent<String> event) {
            if (event != null && !StringUtil.isNullOrEmpty(event.getSelectedItem())) {
                presenter.actionOnColumnSelection();
            }

        }
    });
    colExtrGrid.addEditorWidget(ColumnExtractionRuleProperties.getProperties().getExtractedDataColumnName(),
            columnCombo);

    CheckBoxCell multilineAnchorCell = new CheckBoxCell() {

        @Override
        public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event,
                ValueUpdater<Boolean> valueUpdater) {
            final InputElement input = getInputElement(parent);
            Boolean checked = input.isChecked();
            if (null != event.getType() && null != checked
                    && BatchClassManagementConstants.LABEL_EVENT_CLICK.equals(event.getType()) && checked) {
                presenter.actionOnMandatorySelection();
            }
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
        }
    };
    colExtrGrid.setCell(ColumnExtractionRuleProperties.getProperties().getMandatory(), multilineAnchorCell);

    CheckBoxCell requiredCell = new CheckBoxCell() {

        @Override
        public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event,
                ValueUpdater<Boolean> valueUpdater) {
            final InputElement input = getInputElement(parent);
            Boolean checked = input.isChecked();
            if (null != event.getType() && null != checked
                    && BatchClassManagementConstants.LABEL_EVENT_CLICK.equals(event.getType()) && checked) {
                presenter.actionOnRequiredSelection();
            }
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
        }
    };
    colExtrGrid.setCell(ColumnExtractionRuleProperties.getProperties().getRequired(), requiredCell);
}

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

License:sencha.com license

public List<M> getChecked() {
    if (rendered) {
        List<M> l = new ArrayList<M>();
        NodeList<Element> nodes = el().select(checkBoxSelector);
        for (int i = 0; i < nodes.getLength(); i++) {
            if (InputElement.is(nodes.getItem(i))) {
                InputElement e = InputElement.as(nodes.getItem(i));
                if (e.isChecked()) {
                    l.add(getStore().getAt(i));
                }/*from  w w w.  j  a va 2s  . c o m*/
            }
        }
        return l;
    } else {
        return checkedPreRender != null ? new ArrayList<M>(checkedPreRender) : new ArrayList<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  ww.  j  a va2 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 && (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();// w  w  w .ja  v a2s.  c om
        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;//from w  w  w .j a  va  2s . com
    }
    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   www .j  av 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 && (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. j a  v a 2  s  .com*/
        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.datacleaner.monitor.shared.widgets.FormWizardClientController.java

License:Open Source License

@Override
public void requestNextPage(final AsyncCallback<WizardPage> callback) {
    final Map<String, List<String>> formParameters = new HashMap<String, List<String>>();

    final FormElement formElement = FormElement.as(_form);

    final NodeCollection<com.google.gwt.dom.client.Element> inputElements = formElement.getElements();
    for (int i = 0; i < inputElements.getLength(); i++) {
        final Element element = inputElements.getItem(i);

        final String name;
        final String value;
        final boolean included;

        final String tagName = element.getTagName();
        if (tagName.equalsIgnoreCase("input")) {
            InputElement inputElement = InputElement.as(element);
            name = inputElement.getName();
            value = inputElement.getValue();

            String type = inputElement.getType();
            if ("checkbox".equals(type) || "radio".equals(type)) {
                included = inputElement.isChecked();
            } else {
                included = true;//from w w w  .  jav a2  s . co m
            }
        } else {
            // useful for eg. <textarea> and <select> element types
            name = element.getPropertyString("name");
            value = element.getPropertyString("value");
            included = true;
        }

        if (included) {
            List<String> valueList = formParameters.get(name);
            if (valueList == null) {
                valueList = new ArrayList<String>();
                formParameters.put(name, valueList);
            }
            valueList.add(value);
        }
    }

    _service.nextPage(_tenant, _wizardPage.getSessionIdentifier(), formParameters, callback);
}

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();

        /*/*  w  ww.  ja  v  a 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) {
            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();

        /*//ww  w.j a 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);
        }
    }
}