/** * Checks or unchecks the check box, firing {@link ValueChangeEvent} if * appropriate. * <p> * Note that this <em>does not</em> set the value property of the checkbox * input element wrapped by this widget. For access to that property, see * {@link #setFormValue(String)} * * @param value true to check, false to uncheck; null value implies false * @param fireEvents If true, and value has changed, fire a * {@link ValueChangeEvent} */ @Override public void setValue(Boolean value, boolean fireEvents) { if (value == null) { value = Boolean.FALSE; } Boolean oldValue = getValue(); inputElem.setChecked(value); inputElem.setDefaultChecked(value); if (value.equals(oldValue)) { return; } if (fireEvents) { ValueChangeEvent.fire(this, value); } }
/** * Returns the value property of the input element that backs this widget. * This is the value that will be associated with the CheckBox name and * submitted to the server if a {@link FormPanel} that holds it is submitted * and the box is checked. * <p> * Don't confuse this with {@link #getValue}, which returns true or false if * the widget is checked. */ public String getFormValue() { return inputElem.getValue(); }
/** * This constructor may be used by subclasses to explicitly use an existing * element. This element must be an <input> element whose type is * 'radio'. * * @param element the element to be used */ protected SimpleRadioButton(Element element) { super(element, null); assert InputElement.as(element).getType().equalsIgnoreCase("radio"); } }
/** * Check whether or not an element is a checkbox or radio button. * * @param elem the element to check * @return true if a checkbox, false if not */ private static boolean isCheckbox(Element elem) { if (elem == null || !"input".equalsIgnoreCase(elem.getTagName())) { return false; } String inputType = InputElement.as(elem).getType().toLowerCase(Locale.ROOT); return "checkbox".equals(inputType) || "radio".equals(inputType); }
public DateInput() { super(InputElement.as(Document.get().createTextInputElement())); getElement().setAttribute("type", "date"); }
protected CheckBox(Element elem) { super(DOM.createSpan()); inputElem = InputElement.as(elem); labelElem = Document.get().createLabelElement(); getElement().appendChild(inputElem); getElement().appendChild(labelElem); String uid = DOM.createUniqueId(); inputElem.setPropertyString("id", uid); labelElem.setHtmlFor(uid); directionalTextHelper = new DirectionalTextHelper(labelElem, true); // Accessibility: setting tab index to be 0 by default, ensuring element // appears in tab sequence. FocusWidget's setElement method already // calls setTabIndex, which is overridden below. However, at the time // that this call is made, inputElem has not been created. So, we have // to call setTabIndex again, once inputElem has been created. setTabIndex(0); }
private void addHtml5Input() { if (input == null) { input = Document.get().createTextInputElement(); if (min != null) { input.setAttribute("min", min); } if (max != null) { input.setAttribute("max", max); } input.setDisabled(!enabled); getElement().appendChild(input); com.google.gwt.user.client.Element userElement = (com.google.gwt.user.client.Element) Element .as(input); DOM.sinkEvents(userElement, Event.ONCHANGE | Event.ONBLUR); DOM.setEventListener(userElement, elementListener); } }
public SingleValueTagsInput(final Collection<? extends Dataset<T>> datasets) { InputElement tagsInput = Document.get().createTextInputElement(); tagsInput.setAttribute("data-role", "tagsinput"); setElement(tagsInput); setDatasets(datasets); }
protected void copyAttributes(Element src, Element dest) { InputElement source = src.cast(); InputElement destination = dest.cast(); destination.setAccessKey(source.getAccessKey()); destination.setDefaultValue(source.getDefaultValue()); destination.setDisabled(source.isDisabled()); if (source.getMaxLength() > 0) destination.setMaxLength(source.getMaxLength()); destination.setReadOnly(source.isReadOnly()); destination.setSize(source.getSize()); destination.setName(source.getName()); destination.setValue(source.getValue()); }
private void startEditing() { if (myEditing) { throw new IllegalStateException(); } myEditing = true; mySource.setInnerText(""); mySource.appendChild(myEditor); myEditor.setValue(myValue); myEditor.focus(); }
public SelectAction translateSelectionEvent(CellPreviewEvent<T> event) { // Handle the event. NativeEvent nativeEvent = event.getNativeEvent(); if (BrowserEvents.CLICK.equals(nativeEvent.getType())) { // Ignore if the event didn't occur in the correct column. if (column > -1 && column != event.getColumn()) { return SelectAction.IGNORE; } // Determine if we clicked on a checkbox. Element target = nativeEvent.getEventTarget().cast(); if ("input".equals(target.getTagName().toLowerCase(Locale.ROOT))) { final InputElement input = target.cast(); if ("checkbox".equals(input.getType().toLowerCase(Locale.ROOT))) { // Synchronize the checkbox with the current selection state. input.setChecked(event.getDisplay().getSelectionModel().isSelected( event.getValue())); return SelectAction.TOGGLE; } } return SelectAction.IGNORE; } // For keyboard events, do the default action. return SelectAction.DEFAULT; } }
private static InputElement createInputElement(Document doc, String type, String name) { InputElement e = doc.createElement("input").cast(); e.setAttribute("type", type); if (name != null) { e.setAttribute("name", name); } return e; }
@Override public void setAccessKey(final char key) { final Element element = uiObject.getElement(); final String accessKey = Character.toString(key); if (AnchorElement.is(element)) { AnchorElement.as(element).setAccessKey(accessKey); } else if (ButtonElement.is(element)) { ButtonElement.as(element).setAccessKey(accessKey); } else if (InputElement.is(element)) { InputElement.as(element).setAccessKey(accessKey); } }
InputElement newInputElem = InputElement.as(elem); boolean enabled = isEnabled(); String formValue = getFormValue(); String uid = inputElem.getId(); String accessKey = inputElem.getAccessKey(); int sunkEvents = Event.getEventsSunk(inputElem); getElement().replaceChild(newInputElem, inputElem); inputElem.setId(uid); if (!"".equals(accessKey)) { inputElem.setAccessKey(accessKey);
&& event.getKeyCode() == KeyCodes.KEY_ENTER; if (BrowserEvents.CHANGE.equals(type) || enterPressed) { InputElement input = parent.getFirstChild().cast(); Boolean isChecked = input.isChecked(); input.setChecked(isChecked);
@Override public void setRawValue(String value) { boolean b = Boolean.valueOf(value).booleanValue(); ((InputElement) getInputEl().dom.cast()).setChecked(b); }
boolean eventTargetIsCheckBox(DomEvent<?> event) { EventTarget eventTarget = event.getNativeEvent().getEventTarget(); return InputElement.is(eventTarget) && "checkbox".equals(InputElement.as(eventTarget).getAttribute("type")); //$NON-NLS-1$ //$NON-NLS-2$ }