1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2a97ec55SAndrew Rist  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2a97ec55SAndrew Rist  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19*2a97ec55SAndrew Rist  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include "controlwizard.hxx"
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XPreparedStatement.hpp>
32cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
34cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
35cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetView.hpp>
36cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawView.hpp>
37cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
38cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
39cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
41cdf0e10cSrcweir #include <comphelper/types.hxx>
42cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
43cdf0e10cSrcweir #include <vcl/msgbox.hxx>
44cdf0e10cSrcweir #include <comphelper/interaction.hxx>
45cdf0e10cSrcweir #include <vcl/stdtext.hxx>
46cdf0e10cSrcweir #include <svtools/localresaccess.hxx>
47cdf0e10cSrcweir #include <connectivity/conncleanup.hxx>
48cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
49cdf0e10cSrcweir #include <tools/urlobj.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir //.........................................................................
52cdf0e10cSrcweir namespace dbp
53cdf0e10cSrcweir {
54cdf0e10cSrcweir //.........................................................................
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
57cdf0e10cSrcweir 	using namespace ::com::sun::star::awt;
58cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
59cdf0e10cSrcweir 	using namespace ::com::sun::star::sdb;
60cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
61cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
62cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
63cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
64cdf0e10cSrcweir 	using namespace ::com::sun::star::drawing;
65cdf0e10cSrcweir 	using namespace ::com::sun::star::frame;
66cdf0e10cSrcweir 	using namespace ::com::sun::star::sheet;
67cdf0e10cSrcweir 	using namespace ::com::sun::star::form;
68cdf0e10cSrcweir 	using namespace ::com::sun::star::task;
69cdf0e10cSrcweir 	using namespace ::svt;
70cdf0e10cSrcweir 	using namespace ::comphelper;
71cdf0e10cSrcweir 	using namespace ::dbtools;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	//=====================================================================
74cdf0e10cSrcweir 	//= OAccessRegulator
75cdf0e10cSrcweir 	//=====================================================================
76cdf0e10cSrcweir 	struct OAccessRegulator
77cdf0e10cSrcweir 	{
78cdf0e10cSrcweir 		friend class OControlWizardPage;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	protected:
OAccessRegulatordbp::OAccessRegulator81cdf0e10cSrcweir 		OAccessRegulator() { }
82cdf0e10cSrcweir 	};
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	//=====================================================================
85cdf0e10cSrcweir 	//= OControlWizardPage
86cdf0e10cSrcweir 	//=====================================================================
87cdf0e10cSrcweir 	//---------------------------------------------------------------------
OControlWizardPage(OControlWizard * _pParent,const ResId & _rResId)88cdf0e10cSrcweir 	OControlWizardPage::OControlWizardPage( OControlWizard* _pParent, const ResId& _rResId )
89cdf0e10cSrcweir 		:OControlWizardPage_Base( _pParent, _rResId )
90cdf0e10cSrcweir 		,m_pFormSettingsSeparator(NULL)
91cdf0e10cSrcweir 		,m_pFormDatasourceLabel(NULL)
92cdf0e10cSrcweir 		,m_pFormDatasource(NULL)
93cdf0e10cSrcweir 		,m_pFormContentTypeLabel(NULL)
94cdf0e10cSrcweir 		,m_pFormContentType(NULL)
95cdf0e10cSrcweir 		,m_pFormTableLabel(NULL)
96cdf0e10cSrcweir 		,m_pFormTable(NULL)
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 	}
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	//---------------------------------------------------------------------
~OControlWizardPage()101cdf0e10cSrcweir 	OControlWizardPage::~OControlWizardPage()
102cdf0e10cSrcweir 	{
103cdf0e10cSrcweir 		delete m_pFormSettingsSeparator;
104cdf0e10cSrcweir 		delete m_pFormDatasourceLabel;
105cdf0e10cSrcweir 		delete m_pFormDatasource;
106cdf0e10cSrcweir 		delete m_pFormContentTypeLabel;
107cdf0e10cSrcweir 		delete m_pFormContentType;
108cdf0e10cSrcweir 		delete m_pFormTableLabel;
109cdf0e10cSrcweir 		delete m_pFormTable;
110cdf0e10cSrcweir 	}
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	//---------------------------------------------------------------------
getDialog()113cdf0e10cSrcweir 	OControlWizard* OControlWizardPage::getDialog()
114cdf0e10cSrcweir 	{
115cdf0e10cSrcweir 		return static_cast< OControlWizard* >(GetParent());
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	//---------------------------------------------------------------------
getDialog() const119cdf0e10cSrcweir 	const OControlWizard* OControlWizardPage::getDialog() const
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		return static_cast< OControlWizard* >(GetParent());
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	//---------------------------------------------------------------------
updateContext()125cdf0e10cSrcweir 	sal_Bool OControlWizardPage::updateContext()
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		return getDialog()->updateContext(OAccessRegulator());
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	//---------------------------------------------------------------------
getFormConnection() const131cdf0e10cSrcweir 	Reference< XConnection > OControlWizardPage::getFormConnection() const
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		return getDialog()->getFormConnection(OAccessRegulator());
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	//---------------------------------------------------------------------
setFormConnection(const Reference<XConnection> & _rxConn,sal_Bool _bAutoDispose)137cdf0e10cSrcweir 	void OControlWizardPage::setFormConnection( const Reference< XConnection >& _rxConn, sal_Bool _bAutoDispose )
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir 		getDialog()->setFormConnection( OAccessRegulator(), _rxConn, _bAutoDispose );
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	//---------------------------------------------------------------------
getContext()143cdf0e10cSrcweir 	const OControlWizardContext& OControlWizardPage::getContext()
144cdf0e10cSrcweir 	{
145cdf0e10cSrcweir 		return getDialog()->getContext();
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	//---------------------------------------------------------------------
fillListBox(ListBox & _rList,const Sequence<::rtl::OUString> & _rItems,sal_Bool _bClear)149cdf0e10cSrcweir 	void OControlWizardPage::fillListBox(ListBox& _rList, const Sequence< ::rtl::OUString >& _rItems, sal_Bool _bClear)
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		if (_bClear)
152cdf0e10cSrcweir 			_rList.Clear();
153cdf0e10cSrcweir 		const ::rtl::OUString* pItems = _rItems.getConstArray();
154cdf0e10cSrcweir 		const ::rtl::OUString* pEnd = pItems + _rItems.getLength();
155cdf0e10cSrcweir 		::svt::WizardTypes::WizardState nPos;
156cdf0e10cSrcweir 		sal_Int32 nIndex = 0;
157cdf0e10cSrcweir 		for (;pItems < pEnd; ++pItems, ++nIndex)
158cdf0e10cSrcweir 		{
159cdf0e10cSrcweir 			nPos = _rList.InsertEntry(*pItems);
160cdf0e10cSrcweir 			_rList.SetEntryData(nPos, reinterpret_cast<void*>(nIndex));
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	//---------------------------------------------------------------------
fillListBox(ComboBox & _rList,const Sequence<::rtl::OUString> & _rItems,sal_Bool _bClear)165cdf0e10cSrcweir 	void OControlWizardPage::fillListBox(ComboBox& _rList, const Sequence< ::rtl::OUString >& _rItems, sal_Bool _bClear)
166cdf0e10cSrcweir 	{
167cdf0e10cSrcweir 		if (_bClear)
168cdf0e10cSrcweir 			_rList.Clear();
169cdf0e10cSrcweir 		const ::rtl::OUString* pItems = _rItems.getConstArray();
170cdf0e10cSrcweir 		const ::rtl::OUString* pEnd = pItems + _rItems.getLength();
171cdf0e10cSrcweir 		::svt::WizardTypes::WizardState nPos;
172cdf0e10cSrcweir 		sal_Int32 nIndex = 0;
173cdf0e10cSrcweir 		for (;pItems < pEnd; ++pItems)
174cdf0e10cSrcweir 		{
175cdf0e10cSrcweir 			nPos = _rList.InsertEntry(*pItems);
176cdf0e10cSrcweir 			_rList.SetEntryData(nPos, reinterpret_cast<void*>(nIndex));
177cdf0e10cSrcweir 		}
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	//---------------------------------------------------------------------
enableFormDatasourceDisplay()181cdf0e10cSrcweir 	void OControlWizardPage::enableFormDatasourceDisplay()
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 		if (m_pFormSettingsSeparator)
184cdf0e10cSrcweir 			// nothing to do
185cdf0e10cSrcweir 			return;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         ModuleRes aModuleRes(RID_PAGE_FORM_DATASOURCE_STATUS);
188cdf0e10cSrcweir 		OLocalResourceAccess aLocalControls(aModuleRes, RSC_TABPAGE);
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 		m_pFormSettingsSeparator	= new FixedLine(this,  ModuleRes(FL_FORMSETINGS));
191cdf0e10cSrcweir 		m_pFormDatasourceLabel		= new FixedText(this,  ModuleRes(FT_FORMDATASOURCELABEL));
192cdf0e10cSrcweir 		m_pFormDatasource			= new FixedText(this,  ModuleRes(FT_FORMDATASOURCE));
193cdf0e10cSrcweir 		m_pFormContentTypeLabel		= new FixedText(this,  ModuleRes(FT_FORMCONTENTTYPELABEL));
194cdf0e10cSrcweir 		m_pFormContentType			= new FixedText(this,  ModuleRes(FT_FORMCONTENTTYPE));
195cdf0e10cSrcweir 		m_pFormTableLabel			= new FixedText(this,  ModuleRes(FT_FORMTABLELABEL));
196cdf0e10cSrcweir 		m_pFormTable				= new FixedText(this,  ModuleRes(FT_FORMTABLE));
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 		const OControlWizardContext& rContext = getContext();
199cdf0e10cSrcweir 		if ( rContext.bEmbedded )
200cdf0e10cSrcweir 		{
201cdf0e10cSrcweir 			m_pFormDatasourceLabel->Hide();
202cdf0e10cSrcweir 			m_pFormDatasource->Hide();
203cdf0e10cSrcweir 			m_pFormContentTypeLabel->SetPosPixel(m_pFormDatasourceLabel->GetPosPixel());
204cdf0e10cSrcweir 			m_pFormContentType->SetPosPixel(m_pFormDatasource->GetPosPixel());
205cdf0e10cSrcweir 			m_pFormTableLabel->SetPosPixel(::Point(m_pFormDatasourceLabel->GetPosPixel().X(),m_pFormTableLabel->GetPosPixel().Y()));
206cdf0e10cSrcweir 			m_pFormTable->SetPosPixel(::Point(m_pFormDatasource->GetPosPixel().X(),m_pFormTable->GetPosPixel().Y()));
207cdf0e10cSrcweir 		}
208cdf0e10cSrcweir 	}
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	//---------------------------------------------------------------------
adjustControlForNoDSDisplay(Control * _pControl,sal_Bool _bConstLowerDistance)211cdf0e10cSrcweir 	void OControlWizardPage::adjustControlForNoDSDisplay(Control* _pControl, sal_Bool _bConstLowerDistance)
212cdf0e10cSrcweir 	{
213cdf0e10cSrcweir 		::Size aDistanceToMove = LogicToPixel( ::Size( 0, 37 ), MAP_APPFONT );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 		::Point aPos = _pControl->GetPosPixel();
216cdf0e10cSrcweir 		aPos.Y() -= aDistanceToMove.Height();
217cdf0e10cSrcweir 		_pControl->SetPosPixel(aPos);
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 		if (_bConstLowerDistance)
220cdf0e10cSrcweir 		{
221cdf0e10cSrcweir 			::Size aSize = _pControl->GetSizePixel();
222cdf0e10cSrcweir 			aSize.Height() += aDistanceToMove.Height();
223cdf0e10cSrcweir 			_pControl->SetSizePixel(aSize);
224cdf0e10cSrcweir 		}
225cdf0e10cSrcweir 	}
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 	//---------------------------------------------------------------------
initializePage()228cdf0e10cSrcweir 	void OControlWizardPage::initializePage()
229cdf0e10cSrcweir 	{
230cdf0e10cSrcweir 		if (m_pFormDatasource && m_pFormContentTypeLabel && m_pFormTable)
231cdf0e10cSrcweir 		{
232cdf0e10cSrcweir 			const OControlWizardContext& rContext = getContext();
233cdf0e10cSrcweir 			::rtl::OUString sDataSource;
234cdf0e10cSrcweir 			::rtl::OUString sCommand;
235cdf0e10cSrcweir 			sal_Int32 nCommandType = CommandType::COMMAND;
236cdf0e10cSrcweir 			try
237cdf0e10cSrcweir 			{
238cdf0e10cSrcweir 				rContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("DataSourceName")) >>= sDataSource;
239cdf0e10cSrcweir 				rContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("Command")) >>= sCommand;
240cdf0e10cSrcweir 				rContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("CommandType")) >>= nCommandType;
241cdf0e10cSrcweir 			}
242cdf0e10cSrcweir 			catch(const Exception&)
243cdf0e10cSrcweir 			{
244cdf0e10cSrcweir 				DBG_ERROR("OControlWizardPage::initializePage: caught an exception!");
245cdf0e10cSrcweir 			}
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 			INetURLObject aURL( sDataSource );
248cdf0e10cSrcweir 			if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
249cdf0e10cSrcweir 				sDataSource = aURL.GetName(INetURLObject::DECODE_WITH_CHARSET);
250cdf0e10cSrcweir 			m_pFormDatasource->SetText(sDataSource);
251cdf0e10cSrcweir 			m_pFormTable->SetText(sCommand);
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 			::svt::WizardTypes::WizardState nCommandTypeResourceId = 0;
254cdf0e10cSrcweir 			switch (nCommandType)
255cdf0e10cSrcweir 			{
256cdf0e10cSrcweir 				case CommandType::TABLE:
257cdf0e10cSrcweir 					nCommandTypeResourceId = RID_STR_TYPE_TABLE;
258cdf0e10cSrcweir 					break;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 				case CommandType::QUERY:
261cdf0e10cSrcweir 					nCommandTypeResourceId = RID_STR_TYPE_QUERY;
262cdf0e10cSrcweir 					break;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 				default:
265cdf0e10cSrcweir 					nCommandTypeResourceId = RID_STR_TYPE_COMMAND;
266cdf0e10cSrcweir 					break;
267cdf0e10cSrcweir 			}
268cdf0e10cSrcweir 			m_pFormContentType->SetText(String(ModuleRes(nCommandTypeResourceId)));
269cdf0e10cSrcweir 		}
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 		OControlWizardPage_Base::initializePage();
272cdf0e10cSrcweir 	}
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 	//=====================================================================
275cdf0e10cSrcweir 	//= OControlWizard
276cdf0e10cSrcweir 	//=====================================================================
277cdf0e10cSrcweir 	//---------------------------------------------------------------------
OControlWizard(Window * _pParent,const ResId & _rId,const Reference<XPropertySet> & _rxObjectModel,const Reference<XMultiServiceFactory> & _rxORB)278cdf0e10cSrcweir 	OControlWizard::OControlWizard( Window* _pParent, const ResId& _rId,
279cdf0e10cSrcweir 			const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB )
280cdf0e10cSrcweir 		:OWizardMachine(_pParent, _rId, WZB_CANCEL | WZB_PREVIOUS | WZB_NEXT | WZB_FINISH)
281cdf0e10cSrcweir 		,m_xORB(_rxORB)
282cdf0e10cSrcweir 	{
283cdf0e10cSrcweir 		m_aContext.xObjectModel = _rxObjectModel;
284cdf0e10cSrcweir 		initContext();
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 		SetPageSizePixel(LogicToPixel(::Size(WINDOW_SIZE_X, WINDOW_SIZE_Y), MAP_APPFONT));
287cdf0e10cSrcweir 		ShowButtonFixedLine(sal_True);
288cdf0e10cSrcweir 		defaultButton(WZB_NEXT);
289cdf0e10cSrcweir 		enableButtons(WZB_FINISH, sal_False);
290cdf0e10cSrcweir 	}
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	//---------------------------------------------------------------------
~OControlWizard()293cdf0e10cSrcweir 	OControlWizard::~OControlWizard()
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 	}
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	//---------------------------------------------------------------------
Execute()298cdf0e10cSrcweir 	short OControlWizard::Execute()
299cdf0e10cSrcweir 	{
300cdf0e10cSrcweir 		// get the class id of the control we're dealing with
301cdf0e10cSrcweir 		sal_Int16 nClassId = FormComponentType::CONTROL;
302cdf0e10cSrcweir 		try
303cdf0e10cSrcweir 		{
304cdf0e10cSrcweir 			getContext().xObjectModel->getPropertyValue(::rtl::OUString::createFromAscii("ClassId")) >>= nClassId;
305cdf0e10cSrcweir 		}
306cdf0e10cSrcweir 		catch(Exception&)
307cdf0e10cSrcweir 		{
308cdf0e10cSrcweir 			DBG_ERROR("OControlWizard::activate: could not obtain the class id!");
309cdf0e10cSrcweir 		}
310cdf0e10cSrcweir 		if (!approveControl(nClassId))
311cdf0e10cSrcweir 		{
312cdf0e10cSrcweir 			// TODO: MessageBox or exception
313cdf0e10cSrcweir 			return RET_CANCEL;
314cdf0e10cSrcweir 		}
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 		ActivatePage();
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 		return OControlWizard_Base::Execute();
319cdf0e10cSrcweir 	}
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 	//---------------------------------------------------------------------
ActivatePage()322cdf0e10cSrcweir 	void OControlWizard::ActivatePage()
323cdf0e10cSrcweir 	{
324cdf0e10cSrcweir 		OControlWizard_Base::ActivatePage();
325cdf0e10cSrcweir 	}
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 	//---------------------------------------------------------------------
implDetermineShape()328cdf0e10cSrcweir 	void OControlWizard::implDetermineShape()
329cdf0e10cSrcweir 	{
330cdf0e10cSrcweir 		Reference< XIndexAccess > xPageObjects(m_aContext.xDrawPage, UNO_QUERY);
331cdf0e10cSrcweir 		DBG_ASSERT(xPageObjects.is(), "OControlWizard::implDetermineShape: invalid page!");
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 		// for comparing the model
334cdf0e10cSrcweir 		Reference< XControlModel > xModelCompare(m_aContext.xObjectModel, UNO_QUERY);
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 		if (xPageObjects.is())
337cdf0e10cSrcweir 		{
338cdf0e10cSrcweir 			// loop through all objects of the page
339cdf0e10cSrcweir 			sal_Int32 nObjects = xPageObjects->getCount();
340cdf0e10cSrcweir 			Reference< XControlShape > xControlShape;
341cdf0e10cSrcweir 			Reference< XControlModel > xControlModel;
342cdf0e10cSrcweir 			for (sal_Int32 i=0; i<nObjects; ++i)
343cdf0e10cSrcweir 			{
344cdf0e10cSrcweir 				if (xPageObjects->getByIndex(i) >>= xControlShape)
345cdf0e10cSrcweir 				{	// it _is_ a control shape
346cdf0e10cSrcweir 					xControlModel = xControlShape->getControl();
347cdf0e10cSrcweir 					DBG_ASSERT(xControlModel.is(), "OControlWizard::implDetermineShape: control shape without model!");
348cdf0e10cSrcweir 					if (xModelCompare.get() == xControlModel.get())
349cdf0e10cSrcweir 					{
350cdf0e10cSrcweir 						m_aContext.xObjectShape = xControlShape;
351cdf0e10cSrcweir 						break;
352cdf0e10cSrcweir 					}
353cdf0e10cSrcweir 				}
354cdf0e10cSrcweir 			}
355cdf0e10cSrcweir 		}
356cdf0e10cSrcweir 	}
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 	//---------------------------------------------------------------------
implDetermineForm()359cdf0e10cSrcweir 	void OControlWizard::implDetermineForm()
360cdf0e10cSrcweir 	{
361cdf0e10cSrcweir 		Reference< XChild > xModelAsChild(m_aContext.xObjectModel, UNO_QUERY);
362cdf0e10cSrcweir 		Reference< XInterface > xControlParent;
363cdf0e10cSrcweir 		if (xModelAsChild.is())
364cdf0e10cSrcweir 			xControlParent = xModelAsChild->getParent();
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 		m_aContext.xForm = Reference< XPropertySet >(xControlParent, UNO_QUERY);
367cdf0e10cSrcweir 		m_aContext.xRowSet = Reference< XRowSet >(xControlParent, UNO_QUERY);
368cdf0e10cSrcweir 		DBG_ASSERT(m_aContext.xForm.is() && m_aContext.xRowSet.is(),
369cdf0e10cSrcweir 			"OControlWizard::implDetermineForm: missing some interfaces of the control parent!");
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 	}
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 	//---------------------------------------------------------------------
implDeterminePage()374cdf0e10cSrcweir 	void OControlWizard::implDeterminePage()
375cdf0e10cSrcweir 	{
376cdf0e10cSrcweir 		try
377cdf0e10cSrcweir 		{
378cdf0e10cSrcweir 			// get the document model
379cdf0e10cSrcweir 			Reference< XChild > xControlAsChild(m_aContext.xObjectModel, UNO_QUERY);
380cdf0e10cSrcweir 			Reference< XChild > xModelSearch(xControlAsChild->getParent(), UNO_QUERY);
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 			Reference< XModel > xModel(xModelSearch, UNO_QUERY);
383cdf0e10cSrcweir 			while (xModelSearch.is() && !xModel.is())
384cdf0e10cSrcweir 			{
385cdf0e10cSrcweir 				xModelSearch = Reference< XChild >(xModelSearch->getParent(), UNO_QUERY);
386cdf0e10cSrcweir 				xModel = Reference< XModel >(xModelSearch, UNO_QUERY);
387cdf0e10cSrcweir 			}
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 			Reference< XDrawPage > xPage;
390cdf0e10cSrcweir 			if (xModel.is())
391cdf0e10cSrcweir 			{
392cdf0e10cSrcweir 				m_aContext.xDocumentModel = xModel;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 				Reference< XDrawPageSupplier > xPageSupp(xModel, UNO_QUERY);
395cdf0e10cSrcweir 				if (xPageSupp.is())
396cdf0e10cSrcweir 				{	// it's a document with only one page -> Writer
397cdf0e10cSrcweir 					xPage = xPageSupp->getDrawPage();
398cdf0e10cSrcweir 				}
399cdf0e10cSrcweir 				else
400cdf0e10cSrcweir 				{
401cdf0e10cSrcweir 					// get the controller currently working on this model
402cdf0e10cSrcweir 					Reference< XController > xController = xModel->getCurrentController();
403cdf0e10cSrcweir 					DBG_ASSERT(xController.is(), "OControlWizard::implDeterminePage: no current controller!");
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 					// maybe it's a spredsheet
406cdf0e10cSrcweir 					Reference< XSpreadsheetView > xView(xController, UNO_QUERY);
407cdf0e10cSrcweir 					if (xView.is())
408cdf0e10cSrcweir 					{	// okay, it is one
409cdf0e10cSrcweir 						Reference< XSpreadsheet > xSheet = xView->getActiveSheet();
410cdf0e10cSrcweir 						xPageSupp = Reference< XDrawPageSupplier >(xSheet, UNO_QUERY);
411cdf0e10cSrcweir 						DBG_ASSERT(xPageSupp.is(), "OControlWizard::implDeterminePage: a spreadsheet which is no page supplier!");
412cdf0e10cSrcweir 						if (xPageSupp.is())
413cdf0e10cSrcweir 							xPage = xPageSupp->getDrawPage();
414cdf0e10cSrcweir 					}
415cdf0e10cSrcweir 					else
416cdf0e10cSrcweir 					{	// can be a draw/impress doc only
417cdf0e10cSrcweir 						Reference< XDrawView > xDrawView(xController, UNO_QUERY);
418cdf0e10cSrcweir 						DBG_ASSERT(xDrawView.is(), "OControlWizard::implDeterminePage: no alternatives left ... can't determine the page!");
419cdf0e10cSrcweir 						if (xDrawView.is())
420cdf0e10cSrcweir 							xPage = xDrawView->getCurrentPage();
421cdf0e10cSrcweir 					}
422cdf0e10cSrcweir 				}
423cdf0e10cSrcweir 			}
424cdf0e10cSrcweir 			else
425cdf0e10cSrcweir 			{
426cdf0e10cSrcweir 				DBG_ASSERT(xPage.is(), "OControlWizard::implDeterminePage: can't determine the page (no model)!");
427cdf0e10cSrcweir 			}
428cdf0e10cSrcweir 			m_aContext.xDrawPage = xPage;
429cdf0e10cSrcweir 		}
430cdf0e10cSrcweir 		catch(Exception&)
431cdf0e10cSrcweir 		{
432cdf0e10cSrcweir 			DBG_ERROR("OControlWizard::implDeterminePage: caught an exception!");
433cdf0e10cSrcweir 		}
434cdf0e10cSrcweir 	}
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	//---------------------------------------------------------------------
implGetDSContext()437cdf0e10cSrcweir 	void OControlWizard::implGetDSContext()
438cdf0e10cSrcweir 	{
439cdf0e10cSrcweir 		Reference< XMultiServiceFactory > xORB = getServiceFactory();
440cdf0e10cSrcweir 		try
441cdf0e10cSrcweir 		{
442cdf0e10cSrcweir 			DBG_ASSERT(xORB.is(), "OControlWizard::implGetDSContext: invalid service factory!");
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 			Reference< XInterface > xContext;
445cdf0e10cSrcweir 			if (xORB.is())
446cdf0e10cSrcweir 				xContext = xORB->createInstance(::rtl::OUString::createFromAscii("com.sun.star.sdb.DatabaseContext"));
447cdf0e10cSrcweir 			DBG_ASSERT(xContext.is(), "OControlWizard::implGetDSContext: invalid database context!");
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 			m_aContext.xDatasourceContext = Reference< XNameAccess >(xContext, UNO_QUERY);
450cdf0e10cSrcweir 			DBG_ASSERT(m_aContext.xDatasourceContext.is() || !xContext.is(), "OControlWizard::implGetDSContext: invalid database context (missing the XNameAccess)!");
451cdf0e10cSrcweir 		}
452cdf0e10cSrcweir 		catch(Exception&)
453cdf0e10cSrcweir 		{
454cdf0e10cSrcweir 			DBG_ERROR("OControlWizard::implGetDSContext: invalid database context!");
455cdf0e10cSrcweir 		}
456cdf0e10cSrcweir 	}
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 	//---------------------------------------------------------------------
getFormConnection(const OAccessRegulator &) const459cdf0e10cSrcweir 	Reference< XConnection > OControlWizard::getFormConnection(const OAccessRegulator&) const
460cdf0e10cSrcweir 	{
461cdf0e10cSrcweir 		return getFormConnection();
462cdf0e10cSrcweir 	}
463cdf0e10cSrcweir     //---------------------------------------------------------------------
getFormConnection() const464cdf0e10cSrcweir 	Reference< XConnection > OControlWizard::getFormConnection() const
465cdf0e10cSrcweir 	{
466cdf0e10cSrcweir 		Reference< XConnection > xConn;
467cdf0e10cSrcweir 		try
468cdf0e10cSrcweir 		{
469cdf0e10cSrcweir 			if ( !::dbtools::isEmbeddedInDatabase(m_aContext.xForm,xConn) )
470cdf0e10cSrcweir 				m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("ActiveConnection")) >>= xConn;
471cdf0e10cSrcweir 		}
472cdf0e10cSrcweir 		catch(const Exception&)
473cdf0e10cSrcweir 		{
474cdf0e10cSrcweir 			DBG_ERROR("OControlWizard::getFormConnection: caught an exception!");
475cdf0e10cSrcweir 		}
476cdf0e10cSrcweir 		return xConn;
477cdf0e10cSrcweir 	}
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 	//---------------------------------------------------------------------
setFormConnection(const OAccessRegulator & _rAccess,const Reference<XConnection> & _rxConn,sal_Bool _bAutoDispose)480cdf0e10cSrcweir 	void OControlWizard::setFormConnection( const OAccessRegulator& _rAccess, const Reference< XConnection >& _rxConn, sal_Bool _bAutoDispose )
481cdf0e10cSrcweir 	{
482cdf0e10cSrcweir 		try
483cdf0e10cSrcweir 		{
484cdf0e10cSrcweir 			Reference< XConnection > xOldConn = getFormConnection(_rAccess);
485cdf0e10cSrcweir 			if (xOldConn.get() == _rxConn.get())
486cdf0e10cSrcweir 				return;
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 			disposeComponent(xOldConn);
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 			// set the new connection
491cdf0e10cSrcweir 			if ( _bAutoDispose )
492cdf0e10cSrcweir 			{
493cdf0e10cSrcweir 				// for this, use a AutoDisposer (so the conn is cleaned up when the form dies or get's another connection)
494cdf0e10cSrcweir 				Reference< XRowSet > xFormRowSet( m_aContext.xForm, UNO_QUERY );
495cdf0e10cSrcweir 				OAutoConnectionDisposer* pAutoDispose = new OAutoConnectionDisposer( xFormRowSet, _rxConn );
496cdf0e10cSrcweir 				Reference< XPropertyChangeListener > xEnsureDelete( pAutoDispose );
497cdf0e10cSrcweir 			}
498cdf0e10cSrcweir 			else
499cdf0e10cSrcweir 			{
500cdf0e10cSrcweir 				m_aContext.xForm->setPropertyValue( ::rtl::OUString::createFromAscii("ActiveConnection"), makeAny( _rxConn ) );
501cdf0e10cSrcweir 			}
502cdf0e10cSrcweir 		}
503cdf0e10cSrcweir 		catch(const Exception&)
504cdf0e10cSrcweir 		{
505cdf0e10cSrcweir 			DBG_ERROR("OControlWizard::setFormConnection: caught an exception!");
506cdf0e10cSrcweir 		}
507cdf0e10cSrcweir 	}
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 	//---------------------------------------------------------------------
updateContext(const OAccessRegulator &)510cdf0e10cSrcweir 	sal_Bool OControlWizard::updateContext(const OAccessRegulator&)
511cdf0e10cSrcweir 	{
512cdf0e10cSrcweir 		return initContext();
513cdf0e10cSrcweir 	}
514cdf0e10cSrcweir     //---------------------------------------------------------------------
getInteractionHandler(Window * _pWindow) const515cdf0e10cSrcweir     Reference< XInteractionHandler > OControlWizard::getInteractionHandler(Window* _pWindow) const
516cdf0e10cSrcweir     {
517cdf0e10cSrcweir         const ::rtl::OUString sInteractionHandlerServiceName = ::rtl::OUString::createFromAscii("com.sun.star.task.InteractionHandler");
518cdf0e10cSrcweir 		Reference< XInteractionHandler > xHandler;
519cdf0e10cSrcweir 		try
520cdf0e10cSrcweir 		{
521cdf0e10cSrcweir 			if (getServiceFactory().is())
522cdf0e10cSrcweir 				xHandler = Reference< XInteractionHandler >(getServiceFactory()->createInstance(sInteractionHandlerServiceName), UNO_QUERY);
523cdf0e10cSrcweir 		}
524cdf0e10cSrcweir 		catch(Exception&) { }
525cdf0e10cSrcweir 		if (!xHandler.is())
526cdf0e10cSrcweir 			ShowServiceNotAvailableError(_pWindow, sInteractionHandlerServiceName, sal_True);
527cdf0e10cSrcweir         return xHandler;
528cdf0e10cSrcweir     }
529cdf0e10cSrcweir 	//---------------------------------------------------------------------
initContext()530cdf0e10cSrcweir 	sal_Bool OControlWizard::initContext()
531cdf0e10cSrcweir 	{
532cdf0e10cSrcweir 		DBG_ASSERT(m_aContext.xObjectModel.is(), "OGroupBoxWizard::initContext: have no control model to work with!");
533cdf0e10cSrcweir 		if (!m_aContext.xObjectModel.is())
534cdf0e10cSrcweir 			return sal_False;
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 		// reset the context
537cdf0e10cSrcweir 		m_aContext.xForm.clear();
538cdf0e10cSrcweir 		m_aContext.xRowSet.clear();
539cdf0e10cSrcweir 		m_aContext.xDocumentModel.clear();
540cdf0e10cSrcweir 		m_aContext.xDrawPage.clear();
541cdf0e10cSrcweir 		m_aContext.xObjectShape.clear();
542cdf0e10cSrcweir 		m_aContext.aFieldNames.realloc(0);
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 		m_aContext.xObjectContainer.clear();
545cdf0e10cSrcweir 		m_aContext.aTypes.clear();
546cdf0e10cSrcweir 		m_aContext.bEmbedded = sal_False;
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 		Any aSQLException;
549cdf0e10cSrcweir 		Reference< XPreparedStatement >  xStatement;
550cdf0e10cSrcweir 		try
551cdf0e10cSrcweir 		{
552cdf0e10cSrcweir 			// get the datasource context
553cdf0e10cSrcweir 			implGetDSContext();
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 			// first, determine the form the control belongs to
556cdf0e10cSrcweir 			implDetermineForm();
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 			// need the page, too
559cdf0e10cSrcweir 			implDeterminePage();
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 			// the shape of the control
562cdf0e10cSrcweir 			implDetermineShape();
563cdf0e10cSrcweir 
564cdf0e10cSrcweir 			// get the columns of the object the settins refer to
565cdf0e10cSrcweir 			Reference< XNameAccess >  xColumns;
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 			if (m_aContext.xForm.is())
568cdf0e10cSrcweir 			{
569cdf0e10cSrcweir 				// collect some properties of the form
570cdf0e10cSrcweir 				::rtl::OUString sObjectName = ::comphelper::getString(m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("Command")));
571cdf0e10cSrcweir 				sal_Int32 nObjectType = ::comphelper::getINT32(m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("CommandType")));
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 				// calculate the connection the rowset is working with
574cdf0e10cSrcweir 				Reference< XConnection > xConnection;
575cdf0e10cSrcweir                 m_aContext.bEmbedded = ::dbtools::isEmbeddedInDatabase( m_aContext.xForm, xConnection );
576cdf0e10cSrcweir 				if ( !m_aContext.bEmbedded )
577cdf0e10cSrcweir                     xConnection = ::dbtools::connectRowset( m_aContext.xRowSet, getServiceFactory(), sal_True );
578cdf0e10cSrcweir 
579cdf0e10cSrcweir 				// get the fields
580cdf0e10cSrcweir 				if (xConnection.is())
581cdf0e10cSrcweir 				{
582cdf0e10cSrcweir 					switch (nObjectType)
583cdf0e10cSrcweir 					{
584cdf0e10cSrcweir 						case 0:
585cdf0e10cSrcweir 						{
586cdf0e10cSrcweir 							Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
587cdf0e10cSrcweir 							if (xSupplyTables.is() && xSupplyTables->getTables().is() && xSupplyTables->getTables()->hasByName(sObjectName))
588cdf0e10cSrcweir 							{
589cdf0e10cSrcweir 								Reference< XColumnsSupplier >  xSupplyColumns;
590cdf0e10cSrcweir 								m_aContext.xObjectContainer = xSupplyTables->getTables();
591cdf0e10cSrcweir 								m_aContext.xObjectContainer->getByName(sObjectName) >>= xSupplyColumns;
592cdf0e10cSrcweir 								DBG_ASSERT(xSupplyColumns.is(), "OControlWizard::initContext: invalid table columns!");
593cdf0e10cSrcweir 								xColumns = xSupplyColumns->getColumns();
594cdf0e10cSrcweir 							}
595cdf0e10cSrcweir 						}
596cdf0e10cSrcweir 						break;
597cdf0e10cSrcweir 						case 1:
598cdf0e10cSrcweir 						{
599cdf0e10cSrcweir 							Reference< XQueriesSupplier >  xSupplyQueries(xConnection, UNO_QUERY);
600cdf0e10cSrcweir 							if (xSupplyQueries.is() && xSupplyQueries->getQueries().is() && xSupplyQueries->getQueries()->hasByName(sObjectName))
601cdf0e10cSrcweir 							{
602cdf0e10cSrcweir 								Reference< XColumnsSupplier >  xSupplyColumns;
603cdf0e10cSrcweir 								m_aContext.xObjectContainer = xSupplyQueries->getQueries();
604cdf0e10cSrcweir 								m_aContext.xObjectContainer->getByName(sObjectName) >>= xSupplyColumns;
605cdf0e10cSrcweir 								DBG_ASSERT(xSupplyColumns.is(), "OControlWizard::initContext: invalid query columns!");
606cdf0e10cSrcweir 								xColumns  = xSupplyColumns->getColumns();
607cdf0e10cSrcweir 							}
608cdf0e10cSrcweir 						}
609cdf0e10cSrcweir 						break;
610cdf0e10cSrcweir 						default:
611cdf0e10cSrcweir 						{
612cdf0e10cSrcweir 							xStatement = xConnection->prepareStatement(sObjectName);
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 							// not interested in any results, only in the fields
615cdf0e10cSrcweir 							Reference< XPropertySet > xStatementProps(xStatement, UNO_QUERY);
616cdf0e10cSrcweir 							xStatementProps->setPropertyValue(::rtl::OUString::createFromAscii("MaxRows"), makeAny(sal_Int32(0)));
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 							// TODO: think about handling local SQLExceptions here ...
619cdf0e10cSrcweir 							Reference< XColumnsSupplier >  xSupplyCols(xStatement->executeQuery(), UNO_QUERY);
620cdf0e10cSrcweir 							if (xSupplyCols.is())
621cdf0e10cSrcweir 								xColumns = xSupplyCols->getColumns();
622cdf0e10cSrcweir 						}
623cdf0e10cSrcweir 					}
624cdf0e10cSrcweir 				}
625cdf0e10cSrcweir 			}
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 			if (xColumns.is())
628cdf0e10cSrcweir 			{
629cdf0e10cSrcweir 				m_aContext.aFieldNames = xColumns->getElementNames();
630cdf0e10cSrcweir 				static const ::rtl::OUString s_sFieldTypeProperty	= ::rtl::OUString::createFromAscii("Type");
631cdf0e10cSrcweir 				const ::rtl::OUString* pBegin = m_aContext.aFieldNames.getConstArray();
632cdf0e10cSrcweir 				const ::rtl::OUString* pEnd	  = pBegin + m_aContext.aFieldNames.getLength();
633cdf0e10cSrcweir 				for(;pBegin != pEnd;++pBegin)
634cdf0e10cSrcweir 				{
635cdf0e10cSrcweir 					sal_Int32 nFieldType = DataType::OTHER;
636cdf0e10cSrcweir 					try
637cdf0e10cSrcweir 					{
638cdf0e10cSrcweir 						Reference< XPropertySet > xColumn;
639cdf0e10cSrcweir 						xColumns->getByName(*pBegin) >>= xColumn;
640cdf0e10cSrcweir 						xColumn->getPropertyValue(s_sFieldTypeProperty) >>= nFieldType;
641cdf0e10cSrcweir 					}
642cdf0e10cSrcweir 					catch(Exception&)
643cdf0e10cSrcweir 					{
644cdf0e10cSrcweir 						DBG_ERROR("OControlWizard::initContext: unexpected exception while gathering column information!");
645cdf0e10cSrcweir 					}
646cdf0e10cSrcweir 					m_aContext.aTypes.insert(OControlWizardContext::TNameTypeMap::value_type(*pBegin,nFieldType));
647cdf0e10cSrcweir 				}
648cdf0e10cSrcweir 			}
649cdf0e10cSrcweir 		}
650cdf0e10cSrcweir 		catch(SQLContext& e) { aSQLException <<= e; }
651cdf0e10cSrcweir 		catch(SQLWarning& e) { aSQLException <<= e; }
652cdf0e10cSrcweir 		catch(SQLException& e) { aSQLException <<= e; }
653cdf0e10cSrcweir 		catch(Exception&)
654cdf0e10cSrcweir 		{
655cdf0e10cSrcweir 			DBG_ERROR("OControlWizard::initContext: could not retrieve the control context (caught an exception)!");
656cdf0e10cSrcweir 		}
657cdf0e10cSrcweir 
658cdf0e10cSrcweir 		::comphelper::disposeComponent(xStatement);
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 		if (aSQLException.hasValue())
661cdf0e10cSrcweir 		{	// an SQLException (or derivee) was thrown ...
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 			// prepend an extra SQLContext explaining what we were doing
664cdf0e10cSrcweir 			SQLContext aContext;
665cdf0e10cSrcweir 			aContext.Message = String(ModuleRes(RID_STR_COULDNOTOPENTABLE));
666cdf0e10cSrcweir 			aContext.NextException = aSQLException;
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 			// create an interaction handler to display this exception
669cdf0e10cSrcweir 			Reference< XInteractionHandler > xHandler = getInteractionHandler(this);
670cdf0e10cSrcweir 			if ( !xHandler.is() )
671cdf0e10cSrcweir 				return sal_False;
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 			Reference< XInteractionRequest > xRequest = new OInteractionRequest(makeAny(aContext));
674cdf0e10cSrcweir 			try
675cdf0e10cSrcweir 			{
676cdf0e10cSrcweir 				xHandler->handle(xRequest);
677cdf0e10cSrcweir 			}
678cdf0e10cSrcweir 			catch(Exception&) { }
679cdf0e10cSrcweir 			return sal_False;
680cdf0e10cSrcweir 		}
681cdf0e10cSrcweir 
682cdf0e10cSrcweir 		return 0 != m_aContext.aFieldNames.getLength();
683cdf0e10cSrcweir 	}
684cdf0e10cSrcweir 
685cdf0e10cSrcweir 	//---------------------------------------------------------------------
commitControlSettings(OControlWizardSettings * _pSettings)686cdf0e10cSrcweir 	void OControlWizard::commitControlSettings(OControlWizardSettings* _pSettings)
687cdf0e10cSrcweir 	{
688cdf0e10cSrcweir 		DBG_ASSERT(m_aContext.xObjectModel.is(), "OControlWizard::commitControlSettings: have no control model to work with!");
689cdf0e10cSrcweir 		if (!m_aContext.xObjectModel.is())
690cdf0e10cSrcweir 			return;
691cdf0e10cSrcweir 
692cdf0e10cSrcweir 		// the only thing we have at the moment is the label
693cdf0e10cSrcweir 		try
694cdf0e10cSrcweir 		{
695cdf0e10cSrcweir 			::rtl::OUString sLabelPropertyName = ::rtl::OUString::createFromAscii("Label");
696cdf0e10cSrcweir 			Reference< XPropertySetInfo > xInfo = m_aContext.xObjectModel->getPropertySetInfo();
697cdf0e10cSrcweir 			if (xInfo.is() && xInfo->hasPropertyByName(sLabelPropertyName))
698cdf0e10cSrcweir 			{
699cdf0e10cSrcweir 				::rtl::OUString sControlLabel(_pSettings->sControlLabel);
700cdf0e10cSrcweir 				m_aContext.xObjectModel->setPropertyValue(
701cdf0e10cSrcweir 					::rtl::OUString::createFromAscii("Label"),
702cdf0e10cSrcweir 					makeAny(sControlLabel)
703cdf0e10cSrcweir 				);
704cdf0e10cSrcweir 			}
705cdf0e10cSrcweir 		}
706cdf0e10cSrcweir 		catch(Exception&)
707cdf0e10cSrcweir 		{
708cdf0e10cSrcweir 			DBG_ERROR("OControlWizard::commitControlSettings: could not commit the basic control settings!");
709cdf0e10cSrcweir 		}
710cdf0e10cSrcweir 	}
711cdf0e10cSrcweir 
712cdf0e10cSrcweir 	//---------------------------------------------------------------------
initControlSettings(OControlWizardSettings * _pSettings)713cdf0e10cSrcweir 	void OControlWizard::initControlSettings(OControlWizardSettings* _pSettings)
714cdf0e10cSrcweir 	{
715cdf0e10cSrcweir 		DBG_ASSERT(m_aContext.xObjectModel.is(), "OControlWizard::initControlSettings: have no control model to work with!");
716cdf0e10cSrcweir 		if (!m_aContext.xObjectModel.is())
717cdf0e10cSrcweir 			return;
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 		// initialize some settings from the control model give
720cdf0e10cSrcweir 		try
721cdf0e10cSrcweir 		{
722cdf0e10cSrcweir 			::rtl::OUString sLabelPropertyName = ::rtl::OUString::createFromAscii("Label");
723cdf0e10cSrcweir 			Reference< XPropertySetInfo > xInfo = m_aContext.xObjectModel->getPropertySetInfo();
724cdf0e10cSrcweir 			if (xInfo.is() && xInfo->hasPropertyByName(sLabelPropertyName))
725cdf0e10cSrcweir 			{
726cdf0e10cSrcweir 				::rtl::OUString sControlLabel;
727cdf0e10cSrcweir 				m_aContext.xObjectModel->getPropertyValue(sLabelPropertyName) >>= sControlLabel;
728cdf0e10cSrcweir 				_pSettings->sControlLabel = sControlLabel;
729cdf0e10cSrcweir 			}
730cdf0e10cSrcweir 		}
731cdf0e10cSrcweir 		catch(Exception&)
732cdf0e10cSrcweir 		{
733cdf0e10cSrcweir 			DBG_ERROR("OControlWizard::initControlSettings: could not retrieve the basic control settings!");
734cdf0e10cSrcweir 		}
735cdf0e10cSrcweir 	}
736cdf0e10cSrcweir 
737cdf0e10cSrcweir 	//---------------------------------------------------------------------
needDatasourceSelection()738cdf0e10cSrcweir 	sal_Bool OControlWizard::needDatasourceSelection()
739cdf0e10cSrcweir 	{
740cdf0e10cSrcweir 		// lemme see ...
741cdf0e10cSrcweir 		return (0 == getContext().aFieldNames.getLength());
742cdf0e10cSrcweir 			// if we got fields, the data source is valid ...
743cdf0e10cSrcweir //		try
744cdf0e10cSrcweir //		{
745cdf0e10cSrcweir //			// first, we need a valid data source name
746cdf0e10cSrcweir //			::rtl::OUString sDataSourceName;
747cdf0e10cSrcweir //			m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("DataSourceName")) >>= sDataSourceName;
748cdf0e10cSrcweir //			if (m_aContext.xDatasourceContext.is() && m_aContext.xDatasourceContext->hasByName(sDataSourceName))
749cdf0e10cSrcweir //			{	// at least the data source name is valid ...
750cdf0e10cSrcweir //				// then, a CommandType "table" would be nice ...
751cdf0e10cSrcweir //				sal_Int32 nCommandType = CommandType::COMMAND;
752cdf0e10cSrcweir //				m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("CommandType")) >>= nCommandType;
753cdf0e10cSrcweir //				if (CommandType::TABLE == nCommandType)
754cdf0e10cSrcweir //				{	// okay ....
755cdf0e10cSrcweir //					// now the table itself should be valid
756cdf0e10cSrcweir //					::rtl::OUString sTableName;
757cdf0e10cSrcweir //					m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("Command")) >>= sTableName;
758cdf0e10cSrcweir //					if (m_aContext.xObjectContainer.is() && m_aContext.xObjectContainer->hasByName(sTableName))
759cdf0e10cSrcweir //						return sal_False;
760cdf0e10cSrcweir //				}
761cdf0e10cSrcweir //			}
762cdf0e10cSrcweir //		}
763cdf0e10cSrcweir //		catch(Exception&)
764cdf0e10cSrcweir //		{
765cdf0e10cSrcweir //			DBG_ERROR("OControlWizard::needDatasourceSelection: caught an exception while checking the form settings!");
766cdf0e10cSrcweir //		}
767cdf0e10cSrcweir //		return sal_True;
768cdf0e10cSrcweir 	}
769cdf0e10cSrcweir 
770cdf0e10cSrcweir //.........................................................................
771cdf0e10cSrcweir }	// namespace dbp
772cdf0e10cSrcweir //.........................................................................
773cdf0e10cSrcweir 
774