LCOV - code coverage report
Current view: top level - extensions/source/dbpilots - controlwizard.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 298 0.0 %
Date: 2014-11-03 Functions: 0 34 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10