1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbwiz.cxx,v $
10 * $Revision: 1.21.68.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBAUI_DBWIZ_HXX
37 #ifndef _DBAUI_DBADMIN_HRC_
38 #include "dbadmin.hrc"
41 #include "dbu_dlg.hrc"
43 #ifndef _DBAUI_DATASOURCEITEMS_HXX_
44 #include "dsitems.hxx"
46 #include "dsnItem.hxx"
47 #ifndef _SFXSTRITEM_HXX
48 #include <svtools/stritem.hxx>
50 #ifndef _SFXENUMITEM_HXX
51 #include <svtools/eitem.hxx>
53 #ifndef _SFXINTITEM_HXX
54 #include <svtools/intitem.hxx>
56 #ifndef _SV_MSGBOX_HXX
57 #include <vcl/msgbox.hxx>
59 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
60 #include "dbustrings.hrc"
62 #ifndef _DBAUI_ADMINPAGES_HXX_
63 #include "adminpages.hxx"
65 #ifndef _DBAUI_GENERALPAGE_HXX_
66 #include "generalpage.hxx"
68 #ifndef _DBAUI_LOCALRESACCESS_HXX_
69 #include "localresaccess.hxx"
71 #ifndef _DBAUI_STRINGLISTITEM_HXX_
72 #include "stringlistitem.hxx"
74 #ifndef _DBAUI_PROPERTYSETITEM_HXX_
75 #include "propertysetitem.hxx"
77 #ifndef _UNOTOOLS_CONFIGNODE_HXX_
78 #include <unotools/confignode.hxx>
80 #ifndef DBAUI_CONNECTIONPAGE_HXX
81 #include "ConnectionPage.hxx"
83 #ifndef DBAUI_DRIVERSETTINGS_HXX
84 #include "DriverSettings.hxx"
86 #ifndef _DBAUI_DBADMINIMPL_HXX_
87 #include "DbAdminImpl.hxx"
89 #ifndef _DBA_DBACCESS_HELPID_HRC_
90 #include "dbaccess_helpid.hrc"
93 //.........................................................................
96 //.........................................................................
98 using namespace com::sun::star::uno
;
99 using namespace com::sun::star::sdbc
;
100 using namespace com::sun::star::lang
;
101 using namespace com::sun::star::util
;
102 using namespace com::sun::star::beans
;
103 using namespace com::sun::star::container
;
106 #define CONNECTION_PAGE 1
107 #define ADDITIONAL_PAGE_DBASE 2
108 #define ADDITIONAL_PAGE_FLAT 3
109 #define ADDITIONAL_PAGE_LDAP 4
110 #define ADDITIONAL_PAGE_ADABAS 5
111 #define ADDITIONAL_PAGE_MYSQL_JDBC 6
112 #define ADDITIONAL_PAGE_MYSQL_ODBC 7
113 #define ADDITIONAL_PAGE_ORACLE_JDBC 8
114 #define ADDITIONAL_PAGE_ADO 9
115 #define ADDITIONAL_PAGE_ODBC 10
116 #define ADDITIONAL_USERDEFINED 11
117 #define ADDITIONAL_PAGE_MYSQL_NATIVE 12
120 DBG_NAME(ODbTypeWizDialog
)
121 //=========================================================================
123 //=========================================================================
124 //-------------------------------------------------------------------------
125 ODbTypeWizDialog::ODbTypeWizDialog(Window
* _pParent
127 ,const Reference
< XMultiServiceFactory
>& _rxORB
128 ,const ::com::sun::star::uno::Any
& _aDataSourceName
130 :OWizardMachine(_pParent
, ModuleRes(DLG_DATABASE_TYPE_CHANGE
), WZB_NEXT
| WZB_PREVIOUS
| WZB_FINISH
| WZB_CANCEL
| WZB_HELP
)
132 ,m_bResetting(sal_False
)
133 ,m_bApplied(sal_False
)
134 ,m_bUIEnabled( sal_True
)
136 DBG_CTOR(ODbTypeWizDialog
,NULL
);
137 m_pImpl
= ::std::auto_ptr
<ODbDataSourceAdministrationHelper
>(new ODbDataSourceAdministrationHelper(_rxORB
,this,this));
138 m_pImpl
->setDataSourceOrName(_aDataSourceName
);
139 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
140 m_pOutSet
= new SfxItemSet( *_pItems
->GetPool(), _pItems
->GetRanges() );
142 m_pImpl
->translateProperties(xDatasource
, *m_pOutSet
);
143 m_eType
= m_pImpl
->getDatasourceType(*m_pOutSet
);
145 SetPageSizePixel(LogicToPixel(::Size(PAGE_X
, PAGE_Y
), MAP_APPFONT
));
146 ShowButtonFixedLine(sal_True
);
147 defaultButton(WZB_NEXT
);
148 enableButtons(WZB_FINISH
, sal_False
);
149 enableAutomaticNextButtonState( true );
151 m_pPrevPage
->SetHelpId(HID_DBWIZ_PREVIOUS
);
152 m_pNextPage
->SetHelpId(HID_DBWIZ_NEXT
);
153 m_pCancel
->SetHelpId(HID_DBWIZ_CANCEL
);
154 m_pFinish
->SetHelpId(HID_DBWIZ_FINISH
);
155 m_pHelp
->SetUniqueId(UID_DBWIZ_HELP
);
156 // no local resources needed anymore
158 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, _pItems
->GetItem(DSID_TYPECOLLECTION
));
159 m_pCollection
= pCollectionItem
->getCollection();
165 //-------------------------------------------------------------------------
166 ODbTypeWizDialog::~ODbTypeWizDialog()
168 DBG_DTOR(ODbTypeWizDialog
,NULL
);
171 //-------------------------------------------------------------------------
172 IMPL_LINK(ODbTypeWizDialog
, OnTypeSelected
, OGeneralPage
*, _pTabPage
)
174 m_eType
= _pTabPage
->GetSelectedType();
175 const bool bURLRequired
= m_pCollection
->isConnectionUrlRequired(m_eType
);
176 enableButtons(WZB_NEXT
,bURLRequired
);
177 enableButtons(WZB_FINISH
,!bURLRequired
);
180 //-------------------------------------------------------------------------
181 WizardTypes::WizardState
ODbTypeWizDialog::determineNextState( WizardState _nCurrentState
) const
183 WizardTypes::WizardState nNextState
= WZS_INVALID_STATE
;
184 switch(_nCurrentState
)
187 switch(m_pCollection
->determineType(m_eType
))
189 case ::dbaccess::DST_MOZILLA
:
190 case ::dbaccess::DST_OUTLOOK
:
191 case ::dbaccess::DST_OUTLOOKEXP
:
192 case ::dbaccess::DST_EVOLUTION
:
193 case ::dbaccess::DST_EVOLUTION_GROUPWISE
:
194 case ::dbaccess::DST_EVOLUTION_LDAP
:
195 case ::dbaccess::DST_KAB
:
196 case ::dbaccess::DST_MACAB
:
197 nNextState
= WZS_INVALID_STATE
;
199 case ::dbaccess::DST_MYSQL_NATIVE
:
200 nNextState
= ADDITIONAL_PAGE_MYSQL_NATIVE
;
203 nNextState
= CONNECTION_PAGE
;
207 case CONNECTION_PAGE
:
208 switch(m_pCollection
->determineType(m_eType
))
210 case ::dbaccess::DST_MOZILLA
:
211 case ::dbaccess::DST_THUNDERBIRD
:
212 case ::dbaccess::DST_OUTLOOK
:
213 case ::dbaccess::DST_OUTLOOKEXP
:
214 case ::dbaccess::DST_EVOLUTION
:
215 case ::dbaccess::DST_EVOLUTION_GROUPWISE
:
216 case ::dbaccess::DST_EVOLUTION_LDAP
:
217 case ::dbaccess::DST_KAB
:
218 case ::dbaccess::DST_MACAB
:
219 case ::dbaccess::DST_MSACCESS
:
220 case ::dbaccess::DST_MSACCESS_2007
:
221 case ::dbaccess::DST_JDBC
:
222 case ::dbaccess::DST_CALC
:
223 nNextState
= WZS_INVALID_STATE
;
225 case ::dbaccess::DST_DBASE
:
226 nNextState
= ADDITIONAL_PAGE_DBASE
;
228 case ::dbaccess::DST_FLAT
:
229 nNextState
= ADDITIONAL_PAGE_FLAT
;
231 case ::dbaccess::DST_LDAP
:
232 nNextState
= ADDITIONAL_PAGE_LDAP
;
234 case ::dbaccess::DST_ADABAS
:
235 nNextState
= ADDITIONAL_PAGE_ADABAS
;
237 case ::dbaccess::DST_MYSQL_JDBC
:
238 nNextState
= ADDITIONAL_PAGE_MYSQL_JDBC
;
240 case ::dbaccess::DST_MYSQL_ODBC
:
241 nNextState
= ADDITIONAL_PAGE_MYSQL_ODBC
;
243 case ::dbaccess::DST_ORACLE_JDBC
:
244 nNextState
= ADDITIONAL_PAGE_ORACLE_JDBC
;
246 case ::dbaccess::DST_ADO
:
247 nNextState
= ADDITIONAL_PAGE_ADO
;
249 case ::dbaccess::DST_ODBC
:
250 nNextState
= ADDITIONAL_PAGE_ODBC
;
253 nNextState
= WZS_INVALID_STATE
;
262 // -----------------------------------------------------------------------------
263 const SfxItemSet
* ODbTypeWizDialog::getOutputSet() const
267 // -----------------------------------------------------------------------------
268 SfxItemSet
* ODbTypeWizDialog::getWriteOutputSet()
272 // -----------------------------------------------------------------------------
273 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbTypeWizDialog::createConnection()
275 return m_pImpl
->createConnection();
277 // -----------------------------------------------------------------------------
278 Reference
< XMultiServiceFactory
> ODbTypeWizDialog::getORB() const
280 return m_pImpl
->getORB();
282 // -----------------------------------------------------------------------------
283 Reference
< XDriver
> ODbTypeWizDialog::getDriver()
285 return m_pImpl
->getDriver();
287 // -----------------------------------------------------------------------------
288 ::rtl::OUString
ODbTypeWizDialog::getDatasourceType(const SfxItemSet
& _rSet
) const
290 return m_pImpl
->getDatasourceType(_rSet
);
292 // -----------------------------------------------------------------------------
293 void ODbTypeWizDialog::clearPassword()
295 m_pImpl
->clearPassword();
298 // -----------------------------------------------------------------------------
299 TabPage
* ODbTypeWizDialog::createPage(WizardState _nState
)
301 USHORT nStringId
= STR_PAGETITLE_ADVANCED
;
302 TabPage
* pPage
= NULL
;
305 case START_PAGE
: // start state
307 pPage
= OGeneralPage::Create(this,*m_pOutSet
);
308 OGeneralPage
* pGeneralPage
= static_cast< OGeneralPage
* >( pPage
);
309 pGeneralPage
->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog
, OnTypeSelected
));
310 // pGeneralPage->SetCreationModeHandler( LINK( this, ODbTypeWizDialog, TODO ) );
311 nStringId
= STR_PAGETITLE_GENERAL
;
314 case CONNECTION_PAGE
:
315 pPage
= OConnectionTabPage::Create(this,*m_pOutSet
);
316 nStringId
= STR_PAGETITLE_CONNECTION
;
319 case ADDITIONAL_PAGE_DBASE
:
320 pPage
= ODriversSettings::CreateDbase(this,*m_pOutSet
);
322 case ADDITIONAL_PAGE_FLAT
:
323 pPage
= ODriversSettings::CreateText(this,*m_pOutSet
);
325 case ADDITIONAL_PAGE_LDAP
:
326 pPage
= ODriversSettings::CreateLDAP(this,*m_pOutSet
);
328 case ADDITIONAL_PAGE_ADABAS
:
329 pPage
= ODriversSettings::CreateAdabas(this,*m_pOutSet
);
331 case ADDITIONAL_PAGE_MYSQL_JDBC
:
332 pPage
= ODriversSettings::CreateMySQLJDBC(this,*m_pOutSet
);
334 case ADDITIONAL_PAGE_MYSQL_NATIVE
:
335 pPage
= ODriversSettings::CreateMySQLNATIVE(this,*m_pOutSet
);
337 case ADDITIONAL_PAGE_MYSQL_ODBC
:
338 pPage
= ODriversSettings::CreateMySQLODBC(this,*m_pOutSet
);
340 case ADDITIONAL_PAGE_ORACLE_JDBC
:
341 pPage
= ODriversSettings::CreateOracleJDBC(this,*m_pOutSet
);
343 case ADDITIONAL_PAGE_ADO
:
344 pPage
= ODriversSettings::CreateAdo(this,*m_pOutSet
);
346 case ADDITIONAL_PAGE_ODBC
:
347 pPage
= ODriversSettings::CreateODBC(this,*m_pOutSet
);
349 case ADDITIONAL_USERDEFINED
:
350 pPage
= ODriversSettings::CreateUser(this,*m_pOutSet
);
353 OSL_ENSURE(0,"Wrong state!");
357 // register ourself as modified listener
360 static_cast<OGenericAdministrationPage
*>(pPage
)->SetServiceFactory(m_pImpl
->getORB());
361 static_cast<OGenericAdministrationPage
*>(pPage
)->SetAdminDialog(this,this);
362 // open our own resource block, as the page titles are strings local to this block
363 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
365 pPage
->SetText(String(ModuleRes(nStringId
)));
366 defaultButton( _nState
== START_PAGE
? WZB_NEXT
: WZB_FINISH
);
367 enableButtons( WZB_FINISH
, _nState
== START_PAGE
? sal_False
: sal_True
);
372 // -----------------------------------------------------------------------------
373 sal_Bool
ODbTypeWizDialog::leaveState(WizardState _nState
)
375 SfxTabPage
* pPage
= static_cast<SfxTabPage
*>(WizardDialog::GetPage(_nState
));
377 pPage
->FillItemSet(*m_pOutSet
);
380 // -----------------------------------------------------------------------------
381 void ODbTypeWizDialog::setTitle(const ::rtl::OUString
& _sTitle
)
385 //-------------------------------------------------------------------------
386 void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable
)
388 enableButtons( WZB_FINISH
, _bEnable
);
390 // this is hacky. At the moment, this method is used in only one case (#b6532894#).
391 // As soon as it is to be used more wide-spread, we should find a proper concept
392 // for enabling both the Next and Finish buttons, depending on the current page state.
393 // Plus, the concept must also care for the case where those pages are embedded into
394 // anormal tab dialog.
396 //-------------------------------------------------------------------------
397 sal_Bool
ODbTypeWizDialog::saveDatasource()
399 SfxTabPage
* pPage
= static_cast<SfxTabPage
*>(WizardDialog::GetPage(getCurrentState()));
401 pPage
->FillItemSet(*m_pOutSet
);
403 DataSourceInfoConverter
aConverter(getORB());
404 ::rtl::OUString sOldURL
;
405 if ( m_pImpl
->getCurrentDataSource().is() )
406 m_pImpl
->getCurrentDataSource()->getPropertyValue(PROPERTY_URL
) >>= sOldURL
;
407 aConverter
.convert(m_pCollection
,sOldURL
,m_eType
,m_pImpl
->getCurrentDataSource());
410 // -----------------------------------------------------------------------------
411 IWizardPage
* ODbTypeWizDialog::getWizardPage(TabPage
* _pCurrentPage
) const
413 OGenericAdministrationPage
* pPage
= static_cast<OGenericAdministrationPage
*>(_pCurrentPage
);
416 // -----------------------------------------------------------------------------
417 sal_Bool
ODbTypeWizDialog::onFinish(sal_Int32 _nResult
)
420 return m_pImpl
->saveChanges(*m_pOutSet
) ? OWizardMachine::onFinish(_nResult
) : sal_False
;
422 //.........................................................................
424 //.........................................................................