1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include "dbadmin.hrc"
32 #include "dbu_dlg.hrc"
33 #include "dsitems.hxx"
34 #include "dsnItem.hxx"
35 #include <svl/stritem.hxx>
36 #include <svl/eitem.hxx>
37 #include <svl/intitem.hxx>
38 #include <vcl/msgbox.hxx>
39 #include "dbustrings.hrc"
40 #include "adminpages.hxx"
41 #include "generalpage.hxx"
42 #include "localresaccess.hxx"
43 #include "stringlistitem.hxx"
44 #include "propertysetitem.hxx"
45 #include <unotools/confignode.hxx>
46 #include "ConnectionPage.hxx"
47 #include "DriverSettings.hxx"
48 #include "DbAdminImpl.hxx"
49 #include "dbaccess_helpid.hrc"
51 //.........................................................................
54 //.........................................................................
56 using namespace com::sun::star::uno
;
57 using namespace com::sun::star::sdbc
;
58 using namespace com::sun::star::lang
;
59 using namespace com::sun::star::util
;
60 using namespace com::sun::star::beans
;
61 using namespace com::sun::star::container
;
64 #define CONNECTION_PAGE 1
65 #define ADDITIONAL_PAGE_DBASE 2
66 #define ADDITIONAL_PAGE_FLAT 3
67 #define ADDITIONAL_PAGE_LDAP 4
68 //5 was ADDITIONAL_PAGE_ADABAS
69 #define ADDITIONAL_PAGE_MYSQL_JDBC 6
70 #define ADDITIONAL_PAGE_MYSQL_ODBC 7
71 #define ADDITIONAL_PAGE_ORACLE_JDBC 8
72 #define ADDITIONAL_PAGE_ADO 9
73 #define ADDITIONAL_PAGE_ODBC 10
74 #define ADDITIONAL_USERDEFINED 11
75 #define ADDITIONAL_PAGE_MYSQL_NATIVE 12
78 DBG_NAME(ODbTypeWizDialog
)
79 //=========================================================================
81 //=========================================================================
82 //-------------------------------------------------------------------------
83 ODbTypeWizDialog::ODbTypeWizDialog(Window
* _pParent
85 ,const Reference
< XMultiServiceFactory
>& _rxORB
86 ,const ::com::sun::star::uno::Any
& _aDataSourceName
88 :OWizardMachine(_pParent
, ModuleRes(DLG_DATABASE_TYPE_CHANGE
), WZB_NEXT
| WZB_PREVIOUS
| WZB_FINISH
| WZB_CANCEL
| WZB_HELP
)
90 ,m_bResetting(sal_False
)
91 ,m_bApplied(sal_False
)
92 ,m_bUIEnabled( sal_True
)
94 DBG_CTOR(ODbTypeWizDialog
,NULL
);
95 m_pImpl
= ::std::auto_ptr
<ODbDataSourceAdministrationHelper
>(new ODbDataSourceAdministrationHelper(_rxORB
,this,this));
96 m_pImpl
->setDataSourceOrName(_aDataSourceName
);
97 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
98 m_pOutSet
= new SfxItemSet( *_pItems
->GetPool(), _pItems
->GetRanges() );
100 m_pImpl
->translateProperties(xDatasource
, *m_pOutSet
);
101 m_eType
= m_pImpl
->getDatasourceType(*m_pOutSet
);
103 SetPageSizePixel(LogicToPixel(::Size(PAGE_X
, PAGE_Y
), MAP_APPFONT
));
104 ShowButtonFixedLine(sal_True
);
105 defaultButton(WZB_NEXT
);
106 enableButtons(WZB_FINISH
, sal_False
);
107 enableAutomaticNextButtonState( true );
109 m_pPrevPage
->SetHelpId(HID_DBWIZ_PREVIOUS
);
110 m_pNextPage
->SetHelpId(HID_DBWIZ_NEXT
);
111 m_pCancel
->SetHelpId(HID_DBWIZ_CANCEL
);
112 m_pFinish
->SetHelpId(HID_DBWIZ_FINISH
);
113 m_pHelp
->SetUniqueId(UID_DBWIZ_HELP
);
114 // no local resources needed anymore
116 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, _pItems
->GetItem(DSID_TYPECOLLECTION
));
117 m_pCollection
= pCollectionItem
->getCollection();
123 //-------------------------------------------------------------------------
124 ODbTypeWizDialog::~ODbTypeWizDialog()
126 DBG_DTOR(ODbTypeWizDialog
,NULL
);
129 //-------------------------------------------------------------------------
130 IMPL_LINK(ODbTypeWizDialog
, OnTypeSelected
, OGeneralPage
*, _pTabPage
)
132 m_eType
= _pTabPage
->GetSelectedType();
133 const bool bURLRequired
= m_pCollection
->isConnectionUrlRequired(m_eType
);
134 enableButtons(WZB_NEXT
,bURLRequired
);
135 enableButtons(WZB_FINISH
,!bURLRequired
);
138 //-------------------------------------------------------------------------
139 WizardTypes::WizardState
ODbTypeWizDialog::determineNextState( WizardState _nCurrentState
) const
141 WizardTypes::WizardState nNextState
= WZS_INVALID_STATE
;
142 switch(_nCurrentState
)
145 switch(m_pCollection
->determineType(m_eType
))
147 case ::dbaccess::DST_MOZILLA
:
148 case ::dbaccess::DST_OUTLOOK
:
149 case ::dbaccess::DST_OUTLOOKEXP
:
150 case ::dbaccess::DST_EVOLUTION
:
151 case ::dbaccess::DST_EVOLUTION_GROUPWISE
:
152 case ::dbaccess::DST_EVOLUTION_LDAP
:
153 case ::dbaccess::DST_KAB
:
154 case ::dbaccess::DST_MACAB
:
155 nNextState
= WZS_INVALID_STATE
;
157 case ::dbaccess::DST_MYSQL_NATIVE
:
158 nNextState
= ADDITIONAL_PAGE_MYSQL_NATIVE
;
161 nNextState
= CONNECTION_PAGE
;
165 case CONNECTION_PAGE
:
166 switch(m_pCollection
->determineType(m_eType
))
168 case ::dbaccess::DST_MOZILLA
:
169 case ::dbaccess::DST_THUNDERBIRD
:
170 case ::dbaccess::DST_OUTLOOK
:
171 case ::dbaccess::DST_OUTLOOKEXP
:
172 case ::dbaccess::DST_EVOLUTION
:
173 case ::dbaccess::DST_EVOLUTION_GROUPWISE
:
174 case ::dbaccess::DST_EVOLUTION_LDAP
:
175 case ::dbaccess::DST_KAB
:
176 case ::dbaccess::DST_MACAB
:
177 case ::dbaccess::DST_MSACCESS
:
178 case ::dbaccess::DST_MSACCESS_2007
:
179 case ::dbaccess::DST_JDBC
:
180 case ::dbaccess::DST_CALC
:
181 nNextState
= WZS_INVALID_STATE
;
183 case ::dbaccess::DST_DBASE
:
184 nNextState
= ADDITIONAL_PAGE_DBASE
;
186 case ::dbaccess::DST_FLAT
:
187 nNextState
= ADDITIONAL_PAGE_FLAT
;
189 case ::dbaccess::DST_LDAP
:
190 nNextState
= ADDITIONAL_PAGE_LDAP
;
192 case ::dbaccess::DST_MYSQL_JDBC
:
193 nNextState
= ADDITIONAL_PAGE_MYSQL_JDBC
;
195 case ::dbaccess::DST_MYSQL_ODBC
:
196 nNextState
= ADDITIONAL_PAGE_MYSQL_ODBC
;
198 case ::dbaccess::DST_ORACLE_JDBC
:
199 nNextState
= ADDITIONAL_PAGE_ORACLE_JDBC
;
201 case ::dbaccess::DST_ADO
:
202 nNextState
= ADDITIONAL_PAGE_ADO
;
204 case ::dbaccess::DST_ODBC
:
205 nNextState
= ADDITIONAL_PAGE_ODBC
;
208 nNextState
= WZS_INVALID_STATE
;
217 // -----------------------------------------------------------------------------
218 const SfxItemSet
* ODbTypeWizDialog::getOutputSet() const
222 // -----------------------------------------------------------------------------
223 SfxItemSet
* ODbTypeWizDialog::getWriteOutputSet()
227 // -----------------------------------------------------------------------------
228 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbTypeWizDialog::createConnection()
230 return m_pImpl
->createConnection();
232 // -----------------------------------------------------------------------------
233 Reference
< XMultiServiceFactory
> ODbTypeWizDialog::getORB() const
235 return m_pImpl
->getORB();
237 // -----------------------------------------------------------------------------
238 Reference
< XDriver
> ODbTypeWizDialog::getDriver()
240 return m_pImpl
->getDriver();
242 // -----------------------------------------------------------------------------
243 ::rtl::OUString
ODbTypeWizDialog::getDatasourceType(const SfxItemSet
& _rSet
) const
245 return m_pImpl
->getDatasourceType(_rSet
);
247 // -----------------------------------------------------------------------------
248 void ODbTypeWizDialog::clearPassword()
250 m_pImpl
->clearPassword();
253 // -----------------------------------------------------------------------------
254 TabPage
* ODbTypeWizDialog::createPage(WizardState _nState
)
256 sal_uInt16 nStringId
= STR_PAGETITLE_ADVANCED
;
257 TabPage
* pPage
= NULL
;
260 case START_PAGE
: // start state
262 pPage
= OGeneralPage::Create(this,*m_pOutSet
);
263 OGeneralPage
* pGeneralPage
= static_cast< OGeneralPage
* >( pPage
);
264 pGeneralPage
->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog
, OnTypeSelected
));
265 // pGeneralPage->SetCreationModeHandler( LINK( this, ODbTypeWizDialog, TODO ) );
266 nStringId
= STR_PAGETITLE_GENERAL
;
269 case CONNECTION_PAGE
:
270 pPage
= OConnectionTabPage::Create(this,*m_pOutSet
);
271 nStringId
= STR_PAGETITLE_CONNECTION
;
274 case ADDITIONAL_PAGE_DBASE
:
275 pPage
= ODriversSettings::CreateDbase(this,*m_pOutSet
);
277 case ADDITIONAL_PAGE_FLAT
:
278 pPage
= ODriversSettings::CreateText(this,*m_pOutSet
);
280 case ADDITIONAL_PAGE_LDAP
:
281 pPage
= ODriversSettings::CreateLDAP(this,*m_pOutSet
);
283 case ADDITIONAL_PAGE_MYSQL_JDBC
:
284 pPage
= ODriversSettings::CreateMySQLJDBC(this,*m_pOutSet
);
286 case ADDITIONAL_PAGE_MYSQL_NATIVE
:
287 pPage
= ODriversSettings::CreateMySQLNATIVE(this,*m_pOutSet
);
289 case ADDITIONAL_PAGE_MYSQL_ODBC
:
290 pPage
= ODriversSettings::CreateMySQLODBC(this,*m_pOutSet
);
292 case ADDITIONAL_PAGE_ORACLE_JDBC
:
293 pPage
= ODriversSettings::CreateOracleJDBC(this,*m_pOutSet
);
295 case ADDITIONAL_PAGE_ADO
:
296 pPage
= ODriversSettings::CreateAdo(this,*m_pOutSet
);
298 case ADDITIONAL_PAGE_ODBC
:
299 pPage
= ODriversSettings::CreateODBC(this,*m_pOutSet
);
301 case ADDITIONAL_USERDEFINED
:
302 pPage
= ODriversSettings::CreateUser(this,*m_pOutSet
);
305 OSL_FAIL("Wrong state!");
309 // register ourself as modified listener
312 static_cast<OGenericAdministrationPage
*>(pPage
)->SetServiceFactory(m_pImpl
->getORB());
313 static_cast<OGenericAdministrationPage
*>(pPage
)->SetAdminDialog(this,this);
314 // open our own resource block, as the page titles are strings local to this block
315 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
317 pPage
->SetText(String(ModuleRes(nStringId
)));
318 defaultButton( _nState
== START_PAGE
? WZB_NEXT
: WZB_FINISH
);
319 enableButtons( WZB_FINISH
, _nState
== START_PAGE
? sal_False
: sal_True
);
324 // -----------------------------------------------------------------------------
325 sal_Bool
ODbTypeWizDialog::leaveState(WizardState _nState
)
327 SfxTabPage
* pPage
= static_cast<SfxTabPage
*>(WizardDialog::GetPage(_nState
));
329 pPage
->FillItemSet(*m_pOutSet
);
332 // -----------------------------------------------------------------------------
333 void ODbTypeWizDialog::setTitle(const ::rtl::OUString
& _sTitle
)
337 //-------------------------------------------------------------------------
338 void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable
)
340 enableButtons( WZB_FINISH
, _bEnable
);
342 // this is hacky. At the moment, this method is used in only one case.
343 // As soon as it is to be used more wide-spread, we should find a proper concept
344 // for enabling both the Next and Finish buttons, depending on the current page state.
345 // Plus, the concept must also care for the case where those pages are embedded into
346 // anormal tab dialog.
348 //-------------------------------------------------------------------------
349 sal_Bool
ODbTypeWizDialog::saveDatasource()
351 SfxTabPage
* pPage
= static_cast<SfxTabPage
*>(WizardDialog::GetPage(getCurrentState()));
353 pPage
->FillItemSet(*m_pOutSet
);
355 DataSourceInfoConverter
aConverter(getORB());
356 ::rtl::OUString sOldURL
;
357 if ( m_pImpl
->getCurrentDataSource().is() )
358 m_pImpl
->getCurrentDataSource()->getPropertyValue(PROPERTY_URL
) >>= sOldURL
;
359 aConverter
.convert(m_pCollection
,sOldURL
,m_eType
,m_pImpl
->getCurrentDataSource());
362 // -----------------------------------------------------------------------------
363 IWizardPageController
* ODbTypeWizDialog::getPageController( TabPage
* _pCurrentPage
) const
365 OGenericAdministrationPage
* pPage
= static_cast<OGenericAdministrationPage
*>(_pCurrentPage
);
368 // -----------------------------------------------------------------------------
369 sal_Bool
ODbTypeWizDialog::onFinish()
372 return m_pImpl
->saveChanges(*m_pOutSet
) ? OWizardMachine::onFinish() : sal_False
;
374 //.........................................................................
376 //.........................................................................
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */