1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.report.pentaho.model;
24 
25 import com.sun.star.report.OfficeToken;
26 import com.sun.star.report.pentaho.OfficeNamespaces;
27 
28 import java.util.ArrayList;
29 import java.util.List;
30 
31 import org.jfree.report.structure.Element;
32 
33 
34 /**
35  * A report element is the base class for all content generating elements in a
36  * report.
37  *
38  * @author Thomas Morgner
39  * @since 02.03.2007
40  */
41 public abstract class ReportElement extends Element
42 {
43 
44     private final List formatConditions;
45 
ReportElement()46     protected ReportElement()
47     {
48         formatConditions = new ArrayList();
49     }
50 
51     /**
52      * Checks the current group and prints this element only if the current row is
53      * the first row for that particular group.
54      *
55      * @return true, if the element should only be printed in the first row of the
56      *         current group, false otherwise.
57      */
isPrintWhenGroupChanges()58     public boolean isPrintWhenGroupChanges()
59     {
60         return OfficeToken.TRUE.equals(getAttribute(OfficeNamespaces.OOREPORT_NS, "print-when-group-changes"));
61     }
62 
setPrintWhenGroupChanges(final boolean printWhenGroupChanges)63     public void setPrintWhenGroupChanges(final boolean printWhenGroupChanges)
64     {
65         setAttribute(OfficeNamespaces.OOREPORT_NS, "print-when-group-changes",
66                 String.valueOf(printWhenGroupChanges));
67     }
68 
69     /**
70      * Checks, whether the printed value has been changed since the last run. The
71      * element will only be printed, if there was at least one change.
72      *
73      * @return true, if repeated values should be printed, false if repeated
74      *         values should be surpressed.
75      */
isPrintRepeatedValues()76     public boolean isPrintRepeatedValues()
77     {
78         return OfficeToken.TRUE.equals(getAttribute(OfficeNamespaces.OOREPORT_NS, "print-repeated-values"));
79     }
80 
setPrintRepeatedValues(final boolean printRepeatedValues)81     public void setPrintRepeatedValues(final boolean printRepeatedValues)
82     {
83         setAttribute(OfficeNamespaces.OOREPORT_NS, "print-repeated-values",
84                 String.valueOf(printRepeatedValues));
85     }
86 
addFormatCondition(final FormatCondition formatCondition)87     public void addFormatCondition(final FormatCondition formatCondition)
88     {
89         if (formatCondition == null)
90         {
91             throw new NullPointerException();
92         }
93 
94         this.formatConditions.add(formatCondition);
95     }
96 
getFormatConditions()97     public FormatCondition[] getFormatConditions()
98     {
99         return (FormatCondition[]) this.formatConditions.toArray(new FormatCondition[this.formatConditions.size()]);
100     }
101 
getFormatConditionCount()102     public int getFormatConditionCount()
103     {
104         return formatConditions.size();
105     }
106 }
107