Update ooo320-m1
[ooovba.git] / dbaccess / source / ui / dlg / adminpages.cxx
blobd48e962bc865ac8db3617b4d85c60b79a3f041f5
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: adminpages.cxx,v $
10 * $Revision: 1.52.40.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 #ifndef _DBAUI_ADMINPAGES_HXX_
35 #include "adminpages.hxx"
36 #endif
37 #ifndef _DBAUI_DBADMIN_HRC_
38 #include "dbadmin.hrc"
39 #endif
40 #ifndef _DBU_DLG_HRC_
41 #include "dbu_dlg.hrc"
42 #endif
43 #ifndef _SFXSTRITEM_HXX
44 #include <svtools/stritem.hxx>
45 #endif
46 #ifndef _SFXENUMITEM_HXX
47 #include <svtools/eitem.hxx>
48 #endif
49 #ifndef _SFXINTITEM_HXX
50 #include <svtools/intitem.hxx>
51 #endif
52 #ifndef _DBAUI_DATASOURCEITEMS_HXX_
53 #include "dsitems.hxx"
54 #endif
55 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
56 #include "dbustrings.hrc"
57 #endif
58 #ifndef _DBAUI_DBADMIN_HXX_
59 #include "dbadmin.hxx"
60 #endif
61 #ifndef _SV_MSGBOX_HXX
62 #include <vcl/msgbox.hxx>
63 #endif
64 #ifndef _DBAUI_SQLMESSAGE_HXX_
65 #include "sqlmessage.hxx"
66 #endif
67 #ifndef _SV_ACCEL_HXX
68 #include <vcl/accel.hxx>
69 #endif
70 #include <algorithm>
71 #include <stdlib.h>
72 #ifndef _OSL_FILE_HXX_
73 #include <osl/file.hxx>
74 #endif
75 #ifndef _DBAUI_DSSELECT_HXX_
76 #include "dsselect.hxx"
77 #endif
78 #ifndef _DBAUI_ODBC_CONFIG_HXX_
79 #include "odbcconfig.hxx"
80 #endif
81 #ifndef _DBAUI_LOCALRESACCESS_HXX_
82 #include "localresaccess.hxx"
83 #endif
84 #ifndef _SV_FIELD_HXX
85 #include <vcl/field.hxx>
86 #endif
87 #ifndef _SV_LSTBOX_HXX
88 #include <vcl/lstbox.hxx>
89 #endif
90 #ifndef _SV_EDIT_HXX
91 #include <vcl/edit.hxx>
92 #endif
93 #ifndef _SV_BUTTON_HXX
94 #include <vcl/button.hxx>
95 #endif
99 //.........................................................................
100 namespace dbaui
102 //.........................................................................
104 using namespace ::com::sun::star::uno;
105 using namespace ::com::sun::star::sdbc;
106 using namespace ::com::sun::star::beans;
107 using namespace ::com::sun::star::lang;
108 using namespace ::dbtools;
109 using namespace ::svt;
112 //=========================================================================
113 //= OGenericAdministrationPage
114 //=========================================================================
115 DBG_NAME(OGenericAdministrationPage)
116 //-------------------------------------------------------------------------
117 OGenericAdministrationPage::OGenericAdministrationPage(Window* _pParent, const ResId& _rId, const SfxItemSet& _rAttrSet)
118 :SfxTabPage(_pParent, _rId, _rAttrSet)
119 ,m_abEnableRoadmap(sal_False)
120 ,m_pAdminDialog(NULL)
121 ,m_pItemSetHelper(NULL)
122 ,m_pFT_HeaderText(NULL)
124 DBG_CTOR(OGenericAdministrationPage,NULL);
126 SetExchangeSupport(sal_True);
129 //-------------------------------------------------------------------------
130 OGenericAdministrationPage::~OGenericAdministrationPage()
132 DELETEZ(m_pFT_HeaderText);
134 DBG_DTOR(OGenericAdministrationPage,NULL);
137 //-------------------------------------------------------------------------
138 int OGenericAdministrationPage::DeactivatePage(SfxItemSet* _pSet)
140 if (_pSet)
142 if (!prepareLeave())
143 return KEEP_PAGE;
144 FillItemSet(*_pSet);
147 return LEAVE_PAGE;
150 //-------------------------------------------------------------------------
151 void OGenericAdministrationPage::Reset(const SfxItemSet& _rCoreAttrs)
153 implInitControls(_rCoreAttrs, sal_False);
155 //-------------------------------------------------------------------------
156 void OGenericAdministrationPage::ActivatePage()
158 TabPage::ActivatePage();
159 OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
160 if ( m_pItemSetHelper )
161 ActivatePage(*m_pItemSetHelper->getOutputSet());
163 //-------------------------------------------------------------------------
164 void OGenericAdministrationPage::ActivatePage(const SfxItemSet& _rSet)
166 implInitControls(_rSet, sal_True);
169 // -----------------------------------------------------------------------
170 void OGenericAdministrationPage::getFlags(const SfxItemSet& _rSet, sal_Bool& _rValid, sal_Bool& _rReadonly)
172 SFX_ITEMSET_GET(_rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, sal_True);
173 _rValid = !pInvalid || !pInvalid->GetValue();
174 SFX_ITEMSET_GET(_rSet, pReadonly, SfxBoolItem, DSID_READONLY, sal_True);
175 _rReadonly = !_rValid || (pReadonly && pReadonly->GetValue());
179 // -----------------------------------------------------------------------
180 IMPL_LINK(OGenericAdministrationPage, OnControlModified, Control*, EMPTYARG)
182 callModifiedHdl();
183 return 0L;
185 // -----------------------------------------------------------------------
186 sal_Bool OGenericAdministrationPage::getSelectedDataSource(::rtl::OUString& _sReturn,::rtl::OUString& _sCurr)
188 // collect all ODBC data source names
189 StringBag aOdbcDatasources;
190 OOdbcEnumeration aEnumeration;
191 if (!aEnumeration.isLoaded())
193 // show an error message
194 LocalResourceAccess aLocRes( PAGE_GENERAL, RSC_TABPAGE );
195 String sError(ModuleRes(STR_COULDNOTLOAD_ODBCLIB));
196 sError.SearchAndReplaceAscii("#lib#", aEnumeration.getLibraryName());
197 ErrorBox aDialog(this, WB_OK, sError);
198 aDialog.Execute();
199 return sal_False;
201 else
203 aEnumeration.getDatasourceNames(aOdbcDatasources);
204 // excute the select dialog
205 ODatasourceSelectDialog aSelector(GetParent(), aOdbcDatasources, false);
206 if (_sCurr.getLength())
207 aSelector.Select(_sCurr);
208 if ( RET_OK == aSelector.Execute() )
209 _sReturn = aSelector.GetSelected();
211 return sal_True;
214 // -----------------------------------------------------------------------
215 void OGenericAdministrationPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
217 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
218 sal_Bool bValid, bReadonly;
219 getFlags(_rSet, bValid, bReadonly);
221 ::std::vector< ISaveValueWrapper* > aControlList;
222 if ( _bSaveValue )
224 fillControls(aControlList);
225 ::std::for_each(aControlList.begin(),aControlList.end(),TSaveValueWrapperFunctor());
228 if ( bReadonly )
230 fillWindows(aControlList);
231 ::std::for_each(aControlList.begin(),aControlList.end(),TDisableWrapperFunctor());
234 ::std::for_each(aControlList.begin(),aControlList.end(),TDeleteWrapperFunctor());
235 aControlList.clear();
238 // -----------------------------------------------------------------------
239 void OGenericAdministrationPage::initializePage()
241 OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
242 if ( m_pItemSetHelper )
243 Reset(*m_pItemSetHelper->getOutputSet());
245 // -----------------------------------------------------------------------
246 sal_Bool OGenericAdministrationPage::commitPage( CommitPageReason )
248 return sal_True;
250 // -----------------------------------------------------------------------
251 void OGenericAdministrationPage::fillBool( SfxItemSet& _rSet, CheckBox* _pCheckBox, USHORT _nID, sal_Bool& _bChangedSomething, bool _bRevertValue )
253 if ( (_pCheckBox != NULL ) && ( _pCheckBox->GetState() != _pCheckBox->GetSavedValue() ) )
255 sal_Bool bValue = _pCheckBox->IsChecked();
256 if ( _bRevertValue )
257 bValue = !bValue;
259 _rSet.Put( SfxBoolItem( _nID, bValue ) );
260 _bChangedSomething = sal_True;
263 // -----------------------------------------------------------------------
264 void OGenericAdministrationPage::fillInt32(SfxItemSet& _rSet,NumericField* _pEdit,USHORT _nID,sal_Bool& _bChangedSomething)
266 if( (_pEdit != NULL) && (_pEdit->GetValue() != _pEdit->GetSavedValue().ToInt32()) )
268 _rSet.Put(SfxInt32Item(_nID, static_cast<INT32>(_pEdit->GetValue())));
269 _bChangedSomething = sal_True;
272 // -----------------------------------------------------------------------
273 void OGenericAdministrationPage::fillString(SfxItemSet& _rSet,Edit* _pEdit,USHORT _nID,sal_Bool& _bChangedSomething)
275 if( (_pEdit != NULL) && (_pEdit->GetText() != _pEdit->GetSavedValue()) )
277 _rSet.Put(SfxStringItem(_nID, _pEdit->GetText()));
278 _bChangedSomething = sal_True;
282 void OGenericAdministrationPage::SetControlFontWeight(Window* _pWindow, FontWeight _eWeight)
284 Font aFont = _pWindow->GetControlFont();
285 aFont.SetWeight( _eWeight );
286 _pWindow->SetControlFont( aFont );
289 // -----------------------------------------------------------------------
290 IMPL_LINK(OGenericAdministrationPage, OnTestConnectionClickHdl, PushButton*, /*_pButton*/)
292 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
293 sal_Bool bSuccess = sal_False;
294 if ( m_pAdminDialog )
296 m_pAdminDialog->saveDatasource();
297 OGenericAdministrationPage::implInitControls(*m_pItemSetHelper->getOutputSet(), sal_True);
298 sal_Bool bShowMessage = sal_True;
301 ::std::pair< Reference<XConnection>,sal_Bool> xConnection = m_pAdminDialog->createConnection();
302 bShowMessage = xConnection.second;
303 bSuccess = xConnection.first.is();
304 ::comphelper::disposeComponent(xConnection.first);
306 catch(Exception&)
309 if ( bShowMessage )
311 OSQLMessageBox::MessageType eImage = OSQLMessageBox::Info;
312 String aMessage,sTitle;
313 sTitle = String (ModuleRes(STR_CONNECTION_TEST));
314 if ( bSuccess )
316 aMessage = String(ModuleRes(STR_CONNECTION_SUCCESS));
318 else
320 eImage = OSQLMessageBox::Error;
321 aMessage = String(ModuleRes(STR_CONNECTION_NO_SUCCESS));
323 OSQLMessageBox aMsg( this, sTitle, aMessage, WB_OK, eImage );
324 aMsg.Execute();
326 if ( !bSuccess )
327 m_pAdminDialog->clearPassword();
329 return 0L;
332 void OGenericAdministrationPage::SetHeaderText( USHORT _nFTResId, USHORT _StringResId)
334 delete(m_pFT_HeaderText);
335 m_pFT_HeaderText = new FixedText(this, ModuleRes(_nFTResId));
336 String sHeaderText = String(ModuleRes(_StringResId));
337 m_pFT_HeaderText->SetText(sHeaderText);
338 SetControlFontWeight(m_pFT_HeaderText);
342 //=========================================================================
343 //= LayoutHelper
344 //=========================================================================
345 //-------------------------------------------------------------------------
346 void LayoutHelper::positionBelow( const Control& _rReference, Control& _rControl, const ControlRelation _eRelation,
347 const long _nIndentAppFont )
349 Point aReference = _rReference.GetPosPixel();
350 aReference.Y() += _rReference.GetSizePixel().Height();
352 const Window* pConverter = _rControl.GetParent();
353 Size aOffset = pConverter->LogicToPixel( Size( _nIndentAppFont, ( _eRelation == RelatedControls ? 3 : 6 ) ), MAP_APPFONT );
355 Point aControlPos( aReference.X() + aOffset.Width(), aReference.Y() + aOffset.Height() );
356 _rControl.SetPosPixel( aControlPos );
359 //.........................................................................
360 } // namespace dbaui
361 //.........................................................................