Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/galite-01X0' : Fix CodeDomain fi…
Browse files Browse the repository at this point in the history
…elds in pivot table [APPS-01X0]
  • Loading branch information
mgrati committed Feb 19, 2024
2 parents 79309cc + 72623fb commit 3a8af11
Show file tree
Hide file tree
Showing 20 changed files with 829 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ import org.kopi.galite.visual.dsl.chart.ChartMeasure
import org.kopi.galite.visual.dsl.common.CodeDescription
import org.kopi.galite.visual.dsl.common.LocalizationWriter
import org.kopi.galite.visual.dsl.form.FormField
import org.kopi.galite.visual.dsl.pivottable.Dimension
import org.kopi.galite.visual.dsl.pivottable.PivotTableField
import org.kopi.galite.visual.dsl.report.ReportField
import org.kopi.galite.visual.form.VBooleanCodeField
import org.kopi.galite.visual.form.VField
import org.kopi.galite.visual.form.VDecimalCodeField
import org.kopi.galite.visual.form.VIntegerCodeField
import org.kopi.galite.visual.form.VStringCodeField
import org.kopi.galite.visual.pivottable.VPivotTableColumn
import org.kopi.galite.visual.report.VBooleanCodeColumn
import org.kopi.galite.visual.report.VCalculateColumn
import org.kopi.galite.visual.report.VCellFormat
Expand Down Expand Up @@ -224,6 +227,54 @@ open class CodeDomain<T : Comparable<T>?> : Domain<T>() {
}
}

/**
* Builds the pivot table column model
*/
override fun buildPivotTableFieldModel(
field: PivotTableField<*>,
position: Dimension.Position?,
): VPivotTableColumn {
return with(field) {
when (kClass) {
Boolean::class -> org.kopi.galite.visual.pivottable.VBooleanCodeColumn(
ident,
position,
this@CodeDomain.ident.ifEmpty { ident },
field.source,
codes.map { it.ident }.toTypedArray(),
codes.map { it.value as Boolean }.toBooleanArray()
)
BigDecimal::class -> org.kopi.galite.visual.pivottable.VDecimalCodeColumn(
ident,
position,
this@CodeDomain.ident.ifEmpty { ident },
field.source,
codes.map { it.ident }.toTypedArray(),
codes.map { it.value as? BigDecimal }.toTypedArray()
)
Int::class, Long::class -> org.kopi.galite.visual.pivottable.VIntegerCodeColumn(
ident,
position,
this@CodeDomain.ident.ifEmpty { ident },
field.source!!,
codes.map { it.ident }.toTypedArray(),
codes.map { it.value as Int }.toIntArray()
)
String::class -> org.kopi.galite.visual.pivottable.VStringCodeColumn(
ident,
position,
this@CodeDomain.ident.ifEmpty { ident },
field.source,
codes.map { it.ident }.toTypedArray(),
codes.map { it.value as? String }.toTypedArray()
)
else -> throw RuntimeException("Type ${kClass!!.qualifiedName} is not supported")
}.also {
it.initLabels(codes.map { it.label }.toTypedArray())
}
}
}

