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 "dbadmin.hrc"
32 #include "dbadmin.hxx"
33 #include "dbu_dlg.hrc"
34 #include <svl/stritem.hxx>
35 #include <svl/eitem.hxx>
36 #include <svl/intitem.hxx>
37 #include "dbustrings.hrc"
38 #include "dsitems.hxx"
39 #include "dsselect.hxx"
40 #include "localresaccess.hxx"
41 #include "odbcconfig.hxx"
42 #include "optionalboolitem.hxx"
43 #include "sqlmessage.hxx"
45 #include <osl/file.hxx>
46 #include <vcl/accel.hxx>
47 #include <vcl/button.hxx>
48 #include <vcl/edit.hxx>
49 #include <vcl/field.hxx>
50 #include <vcl/lstbox.hxx>
51 #include <vcl/msgbox.hxx>
56 //.........................................................................
59 //.........................................................................
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::sdbc
;
63 using namespace ::com::sun::star::beans
;
64 using namespace ::com::sun::star::lang
;
65 using namespace ::dbtools
;
66 using namespace ::svt
;
68 ISaveValueWrapper::~ISaveValueWrapper()
72 //=========================================================================
73 //= OGenericAdministrationPage
74 //=========================================================================
75 DBG_NAME(OGenericAdministrationPage
)
76 //-------------------------------------------------------------------------
77 OGenericAdministrationPage::OGenericAdministrationPage(Window
* _pParent
, const ResId
& _rId
, const SfxItemSet
& _rAttrSet
)
78 :SfxTabPage(_pParent
, _rId
, _rAttrSet
)
79 ,m_abEnableRoadmap(sal_False
)
81 ,m_pItemSetHelper(NULL
)
82 ,m_pFT_HeaderText(NULL
)
84 DBG_CTOR(OGenericAdministrationPage
,NULL
);
86 SetExchangeSupport(sal_True
);
89 //-------------------------------------------------------------------------
90 OGenericAdministrationPage::~OGenericAdministrationPage()
92 DELETEZ(m_pFT_HeaderText
);
94 DBG_DTOR(OGenericAdministrationPage
,NULL
);
97 //-------------------------------------------------------------------------
98 int OGenericAdministrationPage::DeactivatePage(SfxItemSet
* _pSet
)
110 //-------------------------------------------------------------------------
111 void OGenericAdministrationPage::Reset(const SfxItemSet
& _rCoreAttrs
)
113 implInitControls(_rCoreAttrs
, sal_False
);
115 //-------------------------------------------------------------------------
116 void OGenericAdministrationPage::ActivatePage()
118 TabPage::ActivatePage();
119 OSL_ENSURE(m_pItemSetHelper
,"NO ItemSetHelper set!");
120 if ( m_pItemSetHelper
)
121 ActivatePage(*m_pItemSetHelper
->getOutputSet());
123 //-------------------------------------------------------------------------
124 void OGenericAdministrationPage::ActivatePage(const SfxItemSet
& _rSet
)
126 implInitControls(_rSet
, sal_True
);
129 // -----------------------------------------------------------------------
130 void OGenericAdministrationPage::getFlags(const SfxItemSet
& _rSet
, sal_Bool
& _rValid
, sal_Bool
& _rReadonly
)
132 SFX_ITEMSET_GET(_rSet
, pInvalid
, SfxBoolItem
, DSID_INVALID_SELECTION
, sal_True
);
133 _rValid
= !pInvalid
|| !pInvalid
->GetValue();
134 SFX_ITEMSET_GET(_rSet
, pReadonly
, SfxBoolItem
, DSID_READONLY
, sal_True
);
135 _rReadonly
= !_rValid
|| (pReadonly
&& pReadonly
->GetValue());
139 // -----------------------------------------------------------------------
140 IMPL_LINK_NOARG(OGenericAdministrationPage
, OnControlModified
)
145 // -----------------------------------------------------------------------
146 sal_Bool
OGenericAdministrationPage::getSelectedDataSource(::rtl::OUString
& _sReturn
,::rtl::OUString
& _sCurr
)
148 // collect all ODBC data source names
149 StringBag aOdbcDatasources
;
150 OOdbcEnumeration aEnumeration
;
151 if (!aEnumeration
.isLoaded())
153 // show an error message
154 LocalResourceAccess
aLocRes( PAGE_GENERAL
, RSC_TABPAGE
);
155 String
sError(ModuleRes(STR_COULDNOTLOAD_ODBCLIB
));
156 sError
.SearchAndReplaceAscii("#lib#", aEnumeration
.getLibraryName());
157 ErrorBox
aDialog(this, WB_OK
, sError
);
163 aEnumeration
.getDatasourceNames(aOdbcDatasources
);
164 // execute the select dialog
165 ODatasourceSelectDialog
aSelector(GetParent(), aOdbcDatasources
);
166 if (!_sCurr
.isEmpty())
167 aSelector
.Select(_sCurr
);
168 if ( RET_OK
== aSelector
.Execute() )
169 _sReturn
= aSelector
.GetSelected();
174 // -----------------------------------------------------------------------
175 void OGenericAdministrationPage::implInitControls(const SfxItemSet
& _rSet
, sal_Bool _bSaveValue
)
177 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
178 sal_Bool bValid
, bReadonly
;
179 getFlags(_rSet
, bValid
, bReadonly
);
181 ::std::vector
< ISaveValueWrapper
* > aControlList
;
184 fillControls(aControlList
);
185 ::std::for_each(aControlList
.begin(),aControlList
.end(),TSaveValueWrapperFunctor());
190 fillWindows(aControlList
);
191 ::std::for_each(aControlList
.begin(),aControlList
.end(),TDisableWrapperFunctor());
194 ::std::for_each(aControlList
.begin(),aControlList
.end(),TDeleteWrapperFunctor());
195 aControlList
.clear();
198 // -----------------------------------------------------------------------
199 void OGenericAdministrationPage::initializePage()
201 OSL_ENSURE(m_pItemSetHelper
,"NO ItemSetHelper set!");
202 if ( m_pItemSetHelper
)
203 Reset(*m_pItemSetHelper
->getOutputSet());
205 // -----------------------------------------------------------------------
206 sal_Bool
OGenericAdministrationPage::commitPage( ::svt::WizardTypes::CommitPageReason
)
210 // -----------------------------------------------------------------------
211 bool OGenericAdministrationPage::canAdvance() const
215 // -----------------------------------------------------------------------
216 void OGenericAdministrationPage::fillBool( SfxItemSet
& _rSet
, CheckBox
* _pCheckBox
, sal_uInt16 _nID
, sal_Bool
& _bChangedSomething
, bool _bRevertValue
)
218 if ( (_pCheckBox
!= NULL
) && ( _pCheckBox
->GetState() != _pCheckBox
->GetSavedValue() ) )
220 sal_Bool bValue
= _pCheckBox
->IsChecked();
224 if ( _pCheckBox
->IsTriStateEnabled() )
226 OptionalBoolItem
aValue( _nID
);
227 if ( _pCheckBox
->GetState() != STATE_DONTKNOW
)
228 aValue
.SetValue( bValue
);
232 _rSet
.Put( SfxBoolItem( _nID
, bValue
) );
234 _bChangedSomething
= sal_True
;
237 // -----------------------------------------------------------------------
238 void OGenericAdministrationPage::fillInt32(SfxItemSet
& _rSet
,NumericField
* _pEdit
,sal_uInt16 _nID
,sal_Bool
& _bChangedSomething
)
240 if( (_pEdit
!= NULL
) && (_pEdit
->GetValue() != _pEdit
->GetSavedValue().ToInt32()) )
242 _rSet
.Put(SfxInt32Item(_nID
, static_cast<sal_Int32
>(_pEdit
->GetValue())));
243 _bChangedSomething
= sal_True
;
246 // -----------------------------------------------------------------------
247 void OGenericAdministrationPage::fillString(SfxItemSet
& _rSet
,Edit
* _pEdit
,sal_uInt16 _nID
,sal_Bool
& _bChangedSomething
)
249 if( (_pEdit
!= NULL
) && (_pEdit
->GetText() != _pEdit
->GetSavedValue()) )
251 _rSet
.Put(SfxStringItem(_nID
, _pEdit
->GetText()));
252 _bChangedSomething
= sal_True
;
256 void OGenericAdministrationPage::SetControlFontWeight(Window
* _pWindow
, FontWeight _eWeight
)
258 Font aFont
= _pWindow
->GetControlFont();
259 aFont
.SetWeight( _eWeight
);
260 _pWindow
->SetControlFont( aFont
);
263 // -----------------------------------------------------------------------
264 IMPL_LINK(OGenericAdministrationPage
, OnTestConnectionClickHdl
, PushButton
*, /*_pButton*/)
266 OSL_ENSURE(m_pAdminDialog
,"No Admin dialog set! ->GPF");
267 sal_Bool bSuccess
= sal_False
;
268 if ( m_pAdminDialog
)
270 m_pAdminDialog
->saveDatasource();
271 OGenericAdministrationPage::implInitControls(*m_pItemSetHelper
->getOutputSet(), sal_True
);
272 sal_Bool bShowMessage
= sal_True
;
275 ::std::pair
< Reference
<XConnection
>,sal_Bool
> xConnection
= m_pAdminDialog
->createConnection();
276 bShowMessage
= xConnection
.second
;
277 bSuccess
= xConnection
.first
.is();
278 ::comphelper::disposeComponent(xConnection
.first
);
285 OSQLMessageBox::MessageType eImage
= OSQLMessageBox::Info
;
286 String aMessage
,sTitle
;
287 sTitle
= String (ModuleRes(STR_CONNECTION_TEST
));
290 aMessage
= String(ModuleRes(STR_CONNECTION_SUCCESS
));
294 eImage
= OSQLMessageBox::Error
;
295 aMessage
= String(ModuleRes(STR_CONNECTION_NO_SUCCESS
));
297 OSQLMessageBox
aMsg( this, sTitle
, aMessage
, WB_OK
, eImage
);
301 m_pAdminDialog
->clearPassword();
306 void OGenericAdministrationPage::SetHeaderText( sal_uInt16 _nFTResId
, sal_uInt16 _StringResId
)
308 delete(m_pFT_HeaderText
);
309 m_pFT_HeaderText
= new FixedText(this, ModuleRes(_nFTResId
));
310 String sHeaderText
= String(ModuleRes(_StringResId
));
311 m_pFT_HeaderText
->SetText(sHeaderText
);
312 SetControlFontWeight(m_pFT_HeaderText
);
315 //=========================================================================
317 //=========================================================================
318 //-------------------------------------------------------------------------
319 void LayoutHelper::positionBelow( const Control
& _rReference
, Control
& _rControl
, const ControlRelation _eRelation
,
320 const long _nIndentAppFont
)
322 Point aReference
= _rReference
.GetPosPixel();
323 aReference
.Y() += _rReference
.GetSizePixel().Height();
325 const Window
* pConverter
= _rControl
.GetParent();
326 Size aOffset
= pConverter
->LogicToPixel( Size( _nIndentAppFont
, ( _eRelation
== RelatedControls
? 3 : 6 ) ), MAP_APPFONT
);
328 Point
aControlPos( aReference
.X() + aOffset
.Width(), aReference
.Y() + aOffset
.Height() );
329 _rControl
.SetPosPixel( aControlPos
);
332 //-------------------------------------------------------------------------
333 void LayoutHelper::fitSizeRightAligned( PushButton
& io_button
)
335 const Point aOldPos
= io_button
.GetPosPixel();
336 const Size aOldSize
= io_button
.GetSizePixel();
337 const Size
aMinSize( io_button
.CalcMinimumSize() );
338 if ( aMinSize
.Width() > aOldSize
.Width() )
340 io_button
.SetPosSizePixel(
341 aOldPos
.X() + aOldSize
.Width() - aMinSize
.Width(),
345 WINDOW_POSSIZE_X
| WINDOW_POSSIZE_WIDTH
350 //.........................................................................
352 //.........................................................................
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */