1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_dbaccess.hxx" 30 31 #ifndef DBAUI_DBWIZ_HXX 32 #include "dbwiz.hxx" 33 #endif 34 #ifndef _DBAUI_DBADMIN_HRC_ 35 #include "dbadmin.hrc" 36 #endif 37 #ifndef _DBU_DLG_HRC_ 38 #include "dbu_dlg.hrc" 39 #endif 40 #ifndef _DBAUI_DATASOURCEITEMS_HXX_ 41 #include "dsitems.hxx" 42 #endif 43 #include "dsnItem.hxx" 44 #ifndef _SFXSTRITEM_HXX 45 #include <svl/stritem.hxx> 46 #endif 47 #ifndef _SFXENUMITEM_HXX 48 #include <svl/eitem.hxx> 49 #endif 50 #ifndef _SFXINTITEM_HXX 51 #include <svl/intitem.hxx> 52 #endif 53 #ifndef _SV_MSGBOX_HXX 54 #include <vcl/msgbox.hxx> 55 #endif 56 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 57 #include "dbustrings.hrc" 58 #endif 59 #ifndef _DBAUI_ADMINPAGES_HXX_ 60 #include "adminpages.hxx" 61 #endif 62 #ifndef _DBAUI_GENERALPAGE_HXX_ 63 #include "generalpage.hxx" 64 #endif 65 #ifndef _DBAUI_LOCALRESACCESS_HXX_ 66 #include "localresaccess.hxx" 67 #endif 68 #ifndef _DBAUI_STRINGLISTITEM_HXX_ 69 #include "stringlistitem.hxx" 70 #endif 71 #ifndef _DBAUI_PROPERTYSETITEM_HXX_ 72 #include "propertysetitem.hxx" 73 #endif 74 #ifndef _UNOTOOLS_CONFIGNODE_HXX_ 75 #include <unotools/confignode.hxx> 76 #endif 77 #ifndef DBAUI_CONNECTIONPAGE_HXX 78 #include "ConnectionPage.hxx" 79 #endif 80 #ifndef DBAUI_DRIVERSETTINGS_HXX 81 #include "DriverSettings.hxx" 82 #endif 83 #ifndef _DBAUI_DBADMINIMPL_HXX_ 84 #include "DbAdminImpl.hxx" 85 #endif 86 #ifndef _DBA_DBACCESS_HELPID_HRC_ 87 #include "dbaccess_helpid.hrc" 88 #endif 89 90 //......................................................................... 91 namespace dbaui 92 { 93 //......................................................................... 94 using namespace svt; 95 using namespace com::sun::star::uno; 96 using namespace com::sun::star::sdbc; 97 using namespace com::sun::star::lang; 98 using namespace com::sun::star::util; 99 using namespace com::sun::star::beans; 100 using namespace com::sun::star::container; 101 102 #define START_PAGE 0 103 #define CONNECTION_PAGE 1 104 #define ADDITIONAL_PAGE_DBASE 2 105 #define ADDITIONAL_PAGE_FLAT 3 106 #define ADDITIONAL_PAGE_LDAP 4 107 #define ADDITIONAL_PAGE_ADABAS 5 108 #define ADDITIONAL_PAGE_MYSQL_JDBC 6 109 #define ADDITIONAL_PAGE_MYSQL_ODBC 7 110 #define ADDITIONAL_PAGE_ORACLE_JDBC 8 111 #define ADDITIONAL_PAGE_ADO 9 112 #define ADDITIONAL_PAGE_ODBC 10 113 #define ADDITIONAL_USERDEFINED 11 114 #define ADDITIONAL_PAGE_MYSQL_NATIVE 12 115 116 117 DBG_NAME(ODbTypeWizDialog) 118 //========================================================================= 119 //= ODbTypeWizDialog 120 //========================================================================= 121 //------------------------------------------------------------------------- 122 ODbTypeWizDialog::ODbTypeWizDialog(Window* _pParent 123 ,SfxItemSet* _pItems 124 ,const Reference< XMultiServiceFactory >& _rxORB 125 ,const ::com::sun::star::uno::Any& _aDataSourceName 126 ) 127 :OWizardMachine(_pParent, ModuleRes(DLG_DATABASE_TYPE_CHANGE), WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP ) 128 ,m_pOutSet(NULL) 129 ,m_bResetting(sal_False) 130 ,m_bApplied(sal_False) 131 ,m_bUIEnabled( sal_True ) 132 { 133 DBG_CTOR(ODbTypeWizDialog,NULL); 134 m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,this,this)); 135 m_pImpl->setDataSourceOrName(_aDataSourceName); 136 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource(); 137 m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() ); 138 139 m_pImpl->translateProperties(xDatasource, *m_pOutSet); 140 m_eType = m_pImpl->getDatasourceType(*m_pOutSet); 141 142 SetPageSizePixel(LogicToPixel(::Size(PAGE_X, PAGE_Y), MAP_APPFONT)); 143 ShowButtonFixedLine(sal_True); 144 defaultButton(WZB_NEXT); 145 enableButtons(WZB_FINISH, sal_False); 146 enableAutomaticNextButtonState( true ); 147 148 m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS); 149 m_pNextPage->SetHelpId(HID_DBWIZ_NEXT); 150 m_pCancel->SetHelpId(HID_DBWIZ_CANCEL); 151 m_pFinish->SetHelpId(HID_DBWIZ_FINISH); 152 m_pHelp->SetUniqueId(UID_DBWIZ_HELP); 153 // no local resources needed anymore 154 155 DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION)); 156 m_pCollection = pCollectionItem->getCollection(); 157 158 FreeResource(); 159 ActivatePage(); 160 } 161 162 //------------------------------------------------------------------------- 163 ODbTypeWizDialog::~ODbTypeWizDialog() 164 { 165 DBG_DTOR(ODbTypeWizDialog,NULL); 166 delete m_pOutSet; 167 } 168 //------------------------------------------------------------------------- 169 IMPL_LINK(ODbTypeWizDialog, OnTypeSelected, OGeneralPage*, _pTabPage) 170 { 171 m_eType = _pTabPage->GetSelectedType(); 172 const bool bURLRequired = m_pCollection->isConnectionUrlRequired(m_eType); 173 enableButtons(WZB_NEXT,bURLRequired); 174 enableButtons(WZB_FINISH,!bURLRequired); 175 return 1L; 176 } 177 //------------------------------------------------------------------------- 178 WizardTypes::WizardState ODbTypeWizDialog::determineNextState( WizardState _nCurrentState ) const 179 { 180 WizardTypes::WizardState nNextState = WZS_INVALID_STATE; 181 switch(_nCurrentState) 182 { 183 case START_PAGE: 184 switch(m_pCollection->determineType(m_eType)) 185 { 186 case ::dbaccess::DST_MOZILLA: 187 case ::dbaccess::DST_OUTLOOK: 188 case ::dbaccess::DST_OUTLOOKEXP: 189 case ::dbaccess::DST_EVOLUTION: 190 case ::dbaccess::DST_EVOLUTION_GROUPWISE: 191 case ::dbaccess::DST_EVOLUTION_LDAP: 192 case ::dbaccess::DST_KAB: 193 case ::dbaccess::DST_MACAB: 194 nNextState = WZS_INVALID_STATE; 195 break; 196 case ::dbaccess::DST_MYSQL_NATIVE: 197 nNextState = ADDITIONAL_PAGE_MYSQL_NATIVE; 198 break; 199 default: 200 nNextState = CONNECTION_PAGE; 201 break; 202 } 203 break; 204 case CONNECTION_PAGE: 205 switch(m_pCollection->determineType(m_eType)) 206 { 207 case ::dbaccess::DST_MOZILLA: 208 case ::dbaccess::DST_THUNDERBIRD: 209 case ::dbaccess::DST_OUTLOOK: 210 case ::dbaccess::DST_OUTLOOKEXP: 211 case ::dbaccess::DST_EVOLUTION: 212 case ::dbaccess::DST_EVOLUTION_GROUPWISE: 213 case ::dbaccess::DST_EVOLUTION_LDAP: 214 case ::dbaccess::DST_KAB: 215 case ::dbaccess::DST_MACAB: 216 case ::dbaccess::DST_MSACCESS: 217 case ::dbaccess::DST_MSACCESS_2007: 218 case ::dbaccess::DST_JDBC: 219 case ::dbaccess::DST_CALC: 220 nNextState = WZS_INVALID_STATE; 221 break; 222 case ::dbaccess::DST_DBASE: 223 nNextState = ADDITIONAL_PAGE_DBASE; 224 break; 225 case ::dbaccess::DST_FLAT: 226 nNextState = ADDITIONAL_PAGE_FLAT; 227 break; 228 case ::dbaccess::DST_LDAP: 229 nNextState = ADDITIONAL_PAGE_LDAP; 230 break; 231 case ::dbaccess::DST_ADABAS: 232 nNextState = ADDITIONAL_PAGE_ADABAS; 233 break; 234 case ::dbaccess::DST_MYSQL_JDBC: 235 nNextState = ADDITIONAL_PAGE_MYSQL_JDBC; 236 break; 237 case ::dbaccess::DST_MYSQL_ODBC: 238 nNextState = ADDITIONAL_PAGE_MYSQL_ODBC; 239 break; 240 case ::dbaccess::DST_ORACLE_JDBC: 241 nNextState = ADDITIONAL_PAGE_ORACLE_JDBC; 242 break; 243 case ::dbaccess::DST_ADO: 244 nNextState = ADDITIONAL_PAGE_ADO; 245 break; 246 case ::dbaccess::DST_ODBC: 247 nNextState = ADDITIONAL_PAGE_ODBC; 248 break; 249 default: 250 nNextState = WZS_INVALID_STATE; 251 break; 252 } 253 break; 254 } 255 256 return nNextState; 257 } 258 259 // ----------------------------------------------------------------------------- 260 const SfxItemSet* ODbTypeWizDialog::getOutputSet() const 261 { 262 return m_pOutSet; 263 } 264 // ----------------------------------------------------------------------------- 265 SfxItemSet* ODbTypeWizDialog::getWriteOutputSet() 266 { 267 return m_pOutSet; 268 } 269 // ----------------------------------------------------------------------------- 270 ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialog::createConnection() 271 { 272 return m_pImpl->createConnection(); 273 } 274 // ----------------------------------------------------------------------------- 275 Reference< XMultiServiceFactory > ODbTypeWizDialog::getORB() const 276 { 277 return m_pImpl->getORB(); 278 } 279 // ----------------------------------------------------------------------------- 280 Reference< XDriver > ODbTypeWizDialog::getDriver() 281 { 282 return m_pImpl->getDriver(); 283 } 284 // ----------------------------------------------------------------------------- 285 ::rtl::OUString ODbTypeWizDialog::getDatasourceType(const SfxItemSet& _rSet) const 286 { 287 return m_pImpl->getDatasourceType(_rSet); 288 } 289 // ----------------------------------------------------------------------------- 290 void ODbTypeWizDialog::clearPassword() 291 { 292 m_pImpl->clearPassword(); 293 } 294 295 // ----------------------------------------------------------------------------- 296 TabPage* ODbTypeWizDialog::createPage(WizardState _nState) 297 { 298 sal_uInt16 nStringId = STR_PAGETITLE_ADVANCED; 299 TabPage* pPage = NULL; 300 switch(_nState) 301 { 302 case START_PAGE: // start state 303 { 304 pPage = OGeneralPage::Create(this,*m_pOutSet); 305 OGeneralPage* pGeneralPage = static_cast< OGeneralPage* >( pPage ); 306 pGeneralPage->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog, OnTypeSelected)); 307 // pGeneralPage->SetCreationModeHandler( LINK( this, ODbTypeWizDialog, TODO ) ); 308 nStringId = STR_PAGETITLE_GENERAL; 309 } 310 break; 311 case CONNECTION_PAGE: 312 pPage = OConnectionTabPage::Create(this,*m_pOutSet); 313 nStringId = STR_PAGETITLE_CONNECTION; 314 break; 315 316 case ADDITIONAL_PAGE_DBASE: 317 pPage = ODriversSettings::CreateDbase(this,*m_pOutSet); 318 break; 319 case ADDITIONAL_PAGE_FLAT: 320 pPage = ODriversSettings::CreateText(this,*m_pOutSet); 321 break; 322 case ADDITIONAL_PAGE_LDAP: 323 pPage = ODriversSettings::CreateLDAP(this,*m_pOutSet); 324 break; 325 case ADDITIONAL_PAGE_ADABAS: 326 pPage = ODriversSettings::CreateAdabas(this,*m_pOutSet); 327 break; 328 case ADDITIONAL_PAGE_MYSQL_JDBC: 329 pPage = ODriversSettings::CreateMySQLJDBC(this,*m_pOutSet); 330 break; 331 case ADDITIONAL_PAGE_MYSQL_NATIVE: 332 pPage = ODriversSettings::CreateMySQLNATIVE(this,*m_pOutSet); 333 break; 334 case ADDITIONAL_PAGE_MYSQL_ODBC: 335 pPage = ODriversSettings::CreateMySQLODBC(this,*m_pOutSet); 336 break; 337 case ADDITIONAL_PAGE_ORACLE_JDBC: 338 pPage = ODriversSettings::CreateOracleJDBC(this,*m_pOutSet); 339 break; 340 case ADDITIONAL_PAGE_ADO: 341 pPage = ODriversSettings::CreateAdo(this,*m_pOutSet); 342 break; 343 case ADDITIONAL_PAGE_ODBC: 344 pPage = ODriversSettings::CreateODBC(this,*m_pOutSet); 345 break; 346 case ADDITIONAL_USERDEFINED: 347 pPage = ODriversSettings::CreateUser(this,*m_pOutSet); 348 break; 349 default: 350 OSL_ENSURE(0,"Wrong state!"); 351 break; 352 } 353 354 // register ourself as modified listener 355 if ( pPage ) 356 { 357 static_cast<OGenericAdministrationPage*>(pPage)->SetServiceFactory(m_pImpl->getORB()); 358 static_cast<OGenericAdministrationPage*>(pPage)->SetAdminDialog(this,this); 359 // open our own resource block, as the page titles are strings local to this block 360 LocalResourceAccess aDummy(DLG_DATABASE_ADMINISTRATION, RSC_TABDIALOG); 361 362 pPage->SetText(String(ModuleRes(nStringId))); 363 defaultButton( _nState == START_PAGE ? WZB_NEXT : WZB_FINISH ); 364 enableButtons( WZB_FINISH, _nState == START_PAGE ? sal_False : sal_True); 365 pPage->Show(); 366 } 367 return pPage; 368 } 369 // ----------------------------------------------------------------------------- 370 sal_Bool ODbTypeWizDialog::leaveState(WizardState _nState) 371 { 372 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState)); 373 if ( pPage ) 374 pPage->FillItemSet(*m_pOutSet); 375 return sal_True; 376 } 377 // ----------------------------------------------------------------------------- 378 void ODbTypeWizDialog::setTitle(const ::rtl::OUString& _sTitle) 379 { 380 SetText(_sTitle); 381 } 382 //------------------------------------------------------------------------- 383 void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable ) 384 { 385 enableButtons( WZB_FINISH, _bEnable ); 386 // TODO: 387 // this is hacky. At the moment, this method is used in only one case (#b6532894#). 388 // As soon as it is to be used more wide-spread, we should find a proper concept 389 // for enabling both the Next and Finish buttons, depending on the current page state. 390 // Plus, the concept must also care for the case where those pages are embedded into 391 // anormal tab dialog. 392 } 393 //------------------------------------------------------------------------- 394 sal_Bool ODbTypeWizDialog::saveDatasource() 395 { 396 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState())); 397 if ( pPage ) 398 pPage->FillItemSet(*m_pOutSet); 399 400 DataSourceInfoConverter aConverter(getORB()); 401 ::rtl::OUString sOldURL; 402 if ( m_pImpl->getCurrentDataSource().is() ) 403 m_pImpl->getCurrentDataSource()->getPropertyValue(PROPERTY_URL) >>= sOldURL; 404 aConverter.convert(m_pCollection,sOldURL,m_eType,m_pImpl->getCurrentDataSource()); 405 return sal_True; 406 } 407 // ----------------------------------------------------------------------------- 408 IWizardPageController* ODbTypeWizDialog::getPageController( TabPage* _pCurrentPage ) const 409 { 410 OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage); 411 return pPage; 412 } 413 // ----------------------------------------------------------------------------- 414 sal_Bool ODbTypeWizDialog::onFinish() 415 { 416 saveDatasource(); 417 return m_pImpl->saveChanges(*m_pOutSet) ? OWizardMachine::onFinish() : sal_False; 418 } 419 //......................................................................... 420 } // namespace dbaui 421 //......................................................................... 422