1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "dbadmin.hrc"
23 #include "dbu_dlg.hrc"
24 #include "dsitems.hxx"
25 #include "dsnItem.hxx"
26 #include <svl/stritem.hxx>
27 #include <svl/eitem.hxx>
28 #include <svl/intitem.hxx>
29 #include <vcl/msgbox.hxx>
30 #include "dbustrings.hrc"
31 #include "adminpages.hxx"
32 #include "generalpage.hxx"
33 #include "localresaccess.hxx"
34 #include "stringlistitem.hxx"
35 #include "propertysetitem.hxx"
36 #include <unotools/confignode.hxx>
37 #include "ConnectionPage.hxx"
38 #include "DriverSettings.hxx"
39 #include "DbAdminImpl.hxx"
40 #include "dbaccess_helpid.hrc"
42 //.........................................................................
45 //.........................................................................
47 using namespace com::sun::star::uno
;
48 using namespace com::sun::star::sdbc
;
49 using namespace com::sun::star::lang
;
50 using namespace com::sun::star::util
;
51 using namespace com::sun::star::beans
;
52 using namespace com::sun::star::container
;
55 #define CONNECTION_PAGE 1
56 #define ADDITIONAL_PAGE_DBASE 2
57 #define ADDITIONAL_PAGE_FLAT 3
58 #define ADDITIONAL_PAGE_LDAP 4
59 //5 was ADDITIONAL_PAGE_ADABAS
60 #define ADDITIONAL_PAGE_MYSQL_JDBC 6
61 #define ADDITIONAL_PAGE_MYSQL_ODBC 7
62 #define ADDITIONAL_PAGE_ORACLE_JDBC 8
63 #define ADDITIONAL_PAGE_ADO 9
64 #define ADDITIONAL_PAGE_ODBC 10
65 #define ADDITIONAL_USERDEFINED 11
66 #define ADDITIONAL_PAGE_MYSQL_NATIVE 12
69 DBG_NAME(ODbTypeWizDialog
)
70 //=========================================================================
72 //=========================================================================
73 //-------------------------------------------------------------------------
74 ODbTypeWizDialog::ODbTypeWizDialog(Window
* _pParent
76 ,const Reference
< XComponentContext
>& _rxORB
77 ,const ::com::sun::star::uno::Any
& _aDataSourceName
79 :OWizardMachine(_pParent
, ModuleRes(DLG_DATABASE_TYPE_CHANGE
), WZB_NEXT
| WZB_PREVIOUS
| WZB_FINISH
| WZB_CANCEL
| WZB_HELP
)
81 ,m_bResetting(sal_False
)
82 ,m_bApplied(sal_False
)
83 ,m_bUIEnabled( sal_True
)
85 DBG_CTOR(ODbTypeWizDialog
,NULL
);
86 m_pImpl
= ::std::auto_ptr
<ODbDataSourceAdministrationHelper
>(new ODbDataSourceAdministrationHelper(_rxORB
,this,this));
87 m_pImpl
->setDataSourceOrName(_aDataSourceName
);
88 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
89 m_pOutSet
= new SfxItemSet( *_pItems
->GetPool(), _pItems
->GetRanges() );
91 m_pImpl
->translateProperties(xDatasource
, *m_pOutSet
);
92 m_eType
= m_pImpl
->getDatasourceType(*m_pOutSet
);
94 SetPageSizePixel(LogicToPixel(::Size(PAGE_X
, PAGE_Y
), MAP_APPFONT
));
95 ShowButtonFixedLine(sal_True
);
96 defaultButton(WZB_NEXT
);
97 enableButtons(WZB_FINISH
, sal_False
);
98 enableAutomaticNextButtonState( true );
100 m_pPrevPage
->SetHelpId(HID_DBWIZ_PREVIOUS
);
101 m_pNextPage
->SetHelpId(HID_DBWIZ_NEXT
);
102 m_pCancel
->SetHelpId(HID_DBWIZ_CANCEL
);
103 m_pFinish
->SetHelpId(HID_DBWIZ_FINISH
);
104 m_pHelp
->SetUniqueId(UID_DBWIZ_HELP
);
105 // no local resources needed anymore
107 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, _pItems
->GetItem(DSID_TYPECOLLECTION
));
108 m_pCollection
= pCollectionItem
->getCollection();
114 //-------------------------------------------------------------------------
115 ODbTypeWizDialog::~ODbTypeWizDialog()
117 DBG_DTOR(ODbTypeWizDialog
,NULL
);
120 //-------------------------------------------------------------------------
121 IMPL_LINK(ODbTypeWizDialog
, OnTypeSelected
, OGeneralPage
*, _pTabPage
)
123 m_eType
= _pTabPage
->GetSelectedType();
124 const bool bURLRequired
= m_pCollection
->isConnectionUrlRequired(m_eType
);
125 enableButtons(WZB_NEXT
,bURLRequired
);
126 enableButtons(WZB_FINISH
,!bURLRequired
);
129 //-------------------------------------------------------------------------
130 WizardTypes::WizardState
ODbTypeWizDialog::determineNextState( WizardState _nCurrentState
) const
132 WizardTypes::WizardState nNextState
= WZS_INVALID_STATE
;
133 switch(_nCurrentState
)
136 switch(m_pCollection
->determineType(m_eType
))
138 case ::dbaccess::DST_MOZILLA
:
139 case ::dbaccess::DST_OUTLOOK
:
140 case ::dbaccess::DST_OUTLOOKEXP
:
141 case ::dbaccess::DST_EVOLUTION
:
142 case ::dbaccess::DST_EVOLUTION_GROUPWISE
:
143 case ::dbaccess::DST_EVOLUTION_LDAP
:
144 case ::dbaccess::DST_KAB
:
145 case ::dbaccess::DST_MACAB
:
146 nNextState
= WZS_INVALID_STATE
;
148 case ::dbaccess::DST_MYSQL_NATIVE
:
149 nNextState
= ADDITIONAL_PAGE_MYSQL_NATIVE
;
152 nNextState
= CONNECTION_PAGE
;
156 case CONNECTION_PAGE
:
157 switch(m_pCollection
->determineType(m_eType
))
159 case ::dbaccess::DST_MOZILLA
:
160 case ::dbaccess::DST_THUNDERBIRD
:
161 case ::dbaccess::DST_OUTLOOK
:
162 case ::dbaccess::DST_OUTLOOKEXP
:
163 case ::dbaccess::DST_EVOLUTION
:
164 case ::dbaccess::DST_EVOLUTION_GROUPWISE
:
165 case ::dbaccess::DST_EVOLUTION_LDAP
:
166 case ::dbaccess::DST_KAB
:
167 case ::dbaccess::DST_MACAB
:
168 case ::dbaccess::DST_MSACCESS
:
169 case ::dbaccess::DST_MSACCESS_2007
:
170 case ::dbaccess::DST_JDBC
:
171 case ::dbaccess::DST_CALC
:
172 nNextState
= WZS_INVALID_STATE
;
174 case ::dbaccess::DST_DBASE
:
175 nNextState
= ADDITIONAL_PAGE_DBASE
;
177 case ::dbaccess::DST_FLAT
:
178 nNextState
= ADDITIONAL_PAGE_FLAT
;
180 case ::dbaccess::DST_LDAP
:
181 nNextState
= ADDITIONAL_PAGE_LDAP
;
183 case ::dbaccess::DST_MYSQL_JDBC
:
184 nNextState
= ADDITIONAL_PAGE_MYSQL_JDBC
;
186 case ::dbaccess::DST_MYSQL_ODBC
:
187 nNextState
= ADDITIONAL_PAGE_MYSQL_ODBC
;
189 case ::dbaccess::DST_ORACLE_JDBC
:
190 nNextState
= ADDITIONAL_PAGE_ORACLE_JDBC
;
192 case ::dbaccess::DST_ADO
:
193 nNextState
= ADDITIONAL_PAGE_ADO
;
195 case ::dbaccess::DST_ODBC
:
196 nNextState
= ADDITIONAL_PAGE_ODBC
;
199 nNextState
= WZS_INVALID_STATE
;
208 // -----------------------------------------------------------------------------
209 const SfxItemSet
* ODbTypeWizDialog::getOutputSet() const
213 // -----------------------------------------------------------------------------
214 SfxItemSet
* ODbTypeWizDialog::getWriteOutputSet()
218 // -----------------------------------------------------------------------------
219 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbTypeWizDialog::createConnection()
221 return m_pImpl
->createConnection();
223 // -----------------------------------------------------------------------------
224 Reference
< XComponentContext
> ODbTypeWizDialog::getORB() const
226 return m_pImpl
->getORB();
228 // -----------------------------------------------------------------------------
229 Reference
< XDriver
> ODbTypeWizDialog::getDriver()
231 return m_pImpl
->getDriver();
233 // -----------------------------------------------------------------------------
234 OUString
ODbTypeWizDialog::getDatasourceType(const SfxItemSet
& _rSet
) const
236 return m_pImpl
->getDatasourceType(_rSet
);
238 // -----------------------------------------------------------------------------
239 void ODbTypeWizDialog::clearPassword()
241 m_pImpl
->clearPassword();
244 // -----------------------------------------------------------------------------
245 TabPage
* ODbTypeWizDialog::createPage(WizardState _nState
)
247 sal_uInt16 nStringId
= STR_PAGETITLE_ADVANCED
;
248 TabPage
* pPage
= NULL
;
251 case START_PAGE
: // start state
253 pPage
= new OGeneralPageDialog(this,*m_pOutSet
);
254 OGeneralPage
* pGeneralPage
= static_cast< OGeneralPage
* >( pPage
);
255 pGeneralPage
->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog
, OnTypeSelected
));
256 nStringId
= STR_PAGETITLE_GENERAL
;
259 case CONNECTION_PAGE
:
260 pPage
= OConnectionTabPage::Create(this,*m_pOutSet
);
261 nStringId
= STR_PAGETITLE_CONNECTION
;
264 case ADDITIONAL_PAGE_DBASE
:
265 pPage
= ODriversSettings::CreateDbase(this,*m_pOutSet
);
267 case ADDITIONAL_PAGE_FLAT
:
268 pPage
= ODriversSettings::CreateText(this,*m_pOutSet
);
270 case ADDITIONAL_PAGE_LDAP
:
271 pPage
= ODriversSettings::CreateLDAP(this,*m_pOutSet
);
273 case ADDITIONAL_PAGE_MYSQL_JDBC
:
274 pPage
= ODriversSettings::CreateMySQLJDBC(this,*m_pOutSet
);
276 case ADDITIONAL_PAGE_MYSQL_NATIVE
:
277 pPage
= ODriversSettings::CreateMySQLNATIVE(this,*m_pOutSet
);
279 case ADDITIONAL_PAGE_MYSQL_ODBC
:
280 pPage
= ODriversSettings::CreateMySQLODBC(this,*m_pOutSet
);
282 case ADDITIONAL_PAGE_ORACLE_JDBC
:
283 pPage
= ODriversSettings::CreateOracleJDBC(this,*m_pOutSet
);
285 case ADDITIONAL_PAGE_ADO
:
286 pPage
= ODriversSettings::CreateAdo(this,*m_pOutSet
);
288 case ADDITIONAL_PAGE_ODBC
:
289 pPage
= ODriversSettings::CreateODBC(this,*m_pOutSet
);
291 case ADDITIONAL_USERDEFINED
:
292 pPage
= ODriversSettings::CreateUser(this,*m_pOutSet
);
295 OSL_FAIL("Wrong state!");
299 // register ourself as modified listener
302 static_cast<OGenericAdministrationPage
*>(pPage
)->SetServiceFactory( m_pImpl
->getORB() );
303 static_cast<OGenericAdministrationPage
*>(pPage
)->SetAdminDialog(this,this);
304 // open our own resource block, as the page titles are strings local to this block
305 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
307 pPage
->SetText(String(ModuleRes(nStringId
)));
308 defaultButton( _nState
== START_PAGE
? WZB_NEXT
: WZB_FINISH
);
309 enableButtons( WZB_FINISH
, _nState
== START_PAGE
? sal_False
: sal_True
);
314 // -----------------------------------------------------------------------------
315 sal_Bool
ODbTypeWizDialog::leaveState(WizardState _nState
)
317 SfxTabPage
* pPage
= static_cast<SfxTabPage
*>(WizardDialog::GetPage(_nState
));
319 pPage
->FillItemSet(*m_pOutSet
);
322 // -----------------------------------------------------------------------------
323 void ODbTypeWizDialog::setTitle(const OUString
& _sTitle
)
327 //-------------------------------------------------------------------------
328 void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable
)
330 enableButtons( WZB_FINISH
, _bEnable
);
332 // this is hacky. At the moment, this method is used in only one case.
333 // As soon as it is to be used more wide-spread, we should find a proper concept
334 // for enabling both the Next and Finish buttons, depending on the current page state.
335 // Plus, the concept must also care for the case where those pages are embedded into
336 // anormal tab dialog.
338 //-------------------------------------------------------------------------
339 sal_Bool
ODbTypeWizDialog::saveDatasource()
341 SfxTabPage
* pPage
= static_cast<SfxTabPage
*>(WizardDialog::GetPage(getCurrentState()));
343 pPage
->FillItemSet(*m_pOutSet
);
346 if ( m_pImpl
->getCurrentDataSource().is() )
347 m_pImpl
->getCurrentDataSource()->getPropertyValue(PROPERTY_URL
) >>= sOldURL
;
348 DataSourceInfoConverter::convert( getORB(), m_pCollection
,sOldURL
,m_eType
,m_pImpl
->getCurrentDataSource());
351 // -----------------------------------------------------------------------------
352 IWizardPageController
* ODbTypeWizDialog::getPageController( TabPage
* _pCurrentPage
) const
354 OGenericAdministrationPage
* pPage
= static_cast<OGenericAdministrationPage
*>(_pCurrentPage
);
357 // -----------------------------------------------------------------------------
358 sal_Bool
ODbTypeWizDialog::onFinish()
361 return m_pImpl
->saveChanges(*m_pOutSet
) ? OWizardMachine::onFinish() : sal_False
;
363 //.........................................................................
365 //.........................................................................
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */