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.layoutprocessor;
24 
25 import com.sun.star.report.OfficeToken;
26 import com.sun.star.report.SDBCReportDataFactory;
27 import com.sun.star.report.pentaho.model.ObjectOleElement;
28 
29 import java.util.ArrayList;
30 import java.util.Iterator;
31 import java.util.List;
32 
33 import org.jfree.layouting.util.AttributeMap;
34 import org.jfree.report.DataFlags;
35 import org.jfree.report.DataRow;
36 import org.jfree.report.DataSourceException;
37 import org.jfree.report.JFreeReportInfo;
38 import org.jfree.report.ReportDataFactoryException;
39 import org.jfree.report.ReportProcessingException;
40 import org.jfree.report.flow.ReportTarget;
41 import org.jfree.report.flow.layoutprocessor.LayoutController;
42 import org.jfree.report.structure.Element;
43 
44 /**
45  *
46  * @author Ocke Janssen
47  */
48 public class ObjectOleLayoutController extends AbstractReportElementLayoutController
49 {
50 
ObjectOleLayoutController()51     public ObjectOleLayoutController()
52     {
53     }
54 
isValueChanged()55     protected boolean isValueChanged()
56     {
57         final ObjectOleElement element = (ObjectOleElement) getNode();
58         final List masterfields = element.getMasterfields();
59         final DataRow view = getFlowController().getMasterRow().getGlobalView();
60         for (final Iterator iter = masterfields.iterator(); iter.hasNext();)
61         {
62             final String master = (String) iter.next();
63             try
64             {
65                 final DataFlags flags = view.getFlags(master);
66                 if (flags != null && flags.isChanged())
67                 {
68                     return true;
69                 }
70             }
71             catch (DataSourceException e)
72             {
73                 // ignore .. assume that the reference has not changed.
74             }
75         }
76         return false;
77     }
78 
delegateContentGeneration(final ReportTarget target)79     protected LayoutController delegateContentGeneration(final ReportTarget target) throws ReportProcessingException, ReportDataFactoryException, DataSourceException
80     {
81         final ObjectOleElement element = (ObjectOleElement) getNode();
82         final String url = element.getUrl();
83         if (url != null)
84         {
85             final AttributeMap ole = new AttributeMap();
86             ole.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, Element.NAMESPACE_ATTRIBUTE, JFreeReportInfo.REPORT_NAMESPACE);
87             ole.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, Element.TYPE_ATTRIBUTE, OfficeToken.OBJECT_OLE);
88             ole.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, "href", url);
89             ole.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, "class-id", element.getClassid());
90             final List masterfields = element.getMasterfields();
91             final List values = new ArrayList();
92             final DataRow view = getFlowController().getMasterRow().getGlobalView();
93             for (final Iterator iter = masterfields.iterator(); iter.hasNext();)
94             {
95                 final String master = (String) iter.next();
96                 try
97                 {
98                     final DataFlags flags = view.getFlags(master);
99                     if (flags != null)
100                     {
101                         values.add(flags.getValue());
102                     }
103                 }
104                 catch (DataSourceException e)
105                 {
106                     // ignore .. assume that the reference has not changed.
107                 }
108             }
109             ole.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, SDBCReportDataFactory.MASTER_COLUMNS, masterfields);
110             ole.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, SDBCReportDataFactory.MASTER_VALUES, values);
111             ole.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, SDBCReportDataFactory.DETAIL_COLUMNS, element.getDetailfields());
112 
113             target.startElement(ole);
114             target.endElement(ole);
115         }
116 
117         return join(getFlowController());
118     }
119 }
120 
121