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 2017/11/01 11:49:28 UTC

[isis] 01/02: ISIS-1766: adds the ability to download a fallback menubars.layout.xml.

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 6c83e3693f3053004c0d38c91729b38a8e14fa94
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Nov 1 11:27:30 2017 +0000

    ISIS-1766: adds the ability to download a fallback menubars.layout.xml.
    
    Also updates some docs
---
 ...esentation-layer-spi_MenuBarsLoaderService.adoc | 16 +++---------
 ...svc_presentation-layer-spi_MenuBarsService.adoc | 29 +++++++++-------------
 .../applib/services/layout/LayoutService2.java     |  4 ++-
 .../applib/services/layout/LayoutServiceMenu.java  | 13 +++++++---
 .../isis/applib/services/menu/MenuBarsService.java | 20 +++++++++++++++
 .../services/layout/LayoutServiceDefault.java      |  4 +--
 .../services/menubars/menubars.layout.xml          |  2 +-
 .../services/menu/MenuBarsServiceDefault.java      | 16 ++++++++++--
 .../java/domainapp/application/menubars.layout.xml |  8 +++---
 9 files changed, 69 insertions(+), 43 deletions(-)

diff --git a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_MenuBarsLoaderService.adoc b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_MenuBarsLoaderService.adoc
index b67e97d..cc0cac4 100644
--- a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_MenuBarsLoaderService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_MenuBarsLoaderService.adoc
@@ -6,17 +6,10 @@
 
 
 
-The `MenuBarsLoaderService` is used by the default implementation of xref:rgsvc.adoc#_rgsvc_presentation-layer-spi_MenuBarsService[MenuBarsService] to return a `MenuBars` instance read from the classpath.
+The `MenuBarsLoaderService` is used by the default implementation of xref:rgsvc.adoc#_rgsvc_presentation-layer-spi_MenuBarsService[MenuBarsService] to return a a xref:../rgcms/rgcms.adoc#_rgcms_classes_menubars[`MenuBars`] instance deserialized from the `menubars.layout.xml` file read from the classpath.
 
 
-
-[NOTE]
-====
-TODO: need to flesh this out...
-====
-
-
-== SPI
+== SPI and Implementation
 
 The SPI defined by this service is:
 
@@ -32,9 +25,8 @@ If not, then the xref:rgsvc.adoc#_rgsvc_presentation-layer-spi_MenuBarsService[M
 <2> Returns a new instance of `MenuBars` if possible, otherwise null.
 
 
+The framework provides a default implementation of this service, namely `o.a.i.core.runtime.services.menu.MenuBarsLayoutServiceDefault`.
 
-== Implementation
+This searches for a file resource `menubars.layout.xml`, expected to reside in the same package as the `AppManifest` used to bootstrap the application.
 
-The framework provides a default implementation of this service, namely `o.a.i.core.runtime.services.menu.MenuBarsLayoutServiceDefault`.
-This searches for a file resource `menubars.layout.xml` in the same package as the `AppManifest` used to bootstrap the application.
 It supports reloading only in prototype mode.
diff --git a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_MenuBarsService.adoc b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_MenuBarsService.adoc
index 583e0d4..b13ebd5 100644
--- a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_MenuBarsService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_MenuBarsService.adoc
@@ -6,35 +6,30 @@
 
 
 
-The `MenuBarsService` is responsible for returning a `MenuBars` instance, a data structure representing the arrangement of domain service actions across multiple menu bars, menus and sections.
+The `MenuBarsService` is responsible for returning a xref:../rgcms/rgcms.adoc#_rgcms_classes_menubars[`MenuBars`] instance, a data structure representing the arrangement of domain service actions across multiple menu bars, menus and sections.
 This is used by the Wicket viewer to build up the menu, and is also served as the "menuBars" resource by the xref:../ugvro/ugvro.adoc#[Restful Objects] viewer.
 
 
-[NOTE]
-====
-TODO: need to flesh this out...
-====
 
-
-== SPI
+== SPI and Implementation
 
 The SPI defined by this service is:
 
 [source,java]
 ----
 public interface MenuBarsService {
-    MenuBars menuBars();                    // <1>
+    enum Strategy {                         // <1>
+        DEFAULT,
+        FALLBACK
+    }
+    MenuBars menuBars();                    // <2>
+    MenuBars menuBars(Strategy strategy);   // <3>
 }
 ----
-<1> An instance of `MenuBars`.
-
-[NOTE]
-====
-TODO: need to document `MenuBars` in the rgcms.adoc guide.
-====
-
+<1> Select whether to return the "default" `MenuBars` instance - which may be obtained from anywhere, eg read from the classpath, or to "fallback"" and derive from the metamodel facet/annotations.
+<2> Convenience API to return the default `MenuBars` instance
+<3> Returns an instance of `MenuBars` according the specified strategy.
 
