1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
#ifndef DBAUI_CONNECTIONPAGE_HXX
#include "ConnectionPage.hxx"
#endif
#ifndef DBAUI_CONNECTIONPAGE_HRC
#include "ConnectionPage.hrc"
#endif
#ifndef _DBU_DLG_HRC_
#include "dbu_dlg.hrc"
#endif
#ifndef DBACCESS_DSMETA_HXX
#include "dsmeta.hxx"
#endif
#ifndef _SFXITEMSET_HXX
#include <svl/itemset.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
#include <unotools/pathoptions.hxx>
#endif
#ifndef _SFXSTRITEM_HXX
#include <svl/stritem.hxx>
#endif
#ifndef _SFXENUMITEM_HXX
#include <svl/eitem.hxx>
#endif
#ifndef _SFXINTITEM_HXX
#include <svl/intitem.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX
#include <unotools/moduleoptions.hxx>
#endif
#ifndef _DBAUI_DATASOURCEITEMS_HXX_
#include "dsitems.hxx"
#endif
#ifndef _DBA_DBACCESS_HELPID_HRC_
#include "dbaccess_helpid.hrc"
#endif
#ifndef _DBAUI_LOCALRESACCESS_HXX_
#include "localresaccess.hxx"
#endif
#ifndef _OSL_PROCESS_H_
#include <osl/process.h>
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef _FILEDLGHELPER_HXX
#include <sfx2/filedlghelper.hxx>
#endif
#ifndef _DBAUI_DBADMIN_HXX_
#include "dbadmin.hxx"
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#ifndef _VCL_STDTEXT_HXX
#include <vcl/stdtext.hxx>
#endif
#ifndef _DBAUI_SQLMESSAGE_HXX_
#include "sqlmessage.hxx"
#endif
#ifndef _DBAUI_ODBC_CONFIG_HXX_
#include "odbcconfig.hxx"
#endif
#ifndef _DBAUI_DSSELECT_HXX_
#include "dsselect.hxx"
#endif
#ifndef SVTOOLS_FILENOTATION_HXX_
#include <svl/filenotation.hxx>
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HPP_
#include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
#include <com/sun/star/sdbc/XRow.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
#include <com/sun/star/awt/XWindow.hpp>
#endif
// #106016# ------------------------------------
#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
#include <com/sun/star/task/XInteractionHandler.hpp>
#endif
#ifndef _COM_SUN_STAR_TASK_XPROGRESSHANDLER_HPP_
#include <com/sun/star/ucb/XProgressHandler.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
#include <com/sun/star/sdbc/XConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_EXTENDEDFILEPICKERELEMENTIDS_HPP_
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERCONTROLACCESS_HPP_
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKER_HPP_
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
#endif
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
#ifndef _UNOTOOLS_LOCALFILEHELPER_HXX
#include <unotools/localfilehelper.hxx>
#endif
#ifndef _UNOTOOLS_UCBHELPER_HXX
#include <unotools/ucbhelper.hxx>
#endif
#ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX
#include <ucbhelper/commandenvironment.hxx>
#endif
#ifndef DBAUI_FILEPICKER_INTERACTION_HXX
#include "finteraction.hxx"
#endif
#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
#include <connectivity/CommonTools.hxx>
#endif
#ifndef _URLOBJ_HXX
#include <tools/urlobj.hxx>
#endif
#ifndef _SFX_DOCFILT_HACK_HXX
#include <sfx2/docfilt.hxx>
#endif
#include "dsnItem.hxx"
#if defined(WIN) || defined(WNT)
#define _ADO_DATALINK_BROWSE_
#endif
#ifdef _ADO_DATALINK_BROWSE_
#if defined( WNT )
#include <tools/prewin.h>
#include <windows.h>
#include <tools/postwin.h>
#endif
#ifndef _SV_SYSDATA_HXX
#include <vcl/sysdata.hxx>
#endif
#ifndef _DBAUI_ADO_DATALINK_HXX_
#include "adodatalinks.hxx"
#endif
#endif //_ADO_DATALINK_BROWSE_
#include "AutoControls.hrc"
//.........................................................................
namespace dbaui
{
//.........................................................................
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::container;
using namespace ::dbtools;
using namespace ::svt;
SfxTabPage* OConnectionTabPage::Create( Window* pParent, const SfxItemSet& _rAttrSet )
{
return ( new OConnectionTabPage( pParent, _rAttrSet ) );
}
//========================================================================
//= OConnectionTabPage
//========================================================================
DBG_NAME(OConnectionTabPage)
OConnectionTabPage::OConnectionTabPage(Window* pParent, const SfxItemSet& _rCoreAttrs)
:OConnectionHelper(pParent, ModuleRes(PAGE_CONNECTION), _rCoreAttrs)
,m_bUserGrabFocus(sal_True)
,m_aFL1(this, ModuleRes(FL_SEPARATOR1))
,m_aFL2(this, ModuleRes(FL_SEPARATOR2))
,m_aUserNameLabel(this, ModuleRes(FT_USERNAME))
,m_aUserName(this, ModuleRes(ET_USERNAME))
,m_aPasswordRequired(this, ModuleRes(CB_PASSWORD_REQUIRED))
,m_aFL3(this, ModuleRes(FL_SEPARATOR3))
,m_aJavaDriverLabel(this, ModuleRes(FT_JDBCDRIVERCLASS))
,m_aJavaDriver(this, ModuleRes(ET_JDBCDRIVERCLASS))
,m_aTestJavaDriver(this, ModuleRes(PB_TESTDRIVERCLASS))
,m_aTestConnection(this, ModuleRes(PB_TESTCONNECTION))
{
DBG_CTOR(OConnectionTabPage,NULL);
m_aConnectionURL.SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
m_aJavaDriver.SetModifyHdl(getControlModifiedLink());
m_aJavaDriver.SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
m_aUserName.SetModifyHdl(getControlModifiedLink());
m_aPasswordRequired.SetClickHdl(getControlModifiedLink());
m_aTestConnection.SetClickHdl(LINK(this,OGenericAdministrationPage,OnTestConnectionClickHdl));
m_aTestJavaDriver.SetClickHdl(LINK(this,OConnectionTabPage,OnTestJavaClickHdl));
FreeResource();
}
// -----------------------------------------------------------------------
OConnectionTabPage::~OConnectionTabPage()
{
DBG_DTOR(OConnectionTabPage,NULL);
}
// -----------------------------------------------------------------------
void OConnectionTabPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
{
// check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
sal_Bool bValid, bReadonly;
getFlags(_rSet, bValid, bReadonly);
m_eType = m_pAdminDialog->getDatasourceType(_rSet);
OConnectionHelper::implInitControls( _rSet, _bSaveValue);
LocalResourceAccess aLocRes( PAGE_CONNECTION, RSC_TABPAGE );
::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
switch( eType )
{
case ::dbaccess::DST_DBASE:
m_aFT_Connection.SetText(String(ModuleRes(STR_DBASE_PATH_OR_FILE)));
m_aConnectionURL.SetHelpId(HID_DSADMIN_DBASE_PATH);
break;
case ::dbaccess::DST_FLAT:
m_aFT_Connection.SetText(String(ModuleRes(STR_FLAT_PATH_OR_FILE)));
m_aConnectionURL.SetHelpId(HID_DSADMIN_FLAT_PATH);
break;
case ::dbaccess::DST_CALC:
m_aFT_Connection.SetText(String(ModuleRes(STR_CALC_PATH_OR_FILE)));
m_aConnectionURL.SetHelpId(HID_DSADMIN_CALC_PATH);
break;
case ::dbaccess::DST_ADABAS:
m_aFT_Connection.SetText(String(ModuleRes(STR_ADABAS_DATABASE_NAME)));
m_aConnectionURL.SetHelpId(HID_DSADMIN_ADABAS_DATABASE);
break;
case ::dbaccess::DST_ADO:
m_aFT_Connection.SetText(String(ModuleRes(STR_COMMONURL)));
break;
case ::dbaccess::DST_MSACCESS:
case ::dbaccess::DST_MSACCESS_2007:
m_aFT_Connection.SetText(String(ModuleRes(STR_MSACCESS_MDB_FILE)));
m_aConnectionURL.SetHelpId(HID_DSADMIN_MSACCESS_MDB_FILE);
break;
case ::dbaccess::DST_MYSQL_NATIVE:
case ::dbaccess::DST_MYSQL_JDBC:
m_aFT_Connection.SetText(String(ModuleRes(STR_MYSQL_DATABASE_NAME)));
m_aConnectionURL.SetHelpId( HID_DSADMIN_MYSQL_DATABASE );
break;
case ::dbaccess::DST_ORACLE_JDBC:
m_aFT_Connection.SetText(String(ModuleRes(STR_ORACLE_DATABASE_NAME)));
m_aConnectionURL.SetHelpId(HID_DSADMIN_ORACLE_DATABASE);
break;
case ::dbaccess::DST_MYSQL_ODBC:
case ::dbaccess::DST_ODBC:
m_aFT_Connection.SetText(String(ModuleRes(STR_NAME_OF_ODBC_DATASOURCE)));
m_aConnectionURL.SetHelpId( eType == ::dbaccess::DST_MYSQL_ODBC ? HID_DSADMIN_MYSQL_ODBC_DATASOURCE : HID_DSADMIN_ODBC_DATASOURCE);
break;
case ::dbaccess::DST_LDAP:
m_aFT_Connection.SetText(String(ModuleRes(STR_HOSTNAME)));
m_aConnectionURL.SetHelpId( HID_DSADMIN_LDAP_HOSTNAME );
break;
case ::dbaccess::DST_MOZILLA:
m_aFT_Connection.SetText(String(ModuleRes(STR_MOZILLA_PROFILE_NAME)));
m_aConnectionURL.SetHelpId( HID_DSADMIN_MOZILLA_PROFILE_NAME );
break;
case ::dbaccess::DST_THUNDERBIRD:
m_aFT_Connection.SetText(String(ModuleRes(STR_THUNDERBIRD_PROFILE_NAME)));
m_aConnectionURL.SetHelpId( HID_DSADMIN_THUNDERBIRD_PROFILE_NAME );
break;
case ::dbaccess::DST_OUTLOOK:
case ::dbaccess::DST_OUTLOOKEXP:
case ::dbaccess::DST_EVOLUTION:
case ::dbaccess::DST_EVOLUTION_GROUPWISE:
case ::dbaccess::DST_EVOLUTION_LDAP:
case ::dbaccess::DST_KAB:
case ::dbaccess::DST_MACAB:
m_aFT_Connection.SetText(String(ModuleRes(STR_NO_ADDITIONAL_SETTINGS)));
{
String sText = m_aFT_Connection.GetText();
sText.SearchAndReplaceAscii("%test",m_aTestConnection.GetText());
String sTemp;
sText.SearchAndReplaceAscii("~",sTemp);
m_aFT_Connection.SetText(sText);
}
m_aConnectionURL.Hide();
break;
case ::dbaccess::DST_JDBC:
default:
m_aFT_Connection.SetText(String(ModuleRes(STR_COMMONURL)));
break;
}
;
AuthenticationMode eAuthMode( DataSourceMetaData::getAuthentication( m_eType ) );
bool bShowUserAuthenfication = ( eAuthMode != AuthNone );
bool bShowUser = ( eAuthMode == AuthUserPwd );
m_aPB_Connection.SetHelpId(HID_DSADMIN_BROWSECONN);
m_aFL2.Show( bShowUserAuthenfication );
m_aUserNameLabel.Show( bShowUser && bShowUserAuthenfication );
m_aUserName.Show( bShowUser && bShowUserAuthenfication );
m_aPasswordRequired.Show( bShowUserAuthenfication );
if ( !bShowUser && bShowUserAuthenfication )
m_aPasswordRequired.SetPosPixel(m_aUserNameLabel.GetPosPixel());
// collect the items
SFX_ITEMSET_GET(_rSet, pUidItem, SfxStringItem, DSID_USER, sal_True);
SFX_ITEMSET_GET(_rSet, pJdbcDrvItem, SfxStringItem, DSID_JDBCDRIVERCLASS, sal_True);
SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True);
SFX_ITEMSET_GET(_rSet, pAllowEmptyPwd, SfxBoolItem, DSID_PASSWORDREQUIRED, sal_True);
// forward the values to the controls
if ( bValid )
{
m_aUserName.SetText(pUidItem->GetValue());
m_aPasswordRequired.Check(pAllowEmptyPwd->GetValue());
String sUrl = pUrlItem->GetValue();
setURL( sUrl );
const BOOL bEnableJDBC = m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC;
if ( !pJdbcDrvItem->GetValue().Len() )
{
String sDefaultJdbcDriverName = m_pCollection->getJavaDriverClass(m_eType);
if ( sDefaultJdbcDriverName.Len() )
{
m_aJavaDriver.SetText(sDefaultJdbcDriverName);
m_aJavaDriver.SetModifyFlag();
}
} // if ( !pJdbcDrvItem->GetValue().Len() )
else
m_aJavaDriver.SetText(pJdbcDrvItem->GetValue());
m_aJavaDriverLabel.Show(bEnableJDBC);
m_aJavaDriver.Show(bEnableJDBC);
m_aTestJavaDriver.Show(bEnableJDBC);
m_aTestJavaDriver.Enable( m_aJavaDriver.GetText().Len() != 0);
m_aFL3.Show(bEnableJDBC);
checkTestConnection();
m_aUserName.ClearModifyFlag();
m_aConnectionURL.ClearModifyFlag();
m_aJavaDriver.ClearModifyFlag();
}
}
// -----------------------------------------------------------------------
void OConnectionTabPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
{
_rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL1));
_rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL2));
_rControlList.push_back(new ODisableWrapper<FixedText>(&m_aJavaDriverLabel));
_rControlList.push_back(new ODisableWrapper<PushButton>(&m_aTestJavaDriver));
_rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL3));
_rControlList.push_back(new ODisableWrapper<FixedText>(&m_aUserNameLabel));
_rControlList.push_back(new ODisableWrapper<PushButton>(&m_aTestConnection));
OConnectionHelper::fillWindows(_rControlList);
}
// -----------------------------------------------------------------------
void OConnectionTabPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
{
_rControlList.push_back(new OSaveValueWrapper<Edit>(&m_aJavaDriver));
_rControlList.push_back(new OSaveValueWrapper<Edit>(&m_aUserName));
_rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aPasswordRequired));
OConnectionHelper::fillControls(_rControlList);
}
// -----------------------------------------------------------------------
sal_Bool OConnectionTabPage::FillItemSet(SfxItemSet& _rSet)
{
sal_Bool bChangedSomething = sal_False;
if (m_aUserName.GetText() != m_aUserName.GetSavedValue())
{
_rSet.Put(SfxStringItem(DSID_USER, m_aUserName.GetText()));
_rSet.Put(SfxStringItem(DSID_PASSWORD, String()));
bChangedSomething = sal_True;
}
fillBool(_rSet,&m_aPasswordRequired,DSID_PASSWORDREQUIRED,bChangedSomething);
if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC )
{
fillString(_rSet,&m_aJavaDriver, DSID_JDBCDRIVERCLASS, bChangedSomething);
}
fillString(_rSet,&m_aConnectionURL, DSID_CONNECTURL, bChangedSomething);
return bChangedSomething;
}
// -----------------------------------------------------------------------
IMPL_LINK(OConnectionTabPage, OnTestJavaClickHdl, PushButton*, /*_pButton*/)
{
OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
sal_Bool bSuccess = sal_False;
try
{
if ( m_aJavaDriver.GetText().Len() )
{
::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM(m_pAdminDialog->getORB());
bSuccess = ::connectivity::existsJavaClassByName(xJVM,m_aJavaDriver.GetText());
}
}
catch(Exception&)
{
}
USHORT nMessage = bSuccess ? STR_JDBCDRIVER_SUCCESS : STR_JDBCDRIVER_NO_SUCCESS;
OSQLMessageBox aMsg( this, String( ModuleRes( nMessage ) ), String() );
aMsg.Execute();
return 0L;
}
// -----------------------------------------------------------------------
bool OConnectionTabPage::checkTestConnection()
{
OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
BOOL bEnableTestConnection = !m_aConnectionURL.IsVisible() || (m_aConnectionURL.GetTextNoPrefix().Len() != 0);
if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC )
bEnableTestConnection = bEnableTestConnection && (m_aJavaDriver.GetText().Len() != 0);
m_aTestConnection.Enable(bEnableTestConnection);
return true;
}
// -----------------------------------------------------------------------
IMPL_LINK(OConnectionTabPage, OnEditModified, Edit*, _pEdit)
{
if ( _pEdit == &m_aJavaDriver )
m_aTestJavaDriver.Enable( m_aJavaDriver.GetText().Len() != 0 );
checkTestConnection();
// tell the listener we were modified
callModifiedHdl();
return 0L;
}
//.........................................................................
} // namespace dbaui
//.........................................................................
|