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 2021/01/05 09:05:00 UTC

[isis] branch ISIS-2476 updated: ISIS-2476: adds in components from wicket viewer to the custom UI

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

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


The following commit(s) were added to refs/heads/ISIS-2476 by this push:
     new d17cfa2  ISIS-2476: adds in components from wicket viewer to the custom UI
d17cfa2 is described below

commit d17cfa209df4384ada378ccbadbb239996c728e9
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Jan 5 09:04:31 2021 +0000

    ISIS-2476: adds in components from wicket viewer to the custom UI
---
 ...escription.adoc => CustomUiVm-description.adoc} |  5 +-
 .../demoapp/dom/ui/custom/vm/TabDemo.layout.xml    | 68 ----------------------
 .../webapp/wicket/customview/CustomUiPanel.html    | 42 ++++++++++++-
 .../webapp/wicket/customview/CustomUiPanel.java    | 31 +++++++++-
 4 files changed, 70 insertions(+), 76 deletions(-)

diff --git a/examples/demo/domain/src/main/java/demoapp/dom/ui/custom/vm/TabDemo-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/ui/custom/vm/CustomUiVm-description.adoc
similarity index 89%
rename from examples/demo/domain/src/main/java/demoapp/dom/ui/custom/vm/TabDemo-description.adoc
rename to examples/demo/domain/src/main/java/demoapp/dom/ui/custom/vm/CustomUiVm-description.adoc
index cf204ed..d5a08f8 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/ui/custom/vm/TabDemo-description.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/ui/custom/vm/CustomUiVm-description.adoc
@@ -1,8 +1,5 @@
 :Notice: 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 ag [...]
 
-(since 1.x)
-
 //TODO
 
-See the sources for this demo here:
-link:${SOURCES_DEMO}/demoapp/dom/tabs[sources]
\ No newline at end of file
+Describe how this page works...
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/ui/custom/vm/TabDemo.layout.xml b/examples/demo/domain/src/main/java/demoapp/dom/ui/custom/vm/TabDemo.layout.xml
deleted file mode 100644
index 2c20a0e..0000000
--- a/examples/demo/domain/src/main/java/demoapp/dom/ui/custom/vm/TabDemo.layout.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<!-- 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. -->
-<bs3:grid xmlns:bs3="http://isis.apache.org/applib/layout/grid/bootstrap3"
-          xmlns:cpt="http://isis.apache.org/applib/layout/component"
->
-    <bs3:row>
-        <bs3:col span="12" unreferencedActions="true">
-            <cpt:domainObject/>
-            <cpt:action id="clearHints"/>
-            <cpt:action id="downloadLayoutXml"/>
-            <cpt:action id="openRestApi"/>
-            <cpt:action id="rebuildMetamodel"/>
-
-            <cpt:action id="doHideField"/>
-            <cpt:action id="doShowField"/>
-
-        </bs3:col>
-    </bs3:row>
-    <bs3:row>
-        <bs3:col span="6">
-
-        	<bs3:tabGroup>
-
-				<bs3:tab name="Tab 1">
-					<bs3:row>
-						<bs3:col span="12">
-							<cpt:fieldSet id="fs1" name="Hideable Field">
-								<cpt:property id="field1"/>
-							</cpt:fieldSet>
-						</bs3:col>
-					</bs3:row>
-				</bs3:tab>
-
-				<bs3:tab name="Tab 2">
-					<bs3:row>
-						<bs3:col span="12">
-							<cpt:fieldSet id="fs2">
-								<cpt:property id="field2"/>
-							</cpt:fieldSet>
-						</bs3:col>
-					</bs3:row>
-				</bs3:tab>
-			</bs3:tabGroup>
-
-<!--         	<cpt:fieldSet name="Tabs" id="tabs"> -->
-<!--                 <cpt:property id="field"/> -->
-<!--             </cpt:fieldSet> -->
-
-        </bs3:col>
-        <bs3:col span="6" unreferencedCollections="true">
-
-            <cpt:fieldSet name="Description" id="description" unreferencedProperties="true">
-                <cpt:property id="description" labelPosition="NONE"/>
-
-            </cpt:fieldSet>
-
-        </bs3:col>
-    </bs3:row>
-</bs3:grid>
diff --git a/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/customview/CustomUiPanel.html b/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/customview/CustomUiPanel.html
index e008c7a..66832ca 100644
--- a/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/customview/CustomUiPanel.html
+++ b/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/customview/CustomUiPanel.html
@@ -22,8 +22,46 @@
 <wicket:panel>
     <div class="customUiPanel">
         <div>
