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: dbadmin.cxx,v $
10 * $Revision: 1.108.18.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 "dsnItem.hxx"
35 #ifndef _DBAUI_DBADMIN_HXX_
36 #include "dbadmin.hxx"
38 #ifndef _DBAUI_DBADMIN_HRC_
39 #include "dbadmin.hrc"
42 #include "dbu_dlg.hrc"
44 #ifndef _DBAUI_DATASOURCEITEMS_HXX_
45 #include "dsitems.hxx"
47 #ifndef _SFXSTRITEM_HXX
48 #include <svtools/stritem.hxx>
50 #ifndef _SFXENUMITEM_HXX
51 #include <svtools/eitem.hxx>
53 #ifndef _SFXINTITEM_HXX
54 #include <svtools/intitem.hxx>
56 #ifndef _SV_MSGBOX_HXX
57 #include <vcl/msgbox.hxx>
59 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
60 #include "dbustrings.hrc"
62 #ifndef _DBAUI_ADMINPAGES_HXX_
63 #include "adminpages.hxx"
65 #ifndef _DBAUI_LOCALRESACCESS_HXX_
66 #include "localresaccess.hxx"
68 #ifndef _DBAUI_STRINGLISTITEM_HXX_
69 #include "stringlistitem.hxx"
71 #ifndef _DBAUI_PROPERTYSETITEM_HXX_
72 #include "propertysetitem.hxx"
74 #ifndef _UNOTOOLS_CONFIGNODE_HXX_
75 #include <unotools/confignode.hxx>
77 #ifndef DBAUI_CONNECTIONPAGE_HXX
78 #include "ConnectionPage.hxx"
80 #ifndef DBAUI_DRIVERSETTINGS_HXX
81 #include "DriverSettings.hxx"
83 #ifndef _DBAUI_DBADMINIMPL_HXX_
84 #include "DbAdminImpl.hxx"
87 //.........................................................................
90 //.........................................................................
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
;
98 //=========================================================================
100 //=========================================================================
101 DBG_NAME(ODbAdminDialog
)
102 //-------------------------------------------------------------------------
103 ODbAdminDialog::ODbAdminDialog(Window
* _pParent
104 , SfxItemSet
* _pItems
105 , const Reference
< XMultiServiceFactory
>& _rxORB
107 :SfxTabDialog(_pParent
, ModuleRes(DLG_DATABASE_ADMINISTRATION
), _pItems
)
108 ,m_bApplied(sal_False
)
109 ,m_bUIEnabled( sal_True
)
110 ,m_nMainPageID( PAGE_CONNECTION
)
112 DBG_CTOR(ODbAdminDialog
,NULL
);
114 m_pImpl
= ::std::auto_ptr
<ODbDataSourceAdministrationHelper
>(new ODbDataSourceAdministrationHelper(_rxORB
,this,this));
116 // add the initial tab page
117 AddTabPage( m_nMainPageID
, String( ModuleRes( STR_PAGETITLE_GENERAL
) ), OConnectionTabPage::Create
, NULL
);
119 // remove the reset button - it's meaning is much too ambiguous in this dialog
121 // no local resources needed anymore
125 //-------------------------------------------------------------------------
126 ODbAdminDialog::~ODbAdminDialog()
129 DELETEZ(pExampleSet
);
131 DBG_DTOR(ODbAdminDialog
,NULL
);
133 //-------------------------------------------------------------------------
134 short ODbAdminDialog::Ok()
138 return ( AR_LEAVE_MODIFIED
== implApplyChanges() ) ? RET_OK
: RET_CANCEL
;
139 // TODO : AR_ERROR is not handled correctly, we always close the dialog here
142 //-------------------------------------------------------------------------
143 void ODbAdminDialog::PageCreated(USHORT _nId
, SfxTabPage
& _rPage
)
145 // register ourself as modified listener
146 static_cast<OGenericAdministrationPage
&>(_rPage
).SetServiceFactory(m_pImpl
->getORB());
147 static_cast<OGenericAdministrationPage
&>(_rPage
).SetAdminDialog(this,this);
150 Window
*pWin
= GetViewWindow();
154 SfxTabDialog::PageCreated(_nId
, _rPage
);
156 // -----------------------------------------------------------------------------
157 void ODbAdminDialog::removeDetailPages()
159 // remove all current detail pages
160 while (m_aCurrentDetailPages
.size())
162 RemoveTabPage((USHORT
)m_aCurrentDetailPages
.top());
163 m_aCurrentDetailPages
.pop();
167 // -----------------------------------------------------------------------------
168 void ODbAdminDialog::addDetailPage(USHORT _nPageId
, USHORT _nTextId
, CreateTabPage _pCreateFunc
)
170 // open our own resource block, as the page titles are strings local to this block
171 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
173 AddTabPage(_nPageId
, String(ModuleRes(_nTextId
)), _pCreateFunc
, NULL
);
174 m_aCurrentDetailPages
.push(_nPageId
);
177 //-------------------------------------------------------------------------
178 void ODbAdminDialog::impl_selectDataSource(const ::com::sun::star::uno::Any
& _aDataSourceName
)
180 m_pImpl
->setDataSourceOrName(_aDataSourceName
);
181 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
182 impl_resetPages( xDatasource
);
184 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, getOutputSet()->GetItem(DSID_TYPECOLLECTION
));
185 ::dbaccess::ODsnTypeCollection
* pCollection
= pCollectionItem
->getCollection();
186 ::dbaccess::DATASOURCE_TYPE eType
= pCollection
->determineType(getDatasourceType(*getOutputSet()));
188 // and insert the new ones
191 case ::dbaccess::DST_DBASE
:
192 addDetailPage(PAGE_DBASE
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateDbase
);
193 // bResetPasswordRequired = sal_True;
196 case ::dbaccess::DST_ADO
:
197 addDetailPage(PAGE_ADO
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateAdo
);
200 case ::dbaccess::DST_FLAT
:
201 addDetailPage(PAGE_TEXT
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateText
);
202 // bResetPasswordRequired = sal_True;
205 case ::dbaccess::DST_ODBC
:
206 addDetailPage(PAGE_ODBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateODBC
);
209 case ::dbaccess::DST_MYSQL_ODBC
:
210 addDetailPage(PAGE_MYSQL_ODBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateMySQLODBC
);
213 case ::dbaccess::DST_MYSQL_JDBC
:
214 addDetailPage(PAGE_MYSQL_JDBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateMySQLJDBC
);
217 case ::dbaccess::DST_ORACLE_JDBC
:
218 addDetailPage(PAGE_ORACLE_JDBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateOracleJDBC
);
221 case ::dbaccess::DST_ADABAS
:
222 // for adabas we have more than one page
223 // CAUTION: the order of inserting pages matters.
224 // the major detail page should be inserted last always (thus, it becomes the first page after
226 addDetailPage(PAGE_ADABAS
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateAdabas
);
229 case ::dbaccess::DST_LDAP
:
230 addDetailPage(PAGE_LDAP
,STR_PAGETITLE_ADVANCED
,ODriversSettings::CreateLDAP
);
232 case ::dbaccess::DST_USERDEFINE1
: /// first user defined driver
233 case ::dbaccess::DST_USERDEFINE2
:
234 case ::dbaccess::DST_USERDEFINE3
:
235 case ::dbaccess::DST_USERDEFINE4
:
236 case ::dbaccess::DST_USERDEFINE5
:
237 case ::dbaccess::DST_USERDEFINE6
:
238 case ::dbaccess::DST_USERDEFINE7
:
239 case ::dbaccess::DST_USERDEFINE8
:
240 case ::dbaccess::DST_USERDEFINE9
:
241 case ::dbaccess::DST_USERDEFINE10
:
243 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
244 String
aTitle(ModuleRes(STR_PAGETITLE_ADVANCED
));
245 AddTabPage(PAGE_USERDRIVER
, aTitle
, ODriversSettings::CreateUser
, 0, sal_False
, 1);
246 m_aCurrentDetailPages
.push(PAGE_USERDRIVER
);
254 //-------------------------------------------------------------------------
255 void ODbAdminDialog::impl_resetPages(const Reference
< XPropertySet
>& _rxDatasource
)
257 // the selection is valid if and only if we have a datasource now
258 GetInputSetImpl()->Put(SfxBoolItem(DSID_INVALID_SELECTION
, !_rxDatasource
.is()));
259 // (sal_False tells the tab pages to disable and reset all their controls, which is different
260 // from "just set them to readonly")
265 SetUpdateMode(sal_False
);
267 // remove all items which relate to indirect properties from the input set
268 // (without this, the following may happen: select an arbitrary data source where some indirect properties
269 // are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
270 // the indirect property values of the first ds are shown in the second ds ...)
271 const ODbDataSourceAdministrationHelper::MapInt2String
& rMap
= m_pImpl
->getIndirectProperties();
272 for ( ODbDataSourceAdministrationHelper::ConstMapInt2StringIterator aIndirect
= rMap
.begin();
273 aIndirect
!= rMap
.end();
276 GetInputSetImpl()->ClearItem( (sal_uInt16
)aIndirect
->first
);
278 // extract all relevant data from the property set of the data source
279 m_pImpl
->translateProperties(_rxDatasource
, *GetInputSetImpl());
281 // propagate this set as our new input set and reset the example set
282 SetInputSet(GetInputSetImpl());
284 pExampleSet
= new SfxItemSet(*GetInputSetImpl());
286 // special case: MySQL Native does not have the generic PAGE_CONNECTION page
288 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, getOutputSet()->GetItem(DSID_TYPECOLLECTION
));
289 ::dbaccess::ODsnTypeCollection
* pCollection
= pCollectionItem
->getCollection();
290 if ( pCollection
->determineType(getDatasourceType( *pExampleSet
)) == ::dbaccess::DST_MYSQL_NATIVE
)
292 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
293 AddTabPage( PAGE_MYSQL_NATIVE
, String( ModuleRes( STR_PAGETITLE_CONNECTION
) ), ODriversSettings::CreateMySQLNATIVE
, NULL
);
294 RemoveTabPage( PAGE_CONNECTION
);
295 m_nMainPageID
= PAGE_MYSQL_NATIVE
;
298 ShowPage( m_nMainPageID
);
299 SfxTabPage
* pConnectionPage
= GetTabPage( m_nMainPageID
);
300 if ( pConnectionPage
)
301 pConnectionPage
->Reset(*GetInputSetImpl());
302 // if this is NULL, the page has not been created yet, which means we're called before the
303 // dialog was displayed (probably from inside the ctor)
305 SetUpdateMode(sal_True
);
307 // -----------------------------------------------------------------------------
308 void ODbAdminDialog::setTitle(const ::rtl::OUString
& _sTitle
)
312 //-------------------------------------------------------------------------
313 void ODbAdminDialog::enableConfirmSettings( bool _bEnable
)
317 //-------------------------------------------------------------------------
318 sal_Bool
ODbAdminDialog::saveDatasource()
320 return PrepareLeaveCurrentPage();
322 //-------------------------------------------------------------------------
323 ODbAdminDialog::ApplyResult
ODbAdminDialog::implApplyChanges()
325 if (!PrepareLeaveCurrentPage())
326 { // the page did not allow us to leave
330 if ( !m_pImpl
->saveChanges(*pExampleSet
) )
334 ShowPage(GetCurPageId());
335 // This does the usual ActivatePage, so the pages can save their current status.
336 // This way, next time they're asked what has changed since now and here, they really
337 // can compare with the status they have _now_ (not the one they had before this apply call).
339 m_bApplied
= sal_True
;
341 return AR_LEAVE_MODIFIED
;
343 //-------------------------------------------------------------------------
344 void ODbAdminDialog::selectDataSource(const ::com::sun::star::uno::Any
& _aDataSourceName
)
346 impl_selectDataSource(_aDataSourceName
);
349 // -----------------------------------------------------------------------------
350 const SfxItemSet
* ODbAdminDialog::getOutputSet() const
352 return GetExampleSet();
354 // -----------------------------------------------------------------------------
355 SfxItemSet
* ODbAdminDialog::getWriteOutputSet()
359 // -----------------------------------------------------------------------------
360 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbAdminDialog::createConnection()
362 return m_pImpl
->createConnection();
364 // -----------------------------------------------------------------------------
365 Reference
< XMultiServiceFactory
> ODbAdminDialog::getORB() const
367 return m_pImpl
->getORB();
369 // -----------------------------------------------------------------------------
370 Reference
< XDriver
> ODbAdminDialog::getDriver()
372 return m_pImpl
->getDriver();
374 // -----------------------------------------------------------------------------
375 ::rtl::OUString
ODbAdminDialog::getDatasourceType(const SfxItemSet
& _rSet
) const
377 return m_pImpl
->getDatasourceType(_rSet
);
379 // -----------------------------------------------------------------------------
380 void ODbAdminDialog::clearPassword()
382 m_pImpl
->clearPassword();
384 //-------------------------------------------------------------------------
385 SfxItemSet
* ODbAdminDialog::createItemSet(SfxItemSet
*& _rpSet
, SfxItemPool
*& _rpPool
, SfxPoolItem
**& _rppDefaults
, ::dbaccess::ODsnTypeCollection
* _pTypeCollection
)
387 // just to be sure ....
392 const ::rtl::OUString
sFilterAll( "%", 1, RTL_TEXTENCODING_ASCII_US
);
393 // create and initialize the defaults
394 _rppDefaults
= new SfxPoolItem
*[DSID_LAST_ITEM_ID
- DSID_FIRST_ITEM_ID
+ 1];
395 SfxPoolItem
** pCounter
= _rppDefaults
; // want to modify this without affecting the out param _rppDefaults
396 *pCounter
++ = new SfxStringItem(DSID_NAME
, String());
397 *pCounter
++ = new SfxStringItem(DSID_ORIGINALNAME
, String());
398 *pCounter
++ = new SfxStringItem(DSID_CONNECTURL
, String());
399 *pCounter
++ = new OStringListItem(DSID_TABLEFILTER
, Sequence
< ::rtl::OUString
>(&sFilterAll
, 1));
400 *pCounter
++ = new DbuTypeCollectionItem(DSID_TYPECOLLECTION
, _pTypeCollection
);
401 *pCounter
++ = new SfxBoolItem(DSID_INVALID_SELECTION
, sal_False
);
402 *pCounter
++ = new SfxBoolItem(DSID_READONLY
, sal_False
);
403 *pCounter
++ = new SfxStringItem(DSID_USER
, String());
404 *pCounter
++ = new SfxStringItem(DSID_PASSWORD
, String());
405 *pCounter
++ = new SfxStringItem(DSID_ADDITIONALOPTIONS
, String());
406 *pCounter
++ = new SfxStringItem(DSID_CHARSET
, String());
407 *pCounter
++ = new SfxBoolItem(DSID_PASSWORDREQUIRED
, sal_False
);
408 *pCounter
++ = new SfxBoolItem(DSID_SHOWDELETEDROWS
, sal_False
);
409 *pCounter
++ = new SfxBoolItem(DSID_ALLOWLONGTABLENAMES
, sal_False
);
410 *pCounter
++ = new SfxStringItem(DSID_JDBCDRIVERCLASS
, String());
411 *pCounter
++ = new SfxStringItem(DSID_FIELDDELIMITER
, ',');
412 *pCounter
++ = new SfxStringItem(DSID_TEXTDELIMITER
, '"');
413 *pCounter
++ = new SfxStringItem(DSID_DECIMALDELIMITER
, '.');
414 *pCounter
++ = new SfxStringItem(DSID_THOUSANDSDELIMITER
, String());
415 *pCounter
++ = new SfxStringItem(DSID_TEXTFILEEXTENSION
, String::CreateFromAscii("txt"));
416 *pCounter
++ = new SfxBoolItem(DSID_TEXTFILEHEADER
, sal_True
);
417 *pCounter
++ = new SfxBoolItem(DSID_PARAMETERNAMESUBST
, sal_False
);
418 *pCounter
++ = new SfxInt32Item(DSID_CONN_PORTNUMBER
, 8100);
419 *pCounter
++ = new SfxBoolItem(DSID_SUPPRESSVERSIONCL
, sal_False
);
420 *pCounter
++ = new OPropertySetItem(DSID_DATASOURCE_UNO
);
421 *pCounter
++ = new SfxBoolItem(DSID_CONN_SHUTSERVICE
, sal_False
);
422 *pCounter
++ = new SfxInt32Item(DSID_CONN_DATAINC
, 20);
423 *pCounter
++ = new SfxInt32Item(DSID_CONN_CACHESIZE
, 20);
424 *pCounter
++ = new SfxStringItem(DSID_CONN_CTRLUSER
, String());
425 *pCounter
++ = new SfxStringItem(DSID_CONN_CTRLPWD
, String());
426 *pCounter
++ = new SfxBoolItem(DSID_USECATALOG
, sal_False
);
427 *pCounter
++ = new SfxStringItem(DSID_CONN_HOSTNAME
, String());
428 *pCounter
++ = new SfxStringItem(DSID_CONN_LDAP_BASEDN
, String());
429 *pCounter
++ = new SfxInt32Item(DSID_CONN_LDAP_PORTNUMBER
, 389);
430 *pCounter
++ = new SfxInt32Item(DSID_CONN_LDAP_ROWCOUNT
, 100);
431 *pCounter
++ = new SfxBoolItem(DSID_SQL92CHECK
, sal_False
);
432 *pCounter
++ = new SfxStringItem(DSID_AUTOINCREMENTVALUE
, String());
433 *pCounter
++ = new SfxStringItem(DSID_AUTORETRIEVEVALUE
, String());
434 *pCounter
++ = new SfxBoolItem(DSID_AUTORETRIEVEENABLED
, sal_False
);
435 *pCounter
++ = new SfxBoolItem(DSID_APPEND_TABLE_ALIAS
, sal_False
);
436 *pCounter
++ = new SfxInt32Item(DSID_MYSQL_PORTNUMBER
, 3306);
437 *pCounter
++ = new SfxBoolItem(DSID_IGNOREDRIVER_PRIV
, sal_True
);
438 *pCounter
++ = new SfxInt32Item(DSID_BOOLEANCOMPARISON
, 0);
439 *pCounter
++ = new SfxInt32Item(DSID_ORACLE_PORTNUMBER
, 1521);
440 *pCounter
++ = new SfxBoolItem(DSID_ENABLEOUTERJOIN
, sal_True
);
441 *pCounter
++ = new SfxBoolItem(DSID_CATALOG
, sal_True
);
442 *pCounter
++ = new SfxBoolItem(DSID_SCHEMA
, sal_True
);
443 *pCounter
++ = new SfxBoolItem(DSID_INDEXAPPENDIX
, sal_True
);
444 *pCounter
++ = new SfxBoolItem(DSID_CONN_LDAP_USESSL
, sal_False
);
445 *pCounter
++ = new SfxStringItem(DSID_DOCUMENT_URL
, String());
446 *pCounter
++ = new SfxBoolItem(DSID_DOSLINEENDS
, sal_False
);
447 *pCounter
++ = new SfxStringItem(DSID_DATABASENAME
, String());
448 *pCounter
++ = new SfxBoolItem(DSID_AS_BEFORE_CORRNAME
, sal_True
);
449 *pCounter
++ = new SfxBoolItem(DSID_CHECK_REQUIRED_FIELDS
, sal_True
);
450 *pCounter
++ = new SfxBoolItem(DSID_IGNORECURRENCY
, sal_False
);
451 *pCounter
++ = new SfxStringItem(DSID_CONN_SOCKET
, String());
452 *pCounter
++ = new SfxBoolItem(DSID_ESCAPE_DATETIME
, sal_True
); // must be the same as in ModelImpl.cxx
453 *pCounter
++ = new SfxStringItem(DSID_NAMED_PIPE
, String());
456 static SfxItemInfo __READONLY_DATA aItemInfos
[DSID_LAST_ITEM_ID
- DSID_FIRST_ITEM_ID
+ 1] =
513 {0,0}, /* for Escape DateTime*/
518 OSL_ENSURE(sizeof(aItemInfos
)/sizeof(aItemInfos
[0]) == DSID_LAST_ITEM_ID
,"Invalid Ids!");
519 _rpPool
= new SfxItemPool(String::CreateFromAscii("DSAItemPool"), DSID_FIRST_ITEM_ID
, DSID_LAST_ITEM_ID
,
520 aItemInfos
, _rppDefaults
);
521 _rpPool
->FreezeIdRanges();
523 // and, finally, the set
524 _rpSet
= new SfxItemSet(*_rpPool
, sal_True
);
528 //-------------------------------------------------------------------------
529 void ODbAdminDialog::destroyItemSet(SfxItemSet
*& _rpSet
, SfxItemPool
*& _rpPool
, SfxPoolItem
**& _rppDefaults
)
531 // _first_ delete the set (refering the pool)
541 _rpPool
->ReleaseDefaults(sal_True
);
542 // the "true" means delete the items, too
543 SfxItemPool::Free(_rpPool
);
547 // reset the defaults ptr
549 // no need to explicitly delete the defaults, this has been done by the ReleaseDefaults
552 //.........................................................................
554 //.........................................................................