/*
************************************************************************
*
* 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: ReportWizard.java,v $
* $Revision: 1.76 $
*
* 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 java.util.Vector;
// import com.sun.star.wizards.reportbuilder.ReportBuilderImplementation;
import com.sun.star.awt.Size;
import com.sun.star.awt.TextEvent;
import com.sun.star.awt.XControl;
import com.sun.star.awt.XControlModel;
import com.sun.star.awt.XFixedText;
import com.sun.star.awt.XLayoutConstrains;
import com.sun.star.awt.XTextListener;
import com.sun.star.awt.XWindow;
import com.sun.star.beans.PropertyValue;
// import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XContentEnumerationAccess;
import com.sun.star.deployment.XPackageInformationProvider;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.sdb.CommandType;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.wizards.common.*;
import com.sun.star.wizards.ui.*;
import com.sun.star.wizards.db.*;
import com.sun.star.lang.XComponent;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;
public class ReportWizard extends WizardDialog implements XTextListener, XCompletion
{
// XMultiServiceFactory xMSF;
// QueryMetaData CurDBMetaData;
FieldSelection CurGroupFieldSelection;
SortingComponent CurSortingComponent;
UnoDialog CurUnoProgressDialog;
TitlesComponent CurTitlesComponent;
CommandFieldSelection CurDBCommandFieldSelection;
GroupFieldHandler CurGroupFieldHandler;
ReportLayouter CurReportLayouter;
ReportFinalizer CurReportFinalizer;
PropertyValue[] DBGPROPERTYVALUE;
String sCommandName = "";
int nCommandType = -1;
int nReportMode = ReportFinalizer.SOCREATEDOCUMENT;
String sReportName = "";
public static final String SOREPORTFORMNAME = "ReportSource";
final int SOSELGROUPLST = 33;
final int SOTXTCOLTITLE = 48;
final int SOTITLESCROLLBAR = 49;
public static final int SONULLPAGE = 0;
public static final int SOMAINPAGE = 1;
public static final int SOTITLEPAGE = 2;
public static final int SOGROUPPAGE = 3;
public static final int SOSORTPAGE = 4;
public static final int SOTEMPLATEPAGE = 5;
public static final int SOSTOREPAGE = 6;
// ReportTextDocument CurReportDocument;
// ReportTextImplementation CurReportDocument;
IReportDocument CurReportDocument;
static String sMsgWizardName;
static String slblFields;
static String slblSelFields;
static String sShowBinaryFields;
static String sGroupings;
String[] WizardHeaderText = new String[6];
static String[] WizardTitle = new String[6];
static String sWriterFilterName;
static String slstDatabasesDefaultText;
static String slstTablesDefaultText;
static String sMsgErrorOccured;
static String sMsgSavingImpossible;
static String sMsgNoConnection;
// Progress display relevant Strings
static String slblColumnTitles;
static String slblColumnNames;
static String sMsgNoConnectionforDataimport;
static String sMsgQueryCreationImpossible;
public static String sMsgFilePathInvalid;
static String slblTables;
// public static String sBlindTextNote;
public static boolean bCloseDocument;
public boolean bHasEscapeProcessing = true;
public ReportWizard(XMultiServiceFactory xMSF)
{
super(xMSF, 34320);
super.addResourceHandler("Report Wizard", "dbw");
if (getReportResources( false) == true)
{
Helper.setUnoPropertyValues(xDialogModel,
new String[] { "Height","Moveable","Name","PositionX","PositionY","Step","TabIndex","Title","Width"},
new Object[] { new Integer(210),Boolean.TRUE, "DialogReport", new Integer(102),new Integer(41),new Integer(1), new Short((short)0), sMsgWizardName, new Integer(310)} );
drawNaviBar();
setRightPaneHeaders(this.WizardHeaderText);
}
}
protected void enterStep(int nOldStep, int nNewStep)
{
if ((nOldStep >= SOTEMPLATEPAGE) && (nNewStep < SOTEMPLATEPAGE))
{
// CurReportDocument.getDoc().oTextSectionHandler.removeTextSectionbyName("RecordSection");
// CurReportDocument.getDoc().oTextTableHandler.removeTextTablebyName("Tbl_RecordSection");
CurReportDocument.removeTextTableAndTextSection();
}
switch (nNewStep)
{
case SOMAINPAGE:
CurDBCommandFieldSelection.setModified(false);
break;
case SOTITLEPAGE:
String[] aFieldNames = CurReportDocument.getRecordParser().getFieldNames();
Map aFieldTitleSet = CurReportDocument.getRecordParser().getFieldTitleSet();
CurTitlesComponent.initialize(aFieldNames, aFieldTitleSet);
break;
case SOGROUPPAGE:
CurGroupFieldHandler.initialize();
break;
case SOSORTPAGE:
String[] aFieldNames2 = CurReportDocument.getRecordParser().getFieldNames();
String[][] aSortFieldNames = CurReportDocument.getRecordParser().getSortFieldNames();
CurSortingComponent.initialize(aFieldNames2, aSortFieldNames);
int nLength = CurReportDocument.getRecordParser().GroupFieldNames.length;
CurSortingComponent.setReadOnlyUntil(nLength, false);
break;
case SOTEMPLATEPAGE:
break;
case SOSTOREPAGE:
//TODO initialize with suitable PathName
CurReportFinalizer.initialize(CurReportDocument.getRecordParser());
break;
default:
break;
}
}
protected void leaveStep(int nOldStep, int nNewStep)
{
switch (nOldStep)
{
case SOMAINPAGE:
String[] aSelectedFieldNames = CurDBCommandFieldSelection.getSelectedFieldNames();
String aTableName = CurDBCommandFieldSelection.getSelectedCommandName();
// set all selected field names, DB Table name
// CurReportDocument.getRecordParser().initializeFieldColumns(aSelectedFieldNames, aTableName);
CurReportDocument.initializeFieldColumns(com.sun.star.sdb.CommandType.TABLE, aTableName, aSelectedFieldNames);
// CurReportDocument.initializeFieldColumns(aSelectedFieldNames, aSelectedCommandName);
// CurReportDocument.getRecordParser().setAllIncludedFieldNames(false);
if (CurDBCommandFieldSelection.isModified())
{
// cleanup document
CurReportDocument.clearDocument();
// CurReportDocument.getDoc().oTextSectionHandler.removeAllTextSections();
// CurReportDocument.getDoc().oTextTableHandler.removeAllTextTables();
// CurReportDocument.getDoc().DBColumnsVector = new Vector();
CurReportDocument.getRecordParser().setGroupFieldNames(new String[]{});
CurGroupFieldHandler.removeGroupFieldNames();
}
break;
case SOTITLEPAGE:
String[] sFieldTitles = CurTitlesComponent.getFieldTitles();
// set new field name titles
// CurReportDocument.getRecordParser().setFieldTitles(sFieldTitles);
CurReportDocument.setFieldTitles(sFieldTitles);
break;
case SOGROUPPAGE:
// TODO: DESIGN!!! a getter should return a value!!!
CurGroupFieldHandler.getGroupFieldNames(CurReportDocument.getRecordParser());
String[] aGroupFieldNames = CurReportDocument.getRecordParser().GroupFieldNames;
// CurReportDocument.getRecordParser().prependSortFieldNames(aGroupFieldNames);
CurReportDocument.setGrouping(aGroupFieldNames);
break;
case SOSORTPAGE:
String[][] aSortFieldNames = CurSortingComponent.getSortFieldNames();
// CurReportDocument.getRecordParser().SortFieldNames = aSortFieldNames;
CurReportDocument.setSorting(aSortFieldNames);
// TODO: why do we make a switch here
super.enablefromStep(SOTEMPLATEPAGE, true);
break;
case SOTEMPLATEPAGE:
break;
case SOSTOREPAGE:
break;
default:
break;
}
if ((nOldStep < SOTEMPLATEPAGE) && (super.getNewStep() >= SOTEMPLATEPAGE))
{
// this is called before SOTEMPLATEPAGE, after SOGROUPPAGE
CurReportDocument.getRecordParser().createRecordFieldNames();
CurReportLayouter.initialize(CurReportDocument.getContentPath());
}
}
private XComponent[] dialogFinish(short RetValue)
{
XComponent[] ret = null;
// Report Wizard Dialog is done.
boolean bdisposeDialog = true;
switch (RetValue)
{
case 0:
// via Cancelbutton or via sourceCode with "endExecute"
this.xComponent.dispose();
if (bCloseDocument == true) {
// OfficeDocument.dispose(xMSF, CurReportDocument.getDoc().xComponent);
CurReportDocument.dispose();
return ret;
}
if ((nReportMode == ReportFinalizer.SOCREATETEMPLATE) || (nReportMode == ReportFinalizer.SOUSETEMPLATE)) {
bdisposeDialog = false;
// Add Report to the DB View
// old: CurReportDocument.getRecordParser().addReportDocument(CurReportDocument.getComponent(), true);
CurReportDocument.addReportToDBView();
boolean bOpenInDesign = ( nReportMode == ReportFinalizer.SOCREATETEMPLATE );
// Create Report
// old: ret = CurReportDocument.getRecordParser().openReportDocument(sReportName, true, bOpenInDesign);
ret = CurReportDocument.createFinalReportDocument(sReportName, true, bOpenInDesign);
}
else
{
bdisposeDialog = false;
CurReportDocument.importReportData(this);
// Dataimport CurDataimport = new Dataimport(xMSF);
// CurDataimport.CurReportDocument = CurReportDocument;
// CurDataimport.showProgressDisplay(xMSF, false);
// importReportData(xMSF, CurDataimport);
// old: ret = CurReportDocument.getRecordParser().openReportDocument(sReportName, false, false);
ret = CurReportDocument.createFinalReportDocument(sReportName, false, false);
}
return ret;
case 1:
if (bdisposeDialog == true)
{
// CurReportDocument.getDoc().unlockallControllers();
}
break;
}
return null;
}
private boolean executeQuery()
{
boolean bQueryCreated = false;
if (this.CurDBCommandFieldSelection.getSelectedCommandType() == CommandType.TABLE)
{
bQueryCreated = CurReportDocument.getRecordParser().oSQLQueryComposer.setQueryCommand(sMsgWizardName, this.xWindow, false, false);
CurReportDocument.setCommandType( CommandType.COMMAND );
String sQuery = CurReportDocument.getRecordParser().oSQLQueryComposer.getQuery();
CurReportDocument.setCommand( sQuery );
}
else
{
try
{
String sQueryName = CurDBCommandFieldSelection.getSelectedCommandName();
DBMetaData.CommandObject oCommand = CurReportDocument.getRecordParser().getQueryByName(sQueryName);
bHasEscapeProcessing = CurReportDocument.getRecordParser().hasEscapeProcessing(oCommand.xPropertySet);
String sCommand = (String) oCommand.xPropertySet.getPropertyValue("Command");
if (bHasEscapeProcessing)
{
// String sCommand = (String) oCommand.xPropertySet.getPropertyValue("Command");
bQueryCreated = (!sCommand.equals(""));
CurReportDocument.getRecordParser().oSQLQueryComposer.xQueryAnalyzer.setQuery(sCommand);
CurReportDocument.getRecordParser().oSQLQueryComposer.prependSortingCriteria();
// TODO: check with query
CurReportDocument.setCommandType( CommandType.COMMAND );
CurReportDocument.setCommand( CurReportDocument.getRecordParser().oSQLQueryComposer.getQuery() );
bQueryCreated = true;
}
else
{
CurReportDocument.setCommandType( CommandType.COMMAND );
CurReportDocument.setCommand( sCommand );
bQueryCreated = true;
}
}
catch (Exception e)
{
e.printStackTrace(System.out);
}
}
if (!bQueryCreated)
{
super.vetoableChange(null);
}
return bQueryCreated;
}
public static void main(String args[])
{
String ConnectStr = "uno:socket,host=localhost,port=8107;urp;StarOffice.NamingService"; //localhost ;Lo-1.Germany.sun.com; 10.16.65.155
try
{
XMultiServiceFactory xLocMSF = com.sun.star.wizards.common.Desktop.connect(ConnectStr);
tests(xLocMSF);
ReportWizard CurReportWizard = new ReportWizard(xLocMSF);
if(xLocMSF != null)
{
System.out.println("Connected to "+ ConnectStr);
PropertyValue[] curproperties = new PropertyValue[1];
// curproperties[0] = Properties.createProperty(
// "DatabaseLocation",
// "file:///localhome/bc93774/NewDatabase2" +
// "C:/Documents and Settings/ll93751/My Documents/RptWizard01_DB.odb");
// "file://C:/Documents%20and%20Settings/ll93751/My%20Documents/RptWizard01_DB.odb");
// "C:/Documents and Settings/bc93774.EHAM02-DEV/My Documents/MyHSQL.odb"); //MyDocAssign.odb; baseLocation ); "DataSourceName", "db1");
// curproperties[0] = Properties.createProperty("DataSourceName", "Bibliography");
curproperties[0] = Properties.createProperty("DataSourceName", "RptWizard01_DB");
CurReportWizard.startReportWizard(xLocMSF, curproperties, true);
}
}
catch(Exception exception)
{
exception.printStackTrace(System.out);
}
System.exit(1);
}
private static void tests(XMultiServiceFactory _xMSF)
{
try
{
// String[] sServices = _xMSF.getAvailableServiceNames();
// File aFile = new File("C:/temp/services.txt");
// aFile.delete();
// FileWriter aRAF = new FileWriter(aFile);
// for (int i=0;i<sServices.length;i++)
// {
// aRAF.write(sServices[i]);
// aRAF.write("\n");
// }
// aRAF.close();
// XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface(XServiceInfo.class, _xMSF);
// String[] sServices = xServiceInfo.getSupportedServiceNames();
// XControl xControl = (XControl)UnoRuntime.queryInterface(XControl.class, xFormattedField);
// Object aPeer = xControl.getPeer();
// XTextConstraints xTC = (XTextConstraints)UnoRuntime.queryInterface(XTextConstraints.class, aPeer);
// int nHeight = xTC.getTextHeight();
// int nWidth = xTC.getTextWidth("Blah Fasel");
// Object aTextShapeObj = _xMSF.createInstance("com.sun.star.drawing.TextShape");
// XText xText = (XText)UnoRuntime.queryInterface(XText.class, aTextShapeObj);
// xText.setString("Blah fasel");
//
// XServiceInfo xServiceInfo2 = (XServiceInfo)UnoRuntime.queryInterface(XServiceInfo.class, aTextShapeObj);
// String[] sServices2 = xServiceInfo2.getSupportedServiceNames();
// Object aToolkitObj = _xMSF.createInstance("com.sun.star.awt.Toolkit");
// XToolkit xToolkit = (XToolkit)UnoRuntime.queryInterface(XToolkit.class, aToolkitObj);
// WindowDescriptor aDescriptor = new WindowDescriptor();
// aDescriptor.Bounds = new Rectangle(0,0,640,480);
//
// XWindowPeer aWindowPeer = xToolkit.createWindow(aDescriptor);
// XWindow xWindow = (XWindow)UnoRuntime.queryInterface(XWindow.class, aWindowPeer);
// xWindow.setVisible(true);
// aWindowPeer.setBackground(0x00000000);
Object aControlContainer = _xMSF.createInstance("com.sun.star.awt.UnoControlContainer");
// XControlContainer xControlContainer = (XControlContainer)UnoRuntime.queryInterface(XControlContainer.class, aControlContainer);
Object aFixedTextModel = _xMSF.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
XControlModel xFixedTextModel = (XControlModel)UnoRuntime.queryInterface(XControlModel.class, aFixedTextModel);
// nicht das Model, sondern gleich den FixedText nehmen??
// XMultiServiceFactory xMSF = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xFixedTextModel);
Object aFixedText = _xMSF.createInstance("com.sun.star.awt.UnoControlFixedText");
XServiceInfo xServiceInfo2 = (XServiceInfo)UnoRuntime.queryInterface(XServiceInfo.class, aFixedText);
String[] sServices2 = xServiceInfo2.getSupportedServiceNames();
XWindow xWindow = (XWindow)UnoRuntime.queryInterface(XWindow.class, aFixedText);
xWindow.setVisible(true);
XFixedText xFixedText = (XFixedText)UnoRuntime.queryInterface(XFixedText.class, aFixedText);
xFixedText.setText("Dies ist ein String");
XControl xControl = (XControl)UnoRuntime.queryInterface(XControl.class, xFixedText);
xControl.setModel(xFixedTextModel);
XLayoutConstrains xLayoutConstrains = (XLayoutConstrains)UnoRuntime.queryInterface(XLayoutConstrains.class, aFixedText);
Size aSize = xLayoutConstrains.getPreferredSize();
// xToolkit.createScreenCompatibleDevice(_nWidth, _nWidth).
// XWindow x = getReportDefinition().getCurrentController().getFrame().getContainerWindow();
// Object aObj = _xSection.getParent();
int dummy = 0;
}
catch (Exception e)
{
int dummy = 0;
}
}
public void buildSteps()
{
// CurReportDocument.getDoc().xProgressBar.setValue(30);
CurDBCommandFieldSelection = new CommandFieldSelection(this, CurReportDocument.getRecordParser(), 100, slblFields, slblSelFields, slblTables, true, 34330);
CurDBCommandFieldSelection.addFieldSelectionListener(new FieldSelectionListener());
insertLabel("lblBinaryFields",
new String[] {"Height", "Label", "PositionX", "PositionY", "Step", "Width"},
new Object[] {new Integer(16), sShowBinaryFields, new Integer(95), new Integer(162), new Integer(1), new Integer(210)});
// CurReportDocument.getDoc().xProgressBar.setValue(40);
CurTitlesComponent = new TitlesComponent(this, SOTITLEPAGE, 97, 37, 210, 7, slblColumnNames, slblColumnTitles, 34381);
CurTitlesComponent.addTextListener(this);
// CurReportDocument.getDoc().xProgressBar.setValue(50);
CurGroupFieldHandler = new GroupFieldHandler(CurReportDocument, this);
// CurReportDocument.getDoc().xProgressBar.setValue(60);
CurSortingComponent = new SortingComponent(this, SOSORTPAGE, 95, 30, 210, 34346);
// CurReportDocument.getDoc().xProgressBar.setValue(70);
CurReportLayouter = new ReportLayouter(xMSF, CurReportDocument, this);
// CurReportDocument.getDoc().xProgressBar.setValue(80);
CurReportFinalizer = new ReportFinalizer(xMSF, CurReportDocument, this);
// CurReportDocument.getDoc().xProgressBar.setValue(100);
bCloseDocument = true;
// CurReportDocument.getDoc().xProgressBar.end();
enableNavigationButtons(false, false, false);
}
public void finishWizard()
{
int ncurStep = getCurrentStep();
if ((switchToStep(ncurStep, SOSTOREPAGE)) || (ncurStep == SOSTOREPAGE))
{
if (this.executeQuery())
{
if (CurReportFinalizer.finish())
{
nReportMode = CurReportFinalizer.getReportOpenMode();
sReportName = CurReportFinalizer.getStoreName();
xDialog.endExecute();
}
}
}
}
public void cancelWizard()
{
xDialog.endExecute();
}
public void insertQueryRelatedSteps()
{
setRMItemLabels(m_oResource, UIConsts.RID_QUERY + 80);
addRoadmap();
int i = 0;
i = insertRoadmapItem(0, true, m_oResource.getResText(UIConsts.RID_QUERY + 80), SOMAINPAGE);
i = insertRoadmapItem(i, false, m_oResource.getResText(UIConsts.RID_REPORT + 68), SOTITLEPAGE);
i = insertRoadmapItem(i, false, m_oResource.getResText(UIConsts.RID_REPORT + 11), SOGROUPPAGE);
i = insertRoadmapItem(i, false, m_oResource.getResText(UIConsts.RID_REPORT + 12), SOSORTPAGE); // Orderby is always supported
i = insertRoadmapItem(i, false, m_oResource.getResText(UIConsts.RID_REPORT + 13), SOTEMPLATEPAGE);
i = insertRoadmapItem(i, false, m_oResource.getResText(UIConsts.RID_REPORT + 14), SOSTOREPAGE);