1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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>
45 #ifndef _SFXSTRITEM_HXX
46 #include <svtools/stritem.hxx>
48 #ifndef _SFXENUMITEM_HXX
49 #include <svtools/eitem.hxx>
51 #ifndef _SFXINTITEM_HXX
52 #include <svtools/intitem.hxx>
54 #ifndef _SV_MSGBOX_HXX
55 #include <vcl/msgbox.hxx>
57 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
58 #include "dbustrings.hrc"
60 #ifndef _DBAUI_ADMINPAGES_HXX_
61 #include "adminpages.hxx"
63 #ifndef _SFX_DOCFILT_HACK_HXX
64 #include <sfx2/docfilt.hxx>
66 #ifndef _UNOTOOLS_UCBHELPER_HXX
67 #include <unotools/ucbhelper.hxx>
69 #ifndef _DBAUI_GENERALPAGE_HXX_
70 #include "generalpage.hxx"
72 #ifndef _DBAUI_LOCALRESACCESS_HXX_
73 #include "localresaccess.hxx"
75 #ifndef _DBAUI_STRINGLISTITEM_HXX_
76 #include "stringlistitem.hxx"
78 #ifndef _DBAUI_PROPERTYSETITEM_HXX_
79 #include "propertysetitem.hxx"
81 #ifndef _UNOTOOLS_CONFIGNODE_HXX_
82 #include <unotools/confignode.hxx>
84 #ifndef _DBAUI_DBADMINIMPL_HXX_
85 #include "DbAdminImpl.hxx"
87 #ifndef _DBA_DBACCESS_HELPID_HRC_
88 #include "dbaccess_helpid.hrc"
90 #ifndef DBAUI_CONNECTIONPAGESETUP_HXX
91 #include "ConnectionPageSetup.hxx"
93 #ifndef DBAUI_TOOLS_HXX
94 #include "UITools.hxx"
96 #ifndef _DBAUI_DBADMIN_HRC_
97 #include "dbadmin.hrc"
99 #ifndef DBAUI_ASYNCRONOUSLINK_HXX
100 #include "AsyncronousLink.hxx"
102 #ifndef _FILEDLGHELPER_HXX
103 #include <sfx2/filedlghelper.hxx>
105 #include <cppuhelper/exc_hlp.hxx>
107 /** === begin UNO includes === **/
108 #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
109 #include <com/sun/star/frame/XStorable.hpp>
111 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
112 #include <com/sun/star/uno/XNamingService.hpp>
114 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
115 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
117 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
118 #include <com/sun/star/sdbc/XDataSource.hpp>
120 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
121 #include <com/sun/star/container/XNameAccess.hpp>
123 #ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
124 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
126 #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
127 #include <com/sun/star/frame/FrameSearchFlag.hpp>
129 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
130 #include <com/sun/star/frame/XComponentLoader.hpp>
132 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
133 #include <com/sun/star/frame/XModel.hpp>
135 #ifndef _COM_SUN_STAR_UCB_XSIMPLEFILEACCESS_HPP_
136 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
138 #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
139 #include <com/sun/star/task/XJobExecutor.hpp>
141 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
142 #include <com/sun/star/lang/XInitialization.hpp>
144 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
145 #include <com/sun/star/sdb/CommandType.hpp>
147 #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP_
148 #include <com/sun/star/ucb/InteractiveIOException.hpp>
150 #ifndef _COM_SUN_STAR_IO_IOEXCEPTION_HPP_
151 #include <com/sun/star/io/IOException.hpp>
153 #ifndef _COM_SUN_STAR_FRAME_XTERMINATELISTENER_HPP_
154 #include <com/sun/star/frame/XTerminateListener.hpp>
156 #ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_
157 #include <com/sun/star/frame/XDesktop.hpp>
159 #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
160 #include <com/sun/star/sdbc/XDriverAccess.hpp>
162 #ifndef _COM_SUN_STAR_DOCUMENT_MACROEXECMODE_HPP_
163 #include <com/sun/star/document/MacroExecMode.hpp>
165 #include <com/sun/star/ucb/IOErrorCode.hpp>
166 #include <com/sun/star/task/XInteractionHandler2.hpp>
167 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
170 /** === end UNO includes === **/
172 #include <svtools/filenotation.hxx>
173 #include <comphelper/interaction.hxx>
174 #include <comphelper/namedvaluecollection.hxx>
175 #include <comphelper/sequenceashashmap.hxx>
176 #include <tools/diagnose_ex.h>
177 #include <connectivity/DriversConfig.hxx>
182 //.........................................................................
185 //.........................................................................
186 using namespace dbtools
;
188 using namespace com::sun::star
;
189 using namespace com::sun::star::uno
;
190 using namespace com::sun::star::sdbc
;
191 using namespace com::sun::star::sdbcx
;
192 using namespace com::sun::star::task
;
193 using namespace com::sun::star::lang
;
194 using namespace com::sun::star::io
;
195 using namespace com::sun::star::util
;
196 using namespace com::sun::star::beans
;
197 using namespace com::sun::star::container
;
198 using namespace com::sun::star::frame
;
199 using namespace com::sun::star::ucb
;
200 using namespace ::com::sun::star::sdb
;
201 using namespace ::com::sun::star::document
;
202 using namespace ::comphelper
;
203 using namespace ::cppu
;
206 #define CONNECTION_PAGE 1
211 //#define DBASE_PATH 1
212 //#define TEXT_PATH 2
213 //#define MSACCESS_PATH 3
214 //#define LDAP_PATH 4
215 //#define ADABAS_PATH 5
217 //#define JDBC_PATH 7
218 //#define ORACLE_PATH 8
219 //#define MYSQL_JDBC_PATH 9
220 //#define MYSQL_ODBC_PATH 10
221 //#define ODBC_PATH 11
222 //#define SPREADSHEET_PATH 12
223 //#define OUTLOOKEXP_PATH 13
224 //#define OUTLOOK_PATH 14
225 //#define MOZILLA_PATH 15
226 //#define EVOLUTION_PATH 16
227 //#define EVOLUTION_PATH_GROUPWISE 17
228 //#define EVOLUTION_PATH_LDAP 18
229 //#define KAB_PATH 19
230 //#define MACAB_PATH 20
231 //#define THUNDERBIRD_PATH 21
232 //#define CREATENEW_PATH 22
233 //#define USERDEFINED_PATH 23
234 //#define OPEN_DOC_PATH 24
235 //#define MSACCESS2007_PATH 25
236 //#define MYSQL_NATIVE_PATH 26
238 OFinalDBPageSetup
* pFinalPage
;
242 DBG_NAME(ODbTypeWizDialogSetup
)
243 //=========================================================================
244 //= ODbTypeWizDialogSetup
245 //=========================================================================
246 //-------------------------------------------------------------------------
247 ODbTypeWizDialogSetup::ODbTypeWizDialogSetup(Window
* _pParent
249 ,const Reference
< XMultiServiceFactory
>& _rxORB
250 ,const ::com::sun::star::uno::Any
& _aDataSourceName
252 :svt::RoadmapWizard( _pParent
, ModuleRes(DLG_DATABASE_WIZARD
),
253 WZB_NEXT
| WZB_PREVIOUS
| WZB_FINISH
| WZB_CANCEL
| WZB_HELP
)
256 , m_bResetting(sal_False
)
257 , m_bApplied(sal_False
)
258 , m_bUIEnabled( sal_True
)
259 , m_bIsConnectable( sal_False
)
260 , m_sRM_IntroText(ModuleRes(STR_PAGETITLE_INTROPAGE
))
261 , m_sRM_dBaseText(ModuleRes(STR_PAGETITLE_DBASE
))
262 , m_sRM_TextText(ModuleRes(STR_PAGETITLE_TEXT
))
263 , m_sRM_MSAccessText(ModuleRes(STR_PAGETITLE_MSACCESS
))
264 , m_sRM_LDAPText(ModuleRes(STR_PAGETITLE_LDAP
))
265 , m_sRM_ADABASText(ModuleRes(STR_PAGETITLE_ADABAS
))
266 , m_sRM_ADOText(ModuleRes(STR_PAGETITLE_ADO
))
267 , m_sRM_JDBCText(ModuleRes(STR_PAGETITLE_JDBC
))
268 , m_sRM_MySQLNativePageTitle(ModuleRes(STR_PAGETITLE_MYSQL_NATIVE
))
269 , m_pGeneralPage( NULL
)
270 , m_pMySQLIntroPage(NULL
)
271 , m_pCollection( NULL
)
273 DBG_CTOR(ODbTypeWizDialogSetup
,NULL
);
274 // no local resources needed anymore
275 m_sRM_MySQLText
= String(ModuleRes(STR_PAGETITLE_MYSQL
));
276 m_sRM_OracleText
= String(ModuleRes(STR_PAGETITLE_ORACLE
));
277 m_sRM_ODBCText
= String(ModuleRes(STR_PAGETITLE_ODBC
));
278 m_sRM_SpreadSheetText
= String(ModuleRes(STR_PAGETITLE_SPREADSHEET
));
279 m_sRM_AuthentificationText
= String(ModuleRes(STR_PAGETITLE_AUTHENTIFICATION
));
280 m_sRM_FinalText
= String(ModuleRes(STR_PAGETITLE_FINAL
));
281 m_sWorkPath
= SvtPathOptions().GetWorkPath();
283 // extract the datasource type collection from the item set
284 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, _pItems
->GetItem(DSID_TYPECOLLECTION
));
286 m_pCollection
= pCollectionItem
->getCollection();
288 DBG_ASSERT(m_pCollection
, "ODbTypeWizDialogSetup::ODbTypeWizDialogSetup : really need a DSN type collection !");
292 m_pImpl
= ::std::auto_ptr
<ODbDataSourceAdministrationHelper
>(new ODbDataSourceAdministrationHelper(_rxORB
,this,this));
293 m_pImpl
->setDataSourceOrName(_aDataSourceName
);
294 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
295 m_pOutSet
= new SfxItemSet( *_pItems
->GetPool(), _pItems
->GetRanges() );
297 m_pImpl
->translateProperties(xDatasource
, *m_pOutSet
);
298 // eType = m_pImpl->getDatasourceType(*m_pOutSet);
300 SetPageSizePixel(LogicToPixel(::Size(WIZARD_PAGE_X
, WIZARD_PAGE_Y
), MAP_APPFONT
));
301 ShowButtonFixedLine(sal_True
);
302 defaultButton(WZB_NEXT
);
303 enableButtons(WZB_FINISH
, sal_True
);
304 enableAutomaticNextButtonState();
306 ::dbaccess::ODsnTypeCollection::TypeIterator aIter
= m_pCollection
->begin();
307 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd
= m_pCollection
->end();
308 for(PathId i
= 1;aIter
!= aEnd
;++aIter
,++i
)
310 const ::rtl::OUString sURLPrefix
= aIter
.getURLPrefix();
311 svt::RoadmapWizardTypes::WizardPath aPath
;
312 aPath
.push_back(PAGE_DBSETUPWIZARD_INTRO
);
313 m_pCollection
->fillPageIds(sURLPrefix
,aPath
);
314 aPath
.push_back(PAGE_DBSETUPWIZARD_AUTHENTIFICATION
);
315 aPath
.push_back(PAGE_DBSETUPWIZARD_FINAL
);
317 declareAuthDepPath(sURLPrefix
,i
,aPath
);
320 svt::RoadmapWizardTypes::WizardPath aPath
;
321 aPath
.push_back(PAGE_DBSETUPWIZARD_INTRO
);
322 declarePath( static_cast<PathId
>(m_pCollection
->size()+1), aPath
);
324 m_pPrevPage
->SetHelpId(HID_DBWIZ_PREVIOUS
);
325 m_pNextPage
->SetHelpId(HID_DBWIZ_NEXT
);
326 m_pCancel
->SetHelpId(HID_DBWIZ_CANCEL
);
327 m_pFinish
->SetHelpId(HID_DBWIZ_FINISH
);
328 m_pHelp
->SetUniqueId(UID_DBWIZ_HELP
);
329 SetRoadmapInteractive( sal_True
);
333 void ODbTypeWizDialogSetup::declareAuthDepPath( const ::rtl::OUString
& _sURL
, PathId _nPathId
, const svt::RoadmapWizardTypes::WizardPath
& _rPaths
)
335 bool bHasAuthentication
= DataSourceMetaData::getAuthentication( _sURL
) != AuthNone
;
337 // collect the elements of the path
340 svt::RoadmapWizardTypes::WizardPath::const_iterator aIter
= _rPaths
.begin();
341 svt::RoadmapWizardTypes::WizardPath::const_iterator aEnd
= _rPaths
.end();
342 for(;aIter
!= aEnd
;++aIter
)
344 if ( bHasAuthentication
|| ( *aIter
!= PAGE_DBSETUPWIZARD_AUTHENTIFICATION
) )
345 aPath
.push_back( *aIter
);
346 } // for(;aIter != aEnd;++aIter)
349 ::svt::RoadmapWizard::declarePath( _nPathId
, aPath
);
352 String
ODbTypeWizDialogSetup::getStateDisplayName( WizardState _nState
) const
357 case PAGE_DBSETUPWIZARD_INTRO
:
358 sRoadmapItem
= m_sRM_IntroText
;
361 case PAGE_DBSETUPWIZARD_DBASE
:
362 sRoadmapItem
= m_sRM_dBaseText
;
364 case PAGE_DBSETUPWIZARD_ADO
:
365 sRoadmapItem
= m_sRM_ADOText
;
367 case PAGE_DBSETUPWIZARD_TEXT
:
368 sRoadmapItem
= m_sRM_TextText
;
370 case PAGE_DBSETUPWIZARD_MSACCESS
:
371 sRoadmapItem
= m_sRM_MSAccessText
;
373 case PAGE_DBSETUPWIZARD_LDAP
:
374 sRoadmapItem
= m_sRM_LDAPText
;
376 case PAGE_DBSETUPWIZARD_ADABAS
:
377 sRoadmapItem
= m_sRM_ADABASText
;
379 case PAGE_DBSETUPWIZARD_JDBC
:
380 sRoadmapItem
= m_sRM_JDBCText
;
382 case PAGE_DBSETUPWIZARD_ORACLE
:
383 sRoadmapItem
= m_sRM_OracleText
;
385 case PAGE_DBSETUPWIZARD_MYSQL_INTRO
:
386 sRoadmapItem
= m_sRM_MySQLText
;
388 case PAGE_DBSETUPWIZARD_MYSQL_JDBC
:
389 sRoadmapItem
= m_sRM_JDBCText
;
391 case PAGE_DBSETUPWIZARD_MYSQL_NATIVE
:
392 sRoadmapItem
= m_sRM_MySQLNativePageTitle
;
394 case PAGE_DBSETUPWIZARD_MYSQL_ODBC
:
395 sRoadmapItem
= m_sRM_ODBCText
;
397 case PAGE_DBSETUPWIZARD_ODBC
:
398 sRoadmapItem
= m_sRM_ODBCText
;
400 case PAGE_DBSETUPWIZARD_SPREADSHEET
:
401 sRoadmapItem
= m_sRM_SpreadSheetText
;
403 case PAGE_DBSETUPWIZARD_AUTHENTIFICATION
:
404 sRoadmapItem
= m_sRM_AuthentificationText
;
406 case PAGE_DBSETUPWIZARD_USERDEFINED
:
408 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
409 sRoadmapItem
= String(ModuleRes(STR_PAGETITLE_CONNECTION
));
412 case PAGE_DBSETUPWIZARD_FINAL
:
413 sRoadmapItem
= m_sRM_FinalText
;
421 //-------------------------------------------------------------------------
422 ODbTypeWizDialogSetup::~ODbTypeWizDialogSetup()
425 DBG_DTOR(ODbTypeWizDialogSetup
,NULL
);
428 //-------------------------------------------------------------------------
429 IMPL_LINK(ODbTypeWizDialogSetup
, OnTypeSelected
, OGeneralPage
*, /*_pTabPage*/)
431 activateDatabasePath();
435 void lcl_removeUnused(const ::comphelper::NamedValueCollection
& _aOld
,const ::comphelper::NamedValueCollection
& _aNew
,::comphelper::NamedValueCollection
& _rDSInfo
)
437 _rDSInfo
.merge(_aNew
,true);
438 uno::Sequence
< beans::NamedValue
> aOldValues
= _aOld
.getNamedValues();
439 const beans::NamedValue
* pIter
= aOldValues
.getConstArray();
440 const beans::NamedValue
* pEnd
= pIter
+ aOldValues
.getLength();
441 for(;pIter
!= pEnd
;++pIter
)
443 if ( !_aNew
.has(pIter
->Name
) )
445 _rDSInfo
.remove(pIter
->Name
);
449 // -----------------------------------------------------------------------------
450 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
)
452 if ( _pCollection
->getPrefix(_sOldURLPrefix
) == _pCollection
->getPrefix(_sNewURLPrefix
) )
454 uno::Sequence
< beans::PropertyValue
> aInfo
;
455 _xDatasource
->getPropertyValue(PROPERTY_INFO
) >>= aInfo
;
456 ::comphelper::NamedValueCollection
aDS(aInfo
);
458 ::connectivity::DriversConfig
aDriverConfig(m_xFactory
);
460 const ::comphelper::NamedValueCollection
& aOldProperties
= aDriverConfig
.getProperties(_sOldURLPrefix
);
461 const ::comphelper::NamedValueCollection
& aNewProperties
= aDriverConfig
.getProperties(_sNewURLPrefix
);
462 lcl_removeUnused(aOldProperties
,aNewProperties
,aDS
);
465 _xDatasource
->setPropertyValue(PROPERTY_INFO
,uno::makeAny(aInfo
));
467 //-------------------------------------------------------------------------
468 void ODbTypeWizDialogSetup::activateDatabasePath()
470 switch ( m_pGeneralPage
->GetDatabaseCreationMode() )
472 case OGeneralPage::eCreateNew
:
474 sal_Int32 nCreateNewDBIndex
= m_pCollection
->getIndexOf( m_pCollection
->getEmbeddedDatabase() );
475 if ( nCreateNewDBIndex
== -1 )
476 nCreateNewDBIndex
= m_pCollection
->getIndexOf( ::rtl::OUString::createFromAscii( "sdbc:dbase:" ) );
477 OSL_ENSURE( nCreateNewDBIndex
!= -1, "ODbTypeWizDialogSetup::activateDatabasePath: the GeneralPage should have prevented this!" );
478 activatePath( static_cast< PathId
>( nCreateNewDBIndex
+ 1 ), sal_True
);
480 enableState(PAGE_DBSETUPWIZARD_FINAL
, sal_True
);
481 enableButtons( WZB_FINISH
, sal_True
);
484 case OGeneralPage::eConnectExternal
:
486 ::rtl::OUString sOld
= m_sURL
;
487 DataSourceInfoConverter
aConverter(getORB());
488 m_sURL
= m_pGeneralPage
->GetSelectedType();
489 aConverter
.convert(m_pCollection
,sOld
,m_sURL
,m_pImpl
->getCurrentDataSource());
490 ::dbaccess::DATASOURCE_TYPE eType
= VerifyDataSourceType(m_pCollection
->determineType(m_sURL
));
491 if (eType
== ::dbaccess::DST_UNKNOWN
)
492 eType
= m_pCollection
->determineType(m_sOldURL
);
494 activatePath( static_cast<PathId
>(m_pCollection
->getIndexOf(m_sURL
) + 1), sal_True
);
495 updateTypeDependentStates();
498 case OGeneralPage::eOpenExisting
:
500 activatePath( static_cast<PathId
>(m_pCollection
->size() + 1), sal_True
);
501 enableButtons( WZB_FINISH
, m_pGeneralPage
->GetSelectedDocument().sURL
.Len() != 0 );
505 DBG_ERROR( "ODbTypeWizDialogSetup::activateDatabasePath: unknown creation mode!" );
508 enableButtons( WZB_NEXT
, m_pGeneralPage
->GetDatabaseCreationMode() != OGeneralPage::eOpenExisting
);
509 // TODO: this should go into the base class. Point is, we activate a path whose *last*
510 // step is also the current one. The base class should automatically disable
511 // the Next button in such a case. However, not for this patch ...
514 //-------------------------------------------------------------------------
515 void ODbTypeWizDialogSetup::updateTypeDependentStates()
517 sal_Bool bDoEnable
= sal_False
;
518 sal_Bool bIsConnectionRequired
= IsConnectionUrlRequired();
519 if (!bIsConnectionRequired
)
521 bDoEnable
= sal_True
;
523 else if ( m_sURL
== m_sOldURL
)
525 bDoEnable
= m_bIsConnectable
;
527 enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION
, bDoEnable
);
528 enableState(PAGE_DBSETUPWIZARD_FINAL
, bDoEnable
);
529 enableButtons( WZB_FINISH
, bDoEnable
);
533 //-------------------------------------------------------------------------
534 sal_Bool
ODbTypeWizDialogSetup::IsConnectionUrlRequired()
536 return m_pCollection
->isConnectionUrlRequired(m_sURL
);
539 //-------------------------------------------------------------------------
540 void ODbTypeWizDialogSetup::resetPages(const Reference
< XPropertySet
>& _rxDatasource
)
542 // remove all items which relate to indirect properties from the input set
543 // (without this, the following may happen: select an arbitrary data source where some indirect properties
544 // are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
545 // the indirect property values of the first ds are shown in the second ds ...)
546 const ODbDataSourceAdministrationHelper::MapInt2String
& rMap
= m_pImpl
->getIndirectProperties();
547 for ( ODbDataSourceAdministrationHelper::ConstMapInt2StringIterator aIndirect
= rMap
.begin();
548 aIndirect
!= rMap
.end();
551 getWriteOutputSet()->ClearItem( (sal_uInt16
)aIndirect
->first
);
553 // extract all relevant data from the property set of the data source
554 m_pImpl
->translateProperties(_rxDatasource
, *getWriteOutputSet());
556 // -----------------------------------------------------------------------------
557 const SfxItemSet
* ODbTypeWizDialogSetup::getOutputSet() const
561 // -----------------------------------------------------------------------------
562 SfxItemSet
* ODbTypeWizDialogSetup::getWriteOutputSet()
566 // -----------------------------------------------------------------------------
567 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbTypeWizDialogSetup::createConnection()
569 return m_pImpl
->createConnection();
571 // -----------------------------------------------------------------------------
572 Reference
< XMultiServiceFactory
> ODbTypeWizDialogSetup::getORB() const
574 return m_pImpl
->getORB();
576 // -----------------------------------------------------------------------------
577 Reference
< XDriver
> ODbTypeWizDialogSetup::getDriver()
579 return m_pImpl
->getDriver();
583 ::dbaccess::DATASOURCE_TYPE
ODbTypeWizDialogSetup::VerifyDataSourceType(const ::dbaccess::DATASOURCE_TYPE _DatabaseType
) const
585 ::dbaccess::DATASOURCE_TYPE LocDatabaseType
= _DatabaseType
;
586 if ((LocDatabaseType
== ::dbaccess::DST_MYSQL_JDBC
) || (LocDatabaseType
== ::dbaccess::DST_MYSQL_ODBC
) || (LocDatabaseType
== ::dbaccess::DST_MYSQL_NATIVE
))
588 if (m_pMySQLIntroPage
!= NULL
)
590 switch( m_pMySQLIntroPage
->getMySQLMode() )
592 case OMySQLIntroPageSetup::VIA_JDBC
:
593 return ::dbaccess::DST_MYSQL_JDBC
;
594 case OMySQLIntroPageSetup::VIA_NATIVE
:
595 return ::dbaccess::DST_MYSQL_NATIVE
;
596 case OMySQLIntroPageSetup::VIA_ODBC
:
597 return ::dbaccess::DST_MYSQL_ODBC
;
601 return LocDatabaseType
;
606 // -----------------------------------------------------------------------------
607 ::rtl::OUString
ODbTypeWizDialogSetup::getDatasourceType(const SfxItemSet
& _rSet
) const
609 ::rtl::OUString sRet
= m_pImpl
->getDatasourceType(_rSet
);
610 if (m_pMySQLIntroPage
!= NULL
&& m_pMySQLIntroPage
->IsVisible() )
612 switch( m_pMySQLIntroPage
->getMySQLMode() )
614 case OMySQLIntroPageSetup::VIA_JDBC
:
615 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
617 case OMySQLIntroPageSetup::VIA_NATIVE
:
618 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
620 case OMySQLIntroPageSetup::VIA_ODBC
:
621 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
628 // -----------------------------------------------------------------------------
629 void ODbTypeWizDialogSetup::clearPassword()
631 m_pImpl
->clearPassword();
634 // -----------------------------------------------------------------------------
635 TabPage
* ODbTypeWizDialogSetup::createPage(WizardState _nState
)
637 SfxTabPage
* pFirstPage
;
638 OGenericAdministrationPage
* pPage
= NULL
;
641 case PAGE_DBSETUPWIZARD_INTRO
:
642 pFirstPage
= OGeneralPage::Create(this,*m_pOutSet
, sal_True
);
643 pPage
= static_cast<OGenericAdministrationPage
*> (pFirstPage
);
644 m_pGeneralPage
= static_cast<OGeneralPage
*>(pFirstPage
);
645 m_pGeneralPage
->SetTypeSelectHandler(LINK(this, ODbTypeWizDialogSetup
, OnTypeSelected
));
646 m_pGeneralPage
->SetCreationModeHandler(LINK( this, ODbTypeWizDialogSetup
, OnChangeCreationMode
) );
647 m_pGeneralPage
->SetDocumentSelectionHandler(LINK( this, ODbTypeWizDialogSetup
, OnRecentDocumentSelected
) );
648 m_pGeneralPage
->SetChooseDocumentHandler(LINK( this, ODbTypeWizDialogSetup
, OnSingleDocumentChosen
) );
651 case PAGE_DBSETUPWIZARD_DBASE
:
652 pPage
= OConnectionTabPageSetup::CreateDbaseTabPage(this,*m_pOutSet
);
655 case PAGE_DBSETUPWIZARD_ADO
:
656 pPage
= OConnectionTabPageSetup::CreateADOTabPage( this, *m_pOutSet
);
659 case PAGE_DBSETUPWIZARD_TEXT
:
660 pPage
= OTextConnectionPageSetup::CreateTextTabPage(this,*m_pOutSet
);
663 case PAGE_DBSETUPWIZARD_ODBC
:
664 pPage
= OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet
);
667 case PAGE_DBSETUPWIZARD_JDBC
:
668 pPage
= OJDBCConnectionPageSetup::CreateJDBCTabPage( this, *m_pOutSet
);
671 case PAGE_DBSETUPWIZARD_MYSQL_ODBC
:
672 m_pOutSet
->Put(SfxStringItem(DSID_CONNECTURL
, m_pCollection
->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:")))));
673 pPage
= OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet
);
676 case PAGE_DBSETUPWIZARD_MYSQL_JDBC
:
677 m_pOutSet
->Put(SfxStringItem(DSID_CONNECTURL
, m_pCollection
->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:")))));
678 pPage
= OGeneralSpecialJDBCConnectionPageSetup::CreateMySQLJDBCTabPage( this, *m_pOutSet
);
680 case PAGE_DBSETUPWIZARD_MYSQL_NATIVE
:
681 m_pOutSet
->Put(SfxStringItem(DSID_CONNECTURL
, m_pCollection
->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:")))));
682 pPage
= MySQLNativeSetupPage::Create( this, *m_pOutSet
);
685 case PAGE_DBSETUPWIZARD_ORACLE
:
686 pPage
= OGeneralSpecialJDBCConnectionPageSetup::CreateOracleJDBCTabPage( this, *m_pOutSet
);
689 case PAGE_DBSETUPWIZARD_ADABAS
:
690 pPage
= OConnectionTabPageSetup::CreateAdabasTabPage( this, *m_pOutSet
);
693 case PAGE_DBSETUPWIZARD_LDAP
:
694 pPage
= OLDAPConnectionPageSetup::CreateLDAPTabPage(this,*m_pOutSet
);
697 case PAGE_DBSETUPWIZARD_SPREADSHEET
: /// first user defined driver
698 pPage
= OSpreadSheetConnectionPageSetup::CreateSpreadSheetTabPage(this,*m_pOutSet
);
701 case PAGE_DBSETUPWIZARD_MSACCESS
:
702 pPage
= OConnectionTabPageSetup::CreateMSAccessTabPage(this,*m_pOutSet
);
704 case PAGE_DBSETUPWIZARD_MYSQL_INTRO
:
705 m_pMySQLIntroPage
= OMySQLIntroPageSetup::CreateMySQLIntroTabPage(this,*m_pOutSet
);
706 m_pMySQLIntroPage
->SetClickHdl(LINK( this, ODbTypeWizDialogSetup
, ImplClickHdl
) );
707 pPage
= m_pMySQLIntroPage
;
710 case PAGE_DBSETUPWIZARD_AUTHENTIFICATION
:
711 pPage
= OAuthentificationPageSetup::CreateAuthentificationTabPage(this,*m_pOutSet
);
714 case PAGE_DBSETUPWIZARD_USERDEFINED
:
715 pPage
= OConnectionTabPageSetup::CreateUserDefinedTabPage(this,*m_pOutSet
);
718 case PAGE_DBSETUPWIZARD_FINAL
:
719 pPage
= OFinalDBPageSetup::CreateFinalDBTabPageSetup(this,*m_pOutSet
);
720 pFinalPage
= static_cast<OFinalDBPageSetup
*> (pPage
);
724 if ((_nState
!= PAGE_DBSETUPWIZARD_INTRO
) && (_nState
!= PAGE_DBSETUPWIZARD_AUTHENTIFICATION
))
726 pPage
->SetModifiedHandler(LINK( this, ODbTypeWizDialogSetup
, ImplModifiedHdl
) );
731 pPage
->SetServiceFactory(m_pImpl
->getORB());
732 pPage
->SetAdminDialog(this, this);
734 defaultButton( _nState
== PAGE_DBSETUPWIZARD_FINAL
? WZB_FINISH
: WZB_NEXT
);
735 enableButtons( WZB_FINISH
, _nState
== PAGE_DBSETUPWIZARD_FINAL
);
736 enableButtons( WZB_NEXT
, _nState
== PAGE_DBSETUPWIZARD_FINAL
? sal_False
: sal_True
);
743 IMPL_LINK(ODbTypeWizDialogSetup
, ImplModifiedHdl
, OGenericAdministrationPage
*, _pConnectionPageSetup
)
745 m_bIsConnectable
= _pConnectionPageSetup
->GetRoadmapStateValue( );
746 enableState(PAGE_DBSETUPWIZARD_FINAL
, m_bIsConnectable
);
747 enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION
, m_bIsConnectable
);
748 if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL
)
749 enableButtons( WZB_FINISH
, sal_True
);
751 enableButtons( WZB_FINISH
, m_bIsConnectable
);
752 enableButtons( WZB_NEXT
, m_bIsConnectable
&& (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL
));
757 // -----------------------------------------------------------------------------
758 IMPL_LINK(ODbTypeWizDialogSetup
, ImplClickHdl
, OMySQLIntroPageSetup
*, _pMySQLIntroPageSetup
)
760 ::rtl::OUString sURLPrefix
;
761 switch( _pMySQLIntroPageSetup
->getMySQLMode() )
763 case OMySQLIntroPageSetup::VIA_ODBC
:
764 sURLPrefix
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
766 case OMySQLIntroPageSetup::VIA_JDBC
:
767 sURLPrefix
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
769 case OMySQLIntroPageSetup::VIA_NATIVE
:
770 sURLPrefix
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
772 } // switch( _pMySQLIntroPageSetup->getMySQLMode() )
773 activatePath( static_cast<PathId
>(m_pCollection
->getIndexOf(sURLPrefix
) + 1), sal_True
);
777 // -----------------------------------------------------------------------------
778 IMPL_LINK(ODbTypeWizDialogSetup
, OnChangeCreationMode
, OGeneralPage
*, /*_pGeneralPage*/)
780 activateDatabasePath();
784 // -----------------------------------------------------------------------------
785 IMPL_LINK(ODbTypeWizDialogSetup
, OnRecentDocumentSelected
, OGeneralPage
*, /*_pGeneralPage*/)
787 enableButtons( WZB_FINISH
, m_pGeneralPage
->GetSelectedDocument().sURL
.Len() != 0 );
791 // -----------------------------------------------------------------------------
792 IMPL_LINK(ODbTypeWizDialogSetup
, OnSingleDocumentChosen
, OGeneralPage
*, /*_pGeneralPage*/)
794 if ( prepareLeaveCurrentState( eFinish
) )
799 // -----------------------------------------------------------------------------
800 void ODbTypeWizDialogSetup::enterState(WizardState _nState
)
802 m_sURL
= m_pImpl
->getDatasourceType(*m_pOutSet
);
803 RoadmapWizard::enterState(_nState
);
806 case PAGE_DBSETUPWIZARD_INTRO
:
809 case PAGE_DBSETUPWIZARD_FINAL
:
810 enableButtons( WZB_FINISH
, sal_True
);
812 pFinalPage
->enableTableWizardCheckBox(m_pCollection
->supportsTableCreation(m_sURL
));
817 //-------------------------------------------------------------------------
818 sal_Bool
ODbTypeWizDialogSetup::saveDatasource()
820 SfxTabPage
* pPage
= static_cast<SfxTabPage
*>(WizardDialog::GetPage(getCurrentState()));
822 pPage
->FillItemSet(*m_pOutSet
);
827 // -----------------------------------------------------------------------------
828 sal_Bool
ODbTypeWizDialogSetup::leaveState(WizardState _nState
)
830 if (_nState
== PAGE_DBSETUPWIZARD_MYSQL_INTRO
)
832 if ( _nState
== PAGE_DBSETUPWIZARD_INTRO
&& m_sURL
!= m_sOldURL
)
834 resetPages(m_pImpl
->getCurrentDataSource());
836 SfxTabPage
* pPage
= static_cast<SfxTabPage
*>(WizardDialog::GetPage(_nState
));
837 return pPage
&& pPage
->DeactivatePage(m_pOutSet
) != 0;
840 // -----------------------------------------------------------------------------
841 void ODbTypeWizDialogSetup::setTitle(const ::rtl::OUString
& /*_sTitle*/)
843 DBG_ERROR( "ODbTypeWizDialogSetup::setTitle: not implemented!" );
847 //-------------------------------------------------------------------------
848 void ODbTypeWizDialogSetup::enableConfirmSettings( bool _bEnable
)
853 //-------------------------------------------------------------------------
856 bool lcl_handle( const Reference
< XInteractionHandler2
>& _rxHandler
, const Any
& _rRequest
)
858 OInteractionRequest
* pRequest
= new OInteractionRequest( _rRequest
);
859 Reference
< XInteractionRequest
> xRequest( pRequest
);
860 OInteractionAbort
* pAbort
= new OInteractionAbort
;
861 pRequest
->addContinuation( pAbort
);
863 return _rxHandler
->handleInteractionRequest( xRequest
);
867 //-------------------------------------------------------------------------
868 sal_Bool
ODbTypeWizDialogSetup::SaveDatabaseDocument()
870 Reference
< XInteractionHandler2
> xHandler( getORB()->createInstance( SERVICE_TASK_INTERACTION_HANDLER
), UNO_QUERY
);
873 if (callSaveAsDialog() == sal_True
)
875 m_pImpl
->saveChanges(*m_pOutSet
);
876 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
877 Reference
< XModel
> xModel( getDataSourceOrModel( xDatasource
), UNO_QUERY_THROW
);
878 Reference
< XStorable
> xStore( xModel
, UNO_QUERY_THROW
);
880 if ( m_pGeneralPage
->GetDatabaseCreationMode() == OGeneralPage::eCreateNew
)
883 ::comphelper::NamedValueCollection
aArgs( xModel
->getArgs() );
884 aArgs
.put( "Overwrite", sal_Bool( sal_True
) );
885 aArgs
.put( "InteractionHandler", xHandler
);
886 aArgs
.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG
);
888 ::rtl::OUString sPath
= m_pImpl
->getDocumentUrl( *m_pOutSet
);
889 xStore
->storeAsURL( sPath
, aArgs
.getPropertyValues() );
891 if ( !pFinalPage
|| pFinalPage
->IsDatabaseDocumentToBeRegistered() )
892 RegisterDataSourceByLocation( sPath
);
897 catch ( const Exception
& e
)
899 Any aError
= ::cppu::getCaughtException();
902 if ( !lcl_handle( xHandler
, aError
) )
904 InteractiveIOException aRequest
;
905 aRequest
.Classification
= InteractionClassification_ERROR
;
906 if ( aError
.isExtractableTo( ::cppu::UnoType
< IOException
>::get() ) )
907 // assume savint the document faile
908 aRequest
.Code
= IOErrorCode_CANT_WRITE
;
910 aRequest
.Code
= IOErrorCode_GENERAL
;
911 aRequest
.Message
= e
.Message
;
912 aRequest
.Context
= e
.Context
;
913 lcl_handle( xHandler
, makeAny( aRequest
) );
919 // ------------------------------------------------------------------------
920 sal_Bool
ODbTypeWizDialogSetup::IsDatabaseDocumentToBeOpened() const
922 if ( m_pGeneralPage
->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting
)
925 if ( pFinalPage
!= NULL
)
926 return pFinalPage
->IsDatabaseDocumentToBeOpened();
931 // ------------------------------------------------------------------------
932 sal_Bool
ODbTypeWizDialogSetup::IsTableWizardToBeStarted() const
934 if ( m_pGeneralPage
->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting
)
937 if ( pFinalPage
!= NULL
)
938 return pFinalPage
->IsTableWizardToBeStarted();
943 //-------------------------------------------------------------------------
944 ::rtl::OUString
ODbTypeWizDialogSetup::getDefaultDatabaseType() const
946 ::rtl::OUString sEmbeddedURL
= m_pCollection
->getEmbeddedDatabase();
947 ::connectivity::DriversConfig
aDriverConfig(getORB());
948 if ( !aDriverConfig
.getDriverFactoryName(sEmbeddedURL
).getLength() )
949 sEmbeddedURL
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:"));
954 //-------------------------------------------------------------------------
955 void ODbTypeWizDialogSetup::CreateDatabase()
957 ::rtl::OUString sUrl
;
958 ::rtl::OUString eType
= getDefaultDatabaseType();
959 if ( m_pCollection
->isEmbeddedDatabase(eType
) )
962 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
963 OSL_ENSURE(xDatasource
.is(),"DataSource is null!");
964 if ( xDatasource
.is() )
965 xDatasource
->setPropertyValue( PROPERTY_INFO
, makeAny( m_pCollection
->getDefaultDBSettings( eType
) ) );
966 m_pImpl
->translateProperties(xDatasource
,*m_pOutSet
);
968 else if ( m_pCollection
->isFileSystemBased(eType
) )
970 Reference
< XSimpleFileAccess
> xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY
);
971 INetURLObject
aDBPathURL(m_sWorkPath
);
972 aDBPathURL
.Append(m_aDocURL
.getBase());
973 createUniqueFolderName(&aDBPathURL
);
974 ::rtl::OUString sPrefix
= eType
;
975 sUrl
= aDBPathURL
.GetMainURL( INetURLObject::NO_DECODE
);
976 xSimpleFileAccess
->createFolder(sUrl
);
977 //OFileNotation aFileNotation(sUrl);
978 //sUrl = aFileNotation.get(OFileNotation::N_SYSTEM);
979 sUrl
= sPrefix
.concat(sUrl
);
981 m_pOutSet
->Put(SfxStringItem(DSID_CONNECTURL
, sUrl
));
982 m_pImpl
->saveChanges(*m_pOutSet
);
985 //-------------------------------------------------------------------------
986 void ODbTypeWizDialogSetup::RegisterDataSourceByLocation(const ::rtl::OUString
& _sPath
)
988 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
989 Reference
< XNamingService
> xDatabaseContext(getORB()->createInstance(SERVICE_SDB_DATABASECONTEXT
), UNO_QUERY
);
990 Reference
< XNameAccess
> xNameAccessDatabaseContext(xDatabaseContext
, UNO_QUERY
);
991 INetURLObject
aURL( _sPath
);
992 ::rtl::OUString sFilename
= aURL
.getBase( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
);
993 ::rtl::OUString sDatabaseName
= ::dbtools::createUniqueName(xNameAccessDatabaseContext
, sFilename
,sal_False
);
994 xDatabaseContext
->registerObject(sDatabaseName
, xDatasource
);
998 //-------------------------------------------------------------------------
999 sal_Bool
ODbTypeWizDialogSetup::callSaveAsDialog()
1001 sal_Bool bRet
= sal_False
;
1002 WinBits
nBits(WB_STDMODAL
|WB_SAVEAS
);
1003 ::sfx2::FileDialogHelper
aFileDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION
, static_cast<sal_uInt32
>(nBits
), this);
1004 const SfxFilter
* pFilter
= getStandardDatabaseFilter();
1007 INetURLObject
aWorkURL( m_sWorkPath
);
1008 aFileDlg
.SetDisplayFolder( aWorkURL
.GetMainURL( INetURLObject::NO_DECODE
));
1010 ::rtl::OUString sDefaultName
= String( ModuleRes( STR_DATABASEDEFAULTNAME
) );
1011 ::rtl::OUString sExtension
= pFilter
->GetDefaultExtension();
1012 sDefaultName
+= sExtension
.replaceAt( 0, 1, ::rtl::OUString() );
1013 aWorkURL
.Append( sDefaultName
);
1014 sDefaultName
= createUniqueFileName( aWorkURL
);
1015 aFileDlg
.SetFileName( sDefaultName
);
1017 aFileDlg
.AddFilter(pFilter
->GetUIName(),pFilter
->GetDefaultExtension());
1018 aFileDlg
.SetCurrentFilter(pFilter
->GetUIName());
1020 if ( aFileDlg
.Execute() == ERRCODE_NONE
)
1022 m_aDocURL
= INetURLObject(aFileDlg
.GetPath());
1024 if( m_aDocURL
.GetProtocol() != INET_PROT_NOT_VALID
)
1026 ::rtl::OUString sFileName
= m_aDocURL
.GetMainURL( INetURLObject::NO_DECODE
);
1027 if ( ::utl::UCBContentHelper::IsDocument(sFileName
) )
1028 ::utl::UCBContentHelper::Kill(sFileName
);
1029 m_pOutSet
->Put(SfxStringItem(DSID_DOCUMENT_URL
, sFileName
));
1036 //-------------------------------------------------------------------------
1037 void ODbTypeWizDialogSetup::createUniqueFolderName(INetURLObject
* pURL
)
1039 Reference
< XSimpleFileAccess
> xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY
);
1040 :: rtl::OUString sLastSegmentName
= pURL
->getName();
1041 sal_Bool bFolderExists
= sal_True
;
1043 while (bFolderExists
== sal_True
)
1045 bFolderExists
= xSimpleFileAccess
->isFolder(pURL
->GetMainURL( INetURLObject::NO_DECODE
));
1046 if (bFolderExists
== sal_True
)
1049 pURL
->setName(sLastSegmentName
.concat(::rtl::OUString::valueOf(i
)));
1054 //-------------------------------------------------------------------------
1055 String
ODbTypeWizDialogSetup::createUniqueFileName(const INetURLObject
& _rURL
)
1057 Reference
< XSimpleFileAccess
> xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY
);
1058 :: rtl::OUString sFilename
= _rURL
.getName();
1059 ::rtl::OUString BaseName
= _rURL
.getBase();
1060 ::rtl::OUString sExtension
= _rURL
.getExtension();
1062 sal_Bool bElementExists
= sal_True
;
1064 INetURLObject
aExistenceCheck( _rURL
);
1065 for ( sal_Int32 i
= 1; bElementExists
; )
1067 bElementExists
= xSimpleFileAccess
->exists( aExistenceCheck
.GetMainURL( INetURLObject::NO_DECODE
) );
1068 if ( bElementExists
)
1070 aExistenceCheck
.setBase( BaseName
.concat( ::rtl::OUString::valueOf( i
) ) );
1074 return aExistenceCheck
.getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
);
1076 // -----------------------------------------------------------------------------
1077 IWizardPage
* ODbTypeWizDialogSetup::getWizardPage(TabPage
* _pCurrentPage
) const
1079 OGenericAdministrationPage
* pPage
= static_cast<OGenericAdministrationPage
*>(_pCurrentPage
);
1083 // -----------------------------------------------------------------------------
1086 // .............................................................................
1087 typedef ::cppu::WeakImplHelper1
< XTerminateListener
1089 class AsyncLoader
: public AsyncLoader_Base
1092 Reference
< XComponentLoader
> m_xFrameLoader
;
1093 Reference
< XDesktop
> m_xDesktop
;
1094 Reference
< XInteractionHandler
> m_xInteractionHandler
;
1095 ::rtl::OUString m_sURL
;
1096 OAsyncronousLink m_aAsyncCaller
;
1099 AsyncLoader( const Reference
< XMultiServiceFactory
>& _rxORB
, const ::rtl::OUString
& _rURL
);
1103 // XTerminateListener
1104 virtual void SAL_CALL
queryTermination( const EventObject
& Event
) throw (TerminationVetoException
, RuntimeException
);
1105 virtual void SAL_CALL
notifyTermination( const EventObject
& Event
) throw (RuntimeException
);
1107 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
);
1110 DECL_LINK( OnOpenDocument
, void* );
1113 // .............................................................................
1114 AsyncLoader::AsyncLoader( const Reference
< XMultiServiceFactory
>& _rxORB
, const ::rtl::OUString
& _rURL
)
1116 ,m_aAsyncCaller( LINK( this, AsyncLoader
, OnOpenDocument
) )
1120 m_xDesktop
.set( _rxORB
->createInstance( SERVICE_FRAME_DESKTOP
), UNO_QUERY_THROW
);
1121 m_xFrameLoader
.set( m_xDesktop
, UNO_QUERY_THROW
);
1122 m_xInteractionHandler
.set(
1123 _rxORB
->createInstance(
1124 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.InteractionHandler" ) )
1128 catch( const Exception
& )
1130 DBG_UNHANDLED_EXCEPTION();
1134 // .............................................................................
1135 void AsyncLoader::doLoadAsync()
1137 OSL_ENSURE( !m_aAsyncCaller
.IsRunning(), "AsyncLoader:doLoadAsync: already running!" );
1142 if ( m_xDesktop
.is() )
1143 m_xDesktop
->addTerminateListener( this );
1145 catch( const Exception
& ) { DBG_UNHANDLED_EXCEPTION(); }
1147 m_aAsyncCaller
.Call( NULL
);
1150 // .............................................................................
1151 IMPL_LINK( AsyncLoader
, OnOpenDocument
, void*, /*_pEmptyArg*/ )
1155 if ( m_xFrameLoader
.is() )
1157 ::comphelper::NamedValueCollection aLoadArgs
;
1158 aLoadArgs
.put( "InteractionHandler", m_xInteractionHandler
);
1159 aLoadArgs
.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG
);
1161 Sequence
< PropertyValue
> aLoadArgPV
;
1162 aLoadArgs
>>= aLoadArgPV
;
1164 m_xFrameLoader
->loadComponentFromURL( m_sURL
,
1165 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ),
1166 FrameSearchFlag::ALL
,
1171 catch( const Exception
& )
1174 // Such an exception happens for instance of the to-be-loaded document does not exist anymore.
1179 if ( m_xDesktop
.is() )
1180 m_xDesktop
->removeTerminateListener( this );
1182 catch( const Exception
& ) { DBG_UNHANDLED_EXCEPTION(); }
1188 // .............................................................................
1189 void SAL_CALL
AsyncLoader::queryTermination( const EventObject
& /*Event*/ ) throw (TerminationVetoException
, RuntimeException
)
1191 throw TerminationVetoException();
1194 // .............................................................................
1195 void SAL_CALL
AsyncLoader::notifyTermination( const EventObject
& /*Event*/ ) throw (RuntimeException
)
1198 // .............................................................................
1199 void SAL_CALL
AsyncLoader::disposing( const EventObject
& /*Source*/ ) throw (RuntimeException
)
1204 // -----------------------------------------------------------------------------
1205 sal_Bool
ODbTypeWizDialogSetup::onFinish(sal_Int32 _nResult
)
1207 if ( m_pGeneralPage
->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting
)
1209 // we're not going to re-use the XModel we have - since the document the user
1210 // wants us to load could be a non-database document. Instead, we asynchronously
1211 // open the selected document. Thus, the wizard's return value is RET_CANCEL,
1212 // which means to not continue loading the database document
1213 if ( !OWizardMachine::onFinish( RET_CANCEL
) )
1216 Reference
< XComponentLoader
> xFrameLoader
;
1219 AsyncLoader
* pAsyncLoader
= new AsyncLoader( getORB(), m_pGeneralPage
->GetSelectedDocument().sURL
);
1220 ::rtl::Reference
< AsyncLoader
> xKeepAlive( pAsyncLoader
);
1221 pAsyncLoader
->doLoadAsync();
1223 catch( const Exception
& )
1225 DBG_UNHANDLED_EXCEPTION();
1231 if (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL
)
1233 skipUntil(PAGE_DBSETUPWIZARD_FINAL
);
1235 if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL
)
1236 return SaveDatabaseDocument() ? OWizardMachine::onFinish( _nResult
) : sal_False
;
1239 enableButtons( WZB_FINISH
, sal_False
);
1244 //.........................................................................
1245 } // namespace dbaui
1246 //.........................................................................