blob: 81c2f2758382770fce6d826df4b725d33ace9f55 [file] [log] [blame]
/**
*
* 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
*/
package org.eclipse.osbp.xtext.reportdsl.common.item;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osbp.utils.entityhelper.DataType;
import org.eclipse.osbp.xtext.datamartdsl.DatamartAttribute;
import org.eclipse.osbp.xtext.datamartdsl.DatamartDefinition;
import org.eclipse.osbp.xtext.reportdsl.AutoText;
import org.eclipse.osbp.xtext.reportdsl.AutoTextEnum;
import org.eclipse.osbp.xtext.reportdsl.DatamartTableAttribute;
import org.eclipse.osbp.xtext.reportdsl.DatamartTableGroup;
import org.eclipse.osbp.xtext.reportdsl.Element;
import org.eclipse.osbp.xtext.reportdsl.GridCell;
import org.eclipse.osbp.xtext.reportdsl.GridRow;
import org.eclipse.osbp.xtext.reportdsl.Report;
import org.eclipse.osbp.xtext.reportdsl.StringBinder;
import org.eclipse.osbp.xtext.reportdsl.Style;
import org.eclipse.osbp.xtext.reportdsl.UnitEnum;
import org.eclipse.osbp.xtext.reportdsl.VisibilityItem;
import org.eclipse.osbp.xtext.reportdsl.WithHeaderFooter;
import org.eclipse.osbp.xtext.reportdsl.WithStyle;
import org.eclipse.osbp.xtext.reportdsl.common.attribute.Attribute;
import org.eclipse.osbp.xtext.reportdsl.common.attribute.StyleName;
import org.eclipse.osbp.xtext.reportdsl.common.attribute.TextAlign;
import org.eclipse.osbp.xtext.reportdsl.common.attribute.TextAlign.Align;
import org.eclipse.osbp.xtext.reportdsl.common.attribute.Visibility;
import org.eclipse.osbp.xtext.reportdsl.common.attribute.Width;
import org.eclipse.osbp.xtext.reportdsl.jvmmodel.ReportGeneratorWorkSet;
import org.eclipse.xtext.util.Pair;
public abstract class ContainerItem extends AContainerItem {
private Visibility getVisibilityAttribute(EObject container) {
return (container instanceof VisibilityItem) ? new Visibility(((VisibilityItem)container).getVisibilityItem()) : null;
}
public ContainerItem(ReportGeneratorWorkSet workset) {
super(workset);
}
private Style getStyle(Element element) {
return (element instanceof WithStyle) ? ((WithStyle)element).getStyle() : null;
}
public void addHeader(int level, String i18nKey, String title, Element element) throws SemanticException {
Style style = getStyle(element);
add(
new TextItem(fWorkset, i18nKey, "<h"+level+">"+title+"</h"+level+">", BaseItem.CONTENT_TYPE_HTML),
style,
new Width("100%"),
new TextAlign(Align.center),
new StyleName("h"+level)
);
}
public void addLabel(String i18nKey, String text, Element element) throws SemanticException {
Style style = getStyle(element);
add(
new LabelItem(fWorkset, i18nKey, text),
style
);
}
public void addText(String i18nKey, String text, Element element) throws SemanticException {
Style style = getStyle(element);
add(
new TextItem(fWorkset, i18nKey, text, BaseItem.CONTENT_TYPE_PLAIN),
style
);
}
public void addText(String i18nKey, String text, Element element, String contentType) throws SemanticException {
Style style = getStyle(element);
add(
new TextItem(fWorkset, i18nKey, text, contentType),
style
);
}
public void addText(String text, Element element) throws SemanticException {
Style style = getStyle(element);
add(
new TextItem(fWorkset, text, BaseItem.CONTENT_TYPE_PLAIN),
style,
getVisibilityAttribute(element.eContainer())
);
}
public void addText(DatamartDefinition datamart, List<Pair<DatamartAttribute, String>> datamartAttributes, Style style) throws SemanticException {
add(
new TextItem(fWorkset, BaseItem.CONTENT_TYPE_HTML, datamart, datamartAttributes),
style,
getVisibilityAttribute(datamart.eContainer())
);
}
public void addText(DatamartDefinition datamart, StringBinder stringBinder, DataType dtType, Style style) throws SemanticException {
add(
new TextItem(fWorkset, BaseItem.CONTENT_TYPE_HTML, datamart, stringBinder, dtType),
style,
getVisibilityAttribute(datamart.eContainer())
);
}
public void addText(AutoTextEnum autoTextEnum, Element element) throws SemanticException {
Style style = getStyle(element);
add(
new TextItem(fWorkset, BaseItem.CONTENT_TYPE_HTML, autoTextEnum),
style
);
}
public void addAutoText(AutoText element) throws SemanticException {
String type = element.getType().toString();
Style style = getStyle(element);
add(
new AutoTextItem(fWorkset, type),
style
);
}
public void addAutoText(AutoTextEnum autoTextEnum, Element element) throws SemanticException {
Style style = getStyle(element);
add(
new AutoTextItem(fWorkset, autoTextEnum.toString()),
style
);
}
public TableItem createTable() {
return new TableItem(fWorkset);
}
public TableItem createTable(int columns) {
return new TableItem(fWorkset, columns);
}
public void addTable(DatamartDefinition datamart, DataSetHandle dataSet, WithHeaderFooter withHeaderFooter, List<ComputedColumn> boundColumns, DatamartTableGroup[] groups, Style propertiesStyle, DatamartTableAttribute[] tableProperties, Style style, Attribute[] attributes) throws SemanticException { // NOSONAR
// int size = attributes.length;
// attributes[size] = getVisibilityAttribute(datamart.eContainer());
List<Attribute> attributeList = new ArrayList<>(Arrays.asList(attributes));
attributeList.add(getVisibilityAttribute(withHeaderFooter));
add(
new TableItem(datamart, fWorkset, dataSet, withHeaderFooter, boundColumns, groups, propertiesStyle, tableProperties),
style,
// attributes
attributeList.toArray(new Attribute[attributeList.size()])
);
}
public void addFlexibleData(DatamartTableAttribute tableAttribute, DatamartDefinition datamart, DatamartAttribute datamartAttribute, Style style, String dataTypeStr) throws SemanticException {
add(
getBaseItem(tableAttribute, datamartAttribute, dataTypeStr),
// new DataItem(fWorkset, tableAttribute),
style,
getVisibilityAttribute(tableAttribute.eContainer())
);
}
public void addData(DatamartTableAttribute tableAttribute, DataSetHandle dataSet, String dataSetName, Style style) throws SemanticException {
add(
new DataItem(fWorkset, dataSet, fWorkset.getComputedColumns(dataSetName), tableAttribute),
style,
getVisibilityAttribute(tableAttribute.eContainer())
);
}
public void addDataImage(DatamartTableAttribute tableAttribute, Style style) throws SemanticException {
double height = -1.0d;
double width = -1.0d;
UnitEnum defaultUnit = UnitEnum.MM;
if (tableAttribute.getWidthValue() > 0.0) {
width = tableAttribute.getWidthValue();
}
EObject eObj = tableAttribute.eContainer();
while (eObj != null && !(eObj instanceof GridCell)) {
eObj = eObj.eContainer();
}
if (eObj != null && ((GridCell)eObj).getWidthValue() > 0.0) {
width = ((GridCell)eObj).getWidthValue();
}
while (eObj != null && !(eObj instanceof GridRow)) {
eObj = eObj.eContainer();
}
if (eObj != null && ((GridRow)eObj).getHeightValue() > 0.0) {
height = ((GridRow)eObj).getHeightValue();
}
while (eObj != null && !(eObj instanceof Report)) {
eObj = eObj.eContainer();
}
if (eObj != null && ((Report)eObj).getDefaultUnit() != null) {
defaultUnit = ((Report)eObj).getDefaultUnit();
}
add(new ImageItem(fWorkset, DataUtils.getAttributeName(tableAttribute), DesignChoiceConstants.IMAGE_SIZE_SIZE_TO_IMAGE, -1.0d, height, defaultUnit, width, defaultUnit, DesignChoiceConstants.IMAGE_REF_TYPE_EXPR, null),
style,
getVisibilityAttribute(tableAttribute.eContainer())
);
}
public void addHeaderData(DatamartTableAttribute tableAttribute, Style style) throws SemanticException {
add(
new DataItem(fWorkset, tableAttribute),
style,
getVisibilityAttribute(tableAttribute.eContainer())
);
}
}