| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| * |
| */ |
| |
| package org.eclipse.osbp.xtext.reportdsl.jvmmodel |
| |
| import com.google.inject.Inject |
| import com.ibm.icu.util.ULocale |
| import com.vaadin.data.Container.Filter |
| import com.vaadin.server.Sizeable.Unit |
| import com.vaadin.server.StreamResource |
| import com.vaadin.ui.AbstractComponent |
| import com.vaadin.ui.BrowserFrame |
| import com.vaadin.ui.Button |
| import com.vaadin.ui.HorizontalLayout |
| import java.io.ByteArrayOutputStream |
| import java.io.PrintStream |
| import java.util.ArrayList |
| import java.util.HashMap |
| import java.util.List |
| import java.util.Locale |
| import java.util.UUID |
| import org.eclipse.birt.report.model.api.ColumnHandle |
| import org.eclipse.birt.report.model.api.GridHandle |
| import org.eclipse.birt.report.model.api.IDesignEngine |
| import org.eclipse.birt.report.model.api.OdaDataSetHandle |
| import org.eclipse.birt.report.model.api.RowHandle |
| import org.eclipse.birt.report.model.api.StructureFactory |
| import org.eclipse.birt.report.model.api.command.ContentException |
| import org.eclipse.birt.report.model.api.command.CustomMsgException |
| import org.eclipse.birt.report.model.api.core.IModuleModel |
| import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants |
| import org.eclipse.birt.report.model.api.elements.structures.CachedMetaData |
| import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn |
| import org.eclipse.birt.report.model.api.elements.structures.OdaResultSetColumn |
| import org.eclipse.birt.report.model.api.metadata.DimensionValue |
| import org.eclipse.birt.report.model.elements.interfaces.IDataSetModel |
| import org.eclipse.birt.report.model.util.CssPropertyConstants |
| import org.eclipse.e4.core.di.extensions.EventUtils |
| import org.eclipse.e4.core.services.events.IEventBroker |
| import org.eclipse.emf.ecore.EObject |
| import org.eclipse.emf.ecore.resource.Resource |
| import org.eclipse.osbp.dsl.semantic.common.types.LDataType |
| import org.eclipse.osbp.dsl.semantic.common.types.LPackage |
| import org.eclipse.osbp.dsl.semantic.entity.LEntityAttribute |
| import org.eclipse.osbp.eventbroker.EventBrokerMsg |
| import org.eclipse.osbp.ui.api.datamart.IDataMart.EType |
| import org.eclipse.osbp.ui.api.report.IReportProvider |
| import org.eclipse.osbp.utils.entityhelper.DataType |
| import org.eclipse.osbp.utils.vaadin.ViewLayoutManager |
| import org.eclipse.osbp.xtext.action.common.IToolbarAction |
| import org.eclipse.osbp.xtext.basic.generator.BasicDslGeneratorUtils |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartAttribute |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartCube |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartDefinition |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartEntity |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartTask |
| import org.eclipse.osbp.xtext.datamartdsl.jvmmodel.DatamartDSLJvmModelInferrer |
| import org.eclipse.osbp.xtext.datamartdsl.util.DatamartAttributeUtil |
| import org.eclipse.osbp.xtext.i18n.DSLOutputConfigurationProvider |
| import org.eclipse.osbp.xtext.i18n.I18NKeyGenerator |
| import org.eclipse.osbp.xtext.i18n.I18NModelGenerator |
| import org.eclipse.osbp.xtext.reportdsl.AutoText |
| import org.eclipse.osbp.xtext.reportdsl.AutoTextEnum |
| import org.eclipse.osbp.xtext.reportdsl.DatamartTable |
| import org.eclipse.osbp.xtext.reportdsl.DatamartTableAttribute |
| import org.eclipse.osbp.xtext.reportdsl.Element |
| import org.eclipse.osbp.xtext.reportdsl.Grid |
| import org.eclipse.osbp.xtext.reportdsl.GridCell |
| import org.eclipse.osbp.xtext.reportdsl.Image |
| import org.eclipse.osbp.xtext.reportdsl.Label |
| import org.eclipse.osbp.xtext.reportdsl.NonTranslatableText |
| import org.eclipse.osbp.xtext.reportdsl.PageDetail |
| import org.eclipse.osbp.xtext.reportdsl.PageFooter |
| import org.eclipse.osbp.xtext.reportdsl.PageHeader |
| import org.eclipse.osbp.xtext.reportdsl.PageTemplate |
| import org.eclipse.osbp.xtext.reportdsl.Report |
| import org.eclipse.osbp.xtext.reportdsl.ReportDesignTemplate |
| import org.eclipse.osbp.xtext.reportdsl.ReportModel |
| import org.eclipse.osbp.xtext.reportdsl.ReportPackage |
| import org.eclipse.osbp.xtext.reportdsl.StringBinder |
| import org.eclipse.osbp.xtext.reportdsl.Style |
| import org.eclipse.osbp.xtext.reportdsl.SubSubTitle |
| import org.eclipse.osbp.xtext.reportdsl.SubTitle |
| import org.eclipse.osbp.xtext.reportdsl.TableAttribute |
| import org.eclipse.osbp.xtext.reportdsl.Text |
| import org.eclipse.osbp.xtext.reportdsl.Title |
| import org.eclipse.osbp.xtext.reportdsl.common.BaseReport |
| import org.eclipse.osbp.xtext.reportdsl.common.BirtEngine |
| import org.eclipse.osbp.xtext.reportdsl.common.DatatypeUtilities |
| import org.eclipse.osbp.xtext.reportdsl.common.OdaConnProperties |
| import org.eclipse.osbp.xtext.reportdsl.common.attribute.Attribute |
| import org.eclipse.osbp.xtext.reportdsl.common.attribute.Width |
| import org.eclipse.osbp.xtext.reportdsl.common.item.BaseItem |
| import org.eclipse.osbp.xtext.reportdsl.common.item.BodyItem |
| import org.eclipse.osbp.xtext.reportdsl.common.item.ContainerItem |
| import org.eclipse.osbp.xtext.reportdsl.common.item.DataUtils |
| import org.eclipse.osbp.xtext.reportdsl.common.item.GridItem |
| import org.eclipse.osbp.xtext.reportdsl.common.item.ImageItem |
| import org.eclipse.osbp.xtext.reportdsl.common.item.PageFooterItem |
| import org.eclipse.osbp.xtext.reportdsl.common.item.PageHeaderItem |
| import org.eclipse.xtext.generator.IFileSystemAccess |
| import org.eclipse.xtext.naming.IQualifiedNameProvider |
| import org.eclipse.xtext.xbase.compiler.GeneratorConfig |
| import org.eclipse.xtext.xbase.compiler.ImportManager |
| import org.osgi.service.event.Event |
| import org.osgi.service.event.EventHandler |
| import org.slf4j.Logger |
| import org.slf4j.LoggerFactory |
| import org.eclipse.xtext.util.Tuples |
| |
| class ReportModelGenerator extends I18NModelGenerator { |
| @Inject extension IQualifiedNameProvider |
| @Inject extension DatamartDSLJvmModelInferrer datamartInferrer |
| @Inject extension BasicDslGeneratorUtils |
| |
| @Inject |
| @Extension |
| private DataType dtType; |
| private static final Logger LOGGER = LoggerFactory.getLogger(typeof(ReportModelGenerator)); |
| |
| static var designEngine = null |
| |
| override void doGenerate(Resource input, IFileSystemAccess fsa) { |
| addTranslatables('''«BaseReport.CAPTION_I18NKEY_SAVE_PDF»,«BaseReport.CAPTION_I18NKEY_PRINT_PDF»''') |
| super.doGenerate(input, fsa) |
| } |
| |
| def dispatch void internalDoGenerate(ReportModel reportModel, IFileSystemAccess fsa) { |
| designEngine = BirtEngine.createDesignEngine() |
| for (pkg:reportModel.pckg) { |
| for (report : pkg.reports) { |
| try { |
| generateReportFile(pkg, report, fsa) |
| } |
| catch (Exception e) { |
| LOGGER.error("{}", e); |
| } |
| } |
| } |
| } |
| |
| private def void generateReportFile(ReportPackage pckg, Report report, IFileSystemAccess fsa) { |
| if (report.design instanceof ReportDesignTemplate) { |
| var workSet = new ReportGeneratorWorkSet() |
| workSet.generator = this |
| workSet.report = report |
| workSet.fsa = fsa |
| // --- generate full path name to the report design file to be generated --- |
| var template = report.design as ReportDesignTemplate |
| var pckgName = pckg.fullyQualifiedName.toString |
| var pckgNamePath = pckgName.replaceAll("\\.","/") |
| var filename = '''«report.name».rptdesign''' |
| var fullpath = '''«pckgNamePath»/«filename»''' |
| |
| // --- get managing BIRT instances --- |
| var session = (designEngine as IDesignEngine).newSessionHandle(ULocale.forLocale(Locale.getDefault())) |
| // --- Create a new report design --- |
| workSet.design = session.createDesign() |
| // --- The element factory creates instances of the various BIRT elements --- |
| workSet.factory = workSet.design.getElementFactory() |
| // set the i18n attribute resources |
| workSet.design.setIncludeResource("i18n/I18N") |
| // set the default unit |
| workSet.design.setProperty(DesignChoiceConstants.CHOICE_UNITS, report.defaultUnit.literal) |
| // set the requested media for this report |
| workSet.requestedMedia = report.media |
| |
| var body = new BodyItem(workSet) |
| // --- add the master datamart --- |
| addDatamartSourceAndSet(report.datamartRef, workSet, null, null) |
| |
| // --- generate a master page --- |
| generateMasterPage(report.datamartRef, workSet, report.pageTemplate, template.header, template.footer) |
| |
| generateItems(report.datamartRef, workSet, body, template.detail.elements) |
| |
| // --- generate an output stream to receive the BIRT generated report design --- |
| var baos = new ByteArrayOutputStream() |
| try { |
| workSet.design.getModule().prepareToSave(); |
| workSet.design.getModule().getWriter().write(baos); |
| workSet.design.getModule().onSave(); |
| } |
| catch (Exception e) { |
| baos = new ByteArrayOutputStream() |
| e.printStackTrace(new PrintStream(baos)) |
| } |
| |
| // --- generated output stream to the file --- |
| fsa.generateFile(fullpath, DSLOutputConfigurationProvider.DEFAULT_REPORT_OUTPUT, baos.toString()) |
| } |
| } |
| |
| private def generateMasterPage(DatamartDefinition datamart, ReportGeneratorWorkSet workSet, PageTemplate pageTemplate, PageHeader pageHeader, PageFooter pageFooter) { |
| // Note: The report will fail to load in the BIRT designer unless you create a master page. |
| var header = pageHeader |
| var footer = pageFooter |
| if (header === null) { |
| header = pageTemplate.header |
| } |
| if (footer === null) { |
| footer = pageTemplate.footer |
| } |
| var masterPage = workSet.factory.newSimpleMasterPage(pageTemplate.name); //$NON-NLS-1$ |
| masterPage.setPageType(pageTemplate.size.name().toLowerCase); |
| masterPage.setOrientation(pageTemplate.orientation.name().toLowerCase) |
| masterPage.leftMargin.setValue(new DimensionValue(pageTemplate.leftMarginValue, workSet.report.defaultUnit.literal)) |
| masterPage.topMargin.setValue(new DimensionValue(pageTemplate.topMarginValue, workSet.report.defaultUnit.literal)) |
| masterPage.bottomMargin.setValue(new DimensionValue(pageTemplate.bottomMarginValue, workSet.report.defaultUnit.literal)) |
| masterPage.rightMargin.setValue(new DimensionValue(pageTemplate.rightMarginValue, workSet.report.defaultUnit.literal)) |
| if (header !== null) { |
| masterPage.setShowHeaderOnFirst(header.showOnFirst) |
| masterPage.headerHeight.setValue(new DimensionValue(header.heightValue, workSet.report.defaultUnit.literal)) |
| generateItems(datamart, workSet, new PageHeaderItem(workSet, masterPage), header.elements) |
| } |
| if (footer !== null) { |
| masterPage.setShowFooterOnLast(footer.showOnLast) |
| masterPage.footerHeight.setValue(new DimensionValue(footer.heightValue, workSet.report.defaultUnit.literal)) |
| generateItems(datamart, workSet, new PageFooterItem(workSet, masterPage), footer.elements) |
| } |
| workSet.design.getMasterPages().add(masterPage); |
| } |
| |
| private def addDatamartSourceAndSet(DatamartDefinition datamart, ReportGeneratorWorkSet workSet, String alias, DatamartAttribute[] hiddens) { |
| // --- generate the Data Source --- |
| var dataSourceName = Utilities.getDataSourceName(alias, datamart).toString |
| var slot = workSet.design.getModule().getSlot(IModuleModel.DATA_SOURCE_SLOT) |
| var createDataSource = true |
| for (slotElem : slot.contents){ |
| if (dataSourceName.equals(slotElem.name)){ |
| // if a data source with this dataSourceName already exists in the data source slot |
| // the creation of a identical data source is not allowed. |
| createDataSource = false |
| } |
| } |
| // to avoid the creation of duplicated data source and data set entries!!! |
| if (createDataSource){ |
| var odsourceh = workSet.factory.newOdaDataSource(dataSourceName, BaseReport.DATASOURCE_EXTENSION_ID); |
| odsourceh.getElement().setID(workSet.design.getModule().getNextID()); |
| workSet.design.getModule().addElementID(odsourceh.getElement()); |
| workSet.design.getModule().add(odsourceh.getElement(), IModuleModel.DATA_SOURCE_SLOT); |
| |
| // --- generate the Data Set connected to the Data Source --- |
| var dataSetName = Utilities.getDataSetName(alias, datamart).toString |
| var odseth = workSet.factory.newOdaDataSet(dataSetName, BaseReport.DATASOURCE_EXTENSION_ID.concat(".dataSet")); |
| workSet.dataSets.put(dataSetName, odseth) |
| odseth.getElement().setID(workSet.design.getModule().getNextID()); |
| odseth.setProperty(OdaConnProperties.DATAMART_BUNDLENAME, Utilities.getBundleName(datamart)); |
| odseth.setProperty(OdaConnProperties.DATAMART_CLASSNAME, getDatamartClassName(alias, datamart)); |
| odseth.setProperty(OdaConnProperties.DATAMART_DATASOURCE, odsourceh.getElement().getName()); |
| odseth.setProperty(OdaConnProperties.DATAMART_DATASOURCENAME, dataSourceName); |
| odseth.setProperty(OdaConnProperties.DATAMART_DATASETNAME, dataSetName); |
| // --- add additional informations to the Data Set --- |
| switch (datamart.source) { |
| DatamartCube: |
| addDatamartCubeResultSet(workSet, odseth, dataSetName, datamart) |
| DatamartEntity: |
| addDatamartEntityResultSet(workSet, odseth, dataSetName, datamart) |
| DatamartTask: |
| LOGGER.error("DatamartTask ... todo") |
| } |
| workSet.design.getModule().addElementID(odseth.getElement()); |
| workSet.design.getModule().add(odseth.getElement(), IModuleModel.DATA_SET_SLOT); |
| } |
| } |
| |
| private def addDatamartCubeResultSet(ReportGeneratorWorkSet workSet, OdaDataSetHandle odseth, String dataSetName, DatamartDefinition datamart) { |
| System.err.println("DatamartCube ... todo") |
| |
| // var cube = datamart.source as DatamartCube; |
| var selectColumns = "" |
| var cmd = new CachedMetaData() |
| var sd = new ArrayList<OdaResultSetColumn>() |
| // var cc = new ArrayList<ComputedColumn>() |
| |
| // var position = 0 |
| // // --- at first all navigations --- |
| // for (navigation : entity.navigations) { |
| // for (attribute : navigation.datamartEntity.attributes) { |
| // if ((hiddens == null) || !hiddens.contains(attribute)) { |
| // position = position+1 |
| // addDatamartAttribute(sd, cc, attribute, position) |
| // } |
| // } |
| // } |
| // // --- at last the "pure" data attributes --- |
| // for (attribute : entity.attributes) { |
| // if ((hiddens == null) || !hiddens.contains(attribute)) { |
| // position = position+1 |
| // addDatamartAttribute(sd, cc, attribute, position) |
| // } |
| // } |
| // workSet.putResultSetColumns(dataSetName, sd) |
| // workSet.putComputedColumns(dataSetName, cc) |
| // for (cc1 : cc) { |
| // if (selectColumns.empty) { |
| // selectColumns = cc1.getName(); |
| // } |
| // else { |
| // selectColumns = selectColumns+","+cc1.getName(); |
| // } |
| // } |
| |
| odseth.setProperty("queryText", ('''select «selectColumns» from «datamart.name»''').toString()) |
| cmd.setProperty(IDataSetModel.RESULT_SET_PROP, sd) |
| odseth.setProperty(IDataSetModel.CACHED_METADATA_PROP, cmd) |
| odseth.getElement().setProperty(IDataSetModel.RESULT_SET_PROP, sd) |
| } |
| |
| private def void addAllDatamartProperties(ReportGeneratorWorkSet workSet, ArrayList<OdaResultSetColumn> sd, ArrayList<ComputedColumn> cc, EObject eObject) { |
| switch eObject { |
| DatamartEntity: { |
| // --- only for not suppressed datamart entity attributes --- |
| if (!eObject.suppressAttributes) { |
| // --- at first all navigations --- |
| for (navigation : eObject.navigations) { |
| navigation.eAllContents.forEach[element | |
| addAllDatamartProperties(workSet, sd, cc, element) |
| ] |
| } |
| // --- if no explicit attributes are set --- |
| if (eObject.attributes.nullOrEmpty) { |
| DatamartAttributeUtil.fillEmptyAttributes(eObject) |
| } |
| for (datamartAttribute : eObject.attributes) { |
| var attribute = datamartAttribute.attributeRef |
| if (!attribute.isId && !attribute.isUuid && !attribute.isVersion && !attribute.isTransient) { |
| addDatamartAttribute(workSet, sd, cc, datamartAttribute) |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| private def addDatamartEntityResultSet(ReportGeneratorWorkSet workSet, OdaDataSetHandle odseth, String dataSetName, DatamartDefinition datamart) { |
| var selectColumns = "" |
| var cmd = new CachedMetaData() |
| var sd = new ArrayList<OdaResultSetColumn>() |
| var cc = new ArrayList<ComputedColumn>() |
| |
| workSet.setPosition(0) |
| addAllDatamartProperties(workSet, sd, cc, datamart.source) |
| workSet.putResultSetColumns(dataSetName, sd) |
| workSet.putComputedColumns(dataSetName, cc) |
| for (cc1 : cc) { |
| if (selectColumns.empty) { |
| selectColumns = cc1.getName(); |
| } |
| else { |
| selectColumns = selectColumns.concat(",").concat(cc1.getName()); |
| } |
| } |
| odseth.setProperty("queryText", ('''select «selectColumns» from «datamart.name»''').toString()) |
| cmd.setProperty(IDataSetModel.RESULT_SET_PROP, sd) |
| odseth.setProperty(IDataSetModel.CACHED_METADATA_PROP, cmd) |
| odseth.getElement().setProperty(IDataSetModel.RESULT_SET_PROP, sd) |
| } |
| |
| private def addDatamartAttribute(ReportGeneratorWorkSet workSet, ArrayList<OdaResultSetColumn> sd, ArrayList<ComputedColumn> cc, DatamartAttribute datamartAttribute) { |
| // --- general information about the column --- |
| var attribute = datamartAttribute.attributeRef |
| var dataType = DatatypeUtilities.getDatatype(datamartAttribute, dtType) |
| var name = DatamartAttributeUtil.getAliasedAttributeName(datamartAttribute) |
| // --- check for already found column --- |
| for (column : sd) { |
| if (column.columnName.equalsIgnoreCase(name)) { |
| return |
| } |
| } |
| // --- information needed to access via oda --- |
| var st = new OdaResultSetColumn() |
| st.setColumnName(name) |
| st.setProperty("name", name) |
| st.setNativeDataType(dataType.getNativeOdaDataTypeId()) |
| st.setNativeName(name) |
| workSet.setPosition(workSet.getPosition()+1) |
| st.setPosition(workSet.getPosition()) |
| st.setDataType(dataType.getNativeOdaDataTypeName()) |
| sd.add(st) |
| // --- information needed to access via table --- |
| var cs1 = StructureFactory.createComputedColumn() |
| cs1.setName(name) |
| cs1.setDisplayName(name); |
| cs1.setExpression("dataSetRow[\"".concat(name).concat("\"]")) |
| var scalartype = datamartAttribute.attributeRef.type |
| if (scalartype instanceof LDataType){ |
| cs1.setDataType(DatatypeUtilities.getDatatypeName(datamartAttribute, dtType)) |
| } |
| cs1.setProperties(attribute) |
| cc.add(cs1) |
| } |
| |
| private def setProperties(ComputedColumn column, LEntityAttribute attribute){ |
| var lDataType = getLDataType(attribute) |
| if (lDataType !== null) { |
| for (prop : lDataType.properties) { |
| column.setProperty(prop.key, prop.value) |
| } |
| } |
| } |
| |
| private def getDatamartClassName(String alias, DatamartDefinition datamart) { |
| '''«(datamart.eContainer as LPackage).fullyQualifiedName».«datamart.name»Class''' |
| } |
| |
| public def void generateItems(DatamartDefinition datamart, ReportGeneratorWorkSet workSet, ContainerItem container, Element[] elements) { |
| if (elements !== null) { |
| for (element : elements) { |
| try { |
| switch (element) { |
| Title: |
| container.addHeader(1, I18NKeyGenerator.key(element.text), element.text.replace("\"",""), element.style) |
| SubTitle: |
| container.addHeader(2, I18NKeyGenerator.key(element.text), element.text.replace("\"",""), element.style) |
| SubSubTitle: |
| container.addHeader(3, I18NKeyGenerator.key(element.text), element.text.replace("\"",""), element.style) |
| Label: |
| container.addLabel(I18NKeyGenerator.key(element.text), element.text.replace("\"",""), element.style) |
| Text: |
| if (element.textContentType.literal.equals(BaseItem.CONTENT_TYPE_HTML)) { |
| container.addText(I18NKeyGenerator.key(element.text), element.text, element.style, BaseItem.CONTENT_TYPE_HTML) |
| } else { |
| container.addText(I18NKeyGenerator.key(element.text), element.text.replace("\"",""), element.style) |
| } |
| NonTranslatableText: |
| container.addText(element.value.replace("\"",""), null) |
| AutoText: |
| if (element.type.equals(AutoTextEnum.ACTUAL_DATE) || element.type.equals(AutoTextEnum.ACTUAL_TIME)){ |
| container.addText(element.type, element.style) |
| } else if (element.type.equals(AutoTextEnum.REPORT_NAME)) { |
| var text = workSet.report.name |
| container.addLabel(text, text.replace("\"",""), element.style) |
| } else { |
| container.addAutoText(element.type.toString, element.style) |
| } |
| StringBinder: |
| container.addText(datamart, (element as StringBinder), dtType, element.style) |
| DatamartTableAttribute: { |
| var eObj = element.eContainer |
| while(eObj !== null && |
| !(eObj instanceof PageHeader) && |
| !(eObj instanceof PageFooter) && |
| !(eObj instanceof PageDetail)) { |
| eObj = eObj.eContainer |
| } |
| if(eObj instanceof PageHeader || eObj instanceof PageFooter) { |
| if((element as DatamartTableAttribute).column instanceof TableAttribute) { |
| if (((element as DatamartTableAttribute).column as TableAttribute).valueRef.attributeRef.basicType == EType.BLOPMAPPING) { |
| container.addDataImage(element, element.style) |
| // } else if (((element as DatamartTableAttribute).column as TableAttribute).valueRef.attributeRef.basicType == EType.BOOLEAN_CHECKBOX) { |
| // container.addBooleanCheckbox(element, element.style) |
| } else { |
| var datamartAttribute = ((element as DatamartTableAttribute).column as TableAttribute).valueRef |
| var dataTypeStr = DatatypeUtilities.getDatatypeName(datamartAttribute, dtType) |
| var pair = Tuples.create(datamartAttribute, dataTypeStr) |
| var datamartAttributes = newArrayList(pair) |
| container.addText(datamart, datamartAttributes, element.style) |
| } |
| } |
| } else { |
| if(element instanceof DatamartTableAttribute) { |
| if((element as DatamartTableAttribute).column instanceof TableAttribute && |
| ((element as DatamartTableAttribute).column as TableAttribute).valueRef.attributeRef.basicType == EType.BLOPMAPPING) { |
| container.addDataImage(element, element.style) |
| } else if ((element.eContainer instanceof GridCell) && ((element as DatamartTableAttribute).column instanceof TableAttribute)) { |
| var datamartAttribute = ((element as DatamartTableAttribute).column as TableAttribute).valueRef |
| var dataTypeStr = DatatypeUtilities.getDatatypeName(datamartAttribute, dtType) |
| container.addFlexibleData(element, datamart, datamartAttribute, element.style, dataTypeStr) |
| } else { |
| // Being a DatamartAttribute outside of a grid |
| // the dataSet and boundDataColumns are required |
| |
| // datamart alias do not exist on a grid |
| var datamartAlias = null |
| var hiddens = new ArrayList<DatamartAttribute> |
| var dataSetName = Utilities.getDataSetName(datamartAlias, datamart).toString |
| var dataSet = workSet.dataSets.get(dataSetName) |
| if (dataSet === null) { |
| addDatamartSourceAndSet(datamart, workSet, datamartAlias, hiddens) |
| dataSet = workSet.dataSets.get(dataSetName) |
| } |
| container.addData(element, dataSet, dataSetName, element.style) |
| } |
| } |
| } |
| } |
| Image: |
| addImage(workSet, container, element, null) |
| DatamartTable: |
| addDatamartTable(datamart, |
| workSet, container, element, |
| new Width("100%") |
| ) |
| Grid: |
| addGrid(datamart, |
| workSet, container, element, element.style |
| ) |
| } |
| } |
| catch (ContentException ce) { |
| LOGGER.error("{}", ce) |
| } |
| catch (Exception e) { |
| LOGGER.error("{}", e) |
| } |
| } |
| } |
| } |
| |
| private def addDatamartTable(DatamartDefinition datamart, ReportGeneratorWorkSet workSet, ContainerItem container, DatamartTable datamartTable, Attribute... attributes) { |
| var newDatamart = datamart |
| if (datamartTable.datamartRef !== null) { |
| newDatamart = datamartTable.datamartRef |
| } |
| var hiddens = new ArrayList<DatamartAttribute> |
| var alias = datamartTable.name |
| var dataSetName = Utilities.getDataSetName(alias, newDatamart).toString |
| var dataSet = workSet.dataSets.get(dataSetName) |
| if (dataSet === null) { |
| addDatamartSourceAndSet(newDatamart, workSet, alias, hiddens) |
| dataSet = workSet.dataSets.get(dataSetName) |
| } |
| container.addTable(newDatamart, dataSet, datamartTable, workSet.getComputedColumns(dataSetName), datamartTable.groups, datamartTable.detail.style, datamartTable.detail.columnFormatters, datamartTable.style, attributes) |
| } |
| |
| private def addImage(ReportGeneratorWorkSet workSet, ContainerItem container, Image imageData, Style style, Attribute... attributes) { |
| var image = new ImageItem( |
| workSet, |
| null, |
| imageData.size.literal, |
| imageData.scale, |
| imageData.heightValue, |
| imageData.heightUnit, |
| imageData.widthValue, |
| imageData.widthUnit, |
| imageData.sourceType.literal, |
| imageData.filename |
| ) |
| container.add(image, style, attributes) |
| } |
| |
| private def addGrid(DatamartDefinition datamart, ReportGeneratorWorkSet workSet, ContainerItem container, Grid grid, Style style, Attribute... attributes) { |
| // datamart alias do not exist on a grid |
| var datamartAlias = null |
| var hiddens = new ArrayList<DatamartAttribute> |
| var dataSetName = Utilities.getDataSetName(datamartAlias, datamart).toString |
| var dataSet = workSet.dataSets.get(dataSetName) |
| if (dataSet === null) { |
| addDatamartSourceAndSet(datamart, workSet, datamartAlias, hiddens) |
| dataSet = workSet.dataSets.get(dataSetName) |
| } |
| val gridItem = new GridItem( |
| workSet, |
| dataSet, |
| workSet.getComputedColumns(dataSetName), |
| grid); |
| |
| // grid width |
| var List<Attribute> attributeList = newArrayList |
| for (attribute : attributes) { |
| attributeList.add(attribute) |
| } |
| var propValue = "" |
| if (grid.widthValue !== 0) { |
| propValue = workSet.getLocalizedDoubleValue(gridItem.handle, grid.widthValue) |
| } else { |
| propValue = "100%" |
| } |
| attributeList.add(new Width(propValue)) |
| var newAttributes = attributeList.toArray(newArrayOfSize(attributeList.size)) |
| // |
| |
| if (grid.visibilityItem !== null && grid.visibilityItem.visibility){ |
| DataUtils.addVisibility(gridItem.handle, grid.visibilityItem.visibilityAttribute); |
| } |
| var rowNo = 0 |
| // max cell width map used to identify the max column width |
| var maxCellWidthMap = <Integer, Double>newHashMap() |
| for (row : grid.rows) { |
| var rowHandle = (gridItem.handle as GridHandle).rows.get(rowNo) as RowHandle |
| if (row.visibilityItem !== null && row.visibilityItem.visibility){ |
| DataUtils.addVisibility(rowHandle, row.visibilityItem.visibilityAttribute); |
| } |
| var columnNo = 0 |
| for (cell : row.cells) { |
| if (cell.widthValue != 0) { |
| var cellHandle = rowHandle.cells.get(columnNo) |
| cellHandle.setStringProperty(CssPropertyConstants.WIDTH, '''«workSet.getLocalizedDoubleValue(gridItem.handle, cell.widthValue)»''') |
| if (maxCellWidthMap.empty || maxCellWidthMap.get(columnNo) === null || maxCellWidthMap.get(columnNo) < cell.widthValue) { |
| maxCellWidthMap.put(columnNo, cell.widthValue) |
| } |
| } |
| if (cell.style !== null) { |
| gridItem.applyCellStyle(rowHandle, columnNo, cell.style) |
| } |
| if (cell.visibilityItem !== null && cell.visibilityItem.visibility){ |
| var cellHandle = rowHandle.cells.get(columnNo) |
| DataUtils.addVisibility(cellHandle, cell.visibilityItem.visibilityAttribute); |
| } |
| generateItems(datamart, workSet, gridItem.getCell(columnNo, rowNo).setColumnSpan(cell.columnspan), cell.elements) |
| columnNo = columnNo+1 |
| } |
| |
| if (row.style !== null) { |
| gridItem.applyRowStyle(rowNo, row.style) |
| } |
| if (row.heightValue !== 0) { |
| gridItem.setRowHeight(rowNo, row.heightValue) |
| } |
| rowNo = rowNo+1 |
| } |
| maxCellWidthMap.forEach[columnIdx, columnWidth | |
| if (columnWidth != 0.0) { |
| ((gridItem.handle as GridHandle).columns.get(columnIdx) as ColumnHandle).setStringProperty(CssPropertyConstants.WIDTH, '''«workSet.getLocalizedDoubleValue(gridItem.handle, columnWidth)»''') |
| } |
| ] |
| container.add(gridItem, style, newAttributes) |
| } |
| |
| override createAppendable(EObject context, ImportManager importManager, GeneratorConfig config) { |
| // required to initialize the needed builder to avoid deprecated methods |
| builder = context.eResource |
| // --------- |
| addImportFor(importManager, _typeReferenceBuilder |
| , ReportGeneratorWorkSet |
| , HorizontalLayout |
| , ViewLayoutManager |
| , BrowserFrame |
| , StreamResource |
| , Unit |
| , Button |
| , com.vaadin.ui.Label |
| , IEventBroker |
| , EventHandler |
| , Event |
| , EventUtils |
| , EventBrokerMsg |
| , CustomMsgException |
| , IReportProvider.Rendering |
| , AbstractComponent |
| , UUID |
| , Filter |
| , IToolbarAction |
| , HashMap) |
| super.createAppendable(context, importManager, config) |
| } |
| |
| } |