001 /** 002 * ======================================== 003 * JFreeReport : a free Java report library 004 * ======================================== 005 * 006 * Project Info: http://reporting.pentaho.org/ 007 * 008 * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors. 009 * 010 * This library is free software; you can redistribute it and/or modify it under the terms 011 * of the GNU Lesser General Public License as published by the Free Software Foundation; 012 * either version 2.1 of the License, or (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 015 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 016 * See the GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public License along with this 019 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 020 * Boston, MA 02111-1307, USA. 021 * 022 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 023 * in the United States and other countries.] 024 * 025 * ------------ 026 * $Id: AutoTableItemLayoutController.java 3525 2007-10-16 11:43:48Z tmorgner $ 027 * ------------ 028 * (C) Copyright 2000-2005, by Object Refinery Limited. 029 * (C) Copyright 2005-2007, by Pentaho Corporation. 030 */ 031 032 package org.jfree.report.modules.misc.autotable.flow; 033 034 import org.jfree.report.DataFlags; 035 import org.jfree.report.DataSourceException; 036 import org.jfree.report.ReportDataFactoryException; 037 import org.jfree.report.ReportProcessingException; 038 import org.jfree.report.data.ReportDataRow; 039 import org.jfree.report.flow.FlowController; 040 import org.jfree.report.flow.ReportTarget; 041 import org.jfree.report.flow.layoutprocessor.ElementLayoutController; 042 import org.jfree.report.flow.layoutprocessor.LayoutController; 043 import org.jfree.report.modules.misc.autotable.AutoTableCellContent; 044 045 /** 046 * Creation-Date: Dec 9, 2006, 8:20:51 PM 047 * 048 * @author Thomas Morgner 049 */ 050 public class AutoTableItemLayoutController extends ElementLayoutController 051 { 052 053 public AutoTableItemLayoutController() 054 { 055 } 056 057 protected AutoTableLayoutController findTableParent () 058 { 059 LayoutController parent = getParent(); 060 while (parent != null) 061 { 062 if (parent instanceof AutoTableLayoutController) 063 { 064 return (AutoTableLayoutController) parent; 065 } 066 067 parent = parent.getParent(); 068 } 069 return null; 070 } 071 072 protected LayoutController processContent(final ReportTarget target) 073 throws DataSourceException, ReportProcessingException, ReportDataFactoryException 074 { 075 final AutoTableCellContent content = (AutoTableCellContent) getElement(); 076 final FlowController flowController = getFlowController(); 077 final ReportDataRow reportDataRow = 078 flowController.getMasterRow().getReportDataRow(); 079 080 final AutoTableLayoutController table = findTableParent(); 081 if (table == null) 082 { 083 throw new ReportProcessingException("Invalid state: have no auto-table as context."); 084 } 085 final int currentColumn = table.getCurrentColumn(); 086 087 if ("name".equals(content.getItem())) 088 { 089 final String columnName = reportDataRow.getColumnName(currentColumn); 090 target.processText(columnName); 091 } 092 else if ("value".equals(content.getItem())) 093 { 094 final DataFlags flags = reportDataRow.getFlags(currentColumn); 095 target.processContent(flags); 096 } 097 else 098 { 099 throw new ReportProcessingException("Invalid definition: Content-Item with no valid type"); 100 } 101 102 final AutoTableItemLayoutController derived = (AutoTableItemLayoutController) clone(); 103 derived.setProcessingState(ElementLayoutController.FINISHING); 104 derived.setFlowController(flowController); 105 return derived; 106 107 } 108 109 /** 110 * Joins with a delegated process flow. This is generally called from a child 111 * flow and should *not* (I mean it!) be called from outside. If you do, 112 * you'll suffer. 113 * 114 * @param flowController the flow controller of the parent. 115 * @return the joined layout controller that incorperates all changes from 116 * the delegate. 117 */ 118 public LayoutController join(final FlowController flowController) 119 { 120 final AutoTableItemLayoutController derived = (AutoTableItemLayoutController) clone(); 121 derived.setProcessingState(ElementLayoutController.FINISHING); 122 derived.setFlowController(flowController); 123 return derived; 124 } 125 }