Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / dlg / dbwiz.cxx
blob950e3a567d4241515e85fc9a656167954b8617bd
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 ************************************************************************/
30 #include "dbwiz.hxx"
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 //.........................................................................
52 namespace dbaui
54 //.........................................................................
55 using namespace svt;
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;
63 #define START_PAGE 0
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 //=========================================================================
80 //= ODbTypeWizDialog
81 //=========================================================================
82 //-------------------------------------------------------------------------
83 ODbTypeWizDialog::ODbTypeWizDialog(Window* _pParent
84 ,SfxItemSet* _pItems
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 )
89 ,m_pOutSet(NULL)
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();
119 FreeResource();
120 ActivatePage();
123 //-------------------------------------------------------------------------
124 ODbTypeWizDialog::~ODbTypeWizDialog()
126 DBG_DTOR(ODbTypeWizDialog,NULL);
127 delete m_pOutSet;
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);
136 return 1L;
138 //-------------------------------------------------------------------------
139 WizardTypes::WizardState ODbTypeWizDialog::determineNextState( WizardState _nCurrentState ) const
141 WizardTypes::WizardState nNextState = WZS_INVALID_STATE;
142 switch(_nCurrentState)
144 case START_PAGE:
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;
156 break;
157 case ::dbaccess::DST_MYSQL_NATIVE:
158 nNextState = ADDITIONAL_PAGE_MYSQL_NATIVE;
159 break;
160 default:
161 nNextState = CONNECTION_PAGE;
162 break;
164 break;
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;
182 break;
183 case ::dbaccess::DST_DBASE:
184 nNextState = ADDITIONAL_PAGE_DBASE;
185 break;
186 case ::dbaccess::DST_FLAT:
187 nNextState = ADDITIONAL_PAGE_FLAT;
188 break;
189 case ::dbaccess::DST_LDAP:
190 nNextState = ADDITIONAL_PAGE_LDAP;
191 break;
192 case ::dbaccess::DST_MYSQL_JDBC:
193 nNextState = ADDITIONAL_PAGE_MYSQL_JDBC;
194 break;
195 case ::dbaccess::DST_MYSQL_ODBC:
196 nNextState = ADDITIONAL_PAGE_MYSQL_ODBC;
197 break;
198 case ::dbaccess::DST_ORACLE_JDBC:
199 nNextState = ADDITIONAL_PAGE_ORACLE_JDBC;
200 break;
201 case ::dbaccess::DST_ADO:
202 nNextState = ADDITIONAL_PAGE_ADO;
203 break;
204 case ::dbaccess::DST_ODBC:
205 nNextState = ADDITIONAL_PAGE_ODBC;
206 break;
207 default:
208 nNextState = WZS_INVALID_STATE;
209 break;
211 break;
214 return nNextState;
217 // -----------------------------------------------------------------------------
218 const SfxItemSet* ODbTypeWizDialog::getOutputSet() const
220 return m_pOutSet;
222 // -----------------------------------------------------------------------------
223 SfxItemSet* ODbTypeWizDialog::getWriteOutputSet()
225 return m_pOutSet;
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;
258 switch(_nState)
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;
268 break;
269 case CONNECTION_PAGE:
270 pPage = OConnectionTabPage::Create(this,*m_pOutSet);
271 nStringId = STR_PAGETITLE_CONNECTION;
272 break;
274 case ADDITIONAL_PAGE_DBASE:
275 pPage = ODriversSettings::CreateDbase(this,*m_pOutSet);
276 break;
277 case ADDITIONAL_PAGE_FLAT:
278 pPage = ODriversSettings::CreateText(this,*m_pOutSet);
279 break;
280 case ADDITIONAL_PAGE_LDAP:
281 pPage = ODriversSettings::CreateLDAP(this,*m_pOutSet);
282 break;
283 case ADDITIONAL_PAGE_MYSQL_JDBC:
284 pPage = ODriversSettings::CreateMySQLJDBC(this,*m_pOutSet);
285 break;
286 case ADDITIONAL_PAGE_MYSQL_NATIVE:
287 pPage = ODriversSettings::CreateMySQLNATIVE(this,*m_pOutSet);
288 break;
289 case ADDITIONAL_PAGE_MYSQL_ODBC:
290 pPage = ODriversSettings::CreateMySQLODBC(this,*m_pOutSet);
291 break;
292 case ADDITIONAL_PAGE_ORACLE_JDBC:
293 pPage = ODriversSettings::CreateOracleJDBC(this,*m_pOutSet);
294 break;
295 case ADDITIONAL_PAGE_ADO:
296 pPage = ODriversSettings::CreateAdo(this,*m_pOutSet);
297 break;
298 case ADDITIONAL_PAGE_ODBC:
299 pPage = ODriversSettings::CreateODBC(this,*m_pOutSet);
300 break;
301 case ADDITIONAL_USERDEFINED:
302 pPage = ODriversSettings::CreateUser(this,*m_pOutSet);
303 break;
304 default:
305 OSL_FAIL("Wrong state!");
306 break;
309 // register ourself as modified listener
310 if ( pPage )
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);
320 pPage->Show();
322 return pPage;
324 // -----------------------------------------------------------------------------
325 sal_Bool ODbTypeWizDialog::leaveState(WizardState _nState)
327 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
328 if ( pPage )
329 pPage->FillItemSet(*m_pOutSet);
330 return sal_True;
332 // -----------------------------------------------------------------------------
333 void ODbTypeWizDialog::setTitle(const ::rtl::OUString& _sTitle)
335 SetText(_sTitle);
337 //-------------------------------------------------------------------------
338 void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable )
340 enableButtons( WZB_FINISH, _bEnable );
341 // TODO:
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()));
352 if ( pPage )
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());
360 return sal_True;
362 // -----------------------------------------------------------------------------
363 IWizardPageController* ODbTypeWizDialog::getPageController( TabPage* _pCurrentPage ) const
365 OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
366 return pPage;
368 // -----------------------------------------------------------------------------
369 sal_Bool ODbTypeWizDialog::onFinish()
371 saveDatasource();
372 return m_pImpl->saveChanges(*m_pOutSet) ? OWizardMachine::onFinish() : sal_False;
374 //.........................................................................
375 } // namespace dbaui
376 //.........................................................................
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */