User: rt      
Date: 2008-06-16 13:16:52+0000
Modified:
   
dba/reportdesign/java/com/sun/star/report/pentaho/output/text/TextRawReportTarget.java

Log:
 INTEGRATION: CWS rptchart02 (1.5.4); FILE MERGED
 2008/05/27 08:06:16 oj 1.5.4.6: #i77610# handle keep-with-next and 
may-break-between-rows and keep-together
 2008/04/21 12:53:37 oj 1.5.4.5: export chart for spreadsheet and set default 
command type as command
 2008/04/16 06:24:08 oj 1.5.4.4: RESYNC: (1.5-1.6); FILE MERGED
 2008/04/04 13:06:02 oj 1.5.4.3: enable chart
 2008/04/03 11:59:20 oj 1.5.4.2: export frames of ole object with special style
 2008/03/12 09:42:53 oj 1.5.4.1: impl chart handling and some code refactoring

File Changes:

Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/output/text/
==========================================================================

File [changed]: TextRawReportTarget.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/text/TextRawReportTarget.java?r1=1.7&r2=1.8
Delta lines:  +113 -70
----------------------
--- TextRawReportTarget.java    2008-05-05 14:47:50+0000        1.7
+++ TextRawReportTarget.java    2008-06-16 13:16:49+0000        1.8
@@ -52,6 +52,7 @@
 import com.sun.star.report.pentaho.output.OfficeDocumentReportTarget;
 import com.sun.star.report.pentaho.output.StyleUtilities;
 import com.sun.star.report.pentaho.styles.LengthCalculator;
+import java.util.ArrayList;
 import org.jfree.layouting.input.style.values.CSSNumericValue;
 import org.jfree.layouting.util.AttributeMap;
 import org.jfree.report.DataSourceException;
@@ -60,6 +61,7 @@
 import org.jfree.report.flow.ReportStructureRoot;
 import org.jfree.report.flow.ReportTargetUtil;
 import org.jfree.report.structure.Element;
+import org.jfree.report.structure.Node;
 import org.jfree.report.structure.Section;
 import org.jfree.report.util.AttributeNameGenerator;
 import org.jfree.report.util.IntegerCache;
@@ -83,11 +85,13 @@
     private static final String ALWAYS = "always";
     private static final String KEEP_TOGETHER = "keep-together";
     private static final String KEEP_WITH_NEXT = "keep-with-next";
+    private static final String MAY_BREAK_BETWEEN_ROWS = 
"may-break-between-rows";
     private static final String NAME = "name";
     private static final String NONE = "none";
     private static final String NORMAL = "normal";
     private static final String PARAGRAPH_PROPERTIES = "paragraph-properties";
     private static final String STANDARD = "Standard";
+    private static final String TABLE_PROPERTIES = "table-properties";
     private static final String VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT = 
"variables_paragraph_with_next";
     private static final String VARIABLES_HIDDEN_STYLE_WITHOUT_KEEPWNEXT = 
"variables_paragraph_without_next";
     private static final int TABLE_LAYOUT_VARIABLES_PARAGRAPH = 0;
@@ -564,7 +568,7 @@
             {
                 startImageProcessing(attrs);
             }
-            else if (ObjectUtilities.equal(OfficeToken.OBJECT_OLE, 
elementType) && getCurrentRole() != ROLE_TEMPLATE )
+            else if (ObjectUtilities.equal(OfficeToken.OBJECT_OLE, 
elementType) && getCurrentRole() != ROLE_TEMPLATE)
             {
                 startChartProcessing(attrs);
             }
