You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/09/02 21:28:17 UTC
git commit: ISIS-502: patch for Jeremy Gurr
Updated Branches:
refs/heads/master a2b1d3da4 -> 518bedcd3
ISIS-502: patch for Jeremy Gurr
when replacing a Wicket ComponentFactory, the replacement takes the position of that replaced
Signed-off-by: Dan Haywood <da...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/518bedcd
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/518bedcd
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/518bedcd
Branch: refs/heads/master
Commit: 518bedcd30f592d0b3c3ba7288f88eab9cfca7b8
Parents: a2b1d3d
Author: Dan Haywood <da...@apache.org>
Authored: Mon Sep 2 20:14:47 2013 +0100
Committer: Dan Haywood <da...@apache.org>
Committed: Mon Sep 2 20:14:47 2013 +0100
----------------------------------------------------------------------
.../app/registry/ComponentFactoryRegistrar.java | 31 +++++++++++++++-----
1 file changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/518bedcd/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/app/registry/ComponentFactoryRegistrar.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/app/registry/ComponentFactoryRegistrar.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/app/registry/ComponentFactoryRegistrar.java
index fb4c3d3..5952f0c 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/app/registry/ComponentFactoryRegistrar.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/app/registry/ComponentFactoryRegistrar.java
@@ -19,12 +19,10 @@
package org.apache.isis.viewer.wicket.ui.app.registry;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import org.apache.isis.viewer.wicket.ui.ComponentFactory;
@@ -51,13 +49,32 @@ public interface ComponentFactoryRegistrar {
}
public void replace(final Class<? extends ComponentFactory> toReplace, final ComponentFactory replacementComponentFactory) {
- removeExisting(matching(toReplace));
- add(replacementComponentFactory);
+ int indexOfOldFactory = removeExisting(matching(toReplace));
+ insert(indexOfOldFactory, replacementComponentFactory);
+ }
+
+ private void insert(final int indexToInsertInto, final ComponentFactory replacementComponentFactory) {
+ if (indexToInsertInto > -1 && indexToInsertInto < componentFactories.size()) {
+ componentFactories.add(indexToInsertInto, replacementComponentFactory);
+ } else {
+ componentFactories.add(replacementComponentFactory);
+ }
}
- private void removeExisting(final Predicate<ComponentFactory> predicate) {
- final Collection<ComponentFactory> matching = Collections2.filter(componentFactories, predicate);
- componentFactories.removeAll(matching);
+ private int removeExisting(final Predicate<ComponentFactory> predicate) {
+ int indexOfFirst = -1;
+ for (int i = 0; i < componentFactories.size(); i++) {
+ ComponentFactory factory = componentFactories.get(i);
+ if (predicate.apply(factory)) {
+ componentFactories.remove(i);
+ if (indexOfFirst == -1) {
+ indexOfFirst = i;
+ }
+ i--;
+ }
+ }
+
+ return indexOfFirst;
}
private static Predicate<ComponentFactory> matching(final ComponentType componentType) {