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: Group.java,v 1.7 2007/04/01 18:49:33 taqua Exp $
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.structure;
033
034 import org.jfree.report.expressions.Expression;
035
036 /**
037 * A report group. A group is a repeated section which is bound to an
038 * expression.
039 * <p/>
040 * <h2>Default Behaviour</h2> Whether a new group should be started is evaluated
041 * by the group's expression. If that expression returns Boolean.TRUE, a new
042 * group instance is started. (That expression answers the Questions: 'Does this
043 * group instance end here?').
044 * <p/>
045 * If the group expression is invalid or there is no group expression at all, a
046 * group will consume all rows until the datasource is no longer advanceable.
047 *
048 * @author David Gilbert
049 * @author Thomas Morgner
050 */
051 public class Group extends Section
052 {
053 private Expression groupingExpression;
054
055 /**
056 * Constructs a group with no fields, and an empty header and footer.
057 */
058 public Group()
059 {
060 setType("group");
061 setRepeat(true);
062 }
063
064 /**
065 * Returns a string representation of the group (useful for debugging).
066 *
067 * @return A string.
068 */
069 public String toString()
070 {
071 final StringBuffer b = new StringBuffer();
072 b.append("Group={Name='");
073 b.append(getName());
074 b.append("} ");
075 return b.toString();
076 }
077
078 public Expression getGroupingExpression()
079 {
080 return groupingExpression;
081 }
082
083 public void setGroupingExpression(final Expression groupingExpression)
084 {
085 this.groupingExpression = groupingExpression;
086 }
087
088 public Group getGroup()
089 {
090 return this;
091 }
092
093
094 public Object clone()
095 throws CloneNotSupportedException
096 {
097 final Group group = (Group) super.clone();
098 if (groupingExpression != null)
099 {
100 group.groupingExpression = (Expression) groupingExpression.clone();
101 }
102 return group;
103 }
104 }