@@ -652,42 +656,38 @@
             {
                 if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TEXT_NS, 
OfficeToken.P, attrs))
                 {
+                    final int keepTogetherState = 
getCurrentContext().getKeepTogether();
                     cellEmpty = false;
-                    if (!firstCellSeen && sectionKeepTogether)
+                    if (!firstCellSeen && (sectionKeepTogether || 
keepTogetherState == PageContext.KEEP_TOGETHER_GROUP))
                     {
+                        OfficeStyle style = null;
                         final String styleName = (String) 
attrs.getAttribute(OfficeNamespaces.TEXT_NS, OfficeToken.STYLE_NAME);
-                        final OfficeStyle style = 
deriveStyle(OfficeToken.PARAGRAPH, styleName);
-                        // Lets set the 'keep-together' flag..
+                        if (styleName == null)
+                        {
+                            final boolean keep = (keepTogetherState == 
PageContext.KEEP_TOGETHER_GROUP || expectedTableRowCount > 0) && 
isParentKeepTogether();
+                            final ArrayList propertyNameSpaces = new 
ArrayList();
+                            final ArrayList propertyNames = new ArrayList();
+                            final ArrayList propertyValues = new ArrayList();
 
-                        Element paragraphProps = 
style.getParagraphProperties();
-                        if (paragraphProps == null)
+                            propertyNameSpaces.add(OfficeNamespaces.FO_NS);
+                            propertyNameSpaces.add(OfficeNamespaces.FO_NS);
+                            propertyNames.add(KEEP_TOGETHER);
+                            propertyValues.add(ALWAYS);
+                            if (keep)
                         {
-                            paragraphProps = new Section();
-                            
paragraphProps.setNamespace(OfficeNamespaces.STYLE_NS);
-                            paragraphProps.setType(PARAGRAPH_PROPERTIES);
-                            style.addNode(paragraphProps);
+                                propertyNames.add(KEEP_WITH_NEXT);
+                                propertyValues.add(ALWAYS);
                         }
-                        paragraphProps.setAttribute(OfficeNamespaces.FO_NS, 
KEEP_TOGETHER, ALWAYS);
-                        final int keepTogetherState = 
getCurrentContext().getKeepTogether();
-                        // We prevent pagebreaks within the two adjacent rows 
(this one and the next one) if
-                        // either a group-wide keep-together is defined or if 
we haven't reached the end of the
-                        // current section yet.
-                        if (keepTogetherState == 
PageContext.KEEP_TOGETHER_GROUP || expectedTableRowCount > 0)
+                            else
                         {
-                            
paragraphProps.setAttribute(OfficeNamespaces.FO_NS, KEEP_WITH_NEXT, ALWAYS);
+                                propertyNames.add(KEEP_WITH_NEXT);
+                                propertyValues.add(null);
                         }
-
-                        attrs.setAttribute(OfficeNamespaces.TEXT_NS, 
OfficeToken.STYLE_NAME, style.getStyleName());
+                            style = 
StyleUtilities.queryStyleByProperties(getStylesCollection(), 
OfficeToken.PARAGRAPH, PARAGRAPH_PROPERTIES, propertyNameSpaces, propertyNames, 
propertyValues);
                     }
-                }
-            }
-            else if (isTableNS && 
ObjectUtilities.equal(OfficeToken.TABLE_CELL, elementType))
-            {
-                cellEmpty = false;
-                if (!firstCellSeen && sectionKeepTogether)
+                        if (style == null)
                 {
-                    final String styleName = (String) 
attrs.getAttribute(OfficeNamespaces.TABLE_NS, OfficeToken.STYLE_NAME);
-                    final OfficeStyle style = 
deriveStyle(OfficeToken.TABLE_CELL, styleName);
+                            style = deriveStyle(OfficeToken.PARAGRAPH, 
styleName);
                     // Lets set the 'keep-together' flag..
 
                     Element paragraphProps = style.getParagraphProperties();
@@ -699,20 +699,22 @@
                         style.addNode(paragraphProps);
                     }
                     paragraphProps.setAttribute(OfficeNamespaces.FO_NS, 
KEEP_TOGETHER, ALWAYS);
-                    final int keepTogetherState = 
getCurrentContext().getKeepTogether();
+
                     // We prevent pagebreaks within the two adjacent rows 
(this one and the next one) if
                     // either a group-wide keep-together is defined or if we 
haven't reached the end of the
                     // current section yet.
-                    if (keepTogetherState == PageContext.KEEP_TOGETHER_GROUP 
|| expectedTableRowCount > 0)
+                            if ((keepTogetherState == 
PageContext.KEEP_TOGETHER_GROUP || expectedTableRowCount > 0) && 
isParentKeepTogether())
                     {
                         paragraphProps.setAttribute(OfficeNamespaces.FO_NS, 
KEEP_WITH_NEXT, ALWAYS);
                     }
+                        }
 
-                    attrs.setAttribute(OfficeNamespaces.TABLE_NS, 
OfficeToken.STYLE_NAME, style.getStyleName());
+                        attrs.setAttribute(OfficeNamespaces.TEXT_NS, 
OfficeToken.STYLE_NAME, style.getStyleName());
+                    }
                 }
             }
 
