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