/** * Returns this field editor's text control. * * <p>The control is created if it does not yet exist * * @param parent the parent * @return the text control */ public Text getTextControl(Composite parent) { if (textField == null) { textField = new Text(parent, SWT.SINGLE | SWT.BORDER); textField.setEchoChar('*'); textField.setFont(parent.getFont()); switch (validateStrategy) { case VALIDATE_ON_KEY_STROKE: textField.addKeyListener( new KeyAdapter() { /** {@inheritDoc} */ @Override public void keyReleased(KeyEvent e) { valueChanged(); } }); break; case VALIDATE_ON_FOCUS_LOST: textField.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { clearErrorMessage(); } }); textField.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent e) { refreshValidState(); } @Override public void focusLost(FocusEvent e) { valueChanged(); clearErrorMessage(); } }); break; default: Assert.isTrue(false, "Unknown validate strategy"); // $NON-NLS-1$ } textField.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent event) { textField = null; } }); if (textLimit > 0) { // Only set limits above 0 - see SWT spec textField.setTextLimit(textLimit); } } else { checkParent(textField, parent); } return textField; }
/** * Returns this field editor's text control. * * <p>The control is created if it does not yet exist * * @param parent the parent * @return the text control */ public Text getTextControl(Composite parent) { if (textField == null) { // System.out.println("creating..."); textField = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); textField.setFont(parent.getFont()); switch (validateStrategy) { case VALIDATE_ON_KEY_STROKE: textField.addKeyListener( new KeyAdapter() { /* * (non-Javadoc) * * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent) */ public void keyReleased(KeyEvent e) { valueChanged(); } }); break; case VALIDATE_ON_FOCUS_LOST: textField.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { clearErrorMessage(); } }); textField.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent e) { refreshValidState(); } public void focusLost(FocusEvent e) { valueChanged(); clearErrorMessage(); } }); break; default: Assert.isTrue(false, "Unknown validate strategy"); // $NON-NLS-1$ } textField.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent event) { textField = null; } }); if (textLimit > 0) { // Only set limits above 0 - see SWT spec textField.setTextLimit(textLimit); } } else { checkParent(textField, parent); } return textField; }
/** * Set the edit mask string on the edit mask control. * * @param editMask The edit mask string */ public void setMask(String editMask) { editMaskParser = new EditMaskParser(editMask); text.addVerifyListener(verifyListener); text.addFocusListener(focusListener); text.addDisposeListener(disposeListener); updateTextField.run(); oldValidText = text.getText(); oldValidRawText = editMaskParser.getRawResult(); }
/** * Constructor for the previewer. * * @param s * @param parent */ public DefaultPreviewer(String s, Composite parent) { string = s; text = new Text(parent, SWT.READ_ONLY | SWT.BORDER); text.addDisposeListener( e -> { if (font != null) { font.dispose(); } }); if (string != null) { text.setText(string); } }