-== Implementation
 
 The framework provides a default implementation of this service, namely `o.a.i.core.runtime.services.menu.MenuBarsServiceDefault`.
-This uses the xref:rgsvc.adoc#_rgsvc_presentation-layer-spi_MenuBarsLoaderService[MenuBarsLoaderService]
\ No newline at end of file
+This uses the xref:rgsvc.adoc#_rgsvc_presentation-layer-spi_MenuBarsLoaderService[MenuBarsLoaderService] to load a serialized form of `MenuBars` instance, called `menubars.layout.xml`, from the classpath.
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutService2.java b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutService2.java
index fde7b16..06aa829 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutService2.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutService2.java
@@ -24,7 +24,9 @@ public interface LayoutService2 extends LayoutService {
 
     /**
      * Obtains the serialized XML form of the menu bars layout ({@link MenuBarsService}).
+     * @param type - either the current menubars (could be loaded from a file) or the fallback (obtained from metamodel facets)
      */
     @Programmatic
-    String toMenuBarsXml();
+    String toMenuBarsXml(final MenuBarsService.Type type);
+
 }
\ No newline at end of file
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
index 30c9bb5..435b1ff 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
@@ -29,6 +29,7 @@ import org.apache.isis.applib.annotation.NatureOfService;
 import org.apache.isis.applib.annotation.ParameterLayout;
 import org.apache.isis.applib.annotation.RestrictTo;
 import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.services.menu.MenuBarsService;
 import org.apache.isis.applib.value.Blob;
 import org.apache.isis.applib.value.Clob;
 
