xref: /trunk/main/dbaccess/source/ui/dlg/dbwiz.cxx (revision 96de5490)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 
27 #ifndef DBAUI_DBWIZ_HXX
28 #include "dbwiz.hxx"
29 #endif
30 #ifndef _DBAUI_DBADMIN_HRC_
31 #include "dbadmin.hrc"
32 #endif
33 #ifndef _DBU_DLG_HRC_
34 #include "dbu_dlg.hrc"
35 #endif
36 #ifndef _DBAUI_DATASOURCEITEMS_HXX_
37 #include "dsitems.hxx"
38 #endif
39 #include "dsnItem.hxx"
40 #ifndef _SFXSTRITEM_HXX
41 #include <svl/stritem.hxx>
42 #endif
43 #ifndef _SFXENUMITEM_HXX
44 #include <svl/eitem.hxx>
45 #endif
46 #ifndef _SFXINTITEM_HXX
47 #include <svl/intitem.hxx>
48 #endif
49 #ifndef _SV_MSGBOX_HXX
50 #include <vcl/msgbox.hxx>
51 #endif
52 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
53 #include "dbustrings.hrc"
54 #endif
55 #ifndef _DBAUI_ADMINPAGES_HXX_
56 #include "adminpages.hxx"
57 #endif
58 #ifndef _DBAUI_GENERALPAGE_HXX_
59 #include "generalpage.hxx"
60 #endif
61 #ifndef _DBAUI_LOCALRESACCESS_HXX_
62 #include "localresaccess.hxx"
63 #endif
64 #ifndef _DBAUI_STRINGLISTITEM_HXX_
65 #include "stringlistitem.hxx"
66 #endif
67 #ifndef _DBAUI_PROPERTYSETITEM_HXX_
68 #include "propertysetitem.hxx"
69 #endif
70 #ifndef _UNOTOOLS_CONFIGNODE_HXX_
71 #include <unotools/confignode.hxx>
72 #endif
73 #ifndef DBAUI_CONNECTIONPAGE_HXX
74 #include "ConnectionPage.hxx"
75 #endif
76 #ifndef DBAUI_DRIVERSETTINGS_HXX
77 #include "DriverSettings.hxx"
78 #endif
79 #ifndef _DBAUI_DBADMINIMPL_HXX_
80 #include "DbAdminImpl.hxx"
81 #endif
82 #ifndef _DBA_DBACCESS_HELPID_HRC_
83 #include "dbaccess_helpid.hrc"
84 #endif
85 
86 //.........................................................................
87 namespace dbaui
88 {
89 //.........................................................................
90 using namespace svt;
91 using namespace com::sun::star::uno;
92 using namespace com::sun::star::sdbc;
93 using namespace com::sun::star::lang;
94 using namespace com::sun::star::util;
95 using namespace com::sun::star::beans;
96 using namespace com::sun::star::container;
97 
98 #define START_PAGE			            0
99 #define CONNECTION_PAGE		            1
100 #define ADDITIONAL_PAGE_DBASE     		2
101 #define ADDITIONAL_PAGE_FLAT            3
102 #define ADDITIONAL_PAGE_LDAP            4
103 #define ADDITIONAL_PAGE_ADABAS          5
104 #define ADDITIONAL_PAGE_MYSQL_JDBC      6
105 #define ADDITIONAL_PAGE_MYSQL_ODBC	    7
106 #define ADDITIONAL_PAGE_ORACLE_JDBC     8
107 #define ADDITIONAL_PAGE_ADO             9
108 #define ADDITIONAL_PAGE_ODBC           10
109 #define ADDITIONAL_USERDEFINED         11
110 #define ADDITIONAL_PAGE_MYSQL_NATIVE   12
111 
112 
113 DBG_NAME(ODbTypeWizDialog)
114 //=========================================================================
115 //= ODbTypeWizDialog
116 //=========================================================================
117 //-------------------------------------------------------------------------
118 ODbTypeWizDialog::ODbTypeWizDialog(Window* _pParent
119 							   ,SfxItemSet* _pItems
120 							   ,const Reference< XMultiServiceFactory >& _rxORB
121 							   ,const ::com::sun::star::uno::Any& _aDataSourceName
122 							   )
123 	:OWizardMachine(_pParent, ModuleRes(DLG_DATABASE_TYPE_CHANGE), WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP )
124 	,m_pOutSet(NULL)
125 	,m_bResetting(sal_False)
126 	,m_bApplied(sal_False)
127 	,m_bUIEnabled( sal_True )
128 {
129 	DBG_CTOR(ODbTypeWizDialog,NULL);
130 	m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,this,this));
131 	m_pImpl->setDataSourceOrName(_aDataSourceName);
132 	Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
133 	m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() );
134 
135 	m_pImpl->translateProperties(xDatasource, *m_pOutSet);
136 	m_eType = m_pImpl->getDatasourceType(*m_pOutSet);
137 
138 	SetPageSizePixel(LogicToPixel(::Size(PAGE_X, PAGE_Y), MAP_APPFONT));
139 	ShowButtonFixedLine(sal_True);
140 	defaultButton(WZB_NEXT);
141 	enableButtons(WZB_FINISH, sal_False);
142     enableAutomaticNextButtonState( true );
143 
144     m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS);
145 	m_pNextPage->SetHelpId(HID_DBWIZ_NEXT);
146 	m_pCancel->SetHelpId(HID_DBWIZ_CANCEL);
147 	m_pFinish->SetHelpId(HID_DBWIZ_FINISH);
148 	m_pHelp->SetUniqueId(UID_DBWIZ_HELP);
149 	// no local resources needed anymore
150 
151     DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION));
152 	m_pCollection = pCollectionItem->getCollection();
153 
154 	FreeResource();
155 	ActivatePage();
156 }
157 
158 //-------------------------------------------------------------------------
159 ODbTypeWizDialog::~ODbTypeWizDialog()
160 {
161 	DBG_DTOR(ODbTypeWizDialog,NULL);
162 	delete m_pOutSet;
163 }
164 //-------------------------------------------------------------------------
165 IMPL_LINK(ODbTypeWizDialog, OnTypeSelected, OGeneralPage*, _pTabPage)
166 {
167     m_eType = _pTabPage->GetSelectedType();
168     const bool bURLRequired = m_pCollection->isConnectionUrlRequired(m_eType);
169     enableButtons(WZB_NEXT,bURLRequired);
170 	enableButtons(WZB_FINISH,!bURLRequired);
171 	return 1L;
172 }
173 //-------------------------------------------------------------------------
174 WizardTypes::WizardState ODbTypeWizDialog::determineNextState( WizardState _nCurrentState ) const
175 {
176 	WizardTypes::WizardState nNextState = WZS_INVALID_STATE;
177 	switch(_nCurrentState)
178 	{
179 		case START_PAGE:
180             switch(m_pCollection->determineType(m_eType))
181 			{
182 				case  ::dbaccess::DST_MOZILLA:
183 				case  ::dbaccess::DST_OUTLOOK:
184 				case  ::dbaccess::DST_OUTLOOKEXP:
185 				case  ::dbaccess::DST_EVOLUTION:
186 				case  ::dbaccess::DST_EVOLUTION_GROUPWISE:
187 				case  ::dbaccess::DST_EVOLUTION_LDAP:
188 				case  ::dbaccess::DST_KAB:
189 				case  ::dbaccess::DST_MACAB:
190 					nNextState = WZS_INVALID_STATE;
191 					break;
192 				case  ::dbaccess::DST_MYSQL_NATIVE:
193                     nNextState = ADDITIONAL_PAGE_MYSQL_NATIVE;
194                     break;
195                 default:
196 			        nNextState = CONNECTION_PAGE;
197                     break;
198             }
199 			break;
200 		case CONNECTION_PAGE:
201 			switch(m_pCollection->determineType(m_eType))
202 			{
203                 case  ::dbaccess::DST_MOZILLA:
204                 case  ::dbaccess::DST_THUNDERBIRD:
205 				case  ::dbaccess::DST_OUTLOOK:
206 				case  ::dbaccess::DST_OUTLOOKEXP:
207 				case  ::dbaccess::DST_EVOLUTION:
208 				case  ::dbaccess::DST_EVOLUTION_GROUPWISE:
209 				case  ::dbaccess::DST_EVOLUTION_LDAP:
210 				case  ::dbaccess::DST_KAB:
211 				case  ::dbaccess::DST_MACAB:
212 				case  ::dbaccess::DST_MSACCESS:
213                 case  ::dbaccess::DST_MSACCESS_2007:
214 				case  ::dbaccess::DST_JDBC:
215 				case  ::dbaccess::DST_CALC:
216 					nNextState = WZS_INVALID_STATE;
217 					break;
218                 case  ::dbaccess::DST_DBASE:
219                     nNextState = ADDITIONAL_PAGE_DBASE;
220                     break;
221                 case  ::dbaccess::DST_FLAT:
222                     nNextState = ADDITIONAL_PAGE_FLAT;
223                     break;
224                 case  ::dbaccess::DST_LDAP:
225                     nNextState = ADDITIONAL_PAGE_LDAP;
226                     break;
227                 case  ::dbaccess::DST_ADABAS:
228                     nNextState = ADDITIONAL_PAGE_ADABAS;
229                     break;
230                 case  ::dbaccess::DST_MYSQL_JDBC:
231                     nNextState = ADDITIONAL_PAGE_MYSQL_JDBC;
232                     break;
233                 case  ::dbaccess::DST_MYSQL_ODBC:
234                     nNextState = ADDITIONAL_PAGE_MYSQL_ODBC;
235                     break;
236                 case  ::dbaccess::DST_ORACLE_JDBC:
237                     nNextState = ADDITIONAL_PAGE_ORACLE_JDBC;
238                     break;
239                 case  ::dbaccess::DST_ADO:
240                     nNextState = ADDITIONAL_PAGE_ADO;
241                     break;
242                 case  ::dbaccess::DST_ODBC:
243                     nNextState = ADDITIONAL_PAGE_ODBC;
244                     break;
245 				default:
246 					nNextState = WZS_INVALID_STATE;
247 					break;
248 			}
249 			break;
250 	}
251 
252 	return nNextState;
253 }
254 
255 // -----------------------------------------------------------------------------
256 const SfxItemSet* ODbTypeWizDialog::getOutputSet() const
257 {
258 	return m_pOutSet;
259 }
260 // -----------------------------------------------------------------------------
261 SfxItemSet* ODbTypeWizDialog::getWriteOutputSet()
262 {
263 	return m_pOutSet;
264 }
265 // -----------------------------------------------------------------------------
266 ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialog::createConnection()
267 {
268 	return m_pImpl->createConnection();
269 }
270 // -----------------------------------------------------------------------------
271 Reference< XMultiServiceFactory > ODbTypeWizDialog::getORB() const
272 {
273 	return m_pImpl->getORB();
274 }
275 // -----------------------------------------------------------------------------
276 Reference< XDriver > ODbTypeWizDialog::getDriver()
277 {
278 	return m_pImpl->getDriver();
279 }
280 // -----------------------------------------------------------------------------
281 ::rtl::OUString	ODbTypeWizDialog::getDatasourceType(const SfxItemSet& _rSet) const
282 {
283 	return m_pImpl->getDatasourceType(_rSet);
284 }
285 // -----------------------------------------------------------------------------
286 void ODbTypeWizDialog::clearPassword()
287 {
288 	m_pImpl->clearPassword();
289 }
290 
291 // -----------------------------------------------------------------------------
292 TabPage* ODbTypeWizDialog::createPage(WizardState _nState)
293 {
294 	sal_uInt16 nStringId = STR_PAGETITLE_ADVANCED;
295 	TabPage* pPage = NULL;
296 	switch(_nState)
297 	{
298 		case START_PAGE: // start state
299         {
300 			pPage = OGeneralPage::Create(this,*m_pOutSet);
301             OGeneralPage* pGeneralPage = static_cast< OGeneralPage* >( pPage );
302 			pGeneralPage->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog, OnTypeSelected));
303 //            pGeneralPage->SetCreationModeHandler( LINK( this, ODbTypeWizDialog, TODO ) );
304 			nStringId = STR_PAGETITLE_GENERAL;
305         }
306 		break;
307 		case CONNECTION_PAGE:
308 			pPage = OConnectionTabPage::Create(this,*m_pOutSet);
309 			nStringId = STR_PAGETITLE_CONNECTION;
310 			break;
311 
312         case ADDITIONAL_PAGE_DBASE:
313 			pPage = ODriversSettings::CreateDbase(this,*m_pOutSet);
314             break;
315         case ADDITIONAL_PAGE_FLAT:
316 			pPage = ODriversSettings::CreateText(this,*m_pOutSet);
317             break;
318         case ADDITIONAL_PAGE_LDAP:
319 			pPage = ODriversSettings::CreateLDAP(this,*m_pOutSet);
320             break;
321         case ADDITIONAL_PAGE_ADABAS:
322             pPage = ODriversSettings::CreateAdabas(this,*m_pOutSet);
323             break;
324         case ADDITIONAL_PAGE_MYSQL_JDBC:
325             pPage = ODriversSettings::CreateMySQLJDBC(this,*m_pOutSet);
326             break;
327         case ADDITIONAL_PAGE_MYSQL_NATIVE:
328             pPage = ODriversSettings::CreateMySQLNATIVE(this,*m_pOutSet);
329             break;
330         case ADDITIONAL_PAGE_MYSQL_ODBC:
331             pPage = ODriversSettings::CreateMySQLODBC(this,*m_pOutSet);
332             break;
333         case ADDITIONAL_PAGE_ORACLE_JDBC:
334             pPage = ODriversSettings::CreateOracleJDBC(this,*m_pOutSet);
335             break;
336         case ADDITIONAL_PAGE_ADO:
337 			pPage = ODriversSettings::CreateAdo(this,*m_pOutSet);
338             break;
339         case ADDITIONAL_PAGE_ODBC:
340 			pPage = ODriversSettings::CreateODBC(this,*m_pOutSet);
341             break;
342         case ADDITIONAL_USERDEFINED:
343 			pPage = ODriversSettings::CreateUser(this,*m_pOutSet);
344 			break;
345 		default:
346 			OSL_ENSURE(0,"Wrong state!");
347 			break;
348 	}
349 
350 	// register ourself as modified listener
351 	if ( pPage )
352 	{
353 		static_cast<OGenericAdministrationPage*>(pPage)->SetServiceFactory(m_pImpl->getORB());
354 		static_cast<OGenericAdministrationPage*>(pPage)->SetAdminDialog(this,this);
355 		// open our own resource block, as the page titles are strings local to this block
356 		LocalResourceAccess aDummy(DLG_DATABASE_ADMINISTRATION, RSC_TABDIALOG);
357 
358 		pPage->SetText(String(ModuleRes(nStringId)));
359 		defaultButton( _nState == START_PAGE ? WZB_NEXT : WZB_FINISH );
360 		enableButtons( WZB_FINISH, _nState == START_PAGE ? sal_False : sal_True);
361 		pPage->Show();
362 	}
363 	return pPage;
364 }
365 // -----------------------------------------------------------------------------
366 sal_Bool ODbTypeWizDialog::leaveState(WizardState _nState)
367 {
368 	SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
369 	if ( pPage )
370 		pPage->FillItemSet(*m_pOutSet);
371 	return sal_True;
372 }
373 // -----------------------------------------------------------------------------
374 void ODbTypeWizDialog::setTitle(const ::rtl::OUString& _sTitle)
375 {
376 	SetText(_sTitle);
377 }
378 //-------------------------------------------------------------------------
379 void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable )
380 {
381     enableButtons( WZB_FINISH, _bEnable );
382     // TODO:
383     // this is hacky. At the moment, this method is used in only one case (#b6532894#).
384     // As soon as it is to be used more wide-spread, we should find a proper concept
385     // for enabling both the Next and Finish buttons, depending on the current page state.
386     // Plus, the concept must also care for the case where those pages are embedded into
387     // anormal tab dialog.
388 }
389 //-------------------------------------------------------------------------
390 sal_Bool ODbTypeWizDialog::saveDatasource()
391 {
392 	SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState()));
393 	if ( pPage )
394 		pPage->FillItemSet(*m_pOutSet);
395 
396     DataSourceInfoConverter aConverter(getORB());
397     ::rtl::OUString sOldURL;
398     if ( m_pImpl->getCurrentDataSource().is() )
399         m_pImpl->getCurrentDataSource()->getPropertyValue(PROPERTY_URL) >>= sOldURL;
400     aConverter.convert(m_pCollection,sOldURL,m_eType,m_pImpl->getCurrentDataSource());
401 	return sal_True;
402 }
403 // -----------------------------------------------------------------------------
404 IWizardPageController* ODbTypeWizDialog::getPageController( TabPage* _pCurrentPage ) const
405 {
406 	OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
407 	return pPage;
408 }
409 // -----------------------------------------------------------------------------
410 sal_Bool ODbTypeWizDialog::onFinish()
411 {
412 	saveDatasource();
413 	return m_pImpl->saveChanges(*m_pOutSet) ? OWizardMachine::onFinish() : sal_False;
414 }
415 //.........................................................................
416 }	// namespace dbaui
417 //.........................................................................
418