You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by jo...@apache.org on 2023/03/26 19:44:06 UTC

[causeway] 03/03: ISIS-3171 table row menu shown (again)

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

joergrade pushed a commit to branch ISIS-3171
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit 121c9e3ad914cb6d3cfa7854952997d41f065090
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Sun Mar 26 21:43:47 2023 +0200

    ISIS-3171 table row menu shown (again)
---
 .../causeway/client/kroviz/core/model/ObjectDM.kt  |  8 +++--
 .../apache/causeway/client/kroviz/to/TypeMapper.kt | 41 +++++++++++++---------
 .../client/kroviz/ui/builder/ColBuilder.kt         |  9 +++--
 .../causeway/client/kroviz/ui/builder/RoDisplay.kt |  2 +-
 .../client/kroviz/ui/core/ColumnFactory.kt         |  7 ++--
 .../client/kroviz/ui/core/FormPanelFactory.kt      | 14 +++++---
 .../causeway/client/kroviz/ui/core/ViewManager.kt  |  2 --
 7 files changed, 52 insertions(+), 31 deletions(-)

diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/ObjectDM.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/ObjectDM.kt
index d1a3349861..9edca84dff 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/ObjectDM.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/ObjectDM.kt
@@ -44,12 +44,16 @@ class ObjectDM(override val title: String) : DisplayModelWithLayout() {
         }
     }
 
+    fun hasCollectionModels(): Boolean {
+        return collectionModelList.isNotEmpty()
+    }
+
     fun addLayout(grid: GridBs, aggregator: ObjectAggregator, referrer: String?) {
         layout = ObjectLayout(grid, aggregator, referrer!!)
     }
 
