You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2024/01/03 23:49:49 UTC
(causeway-app-helloworld) 01/03: copies over Brian's example, cleans up
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-3175
in repository https://gitbox.apache.org/repos/asf/causeway-app-helloworld.git
commit 190251a9f125c780c7d832c5f3a1ae26d4438e71
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Jul 28 12:52:13 2023 +0100
copies over Brian's example, cleans up
---
pom.xml | 6 ++
...{HelloWorldObject.java => HelloWorldChild.java} | 38 +++++++-----
.../modules/hello/dom/hwo/HelloWorldObject.java | 29 ++++++++-
.../hello/dom/hwo/HelloWorldObject.layout.xml | 12 ++++
.../dom/hwo/HelloWorldObject_EnableDisable.java | 29 +++++++++
...loWorldObject_LookupChildUsingAutoComplete.java | 70 ++++++++++++++++++++++
.../HelloWorldObject_LookupChildUsingChoices.java | 69 +++++++++++++++++++++
7 files changed, 237 insertions(+), 16 deletions(-)
diff --git a/pom.xml b/pom.xml
index 6e385cd..32ad7a8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -114,6 +114,12 @@
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
<profiles>
diff --git a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldChild.java
similarity index 81%
copy from src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java
copy to src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldChild.java
index dbd7386..39c1c96 100644
--- a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java
+++ b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldChild.java
@@ -7,7 +7,6 @@ import javax.inject.Named;
import javax.jdo.annotations.DatastoreIdentity;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
-import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Queries;
import javax.jdo.annotations.Query;
@@ -36,7 +35,7 @@ import domainapp.modules.hello.types.Notes;
identityType = IdentityType.DATASTORE
)
@Unique(
- name = "HelloWorldObject__name__UNQ", members = {"name"}
+ name = "HelloWorldChild__name__UNQ", members = {"name"}
)
@DatastoreIdentity(strategy = IdGeneratorStrategy.IDENTITY, column = "id")
@Version(strategy= VersionStrategy.VERSION_NUMBER, column ="version")
@@ -44,18 +43,18 @@ import domainapp.modules.hello.types.Notes;
@Query(
name = "findByName",
value = "SELECT " +
- "FROM domainapp.modules.hello.dom.hwo.HelloWorldObject " +
+ "FROM domainapp.modules.hello.dom.hwo.HelloWorldChild " +
"WHERE name.indexOf(:name) >= 0"
)
)
-@Named("hello.HelloWorldObject")
+@Named("hello.HelloWorldChild")
@DomainObject()
@DomainObjectLayout() // causes UI events to be triggered
-public class HelloWorldObject implements Comparable<HelloWorldObject> {
+public class HelloWorldChild implements Comparable<HelloWorldChild> {
- private HelloWorldObject(){}
+ private HelloWorldChild(){}
- public HelloWorldObject(final String name) {
+ public HelloWorldChild(final String name) {
this.name = name;
}
@@ -63,7 +62,7 @@ public class HelloWorldObject implements Comparable<HelloWorldObject> {
private String name;
- @Title(prepend = "Object: ")
+ @Title(prepend = "Child: ")
@Name
@PropertyLayout(fieldSetId = LayoutConstants.FieldSetId.IDENTITY, sequence = "1")
public String getName() {
@@ -75,8 +74,17 @@ public class HelloWorldObject implements Comparable<HelloWorldObject> {
private String notes;
+ private boolean enabled = true;
- @Notes
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Notes
@PropertyLayout(fieldSetId = LayoutConstants.FieldSetId.DETAILS, sequence = "1")
public String getNotes() {
return notes;
@@ -95,7 +103,7 @@ public class HelloWorldObject implements Comparable<HelloWorldObject> {
associateWith = "name",
describedAs = "Updates the object's name"
)
- public HelloWorldObject updateName(
+ public HelloWorldChild updateName(
@Name final String name) {
setName(name);
return this;
@@ -128,13 +136,13 @@ public class HelloWorldObject implements Comparable<HelloWorldObject> {
}
@Override
- public int compareTo(final HelloWorldObject other) {
- return Comparator.comparing(HelloWorldObject::getName).compare(this, other);
+ public int compareTo(final HelloWorldChild other) {
+ return Comparator.comparing(HelloWorldChild::getName).compare(this, other);
}
- @Inject @NotPersistent RepositoryService repositoryService;
- @Inject @NotPersistent TitleService titleService;
- @Inject @NotPersistent MessageService messageService;
+ @Inject RepositoryService repositoryService;
+ @Inject TitleService titleService;
+ @Inject MessageService messageService;
}
diff --git a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java
index dbd7386..34b9f86 100644
--- a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java
+++ b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java
@@ -1,6 +1,7 @@
package domainapp.modules.hello.dom.hwo;
import java.util.Comparator;
+import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
@@ -17,12 +18,15 @@ import javax.jdo.annotations.VersionStrategy;
import org.apache.causeway.applib.annotation.Action;
import org.apache.causeway.applib.annotation.ActionLayout;
+import org.apache.causeway.applib.annotation.Collection;
+import org.apache.causeway.applib.annotation.CollectionLayout;
import org.apache.causeway.applib.annotation.DomainObject;
import org.apache.causeway.applib.annotation.DomainObjectLayout;
import org.apache.causeway.applib.annotation.PropertyLayout;
import org.apache.causeway.applib.annotation.Publishing;
import org.apache.causeway.applib.annotation.SemanticsOf;
import org.apache.causeway.applib.annotation.Title;
+import org.apache.causeway.applib.annotation.Where;
import org.apache.causeway.applib.layout.LayoutConstants;
import org.apache.causeway.applib.services.message.MessageService;
import org.apache.causeway.applib.services.repository.RepositoryService;
@@ -60,7 +64,6 @@ public class HelloWorldObject implements Comparable<HelloWorldObject> {
}
-
private String name;
@Title(prepend = "Object: ")
@@ -87,6 +90,30 @@ public class HelloWorldObject implements Comparable<HelloWorldObject> {
+
+ private List<HelloWorldChild> children;
+
+
+ @Collection
+ @CollectionLayout(hidden = Where.NOWHERE)
+ public List<HelloWorldChild> getChildren() {
+ return children;
+ }
+ public void setChildren(List<HelloWorldChild> children) {
+ this.children = children;
+ }
+
+
+ public HelloWorldObject createChild(String name) {
+ HelloWorldChild newChild = new HelloWorldChild(name);
+ this.children.add(newChild);
+ return this;
+ }
+
+
+
+
+
@Action(
semantics = SemanticsOf.IDEMPOTENT,
executionPublishing = Publishing.ENABLED
diff --git a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.layout.xml b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.layout.xml
index 2d6693e..8a3e512 100644
--- a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.layout.xml
+++ b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.layout.xml
@@ -44,6 +44,18 @@
</bs3:col>
<bs3:col span="6">
<bs3:tabGroup unreferencedCollections="true">
+ <bs3:tab>
+ <bs3:row>
+ <bs3:col span="12">
+ <cpt:collection id = "children">
+ <cpt:action id = "createChild"/>
+ <cpt:action id = "lookupChildUsingAutoComplete"/>
+ <cpt:action id = "lookupChildUsingChoices"/>
+ <cpt:action id = "enableDisable"/>
+ </cpt:collection>
+ </bs3:col>
+ </bs3:row>
+ </bs3:tab>
</bs3:tabGroup>
</bs3:col>
</bs3:row>
diff --git a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject_EnableDisable.java b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject_EnableDisable.java
new file mode 100644
index 0000000..fc4cec6
--- /dev/null
+++ b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject_EnableDisable.java
@@ -0,0 +1,29 @@
+package domainapp.modules.hello.dom.hwo;
+
+import java.util.List;
+
+import org.apache.causeway.applib.annotation.Action;
+
+import lombok.RequiredArgsConstructor;
+
+
+/**
+ * this works fine.
+ * @return
+ */
+@Action(choicesFrom = "children")
+@RequiredArgsConstructor
+public class HelloWorldObject_EnableDisable {
+
+ private final HelloWorldObject target;
+
+ /**
+ * @param selection
+ * @param enabled
+ */
+ public HelloWorldObject act(List<HelloWorldChild> selection, boolean enabled) {
+ selection.stream().forEach((c)->c.setEnabled(enabled));
+ return target;
+ }
+
+}
diff --git a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject_LookupChildUsingAutoComplete.java b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject_LookupChildUsingAutoComplete.java
new file mode 100644
index 0000000..72d5b3d
--- /dev/null
+++ b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject_LookupChildUsingAutoComplete.java
@@ -0,0 +1,70 @@
+package domainapp.modules.hello.dom.hwo;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.inject.Inject;
+
+import org.apache.causeway.applib.annotation.Action;
+import org.apache.causeway.applib.annotation.MinLength;
+import org.apache.causeway.applib.annotation.Parameter;
+
+import lombok.RequiredArgsConstructor;
+import lombok.Value;
+import lombok.experimental.Accessors;
+
+
+@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
+@Action
+@RequiredArgsConstructor
+public class HelloWorldObject_LookupChildUsingAutoComplete {
+
+ @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
+ private final HelloWorldObject target;
+
+ @Value
+ @Accessors(fluent = true)
+ static class Parameters {
+ String objectName;
+ String childName;
+ }
+
+ public HelloWorldChild act(
+ @Parameter String objectName,
+ @Parameter String childName) {
+ return helloWorldObjects.findByName(objectName)
+ .get(0)
+ .getChildren()
+ .stream()
+ .filter((o)->o.getName().equals(childName))
+ .findFirst()
+ .get();
+ }
+
+ public Collection<String> choicesObjectName(HelloWorldObject_LookupChildUsingChoices.Parameters params) {
+ return helloWorldObjects
+ .listAll()
+ .stream()
+ .map((o)->o.getName())
+ .collect(Collectors.toList())
+ ;
+ }
+
+ /**
+ * This method is _not_ picked up.
+ */
+ public Collection<String> autoCompleteChildName(Parameters params,
+ @MinLength(3) String search) {
+ HelloWorldObject helloWorldObject = helloWorldObjects.findByName(params.objectName)
+ .get(0);
+ return List.copyOf(helloWorldObject.getChildren())
+ .stream()
+ .map((o)->o.getName())
+ .collect(Collectors.toList());
+ }
+
+
+ @Inject HelloWorldObjects helloWorldObjects;
+
+}
diff --git a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject_LookupChildUsingChoices.java b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject_LookupChildUsingChoices.java
new file mode 100644
index 0000000..26c55de
--- /dev/null
+++ b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject_LookupChildUsingChoices.java
@@ -0,0 +1,69 @@
+package domainapp.modules.hello.dom.hwo;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.inject.Inject;
+
+import org.apache.causeway.applib.annotation.Action;
+import org.apache.causeway.applib.annotation.Parameter;
+
+import lombok.RequiredArgsConstructor;
+import lombok.Value;
+import lombok.experimental.Accessors;
+
+
+@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
+@Action
+@RequiredArgsConstructor
+public class HelloWorldObject_LookupChildUsingChoices {
+
+ @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
+ private final HelloWorldObject target;
+
+ @Value
+ @Accessors(fluent = true)
+ static class Parameters {
+ String objectName;
+ String childName;
+ }
+
+ public HelloWorldChild act(
+ @Parameter String objectName,
+ @Parameter String childName) {
+ return helloWorldObjects.findByName(objectName)
+ .get(0)
+ .getChildren()
+ .stream()
+ .filter((o)->o.getName().equals(childName))
+ .findFirst()
+ .get();
+ }
+
+ public Collection<String> choicesObjectName(Parameters params) {
+ return helloWorldObjects
+ .listAll()
+ .stream()
+ .map((o)->o.getName())
+ .collect(Collectors.toList())
+ ;
+ }
+
+ /**
+ * This method is pickd up fine.
+ * @param params
+ * @return
+ */
+ public Collection<String> choicesChildName(Parameters params) {
+ HelloWorldObject helloWorldObject = helloWorldObjects.findByName(params.objectName)
+ .get(0);
+ return List.copyOf(helloWorldObject.getChildren())
+ .stream()
+ .map((o)->o.getName())
+ .collect(Collectors.toList());
+ }
+
+ @Inject HelloWorldObjects helloWorldObjects;
+
+}