This is an automated email from the ASF dual-hosted git repository. danhaywood pushed a commit to branch CAUSEWAY-2485 in repository https://gitbox.apache.org/repos/asf/causeway.git
commit f353fe46ebc724b91c5cbf1fc6c742c005d828f9 Author: danhaywood <[email protected]> AuthorDate: Wed Apr 19 07:13:41 2023 +0100 CAUSEWAY-2485: reworks @Property#editing --- .../src/main/java/demoapp/dom/DemoModuleJpa.java | 2 + .../DomainObjectEditingPage-description.adoc | 3 +- .../editing/DomainObjectEditingPage.java | 2 +- .../domain/properties/Property/PropertyMenu.java | 22 +---- .../PropertyEditing.java} | 45 +++++----- .../PropertyEditing.layout.xml} | 39 +++++++-- .../editing/PropertyEditingPage-description.adoc | 83 +++++------------- .../Property/editing/PropertyEditingPage.java | 52 +----------- .../editing/PropertyEditingPage.layout.xml | 13 ++- .../editing/PropertyEditingPage_objects.java | 31 +++++++ ...Annotation.java => PropertyEditingSeeding.java} | 30 ++++--- .../jpa/PropertyEditingJpa-description.adoc} | 30 ++++++- .../Property/editing/jpa/PropertyEditingJpa.java | 97 ++++++++++++++++++++++ .../PropertyEditingJpaEntities.java} | 34 ++++---- .../PropertyEditingReasonDisabledPage.java | 97 ---------------------- ...ropertyLayoutLabelPositionPage-description.adoc | 18 ++-- .../PropertyLayoutMultiLinePage-description.adoc | 12 +-- 17 files changed, 297 insertions(+), 313 deletions(-) diff --git a/examples/demo/domain/src/main/java/demoapp/dom/DemoModuleJpa.java b/examples/demo/domain/src/main/java/demoapp/dom/DemoModuleJpa.java index 47a060579b..055f200abe 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/DemoModuleJpa.java +++ b/examples/demo/domain/src/main/java/demoapp/dom/DemoModuleJpa.java @@ -52,6 +52,7 @@ import demoapp.dom.domain.objects.DomainObjectLayout.tabledec.jpa.DomainObjectLa import demoapp.dom.domain.objects.DomainObjectLayout.xxxUiEvent.jpa.DomainObjectLayoutXxxUiEventJpa; import demoapp.dom.domain.progmodel.objects.embedded.embedded.jpa.NumberConstantJpa; import demoapp.dom.domain.properties.Property.commandPublishing.jpa.PropertyCommandPublishingJpa; +import demoapp.dom.domain.properties.Property.editing.jpa.PropertyEditingJpa; import demoapp.dom.domain.properties.Property.executionPublishing.jpa.PropertyExecutionPublishingJpa; import demoapp.dom.domain.properties.Property.projecting.jpa.PropertyProjectingChildJpa; import demoapp.dom.domain.properties.PropertyLayout.hidden.jpa.PropertyLayoutHiddenJpa; @@ -137,6 +138,7 @@ import demoapp.dom.types.primitive.shorts.jpa.PrimitiveShortJpa; ActionLayoutHiddenJpa.class, PropertyCommandPublishingJpa.class, + PropertyEditingJpa.class, PropertyExecutionPublishingJpa.class, PropertyProjectingChildJpa.class, diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage-description.adoc index a4a4e64188..78db02ad1f 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage-description.adoc +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage-description.adoc @@ -23,7 +23,8 @@ There are therefore three levels at which property editing can be defined: @Property > @DomainObject > global configuration property -Alternatively, this works in the opposite direction also: if the global config property is to _allow_ properties to be edited, then the `@DomainObject#editing` can be used to disable editing and `@Property#editing`. +Alternatively, this works in the opposite direction also: if the global config property is to _allow_ properties to be edited, then the `@DomainObject#editing` (or `@Property#editing`) could be used to disable editing. +This would be much less common, though. In addition, the link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#editingDisabledReason[@DomainObject#editingDisabledReason] can be used to specify the reason why a property cannot be edited. This can also be specified at the property level using link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Property.html#editingDisabledReason[@Property#editingDisabledReason]. diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage.java index bdb463bafd..4ee52cf3fb 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage.java +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage.java @@ -34,7 +34,7 @@ import demoapp.dom._infra.asciidocdesc.HasAsciiDocDescription; @XmlRootElement(name = "root") @XmlType @XmlAccessorType(XmlAccessType.FIELD) -@Named("demo.DomainObjectEditingVm") +@Named("demo.DomainObjectEditingPage") @DomainObject( editing = Editing.ENABLED) public class DomainObjectEditingPage implements HasAsciiDocDescription { diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/PropertyMenu.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/PropertyMenu.java index f01a01db81..667a5311d2 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/PropertyMenu.java +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/PropertyMenu.java @@ -32,14 +32,14 @@ import org.apache.causeway.applib.annotation.SemanticsOf; import org.apache.causeway.applib.value.Blob; import org.apache.causeway.applib.value.Clob; +import demoapp.dom.domain.properties.Property.editing.PropertyEditingPage; + import lombok.RequiredArgsConstructor; import lombok.val; import demoapp.dom._infra.values.ValueHolderRepository; import demoapp.dom.domain.properties.Property.commandPublishing.PropertyCommandPublishingPage; import demoapp.dom.domain.properties.Property.domainEvent.PropertyDomainEventPage; -import demoapp.dom.domain.properties.Property.editing.PropertyEditingPage; -import demoapp.dom.domain.properties.Property.editingReasonDisabled.PropertyEditingReasonDisabledPage; import demoapp.dom.domain.properties.Property.executionPublishing.PropertyExecutionPublishingPage; import demoapp.dom.domain.properties.Property.fileAccept.PropertyFileAcceptPage; import demoapp.dom.domain.properties.Property.maxLength.PropertyMaxLengthPage; @@ -79,23 +79,7 @@ public class PropertyMenu { @Action(semantics = SemanticsOf.SAFE) @ActionLayout(cssClassFa="fa-pencil-alt", describedAs = "Editable fields") public PropertyEditingPage editing(){ - val vm = new PropertyEditingPage(); - - vm.setPropertyUsingAnnotation("this property is editable"); - vm.setPropertyUsingMetaAnnotation("this property is also editable"); - vm.setPropertyUsingMetaAnnotationButOverridden("this property is NOT editable"); - return vm; - } - - @Action(semantics = SemanticsOf.SAFE) - @ActionLayout(cssClassFa="fa-pencil-alt", describedAs = "Not editable fields") - public PropertyEditingReasonDisabledPage editingReasonDisabled(){ - val vm = new PropertyEditingReasonDisabledPage(); - - vm.setPropertyUsingAnnotation("this property NOT is editable"); - vm.setPropertyUsingMetaAnnotation("this property is also NOT editable"); - vm.setPropertyUsingMetaAnnotationButOverridden("this property is NOT editable"); - return vm; + return new PropertyEditingPage(); } @Action(semantics = SemanticsOf.SAFE) diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/EditingReasonDisabledMetaAnnotation.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditing.java similarity index 53% rename from examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/EditingReasonDisabledMetaAnnotation.java rename to examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditing.java index 5c11db4349..75401f9c77 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/EditingReasonDisabledMetaAnnotation.java +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditing.java @@ -16,28 +16,35 @@ * specific language governing permissions and limitations * under the License. */ -package demoapp.dom.domain.properties.Property.editingReasonDisabled; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +package demoapp.dom.domain.properties.Property.editing; import org.apache.causeway.applib.annotation.Editing; import org.apache.causeway.applib.annotation.Property; -//tag::class[] -@Property( - editing = Editing.DISABLED, - editingDisabledReason = "disabled " - + "for demo purposes (meta annot.)") // <.> -@Inherited -@Target({ - ElementType.METHOD, ElementType.FIELD // <.> -}) -@Retention(RetentionPolicy.RUNTIME) -public @interface EditingReasonDisabledMetaAnnotation { +import demoapp.dom._infra.asciidocdesc.HasAsciiDocDescription; +import demoapp.dom._infra.values.ValueHolder; + +@SuppressWarnings("CdiManagedBeanInconsistencyInspection") +public abstract class PropertyEditing + implements + HasAsciiDocDescription, + ValueHolder<String> { + + public String title() { + return value(); + } + + @Override + public String value() { + return getName(); + } + + public abstract String getName(); + public abstract void setName(String value); + + @Property(editing = Editing.DISABLED, editingDisabledReason = "This property cannot be edited") + public abstract String getOriginalName(); + public abstract void setOriginalName(String value); + public abstract Character getInitialCharacter(); } -//end::class[] diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/PropertyEditingReasonDisabledPage.layout.xml b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditing.layout.xml similarity index 74% rename from examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/PropertyEditingReasonDisabledPage.layout.xml rename to examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditing.layout.xml index 790c10145c..691a0c6d47 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/PropertyEditingReasonDisabledPage.layout.xml +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditing.layout.xml @@ -26,11 +26,37 @@ <bs3:row> <bs3:col span="6"> - <cpt:fieldSet name="Annotated" id="annotation"/> - <cpt:fieldSet name="Contributed" id="contributed"/> - <cpt:fieldSet name="Meta-annotated" id="meta-annotated"/> - <cpt:fieldSet name="Meta-annotated Overridden" id="meta-annotated-overridden"/> - <cpt:fieldSet name="Other" id="other" unreferencedProperties="true"/> + <bs3:tabGroup> + <bs3:tab name="General"> + <bs3:row> + <bs3:col span="12"> + <cpt:fieldSet name="General" id="general" > + <cpt:property id="name"/> + <cpt:property id="originalName"/> + <cpt:property id="initialCharacter"/> + </cpt:fieldSet> + </bs3:col> + </bs3:row> + </bs3:tab> + <bs3:tab name="Metadata"> + <bs3:row> + <bs3:col span="12"> + <cpt:fieldSet name="Metadata" id="metadata" > + <cpt:property id="id"/> + <cpt:property id="logicalTypeName"/> + <cpt:property id="version"/> + </cpt:fieldSet> + </bs3:col> + </bs3:row> + </bs3:tab> + <bs3:tab name="Other"> + <bs3:row> + <bs3:col span="12"> + <cpt:fieldSet name="Other" id="other" unreferencedProperties="true"/> + </bs3:col> + </bs3:row> + </bs3:tab> + </bs3:tabGroup> </bs3:col> <bs3:col span="6"> <cpt:fieldSet name="Description" id="description" > @@ -47,8 +73,7 @@ <cpt:action id="openRestApi" position="PANEL_DROPDOWN" /> <cpt:property id="description"/> </cpt:fieldSet> - </bs3:col> - </bs3:row> + </bs3:col> </bs3:row> <bs3:row> <bs3:col span="12" unreferencedCollections="true"/> </bs3:row> diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage-description.adoc index d10ccf210a..8f70f26f26 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage-description.adoc +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage-description.adoc @@ -1,78 +1,39 @@ :Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or ag [...] -The `editing` element specifies that a property's value can be changed through the UI: +The state of the application can be changed either by invoking actions on domain objects, or by directly editing their properties. -* for properties, the element can be specified using either the `@Property` annotation, or a meta-annotation +If the application has complicated business logic, then it's usually preferable to make all changes using actions, with editing globally disabled using a configuration property: -There is no corresponding element for parameters, parameters are implicitly editable. - -== Class Level - -Usually editing of properties is discouraged; it is usually better to modify state through an explicit action instead. -For that reason, editing of properties is disabled by default (though that can be changed globally if necessary using the `causeway.applib.annotation.domain-object.editing` configuration property). - -Editing can also be specified at the class level. -This will override any configured defaults, but just for the properties of that class: - -[source,java,indent=0] -.PropertyEditingPage.java +[source,yaml] +.application.yml ---- -include::PropertyEditingPage.java[tags=class] +causeway: + applib: + annotation: + domain-object: + editing: false # false | true ---- -The property-level element can, in turn, overrides the configured or class-level default. +This demo application is configured in this recommended way, with property editing disabled by default. +The link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Property.html#editing[@Property#editing] annotation allows this to be overridden for a specific property. -== Annotated +Note that it's also possible to override the default for a specific object, so that all of its properties using link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#editing[@DomainObject#editing]. +There are therefore three levels at which property editing can be defined: -The `editing` element can be specified explicitly using an annotation: + @Property > @DomainObject > global configuration property -* for properties, using `@Property#editing()`: -+ -[source,java,indent=0] -.PropertyEditingPage.java ----- -include::PropertyEditingPage.java[tags=annotation] ----- -<.> explicitly specifies that the property is editable +Alternatively, this works in the opposite direction also: if the global config property is to _allow_ properties to be edited, then the `@DomainObject#editing` (or `@Property#editing`) could be used to disable editing. +This would be much less common, though. -The annotation could also be applied to a mixin, but would have little effect because mixin properties are always read-only. +In addition, the link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Property.html#editingDisabledReason[@Property#editingDisabledReason] can be used to specify the reason why a property cannot be edited. +(This can also be specified at the object level using link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#editingDisabledReason[@DomainObject#editingDisabledReason].) -== Meta-annotated -The `editing` element can also be specified using a custom meta-annotation: +== How this demo works -* the meta-annotation is defined as: -+ -[source,java] ----- -include::EditingEnabledMetaAnnotation.java[tags=class] ----- -<.> annotated for a property -<.> annotation can be applied to a property (either its getter or the field directly) +The collection on the left shows a set of entity instances, which use `@Property#editing` to enable editing of one of their properties. +The "initialCharacter" property cannot be edited either, because it is a derived property (has only a getter). -* and can be applied to a property: -+ -[source,java,indent=0] -.PropertyEditingPage.java ----- -include::PropertyEditingPage.java[tags=meta-annotated] ----- -<.> semantic is inherited from the meta-annotation - - - -=== Meta-annotated Overridden - -The meta-annotation can itself be overridden: - -* in a property: -+ -[source,java,indent=0] -.PropertyEditingPage.java ----- -include::PropertyEditingPage.java[tags=meta-annotated-overridden] ----- -<.> semantic from meta-annotation ... -<.> \... is overridden by the `@Property` annotation +Navigate through to the entity in order to edit its properties, and to see the corresponding source code. diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage.java index 894329fe7f..12e8d7edef 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage.java +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage.java @@ -21,19 +21,12 @@ package demoapp.dom.domain.properties.Property.editing; import javax.inject.Named; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import org.apache.causeway.applib.annotation.DomainObject; import org.apache.causeway.applib.annotation.Editing; -import org.apache.causeway.applib.annotation.Nature; import org.apache.causeway.applib.annotation.ObjectSupport; -import org.apache.causeway.applib.annotation.Property; -import org.apache.causeway.applib.annotation.PropertyLayout; - -import lombok.Getter; -import lombok.Setter; import demoapp.dom._infra.asciidocdesc.HasAsciiDocDescription; @@ -43,55 +36,12 @@ import demoapp.dom._infra.asciidocdesc.HasAsciiDocDescription; @XmlAccessorType(XmlAccessType.FIELD) @Named("demo.PropertyEditingPage") @DomainObject( - nature=Nature.VIEW_MODEL, - editing = Editing.DISABLED // <.> -) + editing = Editing.ENABLED) public class PropertyEditingPage implements HasAsciiDocDescription { - // ... -//end::class[] @ObjectSupport public String title() { return "@Property#editing"; } -//tag::annotation[] - @Property( - editing = Editing.ENABLED // <.> - ) - @PropertyLayout( - describedAs = "@Property(editing = ENABLED)", - fieldSetId = "annotation", sequence = "1") - @XmlElement(required = true) - @Getter @Setter - private String propertyUsingAnnotation; -//end::annotation[] - -//tag::meta-annotated[] - @Property() - @EditingEnabledMetaAnnotation // <.> - @PropertyLayout( - describedAs = "@EditingEnabledMetaAnnotation", - fieldSetId = "meta-annotated", sequence = "1") - @XmlElement(required = true) - @Getter @Setter - private String propertyUsingMetaAnnotation; -//end::meta-annotated[] - -//tag::meta-annotated-overridden[] - @EditingEnabledMetaAnnotation // <.> - @Property( - editing = Editing.DISABLED // <.> - ) - @PropertyLayout( - describedAs = - "@EditingEnabledMetaAnnotation " + - "@Property(editing = DISABLED)", - fieldSetId = "meta-annotated-overridden", sequence = "1") - @XmlElement(required = false) - @Getter @Setter - private String propertyUsingMetaAnnotationButOverridden; -//end::meta-annotated-overridden[] - -//tag::class[] } //end::class[] diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage.layout.xml b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage.layout.xml index 790c10145c..d10fab04a4 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage.layout.xml +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage.layout.xml @@ -26,11 +26,10 @@ <bs3:row> <bs3:col span="6"> - <cpt:fieldSet name="Annotated" id="annotation"/> - <cpt:fieldSet name="Contributed" id="contributed"/> - <cpt:fieldSet name="Meta-annotated" id="meta-annotated"/> - <cpt:fieldSet name="Meta-annotated Overridden" id="meta-annotated-overridden"/> <cpt:fieldSet name="Other" id="other" unreferencedProperties="true"/> + <cpt:collection id="objects"> + <cpt:action id="find"/> + </cpt:collection> </bs3:col> <bs3:col span="6"> <cpt:fieldSet name="Description" id="description" > @@ -40,9 +39,9 @@ <cpt:action id="inspectMetamodel" position="PANEL_DROPDOWN"/> <cpt:action id="downloadMetamodelXml" position="PANEL_DROPDOWN"/> <cpt:action id="downloadJdoMetamodel" position="PANEL_DROPDOWN"/> - <cpt:action id="recentCommands" position="PANEL_DROPDOWN"/> - <cpt:action id="recentExecutions" position="PANEL_DROPDOWN"/> - <cpt:action id="recentAuditTrailEntries" position="PANEL_DROPDOWN"/> + <cpt:action id="recentCommands" position="PANEL_DROPDOWN"/> + <cpt:action id="recentExecutions" position="PANEL_DROPDOWN"/> + <cpt:action id="recentAuditTrailEntries" position="PANEL_DROPDOWN"/> <cpt:action id="impersonateWithRoles" position="PANEL_DROPDOWN"/> <cpt:action id="openRestApi" position="PANEL_DROPDOWN" /> <cpt:property id="description"/> diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage_objects.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage_objects.java new file mode 100644 index 0000000000..b2700dcbe9 --- /dev/null +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingPage_objects.java @@ -0,0 +1,31 @@ +package demoapp.dom.domain.properties.Property.editing; + +import java.util.List; + +import javax.inject.Inject; + +import org.apache.causeway.applib.annotation.Collection; +import org.apache.causeway.applib.annotation.CollectionLayout; +import org.apache.causeway.applib.annotation.MemberSupport; + +import lombok.RequiredArgsConstructor; + +import demoapp.dom._infra.values.ValueHolderRepository; + +@Collection() +@CollectionLayout() +@RequiredArgsConstructor +public class PropertyEditingPage_objects { + + @SuppressWarnings("unused") + private final PropertyEditingPage page; + + @MemberSupport + public List<? extends PropertyEditing> coll() { + return objectRepository.all(); + } + + @Inject + ValueHolderRepository<String, ? extends PropertyEditing> objectRepository; + +} diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/EditingEnabledMetaAnnotation.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingSeeding.java similarity index 61% copy from examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/EditingEnabledMetaAnnotation.java copy to examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingSeeding.java index 84950c8824..3f6930739e 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/EditingEnabledMetaAnnotation.java +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/PropertyEditingSeeding.java @@ -18,23 +18,21 @@ */ package demoapp.dom.domain.properties.Property.editing; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +import javax.inject.Inject; -import org.apache.causeway.applib.annotation.Editing; -import org.apache.causeway.applib.annotation.Property; +import org.springframework.stereotype.Service; -//tag::class[] -@Property(editing = Editing.ENABLED) // <.> -@Inherited -@Target({ - ElementType.METHOD, ElementType.FIELD // <.> -}) -@Retention(RetentionPolicy.RUNTIME) -public @interface EditingEnabledMetaAnnotation { +import demoapp.dom._infra.seed.SeedServiceAbstract; +import demoapp.dom._infra.values.ValueHolderRepository; + +@Service +public class PropertyEditingSeeding +extends SeedServiceAbstract { + + @Inject + public PropertyEditingSeeding( + ValueHolderRepository<String, ? extends PropertyEditing> entities) { + super(entities); + } } -//end::class[] diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/PropertyEditingReasonDisabledPage-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/jpa/PropertyEditingJpa-description.adoc similarity index 51% rename from examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/PropertyEditingReasonDisabledPage-description.adoc rename to examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/jpa/PropertyEditingJpa-description.adoc index f35fc37b30..cc330a0e35 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/PropertyEditingReasonDisabledPage-description.adoc +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/jpa/PropertyEditingJpa-description.adoc @@ -1,4 +1,30 @@ :Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or ag [...] -The `editingReasonDisabled` attribute in combination with attribute `editing=Editing#DISABLED` -provides a tooltip to the UI (as to why this property cannot be edited). \ No newline at end of file +In this demo app, property editing is disabled by default. + +However: + +* for the `name` property, editing has been explicitly enabled: ++ +[source,java,indent=0] +---- +include::PropertyEditingJpa.java[tags=name] +---- +<.> editing is enabled after all + +* The `originalName` property remains as not editable. ++ +It uses `@Property#editingDisabledReason` to explain why: ++ +[source,java,indent=0] +---- +include::PropertyEditingJpa.java[tags=original-name] +---- +<.> this reason is rendered in the UI as a tooltip + +* Meanwhile the `initialCharacter` property is also not editable (this time, because it is derived) but has no additional annotations: ++ +[source,java,indent=0] +---- +include::PropertyEditingJpa.java[tags=initial-character] +---- diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/jpa/PropertyEditingJpa.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/jpa/PropertyEditingJpa.java new file mode 100644 index 0000000000..33d81f04ae --- /dev/null +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/jpa/PropertyEditingJpa.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package demoapp.dom.domain.properties.Property.editing.jpa; + +import javax.inject.Named; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.springframework.context.annotation.Profile; + +import org.apache.causeway.applib.annotation.DomainObject; +import org.apache.causeway.applib.annotation.Editing; +import org.apache.causeway.applib.annotation.Nature; +import org.apache.causeway.applib.annotation.Property; +import org.apache.causeway.persistence.jpa.applib.integration.CausewayEntityListener; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import demoapp.dom.domain.properties.Property.editing.PropertyEditing; + +@Profile("demo-jpa") +@Entity +@Table( + schema = "demo", + name = "PropertyEditingJpa" +) +@EntityListeners(CausewayEntityListener.class) +@Named("demo.PropertyEditing") +@NoArgsConstructor +//tag::class[] +// ... +@DomainObject(nature = Nature.ENTITY) +public class PropertyEditingJpa + extends PropertyEditing { + // ... +//end::class[] + + public PropertyEditingJpa(String value) { + setName(value); + setOriginalName(value); + } + + @Id + @GeneratedValue + private Long id; +//tag::class[] + +//tag::name[] + @Property( + editing = Editing.ENABLED // <.> + ) + @Getter @Setter + private String name; +//end::name[] + +//tag::original-name[] + @Property( + editingDisabledReason = // <.> + "This property cannot be edited; " + + "it stores the original value of the name" + ) + @Getter @Setter + private String originalName; +//end::original-name[] + +//tag::initial-character[] + public Character getInitialCharacter() { // <.> + return getName().charAt(0); + } +//end::initial-character[] +//end::class[] + + +//tag::class[] +} +//end::class[] diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/EditingEnabledMetaAnnotation.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/jpa/PropertyEditingJpaEntities.java similarity index 57% rename from examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/EditingEnabledMetaAnnotation.java rename to examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/jpa/PropertyEditingJpaEntities.java index 84950c8824..9d5351e1fc 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/EditingEnabledMetaAnnotation.java +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editing/jpa/PropertyEditingJpaEntities.java @@ -16,25 +16,25 @@ * specific language governing permissions and limitations * under the License. */ -package demoapp.dom.domain.properties.Property.editing; +package demoapp.dom.domain.properties.Property.editing.jpa; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; -import org.apache.causeway.applib.annotation.Editing; -import org.apache.causeway.applib.annotation.Property; +import demoapp.dom._infra.values.ValueHolderRepository; -//tag::class[] -@Property(editing = Editing.ENABLED) // <.> -@Inherited -@Target({ - ElementType.METHOD, ElementType.FIELD // <.> -}) -@Retention(RetentionPolicy.RUNTIME) -public @interface EditingEnabledMetaAnnotation { +@Profile("demo-jpa") +@Service +public class PropertyEditingJpaEntities +extends ValueHolderRepository<String, PropertyEditingJpa> { + + protected PropertyEditingJpaEntities() { + super(PropertyEditingJpa.class); + } + + @Override + protected PropertyEditingJpa newDetachedEntity(String value) { + return new PropertyEditingJpa(value); + } } -//end::class[] diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/PropertyEditingReasonDisabledPage.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/PropertyEditingReasonDisabledPage.java deleted file mode 100644 index 446ee8e0f0..0000000000 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/Property/editingReasonDisabled/PropertyEditingReasonDisabledPage.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package demoapp.dom.domain.properties.Property.editingReasonDisabled; - -import javax.inject.Named; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import org.apache.causeway.applib.annotation.DomainObject; -import org.apache.causeway.applib.annotation.Editing; -import org.apache.causeway.applib.annotation.Nature; -import org.apache.causeway.applib.annotation.ObjectSupport; -import org.apache.causeway.applib.annotation.Property; -import org.apache.causeway.applib.annotation.PropertyLayout; - -import lombok.Getter; -import lombok.Setter; - -import demoapp.dom._infra.asciidocdesc.HasAsciiDocDescription; - -//tag::class[] -@XmlRootElement(name = "root") -@XmlType -@XmlAccessorType(XmlAccessType.FIELD) -@Named("demo.PropertyEditingReasonDisabledPage") -@DomainObject( - nature=Nature.VIEW_MODEL, - editing = Editing.DISABLED // <.> -) -public class PropertyEditingReasonDisabledPage implements HasAsciiDocDescription { - // ... -//end::class[] - - @ObjectSupport public String title() { - return "@Property#editingReasonDisabled"; - } - -//tag::annotation[] - @Property( - editing = Editing.DISABLED, - editingDisabledReason = "disabled for demo purposes") // <.> - @PropertyLayout( - describedAs = "@Property(editingDisabledReason = \"disabled for demo purposes\")", - fieldSetId = "annotation", sequence = "1") - @XmlElement(required = true) - @Getter @Setter - private String propertyUsingAnnotation; -//end::annotation[] - -//tag::meta-annotated[] - @Property() - @EditingReasonDisabledMetaAnnotation // <.> - @PropertyLayout( - describedAs = "@EditingReasonDisabledMetaAnnotation", - fieldSetId = "meta-annotated", sequence = "1") - @XmlElement(required = true) - @Getter @Setter - private String propertyUsingMetaAnnotation; -//end::meta-annotated[] - -//tag::meta-annotated-overridden[] - @EditingReasonDisabledMetaAnnotation // <.> - @Property( - editing = Editing.DISABLED, - editingDisabledReason = "disabled for demo purposes") // <.> - @PropertyLayout( - describedAs = - "@EditingReasonDisabledMetaAnnotation " + - "@Property(editingDisabledReason = \"disabled for demo purposes\")", - fieldSetId = "meta-annotated-overridden", sequence = "1") - @XmlElement(required = false) - @Getter @Setter - private String propertyUsingMetaAnnotationButOverridden; -//end::meta-annotated-overridden[] - -//tag::class[] -} -//end::class[] diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/PropertyLayout/labelPosition/PropertyLayoutLabelPositionPage-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/PropertyLayout/labelPosition/PropertyLayoutLabelPositionPage-description.adoc index f46e68e95d..8ad755b5d3 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/PropertyLayout/labelPosition/PropertyLayoutLabelPositionPage-description.adoc +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/PropertyLayout/labelPosition/PropertyLayoutLabelPositionPage-description.adoc @@ -26,7 +26,7 @@ include::PropertyLayoutLabelPositionPage.java[tags=annotation] + [source,java,indent=0] ---- -include::PropertyLayoutLabelPositionVm_updateWithParameterLayout.java[tags=annotation] +include::PropertyLayoutLabelPositionPage_updateWithParameterLayout.java[tags=annotation] ---- <.> explicitly specifies the label position for the parameter @@ -59,7 +59,7 @@ The `@PropertyLayout` can also be applied at the class-level to mixin properties [source,java,indent=0] ---- -include::PropertyLayoutLabelPositionVm_mixinProperty.java[tags=class] +include::PropertyLayoutLabelPositionPage_mixinProperty.java[tags=class] ---- <.> explicitly specifies the label position for the contributed property @@ -91,7 +91,7 @@ include::PropertyLayoutLabelPositionPage.java[tags=meta-annotated] + [source,java,indent=0] ---- -include::PropertyLayoutLabelPositionVm_updateWithMetaAnnotation.java[tags=meta-annotation] +include::PropertyLayoutLabelPositionPage_updateWithMetaAnnotation.java[tags=meta-annotation] ---- <.> hint is inherited from the meta-annotation @@ -99,7 +99,7 @@ include::PropertyLayoutLabelPositionVm_updateWithMetaAnnotation.java[tags=meta-a + [source,java,indent=0] ---- -include::PropertyLayoutLabelPositionVm_mixinPropertyWithMetaAnnotation.java[tags=class] +include::PropertyLayoutLabelPositionPage_mixinPropertyWithMetaAnnotation.java[tags=class] ---- <.> hint is inherited from the meta-annotation @@ -120,7 +120,7 @@ include::PropertyLayoutLabelPositionPage.java[tags=meta-annotated-overridden] + [source,java,indent=0] ---- -include::PropertyLayoutLabelPositionVm_updateWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden] +include::PropertyLayoutLabelPositionPage_updateWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden] ---- <.> hint from meta-annotation ... <.> \... is overridden by the `@ParameterLayout` annotation @@ -130,7 +130,7 @@ include::PropertyLayoutLabelPositionVm_updateWithMetaAnnotationOverridden.java[t + [source,java,indent=0] ---- -include::PropertyLayoutLabelPositionVm_mixinPropertyWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden] +include::PropertyLayoutLabelPositionPage_mixinPropertyWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden] ---- <.> hint from meta-annotation ... <.> \... is overridden by the `@PropertyLayout` annotation @@ -153,7 +153,7 @@ And for a parameter: [source,java,indent=0] ---- -include::PropertyLayoutLabelPositionVm_updateVariantLeft.java[tags=annotation] +include::PropertyLayoutLabelPositionPage_updateVariantLeft.java[tags=annotation] ---- === Top @@ -169,7 +169,7 @@ And for a parameter: [source,java,indent=0] ---- -include::PropertyLayoutLabelPositionVm_updateVariantTop.java[tags=annotation] +include::PropertyLayoutLabelPositionPage_updateVariantTop.java[tags=annotation] ---- === Right @@ -227,7 +227,7 @@ And for a parameter: [source,java,indent=0] ---- -include::PropertyLayoutLabelPositionVm_updateVariantNotSpecified.java[tags=annotation] +include::PropertyLayoutLabelPositionPage_updateVariantNotSpecified.java[tags=annotation] ---- The default position itself can be configured globally, in the `application.yml` or `application.properties` configuration file. diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/PropertyLayout/multiLine/PropertyLayoutMultiLinePage-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/PropertyLayout/multiLine/PropertyLayoutMultiLinePage-description.adoc index 54758e63fe..5b4085a293 100644 --- a/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/PropertyLayout/multiLine/PropertyLayoutMultiLinePage-description.adoc +++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/properties/PropertyLayout/multiLine/PropertyLayoutMultiLinePage-description.adoc @@ -24,7 +24,7 @@ include::PropertyLayoutMultiLinePage.java[tags=annotation] + [source,java,indent=0] ---- -include::PropertyLayoutMultiLineVm_updateWithParameterLayout.java[tags=annotation] +include::PropertyLayoutMultiLinePage_updateWithParameterLayout.java[tags=annotation] ---- <.> explicitly specifies that the parameter should use a textbox @@ -59,7 +59,7 @@ The `@PropertyLayout` can also be applied at the class-level to mixin properties [source,java,indent=0] ---- -include::PropertyLayoutMultiLineVm_mixinProperty.java[tags=class] +include::PropertyLayoutMultiLinePage_mixinProperty.java[tags=class] ---- <.> explicitly specifies that the contributed property should use a textbox @@ -91,7 +91,7 @@ include::PropertyLayoutMultiLinePage.java[tags=meta-annotated] + [source,java,indent=0] ---- -include::PropertyLayoutMultiLineVm_updateWithMetaAnnotation.java[tags=meta-annotation] +include::PropertyLayoutMultiLinePage_updateWithMetaAnnotation.java[tags=meta-annotation] ---- <.> hint is inherited from the meta-annotation @@ -99,7 +99,7 @@ include::PropertyLayoutMultiLineVm_updateWithMetaAnnotation.java[tags=meta-annot + [source,java,indent=0] ---- -include::PropertyLayoutMultiLineVm_mixinPropertyWithMetaAnnotation.java[tags=class] +include::PropertyLayoutMultiLinePage_mixinPropertyWithMetaAnnotation.java[tags=class] ---- <.> hint is inherited from the meta-annotation @@ -120,7 +120,7 @@ include::PropertyLayoutMultiLinePage.java[tags=meta-annotated-overridden] + [source,java,indent=0] ---- -include::PropertyLayoutMultiLineVm_updateWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden] +include::PropertyLayoutMultiLinePage_updateWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden] ---- <.> hint from meta-annotation ... <.> \... is overridden by the `@ParameterLayout` annotation @@ -130,7 +130,7 @@ include::PropertyLayoutMultiLineVm_updateWithMetaAnnotationOverridden.java[tags= + [source,java,indent=0] ---- -include::PropertyLayoutMultiLineVm_mixinPropertyWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden] +include::PropertyLayoutMultiLinePage_mixinPropertyWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden] ---- <.> hint from meta-annotation ... <.> \... is overridden by the `@PropertyLayout` annotation
