Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct the handling of CodeDomain types in the pivot table #615

Merged
merged 9 commits into from
Feb 19, 2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corriger l'ordre des imports
supprimer cette ligne : format: VCellFormat?
supprimer l'affectation du l'attribut format au class VBooleanCodeColumn, VDecimalCodeColumn, VIntegerCodeColumn et VStringCodeColumn

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
34 changes: 24 additions & 10 deletions galite-core/src/main/kotlin/org/kopi/galite/visual/domain/Domain.kt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supprimer l'attribut : format: VCellFormat?
supprimer l'affectation du l'attribut format au class VBooleanColumn, VDecimalColumn, VIntegerColumn et VStringColumn
Ajouter les class VDateColumn, VMonthColumn, VWeekColumn, VTimeColumn et VTimestampColumn

Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ 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 +183,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 +248,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restaurer la ligne 34 : internal var userRows: ArrayList? = ArrayList()
et faire les changements nécessaires

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
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supprimer cette import : import org.kopi.galite.visual.report.VCellFormat
supprimer cette ligne format: VCellFormat? ( ligne 12 )
supprimer ligne 18

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corriger l'indentation :
: VCodeColumn(ident,
position,
type,
source,
name) {

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supprimer cette import : import org.kopi.galite.visual.report.VCellFormat
supprimer cette ligne format: VCellFormat? ( ligne 13 )
supprimer ligne 16

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changer ces deux lignes :

  • Copyright (c) 2013-2022 kopiLeft Services SARL, Tunis TN
  • Copyright (c) 1990-2022 kopiRight Managed Solutions GmbH, Wien AT

2022 --> 2023

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supprimer cette import : import org.kopi.galite.visual.report.VCellFormat
supprimer cette ligne format: VCellFormat? ( ligne 35 )
supprimer ligne 39

Changer la méthode format à :
override fun format(o: Any?): String {
return if (names != null) names!![getIndex(o)]!! else idents[getIndex(o)]
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changer ces deux lignes :

  • Copyright (c) 2013-2022 kopiLeft Services SARL, Tunis TN
  • Copyright (c) 1990-2022 kopiRight Managed Solutions GmbH, Wien AT

2022 --> 2023

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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,44 @@
/*
* 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 java.time.LocalDate

/**
* 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
Loading