/**
* Sets a mapping between the values that the domain can take
* and a corresponding text to be displayed in a field.
Expand Down
33 changes: 23 additions & 10 deletions galite-core/src/main/kotlin/org/kopi/galite/visual/domain/Domain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ import org.kopi.galite.visual.dsl.chart.ChartDimension
import org.kopi.galite.visual.dsl.chart.ChartMeasure
import org.kopi.galite.visual.dsl.common.LocalizationWriter
import org.kopi.galite.visual.dsl.form.FormField
import org.kopi.galite.visual.dsl.report.ReportField
import org.kopi.galite.visual.form.*
import org.kopi.galite.visual.report.*
import org.kopi.galite.visual.dsl.pivottable.Dimension
import org.kopi.galite.visual.dsl.pivottable.PivotTableField
import org.kopi.galite.visual.dsl.report.ReportField
import org.kopi.galite.visual.form.*
import org.kopi.galite.visual.pivottable.VPivotTableColumn
import org.kopi.galite.visual.report.*

/**
* A domain is a data type with predefined list of allowed values.
Expand Down Expand Up @@ -182,8 +182,8 @@ open class Domain<T>(val width: Int? = null,
BigDecimal::class -> VDecimalDimension(ident, format, height ?: 6, true)
String::class -> VStringDimension(ident, format)
Boolean::class -> VBooleanDimension(ident, format)
org.joda.time.LocalDate::class, LocalDate::class, java.sql.Date::class, java.util.Date::class ->
VDateDimension(ident, format)
org.joda.time.LocalDate::class, LocalDate::class, java.sql.Date::class, java.util.Date::class
-> VDateDimension(ident, format)
Month::class -> VMonthDimension(ident, format)
Week::class -> VWeekDimension(ident, format)
org.joda.time.LocalTime::class, LocalTime::class -> VTimeDimension(ident, format)
Expand Down Expand Up @@ -247,11 +247,24 @@ open class Domain<T>(val width: Int? = null,
open fun buildPivotTableFieldModel(field: PivotTableField<*>, position: Dimension.Position?): VPivotTableColumn {
return with(field) {
when (kClass) {
Int::class, Long::class, String::class, BigDecimal::class, Boolean::class, org.joda.time.LocalDate::class,
LocalDate::class, java.sql.Date::class, java.util.Date::class, Month::class, Week::class, org.joda.time.LocalTime::class,
LocalTime::class, Instant::class, LocalDateTime::class, DateTime::class ->
VPivotTableColumn(ident, position)

Int::class, Long::class->
org.kopi.galite.visual.pivottable.VIntegerColumn(ident, position)
String::class->
org.kopi.galite.visual.pivottable.VStringColumn(ident, position)
BigDecimal::class->
org.kopi.galite.visual.pivottable.VDecimalColumn(ident, position)
Boolean::class ->
org.kopi.galite.visual.pivottable.VBooleanColumn(ident, position)
org.joda.time.LocalDate::class, LocalDate::class, java.sql.Date::class, java.util.Date::class ->
org.kopi.galite.visual.pivottable.VDateColumn(ident, position)
Month::class ->
org.kopi.galite.visual.pivottable.VMonthColumn(ident, position)
Week::class ->
org.kopi.galite.visual.pivottable.VWeekColumn(ident, position)
org.joda.time.LocalTime::class, LocalTime::class ->
org.kopi.galite.visual.pivottable.VTimeColumn(ident, position)
Instant::class, LocalDateTime::class, DateTime::class ->
org.kopi.galite.visual.pivottable.VTimestampColumn(ident, position)
else -> throw java.lang.RuntimeException("Type ${kClass!!.qualifiedName} is not supported")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package org.kopi.galite.visual.pivottable
import java.io.Serializable

import org.kopi.galite.visual.MessageCode
import org.kopi.galite.visual.report.VReportRow

class MPivotTable : Serializable {

Expand Down Expand Up @@ -81,4 +80,22 @@ class MPivotTable : Serializable {
* @return the desired row
*/
fun getRow(row: Int): VPivotTableRow? = userRows!![row]

