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

Implementation of the Pivot table component #606

Merged
merged 20 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

import org.kopi.galite.gradle._java
import org.kopi.galite.gradle._publishing
import org.kopi.galite.gradle.configureMavenCentralPom
import org.kopi.galite.gradle.signPublication
import org.kopi.galite.gradle.*

plugins {
id("org.jetbrains.kotlin.jvm") version "1.6.10" apply false
Expand All @@ -43,6 +40,9 @@ subprojects {
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
maven {
url = uri("https://mvnrepository.com/artifact/org.vaadin.addons")
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ object Versions {
const val JFREE_CHART = "1.0.19"
const val WYSIWYG_EJAVA = "2.0.1"
const val KOTLINX_DATAFRAME = "0.8.0-rc-7"
const val PIVOT_TABLE = "2.0.0"
}
3 changes: 3 additions & 0 deletions galite-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ dependencies {

// Javax Activation dependency
implementation("javax.activation", "activation", Versions.JAVAX_ACTIVATION)

// Pivot Table dependency
implementation("org.vaadin.addons.componentfactory", "pivottable-flow", Versions.PIVOT_TABLE)
}

dependencyManagement {
Expand Down
69 changes: 26 additions & 43 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 @@ -27,54 +27,21 @@ import java.time.LocalTime
import kotlin.reflect.KClass

import org.joda.time.DateTime
import org.kopi.galite.visual.chart.VBooleanDimension
import org.kopi.galite.visual.chart.VColumnFormat
import org.kopi.galite.visual.chart.VDateDimension
import org.kopi.galite.visual.chart.VDimension
import org.kopi.galite.visual.chart.VDecimalDimension
import org.kopi.galite.visual.chart.VDecimalMeasure
import org.kopi.galite.visual.chart.VIntegerDimension
import org.kopi.galite.visual.chart.VIntegerMeasure
import org.kopi.galite.visual.chart.VMeasure
import org.kopi.galite.visual.chart.VMonthDimension
import org.kopi.galite.visual.chart.VStringDimension
import org.kopi.galite.visual.chart.VTimeDimension
import org.kopi.galite.visual.chart.VTimestampDimension
import org.kopi.galite.visual.chart.VWeekDimension
import org.kopi.galite.type.Image
import org.kopi.galite.type.Month
import org.kopi.galite.type.Week
import org.kopi.galite.visual.VColor
import org.kopi.galite.visual.chart.*
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.VBooleanField
import org.kopi.galite.visual.form.VConstants
import org.kopi.galite.visual.form.VDateField
import org.kopi.galite.visual.form.VField
import org.kopi.galite.visual.form.VDecimalField
import org.kopi.galite.visual.form.VImageField
import org.kopi.galite.visual.form.VIntegerField
import org.kopi.galite.visual.form.VMonthField
import org.kopi.galite.visual.form.VStringField
import org.kopi.galite.visual.form.VTextField
import org.kopi.galite.visual.form.VTimeField
import org.kopi.galite.visual.form.VTimestampField
import org.kopi.galite.visual.form.VWeekField
import org.kopi.galite.visual.report.VBooleanColumn
import org.kopi.galite.visual.report.VCalculateColumn
import org.kopi.galite.visual.report.VCellFormat
import org.kopi.galite.visual.report.VDateColumn
import org.kopi.galite.visual.report.VDecimalColumn
import org.kopi.galite.visual.report.VIntegerColumn
import org.kopi.galite.visual.report.VMonthColumn
import org.kopi.galite.visual.report.VReportColumn
import org.kopi.galite.visual.report.VStringColumn
import org.kopi.galite.visual.report.VTimeColumn
import org.kopi.galite.visual.report.VTimestampColumn
import org.kopi.galite.visual.report.VWeekColumn
import org.kopi.galite.type.Image
import org.kopi.galite.type.Month
import org.kopi.galite.type.Week
import org.kopi.galite.visual.VColor
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.pivottable.VPivotTableColumn

/**
* A domain is a data type with predefined list of allowed values.
Expand Down Expand Up @@ -274,6 +241,22 @@ open class Domain<T>(val width: Int? = null,
}
}

/**
* Builds the pivot table column model
*/
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)

else -> throw java.lang.RuntimeException("Type ${kClass!!.qualifiedName} is not supported")
}
}
}

