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: */package org.jfree.report.modules.misc.autotable.flow;
031:
032: import org.jfree.report.DataFlags;
033: import org.jfree.report.DataSourceException;
034: import org.jfree.report.ReportDataFactoryException;
035: import org.jfree.report.ReportProcessingException;
036: import org.jfree.report.data.ReportDataRow;
037: import org.jfree.report.flow.FlowController;
038: import org.jfree.report.flow.ReportTarget;
039: import org.jfree.report.flow.layoutprocessor.ElementLayoutController;
040: import org.jfree.report.flow.layoutprocessor.LayoutController;
041: import org.jfree.report.modules.misc.autotable.AutoTableCellContent;
042:
043: /**
044: * Creation-Date: Dec 9, 2006, 8:20:51 PM
045: *
046: * @author Thomas Morgner
047: */
048: public class AutoTableItemLayoutController extends
049: ElementLayoutController {
050:
051: public AutoTableItemLayoutController() {
052: }
053:
054: protected AutoTableLayoutController findTableParent() {
055: LayoutController parent = getParent();
056: while (parent != null) {
057: if (parent instanceof AutoTableLayoutController) {
058: return (AutoTableLayoutController) parent;
059: }
060:
061: parent = parent.getParent();
062: }
063: return null;
064: }
065:
066: protected LayoutController processContent(final ReportTarget target)
067: throws DataSourceException, ReportProcessingException,
068: ReportDataFactoryException {
069: final AutoTableCellContent content = (AutoTableCellContent) getElement();
070: final FlowController flowController = getFlowController();
071: final ReportDataRow reportDataRow = flowController
072: .getMasterRow().getReportDataRow();
073:
074: final AutoTableLayoutController table = findTableParent();
075: if (table == null) {
076: throw new ReportProcessingException(
077: "Invalid state: have no auto-table as context.");
078: }
079: final int currentColumn = table.getCurrentColumn();
080:
081: if ("name".equals(content.getItem())) {
082: final String columnName = reportDataRow
083: .getColumnName(currentColumn);
084: target.processText(columnName);
085: } else if ("value".equals(content.getItem())) {
086: final DataFlags flags = reportDataRow
087: .getFlags(currentColumn);
088: target.processContent(flags);
089: } else {
090: throw new ReportProcessingException(
091: "Invalid definition: Content-Item with no valid type");
092: }
093:
094: final AutoTableItemLayoutController derived = (AutoTableItemLayoutController) clone();
095: derived.setProcessingState(ElementLayoutController.FINISHING);
096: derived.setFlowController(flowController);
097: return derived;
098:
099: }
100:
101: /**
102: * Joins with a delegated process flow. This is generally called from a child
103: * flow and should *not* (I mean it!) be called from outside. If you do,
104: * you'll suffer.
105: *
106: * @param flowController the flow controller of the parent.
107: * @return the joined layout controller that incorperates all changes from
108: * the delegate.
109: */
110: public LayoutController join(final FlowController flowController) {
111: final AutoTableItemLayoutController derived = (AutoTableItemLayoutController) clone();
112: derived.setProcessingState(ElementLayoutController.FINISHING);
113: derived.setFlowController(flowController);
114: return derived;
115: }
116: }
|