1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sw.hxx" 30*cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION 31*cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION 32*cdf0e10cSrcweir #endif 33*cdf0e10cSrcweir #include <swtypes.hxx> 34*cdf0e10cSrcweir #include <addresslistdialog.hxx> 35*cdf0e10cSrcweir #include <selectdbtabledialog.hxx> 36*cdf0e10cSrcweir #include <createaddresslistdialog.hxx> 37*cdf0e10cSrcweir #include <mailmergewizard.hxx> 38*cdf0e10cSrcweir #include <mmconfigitem.hxx> 39*cdf0e10cSrcweir #include <mmaddressblockpage.hxx> 40*cdf0e10cSrcweir #ifndef _DBMGR_HXX 41*cdf0e10cSrcweir #include <dbmgr.hxx> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #include <dbconfig.hxx> 44*cdf0e10cSrcweir #include <unotools/tempfile.hxx> 45*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 46*cdf0e10cSrcweir #include <vcl/svapp.hxx> 47*cdf0e10cSrcweir #include <tools/urlobj.hxx> 48*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 49*cdf0e10cSrcweir #include <comphelper/types.hxx> 50*cdf0e10cSrcweir #include <com/sun/star/sdbc/XCloseable.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/sdb/XDocumentDataSource.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowSet.hpp> 58*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSERFACTORY_HPP_ 59*cdf0e10cSrcweir #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp> 60*cdf0e10cSrcweir #endif 61*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 62*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp> 63*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp> 65*cdf0e10cSrcweir #include <swunohelper.hxx> 66*cdf0e10cSrcweir #include <vcl/waitobj.hxx> 67*cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 68*cdf0e10cSrcweir #include <svl/urihelper.hxx> 69*cdf0e10cSrcweir #include <addresslistdialog.hrc> 70*cdf0e10cSrcweir #include <dbui.hrc> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #include <helpid.h> 73*cdf0e10cSrcweir #include <unomid.h> 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir using namespace ::com::sun::star; 77*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 78*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 79*cdf0e10cSrcweir using namespace ::com::sun::star::container; 80*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 81*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 82*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 83*cdf0e10cSrcweir using namespace ::com::sun::star::task; 84*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 85*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 86*cdf0e10cSrcweir using namespace ::rtl; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir #define ITEMID_NAME 1 89*cdf0e10cSrcweir #define ITEMID_TABLE 2 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //typedef SharedUNOComponent< XConnection > SharedConnection; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir static const char* cUTF8 = "UTF-8"; 94*cdf0e10cSrcweir /*-- 07.05.2004 14:11:34--------------------------------------------------- 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 97*cdf0e10cSrcweir struct AddressUserData_Impl 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir uno::Reference<XDataSource> xSource; 100*cdf0e10cSrcweir SharedConnection xConnection; 101*cdf0e10cSrcweir uno::Reference< XColumnsSupplier> xColumnsSupplier; 102*cdf0e10cSrcweir uno::Reference< sdbc::XResultSet> xResultSet; 103*cdf0e10cSrcweir ::rtl::OUString sFilter; 104*cdf0e10cSrcweir ::rtl::OUString sURL; // data is editable 105*cdf0e10cSrcweir sal_Int32 nCommandType; 106*cdf0e10cSrcweir sal_Int32 nTableAndQueryCount; 107*cdf0e10cSrcweir AddressUserData_Impl() : 108*cdf0e10cSrcweir nCommandType(0), 109*cdf0e10cSrcweir nTableAndQueryCount(-1) 110*cdf0e10cSrcweir {} 111*cdf0e10cSrcweir }; 112*cdf0e10cSrcweir ::rtl::OUString lcl_getFlatURL( uno::Reference<beans::XPropertySet>& xSourceProperties ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir ::rtl::OUString sURL; 115*cdf0e10cSrcweir if(xSourceProperties.is()) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir rtl::OUString sDBURL; 118*cdf0e10cSrcweir xSourceProperties->getPropertyValue(C2U("URL")) >>= sDBURL; 119*cdf0e10cSrcweir if(String(sDBURL).SearchAscii("sdbc:flat:") == 0) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir uno::Sequence<OUString> aFilters; 122*cdf0e10cSrcweir xSourceProperties->getPropertyValue(C2U("TableFilter")) >>= aFilters; 123*cdf0e10cSrcweir uno::Sequence<PropertyValue> aInfo; 124*cdf0e10cSrcweir xSourceProperties->getPropertyValue(C2U("Info")) >>= aInfo; 125*cdf0e10cSrcweir if(aFilters.getLength() == 1 && aInfo.getLength() ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir ::rtl::OUString sFieldDelim; 128*cdf0e10cSrcweir ::rtl::OUString sStringDelim; 129*cdf0e10cSrcweir ::rtl::OUString sExtension; 130*cdf0e10cSrcweir ::rtl::OUString sCharSet; 131*cdf0e10cSrcweir for(sal_Int32 nInfo = 0; nInfo < aInfo.getLength(); ++nInfo) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir if(aInfo[nInfo].Name == C2U("FieldDelimiter")) 134*cdf0e10cSrcweir aInfo[nInfo].Value >>= sFieldDelim; 135*cdf0e10cSrcweir else if(aInfo[nInfo].Name == C2U("StringDelimiter")) 136*cdf0e10cSrcweir aInfo[nInfo].Value >>= sStringDelim; 137*cdf0e10cSrcweir else if(aInfo[nInfo].Name == C2U("Extension")) 138*cdf0e10cSrcweir aInfo[nInfo].Value >>= sExtension; 139*cdf0e10cSrcweir else if(aInfo[nInfo].Name == C2U("CharSet")) 140*cdf0e10cSrcweir aInfo[nInfo].Value >>= sCharSet; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir if(!sCharSet.compareToAscii( cUTF8 )) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir sURL = String(sDBURL).Copy( 10 ); 145*cdf0e10cSrcweir //#i97577# at this point the 'URL' can also be a file name! 146*cdf0e10cSrcweir sURL = URIHelper::SmartRel2Abs( INetURLObject(), sURL ); 147*cdf0e10cSrcweir sURL += C2U("/"); 148*cdf0e10cSrcweir sURL += aFilters[0]; 149*cdf0e10cSrcweir sURL += C2U("."); 150*cdf0e10cSrcweir sURL += sExtension; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir return sURL; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir /*-- 07.04.2004 16:35:43--------------------------------------------------- 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 160*cdf0e10cSrcweir SwAddressListDialog::SwAddressListDialog(SwMailMergeAddressBlockPage* pParent) : 161*cdf0e10cSrcweir SfxModalDialog(pParent, SW_RES(DLG_MM_ADDRESSLISTDIALOG)), 162*cdf0e10cSrcweir #ifdef MSC 163*cdf0e10cSrcweir #pragma warning (disable : 4355) 164*cdf0e10cSrcweir #endif 165*cdf0e10cSrcweir m_aDescriptionFI( this, SW_RES( FI_DESCRIPTION )), 166*cdf0e10cSrcweir m_aListFT( this, SW_RES( FT_LIST )), 167*cdf0e10cSrcweir m_aListHB( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER), 168*cdf0e10cSrcweir m_aListLB( this, SW_RES( LB_LIST )), 169*cdf0e10cSrcweir m_aLoadListPB( this, SW_RES( PB_LOADLIST )), 170*cdf0e10cSrcweir m_aCreateListPB(this, SW_RES( PB_CREATELIST )), 171*cdf0e10cSrcweir m_aFilterPB( this, SW_RES( PB_FILTER )), 172*cdf0e10cSrcweir m_aEditPB(this, SW_RES( PB_EDIT )), 173*cdf0e10cSrcweir m_aTablePB(this, SW_RES( PB_TABLE )), 174*cdf0e10cSrcweir m_aSeparatorFL(this, SW_RES( FL_SEPARATOR )), 175*cdf0e10cSrcweir m_aOK( this, SW_RES( PB_OK )), 176*cdf0e10cSrcweir m_aCancel( this, SW_RES( PB_CANCEL )), 177*cdf0e10cSrcweir m_aHelp( this, SW_RES( PB_HELP )), 178*cdf0e10cSrcweir #ifdef MSC 179*cdf0e10cSrcweir #pragma warning (default : 4355) 180*cdf0e10cSrcweir #endif 181*cdf0e10cSrcweir m_sName( SW_RES( ST_NAME )), 182*cdf0e10cSrcweir m_sTable( SW_RES( ST_TABLE )), 183*cdf0e10cSrcweir m_sConnecting( SW_RES( ST_CONNECTING )), 184*cdf0e10cSrcweir m_pCreatedDataSource(0), 185*cdf0e10cSrcweir m_bInSelectHdl(false), 186*cdf0e10cSrcweir m_pAddressPage(pParent) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir FreeResource(); 189*cdf0e10cSrcweir String sTemp(m_aDescriptionFI.GetText()); 190*cdf0e10cSrcweir sTemp.SearchAndReplaceAscii("%1", m_aLoadListPB.GetText()); 191*cdf0e10cSrcweir sTemp.SearchAndReplaceAscii("%2", m_aCreateListPB.GetText()); 192*cdf0e10cSrcweir m_aDescriptionFI.SetText(sTemp); 193*cdf0e10cSrcweir m_aFilterPB.SetClickHdl( LINK( this, SwAddressListDialog, FilterHdl_Impl )); 194*cdf0e10cSrcweir m_aLoadListPB.SetClickHdl( LINK( this, SwAddressListDialog, LoadHdl_Impl )); 195*cdf0e10cSrcweir m_aCreateListPB.SetClickHdl( LINK( this, SwAddressListDialog,CreateHdl_Impl )); 196*cdf0e10cSrcweir m_aEditPB.SetClickHdl(LINK( this, SwAddressListDialog, EditHdl_Impl)); 197*cdf0e10cSrcweir m_aTablePB.SetClickHdl(LINK( this, SwAddressListDialog, TableSelectHdl_Impl)); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir Size aLBSize(m_aListLB.GetSizePixel()); 200*cdf0e10cSrcweir m_aListHB.SetSizePixel(aLBSize); 201*cdf0e10cSrcweir Size aHeadSize(m_aListHB.CalcWindowSizePixel()); 202*cdf0e10cSrcweir aHeadSize.Width() = aLBSize.Width(); 203*cdf0e10cSrcweir m_aListHB.SetSizePixel(aHeadSize); 204*cdf0e10cSrcweir Point aLBPos(m_aListLB.GetPosPixel()); 205*cdf0e10cSrcweir m_aListHB.SetPosPixel(aLBPos); 206*cdf0e10cSrcweir aLBPos.Y() += aHeadSize.Height(); 207*cdf0e10cSrcweir aLBSize.Height() -= aHeadSize.Height(); 208*cdf0e10cSrcweir m_aListLB.SetPosSizePixel(aLBPos, aLBSize); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir Size aSz(m_aListHB.GetOutputSizePixel()); 211*cdf0e10cSrcweir m_aListHB.InsertItem( ITEMID_NAME, m_sName, 212*cdf0e10cSrcweir aSz.Width()/2, 213*cdf0e10cSrcweir HIB_LEFT | HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS/*| HIB_CLICKABLE | HIB_UPARROW */); 214*cdf0e10cSrcweir m_aListHB.InsertItem( ITEMID_TABLE, m_sTable, 215*cdf0e10cSrcweir aSz.Width()/2, 216*cdf0e10cSrcweir HIB_LEFT | HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS /*| HIB_CLICKABLE | HIB_UPARROW */); 217*cdf0e10cSrcweir m_aListHB.SetHelpId(HID_MM_ADDRESSLIST_HB ); 218*cdf0e10cSrcweir m_aListHB.Show(); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir m_aListLB.SetHelpId(HID_MM_ADDRESSLIST_TLB); 221*cdf0e10cSrcweir static long nTabs[] = {2, 0, aSz.Width()/2 }; 222*cdf0e10cSrcweir m_aListLB.SetStyle( m_aListLB.GetStyle() | WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ); 223*cdf0e10cSrcweir m_aListLB.SetSelectionMode( SINGLE_SELECTION ); 224*cdf0e10cSrcweir m_aListLB.SetTabs(&nTabs[0], MAP_PIXEL); 225*cdf0e10cSrcweir m_aOK.SetClickHdl( LINK( this, SwAddressListDialog, OKHdl_Impl)); 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() ); 228*cdf0e10cSrcweir if( xMgr.is() ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir uno::Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.sdb.DatabaseContext" )); 231*cdf0e10cSrcweir m_xDBContext = uno::Reference<XNameAccess>(xInstance, UNO_QUERY) ; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem = m_pAddressPage->GetWizard()->GetConfigItem(); 234*cdf0e10cSrcweir const SwDBData& rCurrentData = rConfigItem.GetCurrentDBData(); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir DBG_ASSERT(m_xDBContext.is(), "service 'com.sun.star.sdb.DatabaseContext' not found!"); 237*cdf0e10cSrcweir sal_Bool bEnableEdit = sal_False; 238*cdf0e10cSrcweir sal_Bool bEnableOK = sal_True; 239*cdf0e10cSrcweir m_aListLB.SelectAll( sal_False ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir if(m_xDBContext.is()) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir SwDBConfig aDb; 244*cdf0e10cSrcweir ::rtl::OUString sBibliography = aDb.GetBibliographySource().sDataSource; 245*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> aNames = m_xDBContext->getElementNames(); 246*cdf0e10cSrcweir const ::rtl::OUString* pNames = aNames.getConstArray(); 247*cdf0e10cSrcweir for(sal_Int32 nName = 0; nName < aNames.getLength(); ++nName) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir if ( pNames[nName] == sBibliography ) 250*cdf0e10cSrcweir continue; 251*cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aListLB.InsertEntry(pNames[nName]); 252*cdf0e10cSrcweir AddressUserData_Impl* pUserData = new AddressUserData_Impl(); 253*cdf0e10cSrcweir pEntry->SetUserData(pUserData); 254*cdf0e10cSrcweir if(pNames[nName] == rCurrentData.sDataSource) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir m_aListLB.Select(pEntry); 257*cdf0e10cSrcweir m_aListLB.SetEntryText(rCurrentData.sCommand, pEntry, ITEMID_TABLE - 1); 258*cdf0e10cSrcweir pUserData->nCommandType = rCurrentData.nCommandType; 259*cdf0e10cSrcweir pUserData->xSource = rConfigItem.GetSource(); 260*cdf0e10cSrcweir pUserData->xConnection = rConfigItem.GetConnection(); 261*cdf0e10cSrcweir pUserData->xColumnsSupplier = rConfigItem.GetColumnsSupplier(); 262*cdf0e10cSrcweir pUserData->xResultSet = rConfigItem.GetResultSet(); 263*cdf0e10cSrcweir pUserData->sFilter = rConfigItem.GetFilter(); 264*cdf0e10cSrcweir //is the data source editable (csv, Unicode, single table) 265*cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xSourceProperties; 266*cdf0e10cSrcweir try 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir m_xDBContext->getByName(pNames[nName]) >>= xSourceProperties; 269*cdf0e10cSrcweir pUserData->sURL = lcl_getFlatURL( xSourceProperties ); 270*cdf0e10cSrcweir bEnableEdit = pUserData->sURL.getLength() > 0 && 271*cdf0e10cSrcweir SWUnoHelper::UCB_IsFile( pUserData->sURL ) && //#i97577# 272*cdf0e10cSrcweir !SWUnoHelper::UCB_IsReadOnlyFileName( pUserData->sURL ); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir catch(const uno::Exception& ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir bEnableOK = sal_False; 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir m_aDBData = rCurrentData; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir m_aOK.Enable(m_aListLB.GetEntryCount()>0 && bEnableOK); 283*cdf0e10cSrcweir m_aEditPB.Enable(bEnableEdit); 284*cdf0e10cSrcweir m_aListLB.SetSelectHdl(LINK(this, SwAddressListDialog, ListBoxSelectHdl_Impl)); 285*cdf0e10cSrcweir TableSelectHdl_Impl(NULL); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir /*-- 07.04.2004 16:35:43--------------------------------------------------- 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 290*cdf0e10cSrcweir SwAddressListDialog::~SwAddressListDialog() 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aListLB.First(); 293*cdf0e10cSrcweir while(pEntry) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pEntry->GetUserData()); 296*cdf0e10cSrcweir delete pUserData; 297*cdf0e10cSrcweir pEntry = m_aListLB.Next( pEntry ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir /*-- 07.04.2004 16:35:44--------------------------------------------------- 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 303*cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, FilterHdl_Impl, PushButton*, EMPTYARG) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir SvLBoxEntry* pSelect = m_aListLB.FirstSelected(); 306*cdf0e10cSrcweir uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() ); 307*cdf0e10cSrcweir if(pSelect && xMgr.is()) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir String sCommand = m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1); 310*cdf0e10cSrcweir if ( !sCommand.Len() ) 311*cdf0e10cSrcweir return 0; 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); 314*cdf0e10cSrcweir if(pUserData->xConnection.is() ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir try 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir uno::Reference<lang::XMultiServiceFactory> xConnectFactory(pUserData->xConnection, UNO_QUERY_THROW); 319*cdf0e10cSrcweir uno::Reference<XSingleSelectQueryComposer> xComposer( 320*cdf0e10cSrcweir xConnectFactory->createInstance(C2U("com.sun.star.sdb.SingleSelectQueryComposer")), UNO_QUERY_THROW); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir PropertyValue aSecond; 323*cdf0e10cSrcweir aSecond.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RowSet" ) ); 324*cdf0e10cSrcweir uno::Reference<XRowSet> xRowSet( 325*cdf0e10cSrcweir xMgr->createInstance(C2U("com.sun.star.sdb.RowSet")), UNO_QUERY); 326*cdf0e10cSrcweir uno::Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY); 327*cdf0e10cSrcweir xRowProperties->setPropertyValue(C2U("DataSourceName"), 328*cdf0e10cSrcweir makeAny(OUString(m_aListLB.GetEntryText(pSelect, ITEMID_NAME - 1)))); 329*cdf0e10cSrcweir xRowProperties->setPropertyValue(C2U("Command"), makeAny( 330*cdf0e10cSrcweir OUString(sCommand))); 331*cdf0e10cSrcweir xRowProperties->setPropertyValue(C2U("CommandType"), makeAny(pUserData->nCommandType)); 332*cdf0e10cSrcweir xRowProperties->setPropertyValue(C2U("ActiveConnection"), makeAny(pUserData->xConnection.getTyped())); 333*cdf0e10cSrcweir xRowSet->execute(); 334*cdf0e10cSrcweir aSecond.Value <<= xRowSet; 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir PropertyValue aFirst; 337*cdf0e10cSrcweir aFirst.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "QueryComposer" ) ); 338*cdf0e10cSrcweir ::rtl::OUString sQuery; 339*cdf0e10cSrcweir xRowProperties->getPropertyValue(C2U("ActiveCommand"))>>= sQuery; 340*cdf0e10cSrcweir xComposer->setQuery(sQuery); 341*cdf0e10cSrcweir if(pUserData->sFilter.getLength()) 342*cdf0e10cSrcweir xComposer->setFilter(pUserData->sFilter); 343*cdf0e10cSrcweir aFirst.Value <<= xComposer; 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir uno::Sequence<Any> aInit(2); 346*cdf0e10cSrcweir aInit[0] <<= aFirst; 347*cdf0e10cSrcweir aInit[1] <<= aSecond; 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir ::rtl::OUString sDialogServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.FilterDialog" ) ); 350*cdf0e10cSrcweir uno::Reference< XExecutableDialog> xDialog( 351*cdf0e10cSrcweir xMgr->createInstanceWithArguments( sDialogServiceName, aInit ), UNO_QUERY); 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir if ( RET_OK == xDialog->execute() ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir WaitObject aWO( NULL ); 356*cdf0e10cSrcweir pUserData->sFilter = xComposer->getFilter(); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir ::comphelper::disposeComponent(xRowSet); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir catch(Exception& ) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir DBG_ERROR("exception caught in SwAddressListDialog::FilterHdl_Impl"); 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir return 0; 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir /*-- 07.04.2004 16:35:44--------------------------------------------------- 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 371*cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, LoadHdl_Impl, PushButton*, EMPTYARG) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir String sNewSource = SwNewDBMgr::LoadAndRegisterDataSource(); 374*cdf0e10cSrcweir if(sNewSource.Len()) 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir SvLBoxEntry* pNewSource = m_aListLB.InsertEntry(sNewSource); 377*cdf0e10cSrcweir pNewSource->SetUserData(new AddressUserData_Impl()); 378*cdf0e10cSrcweir m_aListLB.Select(pNewSource); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir return 0; 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir /*-- 07.04.2004 16:35:44--------------------------------------------------- 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 385*cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, CreateHdl_Impl, PushButton*, pButton) 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir String sInputURL; 388*cdf0e10cSrcweir SwCreateAddressListDialog* pDlg = 389*cdf0e10cSrcweir new SwCreateAddressListDialog( 390*cdf0e10cSrcweir pButton, 391*cdf0e10cSrcweir sInputURL, 392*cdf0e10cSrcweir m_pAddressPage->GetWizard()->GetConfigItem()); 393*cdf0e10cSrcweir if(RET_OK == pDlg->Execute()) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir //register the URL a new datasource 396*cdf0e10cSrcweir OUString sURL = pDlg->GetURL(); 397*cdf0e10cSrcweir try 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir uno::Reference<XSingleServiceFactory> xFact( m_xDBContext, UNO_QUERY); 400*cdf0e10cSrcweir uno::Reference<XInterface> xNewInstance = xFact->createInstance(); 401*cdf0e10cSrcweir INetURLObject aURL( sURL ); 402*cdf0e10cSrcweir OUString sNewName = aURL.getBase(); 403*cdf0e10cSrcweir //find a unique name if sNewName already exists 404*cdf0e10cSrcweir OUString sFind(sNewName); 405*cdf0e10cSrcweir sal_Int32 nIndex = 0; 406*cdf0e10cSrcweir while(m_xDBContext->hasByName(sFind)) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir sFind = sNewName; 409*cdf0e10cSrcweir sFind += OUString::valueOf(++nIndex); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir uno::Reference<XPropertySet> xDataProperties(xNewInstance, UNO_QUERY); 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir OUString sDBURL(C2U("sdbc:flat:")); 414*cdf0e10cSrcweir //only the 'path' has to be added 415*cdf0e10cSrcweir INetURLObject aTempURL(aURL); 416*cdf0e10cSrcweir aTempURL.removeSegment(); 417*cdf0e10cSrcweir aTempURL.removeFinalSlash(); 418*cdf0e10cSrcweir sDBURL += aTempURL.GetMainURL(INetURLObject::NO_DECODE); 419*cdf0e10cSrcweir Any aAny(&sDBURL, ::getCppuType(&sDBURL)); 420*cdf0e10cSrcweir xDataProperties->setPropertyValue(C2U("URL"), aAny); 421*cdf0e10cSrcweir //set the filter to the file name without extension 422*cdf0e10cSrcweir uno::Sequence<OUString> aFilters(1); 423*cdf0e10cSrcweir aFilters[0] = sNewName; 424*cdf0e10cSrcweir aAny <<= aFilters; 425*cdf0e10cSrcweir xDataProperties->setPropertyValue(C2U("TableFilter"), aAny); 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir uno::Sequence<PropertyValue> aInfo(4); 428*cdf0e10cSrcweir PropertyValue* pInfo = aInfo.getArray(); 429*cdf0e10cSrcweir pInfo[0].Name = C2U("FieldDelimiter"); 430*cdf0e10cSrcweir pInfo[0].Value <<= OUString(String('\t')); 431*cdf0e10cSrcweir pInfo[1].Name = C2U("StringDelimiter"); 432*cdf0e10cSrcweir pInfo[1].Value <<= OUString('"'); 433*cdf0e10cSrcweir pInfo[2].Name = C2U("Extension"); 434*cdf0e10cSrcweir pInfo[2].Value <<= ::rtl::OUString(aURL.getExtension());//C2U("csv"); 435*cdf0e10cSrcweir pInfo[3].Name = C2U("CharSet"); 436*cdf0e10cSrcweir pInfo[3].Value <<= C2U(cUTF8); 437*cdf0e10cSrcweir aAny <<= aInfo; 438*cdf0e10cSrcweir xDataProperties->setPropertyValue(C2U("Info"), aAny); 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW); 441*cdf0e10cSrcweir uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW); 442*cdf0e10cSrcweir String sExt = String::CreateFromAscii(".odb"); 443*cdf0e10cSrcweir String sTmpName; 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir String sHomePath(SvtPathOptions().GetWorkPath()); 446*cdf0e10cSrcweir utl::TempFile aTempFile(sFind , &sExt, &sHomePath); 447*cdf0e10cSrcweir aTempFile.EnableKillingFile(sal_True); 448*cdf0e10cSrcweir sTmpName = aTempFile.GetURL(); 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir xStore->storeAsURL(sTmpName, Sequence< PropertyValue >()); 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir uno::Reference<XNamingService> xNaming(m_xDBContext, UNO_QUERY); 454*cdf0e10cSrcweir xNaming->registerObject( sFind, xNewInstance ); 455*cdf0e10cSrcweir //now insert the new source into the ListBox 456*cdf0e10cSrcweir String sEntry(sFind); 457*cdf0e10cSrcweir sEntry += '\t'; 458*cdf0e10cSrcweir sEntry += String(aFilters[0]); 459*cdf0e10cSrcweir m_pCreatedDataSource = m_aListLB.InsertEntry(sEntry); 460*cdf0e10cSrcweir AddressUserData_Impl* pUserData = new AddressUserData_Impl(); 461*cdf0e10cSrcweir pUserData->sURL = sURL; 462*cdf0e10cSrcweir m_pCreatedDataSource->SetUserData(pUserData); 463*cdf0e10cSrcweir m_aListLB.Select(m_pCreatedDataSource); 464*cdf0e10cSrcweir m_aCreateListPB.Enable(sal_False); 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir catch(Exception& ) 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir delete pDlg; 472*cdf0e10cSrcweir return 0; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir /*-- 22.04.2004 10:30:40--------------------------------------------------- 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 477*cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, EditHdl_Impl, PushButton*, pButton) 478*cdf0e10cSrcweir { 479*cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aListLB.FirstSelected(); 480*cdf0e10cSrcweir AddressUserData_Impl* pUserData = pEntry ? static_cast<AddressUserData_Impl*>(pEntry->GetUserData()) : 0; 481*cdf0e10cSrcweir if(pUserData && pUserData->sURL.getLength()) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir if(pUserData->xResultSet.is()) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem = m_pAddressPage->GetWizard()->GetConfigItem(); 486*cdf0e10cSrcweir if(rConfigItem.GetResultSet() != pUserData->xResultSet) 487*cdf0e10cSrcweir ::comphelper::disposeComponent( pUserData->xResultSet ); 488*cdf0e10cSrcweir pUserData->xResultSet = 0; 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir rConfigItem.DisposeResultSet(); 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir pUserData->xSource.clear(); 493*cdf0e10cSrcweir pUserData->xColumnsSupplier.clear(); 494*cdf0e10cSrcweir pUserData->xConnection.clear(); 495*cdf0e10cSrcweir // will automatically close if it was the las reference 496*cdf0e10cSrcweir SwCreateAddressListDialog* pDlg = 497*cdf0e10cSrcweir new SwCreateAddressListDialog( 498*cdf0e10cSrcweir pButton, 499*cdf0e10cSrcweir pUserData->sURL, 500*cdf0e10cSrcweir m_pAddressPage->GetWizard()->GetConfigItem()); 501*cdf0e10cSrcweir if(RET_OK == pDlg->Execute()) 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir delete pDlg; 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir return 0; 507*cdf0e10cSrcweir }; 508*cdf0e10cSrcweir /*-- 19.04.2004 09:41:05--------------------------------------------------- 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 511*cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, ListBoxSelectHdl_Impl, SvTabListBox*, EMPTYARG) 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir SvLBoxEntry* pSelect = m_aListLB.FirstSelected(); 514*cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK( this, SwAddressListDialog, 515*cdf0e10cSrcweir StaticListBoxSelectHdl_Impl ), pSelect ); 516*cdf0e10cSrcweir return 0; 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir IMPL_STATIC_LINK(SwAddressListDialog, StaticListBoxSelectHdl_Impl, SvLBoxEntry*, pSelect) 519*cdf0e10cSrcweir { 520*cdf0e10cSrcweir //prevent nested calls of the select handler 521*cdf0e10cSrcweir if(pThis->m_bInSelectHdl) 522*cdf0e10cSrcweir return 0; 523*cdf0e10cSrcweir pThis->EnterWait(); 524*cdf0e10cSrcweir pThis->m_bInSelectHdl = true; 525*cdf0e10cSrcweir AddressUserData_Impl* pUserData = 0; 526*cdf0e10cSrcweir if(pSelect) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir String sTable = pThis->m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1); 529*cdf0e10cSrcweir if(!sTable.Len()) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir pThis->m_aListLB.SetEntryText(pThis->m_sConnecting, pSelect, ITEMID_TABLE - 1); 532*cdf0e10cSrcweir // allow painting of the new entry 533*cdf0e10cSrcweir pThis->m_aListLB.Window::Invalidate(INVALIDATE_UPDATE); 534*cdf0e10cSrcweir for (sal_uInt16 i = 0; i < 10; i++) 535*cdf0e10cSrcweir Application::Reschedule(); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); 539*cdf0e10cSrcweir if(pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir pThis->DetectTablesAndQueries(pSelect, !sTable.Len()); 542*cdf0e10cSrcweir } 543*cdf0e10cSrcweir else 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir //otherwise set the selected db-data 546*cdf0e10cSrcweir pThis->m_aDBData.sDataSource = pThis->m_aListLB.GetEntryText(pSelect, ITEMID_NAME - 1); 547*cdf0e10cSrcweir pThis->m_aDBData.sCommand = pThis->m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1); 548*cdf0e10cSrcweir pThis->m_aDBData.nCommandType = pUserData->nCommandType; 549*cdf0e10cSrcweir pThis->m_aOK.Enable(sal_True); 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir sTable = pThis->m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1); 552*cdf0e10cSrcweir if(sTable == pThis->m_sConnecting) 553*cdf0e10cSrcweir pThis->m_aListLB.SetEntryText(String(), pSelect, ITEMID_TABLE - 1); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir pThis->m_aEditPB.Enable(pUserData && pUserData->sURL.getLength() && 556*cdf0e10cSrcweir SWUnoHelper::UCB_IsFile( pUserData->sURL ) && //#i97577# 557*cdf0e10cSrcweir !SWUnoHelper::UCB_IsReadOnlyFileName( pUserData->sURL ) ); 558*cdf0e10cSrcweir pThis->m_bInSelectHdl = false; 559*cdf0e10cSrcweir pThis->LeaveWait(); 560*cdf0e10cSrcweir return 0; 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir /*-- 13.05.2004 14:59:25--------------------------------------------------- 564*cdf0e10cSrcweir detect the number of tables for a data source 565*cdf0e10cSrcweir if only one is available then set it at the entry 566*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 567*cdf0e10cSrcweir void SwAddressListDialog::DetectTablesAndQueries( 568*cdf0e10cSrcweir SvLBoxEntry* pSelect, 569*cdf0e10cSrcweir bool bWidthDialog) 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir try 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); 574*cdf0e10cSrcweir uno::Reference<XCompletedConnection> xComplConnection; 575*cdf0e10cSrcweir if(!pUserData->xConnection.is()) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir m_aDBData.sDataSource = m_aListLB.GetEntryText(pSelect, ITEMID_NAME - 1); 578*cdf0e10cSrcweir m_xDBContext->getByName(m_aDBData.sDataSource) >>= xComplConnection; 579*cdf0e10cSrcweir pUserData->xSource = uno::Reference<XDataSource>(xComplConnection, UNO_QUERY); 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() ); 582*cdf0e10cSrcweir uno::Reference< XInteractionHandler > xHandler( 583*cdf0e10cSrcweir xMgr->createInstance( C2U( "com.sun.star.task.InteractionHandler" )), UNO_QUERY); 584*cdf0e10cSrcweir pUserData->xConnection = SharedConnection( xComplConnection->connectWithCompletion( xHandler ) ); 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir if(pUserData->xConnection.is()) 587*cdf0e10cSrcweir { 588*cdf0e10cSrcweir sal_Int32 nTables = 0; 589*cdf0e10cSrcweir uno::Sequence<rtl::OUString> aTables; 590*cdf0e10cSrcweir uno::Sequence<rtl::OUString> aQueries; 591*cdf0e10cSrcweir uno::Reference<XTablesSupplier> xTSupplier(pUserData->xConnection, UNO_QUERY); 592*cdf0e10cSrcweir if(xTSupplier.is()) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir uno::Reference<XNameAccess> xTbls = xTSupplier->getTables(); 595*cdf0e10cSrcweir aTables = xTbls->getElementNames(); 596*cdf0e10cSrcweir nTables += aTables.getLength(); 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir uno::Reference<XQueriesSupplier> xQSupplier(pUserData->xConnection, UNO_QUERY); 599*cdf0e10cSrcweir if(xQSupplier.is()) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir uno::Reference<XNameAccess> xQueries = xQSupplier->getQueries(); 602*cdf0e10cSrcweir aQueries = xQueries->getElementNames(); 603*cdf0e10cSrcweir nTables += aQueries.getLength(); 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir pUserData->nTableAndQueryCount = nTables; 606*cdf0e10cSrcweir if(nTables > 1 && bWidthDialog) 607*cdf0e10cSrcweir { 608*cdf0e10cSrcweir //now call the table select dialog - if more than one table exists 609*cdf0e10cSrcweir SwSelectDBTableDialog* pDlg = new SwSelectDBTableDialog(this, pUserData->xConnection); 610*cdf0e10cSrcweir String sTable = m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1); 611*cdf0e10cSrcweir if(sTable.Len()) 612*cdf0e10cSrcweir pDlg->SetSelectedTable(sTable, pUserData->nCommandType == CommandType::TABLE); 613*cdf0e10cSrcweir if(RET_OK == pDlg->Execute()) 614*cdf0e10cSrcweir { 615*cdf0e10cSrcweir bool bIsTable; 616*cdf0e10cSrcweir m_aDBData.sCommand = pDlg->GetSelectedTable(bIsTable); 617*cdf0e10cSrcweir m_aDBData.nCommandType = bIsTable ? CommandType::TABLE : CommandType::QUERY; 618*cdf0e10cSrcweir pUserData->nCommandType = m_aDBData.nCommandType; 619*cdf0e10cSrcweir } 620*cdf0e10cSrcweir delete pDlg; 621*cdf0e10cSrcweir } 622*cdf0e10cSrcweir else if(nTables == 1) 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir if(aTables.getLength()) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir m_aDBData.sCommand = aTables[0]; 627*cdf0e10cSrcweir m_aDBData.nCommandType = CommandType::TABLE; 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir else 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir m_aDBData.sCommand = aQueries[0]; 632*cdf0e10cSrcweir m_aDBData.nCommandType = CommandType::QUERY; 633*cdf0e10cSrcweir } 634*cdf0e10cSrcweir } 635*cdf0e10cSrcweir } 636*cdf0e10cSrcweir if ( m_aDBData.sCommand.getLength() ) 637*cdf0e10cSrcweir { 638*cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xSourceProperties; 639*cdf0e10cSrcweir m_xDBContext->getByName(m_aDBData.sDataSource) >>= xSourceProperties; 640*cdf0e10cSrcweir pUserData->sURL = lcl_getFlatURL( xSourceProperties ); 641*cdf0e10cSrcweir 642*cdf0e10cSrcweir pUserData->xColumnsSupplier = SwNewDBMgr::GetColumnSupplier(pUserData->xConnection, 643*cdf0e10cSrcweir m_aDBData.sCommand, 644*cdf0e10cSrcweir m_aDBData.nCommandType == CommandType::TABLE ? 645*cdf0e10cSrcweir SW_DB_SELECT_TABLE : SW_DB_SELECT_QUERY ); 646*cdf0e10cSrcweir //#i97577# 647*cdf0e10cSrcweir if( pUserData->xColumnsSupplier.is() ) 648*cdf0e10cSrcweir m_aListLB.SetEntryText(m_aDBData.sCommand, pSelect, ITEMID_TABLE - 1); 649*cdf0e10cSrcweir else 650*cdf0e10cSrcweir m_aListLB.SetEntryText(String(), pSelect, ITEMID_TABLE - 1); 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir String sCommand = m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1); 653*cdf0e10cSrcweir m_aOK.Enable(pSelect && sCommand.Len()); 654*cdf0e10cSrcweir m_aFilterPB.Enable( pUserData->xConnection.is() && sCommand.Len() ); 655*cdf0e10cSrcweir m_aTablePB.Enable( pUserData->nTableAndQueryCount > 1 ); 656*cdf0e10cSrcweir } 657*cdf0e10cSrcweir catch(Exception& ) 658*cdf0e10cSrcweir { 659*cdf0e10cSrcweir DBG_ERROR("exception caught in SwAddressListDialog::DetectTablesAndQueries"); 660*cdf0e10cSrcweir m_aOK.Enable( sal_False ); 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir /*-- 13.05.2004 12:55:40--------------------------------------------------- 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 667*cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, TableSelectHdl_Impl, PushButton*, pButton) 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir EnterWait(); 670*cdf0e10cSrcweir SvLBoxEntry* pSelect = m_aListLB.FirstSelected(); 671*cdf0e10cSrcweir if(pSelect) 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); 674*cdf0e10cSrcweir //only call the table select dialog if tables have not been searched for or there 675*cdf0e10cSrcweir //are more than 1 676*cdf0e10cSrcweir String sTable = m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1); 677*cdf0e10cSrcweir if( pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1) 678*cdf0e10cSrcweir { 679*cdf0e10cSrcweir DetectTablesAndQueries(pSelect, (pButton != 0) || (!sTable.Len())); 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir LeaveWait(); 684*cdf0e10cSrcweir return 0; 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir /*-- 08.04.2004 14:52:11--------------------------------------------------- 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 690*cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, OKHdl_Impl, PushButton*, EMPTYARG) 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir EndDialog(sal_True); 693*cdf0e10cSrcweir return 0; 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir /*-- 07.05.2004 14:17:47--------------------------------------------------- 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 699*cdf0e10cSrcweir uno::Reference< XDataSource> SwAddressListDialog::GetSource() 700*cdf0e10cSrcweir { 701*cdf0e10cSrcweir uno::Reference< XDataSource> xRet; 702*cdf0e10cSrcweir SvLBoxEntry* pSelect = m_aListLB.FirstSelected(); 703*cdf0e10cSrcweir if(pSelect) 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); 706*cdf0e10cSrcweir xRet = pUserData->xSource; 707*cdf0e10cSrcweir } 708*cdf0e10cSrcweir return xRet; 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir /*-- 07.05.2004 14:17:48--------------------------------------------------- 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 714*cdf0e10cSrcweir SharedConnection SwAddressListDialog::GetConnection() 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir SharedConnection xRet; 717*cdf0e10cSrcweir SvLBoxEntry* pSelect = m_aListLB.FirstSelected(); 718*cdf0e10cSrcweir if(pSelect) 719*cdf0e10cSrcweir { 720*cdf0e10cSrcweir AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); 721*cdf0e10cSrcweir xRet = pUserData->xConnection; 722*cdf0e10cSrcweir } 723*cdf0e10cSrcweir return xRet; 724*cdf0e10cSrcweir } 725*cdf0e10cSrcweir /*-- 07.05.2004 14:17:48--------------------------------------------------- 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 728*cdf0e10cSrcweir uno::Reference< XColumnsSupplier> SwAddressListDialog::GetColumnsSupplier() 729*cdf0e10cSrcweir { 730*cdf0e10cSrcweir uno::Reference< XColumnsSupplier> xRet; 731*cdf0e10cSrcweir SvLBoxEntry* pSelect = m_aListLB.FirstSelected(); 732*cdf0e10cSrcweir if(pSelect) 733*cdf0e10cSrcweir { 734*cdf0e10cSrcweir AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); 735*cdf0e10cSrcweir xRet = pUserData->xColumnsSupplier; 736*cdf0e10cSrcweir } 737*cdf0e10cSrcweir return xRet; 738*cdf0e10cSrcweir } 739*cdf0e10cSrcweir /*-- 14.05.2004 15:04:09--------------------------------------------------- 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 742*cdf0e10cSrcweir ::rtl::OUString SwAddressListDialog::GetFilter() 743*cdf0e10cSrcweir { 744*cdf0e10cSrcweir ::rtl::OUString sRet; 745*cdf0e10cSrcweir SvLBoxEntry* pSelect = m_aListLB.FirstSelected(); 746*cdf0e10cSrcweir if(pSelect) 747*cdf0e10cSrcweir { 748*cdf0e10cSrcweir AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); 749*cdf0e10cSrcweir sRet = pUserData->sFilter; 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir return sRet; 752*cdf0e10cSrcweir } 753