1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include "controlwizard.hxx"
21 #include <tools/debug.hxx>
22 #include <tools/diagnose_ex.h>
23 #include <com/sun/star/container/XNameAccess.hpp>
24 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
25 #include <com/sun/star/sdb/DatabaseContext.hpp>
26 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
27 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
28 #include <com/sun/star/container/XChild.hpp>
29 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
30 #include <com/sun/star/frame/XModel.hpp>
31 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
32 #include <com/sun/star/drawing/XDrawView.hpp>
33 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
34 #include <com/sun/star/sdb/CommandType.hpp>
35 #include <com/sun/star/sdbc/SQLWarning.hpp>
36 #include <com/sun/star/sdb/SQLContext.hpp>
37 #include <com/sun/star/task/InteractionHandler.hpp>
38 #include <comphelper/types.hxx>
39 #include <connectivity/dbtools.hxx>
40 #include <comphelper/interaction.hxx>
41 #include <vcl/stdtext.hxx>
42 #include <connectivity/conncleanup.hxx>
43 #include <com/sun/star/sdbc/DataType.hpp>
44 #include <tools/urlobj.hxx>
45 
46 #define WIZARD_SIZE_X   60
47 #define WIZARD_SIZE_Y   23
48 
49 namespace dbp
50 {
51     using namespace ::com::sun::star::uno;
52     using namespace ::com::sun::star::awt;
53     using namespace ::com::sun::star::lang;
54     using namespace ::com::sun::star::sdb;
55     using namespace ::com::sun::star::sdbc;
56     using namespace ::com::sun::star::sdbcx;
57     using namespace ::com::sun::star::beans;
58     using namespace ::com::sun::star::container;
59     using namespace ::com::sun::star::drawing;
60     using namespace ::com::sun::star::frame;
61     using namespace ::com::sun::star::sheet;
62     using namespace ::com::sun::star::form;
63     using namespace ::com::sun::star::task;
64     using namespace ::comphelper;
65     using namespace ::dbtools;
66 
67     struct OAccessRegulator
68     {
69         friend class OControlWizardPage;
70 
71     protected:
OAccessRegulatordbp::OAccessRegulator72         OAccessRegulator() { }
73     };
74 
OControlWizardPage(weld::Container * pPage,OControlWizard * pWizard,const OUString & rUIXMLDescription,const OString & rID)75     OControlWizardPage::OControlWizardPage(weld::Container* pPage, OControlWizard* pWizard, const OUString& rUIXMLDescription, const OString& rID)
76         : OControlWizardPage_Base(pPage, pWizard, rUIXMLDescription, rID)
77         , m_pDialog(pWizard)
78     {
79         m_xContainer->set_size_request(m_xContainer->get_approximate_digit_width() * WIZARD_SIZE_X,
80                                        m_xContainer->get_text_height() * WIZARD_SIZE_Y);
81     }
82 
~OControlWizardPage()83     OControlWizardPage::~OControlWizardPage()
84     {
85     }
86 
getDialog()87     OControlWizard* OControlWizardPage::getDialog()
88     {
89         return m_pDialog;
90     }
91 
getDialog() const92     const OControlWizard* OControlWizardPage::getDialog() const
93     {
94         return m_pDialog;
95     }
96 
updateContext()97     bool OControlWizardPage::updateContext()
98     {
99         return m_pDialog->updateContext(OAccessRegulator());
100     }
101 
getFormConnection() const102     Reference< XConnection > OControlWizardPage::getFormConnection() const
103     {
104         return m_pDialog->getFormConnection(OAccessRegulator());
105     }
106 
setFormConnection(const Reference<XConnection> & _rxConn,bool _bAutoDispose)107     void OControlWizardPage::setFormConnection( const Reference< XConnection >& _rxConn, bool _bAutoDispose )
108     {
109         m_pDialog->setFormConnection( OAccessRegulator(), _rxConn, _bAutoDispose );
110     }
111 
getContext() const112     const OControlWizardContext& OControlWizardPage::getContext() const
113     {
114         return m_pDialog->getContext();
115     }
116 
fillListBox(weld::TreeView & _rList,const Sequence<OUString> & _rItems)117     void OControlWizardPage::fillListBox(weld::TreeView& _rList, const Sequence< OUString >& _rItems)
118     {
119         _rList.clear();
120         const OUString* pItems = _rItems.getConstArray();
121         const OUString* pEnd = pItems + _rItems.getLength();
122         sal_Int32 nIndex = 0;
123         for (;pItems < pEnd; ++pItems, ++nIndex)
124         {
125             _rList.append(OUString::number(nIndex), *pItems);
126         }
127     }
128 
fillListBox(weld::ComboBox & _rList,const Sequence<OUString> & _rItems)129     void OControlWizardPage::fillListBox(weld::ComboBox& _rList, const Sequence< OUString >& _rItems)
130     {
131         _rList.clear();
132         const OUString* pItems = _rItems.getConstArray();
133         const OUString* pEnd = pItems + _rItems.getLength();
134         for (;pItems < pEnd; ++pItems)
135         {
136             _rList.append_text(*pItems);
137         }
138     }
139 
enableFormDatasourceDisplay()140     void OControlWizardPage::enableFormDatasourceDisplay()
141     {
142         if (m_xFormContentType)
143             // nothing to do
144             return;
145 
146         m_xFrame = m_xBuilder->weld_frame("sourceframe");
147         m_xFrame->show();
148         m_xFormContentType = m_xBuilder->weld_label("contenttype");
149         m_xFormContentTypeLabel = m_xBuilder->weld_label("contenttypelabel");
150         m_xFormDatasource = m_xBuilder->weld_label("datasource");
151         m_xFormDatasourceLabel = m_xBuilder->weld_label("datasourcelabel");
152         m_xFormTable = m_xBuilder->weld_label("formtable");
153         m_xFormTableLabel = m_xBuilder->weld_label("formtablelabel");
154 
155         const OControlWizardContext& rContext = getContext();
156         if ( rContext.bEmbedded )
157         {
158             m_xFormDatasourceLabel->hide();
159             m_xFormDatasource->hide();
160         }
161     }
162 
initializePage()163     void OControlWizardPage::initializePage()
164     {
165         if (m_xFormDatasource && m_xFormContentTypeLabel && m_xFormTable)
166         {
167             const OControlWizardContext& rContext = getContext();
168             OUString sDataSource;
169             OUString sCommand;
170             sal_Int32 nCommandType = CommandType::COMMAND;
171             try
172             {
173                 rContext.xForm->getPropertyValue("DataSourceName") >>= sDataSource;
174                 rContext.xForm->getPropertyValue("Command") >>= sCommand;
175                 rContext.xForm->getPropertyValue("CommandType") >>= nCommandType;
176             }
177             catch(const Exception&)
178             {
179                 TOOLS_WARN_EXCEPTION("extensions.dbpilots", "OControlWizardPage::initializePage");
180             }
181 
182             INetURLObject aURL( sDataSource );
183             if( aURL.GetProtocol() != INetProtocol::NotValid )
184                 sDataSource = aURL.GetLastName(INetURLObject::DecodeMechanism::WithCharset);
185             m_xFormDatasource->set_label(sDataSource);
186             m_xFormTable->set_label(sCommand);
187 
188             const char* pCommandTypeResourceId = nullptr;
189             switch (nCommandType)
190             {
191                 case CommandType::TABLE:
192                     pCommandTypeResourceId = RID_STR_TYPE_TABLE;
193                     break;
194 
195                 case CommandType::QUERY:
196                     pCommandTypeResourceId = RID_STR_TYPE_QUERY;
197                     break;
198 
199                 default:
200                     pCommandTypeResourceId = RID_STR_TYPE_COMMAND;
201                     break;
202             }
203             m_xFormContentType->set_label(compmodule::ModuleRes(pCommandTypeResourceId));
204         }
205 
206         OControlWizardPage_Base::initializePage();
207     }
208 
OControlWizard(weld::Window * _pParent,const Reference<XPropertySet> & _rxObjectModel,const Reference<XComponentContext> & _rxContext)209     OControlWizard::OControlWizard(weld::Window* _pParent,
210             const Reference< XPropertySet >& _rxObjectModel, const Reference< XComponentContext >& _rxContext )
211         : WizardMachine(_pParent, WizardButtonFlags::CANCEL | WizardButtonFlags::PREVIOUS | WizardButtonFlags::NEXT | WizardButtonFlags::FINISH)
212         , m_xContext(_rxContext)
213     {
214         m_aContext.xObjectModel = _rxObjectModel;
215         initContext();
216 
217         defaultButton(WizardButtonFlags::NEXT);
218         enableButtons(WizardButtonFlags::FINISH, false);
219     }
220 
~OControlWizard()221     OControlWizard::~OControlWizard()
222     {
223     }
224 
run()225     short OControlWizard::run()
226     {
227         // get the class id of the control we're dealing with
228         sal_Int16 nClassId = FormComponentType::CONTROL;
229         try
230         {
231             getContext().xObjectModel->getPropertyValue("ClassId") >>= nClassId;
232         }
233         catch(const Exception&)
234         {
235             OSL_FAIL("OControlWizard::activate: could not obtain the class id!");
236         }
237         if (!approveControl(nClassId))
238         {
239             // TODO: MessageBox or exception
240             return RET_CANCEL;
241         }
242 
243         ActivatePage();
244 
245         m_xAssistant->set_current_page(0);
246 
247         return OControlWizard_Base::run();
248     }
249 
implDetermineShape()250     void OControlWizard::implDetermineShape()
251     {
252         Reference< XIndexAccess > xPageObjects = m_aContext.xDrawPage;
253         DBG_ASSERT(xPageObjects.is(), "OControlWizard::implDetermineShape: invalid page!");
254 
255         // for comparing the model
256         Reference< XControlModel > xModelCompare(m_aContext.xObjectModel, UNO_QUERY);
257 
258         if (!xPageObjects.is())
259             return;
260 
261         // loop through all objects of the page
262         sal_Int32 nObjects = xPageObjects->getCount();
263         Reference< XControlShape > xControlShape;
264         Reference< XControlModel > xControlModel;
265         for (sal_Int32 i=0; i<nObjects; ++i)
266         {
267             if (xPageObjects->getByIndex(i) >>= xControlShape)
268             {   // it _is_ a control shape
269                 xControlModel = xControlShape->getControl();
270                 DBG_ASSERT(xControlModel.is(), "OControlWizard::implDetermineShape: control shape without model!");
271                 if (xModelCompare.get() == xControlModel.get())
272                 {
273                     m_aContext.xObjectShape = xControlShape;
274                     break;
275                 }
276             }
277         }
278     }
279 
280 
implDetermineForm()281     void OControlWizard::implDetermineForm()
282     {
283         Reference< XChild > xModelAsChild(m_aContext.xObjectModel, UNO_QUERY);
284         Reference< XInterface > xControlParent;
285         if (xModelAsChild.is())
286             xControlParent = xModelAsChild->getParent();
287 
288         m_aContext.xForm.set(xControlParent, UNO_QUERY);
289         m_aContext.xRowSet.set(xControlParent, UNO_QUERY);
290         DBG_ASSERT(m_aContext.xForm.is() && m_aContext.xRowSet.is(),
291             "OControlWizard::implDetermineForm: missing some interfaces of the control parent!");
292 
293     }
294 
295 
implDeterminePage()296     void OControlWizard::implDeterminePage()
297     {
298         try
299         {
300             // get the document model
301             Reference< XChild > xControlAsChild(m_aContext.xObjectModel, UNO_QUERY);
302             Reference< XChild > xModelSearch(xControlAsChild->getParent(), UNO_QUERY);
303 
304             Reference< XModel > xModel(xModelSearch, UNO_QUERY);
305             while (xModelSearch.is() && !xModel.is())
306             {
307                 xModelSearch.set(xModelSearch->getParent(), UNO_QUERY);
308                 xModel.set(xModelSearch, UNO_QUERY);
309             }
310 
311             Reference< XDrawPage > xPage;
312             if (xModel.is())
313             {
314                 m_aContext.xDocumentModel = xModel;
315 
316                 Reference< XDrawPageSupplier > xPageSupp(xModel, UNO_QUERY);
317                 if (xPageSupp.is())
318                 {   // it's a document with only one page -> Writer
319                     xPage = xPageSupp->getDrawPage();
320                 }
321                 else
322                 {
323                     // get the controller currently working on this model
324                     Reference< XController > xController = xModel->getCurrentController();
325                     DBG_ASSERT(xController.is(), "OControlWizard::implDeterminePage: no current controller!");
326 
327                     // maybe it's a spreadsheet
328                     Reference< XSpreadsheetView > xView(xController, UNO_QUERY);
329                     if (xView.is())
330                     {   // okay, it is one
331                         Reference< XSpreadsheet > xSheet = xView->getActiveSheet();
332                         xPageSupp.set(xSheet, UNO_QUERY);
333                         DBG_ASSERT(xPageSupp.is(), "OControlWizard::implDeterminePage: a spreadsheet which is no page supplier!");
334                         if (xPageSupp.is())
335                             xPage = xPageSupp->getDrawPage();
336                     }
337                     else
338                     {   // can be a draw/impress doc only
339                         Reference< XDrawView > xDrawView(xController, UNO_QUERY);
340                         DBG_ASSERT(xDrawView.is(), "OControlWizard::implDeterminePage: no alternatives left ... can't determine the page!");
341                         if (xDrawView.is())
342                             xPage = xDrawView->getCurrentPage();
343                     }
344                 }
345             }
346             else
347             {
348                 DBG_ASSERT(xPage.is(), "OControlWizard::implDeterminePage: can't determine the page (no model)!");
349             }
350             m_aContext.xDrawPage = xPage;
351         }
352         catch(const Exception&)
353         {
354             TOOLS_WARN_EXCEPTION("extensions.dbpilots", "OControlWizard::implDeterminePage");
355         }
356     }
357 
358 
implGetDSContext()359     void OControlWizard::implGetDSContext()
360     {
361         try
362         {
363             DBG_ASSERT(m_xContext.is(), "OControlWizard::implGetDSContext: invalid service factory!");
364 
365             m_aContext.xDatasourceContext = DatabaseContext::create(m_xContext);
366         }
367         catch(const Exception&)
368         {
369             OSL_FAIL("OControlWizard::implGetDSContext: invalid database context!");
370         }
371     }
372 
373 
getFormConnection(const OAccessRegulator &) const374     Reference< XConnection > OControlWizard::getFormConnection(const OAccessRegulator&) const
375     {
376         return getFormConnection();
377     }
378 
getFormConnection() const379     Reference< XConnection > OControlWizard::getFormConnection() const
380     {
381         Reference< XConnection > xConn;
382         try
383         {
384             if ( !::dbtools::isEmbeddedInDatabase(m_aContext.xForm,xConn) )
385                 m_aContext.xForm->getPropertyValue("ActiveConnection") >>= xConn;
386         }
387         catch(const Exception&)
388         {
389             TOOLS_WARN_EXCEPTION("extensions.dbpilots", "OControlWizard::getFormConnection");
390         }
391         return xConn;
392     }
393 
394 
setFormConnection(const OAccessRegulator & _rAccess,const Reference<XConnection> & _rxConn,bool _bAutoDispose)395     void OControlWizard::setFormConnection( const OAccessRegulator& _rAccess, const Reference< XConnection >& _rxConn, bool _bAutoDispose )
396     {
397         try
398         {
399             Reference< XConnection > xOldConn = getFormConnection(_rAccess);
400             if (xOldConn.get() == _rxConn.get())
401                 return;
402 
403             disposeComponent(xOldConn);
404 
405             // set the new connection
406             if ( _bAutoDispose )
407             {
408                 // for this, use an AutoDisposer (so the conn is cleaned up when the form dies or gets another connection)
409                 Reference< XRowSet > xFormRowSet( m_aContext.xForm, UNO_QUERY );
410                 new OAutoConnectionDisposer( xFormRowSet, _rxConn );
411             }
412             else
413             {
414                 m_aContext.xForm->setPropertyValue("ActiveConnection", makeAny( _rxConn ) );
415             }
416         }
417         catch(const Exception&)
418         {
419             TOOLS_WARN_EXCEPTION( "extensions.dbpilots", "OControlWizard::setFormConnection");
420         }
421     }
422 
423 
updateContext(const OAccessRegulator &)424     bool OControlWizard::updateContext(const OAccessRegulator&)
425     {
426         return initContext();
427     }
428 
getInteractionHandler(weld::Window * _pWindow) const429     Reference< XInteractionHandler > OControlWizard::getInteractionHandler(weld::Window* _pWindow) const
430     {
431         Reference< XInteractionHandler > xHandler;
432         try
433         {
434             xHandler.set( InteractionHandler::createWithParent(m_xContext, nullptr), UNO_QUERY_THROW );
435         }
436         catch(const Exception&) { }
437         if (!xHandler.is())
438         {
439             ShowServiceNotAvailableError(_pWindow, u"com.sun.star.task.InteractionHandler", true);
440         }
441         return xHandler;
442     }
443 
initContext()444     bool OControlWizard::initContext()
445     {
446         DBG_ASSERT(m_aContext.xObjectModel.is(), "OGroupBoxWizard::initContext: have no control model to work with!");
447         if (!m_aContext.xObjectModel.is())
448             return false;
449 
450         // reset the context
451         m_aContext.xForm.clear();
452         m_aContext.xRowSet.clear();
453         m_aContext.xDocumentModel.clear();
454         m_aContext.xDrawPage.clear();
455         m_aContext.xObjectShape.clear();
456         m_aContext.aFieldNames.realloc(0);
457 
458         m_aContext.xObjectContainer.clear();
459         m_aContext.aTypes.clear();
460         m_aContext.bEmbedded = false;
461 
462         Any aSQLException;
463         Reference< XPreparedStatement >  xStatement;
464         try
465         {
466             // get the datasource context
467             implGetDSContext();
468 
469             // first, determine the form the control belongs to
470             implDetermineForm();
471 
472             // need the page, too
473             implDeterminePage();
474 
475             // the shape of the control
476             implDetermineShape();
477 
478             // get the columns of the object the settings refer to
479             Reference< XNameAccess >  xColumns;
480 
481             if (m_aContext.xForm.is())
482             {
483                 // collect some properties of the form
484                 OUString sObjectName = ::comphelper::getString(m_aContext.xForm->getPropertyValue("Command"));
485                 sal_Int32 nObjectType = ::comphelper::getINT32(m_aContext.xForm->getPropertyValue("CommandType"));
486 
487                 // calculate the connection the rowset is working with
488                 Reference< XConnection > xConnection;
489                 m_aContext.bEmbedded = ::dbtools::isEmbeddedInDatabase( m_aContext.xForm, xConnection );
490                 if ( !m_aContext.bEmbedded )
491                     xConnection = ::dbtools::connectRowset( m_aContext.xRowSet, m_xContext, nullptr );
492 
493                 // get the fields
494                 if (xConnection.is())
495                 {
496                     switch (nObjectType)
497                     {
498                         case 0:
499                         {
500                             Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
501                             if (xSupplyTables.is() && xSupplyTables->getTables().is() && xSupplyTables->getTables()->hasByName(sObjectName))
502                             {
503                                 Reference< XColumnsSupplier >  xSupplyColumns;
504                                 m_aContext.xObjectContainer = xSupplyTables->getTables();
505                                 m_aContext.xObjectContainer->getByName(sObjectName) >>= xSupplyColumns;
506                                 DBG_ASSERT(xSupplyColumns.is(), "OControlWizard::initContext: invalid table columns!");
507                                 xColumns = xSupplyColumns->getColumns();
508                             }
509                         }
510                         break;
511                         case 1:
512                         {
513                             Reference< XQueriesSupplier >  xSupplyQueries(xConnection, UNO_QUERY);
514                             if (xSupplyQueries.is() && xSupplyQueries->getQueries().is() && xSupplyQueries->getQueries()->hasByName(sObjectName))
515                             {
516                                 Reference< XColumnsSupplier >  xSupplyColumns;
517                                 m_aContext.xObjectContainer = xSupplyQueries->getQueries();
518                                 m_aContext.xObjectContainer->getByName(sObjectName) >>= xSupplyColumns;
519                                 DBG_ASSERT(xSupplyColumns.is(), "OControlWizard::initContext: invalid query columns!");
520                                 xColumns  = xSupplyColumns->getColumns();
521                             }
522                         }
523                         break;
524                         default:
525                         {
526                             xStatement = xConnection->prepareStatement(sObjectName);
527 
528                             // not interested in any results, only in the fields
529                             Reference< XPropertySet > xStatementProps(xStatement, UNO_QUERY);
530                             xStatementProps->setPropertyValue("MaxRows", makeAny(sal_Int32(0)));
531 
532                             // TODO: think about handling local SQLExceptions here ...
533                             Reference< XColumnsSupplier >  xSupplyCols(xStatement->executeQuery(), UNO_QUERY);
534                             if (xSupplyCols.is())
535                                 xColumns = xSupplyCols->getColumns();
536                         }
537                     }
538                 }
539             }
540 
541             if (xColumns.is())
542             {
543                 m_aContext.aFieldNames = xColumns->getElementNames();
544                 const OUString* pBegin = m_aContext.aFieldNames.getConstArray();
545                 const OUString* pEnd   = pBegin + m_aContext.aFieldNames.getLength();
546                 for(;pBegin != pEnd;++pBegin)
547                 {
548                     sal_Int32 nFieldType = DataType::OTHER;
549                     try
550                     {
551                         Reference< XPropertySet > xColumn;
552                         xColumns->getByName(*pBegin) >>= xColumn;
553                         xColumn->getPropertyValue("Type") >>= nFieldType;
554                     }
555                     catch(const Exception&)
556                     {
557                         TOOLS_WARN_EXCEPTION(
558                             "extensions.dbpilots",
559                             "unexpected exception while gathering column information!");
560                     }
561                     m_aContext.aTypes.emplace(*pBegin,nFieldType);
562                 }
563             }
564         }
565         catch(const SQLContext& e) { aSQLException <<= e; }
566         catch(const SQLWarning& e) { aSQLException <<= e; }
567         catch(const SQLException& e) { aSQLException <<= e; }
568         catch(const Exception&)
569         {
570             TOOLS_WARN_EXCEPTION( "extensions.dbpilots", "OControlWizard::initContext: could not retrieve the control context");
571         }
572 
573         ::comphelper::disposeComponent(xStatement);
574 
575         if (aSQLException.hasValue())
576         {   // an SQLException (or derivee) was thrown ...
577 
578             // prepend an extra SQLContext explaining what we were doing
579             SQLContext aContext;
580             aContext.Message = compmodule::ModuleRes(RID_STR_COULDNOTOPENTABLE);
581             aContext.NextException = aSQLException;
582 
583             // create an interaction handler to display this exception
584             Reference< XInteractionHandler > xHandler = getInteractionHandler(m_xAssistant.get());
585             if ( !xHandler.is() )
586                 return false;
587 
588             Reference< XInteractionRequest > xRequest = new OInteractionRequest(makeAny(aContext));
589             try
590             {
591                 xHandler->handle(xRequest);
592             }
593             catch(const Exception&) { }
594             return false;
595         }
596 
597         return m_aContext.aFieldNames.hasElements();
598     }
599 
600 
commitControlSettings(OControlWizardSettings const * _pSettings)601     void OControlWizard::commitControlSettings(OControlWizardSettings const * _pSettings)
602     {
603         DBG_ASSERT(m_aContext.xObjectModel.is(), "OControlWizard::commitControlSettings: have no control model to work with!");
604         if (!m_aContext.xObjectModel.is())
605             return;
606 
607         // the only thing we have at the moment is the label
608         try
609         {
610             Reference< XPropertySetInfo > xInfo = m_aContext.xObjectModel->getPropertySetInfo();
611             if (xInfo.is() && xInfo->hasPropertyByName("Label"))
612             {
613                 OUString sControlLabel(_pSettings->sControlLabel);
614                 m_aContext.xObjectModel->setPropertyValue(
615                     "Label",
616                     makeAny(sControlLabel)
617                 );
618             }
619         }
620         catch(const Exception&)
621         {
622             TOOLS_WARN_EXCEPTION( "extensions.dbpilots", "OControlWizard::commitControlSettings: could not commit the basic control settings!");
623         }
624     }
625 
626 
initControlSettings(OControlWizardSettings * _pSettings)627     void OControlWizard::initControlSettings(OControlWizardSettings* _pSettings)
628     {
629         DBG_ASSERT(m_aContext.xObjectModel.is(), "OControlWizard::initControlSettings: have no control model to work with!");
630         if (!m_aContext.xObjectModel.is())
631             return;
632 
633         // initialize some settings from the control model give
634         try
635         {
636             OUString sLabelPropertyName("Label");
637             Reference< XPropertySetInfo > xInfo = m_aContext.xObjectModel->getPropertySetInfo();
638             if (xInfo.is() && xInfo->hasPropertyByName(sLabelPropertyName))
639             {
640                 OUString sControlLabel;
641                 m_aContext.xObjectModel->getPropertyValue(sLabelPropertyName) >>= sControlLabel;
642                 _pSettings->sControlLabel = sControlLabel;
643             }
644         }
645         catch(const Exception&)
646         {
647             TOOLS_WARN_EXCEPTION( "extensions.dbpilots", "OControlWizard::initControlSettings: could not retrieve the basic control settings!");
648         }
649     }
650 
651 
needDatasourceSelection()652     bool OControlWizard::needDatasourceSelection()
653     {
654         // lemme see ...
655         return !getContext().aFieldNames.hasElements();
656             // if we got fields, the data source is valid ...
657     }
658 
659 
660 }   // namespace dbp
661 
662 
663 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
664