Exemplo n.º 1
0
  @Override
  public void render(Context context, SafeHtml value, SafeHtmlBuilder sb) {

    ObjectProperty property = (ObjectProperty) context.getKey();
    if (navigable && property != null && !property.isBaseType()) {
      SafeHtml startAnchor = null;
      SafeHtml endAnchor = null;
      startAnchor =
          new SafeHtml() {
            @Override
            public String asString() {
              return "<div style=\"cursor: pointer;\">";
            }
          };

      endAnchor =
          new SafeHtml() {
            @Override
            public String asString() {
              return "</div>";
            }
          };

      sb.append(startAnchor);
      sb.append(value);
      sb.append(endAnchor);

    } else {
      super.render(context, value, sb);
    }
  }
Exemplo n.º 2
0
 @Override
 public void onBrowserEvent(
     Context context,
     Element parent,
     String value,
     NativeEvent event,
     ValueUpdater<String> valueUpdater) {
   super.onBrowserEvent(context, parent, value, event, valueUpdater);
   String type = event.getType();
   if ("change".equals(type)) {
     HasOptions key = (HasOptions) context.getKey();
     SelectElement select = parent.getFirstChild().cast();
     String newValue = null;
     if (key.hasOptions()) {
       List<String> options = key.getOptions();
       int optionsPreambleSize =
           key.getOptionsPreamble() == null ? 0 : key.getOptionsPreamble().size();
       int selectedOptionIndex = select.getSelectedIndex() - optionsPreambleSize;
       if (selectedOptionIndex >= 0) newValue = options.get(selectedOptionIndex);
     } else newValue = key.getNoOptionsString();
     setViewData(key, newValue);
     finishEditing(parent, newValue, key, valueUpdater);
     if (valueUpdater != null) {
       valueUpdater.update(newValue);
     }
   }
 }
Exemplo n.º 3
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);
     }
   }
 }
Exemplo n.º 4
0
  @Override
  public void onBrowserEvent(
      Context context,
      Element parent,
      String value,
      NativeEvent event,
      ValueUpdater<String> stringValueUpdater) {

    ObjectProperty property = (ObjectProperty) context.getKey();
    if (DOM.eventGetType((Event) event) == Event.ONCLICK && !property.isBaseType()) {
      editor.onTypeCellSelection(property);
    } else {
      super.onBrowserEvent(context, parent, value, event, stringValueUpdater);
    }
  }
Exemplo n.º 5
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);
       }
     }
   }
 }
 @Override
 public void onBrowserEvent(
     final Context context,
     final Element parent,
     final String value,
     final NativeEvent event,
     final ValueUpdater<String> valueUpdater) {
   super.onBrowserEvent(context, parent, value, event, valueUpdater);
   final String type = event.getType();
   if ("change".equals(type)) {
     final Object key = context.getKey();
     final SelectElement select = parent.getFirstChild().cast();
     final String newValue = options.get(select.getSelectedIndex());
     setViewData(key, newValue);
     finishEditing(parent, newValue, key, valueUpdater);
     if (valueUpdater != null) {
       valueUpdater.update(newValue);
     }
   }
 }
 @Override
 public void render(Context context, String value, SafeHtmlBuilder sb) {
   // Get the view data.
   Object key = context.getKey();
   String viewData = getViewData(key);
   if (viewData != null && viewData.equals(value)) {
     clearViewData(key);
     viewData = null;
   }
   int selectedIndex = getSelectedIndex(viewData == null ? value : viewData);
   sb.appendHtmlConstant("<select tabindex=\"-1\">");
   int index = 0;
   for (String option : options) {
     if (index++ == selectedIndex) {
       sb.append(template.selected(option));
     } else {
       sb.append(template.deselected(option));
     }
   }
   sb.appendHtmlConstant("</select>");
 }
Exemplo n.º 8
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");
    }
  }
Exemplo n.º 9
0
  @Override
  public void render(Context context, String value, SafeHtmlBuilder sb) {
    // Get the view data.
    HasOptions key = (HasOptions) context.getKey();
    String viewData = getViewData(key);
    if (viewData != null && viewData.equals(value)) {
      clearViewData(key);
      viewData = null;
    }

    if (key.hasOptions()) {
      if (cellWidth != null)
        sb.appendHtmlConstant("<select tabindex=\"-1\" style=\"width: " + cellWidth + "\">");
      else sb.appendHtmlConstant("<select tabindex=\"-1\">");

      int selectedOptionIndex = getSelectedOptionIndex(key, viewData == null ? value : viewData);

      int index = 0;

      // append options preamble
      List<String> optionsPreamble = key.getOptionsPreamble();
      if (optionsPreamble != null) {
        for (String option : optionsPreamble) sb.append(template.deselected(option));
      }

      // append the rest of the options
      for (String option : key.getOptions()) {
        if (index++ == selectedOptionIndex) {
          sb.append(template.selected(option));
        } else {
          sb.append(template.deselected(option));
        }
      }
      sb.appendHtmlConstant("</select>");
    } else sb.appendHtmlConstant("<div>" + key.getNoOptionsString() + "</div>");
  }
Exemplo n.º 10
0
 @Override
 public boolean isEditing(Context context, Element parent, String value) {
   ViewData viewData = getViewData(context.getKey());
   return viewData == null ? false : viewData.isEditing();
 }