/** * Sets the component's to read-only mode to the specified state. * * @see Component#setReadOnly(boolean) */ @Override public void setReadOnly(boolean readOnly) { super.setReadOnly(readOnly); for (final Object id : propertyIds) { fields.get(id).setReadOnly(readOnly); } }
@Override public Field<?> createField(Container container, Object itemId, Object propertyId, Component uiContext) { Field<?> field = super.createField(container, itemId, propertyId, uiContext); if (propertyId.equals("Key")) { field.setReadOnly(true); } else { field.setSizeFull(); } return field; } });
/** * Sets the read only state to the given value for all fields with writable * data source. Fields with read only data source will always be set to read * only. * * @param fieldsReadOnly * true to set the fields with writable data source to read only, * false to set them to read write */ public void setReadOnly(boolean fieldsReadOnly) { readOnly = fieldsReadOnly; for (Field<?> field : getFields()) { if (field.getPropertyDataSource() == null || !field.getPropertyDataSource().isReadOnly()) { field.setReadOnly(fieldsReadOnly); } else { field.setReadOnly(true); } } }
/** * Clears field and any possible existing binding. * * @param field * The field to be cleared * @since 7.7.5 */ protected void clearField(Field<?> field) { // Clear any possible existing binding to clear the field field.setPropertyDataSource(null); boolean fieldReadOnly = field.isReadOnly(); if (!fieldReadOnly) { field.clear(); } else { // Temporarily make the field read-write so we can clear the // value. Needed because setPropertyDataSource(null) does not // currently clear the field // (https://dev.vaadin.com/ticket/14733) field.setReadOnly(false); field.clear(); field.setReadOnly(true); } }
/** * Configures a field with the settings set for this FieldBinder. * <p> * By default this updates the buffered, read only and enabled state of the * field. Also adds validators when applicable. Fields with read only data * source are always configured as read only. * * @param field * The field to update */ protected void configureField(Field<?> field) { field.setBuffered(isBuffered()); field.setEnabled(isEnabled()); if (field.getPropertyDataSource().isReadOnly()) { field.setReadOnly(true); } else { field.setReadOnly(isReadOnly()); } }
/** * Configures a field with the settings set for this FieldBinder. * <p> * By default this updates the buffered, read only and enabled state of the * field. Also adds validators when applicable. Fields with read only data * source are always configured as read only. * <p> * Unlike the default implementation in FieldGroup, MBeanFieldGroup only * makes field read only based on the property's hint, not the opposite. * This way developer can in form code choose to make some fields read only. * * @param field The field to update */ @Override protected void configureField(Field<?> field) { boolean readOnlyStatus = isReadOnly() || field.getPropertyDataSource().isReadOnly(); super.configureField(field); // reset the badly set readOnlyStatus field.setReadOnly(readOnlyStatus); }
@SuppressWarnings("unchecked") protected Field<?> createField(Container container, Object itemId, Object propertyId, Component uiContext) { ColumnModel model = getColumnModel(String.valueOf(propertyId)); boolean editable = tableEditable && itemId.equals(editableId) && model.isEditable() ; Field<?> f = null; Class<?> type = container.getType(propertyId); f = createFieldForType(type); f.setCaption(null); f.setWidth("100%"); f.setReadOnly(!editable); if (f instanceof AbstractField) { if (model.getConverter() == null) { model.setConverter(findDefaultConverter(model,type)); } if (model.getConverter() != null) ((AbstractField<String>)f).setConverter((Converter<String, ?>)model.generateConverter(type)); } return f; }
@Override public void selectionChanged(SelectionChangedEvent changeEvent) { if (parameter != null) { try { blockListenerOrValidators = true; setData(changeEvent.getSelectedBean()); setItemId(changeEvent.getSelectedItemId()); final BeanItem beanItem = new BeanItem(changeEvent.getSelectedBean(), parameter.getEditablePropertyName(), parameter.getNonEditablePropertyName()); // this is a hack, but we need to know if the selection changed beanItem.addItemProperty("selected", changeEvent.getSelectedItem().getItemProperty("selected")); captionLabel.setValue(String.format("<b>%s</b>", parameter.getCaption())); fieldGroup = new FieldGroup(); fieldGroup.setBuffered(false); fieldGroup.bind(selectedField, "selected"); fieldGroup.bind(editableField, parameter.getEditablePropertyName()); fieldGroup.bind(nonEditableField, parameter.getNonEditablePropertyName()); fieldGroup.setItemDataSource(beanItem); fieldGroup.getField(parameter.getNonEditablePropertyName()).setCaption(parameter.getNonEditablePropertyCaption()); fieldGroup.getField(parameter.getNonEditablePropertyName()).setReadOnly(true); fieldGroup.getField(parameter.getEditablePropertyName()).setCaption(parameter.getEditablePropertyCaption()); fieldGroup.getField(parameter.getEditablePropertyName()).setReadOnly(false); updateEnabledState(); UIHelper.validateField(editableField, true); } finally { blockListenerOrValidators = false; } } }
keyLength.setReadOnly(true); createButton.setEnabled(false); publicKey.setReadOnly(true);