Update ooo320-m1
[ooovba.git] / dbaccess / source / ui / dlg / ConnectionPage.cxx
blob0fd8ebc134b0faae7be433a896a7dacef80d92ee
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: ConnectionPage.cxx,v $
10 * $Revision: 1.25.26.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_CONNECTIONPAGE_HXX
35 #include "ConnectionPage.hxx"
36 #endif
37 #ifndef DBAUI_CONNECTIONPAGE_HRC
38 #include "ConnectionPage.hrc"
39 #endif
40 #ifndef _DBU_DLG_HRC_
41 #include "dbu_dlg.hrc"
42 #endif
43 #ifndef DBACCESS_DSMETA_HXX
44 #include "dsmeta.hxx"
45 #endif
46 #ifndef _SFXITEMSET_HXX
47 #include <svtools/itemset.hxx>
48 #endif
49 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
50 #include <svtools/pathoptions.hxx>
51 #endif
52 #ifndef _SFXSTRITEM_HXX
53 #include <svtools/stritem.hxx>
54 #endif
55 #ifndef _SFXENUMITEM_HXX
56 #include <svtools/eitem.hxx>
57 #endif
58 #ifndef _SFXINTITEM_HXX
59 #include <svtools/intitem.hxx>
60 #endif
61 #ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX
62 #include <svtools/moduleoptions.hxx>
63 #endif
64 #ifndef _DBAUI_DATASOURCEITEMS_HXX_
65 #include "dsitems.hxx"
66 #endif
67 #ifndef _DBA_DBACCESS_HELPID_HRC_
68 #include "dbaccess_helpid.hrc"
69 #endif
70 #ifndef _DBAUI_LOCALRESACCESS_HXX_
71 #include "localresaccess.hxx"
72 #endif
73 #ifndef _OSL_PROCESS_H_
74 #include <osl/process.h>
75 #endif
76 #ifndef _SV_MSGBOX_HXX
77 #include <vcl/msgbox.hxx>
78 #endif
79 #ifndef _FILEDLGHELPER_HXX
80 #include <sfx2/filedlghelper.hxx>
81 #endif
82 #ifndef _DBAUI_DBADMIN_HXX_
83 #include "dbadmin.hxx"
84 #endif
85 #ifndef _COMPHELPER_TYPES_HXX_
86 #include <comphelper/types.hxx>
87 #endif
88 #ifndef _VCL_STDTEXT_HXX
89 #include <vcl/stdtext.hxx>
90 #endif
91 #ifndef _DBAUI_SQLMESSAGE_HXX_
92 #include "sqlmessage.hxx"
93 #endif
94 #ifndef _DBAUI_ODBC_CONFIG_HXX_
95 #include "odbcconfig.hxx"
96 #endif
97 #ifndef _DBAUI_DSSELECT_HXX_
98 #include "dsselect.hxx"
99 #endif
100 #ifndef SVTOOLS_FILENOTATION_HXX_
101 #include <svtools/filenotation.hxx>
102 #endif
103 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
104 #include "dbustrings.hrc"
105 #endif
106 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HPP_
107 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
108 #endif
109 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
110 #include <com/sun/star/sdbc/XRow.hpp>
111 #endif
112 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
113 #include <com/sun/star/awt/XWindow.hpp>
114 #endif
115 // #106016# ------------------------------------
116 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
117 #include <com/sun/star/task/XInteractionHandler.hpp>
118 #endif
119 #ifndef _COM_SUN_STAR_TASK_XPROGRESSHANDLER_HPP_
120 #include <com/sun/star/ucb/XProgressHandler.hpp>
121 #endif
122 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
123 #include <com/sun/star/sdbc/XConnection.hpp>
124 #endif
125 #ifndef _COM_SUN_STAR_UI_DIALOGS_EXTENDEDFILEPICKERELEMENTIDS_HPP_
126 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
127 #endif
128 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERCONTROLACCESS_HPP_
129 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
130 #endif
131 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKER_HPP_
132 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
133 #endif
134 #ifndef DBAUI_TOOLS_HXX
135 #include "UITools.hxx"
136 #endif
137 #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX
138 #include <unotools/localfilehelper.hxx>
139 #endif
140 #ifndef _UNOTOOLS_UCBHELPER_HXX
141 #include <unotools/ucbhelper.hxx>
142 #endif
143 #ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX
144 #include <ucbhelper/commandenvironment.hxx>
145 #endif
146 #ifndef DBAUI_FILEPICKER_INTERACTION_HXX
147 #include "finteraction.hxx"
148 #endif
149 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
150 #include <connectivity/CommonTools.hxx>
151 #endif
152 #ifndef _URLOBJ_HXX
153 #include <tools/urlobj.hxx>
154 #endif
155 #ifndef _SFX_DOCFILT_HACK_HXX
156 #include <sfx2/docfilt.hxx>
157 #endif
158 #include "dsnItem.hxx"
159 #if defined(WIN) || defined(WNT)
160 #define _ADO_DATALINK_BROWSE_
161 #endif
163 #ifdef _ADO_DATALINK_BROWSE_
164 #if defined( WNT )
165 #include <tools/prewin.h>
166 #include <windows.h>
167 #include <tools/postwin.h>
168 #endif
169 #ifndef _SV_SYSDATA_HXX
170 #include <vcl/sysdata.hxx>
171 #endif
172 #ifndef _DBAUI_ADO_DATALINK_HXX_
173 #include "adodatalinks.hxx"
174 #endif
175 #endif //_ADO_DATALINK_BROWSE_
177 #include "AutoControls.hrc"
179 //.........................................................................
180 namespace dbaui
182 //.........................................................................
183 using namespace ::com::sun::star::uno;
184 using namespace ::com::sun::star::ucb;
185 using namespace ::com::sun::star::ui::dialogs;
186 using namespace ::com::sun::star::sdbc;
187 using namespace ::com::sun::star::beans;
188 using namespace ::com::sun::star::lang;
189 using namespace ::com::sun::star::container;
190 using namespace ::dbtools;
191 using namespace ::svt;
193 SfxTabPage* OConnectionTabPage::Create( Window* pParent, const SfxItemSet& _rAttrSet )
195 return ( new OConnectionTabPage( pParent, _rAttrSet ) );
197 //========================================================================
198 //= OConnectionTabPage
199 //========================================================================
200 DBG_NAME(OConnectionTabPage)
201 OConnectionTabPage::OConnectionTabPage(Window* pParent, const SfxItemSet& _rCoreAttrs)
202 :OConnectionHelper(pParent, ModuleRes(PAGE_CONNECTION), _rCoreAttrs)
203 ,m_bUserGrabFocus(sal_True)
204 ,m_aFL1(this, ModuleRes(FL_SEPARATOR1))
205 ,m_aFL2(this, ModuleRes(FL_SEPARATOR2))
206 ,m_aUserNameLabel(this, ModuleRes(FT_USERNAME))
207 ,m_aUserName(this, ModuleRes(ET_USERNAME))
208 ,m_aPasswordRequired(this, ModuleRes(CB_PASSWORD_REQUIRED))
209 ,m_aFL3(this, ModuleRes(FL_SEPARATOR3))
210 ,m_aJavaDriverLabel(this, ModuleRes(FT_JDBCDRIVERCLASS))
211 ,m_aJavaDriver(this, ModuleRes(ET_JDBCDRIVERCLASS))
212 ,m_aTestJavaDriver(this, ModuleRes(PB_TESTDRIVERCLASS))
213 ,m_aTestConnection(this, ModuleRes(PB_TESTCONNECTION))
215 DBG_CTOR(OConnectionTabPage,NULL);
216 m_aConnectionURL.SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
217 m_aJavaDriver.SetModifyHdl(getControlModifiedLink());
218 m_aJavaDriver.SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
219 m_aUserName.SetModifyHdl(getControlModifiedLink());
220 m_aPasswordRequired.SetClickHdl(getControlModifiedLink());
222 m_aTestConnection.SetClickHdl(LINK(this,OGenericAdministrationPage,OnTestConnectionClickHdl));
223 m_aTestJavaDriver.SetClickHdl(LINK(this,OConnectionTabPage,OnTestJavaClickHdl));
225 FreeResource();
228 // -----------------------------------------------------------------------
229 OConnectionTabPage::~OConnectionTabPage()
231 DBG_DTOR(OConnectionTabPage,NULL);
234 // -----------------------------------------------------------------------
235 void OConnectionTabPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
237 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
238 sal_Bool bValid, bReadonly;
239 getFlags(_rSet, bValid, bReadonly);
241 m_eType = m_pAdminDialog->getDatasourceType(_rSet);
242 OConnectionHelper::implInitControls( _rSet, _bSaveValue);
244 LocalResourceAccess aLocRes( PAGE_CONNECTION, RSC_TABPAGE );
245 ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
246 switch( eType )
248 case ::dbaccess::DST_DBASE:
249 m_aFT_Connection.SetText(String(ModuleRes(STR_DBASE_PATH_OR_FILE)));
250 m_aConnectionURL.SetHelpId(HID_DSADMIN_DBASE_PATH);
251 break;
252 case ::dbaccess::DST_FLAT:
253 m_aFT_Connection.SetText(String(ModuleRes(STR_FLAT_PATH_OR_FILE)));
254 m_aConnectionURL.SetHelpId(HID_DSADMIN_FLAT_PATH);
255 break;
256 case ::dbaccess::DST_CALC:
257 m_aFT_Connection.SetText(String(ModuleRes(STR_CALC_PATH_OR_FILE)));
258 m_aConnectionURL.SetHelpId(HID_DSADMIN_CALC_PATH);
259 break;
260 case ::dbaccess::DST_ADABAS:
261 m_aFT_Connection.SetText(String(ModuleRes(STR_ADABAS_DATABASE_NAME)));
262 m_aConnectionURL.SetHelpId(HID_DSADMIN_ADABAS_DATABASE);
263 break;
264 case ::dbaccess::DST_ADO:
265 m_aFT_Connection.SetText(String(ModuleRes(STR_COMMONURL)));
266 break;
267 case ::dbaccess::DST_MSACCESS:
268 case ::dbaccess::DST_MSACCESS_2007:
269 m_aFT_Connection.SetText(String(ModuleRes(STR_MSACCESS_MDB_FILE)));
270 m_aConnectionURL.SetHelpId(HID_DSADMIN_MSACCESS_MDB_FILE);
271 break;
272 case ::dbaccess::DST_MYSQL_NATIVE:
273 case ::dbaccess::DST_MYSQL_JDBC:
274 m_aFT_Connection.SetText(String(ModuleRes(STR_MYSQL_DATABASE_NAME)));
275 m_aConnectionURL.SetHelpId( HID_DSADMIN_MYSQL_DATABASE );
276 break;
277 case ::dbaccess::DST_ORACLE_JDBC:
278 m_aFT_Connection.SetText(String(ModuleRes(STR_ORACLE_DATABASE_NAME)));
279 m_aConnectionURL.SetHelpId(HID_DSADMIN_ORACLE_DATABASE);
280 break;
281 case ::dbaccess::DST_MYSQL_ODBC:
282 case ::dbaccess::DST_ODBC:
283 m_aFT_Connection.SetText(String(ModuleRes(STR_NAME_OF_ODBC_DATASOURCE)));
284 m_aConnectionURL.SetHelpId( eType == ::dbaccess::DST_MYSQL_ODBC ? HID_DSADMIN_MYSQL_ODBC_DATASOURCE : HID_DSADMIN_ODBC_DATASOURCE);
285 break;
286 case ::dbaccess::DST_LDAP:
287 m_aFT_Connection.SetText(String(ModuleRes(STR_HOSTNAME)));
288 m_aConnectionURL.SetHelpId( HID_DSADMIN_LDAP_HOSTNAME );
289 break;
290 case ::dbaccess::DST_MOZILLA:
291 m_aFT_Connection.SetText(String(ModuleRes(STR_MOZILLA_PROFILE_NAME)));
292 m_aConnectionURL.SetHelpId( HID_DSADMIN_MOZILLA_PROFILE_NAME );
293 break;
294 case ::dbaccess::DST_THUNDERBIRD:
295 m_aFT_Connection.SetText(String(ModuleRes(STR_THUNDERBIRD_PROFILE_NAME)));
296 m_aConnectionURL.SetHelpId( HID_DSADMIN_THUNDERBIRD_PROFILE_NAME );
297 break;
298 case ::dbaccess::DST_OUTLOOK:
299 case ::dbaccess::DST_OUTLOOKEXP:
300 case ::dbaccess::DST_EVOLUTION:
301 case ::dbaccess::DST_EVOLUTION_GROUPWISE:
302 case ::dbaccess::DST_EVOLUTION_LDAP:
303 case ::dbaccess::DST_KAB:
304 case ::dbaccess::DST_MACAB:
305 m_aFT_Connection.SetText(String(ModuleRes(STR_NO_ADDITIONAL_SETTINGS)));
307 String sText = m_aFT_Connection.GetText();
308 sText.SearchAndReplaceAscii("%test",m_aTestConnection.GetText());
309 String sTemp;
310 sText.SearchAndReplaceAscii("~",sTemp);
311 m_aFT_Connection.SetText(sText);
313 m_aConnectionURL.Hide();
314 break;
315 case ::dbaccess::DST_JDBC:
316 default:
317 m_aFT_Connection.SetText(String(ModuleRes(STR_COMMONURL)));
318 break;
322 AuthenticationMode eAuthMode( DataSourceMetaData::getAuthentication( m_eType ) );
323 bool bShowUserAuthenfication = ( eAuthMode != AuthNone );
324 bool bShowUser = ( eAuthMode == AuthUserPwd );
326 m_aPB_Connection.SetHelpId(HID_DSADMIN_BROWSECONN);
327 m_aFL2.Show( bShowUserAuthenfication );
328 m_aUserNameLabel.Show( bShowUser && bShowUserAuthenfication );
329 m_aUserName.Show( bShowUser && bShowUserAuthenfication );
330 m_aPasswordRequired.Show( bShowUserAuthenfication );
331 if ( !bShowUser && bShowUserAuthenfication )
332 m_aPasswordRequired.SetPosPixel(m_aUserNameLabel.GetPosPixel());
334 // collect the items
335 SFX_ITEMSET_GET(_rSet, pUidItem, SfxStringItem, DSID_USER, sal_True);
337 SFX_ITEMSET_GET(_rSet, pJdbcDrvItem, SfxStringItem, DSID_JDBCDRIVERCLASS, sal_True);
338 SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True);
339 SFX_ITEMSET_GET(_rSet, pAllowEmptyPwd, SfxBoolItem, DSID_PASSWORDREQUIRED, sal_True);
341 // forward the values to the controls
342 if ( bValid )
344 m_aUserName.SetText(pUidItem->GetValue());
345 m_aPasswordRequired.Check(pAllowEmptyPwd->GetValue());
347 String sUrl = pUrlItem->GetValue();
348 setURL( sUrl );
350 const BOOL bEnableJDBC = m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC;
351 if ( !pJdbcDrvItem->GetValue().Len() )
353 String sDefaultJdbcDriverName = m_pCollection->getJavaDriverClass(m_eType);
354 if ( sDefaultJdbcDriverName.Len() )
356 m_aJavaDriver.SetText(sDefaultJdbcDriverName);
357 m_aJavaDriver.SetModifyFlag();
359 } // if ( !pJdbcDrvItem->GetValue().Len() )
360 else
361 m_aJavaDriver.SetText(pJdbcDrvItem->GetValue());
363 m_aJavaDriverLabel.Show(bEnableJDBC);
364 m_aJavaDriver.Show(bEnableJDBC);
365 m_aTestJavaDriver.Show(bEnableJDBC);
366 m_aTestJavaDriver.Enable( m_aJavaDriver.GetText().Len() != 0);
367 m_aFL3.Show(bEnableJDBC);
369 checkTestConnection();
371 m_aUserName.ClearModifyFlag();
372 m_aConnectionURL.ClearModifyFlag();
373 m_aJavaDriver.ClearModifyFlag();
376 // -----------------------------------------------------------------------
377 void OConnectionTabPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
379 _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL1));
381 _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL2));
382 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aJavaDriverLabel));
383 _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aTestJavaDriver));
385 _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL3));
386 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aUserNameLabel));
387 _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aTestConnection));
388 OConnectionHelper::fillWindows(_rControlList);
391 // -----------------------------------------------------------------------
392 void OConnectionTabPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
394 _rControlList.push_back(new OSaveValueWrapper<Edit>(&m_aJavaDriver));
395 _rControlList.push_back(new OSaveValueWrapper<Edit>(&m_aUserName));
396 _rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aPasswordRequired));
397 OConnectionHelper::fillControls(_rControlList);
400 // -----------------------------------------------------------------------
401 sal_Bool OConnectionTabPage::FillItemSet(SfxItemSet& _rSet)
403 sal_Bool bChangedSomething = sal_False;
405 if (m_aUserName.GetText() != m_aUserName.GetSavedValue())
407 _rSet.Put(SfxStringItem(DSID_USER, m_aUserName.GetText()));
408 _rSet.Put(SfxStringItem(DSID_PASSWORD, String()));
409 bChangedSomething = sal_True;
412 fillBool(_rSet,&m_aPasswordRequired,DSID_PASSWORDREQUIRED,bChangedSomething);
414 if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC )
416 fillString(_rSet,&m_aJavaDriver, DSID_JDBCDRIVERCLASS, bChangedSomething);
419 fillString(_rSet,&m_aConnectionURL, DSID_CONNECTURL, bChangedSomething);
421 return bChangedSomething;
423 // -----------------------------------------------------------------------
424 IMPL_LINK(OConnectionTabPage, OnTestJavaClickHdl, PushButton*, /*_pButton*/)
426 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
427 sal_Bool bSuccess = sal_False;
430 if ( m_aJavaDriver.GetText().Len() )
432 ::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM(m_pAdminDialog->getORB());
433 bSuccess = ::connectivity::existsJavaClassByName(xJVM,m_aJavaDriver.GetText());
436 catch(Exception&)
440 USHORT nMessage = bSuccess ? STR_JDBCDRIVER_SUCCESS : STR_JDBCDRIVER_NO_SUCCESS;
441 OSQLMessageBox aMsg( this, String( ModuleRes( nMessage ) ), String() );
442 aMsg.Execute();
443 return 0L;
445 // -----------------------------------------------------------------------
446 bool OConnectionTabPage::checkTestConnection()
448 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
449 BOOL bEnableTestConnection = !m_aConnectionURL.IsVisible() || (m_aConnectionURL.GetTextNoPrefix().Len() != 0);
450 if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC )
451 bEnableTestConnection = bEnableTestConnection && (m_aJavaDriver.GetText().Len() != 0);
452 m_aTestConnection.Enable(bEnableTestConnection);
453 return true;
455 // -----------------------------------------------------------------------
456 IMPL_LINK(OConnectionTabPage, OnEditModified, Edit*, _pEdit)
458 if ( _pEdit == &m_aJavaDriver )
459 m_aTestJavaDriver.Enable( m_aJavaDriver.GetText().Len() != 0 );
461 checkTestConnection();
462 // tell the listener we were modified
463 callModifiedHdl();
464 return 0L;
466 //.........................................................................
467 } // namespace dbaui
468 //.........................................................................