Exemplo n.º 1
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);
       }
     }
   }
 }
Exemplo n.º 2
0
 public void change(int index, NativeEvent event) {
   change(index, event.getCtrlKey(), event.getShiftKey());
 }