-            <p>Where in the world?</p>
-            <img wicket:id="img" width="800px" height="600px"/>
+            <div class="row">
+                <div class="col-lg-10">
+                    <h2>Where in the world?</h2>
+                </div>
+                <div class="col-lg-2">
+                    <div class="fieldSets">
+                        <fieldset class="memberGroup" id="fieldSet-sources">
+                            <div class="panel panel-default">
+                                <div class="properties panel-body">
+                                    <div>
+                                        <div class="property sources" wicket:id="sources"></div>
+                                    </div>
+                                </div>
+                            </div>
+                        </fieldset>
+                    </div>
+                </div>
+            </div>
+            <div class="row">
+                <div class="col-lg-6">
+                    <label wicket:id="address"></label>
+                    <br/>
+                    (<label wicket:id="latitude"></label>,<label wicket:id="longitude"></label>)
+                    <img wicket:id="map" width="800px" height="600px"/>
+                </div>
+                <div class="col-lg-6">
+                    <fieldset class="memberGroup" id="fieldSet-description">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">
+                                <span class="panel-title">Description</span>
+                            </div>
+                            <div class="properties panel-body">
+                                <div>
+                                    <div class="property description" wicket:id="description"></div>
+                                </div>
+                            </div>
+                        </div>
+                    </fieldset>
+                </div>
+            </div>
         </div>
     </div>
 </wicket:panel>
diff --git a/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/customview/CustomUiPanel.java b/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/customview/CustomUiPanel.java
index 3827047..52bd118 100644
--- a/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/customview/CustomUiPanel.java
+++ b/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/customview/CustomUiPanel.java
@@ -19,13 +19,21 @@
 
 package demoapp.webapp.wicket.customview;
 
+import java.io.IOException;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.image.Image;
 import org.apache.wicket.request.resource.ByteArrayResource;
 
 import org.apache.isis.core.metamodel.spec.ManagedObject;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+import org.apache.isis.viewer.common.model.object.ObjectUiModel;
 import org.apache.isis.viewer.wicket.model.hints.UiHintContainer;
+import org.apache.isis.viewer.wicket.model.mementos.PropertyMemento;
 import org.apache.isis.viewer.wicket.model.models.EntityModel;
 import org.apache.isis.viewer.wicket.ui.ComponentFactory;
+import org.apache.isis.viewer.wicket.ui.ComponentType;
 import org.apache.isis.viewer.wicket.ui.panels.PanelAbstract;
 
 import lombok.SneakyThrows;
@@ -71,11 +79,30 @@ public class CustomUiPanel extends PanelAbstract<EntityModel>  {
         val managedObject = (ManagedObject) getModelObject();
         val customUiVm = (CustomUiVm) managedObject.getPojo();
 
+        val latitude = new Label("latitude", customUiVm.getLatitude());
+        val longitude = new Label("longitude", customUiVm.getLongitude());
+        val address = new Label("address", customUiVm.getAddress());
+        val map = createMapComponent("map", customUiVm);
+        val sourcesComponent = createPropertyComponent(managedObject, "sources");
+        val descriptionComponent = createPropertyComponent(managedObject, "description");
+
+        addOrReplace(latitude, longitude, address, map, sourcesComponent, descriptionComponent);
+    }
+
+    private Image createMapComponent(String id, CustomUiVm customUiVm) throws IOException {
         val bytes = geoapifyClient.toJpeg(customUiVm.getLatitude(), customUiVm.getLongitude(), customUiVm.getZoom());
+        val map = new Image(id, new ByteArrayResource("image/jpeg", bytes));
+        return map;
+    }
 
-        val img = new Image("img", new ByteArrayResource("image/jpeg", bytes));
+    private Component createPropertyComponent(ManagedObject managedObject, String propertyId) {
+        val spec = managedObject.getSpecification();
+        val descriptionAssoc = (OneToOneAssociation) spec.getAssociationElseFail(propertyId);
+        val descriptionPm = new PropertyMemento(descriptionAssoc);
 
-        addOrReplace(img);
+        val entityModel = EntityModel.ofAdapter(getCommonContext(), managedObject);
+        val descriptionModel = entityModel.getPropertyModel(descriptionPm, ObjectUiModel.Mode.VIEW, ObjectUiModel.RenderingHint.REGULAR);
+        return getComponentFactoryRegistry().createComponent(ComponentType.SCALAR_NAME_AND_VALUE, propertyId, descriptionModel);
     }