Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / dlg / UserAdminDlg.cxx
blob3963bc565409b2f4211efdbc58ebfcf314788093
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "adminpages.hxx"
31 #include "DbAdminImpl.hxx"
32 #include "dbu_dlg.hrc"
33 #include "DriverSettings.hxx"
34 #include "dsitems.hxx"
35 #include "propertysetitem.hxx"
36 #include "UITools.hxx"
37 #include "UserAdmin.hxx"
38 #include "UserAdminDlg.hrc"
39 #include "UserAdminDlg.hxx"
41 #include <comphelper/componentcontext.hxx>
42 #include <connectivity/dbmetadata.hxx>
43 #include <cppuhelper/exc_hlp.hxx>
44 #include <svl/eitem.hxx>
45 #include <svl/intitem.hxx>
46 #include <svl/stritem.hxx>
47 #include <tools/diagnose_ex.h>
48 #include <vcl/msgbox.hxx>
49 #include <vcl/stdtext.hxx>
51 //.........................................................................
52 namespace dbaui
54 //.........................................................................
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::beans;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::sdbc;
59 using namespace ::com::sun::star::sdbcx;
61 //========================================================================
62 //= OUserAdminDlg
63 DBG_NAME(OUserAdminDlg)
64 //========================================================================
65 OUserAdminDlg::OUserAdminDlg(Window* _pParent
66 , SfxItemSet* _pItems
67 ,const Reference< XMultiServiceFactory >& _rxORB
68 ,const ::com::sun::star::uno::Any& _aDataSourceName
69 ,const Reference< XConnection >& _xConnection)
70 :SfxTabDialog(_pParent, ModuleRes(DLG_DATABASE_USERADMIN), _pItems)
71 ,m_pItemSet(_pItems)
72 ,m_xConnection(_xConnection)
73 ,m_bOwnConnection(!_xConnection.is())
75 DBG_CTOR(OUserAdminDlg,NULL);
77 m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,_pParent,this));
78 m_pImpl->setDataSourceOrName(_aDataSourceName);
79 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
80 m_pImpl->translateProperties(xDatasource, *_pItems);
81 SetInputSet(_pItems);
82 // propagate this set as our new input set and reset the example set
83 delete pExampleSet;
84 pExampleSet = new SfxItemSet(*GetInputSetImpl());
86 AddTabPage(TAB_PAGE_USERADMIN, String(ModuleRes(STR_PAGETITLE_USERADMIN)), OUserAdmin::Create,0, sal_False, 1);
88 // remove the reset button - it's meaning is much too ambiguous in this dialog
89 RemoveResetButton();
90 FreeResource();
93 // -----------------------------------------------------------------------
94 OUserAdminDlg::~OUserAdminDlg()
96 if ( m_bOwnConnection )
98 try
100 ::comphelper::disposeComponent(m_xConnection);
102 catch(const 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&)
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(sal_uInt16 _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 //.........................................................................
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */