예제 #1
0
  @Override
  public void onModuleLoad() {
    class Handler implements FocusHandler, BlurHandler {

      @Override
      public void onBlur(BlurEvent event) {
        System.out.println("blur");
      }

      @Override
      public void onFocus(FocusEvent event) {
        System.out.println("focus");
      }
    }

    TextField field = new TextField();
    field.setName("thename");
    field.setEmptyText("sdfsdf");
    field.addValidator(new EmptyValidator<String>());

    Handler h = new Handler();
    field.addFocusHandler(h);
    field.addBlurHandler(h);

    NumberField<Double> number = new NumberField<Double>(new DoublePropertyEditor());
    number.setEmptyText("sdfdsfsf");
    h = new Handler();
    number.addFocusHandler(h);
    number.addBlurHandler(h);

    DateField date = new DateField();
    h = new Handler();
    date.addFocusHandler(h);
    date.addBlurHandler(h);
    date.setEmptyText("empty texxxt");
    // field.setFieldLabel("Name");
    // field.markInvalid("error", null);

    TextArea area = new TextArea();
    area.setEmptyText("sdfdsfsdf");

    VerticalPanel vp = new VerticalPanel();
    vp.setSpacing(10);

    vp.add(field);
    vp.add(number);
    vp.add(date);
    vp.add(area);

    RootPanel.get().add(vp);

    date.redraw();
    field.redraw();
    number.redraw();
  }
예제 #2
0
  /** @param supportedValidatorTypes use these to construct content of the combo box */
  AddValidatorDialog(
      Set<ArgumentValidatorType> supportedValidatorTypes, ArgumentValidatorMessages avMessages) {
    this.avMessages = avMessages;

    setHeadingText(avMessages.validatorDialogHeading());
    setAutoHide(false);
    setSize("400", "250");
    // Initialize the ComboBox list store with the given Set<..>
    ListStore<ArgumentValidatorType> validatorTypes = new ListStore<>(new AVTLabelKeyProvider());
    validatorTypes.addAll(supportedValidatorTypes);

    // Initialize the ComboBox
    validatorTypeCB = new ComboBox<>(validatorTypes, new AVTLabelKeyProvider());
    validatorTypeCB.setForceSelection(true);
    validatorTypeCB.setAllowBlank(false);
    validatorTypeCB.setTriggerAction(TriggerAction.ALL);

    // Construct all "provided" fields.
    constructDoubleSpinnerFields();
    constructIntegerSpinnerFields();
    charLimitField = new NumberField<>(new NumberPropertyEditor.IntegerPropertyEditor());
    charLimitField.setAllowBlank(false);
    charLimitField.addValidHandler(this);
    charLimitField.addInvalidHandler(this);

    add(BINDER.createAndBindUi(this));

    // Initialize validatorTypeToCardMap
    validatorTypeToCardMap = Maps.newHashMap();
    validatorTypeToCardMap.put(ArgumentValidatorType.DoubleAbove, dblAboveValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.DoubleBelow, dblBelowValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.DoubleRange, dblRangeValidatorCon);

    validatorTypeToCardMap.put(ArgumentValidatorType.IntAbove, intAboveValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.IntBelow, intBelowValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.IntRange, intRangeValidatorCon);

    validatorTypeToCardMap.put(ArgumentValidatorType.Regex, regexValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.CharacterLimit, characterLimitValidatorCon);

    // Set default values.
    ArgumentValidatorType next = supportedValidatorTypes.iterator().next();
    validatorTypeCB.setValue(next, true);
    cardLC.setActiveWidget(validatorTypeToCardMap.get(next));
  }
예제 #3
0
  /** This method should be called when after okButton is clicked. */
  ArgumentValidator getArgumentValidator() {
    Splittable params = StringQuoter.createIndexed();

    switch (validatorTypeCB.getCurrentValue()) {
      case Regex:
        String regex = regexField.getCurrentValue();
        StringQuoter.create(regex).assign(params, 0);
        break;
      case CharacterLimit:
        int charLimit = charLimitField.getCurrentValue();
        StringQuoter.create(charLimit).assign(params, 0);
        break;

      case IntAbove:
        int intAbove = intAboveField.getCurrentValue();
        StringQuoter.create(intAbove).assign(params, 0);
        break;

      case IntBelow:
        int intBelow = intBelowField.getCurrentValue();
        StringQuoter.create(intBelow).assign(params, 0);
        break;
      case IntRange:
        int intRangeAbove = intRangeAboveField.getCurrentValue();
        int intRangeBelow = intRangeBelowField.getCurrentValue();
        StringQuoter.create(intRangeAbove).assign(params, 0);
        StringQuoter.create(intRangeBelow).assign(params, 1);
        break;

      case DoubleAbove:
        double dblAbove = dblAboveField.getCurrentValue();
        StringQuoter.create(dblAbove).assign(params, 0);
        break;
      case DoubleBelow:
        double dblBelow = dblBelowField.getCurrentValue();
        StringQuoter.create(dblBelow).assign(params, 0);
        break;

      case DoubleRange:
        double dblRangeAbove = dblRangeAboveField.getCurrentValue();
        double dblRangeBelow = dblRangeBelowField.getCurrentValue();
        StringQuoter.create(dblRangeAbove).assign(params, 0);
        StringQuoter.create(dblRangeBelow).assign(params, 1);
        break;
      default:
        break;
    }
    AutoBean<ArgumentValidator> avAutobean = factory.argumentValidator();
    avAutobean.as().setType(validatorTypeCB.getCurrentValue());
    avAutobean.as().setParams(params);

    // JDS Get the actual validator, and add it as metadata to the autobean.
    AbstractArgumentEditor.createAndAttachValidator(avAutobean.as());

    return avAutobean.as();
  }
예제 #4
0
  /** This method is used to update this widget to reflect the given argument validator */
  void setArgumentValidator(final ArgumentValidator av) {
    // Set the comboBox item and corresponding card.
    validatorTypeCB.setValue(av.getType(), true);
    cardLC.setActiveWidget(validatorTypeToCardMap.get(av.getType()));
    Splittable params = av.getParams();
    switch (av.getType()) {
      case Regex:
        String regex = params.get(0).asString();
        regexField.setValue(regex);
        break;
      case CharacterLimit:
        int charLimit = Double.valueOf(params.get(0).asNumber()).intValue();
        charLimitField.setValue(charLimit);
        break;

      case IntAbove:
        int intAbove = Double.valueOf(params.get(0).asNumber()).intValue();
        intAboveField.setValue(intAbove);
        break;

      case IntBelow:
        int intBelow = Double.valueOf(params.get(0).asNumber()).intValue();
        intBelowField.setValue(intBelow);
        break;
      case IntRange:
        int intRangeAbove = Double.valueOf(params.get(0).asNumber()).intValue();
        int intRangeBelow = Double.valueOf(params.get(1).asNumber()).intValue();
        intRangeAboveField.setValue(intRangeAbove);
        intRangeBelowField.setValue(intRangeBelow);
        break;

      case DoubleAbove:
        double dblAbove = params.get(0).asNumber();
        dblAboveField.setValue(dblAbove);
        break;
      case DoubleBelow:
        double dblBelow = params.get(0).asNumber();
        dblBelowField.setValue(dblBelow);
        break;

      case DoubleRange:
        double dblRangeAbove = params.get(0).asNumber();
        double dblRangeBelow = params.get(1).asNumber();
        dblRangeAboveField.setValue(dblRangeAbove);
        dblRangeBelowField.setValue(dblRangeBelow);
        break;

      default:
        break;
    }
  }