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: 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"
37 #ifndef _DBAUI_DBADMIN_HRC_
38 #include "dbadmin.hrc"
41 #include "dbu_dlg.hrc"
43 #ifndef _SFXSTRITEM_HXX
44 #include <svtools/stritem.hxx>
46 #ifndef _SFXENUMITEM_HXX
47 #include <svtools/eitem.hxx>
49 #ifndef _SFXINTITEM_HXX
50 #include <svtools/intitem.hxx>
52 #ifndef _DBAUI_DATASOURCEITEMS_HXX_
53 #include "dsitems.hxx"
55 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
56 #include "dbustrings.hrc"
58 #ifndef _DBAUI_DBADMIN_HXX_
59 #include "dbadmin.hxx"
61 #ifndef _SV_MSGBOX_HXX
62 #include <vcl/msgbox.hxx>
64 #ifndef _DBAUI_SQLMESSAGE_HXX_
65 #include "sqlmessage.hxx"
68 #include <vcl/accel.hxx>
72 #ifndef _OSL_FILE_HXX_
73 #include <osl/file.hxx>
75 #ifndef _DBAUI_DSSELECT_HXX_
76 #include "dsselect.hxx"
78 #ifndef _DBAUI_ODBC_CONFIG_HXX_
79 #include "odbcconfig.hxx"
81 #ifndef _DBAUI_LOCALRESACCESS_HXX_
82 #include "localresaccess.hxx"
85 #include <vcl/field.hxx>
87 #ifndef _SV_LSTBOX_HXX
88 #include <vcl/lstbox.hxx>
91 #include <vcl/edit.hxx>
93 #ifndef _SV_BUTTON_HXX
94 #include <vcl/button.hxx>
99 //.........................................................................
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
)
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
)
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
);
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();
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
;
224 fillControls(aControlList
);
225 ::std::for_each(aControlList
.begin(),aControlList
.end(),TSaveValueWrapperFunctor());
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
)
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();
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
);
311 OSQLMessageBox::MessageType eImage
= OSQLMessageBox::Info
;
312 String aMessage
,sTitle
;
313 sTitle
= String (ModuleRes(STR_CONNECTION_TEST
));
316 aMessage
= String(ModuleRes(STR_CONNECTION_SUCCESS
));
320 eImage
= OSQLMessageBox::Error
;
321 aMessage
= String(ModuleRes(STR_CONNECTION_NO_SUCCESS
));
323 OSQLMessageBox
aMsg( this, sTitle
, aMessage
, WB_OK
, eImage
);
327 m_pAdminDialog
->clearPassword();
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 //=========================================================================
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 //.........................................................................
361 //.........................................................................