| 1 |
/** |
| 2 |
* ======================================== |
| 3 |
* JFreeReport : a free Java report library |
| 4 |
* ======================================== |
| 5 |
* |
| 6 |
* Project Info: http://reporting.pentaho.org/ |
| 7 |
* |
| 8 |
* (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors. |
| 9 |
* |
| 10 |
* This library is free software; you can redistribute it and/or modify it under the terms |
| 11 |
* of the GNU Lesser General Public License as published by the Free Software Foundation; |
| 12 |
* either version 2.1 of the License, or (at your option) any later version. |
| 13 |
* |
| 14 |
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 16 |
* See the GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License along with this |
| 19 |
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 20 |
* Boston, MA 02111-1307, USA. |
| 21 |
* |
| 22 |
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. |
| 23 |
* in the United States and other countries.] |
| 24 |
* |
| 25 |
* ------------ |
| 26 |
* $Id: AutoTableItemLayoutController.java 10756 2009-12-02 15:58:24Z tmorgner $ |
| 27 |
* ------------ |
| 28 |
* (C) Copyright 2000-2005, by Object Refinery Limited. |
| 29 |
* (C) Copyright 2005-2007, by Pentaho Corporation. |
| 30 |
*/ |
| 31 |
|
| 32 |
package org.jfree.report.modules.misc.autotable.flow; |
| 33 |
|
| 34 |
import org.jfree.report.DataFlags; |
| 35 |
import org.jfree.report.DataSourceException; |
| 36 |
import org.jfree.report.ReportDataFactoryException; |
| 37 |
import org.jfree.report.ReportProcessingException; |
| 38 |
import org.jfree.report.data.ReportDataRow; |
| 39 |
import org.jfree.report.flow.FlowController; |
| 40 |
import org.jfree.report.flow.ReportTarget; |
| 41 |
import org.jfree.report.flow.layoutprocessor.ElementLayoutController; |
| 42 |
import org.jfree.report.flow.layoutprocessor.LayoutController; |
| 43 |
import org.jfree.report.modules.misc.autotable.AutoTableCellContent; |
| 44 |
|
| 45 |
/** |
| 46 |
* Creation-Date: Dec 9, 2006, 8:20:51 PM |
| 47 |
* |
| 48 |
* @author Thomas Morgner |
| 49 |
*/ |
| 50 |
public class AutoTableItemLayoutController extends ElementLayoutController |
| 51 |
{ |
| 52 |
|
| 53 |
public AutoTableItemLayoutController() |
| 54 |
{ |
| 55 |
} |
| 56 |
|
| 57 |
protected AutoTableLayoutController findTableParent () |
| 58 |
{ |
| 59 |
LayoutController parent = getParent(); |
| 60 |
while (parent != null) |
| 61 |
{ |
| 62 |
if (parent instanceof AutoTableLayoutController) |
| 63 |
{ |
| 64 |
return (AutoTableLayoutController) parent; |
| 65 |
} |
| 66 |
|
| 67 |
parent = parent.getParent(); |
| 68 |
} |
| 69 |
return null; |
| 70 |
} |
| 71 |
|
| 72 |
protected LayoutController processContent(final ReportTarget target) |
| 73 |
throws DataSourceException, ReportProcessingException, ReportDataFactoryException |
| 74 |
{ |
| 75 |
final AutoTableCellContent content = (AutoTableCellContent) getElement(); |
| 76 |
final FlowController flowController = getFlowController(); |
| 77 |
final ReportDataRow reportDataRow = |
| 78 |
flowController.getMasterRow().getReportDataRow(); |
| 79 |
|
| 80 |
final AutoTableLayoutController table = findTableParent(); |
| 81 |
if (table == null) |
| 82 |
{ |
| 83 |
throw new ReportProcessingException("Invalid state: have no auto-table as context."); |
| 84 |
} |
| 85 |
final int currentColumn = table.getCurrentColumn(); |
| 86 |
|
| 87 |
if ("name".equals(content.getItem())) |
| 88 |
{ |
| 89 |
final String columnName = reportDataRow.getColumnName(currentColumn); |
| 90 |
target.processText(columnName); |
| 91 |
} |
| 92 |
else if ("value".equals(content.getItem())) |
| 93 |
{ |
| 94 |
final DataFlags flags = reportDataRow.getFlags(currentColumn); |
| 95 |
target.processContent(flags); |
| 96 |
} |
| 97 |
else |
| 98 |
{ |
| 99 |
throw new ReportProcessingException("Invalid definition: Content-Item with no valid type"); |
| 100 |
} |
| 101 |
|
| 102 |
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 |
} |