1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "controlwizard.hxx"
21 #include <tools/debug.hxx>
22 #include <com/sun/star/container/XNameAccess.hpp>
23 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
24 #include <com/sun/star/sdb/DatabaseContext.hpp>
25 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
26 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
27 #include <com/sun/star/container/XChild.hpp>
28 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
29 #include <com/sun/star/frame/XModel.hpp>
30 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
31 #include <com/sun/star/drawing/XDrawView.hpp>
32 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
33 #include <com/sun/star/sdb/CommandType.hpp>
34 #include <com/sun/star/sdbc/SQLWarning.hpp>
35 #include <com/sun/star/sdb/SQLContext.hpp>
36 #include <com/sun/star/task/InteractionHandler.hpp>
37 #include <comphelper/processfactory.hxx>
38 #include <comphelper/types.hxx>
39 #include <connectivity/dbtools.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <comphelper/interaction.hxx>
42 #include <vcl/stdtext.hxx>
43 #include <svtools/localresaccess.hxx>
44 #include <connectivity/conncleanup.hxx>
45 #include <com/sun/star/sdbc/DataType.hpp>
46 #include <tools/urlobj.hxx>
48 //.........................................................................
51 //.........................................................................
53 using namespace ::com::sun::star::uno
;
54 using namespace ::com::sun::star::awt
;
55 using namespace ::com::sun::star::lang
;
56 using namespace ::com::sun::star::sdb
;
57 using namespace ::com::sun::star::sdbc
;
58 using namespace ::com::sun::star::sdbcx
;
59 using namespace ::com::sun::star::beans
;
60 using namespace ::com::sun::star::container
;
61 using namespace ::com::sun::star::drawing
;
62 using namespace ::com::sun::star::frame
;
63 using namespace ::com::sun::star::sheet
;
64 using namespace ::com::sun::star::form
;
65 using namespace ::com::sun::star::task
;
66 using namespace ::svt
;
67 using namespace ::comphelper
;
68 using namespace ::dbtools
;
70 //=====================================================================
72 //=====================================================================
73 struct OAccessRegulator
75 friend class OControlWizardPage
;
78 OAccessRegulator() { }
81 //=====================================================================
82 //= OControlWizardPage
83 //=====================================================================
84 //---------------------------------------------------------------------
85 OControlWizardPage::OControlWizardPage( OControlWizard
* _pParent
, const ResId
& _rResId
)
86 :OControlWizardPage_Base( _pParent
, _rResId
)
87 ,m_pFormSettingsSeparator(NULL
)
88 ,m_pFormDatasourceLabel(NULL
)
89 ,m_pFormDatasource(NULL
)
90 ,m_pFormContentTypeLabel(NULL
)
91 ,m_pFormContentType(NULL
)
92 ,m_pFormTableLabel(NULL
)
97 //---------------------------------------------------------------------
98 OControlWizardPage::~OControlWizardPage()
100 delete m_pFormSettingsSeparator
;
101 delete m_pFormDatasourceLabel
;
102 delete m_pFormDatasource
;
103 delete m_pFormContentTypeLabel
;
104 delete m_pFormContentType
;
105 delete m_pFormTableLabel
;
109 //---------------------------------------------------------------------
110 OControlWizard
* OControlWizardPage::getDialog()
112 return static_cast< OControlWizard
* >(GetParent());
115 //---------------------------------------------------------------------
116 const OControlWizard
* OControlWizardPage::getDialog() const
118 return static_cast< OControlWizard
* >(GetParent());
121 //---------------------------------------------------------------------
122 sal_Bool
OControlWizardPage::updateContext()
124 return getDialog()->updateContext(OAccessRegulator());
127 //---------------------------------------------------------------------
128 Reference
< XConnection
> OControlWizardPage::getFormConnection() const
130 return getDialog()->getFormConnection(OAccessRegulator());
133 //---------------------------------------------------------------------
134 void OControlWizardPage::setFormConnection( const Reference
< XConnection
>& _rxConn
, sal_Bool _bAutoDispose
)
136 getDialog()->setFormConnection( OAccessRegulator(), _rxConn
, _bAutoDispose
);
139 //---------------------------------------------------------------------
140 const OControlWizardContext
& OControlWizardPage::getContext()
142 return getDialog()->getContext();
145 //---------------------------------------------------------------------
146 void OControlWizardPage::fillListBox(ListBox
& _rList
, const Sequence
< OUString
>& _rItems
, sal_Bool _bClear
)
150 const OUString
* pItems
= _rItems
.getConstArray();
151 const OUString
* pEnd
= pItems
+ _rItems
.getLength();
152 ::svt::WizardTypes::WizardState nPos
;
153 sal_Int32 nIndex
= 0;
154 for (;pItems
< pEnd
; ++pItems
, ++nIndex
)
156 nPos
= _rList
.InsertEntry(*pItems
);
157 _rList
.SetEntryData(nPos
, reinterpret_cast<void*>(nIndex
));
161 //---------------------------------------------------------------------
162 void OControlWizardPage::fillListBox(ComboBox
& _rList
, const Sequence
< OUString
>& _rItems
, sal_Bool _bClear
)
166 const OUString
* pItems
= _rItems
.getConstArray();
167 const OUString
* pEnd
= pItems
+ _rItems
.getLength();
168 ::svt::WizardTypes::WizardState nPos
;
169 sal_Int32 nIndex
= 0;
170 for (;pItems
< pEnd
; ++pItems
)
172 nPos
= _rList
.InsertEntry(*pItems
);
173 _rList
.SetEntryData(nPos
, reinterpret_cast<void*>(nIndex
));
177 //---------------------------------------------------------------------
178 void OControlWizardPage::enableFormDatasourceDisplay()
180 if (m_pFormSettingsSeparator
)
184 ModuleRes
aModuleRes(RID_PAGE_FORM_DATASOURCE_STATUS
);
185 OLocalResourceAccess
aLocalControls(aModuleRes
, RSC_TABPAGE
);
187 m_pFormSettingsSeparator
= new FixedLine(this, ModuleRes(FL_FORMSETINGS
));
188 m_pFormDatasourceLabel
= new FixedText(this, ModuleRes(FT_FORMDATASOURCELABEL
));
189 m_pFormDatasource
= new FixedText(this, ModuleRes(FT_FORMDATASOURCE
));
190 m_pFormContentTypeLabel
= new FixedText(this, ModuleRes(FT_FORMCONTENTTYPELABEL
));
191 m_pFormContentType
= new FixedText(this, ModuleRes(FT_FORMCONTENTTYPE
));
192 m_pFormTableLabel
= new FixedText(this, ModuleRes(FT_FORMTABLELABEL
));
193 m_pFormTable
= new FixedText(this, ModuleRes(FT_FORMTABLE
));
195 const OControlWizardContext
& rContext
= getContext();
196 if ( rContext
.bEmbedded
)
198 m_pFormDatasourceLabel
->Hide();
199 m_pFormDatasource
->Hide();
200 m_pFormContentTypeLabel
->SetPosPixel(m_pFormDatasourceLabel
->GetPosPixel());
201 m_pFormContentType
->SetPosPixel(m_pFormDatasource
->GetPosPixel());
202 m_pFormTableLabel
->SetPosPixel(::Point(m_pFormDatasourceLabel
->GetPosPixel().X(),m_pFormTableLabel
->GetPosPixel().Y()));
203 m_pFormTable
->SetPosPixel(::Point(m_pFormDatasource
->GetPosPixel().X(),m_pFormTable
->GetPosPixel().Y()));
207 //---------------------------------------------------------------------
208 void OControlWizardPage::adjustControlForNoDSDisplay(Control
* _pControl
, sal_Bool _bConstLowerDistance
)
210 ::Size aDistanceToMove
= LogicToPixel( ::Size( 0, 37 ), MAP_APPFONT
);
212 ::Point aPos
= _pControl
->GetPosPixel();
213 aPos
.Y() -= aDistanceToMove
.Height();
214 _pControl
->SetPosPixel(aPos
);
216 if (_bConstLowerDistance
)
218 ::Size aSize
= _pControl
->GetSizePixel();
219 aSize
.Height() += aDistanceToMove
.Height();
220 _pControl
->SetSizePixel(aSize
);
224 //---------------------------------------------------------------------
225 void OControlWizardPage::initializePage()
227 if (m_pFormDatasource
&& m_pFormContentTypeLabel
&& m_pFormTable
)
229 const OControlWizardContext
& rContext
= getContext();
230 OUString sDataSource
;
232 sal_Int32 nCommandType
= CommandType::COMMAND
;
235 rContext
.xForm
->getPropertyValue(OUString("DataSourceName")) >>= sDataSource
;
236 rContext
.xForm
->getPropertyValue(OUString("Command")) >>= sCommand
;
237 rContext
.xForm
->getPropertyValue(OUString("CommandType")) >>= nCommandType
;
239 catch(const Exception
&)
241 OSL_FAIL("OControlWizardPage::initializePage: caught an exception!");
244 INetURLObject
aURL( sDataSource
);
245 if( aURL
.GetProtocol() != INET_PROT_NOT_VALID
)
246 sDataSource
= aURL
.GetName(INetURLObject::DECODE_WITH_CHARSET
);
247 m_pFormDatasource
->SetText(sDataSource
);
248 m_pFormTable
->SetText(sCommand
);
250 ::svt::WizardTypes::WizardState nCommandTypeResourceId
= 0;
251 switch (nCommandType
)
253 case CommandType::TABLE
:
254 nCommandTypeResourceId
= RID_STR_TYPE_TABLE
;
257 case CommandType::QUERY
:
258 nCommandTypeResourceId
= RID_STR_TYPE_QUERY
;
262 nCommandTypeResourceId
= RID_STR_TYPE_COMMAND
;
265 m_pFormContentType
->SetText(String(ModuleRes(nCommandTypeResourceId
)));
268 OControlWizardPage_Base::initializePage();
271 //=====================================================================
273 //=====================================================================
274 //---------------------------------------------------------------------
275 OControlWizard::OControlWizard( Window
* _pParent
, const ResId
& _rId
,
276 const Reference
< XPropertySet
>& _rxObjectModel
, const Reference
< XComponentContext
>& _rxContext
)
277 :OWizardMachine(_pParent
, _rId
, WZB_CANCEL
| WZB_PREVIOUS
| WZB_NEXT
| WZB_FINISH
)
278 ,m_xContext(_rxContext
)
280 m_aContext
.xObjectModel
= _rxObjectModel
;
283 SetPageSizePixel(LogicToPixel(::Size(WINDOW_SIZE_X
, WINDOW_SIZE_Y
), MAP_APPFONT
));
284 ShowButtonFixedLine(sal_True
);
285 defaultButton(WZB_NEXT
);
286 enableButtons(WZB_FINISH
, sal_False
);
289 //---------------------------------------------------------------------
290 OControlWizard::~OControlWizard()
294 //---------------------------------------------------------------------
295 short OControlWizard::Execute()
297 // get the class id of the control we're dealing with
298 sal_Int16 nClassId
= FormComponentType::CONTROL
;
301 getContext().xObjectModel
->getPropertyValue(OUString("ClassId")) >>= nClassId
;
303 catch(const Exception
&)
305 OSL_FAIL("OControlWizard::activate: could not obtain the class id!");
307 if (!approveControl(nClassId
))
309 // TODO: MessageBox or exception
315 return OControlWizard_Base::Execute();
318 //---------------------------------------------------------------------
319 void OControlWizard::ActivatePage()
321 OControlWizard_Base::ActivatePage();
324 //---------------------------------------------------------------------
325 void OControlWizard::implDetermineShape()
327 Reference
< XIndexAccess
> xPageObjects(m_aContext
.xDrawPage
, UNO_QUERY
);
328 DBG_ASSERT(xPageObjects
.is(), "OControlWizard::implDetermineShape: invalid page!");
330 // for comparing the model
331 Reference
< XControlModel
> xModelCompare(m_aContext
.xObjectModel
, UNO_QUERY
);
333 if (xPageObjects
.is())
335 // loop through all objects of the page
336 sal_Int32 nObjects
= xPageObjects
->getCount();
337 Reference
< XControlShape
> xControlShape
;
338 Reference
< XControlModel
> xControlModel
;
339 for (sal_Int32 i
=0; i
<nObjects
; ++i
)
341 if (xPageObjects
->getByIndex(i
) >>= xControlShape
)
342 { // it _is_ a control shape
343 xControlModel
= xControlShape
->getControl();
344 DBG_ASSERT(xControlModel
.is(), "OControlWizard::implDetermineShape: control shape without model!");
345 if (xModelCompare
.get() == xControlModel
.get())
347 m_aContext
.xObjectShape
= xControlShape
;
355 //---------------------------------------------------------------------
356 void OControlWizard::implDetermineForm()
358 Reference
< XChild
> xModelAsChild(m_aContext
.xObjectModel
, UNO_QUERY
);
359 Reference
< XInterface
> xControlParent
;
360 if (xModelAsChild
.is())
361 xControlParent
= xModelAsChild
->getParent();
363 m_aContext
.xForm
= Reference
< XPropertySet
>(xControlParent
, UNO_QUERY
);
364 m_aContext
.xRowSet
= Reference
< XRowSet
>(xControlParent
, UNO_QUERY
);
365 DBG_ASSERT(m_aContext
.xForm
.is() && m_aContext
.xRowSet
.is(),
366 "OControlWizard::implDetermineForm: missing some interfaces of the control parent!");
370 //---------------------------------------------------------------------
371 void OControlWizard::implDeterminePage()
375 // get the document model
376 Reference
< XChild
> xControlAsChild(m_aContext
.xObjectModel
, UNO_QUERY
);
377 Reference
< XChild
> xModelSearch(xControlAsChild
->getParent(), UNO_QUERY
);
379 Reference
< XModel
> xModel(xModelSearch
, UNO_QUERY
);
380 while (xModelSearch
.is() && !xModel
.is())
382 xModelSearch
= Reference
< XChild
>(xModelSearch
->getParent(), UNO_QUERY
);
383 xModel
= Reference
< XModel
>(xModelSearch
, UNO_QUERY
);
386 Reference
< XDrawPage
> xPage
;
389 m_aContext
.xDocumentModel
= xModel
;
391 Reference
< XDrawPageSupplier
> xPageSupp(xModel
, UNO_QUERY
);
393 { // it's a document with only one page -> Writer
394 xPage
= xPageSupp
->getDrawPage();
398 // get the controller currently working on this model
399 Reference
< XController
> xController
= xModel
->getCurrentController();
400 DBG_ASSERT(xController
.is(), "OControlWizard::implDeterminePage: no current controller!");
402 // maybe it's a spredsheet
403 Reference
< XSpreadsheetView
> xView(xController
, UNO_QUERY
);
406 Reference
< XSpreadsheet
> xSheet
= xView
->getActiveSheet();
407 xPageSupp
= Reference
< XDrawPageSupplier
>(xSheet
, UNO_QUERY
);
408 DBG_ASSERT(xPageSupp
.is(), "OControlWizard::implDeterminePage: a spreadsheet which is no page supplier!");
410 xPage
= xPageSupp
->getDrawPage();
413 { // can be a draw/impress doc only
414 Reference
< XDrawView
> xDrawView(xController
, UNO_QUERY
);
415 DBG_ASSERT(xDrawView
.is(), "OControlWizard::implDeterminePage: no alternatives left ... can't determine the page!");
417 xPage
= xDrawView
->getCurrentPage();
423 DBG_ASSERT(xPage
.is(), "OControlWizard::implDeterminePage: can't determine the page (no model)!");
425 m_aContext
.xDrawPage
= xPage
;
427 catch(const Exception
&)
429 OSL_FAIL("OControlWizard::implDeterminePage: caught an exception!");
433 //---------------------------------------------------------------------
434 void OControlWizard::implGetDSContext()
438 DBG_ASSERT(m_xContext
.is(), "OControlWizard::implGetDSContext: invalid service factory!");
440 m_aContext
.xDatasourceContext
= DatabaseContext::create(m_xContext
);
442 catch(const Exception
&)
444 OSL_FAIL("OControlWizard::implGetDSContext: invalid database context!");
448 //---------------------------------------------------------------------
449 Reference
< XConnection
> OControlWizard::getFormConnection(const OAccessRegulator
&) const
451 return getFormConnection();
453 //---------------------------------------------------------------------
454 Reference
< XConnection
> OControlWizard::getFormConnection() const
456 Reference
< XConnection
> xConn
;
459 if ( !::dbtools::isEmbeddedInDatabase(m_aContext
.xForm
,xConn
) )
460 m_aContext
.xForm
->getPropertyValue(OUString("ActiveConnection")) >>= xConn
;
462 catch(const Exception
&)
464 OSL_FAIL("OControlWizard::getFormConnection: caught an exception!");
469 //---------------------------------------------------------------------
470 void OControlWizard::setFormConnection( const OAccessRegulator
& _rAccess
, const Reference
< XConnection
>& _rxConn
, sal_Bool _bAutoDispose
)
474 Reference
< XConnection
> xOldConn
= getFormConnection(_rAccess
);
475 if (xOldConn
.get() == _rxConn
.get())
478 disposeComponent(xOldConn
);
480 // set the new connection
483 // for this, use a AutoDisposer (so the conn is cleaned up when the form dies or get's another connection)
484 Reference
< XRowSet
> xFormRowSet( m_aContext
.xForm
, UNO_QUERY
);
485 OAutoConnectionDisposer
* pAutoDispose
= new OAutoConnectionDisposer( xFormRowSet
, _rxConn
);
486 Reference
< XPropertyChangeListener
> xEnsureDelete( pAutoDispose
);
490 m_aContext
.xForm
->setPropertyValue( OUString("ActiveConnection"), makeAny( _rxConn
) );
493 catch(const Exception
&)
495 OSL_FAIL("OControlWizard::setFormConnection: caught an exception!");
499 //---------------------------------------------------------------------
500 sal_Bool
OControlWizard::updateContext(const OAccessRegulator
&)
502 return initContext();
504 //---------------------------------------------------------------------
505 Reference
< XInteractionHandler
> OControlWizard::getInteractionHandler(Window
* _pWindow
) const
507 Reference
< XInteractionHandler
> xHandler
;
510 xHandler
= Reference
< XInteractionHandler
>( InteractionHandler::createWithParent(m_xContext
, 0), UNO_QUERY_THROW
);
512 catch(const Exception
&) { }
515 const OUString
sInteractionHandlerServiceName("com.sun.star.task.InteractionHandler");
516 ShowServiceNotAvailableError(_pWindow
, sInteractionHandlerServiceName
, sal_True
);
520 //---------------------------------------------------------------------
521 sal_Bool
OControlWizard::initContext()
523 DBG_ASSERT(m_aContext
.xObjectModel
.is(), "OGroupBoxWizard::initContext: have no control model to work with!");
524 if (!m_aContext
.xObjectModel
.is())
528 m_aContext
.xForm
.clear();
529 m_aContext
.xRowSet
.clear();
530 m_aContext
.xDocumentModel
.clear();
531 m_aContext
.xDrawPage
.clear();
532 m_aContext
.xObjectShape
.clear();
533 m_aContext
.aFieldNames
.realloc(0);
535 m_aContext
.xObjectContainer
.clear();
536 m_aContext
.aTypes
.clear();
537 m_aContext
.bEmbedded
= sal_False
;
540 Reference
< XPreparedStatement
> xStatement
;
543 // get the datasource context
546 // first, determine the form the control belongs to
549 // need the page, too
552 // the shape of the control
553 implDetermineShape();
555 // get the columns of the object the settins refer to
556 Reference
< XNameAccess
> xColumns
;
558 if (m_aContext
.xForm
.is())
560 // collect some properties of the form
561 OUString sObjectName
= ::comphelper::getString(m_aContext
.xForm
->getPropertyValue(OUString("Command")));
562 sal_Int32 nObjectType
= ::comphelper::getINT32(m_aContext
.xForm
->getPropertyValue(OUString("CommandType")));
564 // calculate the connection the rowset is working with
565 Reference
< XConnection
> xConnection
;
566 m_aContext
.bEmbedded
= ::dbtools::isEmbeddedInDatabase( m_aContext
.xForm
, xConnection
);
567 if ( !m_aContext
.bEmbedded
)
568 xConnection
= ::dbtools::connectRowset( m_aContext
.xRowSet
, m_xContext
, sal_True
);
571 if (xConnection
.is())
577 Reference
< XTablesSupplier
> xSupplyTables(xConnection
, UNO_QUERY
);
578 if (xSupplyTables
.is() && xSupplyTables
->getTables().is() && xSupplyTables
->getTables()->hasByName(sObjectName
))
580 Reference
< XColumnsSupplier
> xSupplyColumns
;
581 m_aContext
.xObjectContainer
= xSupplyTables
->getTables();
582 m_aContext
.xObjectContainer
->getByName(sObjectName
) >>= xSupplyColumns
;
583 DBG_ASSERT(xSupplyColumns
.is(), "OControlWizard::initContext: invalid table columns!");
584 xColumns
= xSupplyColumns
->getColumns();
590 Reference
< XQueriesSupplier
> xSupplyQueries(xConnection
, UNO_QUERY
);
591 if (xSupplyQueries
.is() && xSupplyQueries
->getQueries().is() && xSupplyQueries
->getQueries()->hasByName(sObjectName
))
593 Reference
< XColumnsSupplier
> xSupplyColumns
;
594 m_aContext
.xObjectContainer
= xSupplyQueries
->getQueries();
595 m_aContext
.xObjectContainer
->getByName(sObjectName
) >>= xSupplyColumns
;
596 DBG_ASSERT(xSupplyColumns
.is(), "OControlWizard::initContext: invalid query columns!");
597 xColumns
= xSupplyColumns
->getColumns();
603 xStatement
= xConnection
->prepareStatement(sObjectName
);
605 // not interested in any results, only in the fields
606 Reference
< XPropertySet
> xStatementProps(xStatement
, UNO_QUERY
);
607 xStatementProps
->setPropertyValue(OUString("MaxRows"), makeAny(sal_Int32(0)));
609 // TODO: think about handling local SQLExceptions here ...
610 Reference
< XColumnsSupplier
> xSupplyCols(xStatement
->executeQuery(), UNO_QUERY
);
611 if (xSupplyCols
.is())
612 xColumns
= xSupplyCols
->getColumns();
620 m_aContext
.aFieldNames
= xColumns
->getElementNames();
621 static const OUString
s_sFieldTypeProperty("Type");
622 const OUString
* pBegin
= m_aContext
.aFieldNames
.getConstArray();
623 const OUString
* pEnd
= pBegin
+ m_aContext
.aFieldNames
.getLength();
624 for(;pBegin
!= pEnd
;++pBegin
)
626 sal_Int32 nFieldType
= DataType::OTHER
;
629 Reference
< XPropertySet
> xColumn
;
630 xColumns
->getByName(*pBegin
) >>= xColumn
;
631 xColumn
->getPropertyValue(s_sFieldTypeProperty
) >>= nFieldType
;
633 catch(const Exception
&)
635 OSL_FAIL("OControlWizard::initContext: unexpected exception while gathering column information!");
637 m_aContext
.aTypes
.insert(OControlWizardContext::TNameTypeMap::value_type(*pBegin
,nFieldType
));
641 catch(const SQLContext
& e
) { aSQLException
<<= e
; }
642 catch(const SQLWarning
& e
) { aSQLException
<<= e
; }
643 catch(const SQLException
& e
) { aSQLException
<<= e
; }
644 catch(const Exception
&)
646 OSL_FAIL("OControlWizard::initContext: could not retrieve the control context (caught an exception)!");
649 ::comphelper::disposeComponent(xStatement
);
651 if (aSQLException
.hasValue())
652 { // an SQLException (or derivee) was thrown ...
654 // prepend an extra SQLContext explaining what we were doing
656 aContext
.Message
= String(ModuleRes(RID_STR_COULDNOTOPENTABLE
));
657 aContext
.NextException
= aSQLException
;
659 // create an interaction handler to display this exception
660 Reference
< XInteractionHandler
> xHandler
= getInteractionHandler(this);
661 if ( !xHandler
.is() )
664 Reference
< XInteractionRequest
> xRequest
= new OInteractionRequest(makeAny(aContext
));
667 xHandler
->handle(xRequest
);
669 catch(const Exception
&) { }
673 return 0 != m_aContext
.aFieldNames
.getLength();
676 //---------------------------------------------------------------------
677 void OControlWizard::commitControlSettings(OControlWizardSettings
* _pSettings
)
679 DBG_ASSERT(m_aContext
.xObjectModel
.is(), "OControlWizard::commitControlSettings: have no control model to work with!");
680 if (!m_aContext
.xObjectModel
.is())
683 // the only thing we have at the moment is the label
686 OUString
sLabelPropertyName("Label");
687 Reference
< XPropertySetInfo
> xInfo
= m_aContext
.xObjectModel
->getPropertySetInfo();
688 if (xInfo
.is() && xInfo
->hasPropertyByName(sLabelPropertyName
))
690 OUString
sControlLabel(_pSettings
->sControlLabel
);
691 m_aContext
.xObjectModel
->setPropertyValue(
693 makeAny(sControlLabel
)
697 catch(const Exception
&)
699 OSL_FAIL("OControlWizard::commitControlSettings: could not commit the basic control settings!");
703 //---------------------------------------------------------------------
704 void OControlWizard::initControlSettings(OControlWizardSettings
* _pSettings
)
706 DBG_ASSERT(m_aContext
.xObjectModel
.is(), "OControlWizard::initControlSettings: have no control model to work with!");
707 if (!m_aContext
.xObjectModel
.is())
710 // initialize some settings from the control model give
713 OUString
sLabelPropertyName("Label");
714 Reference
< XPropertySetInfo
> xInfo
= m_aContext
.xObjectModel
->getPropertySetInfo();
715 if (xInfo
.is() && xInfo
->hasPropertyByName(sLabelPropertyName
))
717 OUString sControlLabel
;
718 m_aContext
.xObjectModel
->getPropertyValue(sLabelPropertyName
) >>= sControlLabel
;
719 _pSettings
->sControlLabel
= sControlLabel
;
722 catch(const Exception
&)
724 OSL_FAIL("OControlWizard::initControlSettings: could not retrieve the basic control settings!");
728 //---------------------------------------------------------------------
729 sal_Bool
OControlWizard::needDatasourceSelection()
732 return (0 == getContext().aFieldNames
.getLength());
733 // if we got fields, the data source is valid ...
736 //.........................................................................
738 //.........................................................................
740 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */