Update ooo320-m1
[ooovba.git] / extensions / source / dbpilots / controlwizard.cxx
blobb09b0ae12a8eed190afc8a347536e9b0ed932b88
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: controlwizard.cxx,v $
10 * $Revision: 1.22 $
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 //.........................................................................
59 namespace dbp
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 //=====================================================================
81 //= OAccessRegulator
82 //=====================================================================
83 struct OAccessRegulator
85 friend class OControlWizardPage;
87 protected:
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)
103 ,m_pFormTable(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;
116 delete m_pFormTable;
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)
158 if (_bClear)
159 _rList.Clear();
160 const ::rtl::OUString* pItems = _rItems.getConstArray();
161 const ::rtl::OUString* pEnd = pItems + _rItems.getLength();
162 WizardState nPos;
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)
174 if (_bClear)
175 _rList.Clear();
176 const ::rtl::OUString* pItems = _rItems.getConstArray();
177 const ::rtl::OUString* pEnd = pItems + _rItems.getLength();
178 WizardState nPos;
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)
191 // nothing to do
192 return;
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;
265 break;
267 case CommandType::QUERY:
268 nCommandTypeResourceId = RID_STR_TYPE_QUERY;
269 break;
271 default:
272 nCommandTypeResourceId = RID_STR_TYPE_COMMAND;
273 break;
275 m_pFormContentType->SetText(String(ModuleRes(nCommandTypeResourceId)));
278 OControlWizardPage_Base::initializePage();
281 //=====================================================================
282 //= OControlWizard
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)
288 ,m_xORB(_rxORB)
290 m_aContext.xObjectModel = _rxObjectModel;
291 initContext();
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;
313 catch(Exception&)
315 DBG_ERROR("OControlWizard::activate: could not obtain the class id!");
317 if (!approveControl(nClassId))
319 // TODO: MessageBox or exception
320 return RET_CANCEL;
323 ActivatePage();
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;
358 break;
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;
397 if (xModel.is())
399 m_aContext.xDocumentModel = xModel;
401 Reference< XDrawPageSupplier > xPageSupp(xModel, UNO_QUERY);
402 if (xPageSupp.is())
403 { // it's a document with only one page -> Writer
404 xPage = xPageSupp->getDrawPage();
406 else
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);
414 if (xView.is())
415 { // okay, it is one
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!");
419 if (xPageSupp.is())
420 xPage = xPageSupp->getDrawPage();
422 else
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!");
426 if (xDrawView.is())
427 xPage = xDrawView->getCurrentPage();
431 else
433 DBG_ASSERT(xPage.is(), "OControlWizard::implDeterminePage: can't determine the page (no model)!");
435 m_aContext.xDrawPage = xPage;
437 catch(Exception&)
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;
452 if (xORB.is())
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)!");
459 catch(Exception&)
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!");
483 return xConn;
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())
493 return;
495 disposeComponent(xOldConn);
497 // set the new connection
498 if ( _bAutoDispose )
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 );
505 else
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&) { }
532 if (!xHandler.is())
533 ShowServiceNotAvailableError(_pWindow, sInteractionHandlerServiceName, sal_True);
534 return xHandler;
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())
541 return sal_False;
543 // reset the context
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;
555 Any aSQLException;
556 Reference< XPreparedStatement > xStatement;
559 // get the datasource context
560 implGetDSContext();
562 // first, determine the form the control belongs to
563 implDetermineForm();
565 // need the page, too
566 implDeterminePage();
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 );
586 // get the fields
587 if (xConnection.is())
589 switch (nObjectType)
591 case 0:
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();
603 break;
604 case 1:
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();
616 break;
617 default:
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();
634 if (xColumns.is())
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;
649 catch(Exception&)
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; }
660 catch(Exception&)
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
671 SQLContext aContext;
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() )
678 return sal_False;
680 Reference< XInteractionRequest > xRequest = new OInteractionRequest(makeAny(aContext));
683 xHandler->handle(xRequest);
685 catch(Exception&) { }
686 return sal_False;
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())
697 return;
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)
713 catch(Exception&)
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())
724 return;
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;
738 catch(Exception&)
740 DBG_ERROR("OControlWizard::initControlSettings: could not retrieve the basic control settings!");
744 //---------------------------------------------------------------------
745 sal_Bool OControlWizard::needDatasourceSelection()
747 // lemme see ...
748 return (0 == getContext().aFieldNames.getLength());
749 // if we got fields, the data source is valid ...
750 // try
751 // {
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)
761 // { // okay ....
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))
766 // return sal_False;
767 // }
768 // }
769 // }
770 // catch(Exception&)
771 // {
772 // DBG_ERROR("OControlWizard::needDatasourceSelection: caught an exception while checking the form settings!");
773 // }
774 // return sal_True;
777 //.........................................................................
778 } // namespace dbp
779 //.........................................................................