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_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifndef _DBAUI_DSSELECT_HXX_ 32*cdf0e10cSrcweir #include "dsselect.hxx" 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #ifndef _DBAUI_DSSELECT_HRC_ 35*cdf0e10cSrcweir #include "dsselect.hrc" 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_ 38*cdf0e10cSrcweir #include "dbu_dlg.hrc" 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX 41*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #ifndef _DBAUI_LOCALRESACCESS_HXX_ 44*cdf0e10cSrcweir #include "localresaccess.hxx" 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir #ifndef _TOOLS_RCID_H 47*cdf0e10cSrcweir #include <tools/rcid.h> 48*cdf0e10cSrcweir #endif 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XCREATECATALOG_HPP_ 51*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XCreateCatalog.hpp> 52*cdf0e10cSrcweir #endif 53*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ 54*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 55*cdf0e10cSrcweir #endif 56*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_ 57*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp> 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_ 60*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 61*cdf0e10cSrcweir #endif 62*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_ 63*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 64*cdf0e10cSrcweir #endif 65*cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 66*cdf0e10cSrcweir #include "dbustrings.hrc" 67*cdf0e10cSrcweir #endif 68*cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 69*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 70*cdf0e10cSrcweir #endif 71*cdf0e10cSrcweir #ifndef _COMPHELPER_EXTRACT_HXX_ 72*cdf0e10cSrcweir #include <comphelper/extract.hxx> 73*cdf0e10cSrcweir #endif 74*cdf0e10cSrcweir #ifndef _COMPHELPER_TYPES_HXX_ 75*cdf0e10cSrcweir #include <comphelper/types.hxx> 76*cdf0e10cSrcweir #endif 77*cdf0e10cSrcweir #ifndef _COMPHELPER_PROCESSFACTORY_HXX_ 78*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 79*cdf0e10cSrcweir #endif 80*cdf0e10cSrcweir #ifndef _DBAUI_DATASOURCEITEMS_HXX_ 81*cdf0e10cSrcweir #include "dsitems.hxx" 82*cdf0e10cSrcweir #endif 83*cdf0e10cSrcweir #ifndef _SFXSTRITEM_HXX 84*cdf0e10cSrcweir #include <svl/stritem.hxx> 85*cdf0e10cSrcweir #endif 86*cdf0e10cSrcweir #ifndef _SFXINTITEM_HXX 87*cdf0e10cSrcweir #include <svl/intitem.hxx> 88*cdf0e10cSrcweir #endif 89*cdf0e10cSrcweir #ifndef _SFXENUMITEM_HXX 90*cdf0e10cSrcweir #include <svl/eitem.hxx> 91*cdf0e10cSrcweir #endif 92*cdf0e10cSrcweir #ifndef _SFXITEMSET_HXX 93*cdf0e10cSrcweir #include <svl/itemset.hxx> 94*cdf0e10cSrcweir #endif 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir //......................................................................... 97*cdf0e10cSrcweir namespace dbaui 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir //......................................................................... 100*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 101*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 102*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 103*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 104*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 105*cdf0e10cSrcweir using namespace ::comphelper; 106*cdf0e10cSrcweir //================================================================== 107*cdf0e10cSrcweir ODatasourceSelectDialog::ODatasourceSelectDialog(Window* _pParent, const StringBag& _rDatasources, bool _bAdabas,SfxItemSet* _pOutputSet) 108*cdf0e10cSrcweir :ModalDialog(_pParent, ModuleRes(DLG_DATASOURCE_SELECTION)) 109*cdf0e10cSrcweir ,m_aDescription (this, ModuleRes(FT_DESCRIPTION)) 110*cdf0e10cSrcweir ,m_aDatasource (this, ModuleRes(LB_DATASOURCE)) 111*cdf0e10cSrcweir ,m_aOk (this, ModuleRes(PB_OK)) 112*cdf0e10cSrcweir ,m_aCancel (this, ModuleRes(PB_CANCEL)) 113*cdf0e10cSrcweir ,m_aHelp (this, ModuleRes(PB_HELP)) 114*cdf0e10cSrcweir #ifdef HAVE_ODBC_ADMINISTRATION 115*cdf0e10cSrcweir ,m_aManageDatasources (this, ModuleRes(PB_MANAGE)) 116*cdf0e10cSrcweir #endif 117*cdf0e10cSrcweir ,m_aCreateAdabasDB (this, ModuleRes(PB_CREATE)) 118*cdf0e10cSrcweir ,m_pOutputSet(_pOutputSet) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir if ( _bAdabas ) 121*cdf0e10cSrcweir { // set a new title (indicating that we're browsing local data sources only) 122*cdf0e10cSrcweir SetText(ModuleRes(STR_LOCAL_DATASOURCES)); 123*cdf0e10cSrcweir m_aDescription.SetText(ModuleRes(STR_DESCRIPTION2)); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir m_aCreateAdabasDB.Show(); 126*cdf0e10cSrcweir m_aCreateAdabasDB.SetClickHdl(LINK(this,ODatasourceSelectDialog,CreateDBClickHdl)); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // resize the dialog a little bit, 'cause Adabas data source names are usually somewhat shorter 129*cdf0e10cSrcweir // than ODBC ones are 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // shrink the listbox 132*cdf0e10cSrcweir Size aOldSize = m_aDatasource.GetSizePixel(); 133*cdf0e10cSrcweir Size aNewSize(3 * aOldSize.Width() / 4, aOldSize.Height()); 134*cdf0e10cSrcweir m_aDatasource.SetSizePixel(aNewSize); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir sal_Int32 nLostPixels = aOldSize.Width() - aNewSize.Width(); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // shrink the fixed text 139*cdf0e10cSrcweir aOldSize = m_aDescription.GetSizePixel(); 140*cdf0e10cSrcweir m_aDescription.SetSizePixel(Size(aOldSize.Width() - nLostPixels, aOldSize.Height())); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // move the buttons 143*cdf0e10cSrcweir PushButton* pButtons[] = { &m_aOk, &m_aCancel, &m_aHelp ,&m_aCreateAdabasDB}; 144*cdf0e10cSrcweir for (size_t i=0; i<sizeof(pButtons)/sizeof(pButtons[0]); ++i) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir Point aOldPos = pButtons[i]->GetPosPixel(); 147*cdf0e10cSrcweir pButtons[i]->SetPosPixel(Point(aOldPos.X() - nLostPixels, aOldPos.Y())); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir // resize the dialog itself 151*cdf0e10cSrcweir aOldSize = GetSizePixel(); 152*cdf0e10cSrcweir SetSizePixel(Size(aOldSize.Width() - nLostPixels, aOldSize.Height())); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir fillListBox(_rDatasources); 156*cdf0e10cSrcweir #ifdef HAVE_ODBC_ADMINISTRATION 157*cdf0e10cSrcweir // allow ODBC datasource managenment 158*cdf0e10cSrcweir if ( !_bAdabas ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir m_aManageDatasources.Show(); 161*cdf0e10cSrcweir m_aManageDatasources.Enable(); 162*cdf0e10cSrcweir m_aManageDatasources.SetClickHdl(LINK(this,ODatasourceSelectDialog,ManageClickHdl)); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir #endif 165*cdf0e10cSrcweir m_aDatasource.SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog,ListDblClickHdl)); 166*cdf0e10cSrcweir FreeResource(); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir // ----------------------------------------------------------------------- 170*cdf0e10cSrcweir ODatasourceSelectDialog::~ODatasourceSelectDialog() 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir // ----------------------------------------------------------------------- 175*cdf0e10cSrcweir IMPL_LINK( ODatasourceSelectDialog, ListDblClickHdl, ListBox *, pListBox ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir if (pListBox->GetSelectEntryCount()) 178*cdf0e10cSrcweir EndDialog(RET_OK); 179*cdf0e10cSrcweir return 0; 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir // ----------------------------------------------------------------------- 182*cdf0e10cSrcweir IMPL_LINK( ODatasourceSelectDialog, CreateDBClickHdl, PushButton*, /*pButton*/ ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir try 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir OSL_ENSURE(m_pOutputSet,"No itemset given!"); 187*cdf0e10cSrcweir Reference< ::com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory(); 188*cdf0e10cSrcweir Reference<XCreateCatalog> xCatalog(xORB->createInstance(SERVICE_EXTENDED_ADABAS_DRIVER),UNO_QUERY); 189*cdf0e10cSrcweir if ( xCatalog.is() && m_pOutputSet ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir Sequence< Any > aArgs(2); 192*cdf0e10cSrcweir aArgs[0] <<= PropertyValue(::rtl::OUString::createFromAscii("CreateCatalog"), 0,makeAny(xCatalog) , PropertyState_DIRECT_VALUE); 193*cdf0e10cSrcweir aArgs[1] <<= PropertyValue(PROPERTY_PARENTWINDOW, 0, makeAny(VCLUnoHelper::GetInterface(this)), PropertyState_DIRECT_VALUE); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir Reference< XExecutableDialog > xDialog( 196*cdf0e10cSrcweir xORB->createInstanceWithArguments(SERVICE_SDB_ADABASCREATIONDIALOG, aArgs), UNO_QUERY); 197*cdf0e10cSrcweir if (!xDialog.is()) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir // ShowServiceNotAvailableError(this, String(SERVICE_SDB_ADABASCREATIONDIALOG), sal_True); 200*cdf0e10cSrcweir return 0L; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if ( xDialog->execute() == RET_OK ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir Reference<XPropertySet> xProp(xDialog,UNO_QUERY); 206*cdf0e10cSrcweir if(xProp.is()) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir Reference<XPropertySetInfo> xPropInfo(xProp->getPropertySetInfo()); 209*cdf0e10cSrcweir if(xPropInfo->hasPropertyByName(PROPERTY_DATABASENAME)) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir String sDatabaseName; 212*cdf0e10cSrcweir sDatabaseName = String(::comphelper::getString(xProp->getPropertyValue(PROPERTY_DATABASENAME))); 213*cdf0e10cSrcweir m_aDatasource.SelectEntryPos(m_aDatasource.InsertEntry( sDatabaseName )); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir if ( xPropInfo->hasPropertyByName(PROPERTY_CONTROLUSER) ) 217*cdf0e10cSrcweir m_pOutputSet->Put(SfxStringItem(DSID_CONN_CTRLUSER, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_CONTROLUSER)))); 218*cdf0e10cSrcweir if ( xPropInfo->hasPropertyByName(PROPERTY_CONTROLPASSWORD) ) 219*cdf0e10cSrcweir m_pOutputSet->Put(SfxStringItem(DSID_CONN_CTRLPWD, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_CONTROLPASSWORD)))); 220*cdf0e10cSrcweir if ( xPropInfo->hasPropertyByName(PROPERTY_USER) ) 221*cdf0e10cSrcweir m_pOutputSet->Put(SfxStringItem(DSID_USER, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_USER)))); 222*cdf0e10cSrcweir if ( xPropInfo->hasPropertyByName(PROPERTY_PASSWORD) ) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir m_pOutputSet->Put(SfxStringItem(DSID_PASSWORD, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_PASSWORD)))); 225*cdf0e10cSrcweir m_pOutputSet->Put(SfxBoolItem(DSID_PASSWORDREQUIRED, sal_True)); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir if ( xPropInfo->hasPropertyByName(PROPERTY_CACHESIZE) ) 228*cdf0e10cSrcweir m_pOutputSet->Put(SfxInt32Item(DSID_CONN_CACHESIZE, ::comphelper::getINT32(xProp->getPropertyValue(PROPERTY_CACHESIZE)))); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir catch(Exception&) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir return 0L; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir // ----------------------------------------------------------------------- 240*cdf0e10cSrcweir sal_Bool ODatasourceSelectDialog::Close() 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir #ifdef HAVE_ODBC_ADMINISTRATION 243*cdf0e10cSrcweir if ( m_pODBCManagement.get() && m_pODBCManagement->isRunning() ) 244*cdf0e10cSrcweir return sal_False; 245*cdf0e10cSrcweir #endif 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir return ModalDialog::Close(); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir // ----------------------------------------------------------------------- 251*cdf0e10cSrcweir #ifdef HAVE_ODBC_ADMINISTRATION 252*cdf0e10cSrcweir IMPL_LINK( ODatasourceSelectDialog, ManageClickHdl, PushButton*, EMPTYARG ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir if ( !m_pODBCManagement.get() ) 255*cdf0e10cSrcweir m_pODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) ); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir if ( !m_pODBCManagement->manageDataSources_async() ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir // TODO: error message 260*cdf0e10cSrcweir m_aDatasource.GrabFocus(); 261*cdf0e10cSrcweir m_aManageDatasources.Disable(); 262*cdf0e10cSrcweir return 1L; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir m_aDatasource.Disable(); 266*cdf0e10cSrcweir m_aOk.Disable(); 267*cdf0e10cSrcweir m_aCancel.Disable(); 268*cdf0e10cSrcweir m_aManageDatasources.Disable(); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir OSL_POSTCOND( m_pODBCManagement->isRunning(), "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" ); 271*cdf0e10cSrcweir return 0L; 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir IMPL_LINK( ODatasourceSelectDialog, ManageProcessFinished, void*, /**/ ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir StringBag aOdbcDatasources; 277*cdf0e10cSrcweir OOdbcEnumeration aEnumeration; 278*cdf0e10cSrcweir aEnumeration.getDatasourceNames( aOdbcDatasources ); 279*cdf0e10cSrcweir fillListBox( aOdbcDatasources ); 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir m_aDatasource.Enable(); 282*cdf0e10cSrcweir m_aOk.Enable(); 283*cdf0e10cSrcweir m_aCancel.Enable(); 284*cdf0e10cSrcweir m_aManageDatasources.Enable(); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir return 0L; 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir #endif 290*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 291*cdf0e10cSrcweir void ODatasourceSelectDialog::fillListBox(const StringBag& _rDatasources) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir ::rtl::OUString sSelected; 294*cdf0e10cSrcweir if (m_aDatasource.GetEntryCount()) 295*cdf0e10cSrcweir sSelected = m_aDatasource.GetSelectEntry(); 296*cdf0e10cSrcweir m_aDatasource.Clear(); 297*cdf0e10cSrcweir // fill the list 298*cdf0e10cSrcweir for ( ConstStringBagIterator aDS = _rDatasources.begin(); 299*cdf0e10cSrcweir aDS != _rDatasources.end(); 300*cdf0e10cSrcweir ++aDS 301*cdf0e10cSrcweir ) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir m_aDatasource.InsertEntry( *aDS ); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir if (m_aDatasource.GetEntryCount()) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir if (sSelected.getLength()) 309*cdf0e10cSrcweir m_aDatasource.SelectEntry(sSelected); 310*cdf0e10cSrcweir else // select the first entry 311*cdf0e10cSrcweir m_aDatasource.SelectEntryPos(0); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir //......................................................................... 316*cdf0e10cSrcweir } // namespace dbaui 317*cdf0e10cSrcweir //......................................................................... 318*cdf0e10cSrcweir 319