Search in sources :

Example 1 with InputElement

use of org.gwtproject.dom.client.InputElement in project gwtproject by treblereel.

the class CheckboxCell method onBrowserEvent.

@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().cast();
        Boolean isChecked = input.isChecked();
        /*
       * 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);
        }
    }
}
Also used : InputElement(org.gwtproject.dom.client.InputElement)

Example 2 with InputElement

use of org.gwtproject.dom.client.InputElement in project gwtproject by treblereel.

the class EditTextCellTest method testEdit.

public void testEdit() {
    EditTextCell cell = createCell();
    Element parent = Document.get().createDivElement();
    parent.setInnerHTML("<input type='text' value='editing'></input>");
    ViewData viewData = new ViewData("originalValue");
    viewData.setText("newValue");
    cell.setViewData(DEFAULT_KEY, viewData);
    Context context = new Context(0, 0, DEFAULT_KEY);
    cell.edit(context, parent, "originalValue");
    // Verify the input element.
    Element child = parent.getFirstChildElement();
    assertTrue(InputElement.is(child));
    InputElement input = child.cast();
    assertEquals("newValue", input.getValue());
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) ViewData(org.gwtproject.cell.client.EditTextCell.ViewData) InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element) InputElement(org.gwtproject.dom.client.InputElement)

Example 3 with InputElement

use of org.gwtproject.dom.client.InputElement in project gwtproject by treblereel.

the class CheckBoxTest method testFormValue.

public void testFormValue() {
    InputElement elm = Document.get().createCheckInputElement();
    Element asOldElement = elm.cast();
    cb.replaceInputElement(asOldElement);
    // assertEquals("", elm.getValue());
    cb.setFormValue("valuable");
    assertEquals("valuable", elm.getValue());
    elm.setValue("invaluable");
    assertEquals("invaluable", cb.getFormValue());
}
Also used : InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element) InputElement(org.gwtproject.dom.client.InputElement)

Example 4 with InputElement

use of org.gwtproject.dom.client.InputElement in project gwtproject by treblereel.

the class TextInputCell method onBrowserEvent.

@Override
public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, org.gwtproject.cell.client.ValueUpdater<String> valueUpdater) {
    super.onBrowserEvent(context, parent, value, event, valueUpdater);
    // Ignore events that don't target the input.
    InputElement input = getInputElement(parent);
    Element target = event.getEventTarget().cast();
    if (!input.isOrHasChild(target)) {
        return;
    }
    String eventType = event.getType();
    Object key = context.getKey();
    if (BrowserEvents.CHANGE.equals(eventType)) {
        finishEditing(parent, value, key, valueUpdater);
    } else if (BrowserEvents.KEYUP.equals(eventType)) {
        // Record keys as they are typed.
        ViewData vd = getViewData(key);
        if (vd == null) {
            vd = new ViewData(value);
            setViewData(key, vd);
        }
        vd.setCurrentValue(input.getValue());
    }
}
Also used : InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element) InputElement(org.gwtproject.dom.client.InputElement)

Example 5 with InputElement

use of org.gwtproject.dom.client.InputElement in project gwtproject by treblereel.

the class CheckBox method replaceInputElement.

/**
 * Replace the current input element with a new one. Preserves all state except for the name
 * property, for nasty reasons related to radio button grouping. (See implementation of {@link
 * RadioButton#setName}.)
 *
 * @param elem the new input element
 */
protected void replaceInputElement(Element elem) {
    InputElement newInputElem = InputElement.as(elem);
    // Collect information we need to set
    int tabIndex = getTabIndex();
    boolean checked = getValue();
    boolean enabled = isEnabled();
    String formValue = getFormValue();
    String uid = inputElem.getId();
    String accessKey = inputElem.getAccessKey();
    int sunkEvents = Event.getEventsSunk(inputElem);
    // Clear out the old input element
    DOM.setEventListener(inputElem, null);
    getElement().replaceChild(newInputElem, inputElem);
    // Sink events on the new element
    Event.sinkEvents(elem, Event.getEventsSunk(inputElem));
    Event.sinkEvents(inputElem, 0);
    inputElem = newInputElem;
    // Setup the new element
    Event.sinkEvents(inputElem, sunkEvents);
    inputElem.setId(uid);
    if (!"".equals(accessKey)) {
        inputElem.setAccessKey(accessKey);
    }
    setTabIndex(tabIndex);
    setValue(checked);
    setEnabled(enabled);
    setFormValue(formValue);
    // Set the event listener
    if (isAttached()) {
        DOM.setEventListener(inputElem, this);
    }
}
Also used : InputElement(org.gwtproject.dom.client.InputElement)

Aggregations

InputElement (org.gwtproject.dom.client.InputElement)13 Element (org.gwtproject.dom.client.Element)6 ViewData (org.gwtproject.cell.client.EditTextCell.ViewData)2 HTMLIFrameElement (elemental2.dom.HTMLIFrameElement)1 Context (org.gwtproject.cell.client.Cell.Context)1 NativeEvent (org.gwtproject.dom.client.NativeEvent)1 SubmitEvent (org.gwtproject.user.client.ui.FormPanel.SubmitEvent)1 SubmitHandler (org.gwtproject.user.client.ui.FormPanel.SubmitHandler)1