/**
* Returns the default alignment
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.util.Locale
import org.kopi.galite.visual.ApplicationContext
import org.kopi.galite.visual.VException
import org.kopi.galite.visual.cross.VDynamicReport
import org.kopi.galite.visual.dsl.pivottable.PivotTable
import org.kopi.galite.visual.dsl.report.Report
import org.kopi.galite.visual.form.VDictionaryForm

Expand Down Expand Up @@ -123,6 +124,16 @@ abstract class DictionaryForm(title: String, locale: Locale? = null) : Form(titl
VDynamicReport.createDynamicReport(this.block)
}

/**
* create a pivot table for this form
*/

protected fun Block.createPivotTable(reportbuilder: () -> PivotTable) {
mgrati marked this conversation as resolved.
Show resolved Hide resolved
model.createPivotTable(block) {
reportbuilder().model
}
}

// ----------------------------------------------------------------------
// DICTIONARY FORM MODEL
// ----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ abstract class Form(title: String, locale: Locale? = null) : Window(title, local
save
delete
dynamicReport
pivotTable
help
showHideFilter
report
Expand Down Expand Up @@ -451,6 +452,8 @@ abstract class Form(title: String, locale: Locale? = null) : Window(title, local

open val dynamicReport by lazy { actor(CreateDynamicReport()) }

open val pivotTable by lazy { actor(CreatePivotTable()) }

open val showHideFilter by lazy { actor(ShowHideFilter()) }

open val help by lazy { actor(Help()) }
Expand Down Expand Up @@ -713,6 +716,13 @@ abstract class Form(title: String, locale: Locale? = null) : Window(title, local
}
}

class CreatePivotTable : Actor(menu = ActionMenu(), label = "Pivot Table", help = "Create pivot table.", userActor = false) {
init {
key = Key.F10
icon = Icon.REPORT
}
}

class ShowHideFilter : Actor(menu = ActionMenu(), label = "Show/Hide filter", help = "Show or hide block filters.", userActor = false) {
init {
key = Key.SHIFT_F12
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.dsl.pivottable

import org.kopi.galite.visual.domain.Domain
import org.kopi.galite.visual.dsl.common.LocalizationWriter
import org.kopi.galite.visual.pivottable.Constants
import org.kopi.galite.visual.pivottable.VPivotTableColumn

class Dimension<T>(override val domain: Domain<T>,
val init: Dimension<T>.() -> Unit,
ident: String? = null,
val position: Position,
override val source: String?) : PivotTableField<T>(domain, ident) {

fun initField() {
init()
}

lateinit var model: VPivotTableColumn

fun buildPivotTableColumn(): VPivotTableColumn {
model = domain.buildPivotTableFieldModel(this, position).also { column ->
column.label = label ?: ""
}

return model
}

// ----------------------------------------------------------------------
// XML LOCALIZATION GENERATION
// ----------------------------------------------------------------------
/**
* Generates localization for the field in the xml file
*/
override fun genLocalization(writer: LocalizationWriter) {
(writer as PivotTableLocalizationWriter).genField(ident, label, help)
}

// ----------------------------------------------------------------------
// POSITION CLASS
// ----------------------------------------------------------------------

enum class Position(val value: Int) {
NONE(Constants.DIMENSION_NO_POSITION),
ROW(Constants.DIMENSION_ROW),
COLUMN(Constants.DIMENSION_COLUMN)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.dsl.pivottable

import org.kopi.galite.visual.domain.Domain
import org.kopi.galite.visual.dsl.common.LocalizationWriter
import org.kopi.galite.visual.pivottable.VPivotTableColumn

class Measure<T>(override val domain: Domain<T>,
val init: Measure<T>.() -> Unit,
ident: String? = null,
override val source: String?) : PivotTableField<T>(domain, ident) {

fun initField() {
init()
}

lateinit var model: VPivotTableColumn

fun buildPivotTableColumn(): VPivotTableColumn {
model = domain.buildPivotTableFieldModel(this, Dimension.Position.NONE).also { column ->
column.label = label ?: ""
}

return model
}

// ----------------------------------------------------------------------
// XML LOCALIZATION GENERATION
// ----------------------------------------------------------------------
/**
* Generates localization for the field in the xml file
*/
override fun genLocalization(writer: LocalizationWriter) {
(writer as PivotTableLocalizationWriter).genField(ident, label, help)
}
}
Loading