LCOV - code coverage report
Current view: top level - extensions/source/dbpilots - controlwizard.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 324 0.0 %
Date: 2012-08-25 Functions: 0 33 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "controlwizard.hxx"
      30                 :            : #include <tools/debug.hxx>
      31                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      32                 :            : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      33                 :            : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      34                 :            : #include <com/sun/star/sdbc/XPreparedStatement.hpp>
      35                 :            : #include <com/sun/star/container/XChild.hpp>
      36                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      37                 :            : #include <com/sun/star/frame/XModel.hpp>
      38                 :            : #include <com/sun/star/sheet/XSpreadsheetView.hpp>
      39                 :            : #include <com/sun/star/drawing/XDrawView.hpp>
      40                 :            : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      41                 :            : #include <com/sun/star/sdb/CommandType.hpp>
      42                 :            : #include <com/sun/star/sdbc/SQLWarning.hpp>
      43                 :            : #include <com/sun/star/sdb/SQLContext.hpp>
      44                 :            : #include <comphelper/types.hxx>
      45                 :            : #include <connectivity/dbtools.hxx>
      46                 :            : #include <vcl/msgbox.hxx>
      47                 :            : #include <comphelper/interaction.hxx>
      48                 :            : #include <vcl/stdtext.hxx>
      49                 :            : #include <svtools/localresaccess.hxx>
      50                 :            : #include <connectivity/conncleanup.hxx>
      51                 :            : #include <com/sun/star/sdbc/DataType.hpp>
      52                 :            : #include <tools/urlobj.hxx>
      53                 :            : 
      54                 :            : //.........................................................................
      55                 :            : namespace dbp
      56                 :            : {
      57                 :            : //.........................................................................
      58                 :            : 
      59                 :            :     using namespace ::com::sun::star::uno;
      60                 :            :     using namespace ::com::sun::star::awt;
      61                 :            :     using namespace ::com::sun::star::lang;
      62                 :            :     using namespace ::com::sun::star::sdb;
      63                 :            :     using namespace ::com::sun::star::sdbc;
      64                 :            :     using namespace ::com::sun::star::sdbcx;
      65                 :            :     using namespace ::com::sun::star::beans;
      66                 :            :     using namespace ::com::sun::star::container;
      67                 :            :     using namespace ::com::sun::star::drawing;
      68                 :            :     using namespace ::com::sun::star::frame;
      69                 :            :     using namespace ::com::sun::star::sheet;
      70                 :            :     using namespace ::com::sun::star::form;
      71                 :            :     using namespace ::com::sun::star::task;
      72                 :            :     using namespace ::svt;
      73                 :            :     using namespace ::comphelper;
      74                 :            :     using namespace ::dbtools;
      75                 :            : 
      76                 :            :     //=====================================================================
      77                 :            :     //= OAccessRegulator
      78                 :            :     //=====================================================================
      79                 :            :     struct OAccessRegulator
      80                 :            :     {
      81                 :            :         friend class OControlWizardPage;
      82                 :            : 
      83                 :            :     protected:
      84                 :          0 :         OAccessRegulator() { }
      85                 :            :     };
      86                 :            : 
      87                 :            :     //=====================================================================
      88                 :            :     //= OControlWizardPage
      89                 :            :     //=====================================================================
      90                 :            :     //---------------------------------------------------------------------
      91                 :          0 :     OControlWizardPage::OControlWizardPage( OControlWizard* _pParent, const ResId& _rResId )
      92                 :            :         :OControlWizardPage_Base( _pParent, _rResId )
      93                 :            :         ,m_pFormSettingsSeparator(NULL)
      94                 :            :         ,m_pFormDatasourceLabel(NULL)
      95                 :            :         ,m_pFormDatasource(NULL)
      96                 :            :         ,m_pFormContentTypeLabel(NULL)
      97                 :            :         ,m_pFormContentType(NULL)
      98                 :            :         ,m_pFormTableLabel(NULL)
      99                 :          0 :         ,m_pFormTable(NULL)
     100                 :            :     {
     101                 :          0 :     }
     102                 :            : 
     103                 :            :     //---------------------------------------------------------------------
     104                 :          0 :     OControlWizardPage::~OControlWizardPage()
     105                 :            :     {
     106                 :          0 :         delete m_pFormSettingsSeparator;
     107                 :          0 :         delete m_pFormDatasourceLabel;
     108                 :          0 :         delete m_pFormDatasource;
     109                 :          0 :         delete m_pFormContentTypeLabel;
     110                 :          0 :         delete m_pFormContentType;
     111                 :          0 :         delete m_pFormTableLabel;
     112                 :          0 :         delete m_pFormTable;
     113                 :          0 :     }
     114                 :            : 
     115                 :            :     //---------------------------------------------------------------------
     116                 :          0 :     OControlWizard* OControlWizardPage::getDialog()
     117                 :            :     {
     118                 :          0 :         return static_cast< OControlWizard* >(GetParent());
     119                 :            :     }
     120                 :            : 
     121                 :            :     //---------------------------------------------------------------------
     122                 :          0 :     const OControlWizard* OControlWizardPage::getDialog() const
     123                 :            :     {
     124                 :          0 :         return static_cast< OControlWizard* >(GetParent());
     125                 :            :     }
     126                 :            : 
     127                 :            :     //---------------------------------------------------------------------
     128                 :          0 :     sal_Bool OControlWizardPage::updateContext()
     129                 :            :     {
     130                 :          0 :         return getDialog()->updateContext(OAccessRegulator());
     131                 :            :     }
     132                 :            : 
     133                 :            :     //---------------------------------------------------------------------
     134                 :          0 :     Reference< XConnection > OControlWizardPage::getFormConnection() const
     135                 :            :     {
     136                 :          0 :         return getDialog()->getFormConnection(OAccessRegulator());
     137                 :            :     }
     138                 :            : 
     139                 :            :     //---------------------------------------------------------------------
     140                 :          0 :     void OControlWizardPage::setFormConnection( const Reference< XConnection >& _rxConn, sal_Bool _bAutoDispose )
     141                 :            :     {
     142                 :          0 :         getDialog()->setFormConnection( OAccessRegulator(), _rxConn, _bAutoDispose );
     143                 :          0 :     }
     144                 :            : 
     145                 :            :     //---------------------------------------------------------------------
     146                 :          0 :     const OControlWizardContext& OControlWizardPage::getContext()
     147                 :            :     {
     148                 :          0 :         return getDialog()->getContext();
     149                 :            :     }
     150                 :            : 
     151                 :            :     //---------------------------------------------------------------------
     152                 :          0 :     void OControlWizardPage::fillListBox(ListBox& _rList, const Sequence< ::rtl::OUString >& _rItems, sal_Bool _bClear)
     153                 :            :     {
     154                 :          0 :         if (_bClear)
     155                 :          0 :             _rList.Clear();
     156                 :          0 :         const ::rtl::OUString* pItems = _rItems.getConstArray();
     157                 :          0 :         const ::rtl::OUString* pEnd = pItems + _rItems.getLength();
     158                 :            :         ::svt::WizardTypes::WizardState nPos;
     159                 :          0 :         sal_Int32 nIndex = 0;
     160                 :          0 :         for (;pItems < pEnd; ++pItems, ++nIndex)
     161                 :            :         {
     162                 :          0 :             nPos = _rList.InsertEntry(*pItems);
     163                 :          0 :             _rList.SetEntryData(nPos, reinterpret_cast<void*>(nIndex));
     164                 :            :         }
     165                 :          0 :     }
     166                 :            : 
     167                 :            :     //---------------------------------------------------------------------
     168                 :          0 :     void OControlWizardPage::fillListBox(ComboBox& _rList, const Sequence< ::rtl::OUString >& _rItems, sal_Bool _bClear)
     169                 :            :     {
     170                 :          0 :         if (_bClear)
     171                 :          0 :             _rList.Clear();
     172                 :          0 :         const ::rtl::OUString* pItems = _rItems.getConstArray();
     173                 :          0 :         const ::rtl::OUString* pEnd = pItems + _rItems.getLength();
     174                 :            :         ::svt::WizardTypes::WizardState nPos;
     175                 :          0 :         sal_Int32 nIndex = 0;
     176                 :          0 :         for (;pItems < pEnd; ++pItems)
     177                 :            :         {
     178                 :          0 :             nPos = _rList.InsertEntry(*pItems);
     179                 :          0 :             _rList.SetEntryData(nPos, reinterpret_cast<void*>(nIndex));
     180                 :            :         }
     181                 :          0 :     }
     182                 :            : 
     183                 :            :     //---------------------------------------------------------------------
     184                 :          0 :     void OControlWizardPage::enableFormDatasourceDisplay()
     185                 :            :     {
     186                 :          0 :         if (m_pFormSettingsSeparator)
     187                 :            :             // nothing to do
     188                 :          0 :             return;
     189                 :            : 
     190                 :          0 :         ModuleRes aModuleRes(RID_PAGE_FORM_DATASOURCE_STATUS);
     191                 :          0 :         OLocalResourceAccess aLocalControls(aModuleRes, RSC_TABPAGE);
     192                 :            : 
     193                 :          0 :         m_pFormSettingsSeparator    = new FixedLine(this,  ModuleRes(FL_FORMSETINGS));
     194                 :          0 :         m_pFormDatasourceLabel      = new FixedText(this,  ModuleRes(FT_FORMDATASOURCELABEL));
     195                 :          0 :         m_pFormDatasource           = new FixedText(this,  ModuleRes(FT_FORMDATASOURCE));
     196                 :          0 :         m_pFormContentTypeLabel     = new FixedText(this,  ModuleRes(FT_FORMCONTENTTYPELABEL));
     197                 :          0 :         m_pFormContentType          = new FixedText(this,  ModuleRes(FT_FORMCONTENTTYPE));
     198                 :          0 :         m_pFormTableLabel           = new FixedText(this,  ModuleRes(FT_FORMTABLELABEL));
     199                 :          0 :         m_pFormTable                = new FixedText(this,  ModuleRes(FT_FORMTABLE));
     200                 :            : 
     201                 :          0 :         const OControlWizardContext& rContext = getContext();
     202                 :          0 :         if ( rContext.bEmbedded )
     203                 :            :         {
     204                 :          0 :             m_pFormDatasourceLabel->Hide();
     205                 :          0 :             m_pFormDatasource->Hide();
     206                 :          0 :             m_pFormContentTypeLabel->SetPosPixel(m_pFormDatasourceLabel->GetPosPixel());
     207                 :          0 :             m_pFormContentType->SetPosPixel(m_pFormDatasource->GetPosPixel());
     208                 :          0 :             m_pFormTableLabel->SetPosPixel(::Point(m_pFormDatasourceLabel->GetPosPixel().X(),m_pFormTableLabel->GetPosPixel().Y()));
     209                 :          0 :             m_pFormTable->SetPosPixel(::Point(m_pFormDatasource->GetPosPixel().X(),m_pFormTable->GetPosPixel().Y()));
     210                 :          0 :         }
     211                 :            :     }
     212                 :            : 
     213                 :            :     //---------------------------------------------------------------------
     214                 :          0 :     void OControlWizardPage::adjustControlForNoDSDisplay(Control* _pControl, sal_Bool _bConstLowerDistance)
     215                 :            :     {
     216                 :          0 :         ::Size aDistanceToMove = LogicToPixel( ::Size( 0, 37 ), MAP_APPFONT );
     217                 :            : 
     218                 :          0 :         ::Point aPos = _pControl->GetPosPixel();
     219                 :          0 :         aPos.Y() -= aDistanceToMove.Height();
     220                 :          0 :         _pControl->SetPosPixel(aPos);
     221                 :            : 
     222                 :          0 :         if (_bConstLowerDistance)
     223                 :            :         {
     224                 :          0 :             ::Size aSize = _pControl->GetSizePixel();
     225                 :          0 :             aSize.Height() += aDistanceToMove.Height();
     226                 :          0 :             _pControl->SetSizePixel(aSize);
     227                 :            :         }
     228                 :          0 :     }
     229                 :            : 
     230                 :            :     //---------------------------------------------------------------------
     231                 :          0 :     void OControlWizardPage::initializePage()
     232                 :            :     {
     233                 :          0 :         if (m_pFormDatasource && m_pFormContentTypeLabel && m_pFormTable)
     234                 :            :         {
     235                 :          0 :             const OControlWizardContext& rContext = getContext();
     236                 :          0 :             ::rtl::OUString sDataSource;
     237                 :          0 :             ::rtl::OUString sCommand;
     238                 :          0 :             sal_Int32 nCommandType = CommandType::COMMAND;
     239                 :            :             try
     240                 :            :             {
     241                 :          0 :                 rContext.xForm->getPropertyValue(::rtl::OUString("DataSourceName")) >>= sDataSource;
     242                 :          0 :                 rContext.xForm->getPropertyValue(::rtl::OUString("Command")) >>= sCommand;
     243                 :          0 :                 rContext.xForm->getPropertyValue(::rtl::OUString("CommandType")) >>= nCommandType;
     244                 :            :             }
     245                 :          0 :             catch(const Exception&)
     246                 :            :             {
     247                 :            :                 OSL_FAIL("OControlWizardPage::initializePage: caught an exception!");
     248                 :            :             }
     249                 :            : 
     250                 :          0 :             INetURLObject aURL( sDataSource );
     251                 :          0 :             if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
     252                 :          0 :                 sDataSource = aURL.GetName(INetURLObject::DECODE_WITH_CHARSET);
     253                 :          0 :             m_pFormDatasource->SetText(sDataSource);
     254                 :          0 :             m_pFormTable->SetText(sCommand);
     255                 :            : 
     256                 :          0 :             ::svt::WizardTypes::WizardState nCommandTypeResourceId = 0;
     257                 :          0 :             switch (nCommandType)
     258                 :            :             {
     259                 :            :                 case CommandType::TABLE:
     260                 :          0 :                     nCommandTypeResourceId = RID_STR_TYPE_TABLE;
     261                 :          0 :                     break;
     262                 :            : 
     263                 :            :                 case CommandType::QUERY:
     264                 :          0 :                     nCommandTypeResourceId = RID_STR_TYPE_QUERY;
     265                 :          0 :                     break;
     266                 :            : 
     267                 :            :                 default:
     268                 :          0 :                     nCommandTypeResourceId = RID_STR_TYPE_COMMAND;
     269                 :          0 :                     break;
     270                 :            :             }
     271                 :          0 :             m_pFormContentType->SetText(String(ModuleRes(nCommandTypeResourceId)));
     272                 :            :         }
     273                 :            : 
     274                 :          0 :         OControlWizardPage_Base::initializePage();
     275                 :          0 :     }
     276                 :            : 
     277                 :            :     //=====================================================================
     278                 :            :     //= OControlWizard
     279                 :            :     //=====================================================================
     280                 :            :     //---------------------------------------------------------------------
     281                 :          0 :     OControlWizard::OControlWizard( Window* _pParent, const ResId& _rId,
     282                 :            :             const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB )
     283                 :            :         :OWizardMachine(_pParent, _rId, WZB_CANCEL | WZB_PREVIOUS | WZB_NEXT | WZB_FINISH)
     284                 :          0 :         ,m_xORB(_rxORB)
     285                 :            :     {
     286                 :          0 :         m_aContext.xObjectModel = _rxObjectModel;
     287                 :          0 :         initContext();
     288                 :            : 
     289                 :          0 :         SetPageSizePixel(LogicToPixel(::Size(WINDOW_SIZE_X, WINDOW_SIZE_Y), MAP_APPFONT));
     290                 :          0 :         ShowButtonFixedLine(sal_True);
     291                 :          0 :         defaultButton(WZB_NEXT);
     292                 :          0 :         enableButtons(WZB_FINISH, sal_False);
     293                 :          0 :     }
     294                 :            : 
     295                 :            :     //---------------------------------------------------------------------
     296                 :          0 :     OControlWizard::~OControlWizard()
     297                 :            :     {
     298                 :          0 :     }
     299                 :            : 
     300                 :            :     //---------------------------------------------------------------------
     301                 :          0 :     short OControlWizard::Execute()
     302                 :            :     {
     303                 :            :         // get the class id of the control we're dealing with
     304                 :          0 :         sal_Int16 nClassId = FormComponentType::CONTROL;
     305                 :            :         try
     306                 :            :         {
     307                 :          0 :             getContext().xObjectModel->getPropertyValue(::rtl::OUString("ClassId")) >>= nClassId;
     308                 :            :         }
     309                 :          0 :         catch(const Exception&)
     310                 :            :         {
     311                 :            :             OSL_FAIL("OControlWizard::activate: could not obtain the class id!");
     312                 :            :         }
     313                 :          0 :         if (!approveControl(nClassId))
     314                 :            :         {
     315                 :            :             // TODO: MessageBox or exception
     316                 :          0 :             return RET_CANCEL;
     317                 :            :         }
     318                 :            : 
     319                 :          0 :         ActivatePage();
     320                 :            : 
     321                 :          0 :         return OControlWizard_Base::Execute();
     322                 :            :     }
     323                 :            : 
     324                 :            :     //---------------------------------------------------------------------
     325                 :          0 :     void OControlWizard::ActivatePage()
     326                 :            :     {
     327                 :          0 :         OControlWizard_Base::ActivatePage();
     328                 :          0 :     }
     329                 :            : 
     330                 :            :     //---------------------------------------------------------------------
     331                 :          0 :     void OControlWizard::implDetermineShape()
     332                 :            :     {
     333                 :          0 :         Reference< XIndexAccess > xPageObjects(m_aContext.xDrawPage, UNO_QUERY);
     334                 :            :         DBG_ASSERT(xPageObjects.is(), "OControlWizard::implDetermineShape: invalid page!");
     335                 :            : 
     336                 :            :         // for comparing the model
     337                 :          0 :         Reference< XControlModel > xModelCompare(m_aContext.xObjectModel, UNO_QUERY);
     338                 :            : 
     339                 :          0 :         if (xPageObjects.is())
     340                 :            :         {
     341                 :            :             // loop through all objects of the page
     342                 :          0 :             sal_Int32 nObjects = xPageObjects->getCount();
     343                 :          0 :             Reference< XControlShape > xControlShape;
     344                 :          0 :             Reference< XControlModel > xControlModel;
     345                 :          0 :             for (sal_Int32 i=0; i<nObjects; ++i)
     346                 :            :             {
     347                 :          0 :                 if (xPageObjects->getByIndex(i) >>= xControlShape)
     348                 :            :                 {   // it _is_ a control shape
     349                 :          0 :                     xControlModel = xControlShape->getControl();
     350                 :            :                     DBG_ASSERT(xControlModel.is(), "OControlWizard::implDetermineShape: control shape without model!");
     351                 :          0 :                     if (xModelCompare.get() == xControlModel.get())
     352                 :            :                     {
     353                 :          0 :                         m_aContext.xObjectShape = xControlShape;
     354                 :          0 :                         break;
     355                 :            :                     }
     356                 :            :                 }
     357                 :          0 :             }
     358                 :          0 :         }
     359                 :          0 :     }
     360                 :            : 
     361                 :            :     //---------------------------------------------------------------------
     362                 :          0 :     void OControlWizard::implDetermineForm()
     363                 :            :     {
     364                 :          0 :         Reference< XChild > xModelAsChild(m_aContext.xObjectModel, UNO_QUERY);
     365                 :          0 :         Reference< XInterface > xControlParent;
     366                 :          0 :         if (xModelAsChild.is())
     367                 :          0 :             xControlParent = xModelAsChild->getParent();
     368                 :            : 
     369                 :          0 :         m_aContext.xForm = Reference< XPropertySet >(xControlParent, UNO_QUERY);
     370                 :          0 :         m_aContext.xRowSet = Reference< XRowSet >(xControlParent, UNO_QUERY);
     371                 :            :         DBG_ASSERT(m_aContext.xForm.is() && m_aContext.xRowSet.is(),
     372                 :          0 :             "OControlWizard::implDetermineForm: missing some interfaces of the control parent!");
     373                 :            : 
     374                 :          0 :     }
     375                 :            : 
     376                 :            :     //---------------------------------------------------------------------
     377                 :          0 :     void OControlWizard::implDeterminePage()
     378                 :            :     {
     379                 :            :         try
     380                 :            :         {
     381                 :            :             // get the document model
     382                 :          0 :             Reference< XChild > xControlAsChild(m_aContext.xObjectModel, UNO_QUERY);
     383                 :          0 :             Reference< XChild > xModelSearch(xControlAsChild->getParent(), UNO_QUERY);
     384                 :            : 
     385                 :          0 :             Reference< XModel > xModel(xModelSearch, UNO_QUERY);
     386                 :          0 :             while (xModelSearch.is() && !xModel.is())
     387                 :            :             {
     388                 :          0 :                 xModelSearch = Reference< XChild >(xModelSearch->getParent(), UNO_QUERY);
     389                 :          0 :                 xModel = Reference< XModel >(xModelSearch, UNO_QUERY);
     390                 :            :             }
     391                 :            : 
     392                 :          0 :             Reference< XDrawPage > xPage;
     393                 :          0 :             if (xModel.is())
     394                 :            :             {
     395                 :          0 :                 m_aContext.xDocumentModel = xModel;
     396                 :            : 
     397                 :          0 :                 Reference< XDrawPageSupplier > xPageSupp(xModel, UNO_QUERY);
     398                 :          0 :                 if (xPageSupp.is())
     399                 :            :                 {   // it's a document with only one page -> Writer
     400                 :          0 :                     xPage = xPageSupp->getDrawPage();
     401                 :            :                 }
     402                 :            :                 else
     403                 :            :                 {
     404                 :            :                     // get the controller currently working on this model
     405                 :          0 :                     Reference< XController > xController = xModel->getCurrentController();
     406                 :            :                     DBG_ASSERT(xController.is(), "OControlWizard::implDeterminePage: no current controller!");
     407                 :            : 
     408                 :            :                     // maybe it's a spredsheet
     409                 :          0 :                     Reference< XSpreadsheetView > xView(xController, UNO_QUERY);
     410                 :          0 :                     if (xView.is())
     411                 :            :                     {   // okay, it is one
     412                 :          0 :                         Reference< XSpreadsheet > xSheet = xView->getActiveSheet();
     413                 :          0 :                         xPageSupp = Reference< XDrawPageSupplier >(xSheet, UNO_QUERY);
     414                 :            :                         DBG_ASSERT(xPageSupp.is(), "OControlWizard::implDeterminePage: a spreadsheet which is no page supplier!");
     415                 :          0 :                         if (xPageSupp.is())
     416                 :          0 :                             xPage = xPageSupp->getDrawPage();
     417                 :            :                     }
     418                 :            :                     else
     419                 :            :                     {   // can be a draw/impress doc only
     420                 :          0 :                         Reference< XDrawView > xDrawView(xController, UNO_QUERY);
     421                 :            :                         DBG_ASSERT(xDrawView.is(), "OControlWizard::implDeterminePage: no alternatives left ... can't determine the page!");
     422                 :          0 :                         if (xDrawView.is())
     423                 :          0 :                             xPage = xDrawView->getCurrentPage();
     424                 :          0 :                     }
     425                 :          0 :                 }
     426                 :            :             }
     427                 :            :             else
     428                 :            :             {
     429                 :            :                 DBG_ASSERT(xPage.is(), "OControlWizard::implDeterminePage: can't determine the page (no model)!");
     430                 :            :             }
     431                 :          0 :             m_aContext.xDrawPage = xPage;
     432                 :            :         }
     433                 :          0 :         catch(const Exception&)
     434                 :            :         {
     435                 :            :             OSL_FAIL("OControlWizard::implDeterminePage: caught an exception!");
     436                 :            :         }
     437                 :          0 :     }
     438                 :            : 
     439                 :            :     //---------------------------------------------------------------------
     440                 :          0 :     void OControlWizard::implGetDSContext()
     441                 :            :     {
     442                 :          0 :         Reference< XMultiServiceFactory > xORB = getServiceFactory();
     443                 :            :         try
     444                 :            :         {
     445                 :            :             DBG_ASSERT(xORB.is(), "OControlWizard::implGetDSContext: invalid service factory!");
     446                 :            : 
     447                 :          0 :             Reference< XInterface > xContext;
     448                 :          0 :             if (xORB.is())
     449                 :          0 :                 xContext = xORB->createInstance(::rtl::OUString("com.sun.star.sdb.DatabaseContext"));
     450                 :            :             DBG_ASSERT(xContext.is(), "OControlWizard::implGetDSContext: invalid database context!");
     451                 :            : 
     452                 :          0 :             m_aContext.xDatasourceContext = Reference< XNameAccess >(xContext, UNO_QUERY);
     453                 :          0 :             DBG_ASSERT(m_aContext.xDatasourceContext.is() || !xContext.is(), "OControlWizard::implGetDSContext: invalid database context (missing the XNameAccess)!");
     454                 :            :         }
     455                 :          0 :         catch(const Exception&)
     456                 :            :         {
     457                 :            :             OSL_FAIL("OControlWizard::implGetDSContext: invalid database context!");
     458                 :          0 :         }
     459                 :          0 :     }
     460                 :            : 
     461                 :            :     //---------------------------------------------------------------------
     462                 :          0 :     Reference< XConnection > OControlWizard::getFormConnection(const OAccessRegulator&) const
     463                 :            :     {
     464                 :          0 :         return getFormConnection();
     465                 :            :     }
     466                 :            :     //---------------------------------------------------------------------
     467                 :          0 :     Reference< XConnection > OControlWizard::getFormConnection() const
     468                 :            :     {
     469                 :          0 :         Reference< XConnection > xConn;
     470                 :            :         try
     471                 :            :         {
     472                 :          0 :             if ( !::dbtools::isEmbeddedInDatabase(m_aContext.xForm,xConn) )
     473                 :          0 :                 m_aContext.xForm->getPropertyValue(::rtl::OUString("ActiveConnection")) >>= xConn;
     474                 :            :         }
     475                 :          0 :         catch(const Exception&)
     476                 :            :         {
     477                 :            :             OSL_FAIL("OControlWizard::getFormConnection: caught an exception!");
     478                 :            :         }
     479                 :          0 :         return xConn;
     480                 :            :     }
     481                 :            : 
     482                 :            :     //---------------------------------------------------------------------
     483                 :          0 :     void OControlWizard::setFormConnection( const OAccessRegulator& _rAccess, const Reference< XConnection >& _rxConn, sal_Bool _bAutoDispose )
     484                 :            :     {
     485                 :            :         try
     486                 :            :         {
     487                 :          0 :             Reference< XConnection > xOldConn = getFormConnection(_rAccess);
     488                 :          0 :             if (xOldConn.get() == _rxConn.get())
     489                 :          0 :                 return;
     490                 :            : 
     491                 :          0 :             disposeComponent(xOldConn);
     492                 :            : 
     493                 :            :             // set the new connection
     494                 :          0 :             if ( _bAutoDispose )
     495                 :            :             {
     496                 :            :                 // for this, use a AutoDisposer (so the conn is cleaned up when the form dies or get's another connection)
     497                 :          0 :                 Reference< XRowSet > xFormRowSet( m_aContext.xForm, UNO_QUERY );
     498                 :          0 :                 OAutoConnectionDisposer* pAutoDispose = new OAutoConnectionDisposer( xFormRowSet, _rxConn );
     499                 :          0 :                 Reference< XPropertyChangeListener > xEnsureDelete( pAutoDispose );
     500                 :            :             }
     501                 :            :             else
     502                 :            :             {
     503                 :          0 :                 m_aContext.xForm->setPropertyValue( ::rtl::OUString("ActiveConnection"), makeAny( _rxConn ) );
     504                 :          0 :             }
     505                 :            :         }
     506                 :          0 :         catch(const Exception&)
     507                 :            :         {
     508                 :            :             OSL_FAIL("OControlWizard::setFormConnection: caught an exception!");
     509                 :            :         }
     510                 :            :     }
     511                 :            : 
     512                 :            :     //---------------------------------------------------------------------
     513                 :          0 :     sal_Bool OControlWizard::updateContext(const OAccessRegulator&)
     514                 :            :     {
     515                 :          0 :         return initContext();
     516                 :            :     }
     517                 :            :     //---------------------------------------------------------------------
     518                 :          0 :     Reference< XInteractionHandler > OControlWizard::getInteractionHandler(Window* _pWindow) const
     519                 :            :     {
     520                 :          0 :         const ::rtl::OUString sInteractionHandlerServiceName("com.sun.star.task.InteractionHandler");
     521                 :          0 :         Reference< XInteractionHandler > xHandler;
     522                 :            :         try
     523                 :            :         {
     524                 :          0 :             if (getServiceFactory().is())
     525                 :          0 :                 xHandler = Reference< XInteractionHandler >(getServiceFactory()->createInstance(sInteractionHandlerServiceName), UNO_QUERY);
     526                 :            :         }
     527                 :          0 :         catch(const Exception&) { }
     528                 :          0 :         if (!xHandler.is())
     529                 :          0 :             ShowServiceNotAvailableError(_pWindow, sInteractionHandlerServiceName, sal_True);
     530                 :          0 :         return xHandler;
     531                 :            :     }
     532                 :            :     //---------------------------------------------------------------------
     533                 :          0 :     sal_Bool OControlWizard::initContext()
     534                 :            :     {
     535                 :            :         DBG_ASSERT(m_aContext.xObjectModel.is(), "OGroupBoxWizard::initContext: have no control model to work with!");
     536                 :          0 :         if (!m_aContext.xObjectModel.is())
     537                 :          0 :             return sal_False;
     538                 :            : 
     539                 :            :         // reset the context
     540                 :          0 :         m_aContext.xForm.clear();
     541                 :          0 :         m_aContext.xRowSet.clear();
     542                 :          0 :         m_aContext.xDocumentModel.clear();
     543                 :          0 :         m_aContext.xDrawPage.clear();
     544                 :          0 :         m_aContext.xObjectShape.clear();
     545                 :          0 :         m_aContext.aFieldNames.realloc(0);
     546                 :            : 
     547                 :          0 :         m_aContext.xObjectContainer.clear();
     548                 :          0 :         m_aContext.aTypes.clear();
     549                 :          0 :         m_aContext.bEmbedded = sal_False;
     550                 :            : 
     551                 :          0 :         Any aSQLException;
     552                 :          0 :         Reference< XPreparedStatement >  xStatement;
     553                 :            :         try
     554                 :            :         {
     555                 :            :             // get the datasource context
     556                 :          0 :             implGetDSContext();
     557                 :            : 
     558                 :            :             // first, determine the form the control belongs to
     559                 :          0 :             implDetermineForm();
     560                 :            : 
     561                 :            :             // need the page, too
     562                 :          0 :             implDeterminePage();
     563                 :            : 
     564                 :            :             // the shape of the control
     565                 :          0 :             implDetermineShape();
     566                 :            : 
     567                 :            :             // get the columns of the object the settins refer to
     568                 :          0 :             Reference< XNameAccess >  xColumns;
     569                 :            : 
     570                 :          0 :             if (m_aContext.xForm.is())
     571                 :            :             {
     572                 :            :                 // collect some properties of the form
     573                 :          0 :                 ::rtl::OUString sObjectName = ::comphelper::getString(m_aContext.xForm->getPropertyValue(::rtl::OUString("Command")));
     574                 :          0 :                 sal_Int32 nObjectType = ::comphelper::getINT32(m_aContext.xForm->getPropertyValue(::rtl::OUString("CommandType")));
     575                 :            : 
     576                 :            :                 // calculate the connection the rowset is working with
     577                 :          0 :                 Reference< XConnection > xConnection;
     578                 :          0 :                 m_aContext.bEmbedded = ::dbtools::isEmbeddedInDatabase( m_aContext.xForm, xConnection );
     579                 :          0 :                 if ( !m_aContext.bEmbedded )
     580                 :          0 :                     xConnection = ::dbtools::connectRowset( m_aContext.xRowSet, getServiceFactory(), sal_True );
     581                 :            : 
     582                 :            :                 // get the fields
     583                 :          0 :                 if (xConnection.is())
     584                 :            :                 {
     585                 :          0 :                     switch (nObjectType)
     586                 :            :                     {
     587                 :            :                         case 0:
     588                 :            :                         {
     589                 :          0 :                             Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
     590                 :          0 :                             if (xSupplyTables.is() && xSupplyTables->getTables().is() && xSupplyTables->getTables()->hasByName(sObjectName))
     591                 :            :                             {
     592                 :          0 :                                 Reference< XColumnsSupplier >  xSupplyColumns;
     593                 :          0 :                                 m_aContext.xObjectContainer = xSupplyTables->getTables();
     594                 :          0 :                                 m_aContext.xObjectContainer->getByName(sObjectName) >>= xSupplyColumns;
     595                 :            :                                 DBG_ASSERT(xSupplyColumns.is(), "OControlWizard::initContext: invalid table columns!");
     596                 :          0 :                                 xColumns = xSupplyColumns->getColumns();
     597                 :          0 :                             }
     598                 :            :                         }
     599                 :          0 :                         break;
     600                 :            :                         case 1:
     601                 :            :                         {
     602                 :          0 :                             Reference< XQueriesSupplier >  xSupplyQueries(xConnection, UNO_QUERY);
     603                 :          0 :                             if (xSupplyQueries.is() && xSupplyQueries->getQueries().is() && xSupplyQueries->getQueries()->hasByName(sObjectName))
     604                 :            :                             {
     605                 :          0 :                                 Reference< XColumnsSupplier >  xSupplyColumns;
     606                 :          0 :                                 m_aContext.xObjectContainer = xSupplyQueries->getQueries();
     607                 :          0 :                                 m_aContext.xObjectContainer->getByName(sObjectName) >>= xSupplyColumns;
     608                 :            :                                 DBG_ASSERT(xSupplyColumns.is(), "OControlWizard::initContext: invalid query columns!");
     609                 :          0 :                                 xColumns  = xSupplyColumns->getColumns();
     610                 :          0 :                             }
     611                 :            :                         }
     612                 :          0 :                         break;
     613                 :            :                         default:
     614                 :            :                         {
     615                 :          0 :                             xStatement = xConnection->prepareStatement(sObjectName);
     616                 :            : 
     617                 :            :                             // not interested in any results, only in the fields
     618                 :          0 :                             Reference< XPropertySet > xStatementProps(xStatement, UNO_QUERY);
     619                 :          0 :                             xStatementProps->setPropertyValue(::rtl::OUString("MaxRows"), makeAny(sal_Int32(0)));
     620                 :            : 
     621                 :            :                             // TODO: think about handling local SQLExceptions here ...
     622                 :          0 :                             Reference< XColumnsSupplier >  xSupplyCols(xStatement->executeQuery(), UNO_QUERY);
     623                 :          0 :                             if (xSupplyCols.is())
     624                 :          0 :                                 xColumns = xSupplyCols->getColumns();
     625                 :            :                         }
     626                 :            :                     }
     627                 :          0 :                 }
     628                 :            :             }
     629                 :            : 
     630                 :          0 :             if (xColumns.is())
     631                 :            :             {
     632                 :          0 :                 m_aContext.aFieldNames = xColumns->getElementNames();
     633                 :          0 :                 static const ::rtl::OUString s_sFieldTypeProperty("Type");
     634                 :          0 :                 const ::rtl::OUString* pBegin = m_aContext.aFieldNames.getConstArray();
     635                 :          0 :                 const ::rtl::OUString* pEnd   = pBegin + m_aContext.aFieldNames.getLength();
     636                 :          0 :                 for(;pBegin != pEnd;++pBegin)
     637                 :            :                 {
     638                 :          0 :                     sal_Int32 nFieldType = DataType::OTHER;
     639                 :            :                     try
     640                 :            :                     {
     641                 :          0 :                         Reference< XPropertySet > xColumn;
     642                 :          0 :                         xColumns->getByName(*pBegin) >>= xColumn;
     643                 :          0 :                         xColumn->getPropertyValue(s_sFieldTypeProperty) >>= nFieldType;
     644                 :            :                     }
     645                 :          0 :                     catch(const Exception&)
     646                 :            :                     {
     647                 :            :                         OSL_FAIL("OControlWizard::initContext: unexpected exception while gathering column information!");
     648                 :            :                     }
     649                 :          0 :                     m_aContext.aTypes.insert(OControlWizardContext::TNameTypeMap::value_type(*pBegin,nFieldType));
     650                 :            :                 }
     651                 :          0 :             }
     652                 :            :         }
     653                 :          0 :         catch(const SQLContext& e) { aSQLException <<= e; }
     654                 :          0 :         catch(const SQLWarning& e) { aSQLException <<= e; }
     655                 :          0 :         catch(const SQLException& e) { aSQLException <<= e; }
     656                 :          0 :         catch(const Exception&)
     657                 :            :         {
     658                 :            :             OSL_FAIL("OControlWizard::initContext: could not retrieve the control context (caught an exception)!");
     659                 :            :         }
     660                 :            : 
     661                 :          0 :         ::comphelper::disposeComponent(xStatement);
     662                 :            : 
     663                 :          0 :         if (aSQLException.hasValue())
     664                 :            :         {   // an SQLException (or derivee) was thrown ...
     665                 :            : 
     666                 :            :             // prepend an extra SQLContext explaining what we were doing
     667                 :          0 :             SQLContext aContext;
     668                 :          0 :             aContext.Message = String(ModuleRes(RID_STR_COULDNOTOPENTABLE));
     669                 :          0 :             aContext.NextException = aSQLException;
     670                 :            : 
     671                 :            :             // create an interaction handler to display this exception
     672                 :          0 :             Reference< XInteractionHandler > xHandler = getInteractionHandler(this);
     673                 :          0 :             if ( !xHandler.is() )
     674                 :          0 :                 return sal_False;
     675                 :            : 
     676                 :          0 :             Reference< XInteractionRequest > xRequest = new OInteractionRequest(makeAny(aContext));
     677                 :            :             try
     678                 :            :             {
     679                 :          0 :                 xHandler->handle(xRequest);
     680                 :            :             }
     681                 :          0 :             catch(const Exception&) { }
     682                 :          0 :             return sal_False;
     683                 :            :         }
     684                 :            : 
     685                 :          0 :         return 0 != m_aContext.aFieldNames.getLength();
     686                 :            :     }
     687                 :            : 
     688                 :            :     //---------------------------------------------------------------------
     689                 :          0 :     void OControlWizard::commitControlSettings(OControlWizardSettings* _pSettings)
     690                 :            :     {
     691                 :            :         DBG_ASSERT(m_aContext.xObjectModel.is(), "OControlWizard::commitControlSettings: have no control model to work with!");
     692                 :          0 :         if (!m_aContext.xObjectModel.is())
     693                 :          0 :             return;
     694                 :            : 
     695                 :            :         // the only thing we have at the moment is the label
     696                 :            :         try
     697                 :            :         {
     698                 :          0 :             ::rtl::OUString sLabelPropertyName("Label");
     699                 :          0 :             Reference< XPropertySetInfo > xInfo = m_aContext.xObjectModel->getPropertySetInfo();
     700                 :          0 :             if (xInfo.is() && xInfo->hasPropertyByName(sLabelPropertyName))
     701                 :            :             {
     702                 :          0 :                 ::rtl::OUString sControlLabel(_pSettings->sControlLabel);
     703                 :          0 :                 m_aContext.xObjectModel->setPropertyValue(
     704                 :            :                     ::rtl::OUString("Label"),
     705                 :            :                     makeAny(sControlLabel)
     706                 :          0 :                 );
     707                 :          0 :             }
     708                 :            :         }
     709                 :          0 :         catch(const Exception&)
     710                 :            :         {
     711                 :            :             OSL_FAIL("OControlWizard::commitControlSettings: could not commit the basic control settings!");
     712                 :            :         }
     713                 :            :     }
     714                 :            : 
     715                 :            :     //---------------------------------------------------------------------
     716                 :          0 :     void OControlWizard::initControlSettings(OControlWizardSettings* _pSettings)
     717                 :            :     {
     718                 :            :         DBG_ASSERT(m_aContext.xObjectModel.is(), "OControlWizard::initControlSettings: have no control model to work with!");
     719                 :          0 :         if (!m_aContext.xObjectModel.is())
     720                 :          0 :             return;
     721                 :            : 
     722                 :            :         // initialize some settings from the control model give
     723                 :            :         try
     724                 :            :         {
     725                 :          0 :             ::rtl::OUString sLabelPropertyName("Label");
     726                 :          0 :             Reference< XPropertySetInfo > xInfo = m_aContext.xObjectModel->getPropertySetInfo();
     727                 :          0 :             if (xInfo.is() && xInfo->hasPropertyByName(sLabelPropertyName))
     728                 :            :             {
     729                 :          0 :                 ::rtl::OUString sControlLabel;
     730                 :          0 :                 m_aContext.xObjectModel->getPropertyValue(sLabelPropertyName) >>= sControlLabel;
     731                 :          0 :                 _pSettings->sControlLabel = sControlLabel;
     732                 :          0 :             }
     733                 :            :         }
     734                 :          0 :         catch(const Exception&)
     735                 :            :         {
     736                 :            :             OSL_FAIL("OControlWizard::initControlSettings: could not retrieve the basic control settings!");
     737                 :            :         }
     738                 :            :     }
     739                 :            : 
     740                 :            :     //---------------------------------------------------------------------
     741                 :          0 :     sal_Bool OControlWizard::needDatasourceSelection()
     742                 :            :     {
     743                 :            :         // lemme see ...
     744                 :          0 :         return (0 == getContext().aFieldNames.getLength());
     745                 :            :             // if we got fields, the data source is valid ...
     746                 :            :     }
     747                 :            : 
     748                 :            : //.........................................................................
     749                 :            : }   // namespace dbp
     750                 :            : //.........................................................................
     751                 :            : 
     752                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10