-    fun getCollectionDisplayModelFor(id: String): CollectionDM {
-        return collectionModelList.firstOrNull { it.id == id }!!
+    fun getCollectionDisplayModelFor(id: String): CollectionDM? {
+        return collectionModelList.firstOrNull { it.id == id }
     }
 
     override fun readyToRender(): Boolean {
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/to/TypeMapper.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/to/TypeMapper.kt
index a00b6367b1..12d02bd0ee 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/to/TypeMapper.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/to/TypeMapper.kt
@@ -25,6 +25,7 @@ enum class ValueType(val type: String) {
     BOOLEAN("Boolean"),
     DATE("Date"),
     HTML("Html"),
+    IFRAME("IFrame"),
     IMAGE("Image"),
     NUMERIC("Numeric"),
     PASSWORD("Password"),
@@ -36,7 +37,7 @@ enum class ValueType(val type: String) {
     SHELL("Shell"),
     SVG_MAPPED("Map"),
     SVG_INLINE("Inline"),
-    IFRAME("IFrame")
+    VEGA("Vega"),
 }
 
 class TypeMapper {
@@ -68,23 +69,31 @@ class TypeMapper {
             else -> ValueType.TEXT.type
         }
     }
+    fun forString(content: String): ValueType {
+        return when {
+            content.startsWith(":Notice:") -> ValueType.TEXT_AREA
+            else -> ValueType.TEXT
+        }
+    }
 
     fun forType(type: String): ValueType {
-        when {
-            type == ValueType.BOOLEAN.type -> return ValueType.BOOLEAN
-            type == ValueType.DATE.type -> return ValueType.DATE
-            type == ValueType.HTML.type -> return ValueType.HTML
-            type == ValueType.IMAGE.type -> return ValueType.IMAGE
-            type == ValueType.NUMERIC.type -> return ValueType.NUMERIC
-            type == ValueType.PASSWORD.type -> return ValueType.PASSWORD
-            type == ValueType.TEXT.type -> return ValueType.TEXT
-            type == ValueType.TEXT_AREA.type -> return ValueType.TEXT_AREA
-            type == ValueType.TIME.type -> return ValueType.TIME
-            type == ValueType.SIMPLE_SELECT.type -> return ValueType.SIMPLE_SELECT
-            type == ValueType.SLIDER.type -> return ValueType.SLIDER
-            type == ValueType.SVG_MAPPED.type -> return ValueType.SVG_MAPPED
-            type == ValueType.SVG_INLINE.type -> return ValueType.SVG_INLINE
-            type == ValueType.IFRAME.type -> return ValueType.IFRAME
+        console.log("[TM_forType] $type")
+        when (type) {
+            ValueType.BOOLEAN.type -> return ValueType.BOOLEAN
+            ValueType.DATE.type -> return ValueType.DATE
+            ValueType.HTML.type -> return ValueType.HTML
+            ValueType.IFRAME.type -> return ValueType.IFRAME
+            ValueType.IMAGE.type -> return ValueType.IMAGE
+            ValueType.NUMERIC.type -> return ValueType.NUMERIC
+            ValueType.PASSWORD.type -> return ValueType.PASSWORD
+            ValueType.TEXT.type -> return ValueType.TEXT
+            ValueType.TEXT_AREA.type -> return ValueType.TEXT_AREA
+            ValueType.TIME.type -> return ValueType.TIME
+            ValueType.SIMPLE_SELECT.type -> return ValueType.SIMPLE_SELECT
+            ValueType.SLIDER.type -> return ValueType.SLIDER
+            ValueType.SVG_MAPPED.type -> return ValueType.SVG_MAPPED
+            ValueType.SVG_INLINE.type -> return ValueType.SVG_INLINE
+            ValueType.VEGA.type -> return ValueType.VEGA
             else -> {
                 return ValueType.TEXT
             }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/builder/ColBuilder.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/builder/ColBuilder.kt
index 4824dafbd8..ac254fef31 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/builder/ColBuilder.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/builder/ColBuilder.kt
@@ -68,13 +68,16 @@ class ColBuilder : UiBuilder() {
         col.collectionList.forEach {
             val id = it.id
             val objectDM = dsp.displayModel
-            // static analysis says objectDM is never null, but runtime disagrees
-            if (objectDM != null) {
-                val cdm = objectDM.getCollectionDisplayModelFor(id)
+            try {
+                // objectDM is sometimes null
+                val cdm = objectDM.getCollectionDisplayModelFor(id)!!
                 val fsPanel = FieldsetPanel(legend = cdm.getTitle())
                 fsPanel.add(RoTable(cdm))
                 panel.add(fsPanel)
                 cdm.isRendered = true
+            } catch (npe: NullPointerException) {
+                console.log("[CB_create] failed with NPE")
+                throw npe
             }
         }
         return panel
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/builder/RoDisplay.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/builder/RoDisplay.kt
index ac71944687..9da11b0c75 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/builder/RoDisplay.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/builder/RoDisplay.kt
@@ -35,7 +35,7 @@ class RoDisplay(val displayModel: ObjectDM) : Displayable, VPanel() {
     init {
         val model = displayModel.data!!
         val tObject: TObject = model.delegate
-        val grid = (displayModel.layout as ObjectLayout).grid!!
+        val grid = (displayModel.layout as ObjectLayout).grid
         objectPanel = LayoutBuilder().create(grid, tObject, this)
         objectPanel.overflow = Overflow.AUTO
         objectPanel.width = CssSize(100, UNIT.perc)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ColumnFactory.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ColumnFactory.kt
index e21d79f37f..2b4907d48b 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ColumnFactory.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ColumnFactory.kt
@@ -57,14 +57,15 @@ class ColumnFactory {
             hozAlign = Align.CENTER,
             width = "40",
             headerSort = false,
-            clickMenu = { component: dynamic, _: dynamic ->
-                buildObjectMenu(component)
+            clickMenu = { _: dynamic, cellComponent: dynamic ->
+                buildObjectMenu(cellComponent.unsafeCast<Tabulator.CellComponent>())
             }
         )
     }
 
     private fun buildObjectMenu(cell: Tabulator.CellComponent): dynamic {
-        val exposer = cell.getData() as Exposer
+        val row = cell.getRow()
+        val exposer = row.getData() as Exposer
         val tObject = exposer.delegate
         return DynamicMenuBuilder.buildObjectMenu(tObject)
     }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/FormPanelFactory.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/FormPanelFactory.kt
index df4b72fb14..26f9db4443 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/FormPanelFactory.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/FormPanelFactory.kt
@@ -74,13 +74,17 @@ class FormPanelFactory(items: List<FormItem>) : VPanel() {
                     ValueType.SVG_INLINE -> add(createInline(fi))
                     ValueType.SVG_MAPPED -> add(createSvgMap(fi))
                     ValueType.BUTTON -> add(createButton(fi))
+                    ValueType.VEGA -> {
+                        TODO("implement VEGA")
+                    }
                 }
             }
         }
     }
 
     private fun createButton(fi: FormItem): Button {
-        val item = Button(text = fi.label, icon = IconManager.find(fi.label))
+        val icon = IconManager.find(fi.label)
+        val item = Button(text = fi.label, icon = icon)
         val obj = fi.callBack!! as Controller
         val action = fi.callBackAction
         item.onClick {
@@ -92,8 +96,8 @@ class FormPanelFactory(items: List<FormItem>) : VPanel() {
     private fun createBoolean(fi: FormItem): Component {
         val value = fi.content
         val bools = arrayOf("true", "false")
-        return when {
-            value in bools -> CheckBox(label = fi.label, value = (value == "true"))
+        return when (value) {
+            in bools -> CheckBox(label = fi.label, value = (value == "true"))
             else -> createText(fi)
         }
     }
@@ -137,6 +141,8 @@ class FormPanelFactory(items: List<FormItem>) : VPanel() {
     }
 
     private fun createTextArea(fi: FormItem): TextArea {
+        console.log("[FPF_createTextArea]")
+        console.log(fi)
         val rows = fi.size
         val item: TextArea = if (rows != null) {
             val rowCnt = maxOf(3, rows)
@@ -181,10 +187,10 @@ class FormPanelFactory(items: List<FormItem>) : VPanel() {
                     //image(require("img/kroviz-logo.svg"))
                 }
                 else -> {
+                    TODO("implement")
                 }
             }
         }
-        //TODO
         panel.add(fi.content as Image)
         panel.addCssClass("form-panel")
         return panel
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ViewManager.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ViewManager.kt
index 37e219cf29..7da325bc72 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ViewManager.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ViewManager.kt
@@ -176,8 +176,6 @@ object ViewManager {
     fun openObjectView(aggregator: SystemAggregator) {
         console.log("[VM_openObjectView]")
         val dm = aggregator.displayModel
-/*        val panel = RoDisplay(dm)
-        add(aggregator.getTitle(), panel, aggregator)*/
         dm.isRendered = true
         setNormalCursor()
     }