1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "dsselect.hxx"
22 #include "dsselect.hrc"
23 #include "dbu_dlg.hrc"
24 #include <vcl/msgbox.hxx>
25 #include "localresaccess.hxx"
26 #include <tools/rcid.h>
28 #include <com/sun/star/sdbcx/XCreateCatalog.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/beans/XPropertySetInfo.hpp>
31 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
32 #include <com/sun/star/awt/XWindow.hpp>
33 #include "dbustrings.hrc"
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <comphelper/extract.hxx>
36 #include <comphelper/types.hxx>
37 #include <comphelper/processfactory.hxx>
38 #include "dsitems.hxx"
39 #include <svl/stritem.hxx>
40 #include <svl/intitem.hxx>
41 #include <svl/eitem.hxx>
42 #include <svl/itemset.hxx>
44 //.........................................................................
47 //.........................................................................
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::sdbc
;
51 using namespace ::com::sun::star::sdbcx
;
52 using namespace ::com::sun::star::ui::dialogs
;
53 using namespace ::comphelper
;
54 //==================================================================
55 ODatasourceSelectDialog::ODatasourceSelectDialog(Window
* _pParent
, const StringBag
& _rDatasources
, SfxItemSet
* _pOutputSet
)
56 :ModalDialog(_pParent
, ModuleRes(DLG_DATASOURCE_SELECTION
))
57 ,m_aDescription (this, ModuleRes(FT_DESCRIPTION
))
58 ,m_aDatasource (this, ModuleRes(LB_DATASOURCE
))
59 ,m_aOk (this, ModuleRes(PB_OK
))
60 ,m_aCancel (this, ModuleRes(PB_CANCEL
))
61 ,m_aHelp (this, ModuleRes(PB_HELP
))
62 #ifdef HAVE_ODBC_ADMINISTRATION
63 ,m_aManageDatasources (this, ModuleRes(PB_MANAGE
))
65 ,m_pOutputSet(_pOutputSet
)
67 fillListBox(_rDatasources
);
68 #ifdef HAVE_ODBC_ADMINISTRATION
69 // allow ODBC datasource managenment
70 m_aManageDatasources
.Show();
71 m_aManageDatasources
.Enable();
72 m_aManageDatasources
.SetClickHdl(LINK(this,ODatasourceSelectDialog
,ManageClickHdl
));
74 m_aDatasource
.SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog
,ListDblClickHdl
));
78 // -----------------------------------------------------------------------
79 ODatasourceSelectDialog::~ODatasourceSelectDialog()
83 // -----------------------------------------------------------------------
84 IMPL_LINK( ODatasourceSelectDialog
, ListDblClickHdl
, ListBox
*, pListBox
)
86 if (pListBox
->GetSelectEntryCount())
91 // -----------------------------------------------------------------------
92 sal_Bool
ODatasourceSelectDialog::Close()
94 #ifdef HAVE_ODBC_ADMINISTRATION
95 if ( m_pODBCManagement
.get() && m_pODBCManagement
->isRunning() )
99 return ModalDialog::Close();
102 // -----------------------------------------------------------------------
103 #ifdef HAVE_ODBC_ADMINISTRATION
104 IMPL_LINK_NOARG(ODatasourceSelectDialog
, ManageClickHdl
)
106 if ( !m_pODBCManagement
.get() )
107 m_pODBCManagement
.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog
, ManageProcessFinished
) ) );
109 if ( !m_pODBCManagement
->manageDataSources_async() )
111 // TODO: error message
112 m_aDatasource
.GrabFocus();
113 m_aManageDatasources
.Disable();
117 m_aDatasource
.Disable();
120 m_aManageDatasources
.Disable();
122 OSL_POSTCOND( m_pODBCManagement
->isRunning(), "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
126 IMPL_LINK( ODatasourceSelectDialog
, ManageProcessFinished
, void*, /**/ )
128 StringBag aOdbcDatasources
;
129 OOdbcEnumeration aEnumeration
;
130 aEnumeration
.getDatasourceNames( aOdbcDatasources
);
131 fillListBox( aOdbcDatasources
);
133 m_aDatasource
.Enable();
136 m_aManageDatasources
.Enable();
142 // -----------------------------------------------------------------------------
143 void ODatasourceSelectDialog::fillListBox(const StringBag
& _rDatasources
)
146 if (m_aDatasource
.GetEntryCount())
147 sSelected
= m_aDatasource
.GetSelectEntry();
148 m_aDatasource
.Clear();
150 for ( ConstStringBagIterator aDS
= _rDatasources
.begin();
151 aDS
!= _rDatasources
.end();
155 m_aDatasource
.InsertEntry( *aDS
);
158 if (m_aDatasource
.GetEntryCount())
160 if (!sSelected
.isEmpty())
161 m_aDatasource
.SelectEntry(sSelected
);
162 else // select the first entry
163 m_aDatasource
.SelectEntryPos(0);
167 //.........................................................................
169 //.........................................................................
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */