Example #1
0
  @Override
  protected BigDecimal getFieldValue() {
    String text = fNumber.getText();
    if (text == null) {
      return BigDecimal.ZERO;
    }
    text = text.trim();
    if (text.isEmpty()) {
      return BigDecimal.ZERO;
    }

    final Format format = fNumber.getFormat();
    try {
      if (format == null) {
        return new BigDecimal(text);
      } else if (format instanceof DecimalFormat) {
        final DecimalFormat df = (DecimalFormat) format;
        df.setParseBigDecimal(true);
        final BigDecimal bd = (BigDecimal) df.parse(text);
        return bd;
      } else {
        log.info(
            "Invalid Format '{}' to be used to convert text '{}' to BigDecimal. Assuming ZERO.",
            new Object[] {format, text});
        return Env.ZERO;
      }
    } catch (final Exception e) {
      throw new WrongValueException(
          this, "@" + ITerminalField.MSG_ErrorParsingText + "@ " + text, e);
    }
  }
Example #2
0
  @Override
  protected final void setFieldValue(final BigDecimal value, final boolean fireEvent) {
    final BigDecimal valueOld = this._valueOld; // backup for event

    //
    // Fix value to set
    final BigDecimal valueNew;
    if (value == null) {
      valueNew = Env.ZERO;
    } else {
      // Qty Editor it shall be a small component and we don't want to clutter it with pointless
      // trailing zeros (06112)
      valueNew = NumberUtils.stripTrailingDecimalZeros(value);
    }

    //
    // Get the number editor
    final ITerminalTextField fNumber = this.fNumber;
    if (isDisposed() || fNumber == null) {
      // shall not happen but we are throwing an exception because we got a weird case (FRESH-331)
      new TerminalException(
              "Atempt to set value but field is disposed."
                  + "\n field: "
                  + this
                  + "\n value: "
                  + valueOld
                  + "->"
                  + valueNew
                  + "\n fireEvent: "
                  + fireEvent
                  + "\n fNumber: "
                  + fNumber)
          .throwOrLogWarningIfDeveloperMode(log);
      return;
    }

    //
    // Actually setting the new value
    fNumber.setText(valueNew.toString());
    this._valueOld = valueNew;

    //
    // Fire event
    if (fireEvent) {
      final boolean changed = valueOld == null || valueOld.compareTo(valueNew) != 0;
      if (changed) {
        firePropertyChange(ITerminalField.ACTION_ValueChanged, valueOld, valueNew);
      }
    }
  }
Example #3
0
  @Override
  public void setEditable(final boolean editable) {
    this.editable = editable;

    fNumber.setEditable(editable);
    if (withButtons) {
      bMinus.setEnabled(editable);
      bPlus.setEnabled(editable);
    }
  }
Example #4
0
  @Override
  public void dispose() {
    super.dispose();

    if (bMinus != null) {
      bMinus.dispose();
      bMinus = null;
    }
    if (bPlus != null) {
      bPlus.dispose();
      bPlus = null;
    }
    if (fNumber != null) {
      fNumber.removeListener(numberChangeListener);
      fNumber.dispose();
      fNumber = null;
    }
    if (panel != null) {
      panel.dispose();
      panel = null;
    }
  }
Example #5
0
  private void initComponents() {
    final ITerminalFactory factory = getTerminalFactory();

    fNumber = factory.createTerminalTextField(getName(), getDisplayType(), getFontSize());
    fNumber.addListener(numberChangeListener);

    final String panelColumnConstraints;
    if (withButtons) {
      bMinus = factory.createButtonAction(ITerminalNumericField.ACTION_Minus);
      bMinus.addListener(new MinusButtonAction());
      bPlus = factory.createButtonAction(ITerminalNumericField.ACTION_Plus);
      bPlus.addListener(new PlusButtonAction());

      panelColumnConstraints = "[][][]"; // 3 Columns: Minus button, Qty numeric field, Plus button

    } else {
      panelColumnConstraints = ""; // nothing, we have only the Qty numberic field
    }

    final String panelRowConstraints;
    if (withLabel) {
      panelRowConstraints =
          "[]" // Label row
              + "0" // gap between rows
              + "[shrink 0]"; // Qty field row
    } else {
      panelRowConstraints = "[shrink 0]"; // Qty field row only
    }

    final String panelLayoutConstraints = "insets 0";
    panel =
        factory.createContainer(
            panelLayoutConstraints, // Layout Constraints
            panelColumnConstraints, // Column constraints
            panelRowConstraints // Row constrants
            );
  }
Example #6
0
 @Override
 public void setNumberRO(final boolean ro) {
   fNumber.setEditable(!ro);
 }
Example #7
0
 @Override
 public void requestFocus() {
   fNumber.requestFocus();
 }