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/04/16 08:51:54 UTC

[isis] 02/02: ISIS-2340: adds support for Markup type (vaadin)

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

commit 336cb04ee4fbd35027e81605a0fa6285b7e83b07
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Apr 16 10:51:40 2020 +0200

    ISIS-2340: adds support for Markup type (vaadin)
---
 .../vaadin/ui/IsisModuleIncViewerVaadinUi.java     |  2 +
 .../vaadin/ui/components/markup/MarkupField.java   | 60 ++++++++++++++++++++++
 .../ui/components/markup/MarkupFieldFactory.java   | 45 ++++++++++++++++
 3 files changed, 107 insertions(+)

diff --git a/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/IsisModuleIncViewerVaadinUi.java b/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/IsisModuleIncViewerVaadinUi.java
index e7a888d..9facc50 100644
--- a/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/IsisModuleIncViewerVaadinUi.java
+++ b/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/IsisModuleIncViewerVaadinUi.java
@@ -29,6 +29,7 @@ import org.apache.isis.incubator.viewer.vaadin.ui.auth.VaadinAuthenticationHandl
 import org.apache.isis.incubator.viewer.vaadin.ui.components.UiComponentFactoryVaa;
 import org.apache.isis.incubator.viewer.vaadin.ui.components.blob.BlobFieldFactory;
 import org.apache.isis.incubator.viewer.vaadin.ui.components.clob.ClobFieldFactory;
+import org.apache.isis.incubator.viewer.vaadin.ui.components.markup.MarkupFieldFactory;
 import org.apache.isis.incubator.viewer.vaadin.ui.components.other.FallbackFieldFactory;
 import org.apache.isis.incubator.viewer.vaadin.ui.components.text.TextFieldFactory;
 import org.apache.isis.viewer.common.model.IsisModuleViewerCommon;
@@ -48,6 +49,7 @@ import org.apache.isis.viewer.common.model.IsisModuleViewerCommon;
         // Component Factories
         BlobFieldFactory.class,
         ClobFieldFactory.class,
+        MarkupFieldFactory.class,
         TextFieldFactory.class,
         FallbackFieldFactory.class,
         
diff --git a/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/components/markup/MarkupField.java b/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/components/markup/MarkupField.java
new file mode 100644
index 0000000..cd01d91
--- /dev/null
+++ b/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/components/markup/MarkupField.java
@@ -0,0 +1,60 @@
+/*
+ *  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.incubator.viewer.vaadin.ui.components.markup;
+
+import javax.annotation.Nullable;
+
+import com.vaadin.flow.component.Html;
+import com.vaadin.flow.component.customfield.CustomField;
+import com.vaadin.flow.component.html.Div;
+
+import org.apache.isis.applib.value.Markup;
+
+public class MarkupField extends CustomField<Markup> {
+
+    private static final long serialVersionUID = 1L;
+    
+    private final Div div = new Div();
+    private Markup markup;
+
+    public MarkupField(String label) {
+        super();
+        setLabel(label);
+        add(div);
+    }
+    
+    @Override
+    protected Markup generateModelValue() {
+        return markup;
+    }
+
+    @Override
+    protected void setPresentationValue(@Nullable Markup markup) {
+        this.markup = markup;
+        
+        div.removeAll();
+        
+        if(markup==null) {
+            return;
+        }
+
+        div.add(new Html("<div>" + markup.asString() + "</div>"));
+    }
+
+}
diff --git a/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/components/markup/MarkupFieldFactory.java b/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/components/markup/MarkupFieldFactory.java
new file mode 100644
index 0000000..ce791a5
--- /dev/null
+++ b/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/components/markup/MarkupFieldFactory.java
@@ -0,0 +1,45 @@
+/*
+ *  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.incubator.viewer.vaadin.ui.components.markup;
+
+import com.vaadin.flow.component.Component;
+
+import org.apache.isis.applib.value.Markup;
+import org.apache.isis.incubator.viewer.vaadin.ui.components.UiComponentHandlerVaa;
+import org.apache.isis.viewer.common.model.binding.UiComponentFactory.Request;
+
+import lombok.val;
+
+@org.springframework.stereotype.Component
+public class MarkupFieldFactory implements UiComponentHandlerVaa {
+
+    @Override
+    public boolean isHandling(Request request) {
+        val spec = request.getObjectFeature().getSpecification();
+        return spec.getFullIdentifier().contentEquals(org.apache.isis.applib.value.Markup.class.getName());
+    }
+
+    @Override
+    public Component handle(Request request) {
+        val uiField = new MarkupField(request.getObjectFeature().getName());
+        uiField.setValue((Markup)request.getManagedObject().getPojo()); // pojo is nullable!
+        return uiField;
+    }
+    
+}