From 5e5acf655dcab5cc6a867c8532c9d836af777b8e Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Wed, 25 Jun 2008 13:38:17 +0000 Subject: [PATCH] INTEGRATION: CWS rptwizard01 (1.1.2); FILE ADDED 2008/06/24 14:59:00 kz 1.1.2.14: fixed wrong license header 2008/06/06 10:27:16 lla 1.1.2.13: #i90429# catch a ArrayOutOfBoundsException if there are new values inserted 2008/06/03 06:23:15 lla 1.1.2.12: #i86092# insertPageHeader, Footer some cleanups 2008/06/02 08:07:58 lla 1.1.2.11: #i86092# templates ends with 'otr' 2008/05/20 13:16:27 lla 1.1.2.10: #i86092# support copy of functions 2008/05/20 10:53:02 lla 1.1.2.9: #i86092# support templates 2008/05/16 07:05:45 lla 1.1.2.8: #i86092# restructures to work with design templates 2008/04/14 09:26:00 lla 1.1.2.7: #i86092# cleanup 2008/04/01 11:06:25 lla 1.1.2.6: #i86911# formattedfield with rpt:now() has numberformat DATE in default locale 2008/04/01 07:15:23 lla 1.1.2.5: #i86912# center footer (Page count) 2008/03/18 12:16:09 lla 1.1.2.4: #i86092# insert TableName in title, insert username out of configuration, set CommandType to TableName 2008/03/14 13:50:11 lla 1.1.2.3: #i86092# PMD cleanups 2008/03/11 12:53:35 lla 1.1.2.2: #i86092# cleanups, make labelwidth variable 2008/03/07 07:37:31 lla 1.1.2.1: #i86092# --- .../layout/ReportBuilderLayouter.java | 1599 +++++++++++++++++ 1 file changed, 1599 insertions(+) create mode 100644 wizards/com/sun/star/wizards/reportbuilder/layout/ReportBuilderLayouter.java diff --git a/wizards/com/sun/star/wizards/reportbuilder/layout/ReportBuilderLayouter.java b/wizards/com/sun/star/wizards/reportbuilder/layout/ReportBuilderLayouter.java new file mode 100644 index 000000000000..e6ee5009ec2f --- /dev/null +++ b/wizards/com/sun/star/wizards/reportbuilder/layout/ReportBuilderLayouter.java @@ -0,0 +1,1599 @@ +/* + ************************************************************************ + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ReportBuilderLayouter.java,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.wizards.reportbuilder.layout; + +import com.sun.star.awt.FontDescriptor; +import com.sun.star.awt.Rectangle; +import com.sun.star.awt.Size; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XControlModel; +import com.sun.star.awt.XLayoutConstrains; +import com.sun.star.awt.XUnitConversion; +import com.sun.star.awt.XWindow; +import com.sun.star.awt.XWindowPeer; +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.container.XEnumeration; +import com.sun.star.container.XNameAccess; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.report.XFixedLine; +import com.sun.star.report.XFixedText; +import com.sun.star.report.XFormattedField; +import com.sun.star.report.XGroup; +import com.sun.star.report.XGroups; +import com.sun.star.report.XReportComponent; +import com.sun.star.report.XReportDefinition; +import com.sun.star.report.XSection; +import com.sun.star.drawing.XShape; +import com.sun.star.style.XStyle; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.XNumberFormatTypes; +import com.sun.star.util.XNumberFormats; +import com.sun.star.util.XNumberFormatsSupplier; +import com.sun.star.wizards.common.Configuration; +import com.sun.star.wizards.common.FileAccess; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.PropertySetHelper; +import com.sun.star.wizards.common.Resource; +import com.sun.star.wizards.report.IReportBuilderLayouter; +import com.sun.star.wizards.report.IReportDefinitionReadAccess; +import com.sun.star.wizards.ui.UIConsts; +import java.util.HashMap; +import java.util.Locale; + + +/** + * This class is abstract and more like a helper for create different layouts for Report Builder Wizard. + * @author ll93751 + */ + +// TODO: let a little bit place between 2 formatted fields +// TODO: move all sectionobjects which have a connect to the right max page width to left if there is a orientation change. + +abstract public class ReportBuilderLayouter implements IReportBuilderLayouter +{ + private IReportDefinitionReadAccess m_xReportDefinitionReadAccess; + private Resource m_aResource; + + /** + * dispose the ReportBuilderLayouter + */ + public void dispose() + { + closeDesignTemplate(); + m_xReportDefinitionReadAccess = null; + // m_xReportBuilderLayouter = null; + } + + /** + * The Constructor is protected, this is a abstract class, use Tabular or other to create an instance. + * @param _xDefinitionAccess + * @param _aResource + */ + protected ReportBuilderLayouter(IReportDefinitionReadAccess _xDefinitionAccess, Resource _aResource) + { + m_xReportDefinitionReadAccess = _xDefinitionAccess; + m_aResource = _aResource; + } + + /** + * Access to the current ReportDefinition + * @return the ReportDefinition + */ + public XReportDefinition getReportDefinition() + { + // we have to ask our parent for this value + return m_xReportDefinitionReadAccess.getReportDefinition(); + } + /** + * Access to the global MultiServiceFactory + * @return the global Service Factory + */ + private XMultiServiceFactory getGlobalMSF() + { + return m_xReportDefinitionReadAccess.getGlobalMSF(); + } + + + /** + * Layout the complete report new, by all information we know until this time. + * + * If there are some information less, it is no problem for this function, they will be leaved out. + * It is possible to call this function after every change, but be careful, could take a little bit longer. + */ + public synchronized void layout() + { + try + { + // we bring the clear and insert methods together, this should be a little bit smoother + clearReportHeader(); + insertReportHeader(); + + clearReportFooter(); + insertReportFooter(); + + clearPageHeader(); + insertPageHeader(); + + clearPageFooter(); + insertPageFooter(); + + clearGroups(); + insertGroups(); + + clearDetails(); + // clearFieldTitles(); + insertDetailFieldTitles(); + insertDetailFields(); + } + catch (java.lang.ArrayIndexOutOfBoundsException e) + { + // could happen, if you change the count of values + } + catch (java.lang.RuntimeException e) + { + throw e; + } + catch (Exception e) + { + // Exception not set. Not from interest here. + int dummy = 0; + } + } + + // ------------------------------------------------------------------------- + /** + * Remove all Groups + */ + protected void clearGroups() + { + final XGroups xGroups = getReportDefinition().getGroups(); +// int nCount = xGroups.getCount(); + while (xGroups.hasElements()) + { + try + { + xGroups.removeByIndex(0); + } + catch (com.sun.star.uno.Exception e) + { + // Exception not set. Not from interest here. + } + } + } + // ------------------------------------------------------------------------- + /** + * Remove all fields + * @param _xSectionToClear + */ + private void emptySection(XSection _xSectionToClear) + { + if (_xSectionToClear == null) + { + return; + } + // int nCount = _xSectionToClear.getCount(); + while (_xSectionToClear.hasElements()) + { + try + { + final Object aObj = _xSectionToClear.getByIndex(0); + final XShape aShape = (XShape)UnoRuntime.queryInterface(XShape.class, aObj); + _xSectionToClear.remove(aShape); + } + catch (com.sun.star.uno.Exception e) + { + // Exception not set. + int dummy = 0; + } + + } + } + private void clearDetails() + { + final XSection xSection = getReportDefinition().getDetail(); + emptySection(xSection); + } + +// public void clearFieldTitles() +// { +// } + + + /** + * + * @param _nGroupCount + * @return the left indent in 1/100mm + */ + protected int getLeftGroupIndent(int _nGroupCount) + { +// TODO: Fix values for group indent (1/2cm) only the first 2 groups + int nIndent = 0; + final int MAX_INDENT = 2; + if (_nGroupCount <= MAX_INDENT) + { + nIndent = _nGroupCount * 500; + } + else + { + nIndent = MAX_INDENT * 500; + } + return nIndent; + } + + /** + * Get left page indent. + * The left indent is the area on the left side which will no be printed. + * The default is 2000 1/100mm what is 2cm of DIN A4. + * @return the left indent in 1/100mm + */ + int m_nLeftIndent = -1; + protected int getLeftPageIndent() + { + if (m_nLeftIndent < 0) + { + m_nLeftIndent = getFromPageStyles("LeftMargin", 2000); + } + return m_nLeftIndent; + } + + /** + * Get right page indent. + * The right indent is the area on the right side which will no be printed. + * The default is 2000 1/100mm what is 2cm of DIN A4. + * @return the right indent in 1/100mm + */ + int m_nRightIndent = -1; + protected int getRightPageIndent() + { + if (m_nRightIndent < 0) + { + m_nRightIndent = getFromPageStyles("RightMargin", 2000); + } + return m_nRightIndent; + } + + private XStyle getUsedStyle(String _sStyleName) + { + XStyle aUsedStyle = null; + final XNameAccess xNameAccess = getReportDefinition().getStyleFamilies(); + try + { + // + // String[] aNames = xNameAccess.getElementNames(); + // + + // get all Page Styles + final Object aPageStylesObj = xNameAccess.getByName(_sStyleName); + final XNameAccess xContainer = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, aPageStylesObj); + + // step over all Page Styles, search the one which is in use + final String[] aElementNames = xContainer.getElementNames(); + for (int i = 0; i < aElementNames.length; i++) + { + final String sName = aElementNames[i]; + final Object aObj = xContainer.getByName(sName); + final XStyle xStyle = (XStyle)UnoRuntime.queryInterface(XStyle.class, aObj); + if (xStyle.isInUse()) + { + aUsedStyle = xStyle; + break; + } + } + } + catch (com.sun.star.uno.Exception e) + { + // TODO: Exception not set. + e.printStackTrace(); + } + return aUsedStyle; + } + + protected int getFromPageStyles(String _sStyleName, int _nDefault) + { + int nValue = _nDefault; + final XStyle xStyle = getUsedStyle("PageStyles"); + if (xStyle != null) + { + // we found the page style which is in use + final PropertySetHelper aHelper = new PropertySetHelper(xStyle); + nValue = aHelper.getPropertyValueAsInteger(_sStyleName, nValue); + } + return nValue; + } + + protected void setToPageStyles(String _sStyleName, Object _aObj) + { + final XStyle xStyle = getUsedStyle("PageStyles"); + if (xStyle != null) + { + final PropertySetHelper aHelper = new PropertySetHelper(xStyle); + aHelper.setPropertyValueDontThrow(_sStyleName, _aObj); + } + } + + /** + * Get page width. The default is 21000 1/100mm what is 21cm of DIN A4. + * @return the Width of the page in 1/100mm + */ + int m_nPageWidth = -1; + protected int getPageWidth() + { + if (m_nPageWidth < 0) + { + m_nPageWidth = getFromPageStyles("Width", 21000); + } + return m_nPageWidth; + } + // ------------------------------------------------------------------------- + /** + * Stores the Group names. To insert/create a report with such group names, call layout() + * @param _aGroupNames + */ + public void insertGroupNames(String[] _aGroupNames) + { + m_aGroupNames = _aGroupNames; + } + protected void copyGroupProperties(int _nGroup) + { + if (getDesignTemplate() != null ) + { + try + { + final XGroups xForeignGroups = getDesignTemplate().getGroups(); + int nGroups = xForeignGroups.getCount(); + Object aForeignGroup = xForeignGroups.getByIndex(_nGroup); + XGroup xForeignGroup = (XGroup)UnoRuntime.queryInterface(XGroup.class, aForeignGroup); + XSection xForeignGroupSection = xForeignGroup.getHeader(); + + if (xForeignGroupSection != null) + { + final XGroups xGroups = getReportDefinition().getGroups(); + Object aGroup = xGroups.getByIndex(_nGroup); + XGroup xGroup = (XGroup)UnoRuntime.queryInterface(XGroup.class, aGroup); + XSection xGroupSection = xGroup.getHeader(); + + // copy Properties + copyProperties(xForeignGroupSection, xGroupSection); + } + } + catch (Exception e) + { + int dummy = 0; + } + } + } + // ------------------------------------------------------------------------- + protected void insertGroups() + { + if (m_aGroupNames == null) + { + return; + } + + final XGroups xGroups = getReportDefinition().getGroups(); + final int nLeftPageIndent = getLeftPageIndent(); + final int nLabelWidth = getMaxLabelWidth(); // 3000; + final int nUsablePageWidth = getPageWidth() - getLeftPageIndent() - getRightPageIndent() - getLeftGroupIndent(getCountOfGroups()); + final int nFieldWidth = nUsablePageWidth - nLabelWidth; + + // after done with all groups, we need access to the last group, for set property 'KeepTogether' so we remember it. + XGroup aLastGroup = null; + + for (int i=0;i 0) + { + nWidth = (getPageWidth() - getLeftPageIndent() - getRightPageIndent() - _nLeftIndent) / _nFieldCount; + } + return nWidth; + } + protected String[] getFieldTitleNames() + { + return getNamesWithoutGroupNames(m_aFieldNames, m_aFieldTitleNames); + } + // ------------------------------------------------------------------------- + abstract protected void insertDetailFieldTitles(); + // ------------------------------------------------------------------------- + /** + * Give a list off all field names to insert the field names, call layout() + * @param _aFieldNames + */ + public void insertFieldNames(String[] _aFieldNames) + { + m_aFieldNames = _aFieldNames; + } + + public void insertFieldTypes(int[] _aFieldTypes) + { + m_aFieldTypes = _aFieldTypes; + } + public void insertFieldWidths(int[] _aFieldWidths) + { + m_aFieldWidths = _aFieldWidths; + } + + + protected int getCountOfGroups() + { + return ((m_aGroupNames == null) ? 0 : m_aGroupNames.length); + } + + // ------------------------------------------------------------------------- + protected String[] getFieldNames() + { + return getNamesWithoutGroupNames(m_aFieldNames, null); + } + abstract protected void insertDetailFields(); + + protected void copyDetailProperties() + { + if (getDesignTemplate() != null ) + { + try + { + XSection xForeignSection = getDesignTemplate().getDetail(); + if (xForeignSection != null) + { + XSection xSection = getReportDefinition().getDetail(); + + // copy Properties + copyProperties(xForeignSection, xSection); + } + } + catch (Exception e) + { + } + } + } + // ------------------------------------------------------------------------- + + protected Rectangle insertLabel(XSection _xSection, String _sLabel, Rectangle _aRect, int _nWidth, SectionObject _aSO) + { + if (_xSection != null) + { + try + { + final Object aFixedText = getMSFofReportDefinition().createInstance("com.sun.star.report.FixedText"); + final XFixedText xFixedText = (XFixedText)UnoRuntime.queryInterface(XFixedText.class, aFixedText); + + + int nHeight = 500; // default height of label is fixed. + if (_aSO != null) + { + if (_aSO instanceof SectionEmptyObject) + { + float fCharWeight = _aSO.getCharWeight(com.sun.star.awt.FontWeight.NORMAL); + if (fCharWeight > 0.1f) + { + xFixedText.setCharWeight(fCharWeight); + } + } + else + { + final FontDescriptor aFD = _aSO.getFontDescriptor(); + if (aFD != null) + { + xFixedText.setFontDescriptor(aFD); + } + nHeight = _aSO.getHeight(500); + } + } + xFixedText.setLabel(_sLabel); + + xFixedText.setPositionX(_aRect.X); + xFixedText.setPositionY(_aRect.Y); + + // Width will calculate from outside. + // We have to set, because there exist no right default (0) + xFixedText.setWidth(_nWidth); + _aRect.X += _nWidth; + xFixedText.setHeight(nHeight); + _xSection.add(xFixedText); + } + catch (com.sun.star.uno.Exception e) + { + // TODO: Exception not set. + int dummy = 0; + } + } + return _aRect; + } + // ------------------------------------------------------------------------- + protected String convertToFieldName(String _sElementName) + { + final StringBuffer aDataField = new StringBuffer(32); + aDataField.append("field:[").append(_sElementName).append(']'); + return aDataField.toString(); + + } + // ------------------------------------------------------------------------- + /** + * Insert a already formatted field name into a given section + * + * Use 'convertToFieldName(dbfield)' to convert a dbfield name in the right. + * + * @param _xSection in which section the formatted field will store + * @param _sFormattedfield as String a dbfield or an other function + * @param _aRect .X, .Y are the absolute position (1/100mm) where the formatted field will set + * @param _nWidth the width of the field in 1/100mm + * @param _aSO + * @return a new Rectangle with the new Rect.X position, Rect.Y will not change. + */ + protected Rectangle insertFormattedField(XSection _xSection, String _sFormattedfield, Rectangle _aRect, int _nWidth, SectionObject _aSO) + { + return insertFormattedField(_xSection, _sFormattedfield, _aRect, _nWidth, _aSO, (short)com.sun.star.awt.TextAlign.LEFT); + } + protected Rectangle insertFormattedField(XSection _xSection, String _sFormattedfield, Rectangle _aRect, int _nWidth, SectionObject _aSO, short _nAlignment) + { + if (_xSection != null) + { + try + { + final Object aFormattedField = getMSFofReportDefinition().createInstance("com.sun.star.report.FormattedField"); + final XFormattedField xFormattedField = (XFormattedField)UnoRuntime.queryInterface(XFormattedField.class, aFormattedField); + // #i86907# not documented right in idl description. + xFormattedField.setDataField(_sFormattedfield); + int nHeight = 500; + if (_aSO != null) + { + final FontDescriptor aFD = _aSO.getFontDescriptor(); + if (aFD != null) + { + xFormattedField.setFontDescriptor(aFD); + } + nHeight = _aSO.getHeight(500); + } + xFormattedField.setPositionX(_aRect.X); + xFormattedField.setPositionY(_aRect.Y); + xFormattedField.setWidth(_nWidth); + _aRect.X += _nWidth; + xFormattedField.setHeight(nHeight); + + xFormattedField.setParaAdjust(_nAlignment); + + // spezial case rpt:now() (default date format) + if (_sFormattedfield.equals("rpt:now()")) + { + XNumberFormatsSupplier x = xFormattedField.getFormatsSupplier(); + XNumberFormats xFormats = x.getNumberFormats(); + XNumberFormatTypes x3 = (XNumberFormatTypes)UnoRuntime.queryInterface(XNumberFormatTypes.class, xFormats); + Locale.getDefault(); + com.sun.star.lang.Locale aLocale = new com.sun.star.lang.Locale(); + aLocale.Country = Locale.getDefault().getCountry(); + aLocale.Language = Locale.getDefault().getLanguage(); + + int nFormat = x3.getStandardFormat(com.sun.star.util.NumberFormat.DATE, aLocale); + xFormattedField.setFormatKey(nFormat); + } + _xSection.add(xFormattedField); + } + catch (com.sun.star.uno.Exception e) + { + // TODO: Exception not set. + int dummy = 0; + } + } + return _aRect; + } + + // ------------------------------------------------------------------------- +// TODO: check with Query, this code will not work with Queries + public void setTableName(int _aType, String _sTableName) + { + m_aCommandType = _aType; + m_sTableName = _sTableName; + + // getReportDefinition().setCommandType(com.sun.star.sdb.CommandType.TABLE); + getReportDefinition().setCommandType(_aType); + getReportDefinition().setCommand(_sTableName); + } + + // ------------------------------------------------------------------------- + protected XMultiServiceFactory m_xMSF; + protected XMultiServiceFactory getMSFofReportDefinition() + { + if (m_xMSF == null) + { + final XMultiServiceFactory xMSF = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, getReportDefinition() ); + m_xMSF = xMSF; + } + return m_xMSF; + } + // ------------------------------------------------------------------------- + protected Rectangle insertVerticalLine(XSection _xSection, Rectangle _aRect, int _nWidth, int _nHeight) + { + return insertLine(_xSection, _aRect, _nWidth, _nHeight, 1); + } + protected Rectangle insertHorizontalLine(XSection _xSection, Rectangle _aRect, int _nWidth, int _nHeight) + { + return insertLine(_xSection, _aRect, _nWidth, _nHeight, 0); + } + protected Rectangle insertLine(XSection _xSection, Rectangle _aRect, int _nWidth, int _nHeight, int _nOrientation) + { + if (_xSection != null) + { + try + { + final Object aFixedLine = getMSFofReportDefinition().createInstance("com.sun.star.report.FixedLine"); + final XFixedLine xFixedLine = (XFixedLine)UnoRuntime.queryInterface(XFixedLine.class, aFixedLine); + + xFixedLine.setOrientation(_nOrientation); + // TODO: line width is fixed + xFixedLine.setLineWidth(8); + + xFixedLine.setPositionX(_aRect.X); + xFixedLine.setPositionY(_aRect.Y); + + xFixedLine.setWidth(_nWidth); + _aRect.X += _nWidth; + xFixedLine.setHeight(_nHeight); + _xSection.add(xFixedLine); + } + catch (com.sun.star.uno.Exception e) + { + // TODO: Exception not set. + int dummy = 0; + } + } + return _aRect; + } + + // ------------------------------------------------------------------------- + protected void clearReportHeader() + { + XSection xSection; + try + { + if (getReportDefinition().getReportHeaderOn()) + { + xSection = getReportDefinition().getReportHeader(); + emptySection(xSection); + } + } + catch (com.sun.star.container.NoSuchElementException e) + { + // Exception not set. Not really from interest. + } + } + + protected void insertReportHeader() + { + if (getDesignTemplate() != null) + { + if (getDesignTemplate().getReportHeaderOn()) + { + // copy all Section information from Page Header to our Header + try + { + XSection xForeignSection = getDesignTemplate().getReportHeader(); + + if (xForeignSection != null) + { + getReportDefinition().setReportHeaderOn(true); + XSection xSection = getReportDefinition().getReportHeader(); + + // copy Sections + copySection(xForeignSection, xSection); + } + } + catch (Exception e) + { + } + } + else + { + // we won't a page header + getReportDefinition().setReportHeaderOn(false); + } + } + } + protected void clearReportFooter() + { + XSection xSection; + try + { + if (getReportDefinition().getReportFooterOn()) + { + xSection = getReportDefinition().getReportFooter(); + emptySection(xSection); + } + } + catch (com.sun.star.container.NoSuchElementException e) + { + // Exception not set. Not really from interest. + } + } + protected void insertReportFooter() + { + if (getDesignTemplate() != null) + { + if (getDesignTemplate().getReportFooterOn()) + { + // copy all Section information from Page Header to our Header + try + { + XSection xForeignSection = getDesignTemplate().getReportFooter(); + + if (xForeignSection != null) + { + getReportDefinition().setReportFooterOn(true); + XSection xSection = getReportDefinition().getReportFooter(); + + // copy Sections + copySection(xForeignSection, xSection); + } + } + catch (Exception e) + { + } + } + else + { + // we won't a page header + getReportDefinition().setReportFooterOn(false); + } + } + } + + // ------------------------------------------------------------------------- + protected void clearPageHeader() + { + XSection xSection; + try + { + if (getReportDefinition().getPageHeaderOn()) + { + xSection = getReportDefinition().getPageHeader(); + emptySection(xSection); + } + } + catch (com.sun.star.container.NoSuchElementException e) + { + // Exception not set. Not really from interest. + } + } + +// protected static String getDateString(String _sFormat) +// { +// GregorianCalendar aCalendar = new GregorianCalendar(); +// StringBuffer aBuf = new StringBuffer(); +// +// Locale aLocale = new Locale("en","US"); +// SimpleDateFormat aFormat = new SimpleDateFormat(_sFormat, aLocale); +// aBuf = aFormat.format(aCalendar.getTime(), aBuf, new FieldPosition(0) ); +// // DebugHelper.writeInfo("Date: " + aBuf.toString()); +// return aBuf.toString(); +// } + +// protected String getCurrentDate() +// { +// Calendar aCalendar = Calendar.getInstance(); +//// aCalendar.setTimeInMillis(1202382900000L); +//// aCalendar. +// Date aDate = new Date(); +// String sDate = DateFormat.getDateInstance().format(aDate); +// // String aCalStr = aCalendar.toString(); +// return sDate; +// // +//// Date aDate = new Date(); +//// aDate.setSeconds(0); +//// aDate.setMinutes(15); +//// aDate.setHours(12); +//// // aDate.setMonth(2); +//// // aDate.setYear(2008); +//// // aDate.setDay(7); +//// long nTime = aDate.getTime(); +//// Long aLong = new Long(nTime); +//// String aStr = aLong.toString(); +//// +//// Date aNewDate = new Date(1202382900000L); +////// aNewDate. +//// String aDateStr = aNewDate.toString(); +////// Datetime aNewTime = new Time(1202382900); +////// String aTimeStr = aNewTime.toString(); +//// +// +// } + + protected void clearPageFooter() + { + XSection xSection; + try + { + if (getReportDefinition().getPageFooterOn()) + { + xSection = getReportDefinition().getPageFooter(); + emptySection(xSection); + } + } + catch (com.sun.star.container.NoSuchElementException e) + { + // Exception not set. Should not from interest here. + + } + } + + public void setPageOrientation(int _nOrientation) + { + final int nWidth = getFromPageStyles("Width", 0); + final int nHeight = getFromPageStyles("Height", 0); + + if (com.sun.star.wizards.report.ReportLayouter.SOOPTLANDSCAPE == _nOrientation) + { + setToPageStyles("IsLandscape", Boolean.TRUE); + if (nWidth < nHeight) + { + setToPageStyles("Width", new Integer(nHeight)); + setToPageStyles("Height", new Integer(nWidth)); + } + } + else + { + setToPageStyles("IsLandscape", Boolean.FALSE); + if (nHeight < nWidth) + { + setToPageStyles("Width", new Integer(nHeight)); + setToPageStyles("Height", new Integer(nWidth)); + } + } + // dirty the PageWidth + m_nPageWidth = -1; + } + +/** + * Returns the width and height of a given string (_sText) in 1/100mm drawn in the given font descriptor. + * TODO: This function is a performance leak, we could store already calculated values in a map, to build a cache. Access should be much faster then. + * + * @param _sText + * @param _aFont + * @return width of given text in 1/100mm + */ + Size getPreferredSize(String _sText, FontDescriptor _aFont) + { + Size aSizeMM_100TH = new Size(0,0); + try + { + // Object aControlContainer = getGlobalMSF().createInstance("com.sun.star.awt.UnoControlContainer"); + // XControlContainer xControlContainer = (XControlContainer)UnoRuntime.queryInterface(XControlContainer.class, aControlContainer); + + final Object aFixedTextModel = getGlobalMSF().createInstance("com.sun.star.awt.UnoControlFixedTextModel"); + final XControlModel xFixedTextModel = (XControlModel)UnoRuntime.queryInterface(XControlModel.class, aFixedTextModel); + + final PropertySetHelper aPropertySetHelper = new PropertySetHelper(xFixedTextModel); +// aPropertySetHelper.showProperties(); + aPropertySetHelper.setPropertyValueDontThrow("FontDescriptor", _aFont); + + final Object aUnoCtrlFixedText = getGlobalMSF().createInstance("com.sun.star.awt.UnoControlFixedText"); +// XServiceInfo xServiceInfo2 = (XServiceInfo)UnoRuntime.queryInterface(XServiceInfo.class, aUnoCtrlFixedText); +// String[] sServices2 = xServiceInfo2.getSupportedServiceNames(); + + final XWindow xWindow = (XWindow)UnoRuntime.queryInterface(XWindow.class, aUnoCtrlFixedText); + xWindow.setVisible(false); + + final XControl xControl = (XControl)UnoRuntime.queryInterface(XControl.class, aUnoCtrlFixedText); + xControl.setModel(xFixedTextModel); + + final com.sun.star.awt.XFixedText xFixedText = (com.sun.star.awt.XFixedText)UnoRuntime.queryInterface(com.sun.star.awt.XFixedText.class, aUnoCtrlFixedText); + xFixedText.setText(_sText); + + final XLayoutConstrains xLayoutConstraints = (XLayoutConstrains)UnoRuntime.queryInterface(XLayoutConstrains.class, aUnoCtrlFixedText); + final Size aSizeInPixel = xLayoutConstraints.getPreferredSize(); + + final XWindowPeer xPeerOfReportDefinition = (XWindowPeer)UnoRuntime.queryInterface(XWindowPeer.class, getReportDefinition().getCurrentController().getFrame().getComponentWindow()); + xControl.createPeer(null, xPeerOfReportDefinition); + + final XWindowPeer x = xControl.getPeer(); + + final XUnitConversion xConversion = (XUnitConversion)UnoRuntime.queryInterface(XUnitConversion.class, x); + aSizeMM_100TH = xConversion.convertSizeToLogic(aSizeInPixel, com.sun.star.util.MeasureUnit.MM_100TH); + // xToolkit.createScreenCompatibleDevice(_nWidth, _nWidth). + // XWindow x = getReportDefinition().getCurrentController().getFrame().getContainerWindow(); + // Object aObj = _xSection.getParent(); + + // we don't need the created objects any longer + final XComponent xFixedTextDeleter = (XComponent)UnoRuntime.queryInterface(XComponent.class, xFixedText); + xFixedTextDeleter.dispose(); + + final XComponent xFixedTextModelDeleter = (XComponent)UnoRuntime.queryInterface(XComponent.class, aFixedTextModel); + xFixedTextModelDeleter.dispose(); + } + catch(Exception e) + { + // TODO: Exception not set. + + } + return aSizeMM_100TH; + } + + protected String getTableName() + { + if (m_sTableName != null) + { + return m_sTableName; + } + return ""; + } + + protected String getUserNameFromConfiguration() + { + String sFirstName = ""; + String sLastName = ""; + try + { + Object oProdNameAccess = Configuration.getConfigurationRoot(getGlobalMSF(), "org.openoffice.UserProfile/Data", false); + sFirstName = (String) Helper.getUnoObjectbyName(oProdNameAccess, "givenname"); + sLastName = (String) Helper.getUnoObjectbyName(oProdNameAccess, "sn"); + } + catch (Exception exception) + { + exception.printStackTrace(System.out); + } + return sFirstName + " " + sLastName; + } + +/** + * Helper function, to copy all not read only properties of _xFromSection to _xToSection + * @param _xFromSection + * @param _xToSection + */ + private void copyProperties(Object _aFrom, Object _aTo) + { + XPropertySet xFrom = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, _aFrom); + XPropertySet xTo = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, _aTo); + + + XPropertySetInfo xForeignPropInfo = xFrom.getPropertySetInfo(); + XPropertySetInfo xSectionPropInfo = xTo.getPropertySetInfo(); + Property[] aAllProperties = xForeignPropInfo.getProperties(); + for(int i=0;i 0.1f) + { + m_aFixedTextHelper.setCharWeight(_nCharWeight); + } + if (_nCharHeight > 0.1f) + { + m_aFixedTextHelper.setCharHeight(_nCharHeight); + } + + final FontDescriptor xFont = m_aFixedTextHelper.getFontDescriptor(); + final Size aSize = getPreferredSize(_sLabel, xFont); + nWidth = aSize.Width; + // cache the found width + m_aLabelWidthMap.put(sKey, new Integer(nWidth)); + } + catch (com.sun.star.uno.Exception e) + { + // TODO: Exception not set. + } + } + return nWidth; + } + + protected void doNotBreakInTable(Object _xSectionOrGroup) + { +// try +// { +// _xSection.setKeepTogether(true); + final PropertySetHelper aHelper = new PropertySetHelper(_xSectionOrGroup); + aHelper.setPropertyValueDontThrow("KeepTogether", Boolean.TRUE); +// } +// catch (com.sun.star.uno.Exception e) +// { +// // Exception not set, but not really from interest. +// } + } + + + protected DesignTemplate getDesignTemplate() + { + if (m_xDesignTemplate == null) + { + // initialise the report definition. + String sDefaultHeaderLayout = m_xReportDefinitionReadAccess.getDefaultHeaderLayout(); + loadAndSetBackgroundTemplate(sDefaultHeaderLayout); + + // copy all functions from the design template to the current report definition +// XFunctions xOtherFunctions = m_xDesignTemplate.getReportDefinition().getFunctions(); +// final int nFunctionCount = xOtherFunctions.getCount(); +// for (int i=0;i