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