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 9bbf18daeab81f046b4fda6cb056bda9dd0b7a5f Author: Jörg Rade <[email protected]> AuthorDate: Thu Feb 16 22:52:37 2023 +0100 ISIS-3171 CollectionLayout removed, PropertySpecificationHolder introduced --- .../kroviz/core/aggregator/CollectionAggregator.kt | 19 +---- .../kroviz/core/aggregator/ObjectAggregator.kt | 8 +- .../client/kroviz/core/model/CollectionDM.kt | 53 ++++++++++--- .../client/kroviz/core/model/CollectionLayout.kt | 90 ---------------------- .../kroviz/core/model/PropertySpecification.kt | 19 ++--- .../core/model/PropertySpecificationHolder.kt | 53 +++++++++++++ .../causeway/client/kroviz/to/bs/PropertyBs.kt | 10 +-- .../client/kroviz/ui/core/ColumnFactory.kt | 6 +- .../causeway/client/kroviz/ui/core/ViewManager.kt | 2 - 9 files changed, 115 insertions(+), 145 deletions(-) diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/aggregator/CollectionAggregator.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/aggregator/CollectionAggregator.kt index 3a36d46fd1..d1cbfafcf9 100644 --- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/aggregator/CollectionAggregator.kt +++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/aggregator/CollectionAggregator.kt @@ -22,9 +22,7 @@ import org.apache.causeway.client.kroviz.core.event.EventState import org.apache.causeway.client.kroviz.core.event.LogEntry import org.apache.causeway.client.kroviz.core.event.ResourceProxy import org.apache.causeway.client.kroviz.core.event.ResourceSpecification -import org.apache.causeway.client.kroviz.core.model.BaseLayout import org.apache.causeway.client.kroviz.core.model.CollectionDM -import org.apache.causeway.client.kroviz.core.model.CollectionLayout import org.apache.causeway.client.kroviz.to.* import org.apache.causeway.client.kroviz.to.bs.GridBs import org.apache.causeway.client.kroviz.ui.core.ViewManager @@ -57,7 +55,7 @@ class CollectionAggregator(actionTitle: String, private val parent: ObjectAggreg is TObject -> handleObject(obj) is DomainType -> handleDomainType(obj) is GridBs -> handleLayout(obj) - is Property -> handleProperty(obj) + is Property -> handleProperty(obj, referrer) is Collection -> handleCollection(obj) is Icon -> handleIcon(obj) else -> log(logEntry) @@ -88,10 +86,6 @@ class CollectionAggregator(actionTitle: String, private val parent: ObjectAggreg return displayModel as CollectionDM } - private fun getLayout(): CollectionLayout { - return getDisplayModel().layout as CollectionLayout - } - private fun handleList(resultList: ResultList) { if (resultList.resulttype != ResultType.VOID.type) { val result = resultList.result!! @@ -113,7 +107,7 @@ class CollectionAggregator(actionTitle: String, private val parent: ObjectAggreg invokeLayoutLink(tObj, this, referrer = referrer) } //TODO fold layout into model - getLayout().addObject(tObj, this, referrer = referrer) + getDisplayModel().addObject(tObj, this, referrer = referrer) invokeIconLink(tObj, this, referrer = referrer) } @@ -144,11 +138,7 @@ class CollectionAggregator(actionTitle: String, private val parent: ObjectAggreg } } - private fun handleProperty(property: Property) { - handleProperty(property, referrer, getLayout()) - } - - protected fun handleProperty(property: Property, referrer: String, layout: BaseLayout) { + private fun handleProperty(property: Property, referrer: String) { when { property.isObjectProperty() -> { val op = ObjectProperty(property) @@ -158,7 +148,7 @@ class CollectionAggregator(actionTitle: String, private val parent: ObjectAggreg property.isPropertyDescription() -> { val pd = PropertyDescription(property) - getLayout().addPropertyDescription(pd, this, referrer) + getDisplayModel().addPropertyDescription(pd, this, referrer) } else -> { @@ -173,7 +163,6 @@ class CollectionAggregator(actionTitle: String, private val parent: ObjectAggreg //TODO is _id_ required in both CollectionDM and CollectionLayout? val id = collection.id getDisplayModel().id = id - getLayout().id = id // add displayModel to parent.displayModel val objectDM = parent!!.getDisplayModel() objectDM.addCollectionModel(getDisplayModel()) diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/aggregator/ObjectAggregator.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/aggregator/ObjectAggregator.kt index 17b85d0581..3bbc286a5c 100644 --- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/aggregator/ObjectAggregator.kt +++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/aggregator/ObjectAggregator.kt @@ -58,8 +58,6 @@ class ObjectAggregator(val actionTitle: String) : AggregatorWithLayout() { } if (getDisplayModel().readyToRender()) { - console.log("[OA_readyToRender]") - console.log(getDisplayModel()) ViewManager.openObjectView(this) } } @@ -103,7 +101,9 @@ class ObjectAggregator(val actionTitle: String) : AggregatorWithLayout() { } private fun handleProperty(property: Property, referrer: String) { - handleProperty(property, referrer) //FIXME + //(property, referrer) //FIXME + console.log("[OA_handleProperty] not handled") + console.log(property) } private fun handleGrid(grid: GridBs, referrer: String) { @@ -126,8 +126,6 @@ class ObjectAggregator(val actionTitle: String) : AggregatorWithLayout() { return title } - - override fun reset(): ObjectAggregator { displayModel.reset() return this diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/CollectionDM.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/CollectionDM.kt index af6e1371e5..25279300ac 100644 --- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/CollectionDM.kt +++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/CollectionDM.kt @@ -20,16 +20,17 @@ package org.apache.causeway.client.kroviz.core.model import io.kvision.state.observableListOf import org.apache.causeway.client.kroviz.core.aggregator.AggregatorWithLayout +import org.apache.causeway.client.kroviz.core.aggregator.CollectionAggregator import org.apache.causeway.client.kroviz.core.event.ResourceProxy +import org.apache.causeway.client.kroviz.to.PropertyDescription import org.apache.causeway.client.kroviz.to.TObject import org.apache.causeway.client.kroviz.to.TransferObject import org.apache.causeway.client.kroviz.to.bs.GridBs +import org.apache.causeway.client.kroviz.to.bs.PropertyBs import org.apache.causeway.client.kroviz.utils.StringUtils class CollectionDM(override val title: String) : DisplayModelWithLayout() { - init { - layout = CollectionLayout() - } + val propertySpecificationHolder = PropertySpecificationHolder() var id = "" var data = observableListOf<Exposer>() @@ -40,31 +41,61 @@ class CollectionDM(override val title: String) : DisplayModelWithLayout() { fun setProtoTypeLayout(grid: GridBs) { protoTypeLayout = grid val propertyList = grid.getPropertyList() - propertyList.forEach{ - getLayout().addPropertyDetails(it) + propertyList.forEach { + addPropertyDetails(it) + } + } + + /** + * collection layout needs only to be initialized once with an object (pars pro toto, prototype) + * obj acts as a kind prototype - we assume all elements in the collection have the same structure + */ + fun addObject(obj: TObject, aggregator: CollectionAggregator, referrer: String) { + if (!propertySpecificationHolder.isInitialized()) { + // members contain all properties, regardless if hidden, disabled, etc. + val members = obj.getProperties() + members.forEach { m -> + propertySpecificationHolder.addMember(m) + val l = m.getInvokeLink()!! + ResourceProxy().fetch(l, aggregator, referrer = referrer) + } } } + + private fun addPropertyDetails(propertyBs: PropertyBs) { + val id = propertyBs.id + val ps: PropertySpecification = propertySpecificationHolder.getPropertySpecification(id) + ps.amendWith(propertyBs) + } + + fun addPropertyDescription( + propertyDescription: PropertyDescription, + aggregator: AggregatorWithLayout, + referrer: String + ) { + val id = propertyDescription.id + val ps: PropertySpecification = propertySpecificationHolder.getPropertySpecification(id) + ps.amendWith(propertyDescription) + } + + fun hasProtoType(): Boolean { return protoType != null } - fun setProtoType(to:TransferObject){ + fun setProtoType(to: TransferObject) { protoType = to as TObject } override fun readyToRender(): Boolean { - return getLayout().readyToRender() + return propertySpecificationHolder.readyToRender() } fun getTitle(): String { return StringUtils.extractTitle(title) } - fun getLayout(): CollectionLayout { - return layout as CollectionLayout - } - override fun addData(obj: TransferObject, aggregator: AggregatorWithLayout?, referrer: String?) { //TODO is checking rawdata really needed? if (!rawData.contains(obj)) { diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/CollectionLayout.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/CollectionLayout.kt deleted file mode 100644 index 71b97e68ed..0000000000 --- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/CollectionLayout.kt +++ /dev/null @@ -1,90 +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.causeway.client.kroviz.core.model - -import org.apache.causeway.client.kroviz.core.aggregator.AggregatorWithLayout -import org.apache.causeway.client.kroviz.core.aggregator.CollectionAggregator -import org.apache.causeway.client.kroviz.core.event.ResourceProxy -import org.apache.causeway.client.kroviz.to.PropertyDescription -import org.apache.causeway.client.kroviz.to.TObject -import org.apache.causeway.client.kroviz.to.bs.PropertyBs - -/** - * For collections aggregate information for each column - * in order to display the table, namely: - * - columnName : column header/label - * - id : attribute to be used to retrieve the value of each cell (id) - * - hidden : will the column be displayed or not - */ -class CollectionLayout : BaseLayout() { - var id = "" - var propertySpecificationList = mutableListOf<PropertySpecification>() - - override fun readyToRender(): Boolean { - return isInitialized() && arePropertySpecificationsReadyToRender() - } - - private fun arePropertySpecificationsReadyToRender():Boolean { - propertySpecificationList.forEach { - val ready = it.readyToRender() - if (!ready) { - return false - } - } - return true - } - - /** - * collection layout needs only to be initialized once with an object (pars pro toto, prototype) - * obj acts as a kind prototype - we assume all elements in the collection have the same structure - */ - fun addObject(obj: TObject, aggregator: CollectionAggregator, referrer: String) { - if (!isInitialized()) { - // members contain all properties, regardless if hidden, disabled, etc. - val members = obj.getProperties() - members.forEach { m -> - val ps = PropertySpecification(m) - propertySpecificationList.add(ps) - val l = m.getInvokeLink()!! - ResourceProxy().fetch(l, aggregator, referrer = referrer) - } - } - } - - private fun isInitialized(): Boolean { - return propertySpecificationList.isNotEmpty() && propertySpecificationList.size > 0 - } - - fun addPropertyDetails(propertyBs: PropertyBs) { - val id = propertyBs.id - val ps: PropertySpecification = propertySpecificationList.firstOrNull { it.id == id }!! - ps.amendWith(propertyBs) - } - - fun addPropertyDescription( - propertyDescription: PropertyDescription, - aggregator: AggregatorWithLayout, - referrer: String - ) { - val id = propertyDescription.id - val ps: PropertySpecification = propertySpecificationList.firstOrNull { it.id == id }!! - ps.amendWith(propertyDescription) - } - -} \ No newline at end of file diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/PropertySpecification.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/PropertySpecification.kt index d70a72b0f3..bbb872de0e 100644 --- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/PropertySpecification.kt +++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/PropertySpecification.kt @@ -23,28 +23,22 @@ import org.apache.causeway.client.kroviz.to.PropertyDescription import org.apache.causeway.client.kroviz.to.bs.PropertyBs /** - * Properties have multiple aspects: - * - * - Member of a DomainObject - * - Description (friendlyName, etc.) - * - Layout (disabledReason, labelPosition, etc.) - * - Visibility (hidden) - * - * All are required in order to be correctly displayed (in a table). + * Aggregate information for each column in order to display in a table, namely: + * - columnName : column header/label + * - id : attribute to be used to retrieve the value of each cell (id) + * - hidden : will the column be displayed or not */ class PropertySpecification(member: Member) { var id = member.id var name = "" // aka: columnName, named, label, title var hidden = true var disabled = member.disabledReason.isNotEmpty() - var isAmendedFromBs = false - var isAmendedFromPropertyDescription = false + private var isAmendedFromBs = false + private var isAmendedFromPropertyDescription = false var typicalLength: Int = 10 fun amendWith(pbs: PropertyBs) { - console.log("[PS_amendWith] PropertyBs") - console.log(pbs) name = pbs.named hidden = !(pbs.hidden != null && pbs.hidden.isNotEmpty()) //This is hacky @@ -55,7 +49,6 @@ class PropertySpecification(member: Member) { typicalLength = pbs.typicalLength.toInt() } isAmendedFromBs = true - console.log(this) } fun amendWith(pd: PropertyDescription) { diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/PropertySpecificationHolder.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/PropertySpecificationHolder.kt new file mode 100644 index 0000000000..05aa7f563b --- /dev/null +++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/model/PropertySpecificationHolder.kt @@ -0,0 +1,53 @@ +/* + * 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.causeway.client.kroviz.core.model + +import org.apache.causeway.client.kroviz.to.Member + +class PropertySpecificationHolder() { + var propertySpecificationList = mutableListOf<PropertySpecification>() + + fun getPropertySpecification(id: String): PropertySpecification { + return propertySpecificationList.firstOrNull { it.id == id }!! + } + + fun readyToRender(): Boolean { + return isInitialized() && arePropertySpecificationsReadyToRender() + } + + private fun arePropertySpecificationsReadyToRender(): Boolean { + propertySpecificationList.forEach { + val ready = it.readyToRender() + if (!ready) { + return false + } + } + return true + } + + fun addMember(m: Member) { + val ps = PropertySpecification(m) + propertySpecificationList.add(ps) + } + + fun isInitialized(): Boolean { + return propertySpecificationList.isNotEmpty() && propertySpecificationList.size > 0 + } + +} diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/to/bs/PropertyBs.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/to/bs/PropertyBs.kt index 4c93d3e460..29d3773225 100644 --- a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/to/bs/PropertyBs.kt +++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/to/bs/PropertyBs.kt @@ -36,11 +36,11 @@ class PropertyBs(node: Node) : XmlLayout() { init { // TODO improve casting val dn = node.asDynamic() - hidden = dn.getAttribute("hidden") //as String - id = dn.getAttribute("id") //as String - typicalLength = dn.getAttribute("typicalLength") //as Int - multiLine = dn.getAttribute("multiLine") //as Int - describedAs = dn.getAttribute("describedAs") //as String + hidden = dn.getAttribute("hidden").unsafeCast<String>() + id = dn.getAttribute("id").unsafeCast<String>() + typicalLength = dn.getAttribute("typicalLength").unsafeCast<Int>() + multiLine = dn.getAttribute("multiLine").unsafeCast<Int>() + describedAs = dn.getAttribute("describedAs").unsafeCast<String>() val nodeList = node.childNodes.asList() val namedList = nodeList.filter { it.nodeName == "$nsCpt:named" } 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 1a710e5b7c..dc52247e6f 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 @@ -25,7 +25,6 @@ import io.kvision.tabulator.Formatter import io.kvision.tabulator.js.Tabulator import io.kvision.utils.obj import org.apache.causeway.client.kroviz.core.model.CollectionDM -import org.apache.causeway.client.kroviz.core.model.CollectionLayout import org.apache.causeway.client.kroviz.core.model.Exposer import org.apache.causeway.client.kroviz.ui.menu.DynamicMenuBuilder @@ -46,8 +45,6 @@ class ColumnFactory { addColumnForObjectIcon(displayCollection, columns) addColumnsForProperties(displayCollection, columns) columns.add(columnForObjectMenu()) - console.log("[CF_buildColumns]") - console.log(columns) return columns } @@ -106,7 +103,7 @@ class ColumnFactory { collectionModel: CollectionDM, columns: MutableList<ColumnDefinition<Exposer>>, ) { - val clo = collectionModel.getLayout() + val clo = collectionModel.propertySpecificationHolder val propSpecList = clo.propertySpecificationList if (propSpecList.size == 0) { // without this, propSpecList is empty? problem with mutable list? @@ -117,6 +114,7 @@ class ColumnFactory { var colDef = ColumnDefinition<dynamic>( title = it.name, field = it.id, + width = (it.typicalLength * 8).toString(), headerFilter = Editor.INPUT) if (it.id == "object") { colDef = buildLink() 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 02a7d4386b..12c3fb1ac7 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 @@ -173,9 +173,7 @@ object ViewManager { } fun openObjectView(aggregator: ObjectAggregator) { - console.log("[VM_openObjectView]") val dm = aggregator.getDisplayModel() -// console.log(dm) val panel = RoDisplay(dm) add(aggregator.getTitle(), panel, aggregator) dm.isRendered = true
