final E textComponent = createTextComponent(); textComponent.setRequired(required); textComponent.setImmediate(immediate); textComponent.setReadOnly(readOnly); textComponent.setEnabled(enabled); textComponent.setCaption(caption); textComponent.setStyleName(style); textComponent.addStyleName(styleName); textComponent.setInputPrompt(prompt); textComponent.setMaxLength(maxLengthAllowed); textComponent.setId(id); textComponent.setNullRepresentation("");
/** * Lets the ShortcutListener handle the action while the TextField has focus. * @param textField * @param shortcutListener */ public static void handleShortcut(AbstractTextField textField, ShortcutListener shortcutListener) { textField.addFocusListener((FieldEvents.FocusEvent event) -> textField.addShortcutListener(shortcutListener)); textField.addBlurListener((FieldEvents.BlurEvent event) -> textField.removeShortcutListener(shortcutListener)); }
/** * Sets the placeholder text for the field. * * @see AbstractTextField#setPlaceholder(java.lang.String) * @param placeholder the placeholder text to be used * @return this for method chaining */ public default S withPlaceholder(String placeholder) { ((AbstractTextField) this).setPlaceholder(placeholder); return (S) this; }
protected void doUpdateDescription(DataConnector data) throws MException { if (field instanceof AbstractTextField) { String arg = data.getString((String)((AbstractTextField)field).getInputPrompt()); if (equals(arg,((AbstractTextField)field).getInputPrompt())) return; ((AbstractTextField)field).setInputPrompt(arg); } }
private AbstractTextField createInputField(InputWidgetElement iwe) { AbstractTextField field = iwe.getSecret() != null && iwe.getSecret() ? new PasswordField() : new TextField(); if (iwe.getMaxLength() != null) { field.setMaxLength(iwe.getMaxLength()); } if (hasText(iwe.getRegexp()) && hasText(iwe.getRegexp())) { field.addValidator(new RegexpValidator(WidgetDefinitionLoader.replaceXmlEscapeCharacters(iwe.getRegexp()), iwe.getErrorKey() != null ? iwe.getErrorKey() : getMessage("processdata.block.error.regexp").replaceFirst("%s", iwe.getRegexp()))); } if (nvl(iwe.getRequired(), false)) { field.setRequired(true); if (hasText(iwe.getCaption())) { String caption = iwe.getCaption(); if (caption.endsWith(":")) caption = caption.substring(0, caption.length() - 1); field.setRequiredError(getMessage("processdata.block.field-required-error") + " " + caption); } else { field.setRequiredError(getMessage("processdata.block.field-required-error")); } } if (hasText(iwe.getBaseText())) { field.setValue(getMessage(iwe.getBaseText())); } if (hasText(iwe.getPrompt())) { field.setInputPrompt(getMessage(iwe.getPrompt())); } if (iwe.getValue() != null) field.setValue(iwe.getValue()); return field; }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attr = design.attributes(); if (attr.hasKey("maxlength")) { setMaxLength(DesignAttributeHandler.readAttribute("maxlength", attr, Integer.class)); } }
if (pid.equals(TableProperty.KEY)) { tf = new TextField(); tf.addValidator(new KeyValidator()); } else { TextArea atf = new TextArea(); tf = atf; tf.setWidth("100%"); tf.setResponsive(true); tf.setInputPrompt( Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_PLEASE_ADD_VALUE_0)); tf.setData(new ComponentData(i, itemId, "")); if (!m_valueFields.containsKey(Integer.valueOf(i))) { m_valueFields.put(Integer.valueOf(i), new HashMap<Integer, AbstractTextField>()); tf.addFocusListener(new FocusListener() { tf.addBlurListener(new BlurListener() {
@Override public AbstractTextField createFieldComponent() { // Create a TextArea if the rows > 1 AbstractTextField field; if (getDefinition().getRows() > 1) { TextArea textArea = new TextArea(); textArea.setRows(getDefinition().getRows()); field = textArea; } else { field = new TextField(); } if (getDefinition().getMaxLength() != -1) { field.setMaxLength(getDefinition().getMaxLength()); } String placeholder = getDefinition().getPlaceholder(); if (placeholder != null && !isMessageKey(placeholder)) { field.setPlaceholder(placeholder); } return field; } }
@Override public StringInputBuilder inputPrompt(String inputPrompt) { getInstance().setInputPrompt(inputPrompt); return builder(); }
@Override public StringInputBuilder withBlurListener(BlurListener listener) { getInstance().addBlurListener(listener); return builder(); }
@Override public StringInputBuilder withFocusListener(FocusListener listener) { getInstance().addFocusListener(listener); return builder(); }
@Override public Field createField(Item item, Object propertyId, Component uiContext) { Field field = DefaultFieldFactory.get().createField(item, propertyId, uiContext); // Styling if (field instanceof AbstractTextField) { AbstractTextField textField = (AbstractTextField) field; textField.setNullRepresentation(""); } // All fields are required field.setRequired(true); return field; } }
@Override public StringInputBuilder maxLength(int maxLength) { getInstance().setMaxLength(maxLength); return builder(); }
@Override protected void localize(I instance) { super.localize(instance); if (inputPrompt != null) { instance.setInputPrompt(LocalizationContext.translate(inputPrompt, true)); } }
@Override public StringInputBuilder withBlurListener(BlurListener listener) { getInstance().addBlurListener(listener); return builder(); }
@Override public StringInputBuilder withFocusListener(FocusListener listener) { getInstance().addFocusListener(listener); return builder(); }
public Field createField(Property<?> property, Form form) { Field field = createBaseField(property, form); if (property.getType() == Integer.class) { field.addValidator(new IntegerValidator("is.not.an.integer")); } if (field instanceof AbstractField) { AbstractField abstractField = (AbstractField) field; abstractField.setImmediate(true); } if (field instanceof AbstractTextField) { AbstractTextField textField = (AbstractTextField) field; textField.setNullRepresentation(""); } if (field instanceof RichTextArea) { // RichTextArea does not extend AbstractTextField like TextArea or TextField RichTextArea textArea = (RichTextArea) field; textArea.setNullRepresentation(""); } return field; }
final E textComponent = createTextComponent(); textComponent.setRequired(required); textComponent.setImmediate(immediate); textComponent.setReadOnly(readOnly); textComponent.setEnabled(enabled); textComponent.setCaption(caption); textComponent.setStyleName(style); textComponent.addStyleName(styleName); textComponent.setInputPrompt(prompt); textComponent.setMaxLength(maxLengthAllowed); textComponent.setId(id); textComponent.setNullRepresentation("");
@Override public StringInputBuilder maxLength(int maxLength) { getInstance().setMaxLength(maxLength); return builder(); }
@Override protected Component getField() throws MException { if (field == null) { field = createTextField(); field.setWidth("100%"); if (field instanceof AbstractTextField) ((AbstractTextField)field).setInputPrompt(getElement().getDescription()); getElement().fireAllDataSources(); field.addListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 1L; @Override public void valueChange(ValueChangeEvent event) { try { setValueToDataSource(getElement().getDataConnector(DataSource.CONNECTOR_TASK_DATA)); } catch (MException e) { e.printStackTrace(); } } }); prepareInputField(field); } return field; }