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 2014/11/11 09:24:49 UTC

[26/44] isis git commit: ISIS-537: refactoring out SelectorHelper

ISIS-537: refactoring out SelectorHelper


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/457b3653
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/457b3653
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/457b3653

Branch: refs/heads/master
Commit: 457b365355836c4ad47ff343e992c104b8984e83
Parents: 70af3c3
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Sun Nov 9 15:31:24 2014 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Nov 10 10:21:42 2014 +0000

----------------------------------------------------------------------
 .../viewer/wicket/model/models/EntityModel.java |  5 +-
 .../CollectionContentsSelectorHelper.java       | 96 ++++++++++++++++++++
 ...ectionContentsSelectorDropdownPanelTest.java | 67 ++++++++++++++
 ...ollectionContentsLinksSelectorPanelTest.java | 69 --------------
 .../java/dom/todo/ToDoItemContributions.java    |  3 +-
 5 files changed, 165 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/457b3653/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
index 3955c31..6c66859 100644
--- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
+++ b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
@@ -132,13 +132,11 @@ public class EntityModel extends BookmarkableModel<ObjectAdapter> implements UiH
     private final Map<PropertyMemento, ScalarModel> propertyScalarModels = Maps.newHashMap();
     private MemberGroupLayoutHint memberGroupLayoutHint;
 
-
     /**
      * Toggled by 'entityDetailsButton'.
      */
     private boolean entityDetailsVisible;
 
-
     /**
      * {@link ConcurrencyException}, if any, that might have occurred previously
      */
@@ -479,8 +477,7 @@ public class EntityModel extends BookmarkableModel<ObjectAdapter> implements UiH
             return null;
         }
         String hintKey = hintKey(component, key);
