@Override
 public void updatePropSheet() {
   boolean isMulti = model.isMultilineInput();
   model.setPropertyVisible(TextInputModel.PROP_SHOW_H_SCROLL, isMulti);
   model.setPropertyVisible(TextInputModel.PROP_SHOW_V_SCROLL, isMulti);
   model.setPropertyVisible(TextInputModel.PROP_WRAP_WORDS, isMulti);
   model.setPropertyVisible(TextInputModel.PROP_PASSWORD_INPUT, !isMulti);
 }
 protected void outputText(String newValue) {
   if (editpart.getPV() == null) {
     editpart.setPropertyValue(TextInputModel.PROP_TEXT, newValue);
     editpart.outputPVValue(newValue);
   } else {
     // PV may not be changed instantly, so recover it to old text first.
     text.setText(model.getText());
     // Write PV and update the text with new PV value if writing succeed.
     editpart.outputPVValue(newValue);
   }
 }
  @Override
  public void registerPropertyChangeHandlers() {
    editpart.removeAllPropertyChangeHandlers(TextInputModel.PROP_ALIGN_H);

    PropertyChangeListener updatePropSheetListener =
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            updatePropSheet();
          }
        };

    model
        .getProperty(TextInputModel.PROP_MULTILINE_INPUT)
        .addPropertyChangeListener(updatePropSheetListener);

    IWidgetPropertyChangeHandler handler =
        new IWidgetPropertyChangeHandler() {

          @Override
          public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            AbstractContainerModel parent = model.getParent();
            parent.removeChild(model);
            parent.addChild(model);
            parent.selectWidget(model, true);
            return false;
          }
        };
    editpart.setPropertyChangeHandler(TextInputModel.PROP_SHOW_NATIVE_BORDER, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_MULTILINE_INPUT, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_WRAP_WORDS, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_SHOW_H_SCROLL, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_SHOW_V_SCROLL, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_PASSWORD_INPUT, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_ALIGN_H, handler);
  }
  @Override
  public IFigure doCreateFigure() {

    int style = SWT.NONE;
    if (model.isShowNativeBorder()) style |= SWT.BORDER;
    if (model.isMultilineInput()) {
      style |= SWT.MULTI;
      if (model.isShowHScroll()) style |= SWT.H_SCROLL;
      if (model.isShowVScroll()) style |= SWT.V_SCROLL;
      if (model.isWrapWords()) style |= SWT.WRAP;
    } else {
      style |= SWT.SINGLE;
      if (model.isPasswordInput()) style |= SWT.PASSWORD;
    }
    if (model.isReadOnly()) style |= SWT.READ_ONLY;
    switch (model.getHorizontalAlignment()) {
      case CENTER:
        style |= SWT.CENTER;
        break;
      case LEFT:
        style |= SWT.LEFT;
        break;
      case RIGHT:
        style |= SWT.RIGHT;
      default:
        break;
    }

    final NativeTextFigure figure = new NativeTextFigure(editpart, style);
    text = figure.getSWTWidget();

    if (!model.isReadOnly()) {
      if (model.isMultilineInput()) {
        text.addKeyListener(
            new KeyAdapter() {
              @Override
              public void keyPressed(KeyEvent keyEvent) {
                if (keyEvent.character == '\r') { // Return key
                  if (text != null && !text.isDisposed() && (text.getStyle() & SWT.MULTI) != 0) {
                    if ((keyEvent.stateMask & SWT.CTRL) != 0) {
                      outputText(text.getText());
                      keyEvent.doit = false;
                      text.getShell().setFocus();
                    }
                  }
                }
              }
            });
      } else {
        text.addListener(
            SWT.DefaultSelection,
            new Listener() {
              public void handleEvent(Event e) {
                outputText(text.getText());
                switch (model.getFocusTraverse()) {
                  case LOSE:
                    text.getShell().setFocus();
                    break;
                  case NEXT:
                    SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_PREVIOUS);
                    break;
                  case PREVIOUS:
                    SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_NEXT);
                    break;
                  case KEEP:
                  default:
                    break;
                }
              }
            });
      }
      // Recover text if editing aborted.
      text.addKeyListener(
          new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent keyEvent) {
              if (keyEvent.character == SWT.ESC) {
                text.setText(model.getText());
              }
            }
          });
      text.addFocusListener(
          new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
              // On mobile, lost focus should output text since there is not enter hit or ctrl key.
              if (editpart.getPV() != null && !OPIBuilderPlugin.isMobile(text.getDisplay()))
                text.setText(model.getText());
              else if (figure.isEnabled()) outputText(text.getText());
            }
          });
    }
    return figure;
  }
 public void performAutoSize() {
   model.setSize(((NativeTextFigure) editpart.getFigure()).getAutoSizeDimension());
 }