/**
* Returns an attribute value for a cell.
*
* @param row the index of the row whose value is to be looked up
* @param column the index of the column whose value is to be looked up (column of the model)
* @return the value Object at the specified cell
*/
fun getValueAt(row: Int, column: Int): Any? {
var x: Any? = null

try {
x = userRows?.get(row)!!.getValueAt(column)
} catch (e: Exception) {
e.printStackTrace()
}
return x
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2013-2023 kopiLeft Services SARL, Tunis TN
* Copyright (c) 1990-2023 kopiRight Managed Solutions GmbH, Wien AT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package org.kopi.galite.visual.pivottable

import org.kopi.galite.util.base.InconsistencyException
import org.kopi.galite.visual.dsl.pivottable.Dimension

class VBooleanCodeColumn(
ident: String?,
position: Dimension.Position?,
type: String?,
source: String?,
name: Array<String>,
private val codes: BooleanArray
) : VCodeColumn(ident, position, type, source, name) {

init {
if (codes.size > 2) {
throw InconsistencyException("Can't define more than two codes for a boolean column")
}
}

override fun compareTo(object1: Any, object2: Any): Int {
return if (object1 == object2) 0 else if (true == object1) 1 else -1
}

override fun getIndex(value: Any?): Int {
return if ((value as Boolean) == codes[0]) 0 else 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2013-2023 kopiLeft Services SARL, Tunis TN
* Copyright (c) 1990-2023 kopiRight Managed Solutions GmbH, Wien AT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package org.kopi.galite.visual.pivottable

import org.kopi.galite.visual.dsl.pivottable.Dimension

/**
* Represents a pivot table column description
* @param ident The identifier of the field
* @param position The position of the dimension field
*/
class VBooleanColumn(ident: String?, position: Dimension.Position?) : VPivotTableColumn(ident, position) {

/**
* Compare two objects.
*
* @param object1 the first operand of the comparison
* @param object2 the second operand of the comparison
* @return -1 if the first operand is smaller than the second
* 1 if the second operand if smaller than the first
* 0 if the two operands are equal
*/
override fun compareTo(object1: Any, object2: Any): Int {
return if (object1 == object2) 0 else if (true == object1) 1 else -1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2013-2023 kopiLeft Services SARL, Tunis TN
* Copyright (c) 1990-2023 kopiRight Managed Solutions GmbH, Wien AT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package org.kopi.galite.visual.pivottable

import org.kopi.galite.visual.dsl.pivottable.Dimension
import org.kopi.galite.visual.l10n.FieldLocalizer
import org.kopi.galite.visual.l10n.TypeLocalizer

/**
* Represents a pivot table column description
* @param ident The identifier of the field
* @param position The position of the dimension field
*/
abstract class VCodeColumn(
ident: String?,
position : Dimension.Position?,
private val type: String?,
private val source: String?,
private val idents: Array<String>
) : VPivotTableColumn(ident, position) {

protected var names: Array<String?>? = null // array of external representations

/**
* Compares two objects.
*
* @param object1 the first operand of the comparison
* @param object2 the second operand of the comparison
* @return -1 if the first operand is smaller than the second
* 1 if the second operand if smaller than the first
* 0 if the two operands are equal
*/
abstract override fun compareTo(object1: Any, object2: Any): Int

/**
* Return a string representation.
*/
override fun format(o: Any?): String {
return if (names != null) names!![getIndex(o)]!! else idents[getIndex(o)]
}

/**
* Get the index of the value.
*/
abstract fun getIndex(value: Any?): Int

// ----------------------------------------------------------------------
// LOCALIZATION
// ----------------------------------------------------------------------
/**
* Localizes this field
*
* @param parentLocalizer the caller localizer
*/
override fun localize(parentLocalizer: FieldLocalizer) {
val loc: TypeLocalizer = parentLocalizer.manager.getTypeLocalizer(source, type)
names = Array(idents.size) { i ->
val label = loc.getCodeLabel(idents[i])
label
}
}

fun initLabels(labels: Array<String>) {
names = labels.map { it }.toTypedArray()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2013-2023 kopiLeft Services SARL, Tunis TN
* Copyright (c) 1990-2023 kopiRight Managed Solutions GmbH, Wien AT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package org.kopi.galite.visual.pivottable

import java.time.LocalDate

import org.kopi.galite.visual.dsl.pivottable.Dimension

/**
* Represents a pivot table column description
* @param ident The identifier of the field
* @param position The position of the dimension field
*/
class VDateColumn(ident: String?, position: Dimension.Position?) : VPivotTableColumn(ident, position) {

/**
* Compare two objects.
*
* @param object1 the first operand of the comparison
* @param object2 the second operand of the comparison
* @return -1 if the first operand is smaller than the second
* 1 if the second operand if smaller than the first
* 0 if the two operands are equal
*/
override fun compareTo(object1: Any, object2: Any): Int = (object1 as LocalDate).compareTo(object2 as LocalDate)
}
Loading

0 comments on commit 3a8af11

Please sign in to comment.