@Override public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); AbstractField<T> def = designContext.getDefaultInstance(this); Attributes attr = design.attributes(); DesignAttributeHandler.writeAttribute("readonly", attr, isReadOnly(), def.isReadOnly(), Boolean.class, designContext); }
/** * Sets the value of this field if it has changed and fires a value change * event. If the value originates from the client and this field is * read-only, does nothing. Invokes {@link #doSetValue(Object) doSetValue} * to actually store the value. * * @param value * the new value to set * @param userOriginated * {@code true} if this event originates from the client, * {@code false} otherwise. * @return <code>true</code> if the value was updated, <code>false</code> * otherwise */ protected boolean setValue(T value, boolean userOriginated) { if (userOriginated && isReadOnly()) { return false; } if (!isDifferentValue(value)) { return false; } T oldValue = this.getValue(); doSetValue(value); if (!userOriginated) { markAsDirty(); } fireEvent(createValueChange(oldValue, userOriginated)); return true; }
/** * Sets the value of a text field which may be set to read-only mode.<p> * * When setting a Vaadin field to read-only, you also can't set its value programmatically anymore. * So we need to temporarily disable read-only mode, set the value, and then switch back to read-only mode. * * @param field the field * @param value the value to set */ public static <T> void setReadonlyValue(AbstractField<T> field, T value) { boolean readonly = field.isReadOnly(); try { field.setReadOnly(false); field.setValue(value); } finally { field.setReadOnly(readonly); } }
private boolean findFieldAndFocus(Component compositionRoot) { if (compositionRoot instanceof AbstractComponentContainer) { AbstractComponentContainer cc = (AbstractComponentContainer) compositionRoot; for (Component component : cc) { if (component instanceof AbstractTextField) { AbstractTextField abstractTextField = (AbstractTextField) component; if (!abstractTextField.isReadOnly()) { abstractTextField.selectAll(); return true; } } if (component instanceof AbstractField) { AbstractField abstractField = (AbstractField) component; if (!abstractField.isReadOnly()) { abstractField.focus(); return true; } } if (component instanceof AbstractComponentContainer) { if (findFieldAndFocus(component)) { return true; } } } } return false; }
if (fieldx.isReadOnly()!=property.isReadOnly()) logger.debug("ReadOnly: {} {}",fieldx.isReadOnly(),property.isReadOnly());
if (abstractField.isReadOnly()!=property.isReadOnly()) logger.debug("ReadOnly: {} {}",abstractField.isReadOnly(),property.isReadOnly());