update dev300-m58
[ooovba.git] / dbaccess / source / ui / dlg / dbwizsetup.cxx
blob8ee9f2c6719d044b797a79495c36cba5c2a47e9e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbwizsetup.cxx,v $
10 * $Revision: 1.35.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "dbwizsetup.hxx"
35 #include "dsmeta.hxx"
36 #include "DBSetupConnectionPages.hxx"
37 #include "dbadminsetup.hrc"
38 #include "dbu_dlg.hrc"
39 #include "dsitems.hxx"
40 #include "dsnItem.hxx"
42 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
43 #include <svtools/pathoptions.hxx>
44 #endif
45 #ifndef _SFXSTRITEM_HXX
46 #include <svtools/stritem.hxx>
47 #endif
48 #ifndef _SFXENUMITEM_HXX
49 #include <svtools/eitem.hxx>
50 #endif
51 #ifndef _SFXINTITEM_HXX
52 #include <svtools/intitem.hxx>
53 #endif
54 #ifndef _SV_MSGBOX_HXX
55 #include <vcl/msgbox.hxx>
56 #endif
57 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
58 #include "dbustrings.hrc"
59 #endif
60 #ifndef _DBAUI_ADMINPAGES_HXX_
61 #include "adminpages.hxx"
62 #endif
63 #ifndef _SFX_DOCFILT_HACK_HXX
64 #include <sfx2/docfilt.hxx>
65 #endif
66 #ifndef _UNOTOOLS_UCBHELPER_HXX
67 #include <unotools/ucbhelper.hxx>
68 #endif
69 #ifndef _DBAUI_GENERALPAGE_HXX_
70 #include "generalpage.hxx"
71 #endif
72 #ifndef _DBAUI_LOCALRESACCESS_HXX_
73 #include "localresaccess.hxx"
74 #endif
75 #ifndef _DBAUI_STRINGLISTITEM_HXX_
76 #include "stringlistitem.hxx"
77 #endif
78 #ifndef _DBAUI_PROPERTYSETITEM_HXX_
79 #include "propertysetitem.hxx"
80 #endif
81 #ifndef _UNOTOOLS_CONFIGNODE_HXX_
82 #include <unotools/confignode.hxx>
83 #endif
84 #ifndef _DBAUI_DBADMINIMPL_HXX_
85 #include "DbAdminImpl.hxx"
86 #endif
87 #ifndef _DBA_DBACCESS_HELPID_HRC_
88 #include "dbaccess_helpid.hrc"
89 #endif
90 #ifndef DBAUI_CONNECTIONPAGESETUP_HXX
91 #include "ConnectionPageSetup.hxx"
92 #endif
93 #ifndef DBAUI_TOOLS_HXX
94 #include "UITools.hxx"
95 #endif
96 #ifndef _DBAUI_DBADMIN_HRC_
97 #include "dbadmin.hrc"
98 #endif
99 #ifndef DBAUI_ASYNCRONOUSLINK_HXX
100 #include "AsyncronousLink.hxx"
101 #endif
102 #ifndef _FILEDLGHELPER_HXX
103 #include <sfx2/filedlghelper.hxx>
104 #endif
106 /** === begin UNO includes === **/
107 #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
108 #include <com/sun/star/frame/XStorable.hpp>
109 #endif
110 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
111 #include <com/sun/star/uno/XNamingService.hpp>
112 #endif
113 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
114 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
115 #endif
116 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
117 #include <com/sun/star/sdbc/XDataSource.hpp>
118 #endif
119 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
120 #include <com/sun/star/container/XNameAccess.hpp>
121 #endif
122 #ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
123 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
124 #endif
125 #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
126 #include <com/sun/star/frame/FrameSearchFlag.hpp>
127 #endif
128 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
129 #include <com/sun/star/frame/XComponentLoader.hpp>
130 #endif
131 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
132 #include <com/sun/star/frame/XModel.hpp>
133 #endif
134 #ifndef _COM_SUN_STAR_UCB_XSIMPLEFILEACCESS_HPP_
135 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
136 #endif
137 #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
138 #include <com/sun/star/task/XJobExecutor.hpp>
139 #endif
140 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
141 #include <com/sun/star/lang/XInitialization.hpp>
142 #endif
143 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
144 #include <com/sun/star/sdb/CommandType.hpp>
145 #endif
146 #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP_
147 #include <com/sun/star/ucb/InteractiveIOException.hpp>
148 #endif
149 #ifndef _COM_SUN_STAR_IO_IOEXCEPTION_HPP_
150 #include <com/sun/star/io/IOException.hpp>
151 #endif
152 #ifndef _COM_SUN_STAR_FRAME_XTERMINATELISTENER_HPP_
153 #include <com/sun/star/frame/XTerminateListener.hpp>
154 #endif
155 #ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_
156 #include <com/sun/star/frame/XDesktop.hpp>
157 #endif
158 #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
159 #include <com/sun/star/sdbc/XDriverAccess.hpp>
160 #endif
161 #ifndef _COM_SUN_STAR_DOCUMENT_MACROEXECMODE_HPP_
162 #include <com/sun/star/document/MacroExecMode.hpp>
163 #endif
164 #include <com/sun/star/ucb/IOErrorCode.hpp>
165 #include <com/sun/star/task/XInteractionHandler.hpp>
166 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
169 /** === end UNO includes === **/
171 #include <svtools/filenotation.hxx>
172 #include <comphelper/interaction.hxx>
173 #include <comphelper/namedvaluecollection.hxx>
174 #include <comphelper/sequenceashashmap.hxx>
175 #include <tools/diagnose_ex.h>
176 #include <connectivity/DriversConfig.hxx>
178 #include <memory>
181 //.........................................................................
182 namespace dbaui
184 //.........................................................................
185 using namespace dbtools;
186 using namespace svt;
187 using namespace com::sun::star;
188 using namespace com::sun::star::uno;
189 using namespace com::sun::star::sdbc;
190 using namespace com::sun::star::sdbcx;
191 using namespace com::sun::star::task;
192 using namespace com::sun::star::lang;
193 using namespace com::sun::star::io;
194 using namespace com::sun::star::util;
195 using namespace com::sun::star::beans;
196 using namespace com::sun::star::container;
197 using namespace com::sun::star::frame;
198 using namespace com::sun::star::ucb;
199 using namespace ::com::sun::star::sdb;
200 using namespace ::com::sun::star::document;
201 using namespace ::comphelper;
202 using namespace ::cppu;
204 #define START_PAGE 0
205 #define CONNECTION_PAGE 1
210 //#define DBASE_PATH 1
211 //#define TEXT_PATH 2
212 //#define MSACCESS_PATH 3
213 //#define LDAP_PATH 4
214 //#define ADABAS_PATH 5
215 //#define ADO_PATH 6
216 //#define JDBC_PATH 7
217 //#define ORACLE_PATH 8
218 //#define MYSQL_JDBC_PATH 9
219 //#define MYSQL_ODBC_PATH 10
220 //#define ODBC_PATH 11
221 //#define SPREADSHEET_PATH 12
222 //#define OUTLOOKEXP_PATH 13
223 //#define OUTLOOK_PATH 14
224 //#define MOZILLA_PATH 15
225 //#define EVOLUTION_PATH 16
226 //#define EVOLUTION_PATH_GROUPWISE 17
227 //#define EVOLUTION_PATH_LDAP 18
228 //#define KAB_PATH 19
229 //#define MACAB_PATH 20
230 //#define THUNDERBIRD_PATH 21
231 //#define CREATENEW_PATH 22
232 //#define USERDEFINED_PATH 23
233 //#define OPEN_DOC_PATH 24
234 //#define MSACCESS2007_PATH 25
235 //#define MYSQL_NATIVE_PATH 26
237 OFinalDBPageSetup* pFinalPage;
241 DBG_NAME(ODbTypeWizDialogSetup)
242 //=========================================================================
243 //= ODbTypeWizDialogSetup
244 //=========================================================================
245 //-------------------------------------------------------------------------
246 ODbTypeWizDialogSetup::ODbTypeWizDialogSetup(Window* _pParent
247 ,SfxItemSet* _pItems
248 ,const Reference< XMultiServiceFactory >& _rxORB
249 ,const ::com::sun::star::uno::Any& _aDataSourceName
251 :svt::RoadmapWizard( _pParent, ModuleRes(DLG_DATABASE_WIZARD),
252 WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP )
254 , m_pOutSet(NULL)
255 , m_bResetting(sal_False)
256 , m_bApplied(sal_False)
257 , m_bUIEnabled( sal_True )
258 , m_bIsConnectable( sal_False)
259 , m_sRM_IntroText(ModuleRes(STR_PAGETITLE_INTROPAGE))
260 , m_sRM_dBaseText(ModuleRes(STR_PAGETITLE_DBASE))
261 , m_sRM_TextText(ModuleRes(STR_PAGETITLE_TEXT))
262 , m_sRM_MSAccessText(ModuleRes(STR_PAGETITLE_MSACCESS))
263 , m_sRM_LDAPText(ModuleRes(STR_PAGETITLE_LDAP))
264 , m_sRM_ADABASText(ModuleRes(STR_PAGETITLE_ADABAS))
265 , m_sRM_ADOText(ModuleRes(STR_PAGETITLE_ADO))
266 , m_sRM_JDBCText(ModuleRes(STR_PAGETITLE_JDBC))
267 , m_pGeneralPage( NULL )
268 , m_pMySQLIntroPage(NULL)
269 , m_pCollection( NULL )
271 DBG_CTOR(ODbTypeWizDialogSetup,NULL);
272 // no local resources needed anymore
273 m_sRM_MySQLText = String(ModuleRes(STR_PAGETITLE_MYSQL));
274 m_sRM_OracleText = String(ModuleRes(STR_PAGETITLE_ORACLE));
275 m_sRM_ODBCText = String(ModuleRes(STR_PAGETITLE_ODBC));
276 m_sRM_SpreadSheetText = String(ModuleRes(STR_PAGETITLE_SPREADSHEET));
277 m_sRM_AuthentificationText = String(ModuleRes(STR_PAGETITLE_AUTHENTIFICATION));
278 m_sRM_FinalText = String(ModuleRes(STR_PAGETITLE_FINAL));
279 m_sWorkPath = SvtPathOptions().GetWorkPath();
280 pFinalPage = NULL;
281 // extract the datasource type collection from the item set
282 DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION));
283 if (pCollectionItem)
284 m_pCollection = pCollectionItem->getCollection();
286 DBG_ASSERT(m_pCollection, "ODbTypeWizDialogSetup::ODbTypeWizDialogSetup : really need a DSN type collection !");
288 FreeResource();
290 m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,this,this));
291 m_pImpl->setDataSourceOrName(_aDataSourceName);
292 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
293 m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() );
295 m_pImpl->translateProperties(xDatasource, *m_pOutSet);
296 // eType = m_pImpl->getDatasourceType(*m_pOutSet);
298 SetPageSizePixel(LogicToPixel(::Size(WIZARD_PAGE_X, WIZARD_PAGE_Y), MAP_APPFONT));
299 ShowButtonFixedLine(sal_True);
300 defaultButton(WZB_NEXT);
301 enableButtons(WZB_FINISH, sal_True);
302 enableAutomaticNextButtonState();
304 ::dbaccess::ODsnTypeCollection::TypeIterator aIter = m_pCollection->begin();
305 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
306 for(PathId i = 1;aIter != aEnd;++aIter,++i)
308 const ::rtl::OUString sURLPrefix = aIter.getURLPrefix();
309 svt::RoadmapWizardTypes::WizardPath aPath;
310 aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
311 m_pCollection->fillPageIds(sURLPrefix,aPath);
312 aPath.push_back(PAGE_DBSETUPWIZARD_AUTHENTIFICATION);
313 aPath.push_back(PAGE_DBSETUPWIZARD_FINAL);
315 declareAuthDepPath(sURLPrefix,i,aPath);
318 svt::RoadmapWizardTypes::WizardPath aPath;
319 aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
320 declarePath( static_cast<PathId>(m_pCollection->size()+1), aPath);
322 m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS);
323 m_pNextPage->SetHelpId(HID_DBWIZ_NEXT);
324 m_pCancel->SetHelpId(HID_DBWIZ_CANCEL);
325 m_pFinish->SetHelpId(HID_DBWIZ_FINISH);
326 m_pHelp->SetUniqueId(UID_DBWIZ_HELP);
327 SetRoadmapInteractive( sal_True );
328 ActivatePage();
331 void ODbTypeWizDialogSetup::declareAuthDepPath( const ::rtl::OUString& _sURL, PathId _nPathId, const svt::RoadmapWizardTypes::WizardPath& _rPaths)
333 bool bHasAuthentication = DataSourceMetaData::getAuthentication( _sURL ) != AuthNone;
335 // collect the elements of the path
336 WizardPath aPath;
338 svt::RoadmapWizardTypes::WizardPath::const_iterator aIter = _rPaths.begin();
339 svt::RoadmapWizardTypes::WizardPath::const_iterator aEnd = _rPaths.end();
340 for(;aIter != aEnd;++aIter)
342 if ( bHasAuthentication || ( *aIter != PAGE_DBSETUPWIZARD_AUTHENTIFICATION ) )
343 aPath.push_back( *aIter );
344 } // for(;aIter != aEnd;++aIter)
346 // call base method
347 ::svt::RoadmapWizard::declarePath( _nPathId, aPath );
350 String ODbTypeWizDialogSetup::getStateDisplayName( WizardState _nState ) const
352 String sRoadmapItem;
353 switch( _nState )
355 case PAGE_DBSETUPWIZARD_INTRO:
356 sRoadmapItem = m_sRM_IntroText;
357 break;
359 case PAGE_DBSETUPWIZARD_DBASE:
360 sRoadmapItem = m_sRM_dBaseText;
361 break;
362 case PAGE_DBSETUPWIZARD_ADO:
363 sRoadmapItem = m_sRM_ADOText;
364 break;
365 case PAGE_DBSETUPWIZARD_TEXT:
366 sRoadmapItem = m_sRM_TextText;
367 break;
368 case PAGE_DBSETUPWIZARD_MSACCESS:
369 sRoadmapItem = m_sRM_MSAccessText;
370 break;
371 case PAGE_DBSETUPWIZARD_LDAP:
372 sRoadmapItem = m_sRM_LDAPText;
373 break;
374 case PAGE_DBSETUPWIZARD_ADABAS:
375 sRoadmapItem = m_sRM_ADABASText;
376 break;
377 case PAGE_DBSETUPWIZARD_JDBC:
378 sRoadmapItem = m_sRM_JDBCText;
379 break;
380 case PAGE_DBSETUPWIZARD_ORACLE:
381 sRoadmapItem = m_sRM_OracleText;
382 break;
383 case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
384 sRoadmapItem = m_sRM_MySQLText;
385 break;
386 case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
387 sRoadmapItem = m_sRM_JDBCText;
388 break;
389 case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
390 sRoadmapItem = m_sRM_JDBCText;
391 break;
392 case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
393 sRoadmapItem = m_sRM_ODBCText;
394 break;
395 case PAGE_DBSETUPWIZARD_ODBC:
396 sRoadmapItem = m_sRM_ODBCText;
397 break;
398 case PAGE_DBSETUPWIZARD_SPREADSHEET:
399 sRoadmapItem = m_sRM_SpreadSheetText;
400 break;
401 case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
402 sRoadmapItem = m_sRM_AuthentificationText;
403 break;
404 case PAGE_DBSETUPWIZARD_USERDEFINED:
406 LocalResourceAccess aDummy(DLG_DATABASE_ADMINISTRATION, RSC_TABDIALOG);
407 sRoadmapItem = String(ModuleRes(STR_PAGETITLE_CONNECTION));
409 break;
410 case PAGE_DBSETUPWIZARD_FINAL:
411 sRoadmapItem = m_sRM_FinalText;
412 break;
413 default:
414 break;
416 return sRoadmapItem;
419 //-------------------------------------------------------------------------
420 ODbTypeWizDialogSetup::~ODbTypeWizDialogSetup()
422 delete m_pOutSet;
423 DBG_DTOR(ODbTypeWizDialogSetup,NULL);
426 //-------------------------------------------------------------------------
427 IMPL_LINK(ODbTypeWizDialogSetup, OnTypeSelected, OGeneralPage*, /*_pTabPage*/)
429 activateDatabasePath();
430 return 1L;
433 void lcl_removeUnused(const ::comphelper::NamedValueCollection& _aOld,const ::comphelper::NamedValueCollection& _aNew,::comphelper::NamedValueCollection& _rDSInfo)
435 _rDSInfo.merge(_aNew,true);
436 uno::Sequence< beans::NamedValue > aOldValues = _aOld.getNamedValues();
437 const beans::NamedValue* pIter = aOldValues.getConstArray();
438 const beans::NamedValue* pEnd = pIter + aOldValues.getLength();
439 for(;pIter != pEnd;++pIter)
441 if ( !_aNew.has(pIter->Name) )
443 _rDSInfo.remove(pIter->Name);
447 // -----------------------------------------------------------------------------
448 void DataSourceInfoConverter::convert(const ::dbaccess::ODsnTypeCollection* _pCollection,const ::rtl::OUString& _sOldURLPrefix,const ::rtl::OUString& _sNewURLPrefix,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDatasource)
450 if ( _pCollection->getPrefix(_sOldURLPrefix) == _pCollection->getPrefix(_sNewURLPrefix) )
451 return ;
452 uno::Sequence< beans::PropertyValue> aInfo;
453 _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
454 ::comphelper::NamedValueCollection aDS(aInfo);
456 ::connectivity::DriversConfig aDriverConfig(m_xFactory);
457 const ::comphelper::NamedValueCollection& aOldMetaData = aDriverConfig.getMetaData(_sOldURLPrefix);
458 const ::comphelper::NamedValueCollection& aOldProperties = aDriverConfig.getProperties(_sOldURLPrefix);
460 const ::comphelper::NamedValueCollection& aNewMetaData = aDriverConfig.getMetaData(_sNewURLPrefix);
461 const ::comphelper::NamedValueCollection& aNewProperties = aDriverConfig.getProperties(_sNewURLPrefix);
463 lcl_removeUnused(aOldMetaData,aNewMetaData,aDS);
464 lcl_removeUnused(aOldProperties,aNewProperties,aDS);
465 aDS >>= aInfo;
466 _xDatasource->setPropertyValue(PROPERTY_INFO,uno::makeAny(aInfo));
468 //-------------------------------------------------------------------------
469 void ODbTypeWizDialogSetup::activateDatabasePath()
471 switch ( m_pGeneralPage->GetDatabaseCreationMode() )
473 case OGeneralPage::eCreateNew:
475 activatePath( static_cast<PathId>(m_pCollection->getIndexOf(m_pCollection->getEmbeddedDatabase()) + 1), sal_True);
476 enableState(PAGE_DBSETUPWIZARD_FINAL, sal_True );
477 enableButtons( WZB_FINISH, sal_True);
479 break;
480 case OGeneralPage::eConnectExternal:
482 ::rtl::OUString sOld = m_sURL;
483 DataSourceInfoConverter aConverter(getORB());
484 m_sURL = m_pGeneralPage->GetSelectedType();
485 aConverter.convert(m_pCollection,sOld,m_sURL,m_pImpl->getCurrentDataSource());
486 ::dbaccess::DATASOURCE_TYPE eType = VerifyDataSourceType(m_pCollection->determineType(m_sURL));
487 if (eType == ::dbaccess::DST_UNKNOWN)
488 eType = m_pCollection->determineType(m_sOldURL);
490 activatePath( static_cast<PathId>(m_pCollection->getIndexOf(m_sURL) + 1), sal_True);
491 updateTypeDependentStates();
493 break;
494 case OGeneralPage::eOpenExisting:
496 activatePath( static_cast<PathId>(m_pCollection->size() + 1), sal_True );
497 enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 );
499 break;
500 default:
501 DBG_ERROR( "ODbTypeWizDialogSetup::activateDatabasePath: unknown creation mode!" );
504 enableButtons( WZB_NEXT, m_pGeneralPage->GetDatabaseCreationMode() != OGeneralPage::eOpenExisting );
505 // TODO: this should go into the base class. Point is, we activate a path whose *last*
506 // step is also the current one. The base class should automatically disable
507 // the Next button in such a case. However, not for this patch ...
510 //-------------------------------------------------------------------------
511 void ODbTypeWizDialogSetup::updateTypeDependentStates()
513 sal_Bool bDoEnable = sal_False;
514 sal_Bool bIsConnectionRequired = IsConnectionUrlRequired();
515 if (!bIsConnectionRequired)
517 bDoEnable = sal_True;
519 else if ( m_sURL == m_sOldURL )
521 bDoEnable = m_bIsConnectable;
523 enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, bDoEnable);
524 enableState(PAGE_DBSETUPWIZARD_FINAL, bDoEnable );
525 enableButtons( WZB_FINISH, bDoEnable);
529 //-------------------------------------------------------------------------
530 sal_Bool ODbTypeWizDialogSetup::IsConnectionUrlRequired()
532 return m_pCollection->isConnectionUrlRequired(m_sURL);
535 //-------------------------------------------------------------------------
536 void ODbTypeWizDialogSetup::resetPages(const Reference< XPropertySet >& _rxDatasource)
538 // remove all items which relate to indirect properties from the input set
539 // (without this, the following may happen: select an arbitrary data source where some indirect properties
540 // are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
541 // the indirect property values of the first ds are shown in the second ds ...)
542 const ODbDataSourceAdministrationHelper::MapInt2String& rMap = m_pImpl->getIndirectProperties();
543 for ( ODbDataSourceAdministrationHelper::ConstMapInt2StringIterator aIndirect = rMap.begin();
544 aIndirect != rMap.end();
545 ++aIndirect
547 getWriteOutputSet()->ClearItem( (sal_uInt16)aIndirect->first );
549 // extract all relevant data from the property set of the data source
550 m_pImpl->translateProperties(_rxDatasource, *getWriteOutputSet());
552 // -----------------------------------------------------------------------------
553 const SfxItemSet* ODbTypeWizDialogSetup::getOutputSet() const
555 return m_pOutSet;
557 // -----------------------------------------------------------------------------
558 SfxItemSet* ODbTypeWizDialogSetup::getWriteOutputSet()
560 return m_pOutSet;
562 // -----------------------------------------------------------------------------
563 ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialogSetup::createConnection()
565 return m_pImpl->createConnection();
567 // -----------------------------------------------------------------------------
568 Reference< XMultiServiceFactory > ODbTypeWizDialogSetup::getORB() const
570 return m_pImpl->getORB();
572 // -----------------------------------------------------------------------------
573 Reference< XDriver > ODbTypeWizDialogSetup::getDriver()
575 return m_pImpl->getDriver();
579 ::dbaccess::DATASOURCE_TYPE ODbTypeWizDialogSetup::VerifyDataSourceType(const ::dbaccess::DATASOURCE_TYPE _DatabaseType) const
581 ::dbaccess::DATASOURCE_TYPE LocDatabaseType = _DatabaseType;
582 if ((LocDatabaseType == ::dbaccess::DST_MYSQL_JDBC) || (LocDatabaseType == ::dbaccess::DST_MYSQL_ODBC) || (LocDatabaseType == ::dbaccess::DST_MYSQL_NATIVE))
584 if (m_pMySQLIntroPage != NULL)
586 switch( m_pMySQLIntroPage->getMySQLMode() )
588 case OMySQLIntroPageSetup::VIA_JDBC:
589 return ::dbaccess::DST_MYSQL_JDBC;
590 case OMySQLIntroPageSetup::VIA_NATIVE:
591 return ::dbaccess::DST_MYSQL_NATIVE;
592 case OMySQLIntroPageSetup::VIA_ODBC:
593 return ::dbaccess::DST_MYSQL_ODBC;
597 return LocDatabaseType;
602 // -----------------------------------------------------------------------------
603 ::rtl::OUString ODbTypeWizDialogSetup::getDatasourceType(const SfxItemSet& _rSet) const
605 ::rtl::OUString sRet = m_pImpl->getDatasourceType(_rSet);
606 if (m_pMySQLIntroPage != NULL && m_pMySQLIntroPage->IsVisible() )
608 switch( m_pMySQLIntroPage->getMySQLMode() )
610 case OMySQLIntroPageSetup::VIA_JDBC:
611 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
612 break;
613 case OMySQLIntroPageSetup::VIA_NATIVE:
614 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
615 break;
616 case OMySQLIntroPageSetup::VIA_ODBC:
617 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
618 break;
621 return sRet;
624 // -----------------------------------------------------------------------------
625 void ODbTypeWizDialogSetup::clearPassword()
627 m_pImpl->clearPassword();
630 // -----------------------------------------------------------------------------
631 TabPage* ODbTypeWizDialogSetup::createPage(WizardState _nState)
633 SfxTabPage* pFirstPage;
634 OGenericAdministrationPage* pPage = NULL;
635 switch(_nState)
637 case PAGE_DBSETUPWIZARD_INTRO:
638 pFirstPage = OGeneralPage::Create(this,*m_pOutSet, sal_True);
639 pPage = static_cast<OGenericAdministrationPage*> (pFirstPage);
640 m_pGeneralPage = static_cast<OGeneralPage*>(pFirstPage);
641 m_pGeneralPage->SetTypeSelectHandler(LINK(this, ODbTypeWizDialogSetup, OnTypeSelected));
642 m_pGeneralPage->SetCreationModeHandler(LINK( this, ODbTypeWizDialogSetup, OnChangeCreationMode ) );
643 m_pGeneralPage->SetDocumentSelectionHandler(LINK( this, ODbTypeWizDialogSetup, OnRecentDocumentSelected ) );
644 m_pGeneralPage->SetChooseDocumentHandler(LINK( this, ODbTypeWizDialogSetup, OnSingleDocumentChosen ) );
645 break;
647 case PAGE_DBSETUPWIZARD_DBASE:
648 pPage = OConnectionTabPageSetup::CreateDbaseTabPage(this,*m_pOutSet);
649 break;
651 case PAGE_DBSETUPWIZARD_ADO:
652 pPage = OConnectionTabPageSetup::CreateADOTabPage( this, *m_pOutSet);
653 break;
655 case PAGE_DBSETUPWIZARD_TEXT:
656 pPage = OTextConnectionPageSetup::CreateTextTabPage(this,*m_pOutSet);
657 break;
659 case PAGE_DBSETUPWIZARD_ODBC:
660 pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
661 break;
663 case PAGE_DBSETUPWIZARD_JDBC:
664 pPage = OJDBCConnectionPageSetup::CreateJDBCTabPage( this, *m_pOutSet);
665 break;
667 case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
668 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:")))));
669 pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
670 break;
672 case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
673 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:")))));
674 pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateMySQLJDBCTabPage( this, *m_pOutSet);
675 break;
676 case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
677 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:")))));
678 pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateMySQLNATIVETabPage( this, *m_pOutSet);
679 break;
681 case PAGE_DBSETUPWIZARD_ORACLE:
682 pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateOracleJDBCTabPage( this, *m_pOutSet);
683 break;
685 case PAGE_DBSETUPWIZARD_ADABAS:
686 pPage = OConnectionTabPageSetup::CreateAdabasTabPage( this, *m_pOutSet);
687 break;
689 case PAGE_DBSETUPWIZARD_LDAP :
690 pPage = OLDAPConnectionPageSetup::CreateLDAPTabPage(this,*m_pOutSet);
691 break;
693 case PAGE_DBSETUPWIZARD_SPREADSHEET: /// first user defined driver
694 pPage = OSpreadSheetConnectionPageSetup::CreateSpreadSheetTabPage(this,*m_pOutSet);
695 break;
697 case PAGE_DBSETUPWIZARD_MSACCESS:
698 pPage = OConnectionTabPageSetup::CreateMSAccessTabPage(this,*m_pOutSet);
699 break;
700 case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
701 m_pMySQLIntroPage = OMySQLIntroPageSetup::CreateMySQLIntroTabPage(this,*m_pOutSet);
702 m_pMySQLIntroPage->SetClickHdl(LINK( this, ODbTypeWizDialogSetup, ImplClickHdl ) );
703 pPage = m_pMySQLIntroPage;
704 break;
706 case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
707 pPage = OAuthentificationPageSetup::CreateAuthentificationTabPage(this,*m_pOutSet);
708 break;
710 case PAGE_DBSETUPWIZARD_USERDEFINED:
711 pPage = OConnectionTabPageSetup::CreateUserDefinedTabPage(this,*m_pOutSet);
712 break;
714 case PAGE_DBSETUPWIZARD_FINAL:
715 pPage = OFinalDBPageSetup::CreateFinalDBTabPageSetup(this,*m_pOutSet);
716 pFinalPage = static_cast<OFinalDBPageSetup*> (pPage);
717 break;
720 if ((_nState != PAGE_DBSETUPWIZARD_INTRO) && (_nState != PAGE_DBSETUPWIZARD_AUTHENTIFICATION))
722 pPage->SetModifiedHandler(LINK( this, ODbTypeWizDialogSetup, ImplModifiedHdl ) );
725 if ( pPage )
727 pPage->SetServiceFactory(m_pImpl->getORB());
728 pPage->SetAdminDialog(this, this);
730 defaultButton( _nState == PAGE_DBSETUPWIZARD_FINAL ? WZB_FINISH : WZB_NEXT );
731 enableButtons( WZB_FINISH, _nState == PAGE_DBSETUPWIZARD_FINAL );
732 enableButtons( WZB_NEXT, _nState == PAGE_DBSETUPWIZARD_FINAL ? sal_False : sal_True);
733 pPage->Show();
735 return pPage;
739 IMPL_LINK(ODbTypeWizDialogSetup, ImplModifiedHdl, OGenericAdministrationPage*, _pConnectionPageSetup)
741 m_bIsConnectable = _pConnectionPageSetup->GetRoadmapStateValue( );
742 enableState(PAGE_DBSETUPWIZARD_FINAL, m_bIsConnectable);
743 enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, m_bIsConnectable);
744 if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
745 enableButtons( WZB_FINISH, sal_True);
746 else
747 enableButtons( WZB_FINISH, m_bIsConnectable);
748 enableButtons( WZB_NEXT, m_bIsConnectable && (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL));
749 return sal_True;
753 // -----------------------------------------------------------------------------
754 IMPL_LINK(ODbTypeWizDialogSetup, ImplClickHdl, OMySQLIntroPageSetup*, _pMySQLIntroPageSetup)
756 ::rtl::OUString sURLPrefix;
757 switch( _pMySQLIntroPageSetup->getMySQLMode() )
759 case OMySQLIntroPageSetup::VIA_ODBC:
760 sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
761 break;
762 case OMySQLIntroPageSetup::VIA_JDBC:
763 sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
764 break;
765 case OMySQLIntroPageSetup::VIA_NATIVE:
766 sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
767 break;
768 } // switch( _pMySQLIntroPageSetup->getMySQLMode() )
769 activatePath( static_cast<PathId>(m_pCollection->getIndexOf(sURLPrefix) + 1), sal_True);
770 return sal_True;
773 // -----------------------------------------------------------------------------
774 IMPL_LINK(ODbTypeWizDialogSetup, OnChangeCreationMode, OGeneralPage*, /*_pGeneralPage*/)
776 activateDatabasePath();
777 return sal_True;
780 // -----------------------------------------------------------------------------
781 IMPL_LINK(ODbTypeWizDialogSetup, OnRecentDocumentSelected, OGeneralPage*, /*_pGeneralPage*/)
783 enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 );
784 return 0L;
787 // -----------------------------------------------------------------------------
788 IMPL_LINK(ODbTypeWizDialogSetup, OnSingleDocumentChosen, OGeneralPage*, /*_pGeneralPage*/)
790 if ( prepareLeaveCurrentState( eFinish ) )
791 onFinish( RET_OK );
792 return 0L;
795 // -----------------------------------------------------------------------------
796 void ODbTypeWizDialogSetup::enterState(WizardState _nState)
798 m_sURL = m_pImpl->getDatasourceType(*m_pOutSet);
799 RoadmapWizard::enterState(_nState);
800 switch(_nState)
802 case PAGE_DBSETUPWIZARD_INTRO:
803 m_sOldURL = m_sURL;
804 break;
805 case PAGE_DBSETUPWIZARD_FINAL:
806 enableButtons( WZB_FINISH, sal_True);
807 if ( pFinalPage )
808 pFinalPage->enableTableWizardCheckBox(m_pCollection->supportsTableCreation(m_sURL));
809 break;
813 //-------------------------------------------------------------------------
814 sal_Bool ODbTypeWizDialogSetup::saveDatasource()
816 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState()));
817 if ( pPage )
818 pPage->FillItemSet(*m_pOutSet);
819 return sal_True;
823 // -----------------------------------------------------------------------------
824 sal_Bool ODbTypeWizDialogSetup::leaveState(WizardState _nState)
826 if (_nState == PAGE_DBSETUPWIZARD_MYSQL_INTRO)
827 return sal_True;
828 if ( _nState == PAGE_DBSETUPWIZARD_INTRO && m_sURL != m_sOldURL )
830 resetPages(m_pImpl->getCurrentDataSource());
832 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
833 return pPage && pPage->DeactivatePage(m_pOutSet) != 0;
836 // -----------------------------------------------------------------------------
837 void ODbTypeWizDialogSetup::setTitle(const ::rtl::OUString& /*_sTitle*/)
839 DBG_ERROR( "ODbTypeWizDialogSetup::setTitle: not implemented!" );
840 // why?
843 //-------------------------------------------------------------------------
844 void ODbTypeWizDialogSetup::enableConfirmSettings( bool _bEnable )
846 (void)_bEnable;
849 //-------------------------------------------------------------------------
850 sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument()
852 Reference< XInteractionHandler > xHandler( getORB()->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY );
855 if (callSaveAsDialog() == sal_True)
857 m_pImpl->saveChanges(*m_pOutSet);
858 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
859 Reference< XModel > xModel( getDataSourceOrModel( xDatasource ), UNO_QUERY_THROW );
860 Reference< XStorable > xStore( xModel, UNO_QUERY_THROW );
862 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eCreateNew )
863 CreateDatabase();
865 ::comphelper::NamedValueCollection aArgs( xModel->getArgs() );
866 aArgs.put( "Overwrite", sal_Bool( sal_True ) );
867 aArgs.put( "InteractionHandler", xHandler );
868 aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
870 ::rtl::OUString sPath = m_pImpl->getDocumentUrl( *m_pOutSet );
871 xStore->storeAsURL( sPath, aArgs.getPropertyValues() );
873 if ( !pFinalPage || pFinalPage->IsDatabaseDocumentToBeRegistered() )
874 RegisterDataSourceByLocation( sPath );
876 return sal_True;
879 catch (Exception& e)
881 InteractiveIOException aRequest;
882 aRequest.Code = IOErrorCode_GENERAL;
883 OInteractionRequest * pRequest = new OInteractionRequest (makeAny (aRequest));
884 Reference < XInteractionRequest > xRequest(pRequest );
885 OInteractionAbort* pAbort = new OInteractionAbort;
886 pRequest ->addContinuation (pAbort );
887 if ( xHandler.is() )
888 xHandler->handle( xRequest );
889 (void)e; // make compiler happy
891 return sal_False;
893 // ------------------------------------------------------------------------
894 sal_Bool ODbTypeWizDialogSetup::IsDatabaseDocumentToBeOpened() const
896 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
897 return sal_True;
899 if ( pFinalPage != NULL )
900 return pFinalPage->IsDatabaseDocumentToBeOpened();
902 return sal_True;
905 // ------------------------------------------------------------------------
906 sal_Bool ODbTypeWizDialogSetup::IsTableWizardToBeStarted() const
908 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
909 return sal_False;
911 if ( pFinalPage != NULL )
912 return pFinalPage->IsTableWizardToBeStarted();
914 return sal_False;
917 //-------------------------------------------------------------------------
918 ::rtl::OUString ODbTypeWizDialogSetup::getDefaultDatabaseType() const
920 ::rtl::OUString sEmbeddedURL = m_pCollection->getEmbeddedDatabase();
921 ::connectivity::DriversConfig aDriverConfig(getORB());
922 if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() )
923 sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:"));
925 return sEmbeddedURL;
928 //-------------------------------------------------------------------------
929 void ODbTypeWizDialogSetup::CreateDatabase()
931 ::rtl::OUString sUrl;
932 ::rtl::OUString eType = getDefaultDatabaseType();
933 if ( m_pCollection->isEmbeddedDatabase(eType) )
935 sUrl = eType;
936 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
937 OSL_ENSURE(xDatasource.is(),"DataSource is null!");
938 if ( xDatasource.is() )
939 xDatasource->setPropertyValue( PROPERTY_INFO, makeAny( m_pCollection->getDefaultDBSettings( eType ) ) );
940 m_pImpl->translateProperties(xDatasource,*m_pOutSet);
942 else if ( m_pCollection->isFileSystemBased(eType) )
944 Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
945 INetURLObject aDBPathURL(m_sWorkPath);
946 aDBPathURL.Append(m_aDocURL.getBase());
947 createUniqueFolderName(&aDBPathURL);
948 ::rtl::OUString sPrefix = eType;
949 sUrl = aDBPathURL.GetMainURL( INetURLObject::NO_DECODE);
950 xSimpleFileAccess->createFolder(sUrl);
951 //OFileNotation aFileNotation(sUrl);
952 //sUrl = aFileNotation.get(OFileNotation::N_SYSTEM);
953 sUrl = sPrefix.concat(sUrl);
955 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, sUrl));
956 m_pImpl->saveChanges(*m_pOutSet);
959 //-------------------------------------------------------------------------
960 void ODbTypeWizDialogSetup::RegisterDataSourceByLocation(const ::rtl::OUString& _sPath)
962 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
963 Reference< XNamingService > xDatabaseContext(getORB()->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
964 Reference< XNameAccess > xNameAccessDatabaseContext(xDatabaseContext, UNO_QUERY);
965 INetURLObject aURL( _sPath );
966 ::rtl::OUString sFilename = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
967 ::rtl::OUString sDatabaseName = ::dbtools::createUniqueName(xNameAccessDatabaseContext, sFilename,sal_False);
968 xDatabaseContext->registerObject(sDatabaseName, xDatasource);
972 //-------------------------------------------------------------------------
973 sal_Bool ODbTypeWizDialogSetup::callSaveAsDialog()
975 sal_Bool bRet = sal_False;
976 WinBits nBits(WB_STDMODAL|WB_SAVEAS);
977 ::sfx2::FileDialogHelper aFileDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, static_cast<sal_uInt32>(nBits), this);
978 const SfxFilter* pFilter = getStandardDatabaseFilter();
979 if ( pFilter )
981 INetURLObject aWorkURL( m_sWorkPath );
982 aFileDlg.SetDisplayFolder( aWorkURL.GetMainURL( INetURLObject::NO_DECODE ));
984 ::rtl::OUString sDefaultName = String( ModuleRes( STR_DATABASEDEFAULTNAME ) );
985 ::rtl::OUString sExtension = pFilter->GetDefaultExtension();
986 sDefaultName += sExtension.replaceAt( 0, 1, ::rtl::OUString() );
987 aWorkURL.Append( sDefaultName );
988 sDefaultName = createUniqueFileName( aWorkURL );
989 aFileDlg.SetFileName( sDefaultName );
991 aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
992 aFileDlg.SetCurrentFilter(pFilter->GetUIName());
994 if ( aFileDlg.Execute() == ERRCODE_NONE )
996 m_aDocURL = INetURLObject(aFileDlg.GetPath());
998 if( m_aDocURL.GetProtocol() != INET_PROT_NOT_VALID )
1000 ::rtl::OUString sFileName = m_aDocURL.GetMainURL( INetURLObject::NO_DECODE );
1001 if ( ::utl::UCBContentHelper::IsDocument(sFileName) )
1002 ::utl::UCBContentHelper::Kill(sFileName);
1003 m_pOutSet->Put(SfxStringItem(DSID_DOCUMENT_URL, sFileName));
1004 bRet = sal_True;
1007 return bRet;
1010 //-------------------------------------------------------------------------
1011 void ODbTypeWizDialogSetup::createUniqueFolderName(INetURLObject* pURL)
1013 Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
1014 :: rtl::OUString sLastSegmentName = pURL->getName();
1015 sal_Bool bFolderExists = sal_True;
1016 sal_Int32 i = 1;
1017 while (bFolderExists == sal_True)
1019 bFolderExists = xSimpleFileAccess->isFolder(pURL->GetMainURL( INetURLObject::NO_DECODE ));
1020 if (bFolderExists == sal_True)
1022 i++;
1023 pURL->setName(sLastSegmentName.concat(::rtl::OUString::valueOf(i)));
1028 //-------------------------------------------------------------------------
1029 String ODbTypeWizDialogSetup::createUniqueFileName(const INetURLObject& _rURL)
1031 Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
1032 :: rtl::OUString sFilename = _rURL.getName();
1033 ::rtl::OUString BaseName = _rURL.getBase();
1034 ::rtl::OUString sExtension = _rURL.getExtension();
1036 sal_Bool bElementExists = sal_True;
1038 INetURLObject aExistenceCheck( _rURL );
1039 for ( sal_Int32 i = 1; bElementExists; )
1041 bElementExists = xSimpleFileAccess->exists( aExistenceCheck.GetMainURL( INetURLObject::NO_DECODE ) );
1042 if ( bElementExists )
1044 aExistenceCheck.setBase( BaseName.concat( ::rtl::OUString::valueOf( i ) ) );
1045 ++i;
1048 return aExistenceCheck.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1050 // -----------------------------------------------------------------------------
1051 IWizardPage* ODbTypeWizDialogSetup::getWizardPage(TabPage* _pCurrentPage) const
1053 OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
1054 return pPage;
1057 // -----------------------------------------------------------------------------
1058 namespace
1060 // .............................................................................
1061 typedef ::cppu::WeakImplHelper1 < XTerminateListener
1062 > AsyncLoader_Base;
1063 class AsyncLoader : public AsyncLoader_Base
1065 private:
1066 Reference< XComponentLoader > m_xFrameLoader;
1067 Reference< XDesktop > m_xDesktop;
1068 Reference< XInteractionHandler > m_xInteractionHandler;
1069 ::rtl::OUString m_sURL;
1070 OAsyncronousLink m_aAsyncCaller;
1072 public:
1073 AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL );
1075 void doLoadAsync();
1077 // XTerminateListener
1078 virtual void SAL_CALL queryTermination( const EventObject& Event ) throw (TerminationVetoException, RuntimeException);
1079 virtual void SAL_CALL notifyTermination( const EventObject& Event ) throw (RuntimeException);
1080 // XEventListener
1081 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
1083 private:
1084 DECL_LINK( OnOpenDocument, void* );
1087 // .............................................................................
1088 AsyncLoader::AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL )
1089 :m_sURL( _rURL )
1090 ,m_aAsyncCaller( LINK( this, AsyncLoader, OnOpenDocument ) )
1094 m_xDesktop.set( _rxORB->createInstance( SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW );
1095 m_xFrameLoader.set( m_xDesktop, UNO_QUERY_THROW );
1096 m_xInteractionHandler.set(
1097 _rxORB->createInstance(
1098 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.InteractionHandler" ) )
1100 UNO_QUERY_THROW );
1102 catch( const Exception& )
1104 DBG_UNHANDLED_EXCEPTION();
1108 // .............................................................................
1109 void AsyncLoader::doLoadAsync()
1111 OSL_ENSURE( !m_aAsyncCaller.IsRunning(), "AsyncLoader:doLoadAsync: already running!" );
1113 acquire();
1116 if ( m_xDesktop.is() )
1117 m_xDesktop->addTerminateListener( this );
1119 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1121 m_aAsyncCaller.Call( NULL );
1124 // .............................................................................
1125 IMPL_LINK( AsyncLoader, OnOpenDocument, void*, /*_pEmptyArg*/ )
1129 if ( m_xFrameLoader.is() )
1131 ::comphelper::NamedValueCollection aLoadArgs;
1132 aLoadArgs.put( "InteractionHandler", m_xInteractionHandler );
1133 aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
1135 Sequence< PropertyValue > aLoadArgPV;
1136 aLoadArgs >>= aLoadArgPV;
1138 m_xFrameLoader->loadComponentFromURL( m_sURL,
1139 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ),
1140 FrameSearchFlag::ALL,
1141 aLoadArgPV
1145 catch( const Exception& )
1147 // do not assert.
1148 // Such an exception happens for instance of the to-be-loaded document does not exist anymore.
1153 if ( m_xDesktop.is() )
1154 m_xDesktop->removeTerminateListener( this );
1156 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1158 release();
1159 return 0L;
1162 // .............................................................................
1163 void SAL_CALL AsyncLoader::queryTermination( const EventObject& /*Event*/ ) throw (TerminationVetoException, RuntimeException)
1165 throw TerminationVetoException();
1168 // .............................................................................
1169 void SAL_CALL AsyncLoader::notifyTermination( const EventObject& /*Event*/ ) throw (RuntimeException)
1172 // .............................................................................
1173 void SAL_CALL AsyncLoader::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
1178 // -----------------------------------------------------------------------------
1179 sal_Bool ODbTypeWizDialogSetup::onFinish(sal_Int32 _nResult)
1181 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
1183 // we're not going to re-use the XModel we have - since the document the user
1184 // wants us to load could be a non-database document. Instead, we asynchronously
1185 // open the selected document. Thus, the wizard's return value is RET_CANCEL,
1186 // which means to not continue loading the database document
1187 if ( !OWizardMachine::onFinish( RET_CANCEL ) )
1188 return sal_False;
1190 Reference< XComponentLoader > xFrameLoader;
1193 AsyncLoader* pAsyncLoader = new AsyncLoader( getORB(), m_pGeneralPage->GetSelectedDocument().sURL );
1194 ::rtl::Reference< AsyncLoader > xKeepAlive( pAsyncLoader );
1195 pAsyncLoader->doLoadAsync();
1197 catch( const Exception& )
1199 DBG_UNHANDLED_EXCEPTION();
1202 return sal_True;
1205 if (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL)
1207 skipUntil(PAGE_DBSETUPWIZARD_FINAL);
1209 if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
1210 return SaveDatabaseDocument() ? OWizardMachine::onFinish( _nResult ) : sal_False;
1211 else
1213 enableButtons( WZB_FINISH, sal_False );
1214 return sal_False;
1218 //.........................................................................
1219 } // namespace dbaui
1220 //.........................................................................