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.wizards.reportbuilder.layout;
24 
25 import com.sun.star.awt.Rectangle;
26 import com.sun.star.report.XGroup;
27 import com.sun.star.report.XGroups;
28 import com.sun.star.report.XSection;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.wizards.common.Resource;
31 import com.sun.star.wizards.report.IReportDefinitionReadAccess;
32 import com.sun.star.wizards.ui.UIConsts;
33 
34 /**
35  *
36  * @author ll93751
37  */
38 public class Tabular extends ReportBuilderLayouter
39 {
40 
Tabular(IReportDefinitionReadAccess _xDefinitionAccess, Resource _aResource)41     public Tabular(IReportDefinitionReadAccess _xDefinitionAccess, Resource _aResource)
42     {
43         super(_xDefinitionAccess, _aResource);
44     }
45 
getName()46     public String getName()
47     {
48         return "DefaultLayoutOfData";
49     }
50 
getLocalizedName()51     public String getLocalizedName()
52     {
53         return getResource().getResText(UIConsts.RID_REPORT + 80);
54     }
55 
insertDetailFields()56     protected void insertDetailFields()
57     {
58         copyDetailProperties();
59 
60         String[] aFieldNames = getFieldNames();
61         if (aFieldNames == null)
62         {
63             return;
64         }
65         if (aFieldNames.length == 0)
66         {
67             return;
68         }
69 //        int nGroups = getReportDefinition().getGroups().getCount();
70 
71         final XSection xSection = getReportDefinition().getDetail();
72 
73         Rectangle aRect = new Rectangle();
74         aRect.X = getLeftPageIndent() + getLeftGroupIndent(getCountOfGroups());
75 
76         final int nWidth = calculateFieldWidth(getLeftGroupIndent(getCountOfGroups()), aFieldNames.length);
77         final SectionObject aSO = getDesignTemplate().getDetailTextField();
78         int nHeight = LayoutConstants.FormattedFieldHeight;
79         for (int i = 0; i < aFieldNames.length; i++)
80         {
81             final String sFieldName = convertToFieldName(aFieldNames[i]);
82             aRect = insertFormattedField(xSection, sFieldName, aRect, nWidth, aSO);
83             nHeight = Math.max(aRect.Height, nHeight);
84         }
85         nHeight = Math.max(aSO.getHeight(nHeight), nHeight);
86         xSection.setHeight(nHeight);
87     }
88 
insertDetailFieldTitles(int lastGroupPostion)89     protected void insertDetailFieldTitles(int lastGroupPostion)
90     {
91         final String[] aFieldTitleNames = getFieldTitleNames();
92         if (aFieldTitleNames == null || aFieldTitleNames.length == 0)
93         {
94             return;
95         }
96         try
97         {
98             SectionObject aSO = null;
99             final XGroups xGroups = getReportDefinition().getGroups();
100             final XGroup xGroup;
101             if (lastGroupPostion == -1)
102             {
103                 // Spezial case, there is no Group.
104                 xGroup = xGroups.createGroup();
105                 xGroup.setHeaderOn(true);
106 
107                 xGroups.insertByIndex(xGroups.getCount(), xGroup);
108                 copyGroupProperties(0);
109                 aSO = getDesignTemplate().getDetailLabel();
110                 aSO.setFontToBold();
111             }
112             else
113             {
114                 // we insert the titles in the last group
115                 xGroup = UnoRuntime.queryInterface(XGroup.class, xGroups.getByIndex(lastGroupPostion));
116 
117                 // We don't need to copy the GroupProperties, because this is done in the insertGroup() member function
118                 // copyGroupProperties(0);
119                 aSO = getDesignTemplate().getGroupLabel(lastGroupPostion);
120             }
121 
122             XSection xSection = xGroup.getHeader();
123             Rectangle aRect = new Rectangle();
124             aRect.X = getLeftPageIndent() + getLeftGroupIndent(getCountOfGroups());
125             if (lastGroupPostion == -1)
126             {
127                 xSection.setHeight(0);  // group height + a little empty line)
128                 aRect.Y = 0;
129             }
130             else
131             {
132                 aRect.Y = xSection.getHeight() + LayoutConstants.LineHeight;
133             }
134 
135             final int nWidth = calculateFieldWidth(getLeftGroupIndent(getCountOfGroups()), aFieldTitleNames.length);
136 
137             for (int i = 0; i < aFieldTitleNames.length; i++)
138             {
139                 aRect = insertLabel(xSection, aFieldTitleNames[i], aRect, nWidth, aSO);
140             }
141             xSection.setHeight(xSection.getHeight() + aSO.getHeight(LayoutConstants.LabelHeight));
142         }
143         catch (com.sun.star.uno.Exception e)
144         {
145         }
146     }
147 }
148