예제 #1
0
 /**
  * Commit the current value.
  *
  * @param context the context of the cell
  * @param parent the parent Element
  * @param viewData the {@link ViewData} object
  * @param valueUpdater the {@link ValueUpdater}
  */
 private void commit(
     Context context, Element parent, ViewData viewData, ValueUpdater<String> valueUpdater) {
   String value = updateViewData(parent, viewData, false);
   clearInput(getInputElement(parent));
   setValue(context, parent, viewData.getOriginal());
   if (valueUpdater != null) {
     valueUpdater.update(value);
   }
 }
예제 #2
0
 private void editEvent(
     Context context,
     Element parent,
     String value,
     ViewData viewData,
     NativeEvent event,
     ValueUpdater<String> valueUpdater) {
   String type = event.getType();
   boolean keyUp = KEYUP.equals(type);
   boolean keyDown = KEYDOWN.equals(type);
   if (keyUp || keyDown) {
     int keyCode = event.getKeyCode();
     if (keyUp
         && keyCode == KeyCodes.KEY_ENTER
         && (event.getCtrlKey() || event.getAltKey() || event.getShiftKey())) {
       // Commit the change.
       commit(context, parent, viewData, valueUpdater);
     } else if (keyUp && keyCode == KeyCodes.KEY_ESCAPE) {
       // Cancel edit mode.
       String originalText = viewData.getOriginal();
       if (viewData.isEditingAgain()) {
         viewData.setText(originalText);
         viewData.setEditing(false);
       } else {
         setViewData(context.getKey(), null);
       }
       cancel(context, parent, value);
     } else {
       // Update the text in the view data on each key.
       updateViewData(parent, viewData, true);
     }
   } else if (BLUR.equals(type)) {
     // Commit the change. Ensure that we are blurring the input element and
     // not the parent element itself.
     EventTarget eventTarget = event.getEventTarget();
     if (Element.is(eventTarget)) {
       Element target = Element.as(eventTarget);
       if ("input".equals(target.getTagName().toLowerCase())) {
         commit(context, parent, viewData, valueUpdater);
       }
     }
   }
 }