1*a1b4a26bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a1b4a26bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a1b4a26bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a1b4a26bSAndrew Rist  * distributed with this work for additional information
6*a1b4a26bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a1b4a26bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a1b4a26bSAndrew Rist  * "License"); you may not use this file except in compliance
9*a1b4a26bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a1b4a26bSAndrew Rist  *
11*a1b4a26bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a1b4a26bSAndrew Rist  *
13*a1b4a26bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a1b4a26bSAndrew Rist  * software distributed under the License is distributed on an
15*a1b4a26bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a1b4a26bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*a1b4a26bSAndrew Rist  * specific language governing permissions and limitations
18*a1b4a26bSAndrew Rist  * under the License.
19*a1b4a26bSAndrew Rist  *
20*a1b4a26bSAndrew Rist  *************************************************************/
21*a1b4a26bSAndrew Rist 
22*a1b4a26bSAndrew Rist 
23cdf0e10cSrcweir package com.sun.star.wizards.report;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
26cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
27cdf0e10cSrcweir import com.sun.star.sdb.application.XDatabaseDocumentUI;
28cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.wizards.ui.*;
31cdf0e10cSrcweir import com.sun.star.wizards.common.*;
32cdf0e10cSrcweir import com.sun.star.uno.Exception;
33cdf0e10cSrcweir import java.util.logging.Level;
34cdf0e10cSrcweir import java.util.logging.Logger;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir public class Dataimport extends UnoDialog2 implements com.sun.star.awt.XActionListener
37cdf0e10cSrcweir { // extends ReportWizard
38cdf0e10cSrcweir 
39cdf0e10cSrcweir     // ReportTextDocument CurReportDocument;
40cdf0e10cSrcweir     IReportDocument CurReportDocument;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //    PropertyValue[] CurProperties;
43cdf0e10cSrcweir     static boolean bStopProcess;
44cdf0e10cSrcweir     static String sProgressDBConnection;
45cdf0e10cSrcweir     static String sProgressDataImport;
46cdf0e10cSrcweir     static String sProgressBaseCurRecord;
47cdf0e10cSrcweir     static String sProgressCurRecord;
48cdf0e10cSrcweir     static String sProgressTitle;
49cdf0e10cSrcweir     static String sStop;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir //    public static final String TBLRECORDSECTION = ReportTextDocument.TBLRECORDSECTION;
52cdf0e10cSrcweir //    public static final String TBLGROUPSECTION = ReportTextDocument.TBLGROUPSECTION;
53cdf0e10cSrcweir //    public static final String RECORDSECTION = ReportTextDocument.RECORDSECTION;
54cdf0e10cSrcweir //    public static final String GROUPSECTION = ReportTextDocument.GROUPSECTION;
55cdf0e10cSrcweir //    public static final String COPYOFTBLRECORDSECTION = ReportTextDocument.COPYOFTBLRECORDSECTION;
56cdf0e10cSrcweir //    public static final String COPYOFTBLGROUPSECTION = ReportTextDocument.COPYOFTBLGROUPSECTION;
57cdf0e10cSrcweir //    public static final String COPYOFRECORDSECTION = ReportTextDocument.COPYOFRECORDSECTION;
58cdf0e10cSrcweir //    public static final String COPYOFGROUPSECTION = ReportTextDocument.COPYOFGROUPSECTION;
Dataimport(XMultiServiceFactory _xMSF)59cdf0e10cSrcweir     public Dataimport(XMultiServiceFactory _xMSF)
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         super(_xMSF);
62cdf0e10cSrcweir         super.addResourceHandler("ReportWizard", "dbw");
63cdf0e10cSrcweir         sProgressDBConnection = m_oResource.getResText(UIConsts.RID_DB_COMMON + 34);
64cdf0e10cSrcweir         sProgressDataImport = m_oResource.getResText(UIConsts.RID_REPORT + 67);
65cdf0e10cSrcweir         sProgressTitle = m_oResource.getResText(UIConsts.RID_REPORT + 62);
66cdf0e10cSrcweir         sProgressBaseCurRecord = m_oResource.getResText(UIConsts.RID_REPORT + 63);
67cdf0e10cSrcweir         sStop = m_oResource.getResText(UIConsts.RID_DB_COMMON + 21);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
disposing(com.sun.star.lang.EventObject eventObject)71cdf0e10cSrcweir     public void disposing(com.sun.star.lang.EventObject eventObject)
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir 
actionPerformed(com.sun.star.awt.ActionEvent actionEvent)75cdf0e10cSrcweir     public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent)
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir         // bStopProcess = true;
78cdf0e10cSrcweir         CurReportDocument.StopProcess();
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir //    public static void main(String args[])
82cdf0e10cSrcweir //        {
83cdf0e10cSrcweir //            String ConnectStr = "uno:socket,host=localhost,port=8100;urp,negotiate=0,forcesynchronous=1;StarOffice.NamingService";
84cdf0e10cSrcweir //            XMultiServiceFactory xMSF = null;
85cdf0e10cSrcweir //            try
86cdf0e10cSrcweir //            {
87cdf0e10cSrcweir //                xMSF = com.sun.star.wizards.common.Desktop.connect(ConnectStr);
88cdf0e10cSrcweir //                if (xMSF != null)
89cdf0e10cSrcweir //                {
90cdf0e10cSrcweir //                    System.out.println("Connected to " + ConnectStr);
91cdf0e10cSrcweir //                }
92cdf0e10cSrcweir //                PropertyValue[] curproperties = new PropertyValue[3];
93cdf0e10cSrcweir //                curproperties[0] = Properties.createProperty("DatabaseLocation", "file:///C:/Documents and Settings/bc93774.EHAM02-DEV/My Documents/MyHSQL.odb");
94cdf0e10cSrcweir ////            curproperties[0] = Properties.createProperty("DatabaseLocation", "file:///C:/Documents and Settings/bc93774.EHAM02-DEV/My Documents/MyDocAssign.odb"); //baseLocation ); "DataSourceName", "db1");
95cdf0e10cSrcweir ////            curproperties[0] = Properties.createProperty("DataSourceName", "Bibliography");
96cdf0e10cSrcweir //                curproperties[1] = Properties.createProperty(PropertyNames.COMMAND_TYPE, new Integer(CommandType.TABLE));
97cdf0e10cSrcweir //                curproperties[2] = Properties.createProperty(PropertyNames.COMMAND, "Table2");
98cdf0e10cSrcweir //
99cdf0e10cSrcweir //                Dataimport CurDataimport = new Dataimport(xMSF);
100cdf0e10cSrcweir //                TextDocument oTextDocument = new TextDocument(xMSF, true, null);
101cdf0e10cSrcweir //                CurDataimport.createReport(xMSF, oTextDocument.xTextDocument, curproperties);
102cdf0e10cSrcweir //
103cdf0e10cSrcweir //            }
104cdf0e10cSrcweir //            catch (Exception e)
105cdf0e10cSrcweir //            {
106cdf0e10cSrcweir //                e.printStackTrace(System.out);
107cdf0e10cSrcweir //            }
108cdf0e10cSrcweir //            catch (java.lang.Exception javaexception)
109cdf0e10cSrcweir //            {
110cdf0e10cSrcweir //                javaexception.printStackTrace(System.out);
111cdf0e10cSrcweir //            }
112cdf0e10cSrcweir //        }
showProgressDisplay(XMultiServiceFactory xMSF, boolean bgetConnection)113cdf0e10cSrcweir     public void showProgressDisplay(XMultiServiceFactory xMSF, boolean bgetConnection)
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         try
116cdf0e10cSrcweir         {
117cdf0e10cSrcweir             Helper.setUnoPropertyValues(xDialogModel,
118cdf0e10cSrcweir                     new String[]
119cdf0e10cSrcweir                     {
120cdf0e10cSrcweir                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TITLE, PropertyNames.PROPERTY_WIDTH
121cdf0e10cSrcweir                     },
122cdf0e10cSrcweir                     new Object[]
123cdf0e10cSrcweir                     {
124cdf0e10cSrcweir                         84, 0, sProgressTitle, 180
125cdf0e10cSrcweir                     });
126cdf0e10cSrcweir             com.sun.star.awt.FontDescriptor oFontDesc = new com.sun.star.awt.FontDescriptor();
127cdf0e10cSrcweir             oFontDesc.Weight = com.sun.star.awt.FontWeight.BOLD;
128cdf0e10cSrcweir             if (bgetConnection)
129cdf0e10cSrcweir             {
130cdf0e10cSrcweir                 insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblProgressDBConnection",
131cdf0e10cSrcweir                         new String[]
132cdf0e10cSrcweir                         {
133cdf0e10cSrcweir                             PropertyNames.FONT_DESCRIPTOR, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH
134cdf0e10cSrcweir                         },
135cdf0e10cSrcweir                         new Object[]
136cdf0e10cSrcweir                         {
137cdf0e10cSrcweir                             oFontDesc, 10, sProgressDBConnection, 6, 6, 0, 150
138cdf0e10cSrcweir                         });
139cdf0e10cSrcweir 
140cdf0e10cSrcweir                 insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblProgressDataImport",
141cdf0e10cSrcweir                         new String[]
142cdf0e10cSrcweir                         {
143cdf0e10cSrcweir                             PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH
144cdf0e10cSrcweir                         },
145cdf0e10cSrcweir                         new Object[]
146cdf0e10cSrcweir                         {
147cdf0e10cSrcweir                             10, sProgressDataImport, 6, 24, 0, 120
148cdf0e10cSrcweir                         });
149cdf0e10cSrcweir             }
150cdf0e10cSrcweir             else
151cdf0e10cSrcweir             {
152cdf0e10cSrcweir                 insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblProgressDataImport",
153cdf0e10cSrcweir                         new String[]
154cdf0e10cSrcweir                         {
155cdf0e10cSrcweir                             PropertyNames.FONT_DESCRIPTOR, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH
156cdf0e10cSrcweir                         },
157cdf0e10cSrcweir                         new Object[]
158cdf0e10cSrcweir                         {
159cdf0e10cSrcweir                             oFontDesc, 10, sProgressDataImport, 6, 24, 0, 120
160cdf0e10cSrcweir                         });
161cdf0e10cSrcweir             }
162cdf0e10cSrcweir             insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblCurProgress",
163cdf0e10cSrcweir                     new String[]
164cdf0e10cSrcweir                     {
165cdf0e10cSrcweir                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH
166cdf0e10cSrcweir                     },
167cdf0e10cSrcweir                     new Object[]
168cdf0e10cSrcweir                     {
169cdf0e10cSrcweir                         10, PropertyNames.EMPTY_STRING, 12, 42, 0, 120
170cdf0e10cSrcweir                     });
171cdf0e10cSrcweir 
172cdf0e10cSrcweir             insertButton("cmdCancel", 10000, this,
173cdf0e10cSrcweir                     new String[]
174cdf0e10cSrcweir                     {
175cdf0e10cSrcweir                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH, PropertyNames.PROPERTY_LABEL
176cdf0e10cSrcweir                     },
177cdf0e10cSrcweir                     new Object[]
178cdf0e10cSrcweir                     {
179cdf0e10cSrcweir                         14, HelpIds.getHelpIdString(34321), 74, 58, 0, new Short((short) 1), 40, sStop
180cdf0e10cSrcweir                     });
181cdf0e10cSrcweir             createWindowPeer(CurReportDocument.getWizardParent());
182cdf0e10cSrcweir             calculateDialogPosition(CurReportDocument.getFrame().getComponentWindow().getPosSize());
183cdf0e10cSrcweir             xWindow.setVisible(true);
184cdf0e10cSrcweir             super.xReschedule.reschedule();
185cdf0e10cSrcweir             }
186cdf0e10cSrcweir         catch (Exception e)
187cdf0e10cSrcweir         {
188cdf0e10cSrcweir             Logger.getLogger(Dataimport.class.getName()).log(Level.SEVERE, null, e);
189cdf0e10cSrcweir         // return;
190cdf0e10cSrcweir         }
191cdf0e10cSrcweir         catch (java.lang.Exception e)
192cdf0e10cSrcweir         {
193cdf0e10cSrcweir             Logger.getLogger(Dataimport.class.getName()).log(Level.SEVERE, null, e);
194cdf0e10cSrcweir         // return;
195cdf0e10cSrcweir         }
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     // public void importReportData(final XMultiServiceFactory xMSF, final Dataimport CurDataimport, final ReportTextDocument CurReportDocument.getDoc()) {
importReportData(final XMultiServiceFactory _xMSF, final Dataimport _CurDataimport, IReportDocument _CurReportDocument, PropertyValue[] _properties)199cdf0e10cSrcweir     public void importReportData(final XMultiServiceFactory _xMSF, final Dataimport _CurDataimport, IReportDocument _CurReportDocument, PropertyValue[] _properties)
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         if (CurReportDocument.reconnectToDatabase(_xMSF, _properties))
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir             // The following calls to remove the Sections must occur after the connection to the database
204cdf0e10cSrcweir             modifyFontWeight("lblProgressDBConnection", com.sun.star.awt.FontWeight.NORMAL);
205cdf0e10cSrcweir             modifyFontWeight("lblProgressDataImport", com.sun.star.awt.FontWeight.BOLD);
206cdf0e10cSrcweir             CurReportDocument.insertDatabaseDatatoReportDocument(_xMSF);
207cdf0e10cSrcweir         }
208cdf0e10cSrcweir         xComponent.dispose();
209cdf0e10cSrcweir         CurReportDocument.getRecordParser().dispose();
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir 
createReport( XMultiServiceFactory xMSF, XDatabaseDocumentUI i_documentUI, XTextDocument _textDocument, PropertyValue[] properties)212cdf0e10cSrcweir     public void createReport( XMultiServiceFactory xMSF, XDatabaseDocumentUI i_documentUI, XTextDocument _textDocument,
213cdf0e10cSrcweir         PropertyValue[] properties)
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir         CurReportDocument = ReportTextImplementation.create( xMSF, i_documentUI, _textDocument, m_oResource );
216cdf0e10cSrcweir         showProgressDisplay(xMSF, true);
217cdf0e10cSrcweir         importReportData(xMSF, this, CurReportDocument, properties);
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir }
220