-            if ( ObjectUtilities.equal(OfficeNamespaces.DRAWING_NS, namespace) 
&& ObjectUtilities.equal(OfficeToken.FRAME, elementType) )
+            if (ObjectUtilities.equal(OfficeNamespaces.DRAWING_NS, namespace) 
&& ObjectUtilities.equal(OfficeToken.FRAME, elementType))
             {
                 final String styleName = (String) 
attrs.getAttribute(OfficeNamespaces.DRAWING_NS, OfficeToken.STYLE_NAME);
                 final OfficeStyle predefAutoStyle = 
getPredefinedStylesCollection().getAutomaticStyles().getStyle(OfficeToken.GRAPHIC,
 styleName);
@@ -980,8 +982,8 @@
             {
                 if (localKeepTogether)
                 {
-                    final Element tableProps = produceFirstChild(style, 
OfficeNamespaces.STYLE_NS, "table-properties");
-                    tableProps.setAttribute(OfficeNamespaces.STYLE_NS, 
"may-break-between-rows", OfficeToken.FALSE);
+                    final Element tableProps = produceFirstChild(style, 
OfficeNamespaces.STYLE_NS, TABLE_PROPERTIES);
+                    tableProps.setAttribute(OfficeNamespaces.STYLE_NS, 
MAY_BREAK_BETWEEN_ROWS, OfficeToken.FALSE);
                 }
             }
             else
@@ -997,10 +999,19 @@
             }
             if (keepWithNext)
             {
-                final Element tableProps = produceFirstChild(style, 
OfficeNamespaces.STYLE_NS, "table-properties");
+                boolean addKeepWithNext = true;
+                if (currentRole == ROLE_GROUP_FOOTER)
+                {
+                    addKeepWithNext = isParentKeepTogether();
+                }
+
+                final Element tableProps = produceFirstChild(style, 
OfficeNamespaces.STYLE_NS, TABLE_PROPERTIES);
+                tableProps.setAttribute(OfficeNamespaces.STYLE_NS, 
MAY_BREAK_BETWEEN_ROWS, OfficeToken.FALSE);
+                if (addKeepWithNext)
+                {
                 tableProps.setAttribute(OfficeNamespaces.FO_NS, 
KEEP_WITH_NEXT, ALWAYS);
                 // A keep-with-next does not work, if the may-break-betweek 
rows is not set to false ..
-                tableProps.setAttribute(OfficeNamespaces.STYLE_NS, 
"may-break-between-rows", OfficeToken.FALSE);
+                }
             }
             attrs.setAttribute(OfficeNamespaces.TABLE_NS, 
OfficeToken.STYLE_NAME, style.getStyleName());
         // no need to copy the styles, this was done while deriving the
@@ -1018,6 +1029,22 @@
                 }
                 else if (detailBandProcessingState == DETAIL_SECTION_WAIT)
                 {
+                    if (keepWithNext)
+                    {
+                        final String styleName = (String) 
attrs.getAttribute(OfficeNamespaces.TABLE_NS, OfficeToken.STYLE_NAME);
+
+                        final OfficeStyle style = 
deriveStyle(OfficeToken.TABLE, styleName);
+                        final Element tableProps = produceFirstChild(style, 
OfficeNamespaces.STYLE_NS, TABLE_PROPERTIES);
+                        // A keep-with-next does not work, if the 
may-break-betweek rows is not set to false ..
+                        tableProps.setAttribute(OfficeNamespaces.STYLE_NS, 
MAY_BREAK_BETWEEN_ROWS, OfficeToken.FALSE);
+                        final String hasGroupFooter = (String) 
attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "has-group-footer");
+                        if (hasGroupFooter != null && 
hasGroupFooter.equals(OfficeToken.TRUE))
+                        {
+                            tableProps.setAttribute(OfficeNamespaces.FO_NS, 
KEEP_WITH_NEXT, ALWAYS);
+                        }
+
+                        attrs.setAttribute(OfficeNamespaces.TABLE_NS, 
OfficeToken.STYLE_NAME, style.getStyleName());
+                    }
                     detailBandProcessingState = DETAIL_SECTION_FIRST_STARTED;
                 }
                 else if (detailBandProcessingState == 
DETAIL_SECTION_FIRST_PRINTED)
@@ -1036,6 +1063,20 @@
         xmlWriter.writeTag(namespace, elementType, attrList, 
XmlWriterSupport.OPEN);
     }
 
+    private boolean isParentKeepTogether()
+    {
+        PageContext context = getCurrentContext();
+        if (context != null)
+        {
+            context = context.getParent();
+            if (context != null)
+            {
+                return context.getKeepTogether() == 
PageContext.KEEP_TOGETHER_GROUP;
+            }
+        }
+        return false;
+    }
+
     private boolean isTableMergeActive()
     {
         return getCurrentRole() == ROLE_DETAIL &&
@@ -1351,6 +1392,7 @@
                 xmlWriter.writeCloseTag();
                 variables = null;
             }
+        /** 
             // Only generate the empty paragraph, if we have to add the 
keep-together ..
             else if (cellEmpty && expectedTableRowCount > 0 &&
                     sectionKeepTogether && !firstCellSeen)
@@ -1362,6 +1404,7 @@
                 xmlWriter.writeTag(OfficeNamespaces.TEXT_NS, OfficeToken.P, 
OfficeToken.STYLE_NAME,
                         
TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, 
XmlWriterSupport.CLOSE);
             }
+         */
         }
 
         if (isTableNs && (ObjectUtilities.equal(OfficeToken.TABLE_CELL, 
elementType) || ObjectUtilities.equal(OfficeToken.COVERED_TABLE_CELL, 
elementType)))




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to