ソースを参照

改进page以及pages函数使用范围,由原来只能在页眉页脚使用改成可以在所有地方使用

master
jacky6024 6年前
コミット
bfcbaa3b2b
  1. 10
      ureport2-core/src/main/java/com/bstek/ureport/build/Context.java
  2. 6
      ureport2-core/src/main/java/com/bstek/ureport/build/ReportBuilder.java
  3. 1
      ureport2-core/src/main/java/com/bstek/ureport/build/compute/ExpressionValueCompute.java
  4. 32
      ureport2-core/src/main/java/com/bstek/ureport/build/paging/BasePagination.java
  5. 2
      ureport2-core/src/main/java/com/bstek/ureport/build/paging/FitPagePagination.java
  6. 2
      ureport2-core/src/main/java/com/bstek/ureport/build/paging/FixRowsPagination.java
  7. 19
      ureport2-core/src/main/java/com/bstek/ureport/build/paging/PagingBuilder.java
  8. 3
      ureport2-core/src/main/java/com/bstek/ureport/definition/HeaderFooterDefinition.java
  9. 6
      ureport2-core/src/main/java/com/bstek/ureport/expression/function/page/PageNumberFunction.java
  10. 10
      ureport2-core/src/main/java/com/bstek/ureport/model/Row.java

10
ureport2-core/src/main/java/com/bstek/ureport/build/Context.java

@ -55,6 +55,7 @@ public class Context {
private Map<String,Object> parameters;
private HideRowColumnBuilder hideRowColumnBuilder;
private ElCalculator elCalculator=new ElCalculator();
private List<Cell> existPageFunctionCells=new ArrayList<Cell>();
private Map<String,List<Cell>> unprocessedCellsMap = new HashMap<String,List<Cell>>();
private Map<Row,Map<Column,Cell>> blankCellsMap=new HashMap<Row,Map<Column,Cell>>();
private Map<Row,Integer> fillBlankRowsMap=new HashMap<Row,Integer>();
@ -294,6 +295,15 @@ public class Context {
public List<Row> getCurrentPageRows() {
return currentPageRows;
}
public void addExistPageFunctionCells(Cell cell) {
existPageFunctionCells.add(cell);
}
public List<Cell> getExistPageFunctionCells() {
return existPageFunctionCells;
}
public int getTotalPages() {
return totalPages;
}

6
ureport2-core/src/main/java/com/bstek/ureport/build/ReportBuilder.java

@ -34,6 +34,7 @@ import com.bstek.ureport.build.cell.down.DownExpandBuilder;
import com.bstek.ureport.build.cell.right.RightExpandBuilder;
import com.bstek.ureport.build.paging.BasePagination;
import com.bstek.ureport.build.paging.Page;
import com.bstek.ureport.build.paging.PagingBuilder;
import com.bstek.ureport.definition.Band;
import com.bstek.ureport.definition.Expand;
import com.bstek.ureport.definition.Orientation;
@ -367,6 +368,7 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
}
rowHeight+=rowRealHeight+1;
pageRows.add(row);
row.setPageIndex(pageIndex);
boolean overflow=false;
if((i+1)<rows.size()){
Row nextRow=rows.get(i+1);
@ -389,6 +391,7 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
pages.add(newPage);
}
report.getContext().setTotalPages(pages.size());
buildPageHeaderFooter(pages, report);
}else{
int fixRows=paper.getFixRows()-headerRows.size()-footerRows.size();
@ -428,6 +431,7 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
}
continue;
}
row.setPageIndex(pageIndex);
pageRows.add(row);
if((pageRows.size()+footerRows.size()) >= fixRows){
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
@ -440,9 +444,11 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
pages.add(newPage);
}
report.getContext().setTotalPages(pages.size());
buildPageHeaderFooter(pages, report);
}
buildSummaryRows(summaryRows, pages);
PagingBuilder.computeExistPageFunctionCells(report);
report.setPages(pages);
}

1
ureport2-core/src/main/java/com/bstek/ureport/build/compute/ExpressionValueCompute.java

@ -53,6 +53,7 @@ public class ExpressionValueCompute implements ValueCompute {
boolean hasPageFun=hasPageFunction(expr);
if(hasPageFun){
cell.setExistPageFunction(true);
context.addExistPageFunctionCells(cell);
return list;
}
}

