xref: /trunk/main/dbaccess/source/ui/dlg/UserAdminDlg.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #include "adminpages.hxx"
32 #include "DbAdminImpl.hxx"
33 #include "dbu_dlg.hrc"
34 #include "DriverSettings.hxx"
35 #include "dsitems.hxx"
36 #include "propertysetitem.hxx"
37 #include "UITools.hxx"
38 #include "UserAdmin.hxx"
39 #include "UserAdminDlg.hrc"
40 #include "UserAdminDlg.hxx"
41 
42 #include <comphelper/componentcontext.hxx>
43 #include <connectivity/dbmetadata.hxx>
44 #include <cppuhelper/exc_hlp.hxx>
45 #include <svl/eitem.hxx>
46 #include <svl/intitem.hxx>
47 #include <svl/stritem.hxx>
48 #include <tools/diagnose_ex.h>
49 #include <vcl/msgbox.hxx>
50 #include <vcl/stdtext.hxx>
51 
52 //.........................................................................
53 namespace dbaui
54 {
55 //.........................................................................
56     using namespace ::com::sun::star::uno;
57     using namespace ::com::sun::star::beans;
58     using namespace ::com::sun::star::lang;
59     using namespace ::com::sun::star::sdbc;
60     using namespace ::com::sun::star::sdbcx;
61 
62     //========================================================================
63     //= OUserAdminDlg
64 DBG_NAME(OUserAdminDlg)
65 //========================================================================
66     OUserAdminDlg::OUserAdminDlg(Window* _pParent
67                                             , SfxItemSet* _pItems
68                                             ,const Reference< XMultiServiceFactory >& _rxORB
69                                             ,const ::com::sun::star::uno::Any& _aDataSourceName
70                                             ,const Reference< XConnection >& _xConnection)
71         :SfxTabDialog(_pParent, ModuleRes(DLG_DATABASE_USERADMIN), _pItems)
72         ,m_pItemSet(_pItems)
73         ,m_xConnection(_xConnection)
74         ,m_bOwnConnection(!_xConnection.is())
75     {
76         DBG_CTOR(OUserAdminDlg,NULL);
77 
78         m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,_pParent,this));
79         m_pImpl->setDataSourceOrName(_aDataSourceName);
80         Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
81         m_pImpl->translateProperties(xDatasource, *_pItems);
82         SetInputSet(_pItems);
83         // propagate this set as our new input set and reset the example set
84         delete pExampleSet;
85         pExampleSet = new SfxItemSet(*GetInputSetImpl());
86 
87         AddTabPage(TAB_PAGE_USERADMIN, String(ModuleRes(STR_PAGETITLE_USERADMIN)), OUserAdmin::Create,0, sal_False, 1);
88 
89         // remove the reset button - it's meaning is much too ambiguous in this dialog
90         RemoveResetButton();
91         FreeResource();
92     }
93 
94     // -----------------------------------------------------------------------
95     OUserAdminDlg::~OUserAdminDlg()
96     {
97         if ( m_bOwnConnection )
98             try
99             {
100                 ::comphelper::disposeComponent(m_xConnection);
101             }
102             catch(Exception){}
103 
104         SetInputSet(NULL);
105         DELETEZ(pExampleSet);
106 
107         DBG_DTOR(OUserAdminDlg,NULL);
108     }
109     // -----------------------------------------------------------------------
110     short OUserAdminDlg::Execute()
111     {
112         try
113         {
114             ::dbtools::DatabaseMetaData aMetaData( createConnection().first );
115             if ( !aMetaData.supportsUserAdministration( ::comphelper::ComponentContext( getORB() ) ) )
116             {
117                 String sError(ModuleRes(STR_USERADMIN_NOT_AVAILABLE));
118                 throw SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
119             }
120         }
121         catch(const SQLException& e)
122         {
123             ::dbaui::showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), GetParent(), getORB() );
124             return RET_CANCEL;
125         }
126         catch( const Exception& )
127         {
128             DBG_UNHANDLED_EXCEPTION();
129         }
130         short nRet = SfxTabDialog::Execute();
131         if ( nRet == RET_OK )
132             m_pImpl->saveChanges(*GetOutputItemSet());
133         return nRet;
134     }
135     //-------------------------------------------------------------------------
136     void OUserAdminDlg::PageCreated(sal_uInt16 _nId, SfxTabPage& _rPage)
137     {
138         // register ourself as modified listener
139         static_cast<OGenericAdministrationPage&>(_rPage).SetServiceFactory(m_pImpl->getORB());
140         static_cast<OGenericAdministrationPage&>(_rPage).SetAdminDialog(this,this);
141 
142         AdjustLayout();
143         Window *pWin = GetViewWindow();
144         if(pWin)
145             pWin->Invalidate();
146 
147         SfxTabDialog::PageCreated(_nId, _rPage);
148     }
149     // -----------------------------------------------------------------------------
150     const SfxItemSet* OUserAdminDlg::getOutputSet() const
151     {
152         return m_pItemSet;
153     }
154     // -----------------------------------------------------------------------------
155     SfxItemSet* OUserAdminDlg::getWriteOutputSet()
156     {
157         return m_pItemSet;
158     }
159     // -----------------------------------------------------------------------------
160     ::std::pair< Reference<XConnection>,sal_Bool> OUserAdminDlg::createConnection()
161     {
162         if ( !m_xConnection.is() )
163         {
164             m_xConnection = m_pImpl->createConnection().first;
165             m_bOwnConnection = m_xConnection.is();
166         }
167         return ::std::pair< Reference<XConnection>,sal_Bool> (m_xConnection,sal_False);
168     }
169     // -----------------------------------------------------------------------------
170     Reference< XMultiServiceFactory > OUserAdminDlg::getORB() const
171     {
172         return m_pImpl->getORB();
173     }
174     // -----------------------------------------------------------------------------
175     Reference< XDriver > OUserAdminDlg::getDriver()
176     {
177         return m_pImpl->getDriver();
178     }
179     // -----------------------------------------------------------------------------
180     ::rtl::OUString OUserAdminDlg::getDatasourceType(const SfxItemSet& _rSet) const
181     {
182         return m_pImpl->getDatasourceType(_rSet);
183     }
184     // -----------------------------------------------------------------------------
185     void OUserAdminDlg::clearPassword()
186     {
187         m_pImpl->clearPassword();
188     }
189     // -----------------------------------------------------------------------------
190     void OUserAdminDlg::setTitle(const ::rtl::OUString& _sTitle)
191     {
192         SetText(_sTitle);
193     }
194     //-------------------------------------------------------------------------
195     void OUserAdminDlg::enableConfirmSettings( bool _bEnable )
196     {
197         (void)_bEnable;
198     }
199     //-------------------------------------------------------------------------
200     sal_Bool OUserAdminDlg::saveDatasource()
201     {
202         return PrepareLeaveCurrentPage();
203     }
204 //.........................................................................
205 }   // namespace dbaui
206 //.........................................................................
207