LibreOffice Module dbaccess (master) 1
dbwiz.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <core_resource.hxx>
21#include <dbwiz.hxx>
22#include <strings.hrc>
23#include <strings.hxx>
24#include <dsitems.hxx>
25#include "dsnItem.hxx"
26#include "adminpages.hxx"
27#include "generalpage.hxx"
29#include "ConnectionPage.hxx"
30#include "DriverSettings.hxx"
31#include "DbAdminImpl.hxx"
32#include <helpids.h>
33
34namespace dbaui
35{
36using namespace com::sun::star::uno;
37using namespace com::sun::star::sdbc;
38using namespace com::sun::star::lang;
39using namespace com::sun::star::util;
40using namespace com::sun::star::beans;
41using namespace com::sun::star::container;
42
43#define START_PAGE 0
44#define CONNECTION_PAGE 1
45#define ADDITIONAL_PAGE_DBASE 2
46#define ADDITIONAL_PAGE_FLAT 3
47#define ADDITIONAL_PAGE_LDAP 4
48//5 was ADDITIONAL_PAGE_ADABAS
49#define ADDITIONAL_PAGE_MYSQL_JDBC 6
50#define ADDITIONAL_PAGE_MYSQL_ODBC 7
51#define ADDITIONAL_PAGE_ORACLE_JDBC 8
52#define ADDITIONAL_PAGE_ADO 9
53#define ADDITIONAL_PAGE_ODBC 10
54#define ADDITIONAL_USERDEFINED 11
55#define ADDITIONAL_PAGE_MYSQL_NATIVE 12
56
57// ODbTypeWizDialog
59 const Reference< XComponentContext >& _rxORB, const css::uno::Any& _aDataSourceName)
61{
62 m_pImpl.reset(new ODbDataSourceAdministrationHelper(_rxORB, m_xAssistant.get(), _pParent, this));
63 m_pImpl->setDataSourceOrName(_aDataSourceName);
64 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
65 m_pOutSet.reset(new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() ));
66
67 m_pImpl->translateProperties(xDatasource, *m_pOutSet);
69
70 defaultButton(WizardButtonFlags::NEXT);
71 enableButtons(WizardButtonFlags::FINISH, false);
73
74 m_xPrevPage->set_help_id(HID_DBWIZ_PREVIOUS);
75 m_xNextPage->set_help_id(HID_DBWIZ_NEXT);
76 m_xCancel->set_help_id(HID_DBWIZ_CANCEL);
77 m_xFinish->set_help_id(HID_DBWIZ_FINISH);
78 // no local resources needed anymore
79
80 const DbuTypeCollectionItem* pCollectionItem = dynamic_cast<const DbuTypeCollectionItem*>(_pItems->GetItem(DSID_TYPECOLLECTION));
81 assert(pCollectionItem && "must exist");
82 m_pCollection = pCollectionItem->getCollection();
83
85 setTitleBase(DBA_RES(STR_DATABASE_TYPE_CHANGE));
86
87 m_xAssistant->set_current_page(0);
88}
89
91{
92}
93
94IMPL_LINK(ODbTypeWizDialog, OnTypeSelected, OGeneralPage&, _rTabPage, void)
95{
96 m_eType = _rTabPage.GetSelectedType();
97 const bool bURLRequired = m_pCollection->isConnectionUrlRequired(m_eType);
98 enableButtons(WizardButtonFlags::NEXT,bURLRequired);
99 enableButtons(WizardButtonFlags::FINISH,!bURLRequired);
100}
101
103{
104 WizardState nNextState = WZS_INVALID_STATE;
105 switch(_nCurrentState)
106 {
107 case START_PAGE:
109 {
118 nNextState = WZS_INVALID_STATE;
119 break;
121 nNextState = ADDITIONAL_PAGE_MYSQL_NATIVE;
122 break;
123 default:
124 nNextState = CONNECTION_PAGE;
125 break;
126 }
127 break;
128 case CONNECTION_PAGE:
130 {
145 nNextState = WZS_INVALID_STATE;
146 break;
148 nNextState = ADDITIONAL_PAGE_DBASE;
149 break;
151 nNextState = ADDITIONAL_PAGE_FLAT;
152 break;
154 nNextState = ADDITIONAL_PAGE_LDAP;
155 break;
157 nNextState = ADDITIONAL_PAGE_MYSQL_JDBC;
158 break;
160 nNextState = ADDITIONAL_PAGE_MYSQL_ODBC;
161 break;
163 nNextState = ADDITIONAL_PAGE_ORACLE_JDBC;
164 break;
166 nNextState = ADDITIONAL_PAGE_ADO;
167 break;
169 nNextState = ADDITIONAL_PAGE_ODBC;
170 break;
171 default:
172 nNextState = WZS_INVALID_STATE;
173 break;
174 }
175 break;
176 }
177
178 return nNextState;
179}
180
182{
183 return m_pOutSet.get();
184}
185
187{
188 return m_pOutSet.get();
189}
190
191std::pair< Reference<XConnection>,bool> ODbTypeWizDialog::createConnection()
192{
193 return m_pImpl->createConnection();
194}
195
197{
198 return m_pImpl->getORB();
199}
200
202{
203 return m_pImpl->getDriver();
204}
205
207{
209}
210
212{
213 m_pImpl->clearPassword();
214}
215
216std::unique_ptr<BuilderPage> ODbTypeWizDialog::createPage(WizardState _nState)
217{
218 TranslateId pStringId = STR_PAGETITLE_ADVANCED;
219 std::unique_ptr<BuilderPage> xPage;
220
221 OUString sIdent(OUString::number(_nState));
222 weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
223
224 switch(_nState)
225 {
226 case START_PAGE: // start state
227 {
228 xPage = std::make_unique<OGeneralPageDialog>(pPageContainer, this, *m_pOutSet);
229 OGeneralPage* pGeneralPage = static_cast<OGeneralPage*>(xPage.get());
230 pGeneralPage->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog, OnTypeSelected));
231 pStringId = STR_PAGETITLE_GENERAL;
232 }
233 break;
234 case CONNECTION_PAGE:
235 xPage = OConnectionTabPage::Create(pPageContainer, this, m_pOutSet.get());
236 pStringId = STR_PAGETITLE_CONNECTION;
237 break;
238
240 xPage = ODriversSettings::CreateDbase(pPageContainer, this, m_pOutSet.get());
241 break;
243 xPage = ODriversSettings::CreateText(pPageContainer, this, m_pOutSet.get());
244 break;
246 xPage = ODriversSettings::CreateLDAP(pPageContainer, this, m_pOutSet.get());
247 break;
249 xPage = ODriversSettings::CreateMySQLJDBC(pPageContainer, this, m_pOutSet.get());
250 break;
252 xPage = ODriversSettings::CreateMySQLNATIVE(pPageContainer, this, m_pOutSet.get());
253 break;
255 xPage = ODriversSettings::CreateMySQLODBC(pPageContainer, this, m_pOutSet.get());
256 break;
258 xPage = ODriversSettings::CreateOracleJDBC(pPageContainer, this, m_pOutSet.get());
259 break;
261 xPage = ODriversSettings::CreateAdo(pPageContainer, this, m_pOutSet.get());
262 break;
264 xPage = ODriversSettings::CreateODBC(pPageContainer, this, m_pOutSet.get());
265 break;
267 xPage = ODriversSettings::CreateUser(pPageContainer, this, m_pOutSet.get());
268 break;
269 default:
270 OSL_FAIL("Wrong state!");
271 break;
272 }
273
274 // register ourself as modified listener
275 if ( xPage )
276 {
277 static_cast<OGenericAdministrationPage*>(xPage.get())->SetServiceFactory( m_pImpl->getORB() );
278 static_cast<OGenericAdministrationPage*>(xPage.get())->SetAdminDialog(this,this);
279 m_xAssistant->set_page_title(sIdent, DBA_RES(pStringId));
280 defaultButton( _nState == START_PAGE ? WizardButtonFlags::NEXT : WizardButtonFlags::FINISH );
281 enableButtons( WizardButtonFlags::FINISH, _nState != START_PAGE);
282 }
283 return xPage;
284}
285
287{
288 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardMachine::GetPage(_nState));
289 if ( pPage )
290 pPage->FillItemSet(m_pOutSet.get());
291 return true;
292}
293
294void ODbTypeWizDialog::setTitle(const OUString& _sTitle)
295{
296 m_xAssistant->set_title(_sTitle);
297}
298
300{
301 enableButtons( WizardButtonFlags::FINISH, _bEnable );
302 // TODO:
303 // this is hacky. At the moment, this method is used in only one case.
304 // As soon as it is to be used more wide-spread, we should find a proper concept
305 // for enabling both the Next and Finish buttons, depending on the current page state.
306 // Plus, the concept must also care for the case where those pages are embedded into
307 // a normal tab dialog.
308}
309
311{
313 if ( pPage )
314 pPage->FillItemSet(m_pOutSet.get());
315
316 OUString sOldURL;
317 if ( m_pImpl->getCurrentDataSource().is() )
318 m_pImpl->getCurrentDataSource()->getPropertyValue(PROPERTY_URL) >>= sOldURL;
319 DataSourceInfoConverter::convert( getORB(), m_pCollection,sOldURL,m_eType,m_pImpl->getCurrentDataSource());
320}
321
322vcl::IWizardPageController* ODbTypeWizDialog::getPageController(BuilderPage* pCurrentPage) const
323{
324 OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(pCurrentPage);
325 return pPage;
326}
327
329{
331 return m_pImpl->saveChanges(*m_pOutSet) && WizardMachine::onFinish();
332}
333
334} // namespace dbaui
335
336/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const WhichRangesContainer & GetRanges() const
SfxItemPool * GetPool() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
virtual bool FillItemSet(SfxItemSet *)
DATASOURCE_TYPE determineType(std::u16string_view _rDsn) const
Definition: dsntypes.cxx:299
allows an ODsnTypeCollection to be transported in an SfxItemSet
Definition: dsnItem.hxx:34
::dbaccess::ODsnTypeCollection * getCollection() const
Definition: dsnItem.hxx:44
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
static OUString getDatasourceType(const SfxItemSet &_rSet)
extracts the connection type from the given setThe connection type is determined by the value of the ...
tab dialog for administrating the office wide registered data sources
Definition: dbwiz.hxx:54
OUString m_eType
the DSN type collection instance
Definition: dbwiz.hxx:60
::dbaccess::ODsnTypeCollection * m_pCollection
Definition: dbwiz.hxx:59
virtual css::uno::Reference< css::sdbc::XDriver > getDriver() override
Definition: dbwiz.cxx:201
virtual bool onFinish() override
Definition: dbwiz.cxx:328
virtual void clearPassword() override
Definition: dbwiz.cxx:211
std::unique_ptr< SfxItemSet > m_pOutSet
Definition: dbwiz.hxx:57
virtual WizardState determineNextState(WizardState _nCurrentState) const override
Definition: dbwiz.cxx:102
virtual ::vcl::IWizardPageController * getPageController(BuilderPage *pCurrentPage) const override
Definition: dbwiz.cxx:322
virtual OUString getDatasourceType(const SfxItemSet &_rSet) const override
Definition: dbwiz.cxx:206
ODbTypeWizDialog(weld::Window *pParent, SfxItemSet const *_pItems, const css::uno::Reference< css::uno::XComponentContext > &_rxORB, const css::uno::Any &_aDataSourceName)
ctor.
Definition: dbwiz.cxx:58
virtual bool leaveState(WizardState _nState) override
Definition: dbwiz.cxx:286
virtual css::uno::Reference< css::uno::XComponentContext > getORB() const override
Definition: dbwiz.cxx:196
virtual void saveDatasource() override
Definition: dbwiz.cxx:310
virtual ~ODbTypeWizDialog() override
Definition: dbwiz.cxx:90
virtual void enableConfirmSettings(bool _bEnable) override
enables or disables the user's possibility to confirm the settings
Definition: dbwiz.cxx:299
virtual std::pair< css::uno::Reference< css::sdbc::XConnection >, bool > createConnection() override
Definition: dbwiz.cxx:191
virtual const SfxItemSet * getOutputSet() const override
Definition: dbwiz.cxx:181
std::unique_ptr< ODbDataSourceAdministrationHelper > m_pImpl
Definition: dbwiz.hxx:56
virtual void setTitle(const OUString &_sTitle) override
Definition: dbwiz.cxx:294
virtual SfxItemSet * getWriteOutputSet() override
Definition: dbwiz.cxx:186
virtual std::unique_ptr< BuilderPage > createPage(WizardState _nState) override
to override to create new pages
Definition: dbwiz.cxx:216
static std::unique_ptr< SfxTabPage > CreateMySQLODBC(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for MySQLODBC.
static std::unique_ptr< SfxTabPage > CreateLDAP(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for LDAP.
static std::unique_ptr< SfxTabPage > CreateODBC(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for ODBC.
static std::unique_ptr< SfxTabPage > CreateText(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for Text.
static std::unique_ptr< SfxTabPage > CreateAdo(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for ado.
static std::unique_ptr< SfxTabPage > CreateOracleJDBC(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for Oracle JDBC.
static std::unique_ptr< SfxTabPage > CreateDbase(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for ado.
static std::unique_ptr< SfxTabPage > CreateMySQLJDBC(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for MySQLJDBC.
static std::unique_ptr< SfxTabPage > CreateMySQLNATIVE(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for MySQLNATIVE.
static std::unique_ptr< SfxTabPage > CreateUser(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
Creates the detail page for user.
void SetTypeSelectHandler(const Link< OGeneralPage &, void > &_rHandler)
set a handler which gets called every time the user selects a new type
Definition: generalpage.hxx:65
std::unique_ptr< weld::Button > m_xNextPage
std::unique_ptr< weld::Button > m_xCancel
virtual bool onFinish()
void defaultButton(WizardButtonFlags _nWizardButtonFlags)
void enableAutomaticNextButtonState()
std::unique_ptr< weld::Button > m_xPrevPage
virtual void ActivatePage()
void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
std::unique_ptr< weld::Button > m_xFinish
WizardTypes::WizardState getCurrentState() const
void setTitleBase(const OUString &_rTitleBase)
BuilderPage * GetPage(WizardTypes::WizardState eState) const
std::unique_ptr< weld::Assistant > m_xAssistant
#define DBA_RES(id)
#define CONNECTION_PAGE
Definition: dbwiz.cxx:44
#define ADDITIONAL_PAGE_DBASE
Definition: dbwiz.cxx:45
#define ADDITIONAL_PAGE_MYSQL_JDBC
Definition: dbwiz.cxx:49
#define ADDITIONAL_PAGE_ADO
Definition: dbwiz.cxx:52
#define ADDITIONAL_PAGE_ORACLE_JDBC
Definition: dbwiz.cxx:51
#define ADDITIONAL_USERDEFINED
Definition: dbwiz.cxx:54
#define ADDITIONAL_PAGE_FLAT
Definition: dbwiz.cxx:46
#define ADDITIONAL_PAGE_LDAP
Definition: dbwiz.cxx:47
#define START_PAGE
Definition: dbwiz.cxx:43
#define ADDITIONAL_PAGE_MYSQL_NATIVE
Definition: dbwiz.cxx:55
#define ADDITIONAL_PAGE_ODBC
Definition: dbwiz.cxx:53
#define ADDITIONAL_PAGE_MYSQL_ODBC
Definition: dbwiz.cxx:50
#define DSID_TYPECOLLECTION
Definition: dsitems.hxx:38
const EnumerationType m_eType
constexpr OUStringLiteral HID_DBWIZ_NEXT
Definition: helpids.h:104
constexpr OUStringLiteral HID_DBWIZ_CANCEL
Definition: helpids.h:105
constexpr OUStringLiteral HID_DBWIZ_PREVIOUS
Definition: helpids.h:103
constexpr OUStringLiteral HID_DBWIZ_FINISH
Definition: helpids.h:106
@ DST_MSACCESS_2007
Definition: dsntypes.hxx:58
@ DST_MYSQL_JDBC
Definition: dsntypes.hxx:39
@ DST_CALC
Definition: dsntypes.hxx:42
@ DST_WRITER
Definition: dsntypes.hxx:65
@ DST_MOZILLA
Definition: dsntypes.hxx:48
@ DST_EVOLUTION
Definition: dsntypes.hxx:53
@ DST_MSACCESS
Definition: dsntypes.hxx:37
@ DST_MYSQL_ODBC
Definition: dsntypes.hxx:38
@ DST_JDBC
Definition: dsntypes.hxx:45
@ DST_ODBC
Definition: dsntypes.hxx:46
@ DST_MYSQL_NATIVE
Definition: dsntypes.hxx:60
@ DST_LDAP
Definition: dsntypes.hxx:50
@ DST_DBASE
Definition: dsntypes.hxx:43
@ DST_FLAT
Definition: dsntypes.hxx:44
@ DST_OUTLOOKEXP
Definition: dsntypes.hxx:52
@ DST_ORACLE_JDBC
Definition: dsntypes.hxx:40
@ DST_EVOLUTION_GROUPWISE
Definition: dsntypes.hxx:54
@ DST_OUTLOOK
Definition: dsntypes.hxx:51
@ DST_EVOLUTION_LDAP
Definition: dsntypes.hxx:55
@ DST_THUNDERBIRD
Definition: dsntypes.hxx:49
@ DST_MACAB
Definition: dsntypes.hxx:57
void convert(const css::uno::Reference< css::uno::XComponentContext > &xContext, const ::dbaccess::ODsnTypeCollection *_pCollection, std::u16string_view _sOldURLPrefix, std::u16string_view _sNewURLPrefix, const css::uno::Reference< css::beans::XPropertySet > &_xDatasource)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
PREVIOUS
sal_Int16 WizardState
constexpr OUStringLiteral PROPERTY_URL(u"URL")
NEXT
WizardButtonFlags
#define WZS_INVALID_STATE