コード例 #1
0
 @Override
 public void onBrowserEvent(
     Context context,
     Element parent,
     String value,
     NativeEvent event,
     ValueUpdater<String> valueUpdater) {
   Object key = context.getKey();
   ViewData viewData = getViewData(key);
   if (viewData != null && viewData.isEditing()) {
     // Handle the edit event.
     editEvent(context, parent, value, viewData, event, valueUpdater);
   } else {
     String type = event.getType();
     int keyCode = event.getKeyCode();
     boolean enterPressed = KEYUP.equals(type) && keyCode == KeyCodes.KEY_ENTER;
     if (CLICK.equals(type) || enterPressed) {
       // Go into edit mode.
       if (viewData == null) {
         viewData = new ViewData(value);
         setViewData(key, viewData);
       } else {
         viewData.setEditing(true);
       }
       edit(context, parent, value);
     }
   }
 }
コード例 #2
0
  @Override
  public void render(Context context, String value, SafeHtmlBuilder sb) {
    // Get the view data.
    Object key = context.getKey();
    ViewData viewData = getViewData(key);
    if (viewData != null
        && !viewData.isEditing()
        && value != null
        && value.equals(viewData.getText())) {
      clearViewData(key);
      viewData = null;
    }

    String toRender = value;
    if (viewData != null) {
      String text = viewData.getText();
      if (viewData.isEditing()) {
        /*
         * Do not use the renderer in edit mode because the value of a text
         * input element is always treated as text. SafeHtml isn't valid in the
         * context of the value attribute.
         */
        sb.append(template.input(text));
        return;
      } else {
        // The user pressed enter, but view data still exists.
        toRender = text;
      }
    }

    if (toRender != null && toRender.trim().length() > 0) {
      sb.append(renderer.render(toRender));
    } else {
      /*
       * Render a blank space to force the rendered element to have a height.
       * Otherwise it is not clickable.
       */
      sb.appendHtmlConstant("\u00A0");
    }
  }
コード例 #3
0
 @Override
 public boolean isEditing(Context context, Element parent, String value) {
   ViewData viewData = getViewData(context.getKey());
   return viewData == null ? false : viewData.isEditing();
 }