import {GroupBase} from "./GroupBase"; import {Report} from "../Report"; import {GroupHeaderBand, GroupFooterBand, GroupBand} from "./GroupBand"; import {Collection} from "../../collection/Collection"; import {JRGroup} from "../../jasper/JRGroup"; import {JRSection} from "../../jasper/JRSection"; import {JRDesignSection} from "../../jasper/JRDesignSection"; import {FooterPositionEnum} from "../../jasper/type/Enums"; export class Group extends GroupBase implements JRGroup { private _report: Report; private _groupHeader: GroupHeaderBand; private _groupFooter: GroupFooterBand; private _isStartNewColumn:boolean; private _isStartNewPage:boolean; private _isResetPageNumber:boolean; private _isReprintHeaderOnEachPage:boolean; private _minHeightToStartNewPage:number; private _footerPositionValue:FooterPositionEnum; private _isKeepTogether:boolean; constructor(createHeaderFooter = false) { super(); if (createHeaderFooter) { this._groupHeader = new GroupHeaderBand(this); this._groupFooter = new GroupFooterBand(this); } } get name():string { return this._name; } set name(value:string) { this._name = value; } get groupHeader():GroupHeaderBand { return this._groupHeader; } set groupHeader(value:GroupHeaderBand) { this._groupHeader = value; if (this._groupHeader) { this._groupHeader.group = this; this.initGroupBand(this._groupHeader); } else{ this.check(); } } get groupFooter():GroupFooterBand { return this._groupFooter; } set groupFooter(value:GroupFooterBand) { this._groupFooter = value; if (this._groupFooter) { this._groupFooter.group = this; this.initGroupBand(this._groupFooter); } else{ this.check(); } } get report():Report { return this._report; } set report(value:Report) { if (value !== this._report) { this._report = value; this.initGroupBand(this._groupHeader); this.initGroupBand(this._groupFooter); //如果没有名字,则设置一个名字 if (!this._name){ const groups = value.groups; const len = groups.length; if(len>1){ for(let i=1;i<=len;i++){ const hasI = groups.find( group => group.name === "Group"+i ); if(!hasI){ this._name = "Group"+i; break; } } } else{ this._name = "Group1"; } } } } private initGroupBand(band:GroupBand):void { if (band && band.parent != this._report) { band.parent = this._report; } } private check(){ if (!this._groupHeader && !this._groupFooter){ const groups = this._report.groups; groups.map( (group, index) => { if(group == this){ groups.splice(index,1); } }) } } // ---------------- JRGroup implements block begin getName():string { return this.name; } setName(value:string):void { this.name = value; } isStartNewColumn():boolean { return this._isStartNewColumn; } setStartNewColumn(value:boolean):void { this._isStartNewColumn = value; } isStartNewPage():boolean { return this._isStartNewPage; } setStartNewPage(isStart:boolean):void { this._isStartNewPage = isStart; } isResetPageNumber():boolean { return this._isResetPageNumber; } setResetPageNumber(value:boolean):void { this._isResetPageNumber = value; } isReprintHeaderOnEachPage():boolean { return this._isReprintHeaderOnEachPage; } setReprintHeaderOnEachPage(value:boolean):void { this._isReprintHeaderOnEachPage = value; } getMinHeightToStartNewPage():number { return this._minHeightToStartNewPage; } setMinHeightToStartNewPage(value:number):void { this._minHeightToStartNewPage = value; } getFooterPositionValue():FooterPositionEnum { return this._footerPositionValue; } setFooterPosition(value:FooterPositionEnum):void { this._footerPositionValue = value; } isKeepTogether() { return this._isKeepTogether; } setKeepTogether(value:boolean):void { this._isKeepTogether = value; } getGroupHeaderSection():JRSection { if (this.groupHeader) { return new JRDesignSection(this.groupHeader); } } getGroupFooterSection():JRSection { if (this.groupFooter) { return new JRDesignSection(this.groupFooter); } } // ---------------- JRGroup implements block end } export class GroupCollection extends Collection { }