/*
************************************************************************
*
* 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: ReportTextImplementation.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
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
package com.sun.star.wizards.report;
import com.sun.star.awt.VclWindowPeerAttribute;
import com.sun.star.awt.XWindowPeer;
import com.sun.star.beans.PropertyValue;
import com.sun.star.container.XNameAccess;
import com.sun.star.container.XNameContainer;
import com.sun.star.container.XNamed;
import com.sun.star.frame.XFrame;
// import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.XComponent;
import com.sun.star.sdb.CommandType;
import com.sun.star.table.XCellRange;
import com.sun.star.text.XTextContent;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextTable;
import com.sun.star.uno.Any;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.wizards.common.FileAccess;
import com.sun.star.wizards.common.Helper;
import com.sun.star.wizards.common.InvalidQueryException;
import com.sun.star.wizards.common.JavaTools;
import com.sun.star.wizards.common.Resource;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.wizards.common.SystemDialog;
import com.sun.star.wizards.db.DBMetaData;
import com.sun.star.wizards.db.SQLQueryComposer;
import com.sun.star.wizards.document.OfficeDocument;
import com.sun.star.wizards.ui.UIConsts;
import java.util.ArrayList;
import java.util.Vector;
/**
*
* @author ll93751
*/
public class ReportTextImplementation extends ReportImplementationHelper implements IReportDocument
{
private ReportTextDocument m_aDoc;
private Object m_aInitialDoc;
private Resource m_aResource;
public void setInitialDocument(Object _aDoc)
{
m_aInitialDoc = _aDoc;
}
/**
* This is a TEMPORARY function to give direct access to the old text document.
* We have to remove this!!!
* @return
*/
ReportTextDocument getDoc()
{
if (m_aDoc == null)
{
if (m_aInitialDoc instanceof XTextDocument)
{
m_aDoc = new ReportTextDocument(getMSF(), (XTextDocument)m_aInitialDoc, m_aResource, getRecordParser() );
}
else if (m_aInitialDoc instanceof String)
{
m_aDoc = new ReportTextDocument(getMSF(), (String)m_aInitialDoc, m_aResource, getRecordParser() );
}
else
{
throw new RuntimeException("Unknown type for setInitialDoc() given.");
}
}
return m_aDoc;
}
public void clearDocument()
{
int dummy = 0;
/*CurReportDocument.*/ getDoc().oTextSectionHandler.removeAllTextSections();
/*CurReportDocument.*/ getDoc().oTextTableHandler.removeAllTextTables();
/*CurReportDocument.*/ getDoc().DBColumnsVector = new Vector();
//getRecordParser().setGroupFieldNames(new String[]{});
// CurGroupFieldHandler.removeGroupFieldNames();
}
private ReportTextImplementation(XMultiServiceFactory _xMSF, Resource _oResource)
{
super(_xMSF, ReportLayouter.SOOPTLANDSCAPE);
m_aResource = _oResource;
}
static IReportDocument create(XMultiServiceFactory _xMSF /*, String _sPreviewURL */ , Resource _oResource )
{
ReportTextImplementation a = new ReportTextImplementation(_xMSF, _oResource);
String sPreviewURL = a.getLayoutPath(); // a.getReportPath() + "/stl-default.ott";
a.setInitialDocument(sPreviewURL);
a.initialResources();
return a;
}
static IReportDocument create(XMultiServiceFactory _xMSF, XTextDocument _aDoc, Resource _oResource )
{
ReportTextImplementation a = new ReportTextImplementation(_xMSF, _oResource);
a.setInitialDocument(_aDoc);
a.initialResources();
return a;
}
public XWindowPeer getWizardParent()
{
// throw new UnsupportedOperationException("Not supported yet.");
return getDoc().xWindowPeer;
}
static String sMsgQueryCreationImpossible;
static String sReportFormNotExisting;
static String sMsgHiddenControlMissing;
static String sMsgEndAutopilot;
static String sMsgConnectionImpossible;
static String sMsgNoConnection;
static String[] ReportMessages = new String[4];
private void initialResources()
{
sReportFormNotExisting = m_aResource.getResText(UIConsts.RID_REPORT + 64);
sMsgQueryCreationImpossible = m_aResource.getResText(UIConsts.RID_REPORT + 65);
sMsgHiddenControlMissing = m_aResource.getResText(UIConsts.RID_REPORT + 66);
sMsgEndAutopilot = m_aResource.getResText(UIConsts.RID_DB_COMMON + 33);
sMsgNoConnection = m_aResource.getResText(UIConsts.RID_DB_COMMON + 14);
}
public void addTextSectionCopies()
{
m_aDoc.setLayoutSectionsVisible(false);
XTextCursor xTextCursor = ReportTextDocument.createTextCursor(m_aDoc.xTextDocument.getText());
xTextCursor.gotoStart(false);
for (int i = 0; i < getRecordParser().GroupFieldNames.length; i++)
{
XNamed xNamedTextSection = addLinkedTextSection(xTextCursor, ReportTextDocument.GROUPSECTION + Integer.toString(i + 1), null, null);
xNamedTextSection.setName(ReportTextDocument.COPYOFGROUPSECTION + (i+1));
renameTableofLastSection(ReportTextDocument.COPYOFTBLGROUPSECTION + (i+1));
}
if( getRecordParser().getRecordFieldNames().length > 0)
{
XNamed xNamedTextSection = addLinkedTextSection(xTextCursor, ReportTextDocument.RECORDSECTION, null, null);
xNamedTextSection.setName(ReportTextDocument.COPYOFRECORDSECTION);
renameTableofLastSection(ReportTextDocument.COPYOFTBLRECORDSECTION);
}
}
private XNamed addLinkedTextSection(XTextCursor xTextCursor, String sLinkRegion, DBColumn CurDBColumn, Object CurGroupValue)
{
XNamed xNamedTextSection = null;
try
{
XInterface xTextSection = (XInterface) getDocumentServiceFactory().createInstance("com.sun.star.text.TextSection");
XTextContent xTextSectionContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xTextSection);
xNamedTextSection = (XNamed) UnoRuntime.queryInterface(XNamed.class, xTextSection);
xTextCursor.gotoEnd(false);
xTextCursor.getText().insertTextContent(xTextCursor, xTextSectionContent, true);
Helper.setUnoPropertyValue(xTextSection, "LinkRegion", sLinkRegion);
if (CurDBColumn != null)
{
boolean bIsGroupTable = (sLinkRegion.equals(ReportTextDocument.RECORDSECTION) != true);
if (bIsGroupTable == true)
{
XTextTable xTextTable = getDoc().oTextTableHandler.getlastTextTable();
XCellRange xCellRange =