Example #1
0
  /** Initialize and instantiate the delegate editor class. */
  public AttributeEditorInfo init(
      BindableDescriptor bindable,
      AttributeDescriptor descriptor,
      IAttributeEventProvider eventProvider,
      Map<String, Object> defaultValues) {
    final boolean floatingPointType =
        descriptor.type.equals(Double.class) || descriptor.type.equals(Float.class);

    final boolean unbounded;
    final boolean hasNegativeValues;
    if (floatingPointType) {
      final DoubleRange r = NumberUtils.getDoubleRange(descriptor);

      hasNegativeValues = (r == null || r.min() < 0);
      unbounded = (r == null || NumberUtils.isUnbounded(r));
    } else {
      final IntRange r = NumberUtils.getIntRange(descriptor);

      hasNegativeValues = (r == null || r.min() < 0);
      unbounded = (r == null || NumberUtils.isUnbounded(r));
    }

    final IAttributeEditor delegate;
    if (unbounded) {
      /*
       * If the range is unbounded or contains negative values, use unbounded
       * numeric editor (simple text box). Such unconstrained public attributes
       * shouldn't be common anyway.
       */
      if (floatingPointType) {
        delegate = new UnboundedDoubleEditor();
      } else {
        if (!hasNegativeValues) {
          delegate = new IntegerRangeEditor();
        } else {
          delegate = new UnboundedIntegerEditor();
        }
      }
    } else if (hasNegativeValues) {
      /*
       * If the range covers negative values, or if the range is too big to fit in
       * the integer range, use unbounded double editor. TODO: Negative
       * scale/sliders are available in Eclipse 3.4M5:
       * https://bugs.eclipse.org/bugs/show_bug.cgi?id=91317
       */
      if (floatingPointType) {
        delegate = new UnboundedDoubleEditor();
      } else {
        delegate = new UnboundedIntegerEditor();
      }
    } else {
      /*
       * The range exists, is bounded and contains only non-negative values, use
       * slider/scale directly.
       */
      if (floatingPointType) {
        delegate = new DoubleRangeEditor();
      } else {
        delegate = new IntegerRangeEditor();
      }
    }

    this.delegate = delegate;
    return delegate.init(bindable, descriptor, eventProvider, defaultValues);
  }