@@ -66,7 +67,7 @@ public class LayoutServiceMenu {
     )
     @ActionLayout(
             cssClassFa = "fa-download",
-            named = "Download Layouts (ZIP)"
+            named = "Download Object Layouts (ZIP)"
     )
     @MemberOrder(sequence="500.400.1")
     public Blob downloadLayouts(final LayoutService.Style style) {
@@ -95,10 +96,10 @@ public class LayoutServiceMenu {
     )
     @MemberOrder(sequence="500.400.2")
     public Clob downloadMenuBarsLayout(
-            @ParameterLayout(named = "File name")
-            final String fileName) {
+            @ParameterLayout(named = "File name") final String fileName,
+            final MenuBarsService.Type type) {
 
-        final String xml = layoutService.toMenuBarsXml();
+        final String xml = layoutService.toMenuBarsXml(type);
 
         return new Clob(Util.withSuffix(fileName,  ".xml"), "text/xml", xml);
     }
@@ -107,6 +108,10 @@ public class LayoutServiceMenu {
         return "menubars.layout.xml";
     }
 
+    public MenuBarsService.Type default1DownloadMenuBarsLayout() {
+        return MenuBarsService.Type.DEFAULT;
+    }
+
 
     // //////////////////////////////////////
 
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/menu/MenuBarsService.java b/core/applib/src/main/java/org/apache/isis/applib/services/menu/MenuBarsService.java
index c1e0b1b..298da1d 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/menu/MenuBarsService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/menu/MenuBarsService.java
@@ -22,6 +22,26 @@ import org.apache.isis.applib.annotation.Programmatic;
 import org.apache.isis.applib.layout.menus.MenuBars;
 
 public interface MenuBarsService {
+
+    enum Type {
+        /**
+         * Either derived from annotations or as obtained elsewhere (eg using the {@link MenuBarsLoaderService} if the
+         * default implementation of this service is in use).
+         */
+        DEFAULT,
+        /**
+         * As derived from annotations.
+         */
+        FALLBACK
+    }
+
+    /**
+     * Returns {@link #menuBars()} with a type of {@link Type#DEFAULT}.
+     * @return
+     */
     @Programmatic
     MenuBars menuBars();
+
+    @Programmatic
+    MenuBars menuBars(final Type type);
 }
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/layout/LayoutServiceDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/layout/LayoutServiceDefault.java
index 7064abb..c27b262 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/layout/LayoutServiceDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/layout/LayoutServiceDefault.java
@@ -141,8 +141,8 @@ public class LayoutServiceDefault implements LayoutService2 {
 
     @Programmatic
     @Override
-    public String toMenuBarsXml() {
-        final MenuBars menuBars = menuBarsService.menuBars();
+    public String toMenuBarsXml(final MenuBarsService.Type type) {
+        final MenuBars menuBars = menuBarsService.menuBars(type);
 
         return jaxbService.toXml(menuBars,
                 ImmutableMap.<String,Object>of(
diff --git a/core/metamodel/src/test/resources/org/apache/isis/core/metamodel/services/menubars/menubars.layout.xml b/core/metamodel/src/test/resources/org/apache/isis/core/metamodel/services/menubars/menubars.layout.xml
index 4c345ef..0a7b7a3 100644
--- a/core/metamodel/src/test/resources/org/apache/isis/core/metamodel/services/menubars/menubars.layout.xml
+++ b/core/metamodel/src/test/resources/org/apache/isis/core/metamodel/services/menubars/menubars.layout.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<mnu:menuBars xsi:schemaLocation="http://isis.apache.org/applib/layout/menus http://isis.apache.org/applib/layout/menus/menus.xsd" xmlns:mnu="http://isis.apache.org/applib/layout/menus" xmlns:lnk="http://isis.apache.org/applib/layout/links" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+<mnu:menuBars xsi:schemaLocation="http://isis.apache.org/applib/layout/menus http://isis.apache.org/applib/layout/menus/menus.xsd http://isis.apache.org/applib/layout/links http://isis.apache.org/applib/layout/links/links.xsd" xmlns:mnu="http://isis.apache.org/applib/layout/menus" xmlns:lnk="http://isis.apache.org/applib/layout/links" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <mnu:primary>
         <mnu:menu>
             <mnu:named>Hello World Objects</mnu:named>
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/menu/MenuBarsServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/menu/MenuBarsServiceDefault.java
index 86b2dde..bf7c584 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/menu/MenuBarsServiceDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/menu/MenuBarsServiceDefault.java
@@ -71,7 +71,18 @@ public class MenuBarsServiceDefault implements MenuBarsService {
     @Override
     @Programmatic
     public MenuBars menuBars() {
+        return menuBars(Type.DEFAULT);
+    }
+
+    @Override
+    @Programmatic
+    public MenuBars menuBars(final Type type) {
+
+        if(type == Type.FALLBACK) {
+            return deriveMenuBarsFromMetaModelFacets();
+        }
 
+        // else load (and only fallback if nothing could be loaded)...
         if(menuBars == null || menuBarsLoaderService.supportsReloading()) {
 
             MenuBars menuBars = menuBarsLoaderService.menuBars();
@@ -83,8 +94,6 @@ public class MenuBarsServiceDefault implements MenuBarsService {
             this.menuBars = menuBars;
         }
 
-        menuBars.setTnsAndSchemaLocation(tnsAndSchemaLocation());
-
         return menuBars;
     }
 
@@ -98,6 +107,9 @@ public class MenuBarsServiceDefault implements MenuBarsService {
         append(serviceAdapters, menuBars.getPrimary(), DomainServiceLayout.MenuBar.PRIMARY);
         append(serviceAdapters, menuBars.getSecondary(), DomainServiceLayout.MenuBar.SECONDARY);
         append(serviceAdapters, menuBars.getTertiary(), DomainServiceLayout.MenuBar.TERTIARY);
+
+        menuBars.setTnsAndSchemaLocation(tnsAndSchemaLocation());
+
         return menuBars;
     }
 
diff --git a/example/application/helloworld/src/main/java/domainapp/application/menubars.layout.xml b/example/application/helloworld/src/main/java/domainapp/application/menubars.layout.xml
index 84034a0..0a7b7a3 100644
--- a/example/application/helloworld/src/main/java/domainapp/application/menubars.layout.xml
+++ b/example/application/helloworld/src/main/java/domainapp/application/menubars.layout.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<mnu:menuBars xsi:schemaLocation="http://isis.apache.org/applib/layout/menus http://isis.apache.org/applib/layout/menus/menus.xsd" xmlns:mnu="http://isis.apache.org/applib/layout/menus" xmlns:lnk="http://isis.apache.org/applib/layout/links" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+<mnu:menuBars xsi:schemaLocation="http://isis.apache.org/applib/layout/menus http://isis.apache.org/applib/layout/menus/menus.xsd http://isis.apache.org/applib/layout/links http://isis.apache.org/applib/layout/links/links.xsd" xmlns:mnu="http://isis.apache.org/applib/layout/menus" xmlns:lnk="http://isis.apache.org/applib/layout/links" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <mnu:primary>
         <mnu:menu>
             <mnu:named>Hello World Objects</mnu:named>
@@ -7,12 +7,12 @@
                 <mnu:action oid="helloworld.HelloWorldObjects:1" id="create">
                     <mnu:named>Create</mnu:named>
                 </mnu:action>
-                <mnu:action oid="helloworld.HelloWorldObjects:1" id="listAll">
-                    <mnu:named>List All</mnu:named>
-                </mnu:action>
                 <mnu:action oid="helloworld.HelloWorldObjects:1" id="findByName">
                     <mnu:named>Find By Name</mnu:named>
                 </mnu:action>
+                <mnu:action oid="helloworld.HelloWorldObjects:1" id="listAll">
+                    <mnu:named>List All</mnu:named>
+                </mnu:action>
             </mnu:section>
         </mnu:menu>
     </mnu:primary>

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.