1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: controlwizard.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "controlwizard.hxx"
34 #include <tools/debug.hxx>
35 #include <com/sun/star/container/XNameAccess.hpp>
36 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
37 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
38 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
39 #include <com/sun/star/container/XChild.hpp>
40 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
41 #include <com/sun/star/frame/XModel.hpp>
42 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
43 #include <com/sun/star/drawing/XDrawView.hpp>
44 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
45 #include <com/sun/star/sdb/CommandType.hpp>
46 #include <com/sun/star/sdbc/SQLWarning.hpp>
47 #include <com/sun/star/sdb/SQLContext.hpp>
48 #include <comphelper/types.hxx>
49 #include <connectivity/dbtools.hxx>
50 #include <vcl/msgbox.hxx>
51 #include <comphelper/interaction.hxx>
52 #include <vcl/stdtext.hxx>
53 #include <svtools/localresaccess.hxx>
54 #include <connectivity/conncleanup.hxx>
55 #include <com/sun/star/sdbc/DataType.hpp>
56 #include <tools/urlobj.hxx>
58 //.........................................................................
61 //.........................................................................
63 using namespace ::com::sun::star::uno
;
64 using namespace ::com::sun::star::awt
;
65 using namespace ::com::sun::star::lang
;
66 using namespace ::com::sun::star::sdb
;
67 using namespace ::com::sun::star::sdbc
;
68 using namespace ::com::sun::star::sdbcx
;
69 using namespace ::com::sun::star::beans
;
70 using namespace ::com::sun::star::container
;
71 using namespace ::com::sun::star::drawing
;
72 using namespace ::com::sun::star::frame
;
73 using namespace ::com::sun::star::sheet
;
74 using namespace ::com::sun::star::form
;
75 using namespace ::com::sun::star::task
;
76 using namespace ::svt
;
77 using namespace ::comphelper
;
78 using namespace ::dbtools
;
80 //=====================================================================
82 //=====================================================================
83 struct OAccessRegulator
85 friend class OControlWizardPage
;
88 OAccessRegulator() { }
91 //=====================================================================
92 //= OControlWizardPage
93 //=====================================================================
94 //---------------------------------------------------------------------
95 OControlWizardPage::OControlWizardPage( OControlWizard
* _pParent
, const ResId
& _rResId
)
96 :OControlWizardPage_Base( _pParent
, _rResId
)
97 ,m_pFormSettingsSeparator(NULL
)
98 ,m_pFormDatasourceLabel(NULL
)
99 ,m_pFormDatasource(NULL
)
100 ,m_pFormContentTypeLabel(NULL
)
101 ,m_pFormContentType(NULL
)
102 ,m_pFormTableLabel(NULL
)
107 //---------------------------------------------------------------------
108 OControlWizardPage::~OControlWizardPage()
110 delete m_pFormSettingsSeparator
;
111 delete m_pFormDatasourceLabel
;
112 delete m_pFormDatasource
;
113 delete m_pFormContentTypeLabel
;
114 delete m_pFormContentType
;
115 delete m_pFormTableLabel
;
119 //---------------------------------------------------------------------
120 OControlWizard
* OControlWizardPage::getDialog()
122 return static_cast< OControlWizard
* >(GetParent());
125 //---------------------------------------------------------------------
126 const OControlWizard
* OControlWizardPage::getDialog() const
128 return static_cast< OControlWizard
* >(GetParent());
131 //---------------------------------------------------------------------
132 sal_Bool
OControlWizardPage::updateContext()
134 return getDialog()->updateContext(OAccessRegulator());
137 //---------------------------------------------------------------------
138 Reference
< XConnection
> OControlWizardPage::getFormConnection() const
140 return getDialog()->getFormConnection(OAccessRegulator());
143 //---------------------------------------------------------------------
144 void OControlWizardPage::setFormConnection( const Reference
< XConnection
>& _rxConn
, sal_Bool _bAutoDispose
)
146 getDialog()->setFormConnection( OAccessRegulator(), _rxConn
, _bAutoDispose
);
149 //---------------------------------------------------------------------
150 const OControlWizardContext
& OControlWizardPage::getContext()
152 return getDialog()->getContext();
155 //---------------------------------------------------------------------
156 void OControlWizardPage::fillListBox(ListBox
& _rList
, const Sequence
< ::rtl::OUString
>& _rItems
, sal_Bool _bClear
)
160 const ::rtl::OUString
* pItems
= _rItems
.getConstArray();
161 const ::rtl::OUString
* pEnd
= pItems
+ _rItems
.getLength();
163 sal_Int32 nIndex
= 0;
164 for (;pItems
< pEnd
; ++pItems
, ++nIndex
)
166 nPos
= _rList
.InsertEntry(*pItems
);
167 _rList
.SetEntryData(nPos
, reinterpret_cast<void*>(nIndex
));
171 //---------------------------------------------------------------------
172 void OControlWizardPage::fillListBox(ComboBox
& _rList
, const Sequence
< ::rtl::OUString
>& _rItems
, sal_Bool _bClear
)
176 const ::rtl::OUString
* pItems
= _rItems
.getConstArray();
177 const ::rtl::OUString
* pEnd
= pItems
+ _rItems
.getLength();
179 sal_Int32 nIndex
= 0;
180 for (;pItems
< pEnd
; ++pItems
)
182 nPos
= _rList
.InsertEntry(*pItems
);
183 _rList
.SetEntryData(nPos
, reinterpret_cast<void*>(nIndex
));
187 //---------------------------------------------------------------------
188 void OControlWizardPage::enableFormDatasourceDisplay()
190 if (m_pFormSettingsSeparator
)
194 ModuleRes
aModuleRes(RID_PAGE_FORM_DATASOURCE_STATUS
);
195 OLocalResourceAccess
aLocalControls(aModuleRes
, RSC_TABPAGE
);
197 m_pFormSettingsSeparator
= new FixedLine(this, ModuleRes(FL_FORMSETINGS
));
198 m_pFormDatasourceLabel
= new FixedText(this, ModuleRes(FT_FORMDATASOURCELABEL
));
199 m_pFormDatasource
= new FixedText(this, ModuleRes(FT_FORMDATASOURCE
));
200 m_pFormContentTypeLabel
= new FixedText(this, ModuleRes(FT_FORMCONTENTTYPELABEL
));
201 m_pFormContentType
= new FixedText(this, ModuleRes(FT_FORMCONTENTTYPE
));
202 m_pFormTableLabel
= new FixedText(this, ModuleRes(FT_FORMTABLELABEL
));
203 m_pFormTable
= new FixedText(this, ModuleRes(FT_FORMTABLE
));
205 const OControlWizardContext
& rContext
= getContext();
206 if ( rContext
.bEmbedded
)
208 m_pFormDatasourceLabel
->Hide();
209 m_pFormDatasource
->Hide();
210 m_pFormContentTypeLabel
->SetPosPixel(m_pFormDatasourceLabel
->GetPosPixel());
211 m_pFormContentType
->SetPosPixel(m_pFormDatasource
->GetPosPixel());
212 m_pFormTableLabel
->SetPosPixel(::Point(m_pFormDatasourceLabel
->GetPosPixel().X(),m_pFormTableLabel
->GetPosPixel().Y()));
213 m_pFormTable
->SetPosPixel(::Point(m_pFormDatasource
->GetPosPixel().X(),m_pFormTable
->GetPosPixel().Y()));
217 //---------------------------------------------------------------------
218 void OControlWizardPage::adjustControlForNoDSDisplay(Control
* _pControl
, sal_Bool _bConstLowerDistance
)
220 ::Size aDistanceToMove
= LogicToPixel( ::Size( 0, 37 ), MAP_APPFONT
);
222 ::Point aPos
= _pControl
->GetPosPixel();
223 aPos
.Y() -= aDistanceToMove
.Height();
224 _pControl
->SetPosPixel(aPos
);
226 if (_bConstLowerDistance
)
228 ::Size aSize
= _pControl
->GetSizePixel();
229 aSize
.Height() += aDistanceToMove
.Height();
230 _pControl
->SetSizePixel(aSize
);
234 //---------------------------------------------------------------------
235 void OControlWizardPage::initializePage()
237 if (m_pFormDatasource
&& m_pFormContentTypeLabel
&& m_pFormTable
)
239 const OControlWizardContext
& rContext
= getContext();
240 ::rtl::OUString sDataSource
;
241 ::rtl::OUString sCommand
;
242 sal_Int32 nCommandType
= CommandType::COMMAND
;
245 rContext
.xForm
->getPropertyValue(::rtl::OUString::createFromAscii("DataSourceName")) >>= sDataSource
;
246 rContext
.xForm
->getPropertyValue(::rtl::OUString::createFromAscii("Command")) >>= sCommand
;
247 rContext
.xForm
->getPropertyValue(::rtl::OUString::createFromAscii("CommandType")) >>= nCommandType
;
249 catch(const Exception
&)
251 DBG_ERROR("OControlWizardPage::initializePage: caught an exception!");
254 INetURLObject
aURL( sDataSource
);
255 if( aURL
.GetProtocol() != INET_PROT_NOT_VALID
)
256 sDataSource
= aURL
.GetName(INetURLObject::DECODE_WITH_CHARSET
);
257 m_pFormDatasource
->SetText(sDataSource
);
258 m_pFormTable
->SetText(sCommand
);
260 WizardState nCommandTypeResourceId
= 0;
261 switch (nCommandType
)
263 case CommandType::TABLE
:
264 nCommandTypeResourceId
= RID_STR_TYPE_TABLE
;
267 case CommandType::QUERY
:
268 nCommandTypeResourceId
= RID_STR_TYPE_QUERY
;
272 nCommandTypeResourceId
= RID_STR_TYPE_COMMAND
;
275 m_pFormContentType
->SetText(String(ModuleRes(nCommandTypeResourceId
)));
278 OControlWizardPage_Base::initializePage();
281 //=====================================================================
283 //=====================================================================
284 //---------------------------------------------------------------------
285 OControlWizard::OControlWizard( Window
* _pParent
, const ResId
& _rId
,
286 const Reference
< XPropertySet
>& _rxObjectModel
, const Reference
< XMultiServiceFactory
>& _rxORB
)
287 :OWizardMachine(_pParent
, _rId
, WZB_CANCEL
| WZB_PREVIOUS
| WZB_NEXT
| WZB_FINISH
)
290 m_aContext
.xObjectModel
= _rxObjectModel
;
293 SetPageSizePixel(LogicToPixel(::Size(WINDOW_SIZE_X
, WINDOW_SIZE_Y
), MAP_APPFONT
));
294 ShowButtonFixedLine(sal_True
);
295 defaultButton(WZB_NEXT
);
296 enableButtons(WZB_FINISH
, sal_False
);
299 //---------------------------------------------------------------------
300 OControlWizard::~OControlWizard()
304 //---------------------------------------------------------------------
305 short OControlWizard::Execute()
307 // get the class id of the control we're dealing with
308 sal_Int16 nClassId
= FormComponentType::CONTROL
;
311 getContext().xObjectModel
->getPropertyValue(::rtl::OUString::createFromAscii("ClassId")) >>= nClassId
;
315 DBG_ERROR("OControlWizard::activate: could not obtain the class id!");
317 if (!approveControl(nClassId
))
319 // TODO: MessageBox or exception
325 return OControlWizard_Base::Execute();
328 //---------------------------------------------------------------------
329 void OControlWizard::ActivatePage()
331 OControlWizard_Base::ActivatePage();
334 //---------------------------------------------------------------------
335 void OControlWizard::implDetermineShape()
337 Reference
< XIndexAccess
> xPageObjects(m_aContext
.xDrawPage
, UNO_QUERY
);
338 DBG_ASSERT(xPageObjects
.is(), "OControlWizard::implDetermineShape: invalid page!");
340 // for comparing the model
341 Reference
< XControlModel
> xModelCompare(m_aContext
.xObjectModel
, UNO_QUERY
);
343 if (xPageObjects
.is())
345 // loop through all objects of the page
346 sal_Int32 nObjects
= xPageObjects
->getCount();
347 Reference
< XControlShape
> xControlShape
;
348 Reference
< XControlModel
> xControlModel
;
349 for (sal_Int32 i
=0; i
<nObjects
; ++i
)
351 if (xPageObjects
->getByIndex(i
) >>= xControlShape
)
352 { // it _is_ a control shape
353 xControlModel
= xControlShape
->getControl();
354 DBG_ASSERT(xControlModel
.is(), "OControlWizard::implDetermineShape: control shape without model!");
355 if (xModelCompare
.get() == xControlModel
.get())
357 m_aContext
.xObjectShape
= xControlShape
;
365 //---------------------------------------------------------------------
366 void OControlWizard::implDetermineForm()
368 Reference
< XChild
> xModelAsChild(m_aContext
.xObjectModel
, UNO_QUERY
);
369 Reference
< XInterface
> xControlParent
;
370 if (xModelAsChild
.is())
371 xControlParent
= xModelAsChild
->getParent();
373 m_aContext
.xForm
= Reference
< XPropertySet
>(xControlParent
, UNO_QUERY
);
374 m_aContext
.xRowSet
= Reference
< XRowSet
>(xControlParent
, UNO_QUERY
);
375 DBG_ASSERT(m_aContext
.xForm
.is() && m_aContext
.xRowSet
.is(),
376 "OControlWizard::implDetermineForm: missing some interfaces of the control parent!");
380 //---------------------------------------------------------------------
381 void OControlWizard::implDeterminePage()
385 // get the document model
386 Reference
< XChild
> xControlAsChild(m_aContext
.xObjectModel
, UNO_QUERY
);
387 Reference
< XChild
> xModelSearch(xControlAsChild
->getParent(), UNO_QUERY
);
389 Reference
< XModel
> xModel(xModelSearch
, UNO_QUERY
);
390 while (xModelSearch
.is() && !xModel
.is())
392 xModelSearch
= Reference
< XChild
>(xModelSearch
->getParent(), UNO_QUERY
);
393 xModel
= Reference
< XModel
>(xModelSearch
, UNO_QUERY
);
396 Reference
< XDrawPage
> xPage
;
399 m_aContext
.xDocumentModel
= xModel
;
401 Reference
< XDrawPageSupplier
> xPageSupp(xModel
, UNO_QUERY
);
403 { // it's a document with only one page -> Writer
404 xPage
= xPageSupp
->getDrawPage();
408 // get the controller currently working on this model
409 Reference
< XController
> xController
= xModel
->getCurrentController();
410 DBG_ASSERT(xController
.is(), "OControlWizard::implDeterminePage: no current controller!");
412 // maybe it's a spredsheet
413 Reference
< XSpreadsheetView
> xView(xController
, UNO_QUERY
);
416 Reference
< XSpreadsheet
> xSheet
= xView
->getActiveSheet();
417 xPageSupp
= Reference
< XDrawPageSupplier
>(xSheet
, UNO_QUERY
);
418 DBG_ASSERT(xPageSupp
.is(), "OControlWizard::implDeterminePage: a spreadsheet which is no page supplier!");
420 xPage
= xPageSupp
->getDrawPage();
423 { // can be a draw/impress doc only
424 Reference
< XDrawView
> xDrawView(xController
, UNO_QUERY
);
425 DBG_ASSERT(xDrawView
.is(), "OControlWizard::implDeterminePage: no alternatives left ... can't determine the page!");
427 xPage
= xDrawView
->getCurrentPage();
433 DBG_ASSERT(xPage
.is(), "OControlWizard::implDeterminePage: can't determine the page (no model)!");
435 m_aContext
.xDrawPage
= xPage
;
439 DBG_ERROR("OControlWizard::implDeterminePage: caught an exception!");
443 //---------------------------------------------------------------------
444 void OControlWizard::implGetDSContext()
446 Reference
< XMultiServiceFactory
> xORB
= getServiceFactory();
449 DBG_ASSERT(xORB
.is(), "OControlWizard::implGetDSContext: invalid service factory!");
451 Reference
< XInterface
> xContext
;
453 xContext
= xORB
->createInstance(::rtl::OUString::createFromAscii("com.sun.star.sdb.DatabaseContext"));
454 DBG_ASSERT(xContext
.is(), "OControlWizard::implGetDSContext: invalid database context!");
456 m_aContext
.xDatasourceContext
= Reference
< XNameAccess
>(xContext
, UNO_QUERY
);
457 DBG_ASSERT(m_aContext
.xDatasourceContext
.is() || !xContext
.is(), "OControlWizard::implGetDSContext: invalid database context (missing the XNameAccess)!");
461 DBG_ERROR("OControlWizard::implGetDSContext: invalid database context!");
465 //---------------------------------------------------------------------
466 Reference
< XConnection
> OControlWizard::getFormConnection(const OAccessRegulator
&) const
468 return getFormConnection();
470 //---------------------------------------------------------------------
471 Reference
< XConnection
> OControlWizard::getFormConnection() const
473 Reference
< XConnection
> xConn
;
476 if ( !::dbtools::isEmbeddedInDatabase(m_aContext
.xForm
,xConn
) )
477 m_aContext
.xForm
->getPropertyValue(::rtl::OUString::createFromAscii("ActiveConnection")) >>= xConn
;
479 catch(const Exception
&)
481 DBG_ERROR("OControlWizard::getFormConnection: caught an exception!");
486 //---------------------------------------------------------------------
487 void OControlWizard::setFormConnection( const OAccessRegulator
& _rAccess
, const Reference
< XConnection
>& _rxConn
, sal_Bool _bAutoDispose
)
491 Reference
< XConnection
> xOldConn
= getFormConnection(_rAccess
);
492 if (xOldConn
.get() == _rxConn
.get())
495 disposeComponent(xOldConn
);
497 // set the new connection
500 // for this, use a AutoDisposer (so the conn is cleaned up when the form dies or get's another connection)
501 Reference
< XRowSet
> xFormRowSet( m_aContext
.xForm
, UNO_QUERY
);
502 OAutoConnectionDisposer
* pAutoDispose
= new OAutoConnectionDisposer( xFormRowSet
, _rxConn
);
503 Reference
< XPropertyChangeListener
> xEnsureDelete( pAutoDispose
);
507 m_aContext
.xForm
->setPropertyValue( ::rtl::OUString::createFromAscii("ActiveConnection"), makeAny( _rxConn
) );
510 catch(const Exception
&)
512 DBG_ERROR("OControlWizard::setFormConnection: caught an exception!");
516 //---------------------------------------------------------------------
517 sal_Bool
OControlWizard::updateContext(const OAccessRegulator
&)
519 return initContext();
521 //---------------------------------------------------------------------
522 Reference
< XInteractionHandler
> OControlWizard::getInteractionHandler(Window
* _pWindow
) const
524 const ::rtl::OUString sInteractionHandlerServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.sdb.InteractionHandler");
525 Reference
< XInteractionHandler
> xHandler
;
528 if (getServiceFactory().is())
529 xHandler
= Reference
< XInteractionHandler
>(getServiceFactory()->createInstance(sInteractionHandlerServiceName
), UNO_QUERY
);
531 catch(Exception
&) { }
533 ShowServiceNotAvailableError(_pWindow
, sInteractionHandlerServiceName
, sal_True
);
536 //---------------------------------------------------------------------
537 sal_Bool
OControlWizard::initContext()
539 DBG_ASSERT(m_aContext
.xObjectModel
.is(), "OGroupBoxWizard::initContext: have no control model to work with!");
540 if (!m_aContext
.xObjectModel
.is())
544 m_aContext
.xForm
.clear();
545 m_aContext
.xRowSet
.clear();
546 m_aContext
.xDocumentModel
.clear();
547 m_aContext
.xDrawPage
.clear();
548 m_aContext
.xObjectShape
.clear();
549 m_aContext
.aFieldNames
.realloc(0);
551 m_aContext
.xObjectContainer
.clear();
552 m_aContext
.aTypes
.clear();
553 m_aContext
.bEmbedded
= sal_False
;
556 Reference
< XPreparedStatement
> xStatement
;
559 // get the datasource context
562 // first, determine the form the control belongs to
565 // need the page, too
568 // the shape of the control
569 implDetermineShape();
571 // get the columns of the object the settins refer to
572 Reference
< XNameAccess
> xColumns
;
574 if (m_aContext
.xForm
.is())
576 // collect some properties of the form
577 ::rtl::OUString sObjectName
= ::comphelper::getString(m_aContext
.xForm
->getPropertyValue(::rtl::OUString::createFromAscii("Command")));
578 sal_Int32 nObjectType
= ::comphelper::getINT32(m_aContext
.xForm
->getPropertyValue(::rtl::OUString::createFromAscii("CommandType")));
580 // calculate the connection the rowset is working with
581 Reference
< XConnection
> xConnection
;
582 m_aContext
.bEmbedded
= ::dbtools::isEmbeddedInDatabase( m_aContext
.xForm
, xConnection
);
583 if ( !m_aContext
.bEmbedded
)
584 xConnection
= ::dbtools::connectRowset( m_aContext
.xRowSet
, getServiceFactory(), sal_True
);
587 if (xConnection
.is())
593 Reference
< XTablesSupplier
> xSupplyTables(xConnection
, UNO_QUERY
);
594 if (xSupplyTables
.is() && xSupplyTables
->getTables().is() && xSupplyTables
->getTables()->hasByName(sObjectName
))
596 Reference
< XColumnsSupplier
> xSupplyColumns
;
597 m_aContext
.xObjectContainer
= xSupplyTables
->getTables();
598 m_aContext
.xObjectContainer
->getByName(sObjectName
) >>= xSupplyColumns
;
599 DBG_ASSERT(xSupplyColumns
.is(), "OControlWizard::initContext: invalid table columns!");
600 xColumns
= xSupplyColumns
->getColumns();
606 Reference
< XQueriesSupplier
> xSupplyQueries(xConnection
, UNO_QUERY
);
607 if (xSupplyQueries
.is() && xSupplyQueries
->getQueries().is() && xSupplyQueries
->getQueries()->hasByName(sObjectName
))
609 Reference
< XColumnsSupplier
> xSupplyColumns
;
610 m_aContext
.xObjectContainer
= xSupplyQueries
->getQueries();
611 m_aContext
.xObjectContainer
->getByName(sObjectName
) >>= xSupplyColumns
;
612 DBG_ASSERT(xSupplyColumns
.is(), "OControlWizard::initContext: invalid query columns!");
613 xColumns
= xSupplyColumns
->getColumns();
619 xStatement
= xConnection
->prepareStatement(sObjectName
);
621 // not interested in any results, only in the fields
622 Reference
< XPropertySet
> xStatementProps(xStatement
, UNO_QUERY
);
623 xStatementProps
->setPropertyValue(::rtl::OUString::createFromAscii("MaxRows"), makeAny(sal_Int32(0)));
625 // TODO: think about handling local SQLExceptions here ...
626 Reference
< XColumnsSupplier
> xSupplyCols(xStatement
->executeQuery(), UNO_QUERY
);
627 if (xSupplyCols
.is())
628 xColumns
= xSupplyCols
->getColumns();
636 m_aContext
.aFieldNames
= xColumns
->getElementNames();
637 static const ::rtl::OUString s_sFieldTypeProperty
= ::rtl::OUString::createFromAscii("Type");
638 const ::rtl::OUString
* pBegin
= m_aContext
.aFieldNames
.getConstArray();
639 const ::rtl::OUString
* pEnd
= pBegin
+ m_aContext
.aFieldNames
.getLength();
640 for(;pBegin
!= pEnd
;++pBegin
)
642 sal_Int32 nFieldType
= DataType::OTHER
;
645 Reference
< XPropertySet
> xColumn
;
646 xColumns
->getByName(*pBegin
) >>= xColumn
;
647 xColumn
->getPropertyValue(s_sFieldTypeProperty
) >>= nFieldType
;
651 DBG_ERROR("OControlWizard::initContext: unexpected exception while gathering column information!");
653 m_aContext
.aTypes
.insert(OControlWizardContext::TNameTypeMap::value_type(*pBegin
,nFieldType
));
657 catch(SQLContext
& e
) { aSQLException
<<= e
; }
658 catch(SQLWarning
& e
) { aSQLException
<<= e
; }
659 catch(SQLException
& e
) { aSQLException
<<= e
; }
662 DBG_ERROR("OControlWizard::initContext: could not retrieve the control context (caught an exception)!");
665 ::comphelper::disposeComponent(xStatement
);
667 if (aSQLException
.hasValue())
668 { // an SQLException (or derivee) was thrown ...
670 // prepend an extra SQLContext explaining what we were doing
672 aContext
.Message
= String(ModuleRes(RID_STR_COULDNOTOPENTABLE
));
673 aContext
.NextException
= aSQLException
;
675 // create an interaction handler to display this exception
676 Reference
< XInteractionHandler
> xHandler
= getInteractionHandler(this);
677 if ( !xHandler
.is() )
680 Reference
< XInteractionRequest
> xRequest
= new OInteractionRequest(makeAny(aContext
));
683 xHandler
->handle(xRequest
);
685 catch(Exception
&) { }
689 return 0 != m_aContext
.aFieldNames
.getLength();
692 //---------------------------------------------------------------------
693 void OControlWizard::commitControlSettings(OControlWizardSettings
* _pSettings
)
695 DBG_ASSERT(m_aContext
.xObjectModel
.is(), "OControlWizard::commitControlSettings: have no control model to work with!");
696 if (!m_aContext
.xObjectModel
.is())
699 // the only thing we have at the moment is the label
702 ::rtl::OUString sLabelPropertyName
= ::rtl::OUString::createFromAscii("Label");
703 Reference
< XPropertySetInfo
> xInfo
= m_aContext
.xObjectModel
->getPropertySetInfo();
704 if (xInfo
.is() && xInfo
->hasPropertyByName(sLabelPropertyName
))
706 ::rtl::OUString
sControlLabel(_pSettings
->sControlLabel
);
707 m_aContext
.xObjectModel
->setPropertyValue(
708 ::rtl::OUString::createFromAscii("Label"),
709 makeAny(sControlLabel
)
715 DBG_ERROR("OControlWizard::commitControlSettings: could not commit the basic control settings!");
719 //---------------------------------------------------------------------
720 void OControlWizard::initControlSettings(OControlWizardSettings
* _pSettings
)
722 DBG_ASSERT(m_aContext
.xObjectModel
.is(), "OControlWizard::initControlSettings: have no control model to work with!");
723 if (!m_aContext
.xObjectModel
.is())
726 // initialize some settings from the control model give
729 ::rtl::OUString sLabelPropertyName
= ::rtl::OUString::createFromAscii("Label");
730 Reference
< XPropertySetInfo
> xInfo
= m_aContext
.xObjectModel
->getPropertySetInfo();
731 if (xInfo
.is() && xInfo
->hasPropertyByName(sLabelPropertyName
))
733 ::rtl::OUString sControlLabel
;
734 m_aContext
.xObjectModel
->getPropertyValue(sLabelPropertyName
) >>= sControlLabel
;
735 _pSettings
->sControlLabel
= sControlLabel
;
740 DBG_ERROR("OControlWizard::initControlSettings: could not retrieve the basic control settings!");
744 //---------------------------------------------------------------------
745 sal_Bool
OControlWizard::needDatasourceSelection()
748 return (0 == getContext().aFieldNames
.getLength());
749 // if we got fields, the data source is valid ...
752 // // first, we need a valid data source name
753 // ::rtl::OUString sDataSourceName;
754 // m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("DataSourceName")) >>= sDataSourceName;
755 // if (m_aContext.xDatasourceContext.is() && m_aContext.xDatasourceContext->hasByName(sDataSourceName))
756 // { // at least the data source name is valid ...
757 // // then, a CommandType "table" would be nice ...
758 // sal_Int32 nCommandType = CommandType::COMMAND;
759 // m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("CommandType")) >>= nCommandType;
760 // if (CommandType::TABLE == nCommandType)
762 // // now the table itself should be valid
763 // ::rtl::OUString sTableName;
764 // m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("Command")) >>= sTableName;
765 // if (m_aContext.xObjectContainer.is() && m_aContext.xObjectContainer->hasByName(sTableName))
772 // DBG_ERROR("OControlWizard::needDatasourceSelection: caught an exception while checking the form settings!");
777 //.........................................................................
779 //.........................................................................