-        String value = hints.get(hintKey);
-        return value;
+        return hints.get(hintKey);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/isis/blob/457b3653/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/dropdown/CollectionContentsSelectorHelper.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/dropdown/CollectionContentsSelectorHelper.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/dropdown/CollectionContentsSelectorHelper.java
new file mode 100644
index 0000000..6b796b5
--- /dev/null
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/dropdown/CollectionContentsSelectorHelper.java
@@ -0,0 +1,96 @@
+/*
+ *  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 org.apache.isis.viewer.wicket.ui.components.collectioncontents.selector.dropdown;
+
+import java.util.ArrayList;
+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.model.models.EntityCollectionModel;
+import org.apache.isis.viewer.wicket.ui.ComponentFactory;
+import org.apache.isis.viewer.wicket.ui.ComponentType;
+import org.apache.isis.viewer.wicket.ui.app.registry.ComponentFactoryRegistry;
+import org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.CollectionContentsAsAjaxTablePanelFactory;
+import org.apache.isis.viewer.wicket.ui.components.collectioncontents.selector.links.CollectionContentsLinksSelectorPanelFactory;
+
+public class CollectionContentsSelectorHelper {
+
+    private static final long serialVersionUID = 1L;
+
+    private final ComponentType componentType;
+    private final ComponentFactoryRegistry componentFactoryRegistry;
+    private final EntityCollectionModel model;
+    private final ComponentFactory ignoreFactory;
+
+
+    public CollectionContentsSelectorHelper(
+            final ComponentType componentType,
+            final ComponentFactoryRegistry componentFactoryRegistry,
+            final EntityCollectionModel model,
+            final ComponentFactory ignoreFactory) {
+        this.componentType = componentType;
+        this.componentFactoryRegistry = componentFactoryRegistry;
+        this.model = model;
+        this.ignoreFactory = ignoreFactory;
+    }
+
+
+    public List<ComponentFactory> findOtherComponentFactories() {
+        final List<ComponentFactory> componentFactories = componentFactoryRegistry.findComponentFactories(componentType, model);
+        ArrayList<ComponentFactory> otherFactories = Lists.newArrayList(Collections2.filter(componentFactories, new Predicate<ComponentFactory>() {
+            @Override
+            public boolean apply(final ComponentFactory input) {
+                return input != ignoreFactory && input.getClass() != CollectionContentsLinksSelectorPanelFactory.class;
+            }
+        }));
+        return ordered(otherFactories);
+    }
+
+    private static List<ComponentFactory> ordered(List<ComponentFactory> componentFactories) {
+        return orderAjaxTableToEnd(componentFactories);
+    }
+
+
+
+    static List<ComponentFactory> orderAjaxTableToEnd(List<ComponentFactory> componentFactories) {
+        int ajaxTableIdx = findAjaxTable(componentFactories);
+        if(ajaxTableIdx>=0) {
+            List<ComponentFactory> orderedFactories = Lists.newArrayList(componentFactories);
+            ComponentFactory ajaxTableFactory = orderedFactories.remove(ajaxTableIdx);
+            orderedFactories.add(ajaxTableFactory);
+            return orderedFactories;
+        } else {
+            return componentFactories;
+        }
+    }
+
+    public static int findAjaxTable(List<ComponentFactory> componentFactories) {
+        for(int i=0; i<componentFactories.size(); i++) {
+            if(componentFactories.get(i) instanceof CollectionContentsAsAjaxTablePanelFactory) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/457b3653/component/viewer/wicket/ui/src/test/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/dropdown/CollectionContentsSelectorDropdownPanelTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/test/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/dropdown/CollectionContentsSelectorDropdownPanelTest.java b/component/viewer/wicket/ui/src/test/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/dropdown/CollectionContentsSelectorDropdownPanelTest.java
new file mode 100644
index 0000000..d116be4
--- /dev/null
+++ b/component/viewer/wicket/ui/src/test/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/dropdown/CollectionContentsSelectorDropdownPanelTest.java
@@ -0,0 +1,67 @@
+/*
+ *  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 org.apache.isis.viewer.wicket.ui.components.collectioncontents.selector.dropdown;
+
+import java.util.Arrays;
+import java.util.List;
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.apache.isis.viewer.wicket.ui.ComponentFactory;
+import org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.CollectionContentsAsAjaxTablePanelFactory;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class CollectionContentsSelectorDropdownPanelTest {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+    @Mock
+    private ComponentFactory one;
+    
+    @Mock
+    private ComponentFactory two;
+
+    private ComponentFactory ajaxTableComponentFactory;
+    
+    @Before
+    public void setUp() throws Exception {
+        ajaxTableComponentFactory = new CollectionContentsAsAjaxTablePanelFactory();
+    }
+    
+    @Test
+    public void testOrderAjaxTableToEnd() {
+        
+        List<ComponentFactory> componentFactories = 
+                Arrays.<ComponentFactory>asList(
+                        one,
+                        ajaxTableComponentFactory, 
+                        two);
+        List<ComponentFactory> orderAjaxTableToEnd = CollectionContentsSelectorDropdownPanel.orderAjaxTableToEnd(componentFactories);
+        assertThat(orderAjaxTableToEnd.get(0), is(one));
+        assertThat(orderAjaxTableToEnd.get(1), is(two));
+        assertThat(orderAjaxTableToEnd.get(2), is(ajaxTableComponentFactory));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/457b3653/component/viewer/wicket/ui/src/test/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/links/CollectionContentsLinksSelectorPanelTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/test/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/links/CollectionContentsLinksSelectorPanelTest.java b/component/viewer/wicket/ui/src/test/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/links/CollectionContentsLinksSelectorPanelTest.java
deleted file mode 100644
index 60e6351..0000000
--- a/component/viewer/wicket/ui/src/test/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/selector/links/CollectionContentsLinksSelectorPanelTest.java
+++ /dev/null
@@ -1,69 +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 org.apache.isis.viewer.wicket.ui.components.collectioncontents.selector.links;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.jmock.auto.Mock;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
-import org.apache.isis.viewer.wicket.ui.ComponentFactory;
-import org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.CollectionContentsAsAjaxTablePanelFactory;
-
-public class CollectionContentsLinksSelectorPanelTest {
-
-    @Rule
-    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
-
-    @Mock
-    private ComponentFactory one;
-    
-    @Mock
-    private ComponentFactory two;
-
-    private ComponentFactory ajaxTableComponentFactory;
-    
-    @Before
-    public void setUp() throws Exception {
-        ajaxTableComponentFactory = new CollectionContentsAsAjaxTablePanelFactory();
-    }
-    
-    @Test
-    public void testOrderAjaxTableToEnd() {
-        
-        List<ComponentFactory> componentFactories = 
-                Arrays.<ComponentFactory>asList(
-                        one,
-                        ajaxTableComponentFactory, 
-                        two);
-        List<ComponentFactory> orderAjaxTableToEnd = CollectionContentsLinksSelectorPanel.orderAjaxTableToEnd(componentFactories);
-        assertThat(orderAjaxTableToEnd.get(0), is(one));
-        assertThat(orderAjaxTableToEnd.get(1), is(two));
-        assertThat(orderAjaxTableToEnd.get(2), is(ajaxTableComponentFactory));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/457b3653/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItemContributions.java
----------------------------------------------------------------------
diff --git a/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItemContributions.java b/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItemContributions.java
index 1b758f8..71d9142 100644
--- a/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItemContributions.java
+++ b/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItemContributions.java
@@ -159,10 +159,9 @@ public class ToDoItemContributions extends AbstractFactoryAndRepository {
     @NotInServiceMenu
     @ActionSemantics(Of.SAFE)
     @NotContributed(As.ACTION)
-    @Programmatic
     public List<ToDoItem> similarTo(final ToDoItem toDoItem) {
         final List<ToDoItem> similarToDoItems = allMatches(
-                new QueryDefault<ToDoItem>(ToDoItem.class, 
+                new QueryDefault<ToDoItem>(ToDoItem.class,
                         "findByOwnedByAndCategory", 
                         "ownedBy", currentUserName(), 
                         "category", toDoItem.getCategory()));