xref: /AOO41X/main/extensions/source/dbpilots/commonpagesdbp.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_extensions.hxx"
30*cdf0e10cSrcweir #include "commonpagesdbp.hxx"
31*cdf0e10cSrcweir #ifndef _EXTENSIONS_DBP_DBPRESID_HRC_
32*cdf0e10cSrcweir #include "dbpresid.hrc"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #include "componentmodule.hxx"
35*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
43*cdf0e10cSrcweir #include <tools/debug.hxx>
44*cdf0e10cSrcweir #include <svtools/localresaccess.hxx>
45*cdf0e10cSrcweir #include <comphelper/interaction.hxx>
46*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
47*cdf0e10cSrcweir #include <vcl/stdtext.hxx>
48*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
49*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
50*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
51*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
52*cdf0e10cSrcweir #ifndef SVTOOLS_FILENOTATION_HXX_
53*cdf0e10cSrcweir #include <svl/filenotation.hxx>
54*cdf0e10cSrcweir #endif
55*cdf0e10cSrcweir //.........................................................................
56*cdf0e10cSrcweir namespace dbp
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir //.........................................................................
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
61*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
62*cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
63*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdb;
64*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
65*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
66*cdf0e10cSrcweir 	using namespace ::com::sun::star::task;
67*cdf0e10cSrcweir 	using namespace ::comphelper;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	//=====================================================================
70*cdf0e10cSrcweir 	//= OTableSelectionPage
71*cdf0e10cSrcweir 	//=====================================================================
72*cdf0e10cSrcweir 	//---------------------------------------------------------------------
73*cdf0e10cSrcweir 	OTableSelectionPage::OTableSelectionPage(OControlWizard* _pParent)
74*cdf0e10cSrcweir 		:OControlWizardPage(_pParent, ModuleRes(RID_PAGE_TABLESELECTION))
75*cdf0e10cSrcweir 		,m_aData			(this, ModuleRes(FL_DATA))
76*cdf0e10cSrcweir 		,m_aExplanation		(this, ModuleRes(FT_EXPLANATION))
77*cdf0e10cSrcweir 		,m_aDatasourceLabel	(this, ModuleRes(FT_DATASOURCE))
78*cdf0e10cSrcweir 		,m_aDatasource		(this, ModuleRes(LB_DATASOURCE))
79*cdf0e10cSrcweir 		,m_aSearchDatabase	(this, ModuleRes(PB_FORMDATASOURCE))
80*cdf0e10cSrcweir 		,m_aTableLabel		(this, ModuleRes(FT_TABLE))
81*cdf0e10cSrcweir 		,m_aTable			(this, ModuleRes(LB_TABLE))
82*cdf0e10cSrcweir 	{
83*cdf0e10cSrcweir 		FreeResource();
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 		implCollectDatasource();
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 		m_aDatasource.SetSelectHdl(LINK(this, OTableSelectionPage, OnListboxSelection));
88*cdf0e10cSrcweir 		m_aTable.SetSelectHdl(LINK(this, OTableSelectionPage, OnListboxSelection));
89*cdf0e10cSrcweir 		m_aTable.SetDoubleClickHdl(LINK(this, OTableSelectionPage, OnListboxDoubleClicked));
90*cdf0e10cSrcweir 		m_aSearchDatabase.SetClickHdl(LINK(this, OTableSelectionPage, OnSearchClicked));
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 		m_aDatasource.SetDropDownLineCount(10);
93*cdf0e10cSrcweir 	}
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	//---------------------------------------------------------------------
96*cdf0e10cSrcweir 	void OTableSelectionPage::ActivatePage()
97*cdf0e10cSrcweir 	{
98*cdf0e10cSrcweir 		OControlWizardPage::ActivatePage();
99*cdf0e10cSrcweir 		m_aDatasource.GrabFocus();
100*cdf0e10cSrcweir 	}
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	//---------------------------------------------------------------------
103*cdf0e10cSrcweir 	bool OTableSelectionPage::canAdvance() const
104*cdf0e10cSrcweir 	{
105*cdf0e10cSrcweir 		if (!OControlWizardPage::canAdvance())
106*cdf0e10cSrcweir 			return false;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 		if (0 == m_aDatasource.GetSelectEntryCount())
109*cdf0e10cSrcweir 			return false;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 		if (0 == m_aTable.GetSelectEntryCount())
112*cdf0e10cSrcweir 			return false;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 		return sal_True;
115*cdf0e10cSrcweir 	}
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	//---------------------------------------------------------------------
118*cdf0e10cSrcweir 	void OTableSelectionPage::initializePage()
119*cdf0e10cSrcweir 	{
120*cdf0e10cSrcweir 		OControlWizardPage::initializePage();
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 		const OControlWizardContext& rContext = getContext();
123*cdf0e10cSrcweir 		try
124*cdf0e10cSrcweir 		{
125*cdf0e10cSrcweir 			::rtl::OUString sDataSourceName;
126*cdf0e10cSrcweir 			rContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("DataSourceName")) >>= sDataSourceName;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir             Reference< XConnection > xConnection;
129*cdf0e10cSrcweir             bool bEmbedded = ::dbtools::isEmbeddedInDatabase( rContext.xForm, xConnection );
130*cdf0e10cSrcweir             if ( bEmbedded )
131*cdf0e10cSrcweir 			{
132*cdf0e10cSrcweir 				m_aDatasource.Hide();
133*cdf0e10cSrcweir 				m_aDatasourceLabel.Hide();
134*cdf0e10cSrcweir 				m_aSearchDatabase.Hide();
135*cdf0e10cSrcweir 				m_aTableLabel.SetPosPixel(m_aDatasourceLabel.GetPosPixel());
136*cdf0e10cSrcweir 				m_aTable.SetPosPixel(m_aDatasource.GetPosPixel());
137*cdf0e10cSrcweir 				m_aDatasource.InsertEntry(sDataSourceName);
138*cdf0e10cSrcweir 			}
139*cdf0e10cSrcweir 			m_aDatasource.SelectEntry(sDataSourceName);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 			implFillTables(xConnection);
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 			::rtl::OUString sCommand;
144*cdf0e10cSrcweir 			OSL_VERIFY( rContext.xForm->getPropertyValue( ::rtl::OUString::createFromAscii("Command") ) >>= sCommand );
145*cdf0e10cSrcweir             sal_Int32 nCommandType = CommandType::TABLE;
146*cdf0e10cSrcweir 			OSL_VERIFY( rContext.xForm->getPropertyValue( ::rtl::OUString::createFromAscii("CommandType") ) >>= nCommandType );
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir             // search the entry of the given type with the given name
149*cdf0e10cSrcweir             XubString sLookup( sCommand );
150*cdf0e10cSrcweir             for ( sal_uInt16 nLookup = 0; nLookup < m_aTable.GetEntryCount(); ++nLookup )
151*cdf0e10cSrcweir             {
152*cdf0e10cSrcweir                 if ( m_aTable.GetEntry( nLookup ) == sLookup )
153*cdf0e10cSrcweir                     if ( reinterpret_cast< sal_IntPtr >( m_aTable.GetEntryData( nLookup ) ) == nCommandType )
154*cdf0e10cSrcweir                     {
155*cdf0e10cSrcweir                         m_aTable.SelectEntryPos( nLookup );
156*cdf0e10cSrcweir                         break;
157*cdf0e10cSrcweir                     }
158*cdf0e10cSrcweir             }
159*cdf0e10cSrcweir 		}
160*cdf0e10cSrcweir 		catch(Exception&)
161*cdf0e10cSrcweir 		{
162*cdf0e10cSrcweir 			DBG_ERROR("OTableSelectionPage::initializePage: caught an exception!");
163*cdf0e10cSrcweir 		}
164*cdf0e10cSrcweir 	}
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	//---------------------------------------------------------------------
167*cdf0e10cSrcweir 	sal_Bool OTableSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
168*cdf0e10cSrcweir 	{
169*cdf0e10cSrcweir 		if (!OControlWizardPage::commitPage(_eReason))
170*cdf0e10cSrcweir 			return sal_False;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 		const OControlWizardContext& rContext = getContext();
173*cdf0e10cSrcweir 		try
174*cdf0e10cSrcweir 		{
175*cdf0e10cSrcweir 			Reference< XConnection > xOldConn;
176*cdf0e10cSrcweir 			if ( !rContext.bEmbedded )
177*cdf0e10cSrcweir 			{
178*cdf0e10cSrcweir 				xOldConn = getFormConnection();
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 				::rtl::OUString sDataSource = m_aDatasource.GetSelectEntry();
181*cdf0e10cSrcweir 				rContext.xForm->setPropertyValue( ::rtl::OUString::createFromAscii("DataSourceName"), makeAny( sDataSource ) );
182*cdf0e10cSrcweir 			}
183*cdf0e10cSrcweir             ::rtl::OUString sCommand = m_aTable.GetSelectEntry();
184*cdf0e10cSrcweir             sal_Int32 nCommandType = reinterpret_cast< sal_IntPtr >( m_aTable.GetEntryData( m_aTable.GetSelectEntryPos() ) );
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 			rContext.xForm->setPropertyValue( ::rtl::OUString::createFromAscii("Command"), makeAny( sCommand ) );
187*cdf0e10cSrcweir 			rContext.xForm->setPropertyValue( ::rtl::OUString::createFromAscii("CommandType"), makeAny( nCommandType ) );
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 			if ( !rContext.bEmbedded )
190*cdf0e10cSrcweir 				setFormConnection( xOldConn, sal_False );
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 			if (!updateContext())
193*cdf0e10cSrcweir 				return sal_False;
194*cdf0e10cSrcweir 		}
195*cdf0e10cSrcweir 		catch(Exception&)
196*cdf0e10cSrcweir 		{
197*cdf0e10cSrcweir 			DBG_ERROR("OTableSelectionPage::commitPage: caught an exception!");
198*cdf0e10cSrcweir 		}
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 		return sal_True;
201*cdf0e10cSrcweir 	}
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	//---------------------------------------------------------------------
204*cdf0e10cSrcweir 	IMPL_LINK( OTableSelectionPage, OnSearchClicked, PushButton*, /*_pButton*/ )
205*cdf0e10cSrcweir 	{
206*cdf0e10cSrcweir 		::sfx2::FileDialogHelper aFileDlg(WB_3DLOOK);
207*cdf0e10cSrcweir 		aFileDlg.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 		static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)");
210*cdf0e10cSrcweir 		const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType);
211*cdf0e10cSrcweir 		OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
212*cdf0e10cSrcweir 		if ( pFilter )
213*cdf0e10cSrcweir 		{
214*cdf0e10cSrcweir 			aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
215*cdf0e10cSrcweir 		}
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 		if (0 == aFileDlg.Execute())
218*cdf0e10cSrcweir 		{
219*cdf0e10cSrcweir 			String sDataSourceName = aFileDlg.GetPath();
220*cdf0e10cSrcweir 			::svt::OFileNotation aFileNotation(sDataSourceName);
221*cdf0e10cSrcweir 			sDataSourceName = aFileNotation.get(::svt::OFileNotation::N_SYSTEM);
222*cdf0e10cSrcweir 			m_aDatasource.InsertEntry(sDataSourceName);
223*cdf0e10cSrcweir 			m_aDatasource.SelectEntry(sDataSourceName);
224*cdf0e10cSrcweir 			LINK(this, OTableSelectionPage, OnListboxSelection).Call(&m_aDatasource);
225*cdf0e10cSrcweir 		}
226*cdf0e10cSrcweir 		return 0L;
227*cdf0e10cSrcweir 	}
228*cdf0e10cSrcweir 	//---------------------------------------------------------------------
229*cdf0e10cSrcweir 	IMPL_LINK( OTableSelectionPage, OnListboxDoubleClicked, ListBox*, _pBox )
230*cdf0e10cSrcweir 	{
231*cdf0e10cSrcweir 		if (_pBox->GetSelectEntryCount())
232*cdf0e10cSrcweir 			getDialog()->travelNext();
233*cdf0e10cSrcweir 		return 0L;
234*cdf0e10cSrcweir 	}
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 	//---------------------------------------------------------------------
237*cdf0e10cSrcweir 	IMPL_LINK( OTableSelectionPage, OnListboxSelection, ListBox*, _pBox )
238*cdf0e10cSrcweir 	{
239*cdf0e10cSrcweir 		if (&m_aDatasource == _pBox)
240*cdf0e10cSrcweir 		{	// new data source selected
241*cdf0e10cSrcweir 			implFillTables();
242*cdf0e10cSrcweir 		}
243*cdf0e10cSrcweir 		else
244*cdf0e10cSrcweir 		{
245*cdf0e10cSrcweir 		}
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 		updateDialogTravelUI();
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 		return 0L;
250*cdf0e10cSrcweir 	}
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 	//---------------------------------------------------------------------
253*cdf0e10cSrcweir     namespace
254*cdf0e10cSrcweir     {
255*cdf0e10cSrcweir         void    lcl_fillEntries( ListBox& _rListBox, const Sequence< ::rtl::OUString >& _rNames, const Image& _rImage, sal_Int32 _nCommandType )
256*cdf0e10cSrcweir         {
257*cdf0e10cSrcweir             const ::rtl::OUString* pNames = _rNames.getConstArray();
258*cdf0e10cSrcweir             const ::rtl::OUString* pNamesEnd = _rNames.getConstArray() + _rNames.getLength();
259*cdf0e10cSrcweir             sal_uInt16 nPos = 0;
260*cdf0e10cSrcweir             while ( pNames != pNamesEnd )
261*cdf0e10cSrcweir             {
262*cdf0e10cSrcweir                 nPos = _rListBox.InsertEntry( *pNames++, _rImage );
263*cdf0e10cSrcweir                 _rListBox.SetEntryData( nPos, reinterpret_cast< void* >( _nCommandType ) );
264*cdf0e10cSrcweir             }
265*cdf0e10cSrcweir         }
266*cdf0e10cSrcweir     }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	//---------------------------------------------------------------------
269*cdf0e10cSrcweir 	void OTableSelectionPage::implFillTables(const Reference< XConnection >& _rxConn)
270*cdf0e10cSrcweir 	{
271*cdf0e10cSrcweir 		m_aTable.Clear();
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 		WaitObject aWaitCursor(this);
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 		// will be the table tables of the selected data source
276*cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aTableNames;
277*cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aQueryNames;
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 		// connect to the data source
280*cdf0e10cSrcweir 		Any aSQLException;
281*cdf0e10cSrcweir 		Reference< XConnection > xConn = _rxConn;
282*cdf0e10cSrcweir 		if ( !xConn.is() )
283*cdf0e10cSrcweir 		{
284*cdf0e10cSrcweir 			if (!m_xDSContext.is())
285*cdf0e10cSrcweir 				return;
286*cdf0e10cSrcweir 			// connect to the data source
287*cdf0e10cSrcweir 			try
288*cdf0e10cSrcweir 			{
289*cdf0e10cSrcweir 				::rtl::OUString sCurrentDatasource = m_aDatasource.GetSelectEntry();
290*cdf0e10cSrcweir 				if (sCurrentDatasource.getLength())
291*cdf0e10cSrcweir 				{
292*cdf0e10cSrcweir 					// obtain the DS object
293*cdf0e10cSrcweir 					Reference< XCompletedConnection > xDatasource;
294*cdf0e10cSrcweir 					// check if I know this one otherwise transform it into a file URL
295*cdf0e10cSrcweir 					if ( !m_xDSContext->hasByName(sCurrentDatasource) )
296*cdf0e10cSrcweir 					{
297*cdf0e10cSrcweir 						::svt::OFileNotation aFileNotation(sCurrentDatasource);
298*cdf0e10cSrcweir 						sCurrentDatasource = aFileNotation.get(::svt::OFileNotation::N_URL);
299*cdf0e10cSrcweir 					}
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 					if (m_xDSContext->getByName(sCurrentDatasource) >>= xDatasource)
302*cdf0e10cSrcweir 					{	// connect
303*cdf0e10cSrcweir                         // get the default SDB interaction handler
304*cdf0e10cSrcweir 		                Reference< XInteractionHandler > xHandler = getDialog()->getInteractionHandler(this);
305*cdf0e10cSrcweir 		                if (!xHandler.is() )
306*cdf0e10cSrcweir 			                return;
307*cdf0e10cSrcweir 						xConn = xDatasource->connectWithCompletion(xHandler);
308*cdf0e10cSrcweir 						setFormConnection( xConn );
309*cdf0e10cSrcweir 					}
310*cdf0e10cSrcweir 					else
311*cdf0e10cSrcweir 					{
312*cdf0e10cSrcweir 						DBG_ERROR("OTableSelectionPage::implFillTables: invalid data source object returned by the context");
313*cdf0e10cSrcweir 					}
314*cdf0e10cSrcweir 				}
315*cdf0e10cSrcweir 			}
316*cdf0e10cSrcweir 			catch(SQLContext& e) { aSQLException <<= e; }
317*cdf0e10cSrcweir 			catch(SQLWarning& e) { aSQLException <<= e; }
318*cdf0e10cSrcweir 			catch(SQLException& e) { aSQLException <<= e; }
319*cdf0e10cSrcweir 			catch (Exception&)
320*cdf0e10cSrcweir 			{
321*cdf0e10cSrcweir 				DBG_ERROR("OTableSelectionPage::implFillTables: could not fill the table list!");
322*cdf0e10cSrcweir 			}
323*cdf0e10cSrcweir 		}
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 		// will be the table tables of the selected data source
326*cdf0e10cSrcweir 		if ( xConn.is() )
327*cdf0e10cSrcweir 		{
328*cdf0e10cSrcweir 			try
329*cdf0e10cSrcweir 			{
330*cdf0e10cSrcweir 				// get the tables
331*cdf0e10cSrcweir 				Reference< XTablesSupplier > xSupplTables(xConn, UNO_QUERY);
332*cdf0e10cSrcweir 				if ( xSupplTables.is() )
333*cdf0e10cSrcweir 				{
334*cdf0e10cSrcweir 					Reference< XNameAccess > xTables(xSupplTables->getTables(), UNO_QUERY);
335*cdf0e10cSrcweir 					if (xTables.is())
336*cdf0e10cSrcweir 						aTableNames = xTables->getElementNames();
337*cdf0e10cSrcweir 				}
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir                 // and the queries
340*cdf0e10cSrcweir                 Reference< XQueriesSupplier > xSuppQueries( xConn, UNO_QUERY );
341*cdf0e10cSrcweir                 if ( xSuppQueries.is() )
342*cdf0e10cSrcweir                 {
343*cdf0e10cSrcweir 					Reference< XNameAccess > xQueries( xSuppQueries->getQueries(), UNO_QUERY );
344*cdf0e10cSrcweir 					if ( xQueries.is() )
345*cdf0e10cSrcweir 						aQueryNames = xQueries->getElementNames();
346*cdf0e10cSrcweir                 }
347*cdf0e10cSrcweir 			}
348*cdf0e10cSrcweir 			catch(SQLContext& e) { aSQLException <<= e; }
349*cdf0e10cSrcweir 			catch(SQLWarning& e) { aSQLException <<= e; }
350*cdf0e10cSrcweir 			catch(SQLException& e) { aSQLException <<= e; }
351*cdf0e10cSrcweir 			catch (Exception&)
352*cdf0e10cSrcweir 			{
353*cdf0e10cSrcweir 				DBG_ERROR("OTableSelectionPage::implFillTables: could not fill the table list!");
354*cdf0e10cSrcweir 			}
355*cdf0e10cSrcweir 		}
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 		if ( aSQLException.hasValue() )
359*cdf0e10cSrcweir 		{	// an SQLException (or derivee) was thrown ...
360*cdf0e10cSrcweir 			Reference< XInteractionRequest > xRequest = new OInteractionRequest(aSQLException);
361*cdf0e10cSrcweir 			try
362*cdf0e10cSrcweir 			{
363*cdf0e10cSrcweir                 // get the default SDB interaction handler
364*cdf0e10cSrcweir 		        Reference< XInteractionHandler > xHandler = getDialog()->getInteractionHandler(this);
365*cdf0e10cSrcweir 		        if ( xHandler.is() )
366*cdf0e10cSrcweir 				    xHandler->handle(xRequest);
367*cdf0e10cSrcweir 			}
368*cdf0e10cSrcweir 			catch(Exception&) { }
369*cdf0e10cSrcweir 			return;
370*cdf0e10cSrcweir 		}
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir         Image aTableImage, aQueryImage;
373*cdf0e10cSrcweir         {
374*cdf0e10cSrcweir             ::svt::OLocalResourceAccess aLocalResAccess( ModuleRes( RID_PAGE_TABLESELECTION ), RSC_TABPAGE );
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir             bool bIsHiContrast = m_aTable.GetSettings().GetStyleSettings().GetHighContrastMode();
377*cdf0e10cSrcweir             aTableImage = Image( ModuleRes( bIsHiContrast ? IMG_TABLE_HC : IMG_TABLE ) );
378*cdf0e10cSrcweir             aQueryImage = Image( ModuleRes( bIsHiContrast ? IMG_QUERY_HC : IMG_QUERY ) );
379*cdf0e10cSrcweir         }
380*cdf0e10cSrcweir         lcl_fillEntries( m_aTable, aTableNames, aTableImage, CommandType::TABLE );
381*cdf0e10cSrcweir         lcl_fillEntries( m_aTable, aQueryNames, aQueryImage, CommandType::QUERY );
382*cdf0e10cSrcweir 	}
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 	//---------------------------------------------------------------------
385*cdf0e10cSrcweir 	void OTableSelectionPage::implCollectDatasource()
386*cdf0e10cSrcweir 	{
387*cdf0e10cSrcweir 		try
388*cdf0e10cSrcweir 		{
389*cdf0e10cSrcweir 			m_xDSContext = getContext().xDatasourceContext;
390*cdf0e10cSrcweir 			if (m_xDSContext.is())
391*cdf0e10cSrcweir 				fillListBox(m_aDatasource, m_xDSContext->getElementNames());
392*cdf0e10cSrcweir 		}
393*cdf0e10cSrcweir 		catch (Exception&)
394*cdf0e10cSrcweir 		{
395*cdf0e10cSrcweir 			DBG_ERROR("OTableSelectionPage::implCollectDatasource: could not collect the data source names!");
396*cdf0e10cSrcweir 		}
397*cdf0e10cSrcweir 	}
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 	//=====================================================================
400*cdf0e10cSrcweir 	//= OMaybeListSelectionPage
401*cdf0e10cSrcweir 	//=====================================================================
402*cdf0e10cSrcweir 	//---------------------------------------------------------------------
403*cdf0e10cSrcweir 	OMaybeListSelectionPage::OMaybeListSelectionPage( OControlWizard* _pParent, const ResId& _rId )
404*cdf0e10cSrcweir 		:OControlWizardPage(_pParent, _rId)
405*cdf0e10cSrcweir 		,m_pYes(NULL)
406*cdf0e10cSrcweir 		,m_pNo(NULL)
407*cdf0e10cSrcweir 		,m_pList(NULL)
408*cdf0e10cSrcweir 	{
409*cdf0e10cSrcweir 	}
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 	//---------------------------------------------------------------------
412*cdf0e10cSrcweir 	void OMaybeListSelectionPage::announceControls(RadioButton& _rYesButton, RadioButton& _rNoButton, ListBox& _rSelection)
413*cdf0e10cSrcweir 	{
414*cdf0e10cSrcweir 		m_pYes = &_rYesButton;
415*cdf0e10cSrcweir 		m_pNo = &_rNoButton;
416*cdf0e10cSrcweir 		m_pList = &_rSelection;
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 		m_pYes->SetClickHdl(LINK(this, OMaybeListSelectionPage, OnRadioSelected));
419*cdf0e10cSrcweir 		m_pNo->SetClickHdl(LINK(this, OMaybeListSelectionPage, OnRadioSelected));
420*cdf0e10cSrcweir 		implEnableWindows();
421*cdf0e10cSrcweir 	}
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir 	//---------------------------------------------------------------------
424*cdf0e10cSrcweir 	IMPL_LINK( OMaybeListSelectionPage, OnRadioSelected, RadioButton*, /*NOTINTERESTEDIN*/ )
425*cdf0e10cSrcweir 	{
426*cdf0e10cSrcweir 		implEnableWindows();
427*cdf0e10cSrcweir 		return 0L;
428*cdf0e10cSrcweir 	}
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 	//---------------------------------------------------------------------
431*cdf0e10cSrcweir 	void OMaybeListSelectionPage::implInitialize(const String& _rSelection)
432*cdf0e10cSrcweir 	{
433*cdf0e10cSrcweir 		DBG_ASSERT(m_pYes, "OMaybeListSelectionPage::implInitialize: no controls announced!");
434*cdf0e10cSrcweir 		sal_Bool bIsSelection = (0 != _rSelection.Len());
435*cdf0e10cSrcweir 		m_pYes->Check(bIsSelection);
436*cdf0e10cSrcweir 		m_pNo->Check(!bIsSelection);
437*cdf0e10cSrcweir 		m_pList->Enable(bIsSelection);
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 		m_pList->SelectEntry(bIsSelection ? _rSelection : String());
440*cdf0e10cSrcweir 	}
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 	//---------------------------------------------------------------------
443*cdf0e10cSrcweir 	void OMaybeListSelectionPage::implCommit(String& _rSelection)
444*cdf0e10cSrcweir 	{
445*cdf0e10cSrcweir 		_rSelection = m_pYes->IsChecked() ? m_pList->GetSelectEntry() : String();
446*cdf0e10cSrcweir 	}
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	//---------------------------------------------------------------------
449*cdf0e10cSrcweir 	void OMaybeListSelectionPage::implEnableWindows()
450*cdf0e10cSrcweir 	{
451*cdf0e10cSrcweir 		m_pList->Enable(m_pYes->IsChecked());
452*cdf0e10cSrcweir 	}
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir 	//---------------------------------------------------------------------
455*cdf0e10cSrcweir 	void OMaybeListSelectionPage::ActivatePage()
456*cdf0e10cSrcweir 	{
457*cdf0e10cSrcweir 		OControlWizardPage::ActivatePage();
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 		DBG_ASSERT(m_pYes, "OMaybeListSelectionPage::ActivatePage: no controls announced!");
460*cdf0e10cSrcweir 		if (m_pYes->IsChecked())
461*cdf0e10cSrcweir 			m_pList->GrabFocus();
462*cdf0e10cSrcweir 		else
463*cdf0e10cSrcweir 			m_pNo->GrabFocus();
464*cdf0e10cSrcweir 	}
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir 	//=====================================================================
467*cdf0e10cSrcweir 	//= ODBFieldPage
468*cdf0e10cSrcweir 	//=====================================================================
469*cdf0e10cSrcweir 	//---------------------------------------------------------------------
470*cdf0e10cSrcweir 	ODBFieldPage::ODBFieldPage( OControlWizard* _pParent )
471*cdf0e10cSrcweir 		:OMaybeListSelectionPage(_pParent, ModuleRes(RID_PAGE_OPTION_DBFIELD))
472*cdf0e10cSrcweir 		,m_aFrame			(this, ModuleRes(FL_DATABASEFIELD_EXPL))
473*cdf0e10cSrcweir 		,m_aDescription		(this, ModuleRes(FT_DATABASEFIELD_EXPL))
474*cdf0e10cSrcweir 		,m_aQuestion		(this, ModuleRes(FT_DATABASEFIELD_QUEST))
475*cdf0e10cSrcweir 		,m_aStoreYes		(this, ModuleRes(RB_STOREINFIELD_YES))
476*cdf0e10cSrcweir 		,m_aStoreNo			(this, ModuleRes(LB_STOREINFIELD))
477*cdf0e10cSrcweir 		,m_aStoreWhere		(this, ModuleRes(RB_STOREINFIELD_NO))
478*cdf0e10cSrcweir 	{
479*cdf0e10cSrcweir 		FreeResource();
480*cdf0e10cSrcweir 		announceControls(m_aStoreYes, m_aStoreNo, m_aStoreWhere);
481*cdf0e10cSrcweir 		m_aStoreWhere.SetDropDownLineCount(10);
482*cdf0e10cSrcweir 	}
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir 	//---------------------------------------------------------------------
485*cdf0e10cSrcweir 	void ODBFieldPage::initializePage()
486*cdf0e10cSrcweir 	{
487*cdf0e10cSrcweir 		OMaybeListSelectionPage::initializePage();
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir 		// fill the fields page
490*cdf0e10cSrcweir 		fillListBox(m_aStoreWhere, getContext().aFieldNames);
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 		implInitialize(getDBFieldSetting());
493*cdf0e10cSrcweir 	}
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 	//---------------------------------------------------------------------
496*cdf0e10cSrcweir 	sal_Bool ODBFieldPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
497*cdf0e10cSrcweir 	{
498*cdf0e10cSrcweir 		if (!OMaybeListSelectionPage::commitPage(_eReason))
499*cdf0e10cSrcweir 			return sal_False;
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir 		implCommit(getDBFieldSetting());
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir 		return sal_True;
504*cdf0e10cSrcweir 	}
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir //.........................................................................
507*cdf0e10cSrcweir }	// namespace dbp
508*cdf0e10cSrcweir //.........................................................................
509*cdf0e10cSrcweir 
510