merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / dlg / UserAdminDlg.cxx
blob642b431bc565539279277a90ce08042df3b588fe
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: UserAdminDlg.cxx,v $
10 * $Revision: 1.14.68.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 "adminpages.hxx"
35 #include "DbAdminImpl.hxx"
36 #include "dbu_dlg.hrc"
37 #include "DriverSettings.hxx"
38 #include "dsitems.hxx"
39 #include "propertysetitem.hxx"
40 #include "UITools.hxx"
41 #include "UserAdmin.hxx"
42 #include "UserAdminDlg.hrc"
43 #include "UserAdminDlg.hxx"
45 #include <comphelper/componentcontext.hxx>
46 #include <connectivity/dbmetadata.hxx>
47 #include <cppuhelper/exc_hlp.hxx>
48 #include <svtools/eitem.hxx>
49 #include <svtools/intitem.hxx>
50 #include <svtools/stritem.hxx>
51 #include <tools/diagnose_ex.h>
52 #include <vcl/msgbox.hxx>
53 #include <vcl/stdtext.hxx>
55 //.........................................................................
56 namespace dbaui
58 //.........................................................................
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::sdbc;
63 using namespace ::com::sun::star::sdbcx;
65 //========================================================================
66 //= OUserAdminDlg
67 DBG_NAME(OUserAdminDlg)
68 //========================================================================
69 OUserAdminDlg::OUserAdminDlg(Window* _pParent
70 , SfxItemSet* _pItems
71 ,const Reference< XMultiServiceFactory >& _rxORB
72 ,const ::com::sun::star::uno::Any& _aDataSourceName
73 ,const Reference< XConnection >& _xConnection)
74 :SfxTabDialog(_pParent, ModuleRes(DLG_DATABASE_USERADMIN), _pItems)
75 ,m_pItemSet(_pItems)
76 ,m_xConnection(_xConnection)
77 ,m_bOwnConnection(!_xConnection.is())
79 DBG_CTOR(OUserAdminDlg,NULL);
81 m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,_pParent,this));
82 m_pImpl->setDataSourceOrName(_aDataSourceName);
83 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
84 m_pImpl->translateProperties(xDatasource, *_pItems);
85 SetInputSet(_pItems);
86 // propagate this set as our new input set and reset the example set
87 delete pExampleSet;
88 pExampleSet = new SfxItemSet(*GetInputSetImpl());
90 AddTabPage(TAB_PAGE_USERADMIN, String(ModuleRes(STR_PAGETITLE_USERADMIN)), OUserAdmin::Create,0, sal_False, 1);
92 // remove the reset button - it's meaning is much too ambiguous in this dialog
93 RemoveResetButton();
94 FreeResource();
97 // -----------------------------------------------------------------------
98 OUserAdminDlg::~OUserAdminDlg()
100 if ( m_bOwnConnection )
103 ::comphelper::disposeComponent(m_xConnection);
105 catch(Exception){}
107 SetInputSet(NULL);
108 DELETEZ(pExampleSet);
110 DBG_DTOR(OUserAdminDlg,NULL);
112 // -----------------------------------------------------------------------
113 short OUserAdminDlg::Execute()
117 ::dbtools::DatabaseMetaData aMetaData( createConnection().first );
118 if ( !aMetaData.supportsUserAdministration( ::comphelper::ComponentContext( getORB() ) ) )
120 String sError(ModuleRes(STR_USERADMIN_NOT_AVAILABLE));
121 throw SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
124 catch(const SQLException& e)
126 ::dbaui::showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), GetParent(), getORB() );
127 return RET_CANCEL;
129 catch( const Exception& )
131 DBG_UNHANDLED_EXCEPTION();
133 short nRet = SfxTabDialog::Execute();
134 if ( nRet == RET_OK )
135 m_pImpl->saveChanges(*GetOutputItemSet());
136 return nRet;
138 //-------------------------------------------------------------------------
139 void OUserAdminDlg::PageCreated(USHORT _nId, SfxTabPage& _rPage)
141 // register ourself as modified listener
142 static_cast<OGenericAdministrationPage&>(_rPage).SetServiceFactory(m_pImpl->getORB());
143 static_cast<OGenericAdministrationPage&>(_rPage).SetAdminDialog(this,this);
145 AdjustLayout();
146 Window *pWin = GetViewWindow();
147 if(pWin)
148 pWin->Invalidate();
150 SfxTabDialog::PageCreated(_nId, _rPage);
152 // -----------------------------------------------------------------------------
153 const SfxItemSet* OUserAdminDlg::getOutputSet() const
155 return m_pItemSet;
157 // -----------------------------------------------------------------------------
158 SfxItemSet* OUserAdminDlg::getWriteOutputSet()
160 return m_pItemSet;
162 // -----------------------------------------------------------------------------
163 ::std::pair< Reference<XConnection>,sal_Bool> OUserAdminDlg::createConnection()
165 if ( !m_xConnection.is() )
167 m_xConnection = m_pImpl->createConnection().first;
168 m_bOwnConnection = m_xConnection.is();
170 return ::std::pair< Reference<XConnection>,sal_Bool> (m_xConnection,sal_False);
172 // -----------------------------------------------------------------------------
173 Reference< XMultiServiceFactory > OUserAdminDlg::getORB() const
175 return m_pImpl->getORB();
177 // -----------------------------------------------------------------------------
178 Reference< XDriver > OUserAdminDlg::getDriver()
180 return m_pImpl->getDriver();
182 // -----------------------------------------------------------------------------
183 ::rtl::OUString OUserAdminDlg::getDatasourceType(const SfxItemSet& _rSet) const
185 return m_pImpl->getDatasourceType(_rSet);
187 // -----------------------------------------------------------------------------
188 void OUserAdminDlg::clearPassword()
190 m_pImpl->clearPassword();
192 // -----------------------------------------------------------------------------
193 void OUserAdminDlg::setTitle(const ::rtl::OUString& _sTitle)
195 SetText(_sTitle);
197 //-------------------------------------------------------------------------
198 void OUserAdminDlg::enableConfirmSettings( bool _bEnable )
200 (void)_bEnable;
202 //-------------------------------------------------------------------------
203 sal_Bool OUserAdminDlg::saveDatasource()
205 return PrepareLeaveCurrentPage();
207 //.........................................................................
208 } // namespace dbaui
209 //.........................................................................