32
ureport2-core/src/main/java/com/bstek/ureport/build/paging/BasePagination.java

@ -19,7 +19,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.bstek.ureport.build.BindData;
import com.bstek.ureport.build.Context;
import com.bstek.ureport.definition.HeaderFooterDefinition;
import com.bstek.ureport.model.Cell;
@ -39,6 +38,7 @@ public abstract class BasePagination {
int summaryRowSize=summaryRows.size()-1;
for(int i=summaryRowSize;i>-1;i--){
Row row=summaryRows.get(i);
row.setPageIndex(pages.size());
lastPageRows.add(row);
}
}
@ -63,7 +63,6 @@ public abstract class BasePagination {
if(cell==null){
continue;
}
buildExistPageFunctionCell(context, cell);
int rowSpan=cell.getPageRowSpan();
if(rowSpan==0){
continue;
@ -112,7 +111,9 @@ public abstract class BasePagination {
int headerRowSize=headerRows.size()-1;
for(int i=headerRowSize;i>-1;i--){
Row row=headerRows.get(i);
row.setPageIndex(pageIndex);
Row newRow=duplicateRepeateRow(row, context);
newRow.setPageIndex(pageIndex);
rows.add(0,newRow);
Map<Column,Cell> colMap=rowColCellsMap.get(newRow);
if(colMap==null){
@ -123,7 +124,6 @@ public abstract class BasePagination {
if(cell==null){
continue;
}
buildExistPageFunctionCell(context, cell);
}
}
if(pageIndex==1){
@ -140,12 +140,12 @@ public abstract class BasePagination {
if(cell==null){
continue;
}
buildExistPageFunctionCell(context, cell);
}
}
}
for(Row row:footerRows){
Row newRow=duplicateRepeateRow(row, context);
newRow.setPageIndex(pageIndex);
rows.add(newRow);
Map<Column,Cell> colMap=rowColCellsMap.get(newRow);
if(colMap==null){
@ -156,7 +156,6 @@ public abstract class BasePagination {
if(cell==null){
continue;
}
buildExistPageFunctionCell(context, cell);
}
}
Page page=new Page(rows,columns);
@ -177,6 +176,7 @@ public abstract class BasePagination {
private Row duplicateRepeateRow(Row row,Context context){
Row newRow=row.newRow();
newRow.setPageIndex(row.getPageIndex());
Map<Row, Map<Column, Cell>> cellMap=context.getReport().getRowColCellMap();
Map<Column, Cell> map=cellMap.get(row);
if(map==null){
@ -197,25 +197,13 @@ public abstract class BasePagination {
newCell.setCustomCellStyle(cell.getCustomCellStyle());
newCell.setFormatData(cell.getFormatData());
newCell.setExistPageFunction(cell.isExistPageFunction());
if(cell.isExistPageFunction()){
context.addExistPageFunctionCells(newCell);
}
newMap.put(col, newCell);
}
return newRow;
}
private void buildExistPageFunctionCell(Context context, Cell cell) {
if(cell.isExistPageFunction()){
List<BindData> dataList=context.buildCellData(cell);
if(dataList==null || dataList.size()==0){
return;
}
BindData bindData=dataList.get(0);
cell.setData(bindData.getValue());
cell.setBindData(bindData.getDataList());
cell.doFormat();
cell.doDataWrapCompute(context);
}
}
protected void buildPageHeaderFooter(List<Page> pages,Report report){
int totalPages=pages.size();
for(int i=0;i<totalPages;i++){
@ -223,12 +211,12 @@ public abstract class BasePagination {
HeaderFooterDefinition headerDef=report.getHeader();
int pageIndex=i+1;
if(headerDef!=null){
HeaderFooter hf=headerDef.buildHeaderFooter(pageIndex, totalPages, report.getContext());
HeaderFooter hf=headerDef.buildHeaderFooter(pageIndex, report.getContext());
page.setHeader(hf);
}
HeaderFooterDefinition footerDef=report.getFooter();
if(footerDef!=null){
HeaderFooter hf=footerDef.buildHeaderFooter(pageIndex, totalPages, report.getContext());
HeaderFooter hf=footerDef.buildHeaderFooter(pageIndex, report.getContext());
page.setFooter(hf);
}
}

2
ureport2-core/src/main/java/com/bstek/ureport/build/paging/FitPagePagination.java

@ -88,6 +88,7 @@ public class FitPagePagination extends BasePagination implements Pagination {
}
rowHeight+=rowRealHeight+1;
pageRows.add(row);
row.setPageIndex(pageIndex);
boolean overflow=false;
if((i+1)<rows.size()){
Row nextRow=rows.get(i+1);
@ -116,6 +117,7 @@ public class FitPagePagination extends BasePagination implements Pagination {
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
pages.add(newPage);
}
report.getContext().setTotalPages(pages.size());
buildPageHeaderFooter(pages, report);
buildSummaryRows(summaryRows, pages);
return pages;

2
ureport2-core/src/main/java/com/bstek/ureport/build/paging/FixRowsPagination.java

@ -80,6 +80,7 @@ public class FixRowsPagination extends BasePagination implements Pagination {
continue;
}
pageRows.add(row);
row.setPageIndex(pageIndex);
if((pageRows.size()+footerRows.size()) >= fixRows){
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
pageIndex++;
@ -92,6 +93,7 @@ public class FixRowsPagination extends BasePagination implements Pagination {
pageIndex++;
pages.add(newPage);
}
report.getContext().setTotalPages(pages.size());
buildPageHeaderFooter(pages, report);
buildSummaryRows(summaryRows, pages);
return pages;

19
ureport2-core/src/main/java/com/bstek/ureport/build/paging/PagingBuilder.java

@ -19,8 +19,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.bstek.ureport.build.BindData;
import com.bstek.ureport.build.Context;
import com.bstek.ureport.definition.PagingMode;
import com.bstek.ureport.definition.Paper;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.model.Report;
/**
@ -37,6 +40,22 @@ public class PagingBuilder {
Paper paper = report.getPaper();
Pagination pagination=paginationMap.get(paper.getPagingMode());
List<Page> pages=pagination.doPaging(report);
computeExistPageFunctionCells(report);
return pages;
}
public static void computeExistPageFunctionCells(Report report) {
Context context=report.getContext();
List<Cell> existPageFunctionCells=context.getExistPageFunctionCells();
for(Cell cell:existPageFunctionCells){
List<BindData> dataList=context.buildCellData(cell);
if(dataList==null || dataList.size()==0){
continue;
}
BindData bindData=dataList.get(0);
cell.setData(bindData.getValue());
cell.setBindData(bindData.getDataList());
cell.doFormat();
cell.doDataWrapCompute(context);
}
}
}

3
ureport2-core/src/main/java/com/bstek/ureport/definition/HeaderFooterDefinition.java

@ -50,7 +50,7 @@ public class HeaderFooterDefinition implements Serializable{
private Expression centerExpression;
@JsonIgnore
private Expression rightExpression;
public HeaderFooter buildHeaderFooter(int pageIndex,int totalPages,Context context){
public HeaderFooter buildHeaderFooter(int pageIndex,Context context){
HeaderFooter hf=new HeaderFooter();
hf.setBold(bold);
hf.setFontFamily(fontFamily);
@ -61,7 +61,6 @@ public class HeaderFooterDefinition implements Serializable{
hf.setUnderline(underline);
hf.setMargin(margin);
context.setPageIndex(pageIndex);
context.setTotalPages(totalPages);
if(leftExpression!=null){
Object obj = buildExpression(context,leftExpression);
if(obj!=null){

6
ureport2-core/src/main/java/com/bstek/ureport/expression/function/page/PageNumberFunction.java

@ -28,7 +28,11 @@ import com.bstek.ureport.model.Cell;
public class PageNumberFunction extends PageFunction {
@Override
public Object execute(List<ExpressionData<?>> dataList,Context context,Cell currentCell) {
return context.getPageIndex();
if(currentCell!=null && currentCell.getRow()!=null){
return currentCell.getRow().getPageIndex();
}else{
return context.getPageIndex();
}
}
@Override
public String name() {

10
ureport2-core/src/main/java/com/bstek/ureport/model/Row.java

@ -33,6 +33,7 @@ public class Row extends Line{
*/
private int tempRowNumber;
private Band band;
private int pageIndex;
private boolean forPaging;
private boolean pageBreak;
private boolean hide;
@ -70,6 +71,15 @@ public class Row extends Line{
public void setHeight(int height) {
this.height = height;
}
public int getPageIndex() {
return pageIndex;
}
public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex;
}
public Band getBand() {
return band;
}

読み込み中…
キャンセル
保存