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