Ejemplo n.º 1
0
  @Override
  public String getDisplayValue(T value) {
    fSelectedElement = value;

    if (value == null) {
      return "";
    }

    return DTOUtils.getLabelProvider(value).getText(value);
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  public APPEDTOField(
      Composite parent, FormToolkit toolkit, String labelText, Class<T> clazz, int style) {
    super(parent, toolkit, labelText, style);
    fClazz = clazz;
    fDropDownPopup = new ContentTableAssistPopup(fControl, DTOUtils.getQuickSearchModel(clazz));

    addModifyListener(
        new ModifyListener() {

          @Override
          public void modifyText(ModifyEvent e) {
            if (!fUpdatingFromModel) {
              fDropDownPopup.show(false);
              fDropDownPopup.updateFilter(fControl.getText());
            }
          }
        });

    setValidator(
        new iValidator<T>() {

          @Override
          public boolean validate(String input, boolean isNullable) {
            if (fSelectedElement == null && isNullable) {
              return true;
            } else if (fSelectedElement == null) {
              return false;
            } else {
              return true;
            }
          }

          @Override
          public T getValueFor(String value) {
            // Dummy implementation
            return null;
          }
        });

    fControl.addKeyListener(
        new KeyListener() {

          @Override
          public void keyReleased(KeyEvent e) {
            handleKeyRelease(e);
          }

          @Override
          public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN) {
              if (fDropDownPopup.isShown()) {
                fDropDownPopup.focus();
              }
            }
          }
        });

    fControl.addTraverseListener(
        new TraverseListener() {
          @Override
          public void keyTraversed(TraverseEvent e) {
            if (e.character == SWT.TAB) {
              if (fDropDownPopup.isShown()) {
                fDropDownPopup.focus();
              }
            }
          }
        });
  }