diff --git a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/AbstractCustomMultiField.java b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/AbstractCustomMultiField.java index 8f0fd57..7b3d5cf 100644 --- a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/AbstractCustomMultiField.java +++ b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/AbstractCustomMultiField.java @@ -139,7 +139,7 @@ T fieldValues = (T) getPropertyDataSource().getValue(); initFields(fieldValues); // Update DataSource in order to handle the fields default values - if (relatedFieldItem instanceof ItemAdapter && ((ItemAdapter) relatedFieldItem).isNew()) { + if (relatedFieldItem instanceof ItemAdapter && ((ItemAdapter) relatedFieldItem).isNew() && !this.definition.isReadOnly()) { getPropertyDataSource().setValue(getValue()); } } @@ -173,7 +173,6 @@ ((ConfiguredFieldDefinition) fieldDefinition).setI18nBasename(definition.getI18nBasename()); } Field field = fieldfactory.createField(); - // If the value property is not an Item but a property, set this property as datasource to the field // and add a value change listener in order to propagate changes if (!holdsItem(property)) { @@ -209,6 +208,9 @@ }); } + // Set read only based on the single field definition + field.setReadOnly(fieldDefinition.isReadOnly()); + return field; } diff --git a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/CompositeField.java b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/CompositeField.java index 42fb9e9..af25568 100644 --- a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/CompositeField.java +++ b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/CompositeField.java @@ -87,6 +87,10 @@ protected void initFields(PropertysetItem fieldValues) { root.removeAllComponents(); for (ConfiguredFieldDefinition fieldDefinition : definition.getFields()) { + // Only propagate read only if the parent definition is read only + if (definition.isReadOnly()) { + fieldDefinition.setReadOnly(definition.isReadOnly()); + } Field field = createLocalField(fieldDefinition, fieldValues.getItemProperty(fieldDefinition.getName()), false); if (fieldValues.getItemProperty(fieldDefinition.getName()) == null) { fieldValues.addItemProperty(fieldDefinition.getName(), field.getPropertyDataSource()); diff --git a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/MultiField.java b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/MultiField.java index d5cb14b..d4f724d 100644 --- a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/MultiField.java +++ b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/MultiField.java @@ -82,6 +82,10 @@ public MultiField(MultiValueFieldDefinition definition, FieldFactoryFactory fieldFactoryFactory, ComponentProvider componentProvider, Item relatedFieldItem, I18NAuthoringSupport i18nAuthoringSupport) { super(definition, fieldFactoryFactory, componentProvider, relatedFieldItem, i18nAuthoringSupport); this.fieldDefinition = definition.getField(); + // Only propagate read only if the parent definition is read only + if (definition.isReadOnly()) { + fieldDefinition.setReadOnly(definition.isReadOnly()); + } } /** @@ -129,6 +133,7 @@ } root.addComponent(createEntryComponent(newPropertyId, property), root.getComponentCount() - 1); + }; }); @@ -151,7 +156,9 @@ Property property = newValue.getItemProperty(propertyId); root.addComponent(createEntryComponent(propertyId, property)); } - root.addComponent(addButton); + if (!this.definition.isReadOnly()) { + root.addComponent(addButton); + } } /** @@ -175,6 +182,14 @@ ((PropertysetItem) getPropertyDataSource().getValue()).addItemProperty(propertyId, property); } final Property propertyReference = property; + // set layout to full width + layout.setWidth(100, Unit.PERCENTAGE); + + // distribute space in favour of field over delete button + layout.setExpandRatio(field, 1); + if (definition.isReadOnly()) { + return layout; + } // Delete Button Button deleteButton = new Button(); @@ -206,12 +221,6 @@ } }); layout.addComponent(deleteButton); - - // set layout to full width - layout.setWidth(100, Unit.PERCENTAGE); - - // distribute space in favour of field over delete button - layout.setExpandRatio(field, 1); layout.setExpandRatio(deleteButton, 0); // make sure button stays aligned with the field and not with the optional field label when used @@ -219,7 +228,6 @@ return layout; } - @Override public Class getType() { @@ -252,7 +260,7 @@ } while (fromIndex < valuesSize) { toIndex = fromIndex; - fromIndex +=1; + fromIndex += 1; getValue().addItemProperty(toIndex, getValue().getItemProperty(fromIndex)); getValue().removeItemProperty(fromIndex); } diff --git a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/SwitchableField.java b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/SwitchableField.java index de6a8e7..6ba88c1 100644 --- a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/SwitchableField.java +++ b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/SwitchableField.java @@ -101,6 +101,10 @@ // Create all Fields including the select Field. for (ConfiguredFieldDefinition fieldDefinition : definition.getFields()) { String name = fieldDefinition.getName(); + // Only propagate read only if the parent definition is read only + if (definition.isReadOnly()) { + fieldDefinition.setReadOnly(definition.isReadOnly()); + } Field field = createLocalField(fieldDefinition, fieldValues.getItemProperty(fieldDefinition.getName()), false); // Do not add hidden field. if (!field.isVisible()) {