You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/06/25 07:24:35 UTC
[isis] branch master updated: ISIS-2380: adds element removal to
Can (fixes this issue)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 76985ca ISIS-2380: adds element removal to Can<T> (fixes this issue)
76985ca is described below
commit 76985cab48372a75cbebac044ce5f81bb89e5527
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Jun 25 09:24:16 2020 +0200
ISIS-2380: adds element removal to Can<T> (fixes this issue)
---
.../java/org/apache/isis/core/commons/collections/Can.java | 4 ++--
.../org/apache/isis/core/commons/collections/Can_Empty.java | 5 +++++
.../org/apache/isis/core/commons/collections/Can_Multiple.java | 7 +++++++
.../apache/isis/core/commons/collections/Can_Singleton.java | 8 ++++++++
...mitiveCharHolder_updateReadOnlyProperty2InlineAsIfEdit.java | 4 ++--
.../apache/isis/viewer/wicket/model/models/ScalarModel.java | 10 ++++------
6 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can.java b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can.java
index 8d08b0b..913f177 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can.java
@@ -436,6 +436,8 @@ public interface Can<T> extends Iterable<T>, Serializable {
*/
Can<T> remove(int index);
+ Can<T> remove(T element);
+
// -- SEARCH
/**
@@ -546,7 +548,5 @@ public interface Can<T> extends Iterable<T>, Serializable {
* @return a non-null array, containing the elements of this Can
*/
T[] toArray(Class<T> elementType);
-
-
}
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Empty.java b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Empty.java
index a17feca..8042578 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Empty.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Empty.java
@@ -107,6 +107,11 @@ final class Can_Empty<T> implements Can<T> {
}
@Override
+ public Can<T> remove(T element) {
+ return this; // on an empty can this is a no-op
+ }
+
+ @Override
public int indexOf(T element) {
return -1;
}
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Multiple.java b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Multiple.java
index 71aee59..53b0212 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Multiple.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Multiple.java
@@ -127,6 +127,13 @@ final class Can_Multiple<T> implements Can<T> {
}
@Override
+ public Can<T> remove(T element) {
+ val newElements = new ArrayList<T>(elements);
+ newElements.remove(element);
+ return Can.ofCollection(newElements);
+ }
+
+ @Override
public int indexOf(@NonNull T element) {
return this.elements.indexOf(element);
}
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Singleton.java b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Singleton.java
index 2a41fbe..b7e706c 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Singleton.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Singleton.java
@@ -123,6 +123,14 @@ final class Can_Singleton<T> implements Can<T> {
}
@Override
+ public Can<T> remove(T element) {
+ if(this.element.equals(element)) {
+ return Can.empty();
+ }
+ return this;
+ }
+
+ @Override
public int indexOf(@NonNull T element) {
return this.element.equals(element) ? 0 : -1;
}
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/types/primitive/chars/holder/PrimitiveCharHolder_updateReadOnlyProperty2InlineAsIfEdit.java b/examples/demo/domain/src/main/java/demoapp/dom/types/primitive/chars/holder/PrimitiveCharHolder_updateReadOnlyProperty2InlineAsIfEdit.java
index e7d4f19..b03570f 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/types/primitive/chars/holder/PrimitiveCharHolder_updateReadOnlyProperty2InlineAsIfEdit.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/types/primitive/chars/holder/PrimitiveCharHolder_updateReadOnlyProperty2InlineAsIfEdit.java
@@ -31,8 +31,8 @@ import lombok.RequiredArgsConstructor;
associateWith = "readOnlyProperty2",
associateWithSequence = "1"
)
-//@ActionLayout(promptStyle = PromptStyle.INLINE_AS_IF_EDIT) // broken
-@ActionLayout(promptStyle = PromptStyle.INLINE, named = "Inline as if edit (broken)")
+@ActionLayout(promptStyle = PromptStyle.INLINE_AS_IF_EDIT) // broken
+//@ActionLayout(promptStyle = PromptStyle.INLINE, named = "Inline as if edit (broken)")
@RequiredArgsConstructor
public class PrimitiveCharHolder_updateReadOnlyProperty2InlineAsIfEdit {
diff --git a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java
index ccf0dea..9009c15 100644
--- a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java
+++ b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java
@@ -294,12 +294,10 @@ implements HasRenderingHints, ScalarUiModel, LinksProvider, FormExecutorContext
private final List<ObjectAction> remainingAssociated;
AssociatedActions(final Can<ObjectAction> allAssociated) {
- final List<ObjectAction> temp = allAssociated.toList();
- this.firstAssociatedWithInlineAsIfEdit = firstAssociatedActionWithInlineAsIfEdit(allAssociated);
- if(this.firstAssociatedWithInlineAsIfEdit != null) {
- temp.remove(firstAssociatedWithInlineAsIfEdit);
- }
- remainingAssociated = Collections.unmodifiableList(temp);
+ firstAssociatedWithInlineAsIfEdit = firstAssociatedActionWithInlineAsIfEdit(allAssociated);
+ remainingAssociated = (firstAssociatedWithInlineAsIfEdit != null)
+ ? allAssociated.remove(firstAssociatedWithInlineAsIfEdit).toList()
+ : allAssociated.toList();
}
public List<ObjectAction> getRemainingAssociated() {