LCOV - code coverage report
Current view: top level - extensions/source/bibliography - datman.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 6 874 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 70 2.9 %
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 <osl/mutex.hxx>
      21             : #include <sal/log.hxx>
      22             : #include <tools/diagnose_ex.h>
      23             : #include <comphelper/processfactory.hxx>
      24             : #include <com/sun/star/io/XPersistObject.hpp>
      25             : #include <com/sun/star/sdbc/ResultSetType.hpp>
      26             : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
      27             : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
      28             : #include <com/sun/star/sdbcx/XRowLocate.hpp>
      29             : #include <com/sun/star/sdbc/DataType.hpp>
      30             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      31             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      32             : #include <com/sun/star/sdb/XDatabaseEnvironment.hpp>
      33             : #include <com/sun/star/uno/XNamingService.hpp>
      34             : #include <com/sun/star/sdbc/XDataSource.hpp>
      35             : #include <com/sun/star/sdb/CommandType.hpp>
      36             : #include <com/sun/star/sdb/DatabaseContext.hpp>
      37             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      38             : #include <com/sun/star/sdbc/XConnection.hpp>
      39             : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      40             : #include <com/sun/star/task/InteractionHandler.hpp>
      41             : #include <com/sun/star/form/ListSourceType.hpp>
      42             : #include <com/sun/star/form/XLoadable.hpp>
      43             : #include <com/sun/star/form/runtime/FormController.hpp>
      44             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      45             : #include <com/sun/star/form/XGridColumnFactory.hpp>
      46             : #include <com/sun/star/io/XDataInputStream.hpp>
      47             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      48             : #include <com/sun/star/container/XNameContainer.hpp>
      49             : #include <comphelper/container.hxx>
      50             : #include <svl/urihelper.hxx>
      51             : #include <svtools/svtabbx.hxx>
      52             : #include <svtools/headbar.hxx>
      53             : #include <vcl/dialog.hxx>
      54             : #include <vcl/button.hxx>
      55             : #include <vcl/fixed.hxx>
      56             : #include <vcl/group.hxx>
      57             : #include <vcl/lstbox.hxx>
      58             : #include <vcl/edit.hxx>
      59             : #include <vcl/msgbox.hxx>
      60             : #include <tools/debug.hxx>
      61             : #include "datman.hxx"
      62             : #include "bibresid.hxx"
      63             : #include "bibmod.hxx"
      64             : #include "bibview.hxx"
      65             : #include "bibprop.hrc"
      66             : #include "toolbar.hxx"
      67             : #include "toolbar.hrc"
      68             : #include "bibconfig.hxx"
      69             : #include "bibbeam.hxx"
      70             : #include "general.hxx"
      71             : #include "bib.hrc"
      72             : #include "bibliography.hrc"
      73             : #include <connectivity/dbtools.hxx>
      74             : #include <boost/scoped_ptr.hpp>
      75             : 
      76             : using namespace ::com::sun::star;
      77             : using namespace ::com::sun::star::beans;
      78             : using namespace ::com::sun::star::container;
      79             : using namespace ::com::sun::star::uno;
      80             : using namespace ::com::sun::star::sdb;
      81             : using namespace ::com::sun::star::sdbc;
      82             : using namespace ::com::sun::star::sdbcx;
      83             : using namespace ::com::sun::star::form;
      84             : using namespace ::com::sun::star::frame;
      85             : using namespace ::com::sun::star::lang;
      86             : 
      87           0 : Reference< XConnection > getConnection(const OUString& _rURL)
      88             : {
      89             :     // first get the sdb::DataSource corresponding to the url
      90           0 :     Reference< XDataSource >    xDataSource;
      91             :     // is it a favorite title ?
      92           0 :     Reference<XComponentContext>  xContext = comphelper::getProcessComponentContext();
      93           0 :     Reference< XDatabaseContext >  xNamingContext = DatabaseContext::create(xContext);
      94           0 :     if (xNamingContext->hasByName(_rURL))
      95             :     {
      96             :         DBG_ASSERT(xNamingContext.is(), "::getDataSource : no NamingService interface on the sdb::DatabaseAccessContext !");
      97             :         try
      98             :         {
      99           0 :             xDataSource = Reference< XDataSource > (xNamingContext->getRegisteredObject(_rURL), UNO_QUERY);
     100             :         }
     101           0 :         catch (const Exception&)
     102             :         {
     103             :             OSL_FAIL("Exception caught in ODatabaseContext::getRegisteredObject()");
     104             :         }
     105             :     }
     106             :     // build the connection from the data source
     107           0 :     Reference< XConnection > xConn;
     108           0 :     if (xDataSource.is())
     109             :     {
     110             :         // need user/pwd for this
     111           0 :         Reference< XPropertySet >  xDataSourceProps(xDataSource, UNO_QUERY);
     112           0 :         Reference< XCompletedConnection > xComplConn(xDataSource, UNO_QUERY);
     113             :         try
     114             :         {
     115           0 :             Reference<task::XInteractionHandler> xIHdl( task::InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW);
     116           0 :             xConn = xComplConn->connectWithCompletion(xIHdl);
     117             :         }
     118           0 :         catch (const SQLException&)
     119             :         {
     120             :             // TODO : a real error handling
     121             :         }
     122           0 :         catch (const Exception&)
     123             :         {
     124           0 :         }
     125             :     }
     126           0 :     return xConn;
     127             : }
     128             : 
     129           0 : Reference< XConnection >    getConnection(const Reference< XInterface > & xRowSet)
     130             : {
     131           0 :     Reference< XConnection >    xConn;
     132             :     try
     133             :     {
     134           0 :         Reference< XPropertySet >  xFormProps(xRowSet, UNO_QUERY);
     135           0 :         if (!xFormProps.is())
     136           0 :             return xConn;
     137             : 
     138           0 :         xConn = Reference< XConnection > (*static_cast<Reference< XInterface > const *>(xFormProps->getPropertyValue("ActiveConnection").getValue()), UNO_QUERY);
     139           0 :         if (!xConn.is())
     140             :         {
     141             :             DBG_WARNING("no active connection");
     142           0 :         }
     143             :     }
     144           0 :     catch (const Exception&)
     145             :     {
     146             :         OSL_FAIL("exception in getConnection");
     147             :     }
     148             : 
     149           0 :     return xConn;
     150             : }
     151             : 
     152           0 : Reference< XNameAccess >  getColumns(const Reference< XForm > & _rxForm)
     153             : {
     154           0 :     Reference< XNameAccess >  xReturn;
     155             :     // check if the form is alive
     156           0 :     Reference< XColumnsSupplier >  xSupplyCols( _rxForm, UNO_QUERY );
     157           0 :     if (xSupplyCols.is())
     158           0 :         xReturn = xSupplyCols->getColumns();
     159             : 
     160           0 :     if (!xReturn.is() || (xReturn->getElementNames().getLength() == 0))
     161             :     {   // no ....
     162           0 :         xReturn = NULL;
     163             :         // -> get the table the form is bound to and ask it for their columns
     164           0 :         Reference< XTablesSupplier >  xSupplyTables( getConnection( _rxForm ), UNO_QUERY );
     165           0 :         Reference< XPropertySet >  xFormProps( _rxForm, UNO_QUERY );
     166           0 :         if (xFormProps.is() && xSupplyTables.is())
     167             :         {
     168             :             try
     169             :             {
     170             :                 DBG_ASSERT((*static_cast<sal_Int32 const *>(xFormProps->getPropertyValue("CommandType").getValue())) == CommandType::TABLE,
     171             :                     "::getColumns : invalid form (has no table as data source) !");
     172           0 :                 OUString sTable;
     173           0 :                 xFormProps->getPropertyValue("Command") >>= sTable;
     174           0 :                 Reference< XNameAccess >  xTables = xSupplyTables->getTables();
     175           0 :                 if (xTables.is() && xTables->hasByName(sTable))
     176           0 :                     xSupplyCols = Reference< XColumnsSupplier > (
     177           0 :                         *static_cast<Reference< XInterface > const *>(xTables->getByName(sTable).getValue()), UNO_QUERY);
     178           0 :                 if (xSupplyCols.is())
     179           0 :                     xReturn = xSupplyCols->getColumns();
     180             :             }
     181           0 :             catch (const Exception& e)
     182             :             {
     183             : #ifdef DBG_UTIL
     184             :                 OUString sMsg( "::getColumns : catched an exception (" + e.Message + ") ..." );
     185             : 
     186             :                 OSL_FAIL(OUStringToOString(sMsg, RTL_TEXTENCODING_ASCII_US ).getStr());
     187             : #else
     188             :                 (void)e;
     189             : #endif
     190             :             }
     191             : 
     192           0 :         }
     193             :     }
     194           0 :     return xReturn;
     195             : }
     196             : 
     197             : class MappingDialog_Impl : public ModalDialog
     198             : {
     199             :     BibDataManager* pDatMan;
     200             :     VclPtr<OKButton>       pOKBT;
     201             :     VclPtr<ListBox>        pIdentifierLB;
     202             :     VclPtr<ListBox>        pAuthorityTypeLB;
     203             :     VclPtr<ListBox>        pAuthorLB;
     204             :     VclPtr<ListBox>        pTitleLB;
     205             :     VclPtr<ListBox>        pMonthLB;
     206             :     VclPtr<ListBox>        pYearLB;
     207             :     VclPtr<ListBox>        pISBNLB;
     208             :     VclPtr<ListBox>        pBooktitleLB;
     209             :     VclPtr<ListBox>        pChapterLB;
     210             :     VclPtr<ListBox>        pEditionLB;
     211             :     VclPtr<ListBox>        pEditorLB;
     212             :     VclPtr<ListBox>        pHowpublishedLB;
     213             :     VclPtr<ListBox>        pInstitutionLB;
     214             :     VclPtr<ListBox>        pJournalLB;
     215             :     VclPtr<ListBox>        pNoteLB;
     216             :     VclPtr<ListBox>        pAnnoteLB;
     217             :     VclPtr<ListBox>        pNumberLB;
     218             :     VclPtr<ListBox>        pOrganizationsLB;
     219             :     VclPtr<ListBox>        pPagesLB;
     220             :     VclPtr<ListBox>        pPublisherLB;
     221             :     VclPtr<ListBox>        pAddressLB;
     222             :     VclPtr<ListBox>        pSchoolLB;
     223             :     VclPtr<ListBox>        pSeriesLB;
     224             :     VclPtr<ListBox>        pReportTypeLB;
     225             :     VclPtr<ListBox>        pVolumeLB;
     226             :     VclPtr<ListBox>        pURLLB;
     227             :     VclPtr<ListBox>        pCustom1LB;
     228             :     VclPtr<ListBox>        pCustom2LB;
     229             :     VclPtr<ListBox>        pCustom3LB;
     230             :     VclPtr<ListBox>        pCustom4LB;
     231             :     VclPtr<ListBox>        pCustom5LB;
     232             :     VclPtr<ListBox>        aListBoxes[COLUMN_COUNT];
     233             :     OUString        sNone;
     234             : 
     235             :     bool        bModified;
     236             : 
     237             : 
     238             : 
     239             :     DECL_LINK(OkHdl, void *);
     240             :     DECL_LINK(ListBoxSelectHdl, ListBox*);
     241             : 
     242             : public:
     243             :     MappingDialog_Impl(vcl::Window* pParent, BibDataManager* pDatMan);
     244             :     virtual ~MappingDialog_Impl();
     245             :     virtual void dispose() SAL_OVERRIDE;
     246             : 
     247           0 :     void    SetModified() {bModified = true;}
     248             : 
     249             : };
     250             : 
     251           0 : static sal_uInt16 lcl_FindLogicalName(BibConfig* pConfig ,
     252             :                                     const OUString& rLogicalColumnName)
     253             : {
     254           0 :     for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
     255             :     {
     256           0 :         if(rLogicalColumnName == pConfig->GetDefColumnName(i))
     257           0 :             return i;
     258             :     }
     259           0 :     return USHRT_MAX;
     260             : }
     261             : 
     262           0 : MappingDialog_Impl::MappingDialog_Impl(vcl::Window* pParent, BibDataManager* pMan)
     263             :     : ModalDialog(pParent, "MappingDialog", "modules/sbibliography/ui/mappingdialog.ui")
     264             :     , pDatMan(pMan)
     265             :     , sNone(BIB_RESSTR(RID_BIB_STR_NONE))
     266           0 :     , bModified(false)
     267             : {
     268           0 :     get(pOKBT, "ok");
     269           0 :     get(pIdentifierLB, "identifierCombobox");
     270           0 :     get(pAuthorityTypeLB, "authorityTypeCombobox");
     271           0 :     get(pAuthorLB, "authorCombobox");
     272           0 :     get(pTitleLB, "titleCombobox");
     273           0 :     get(pMonthLB, "monthCombobox");
     274           0 :     get(pYearLB, "yearCombobox");
     275           0 :     get(pISBNLB, "ISBNCombobox");
     276           0 :     get(pBooktitleLB, "bookTitleCombobox");
     277           0 :     get(pChapterLB, "chapterCombobox");
     278           0 :     get(pEditionLB, "editionCombobox");
     279           0 :     get(pEditorLB, "editorCombobox");
     280           0 :     get(pHowpublishedLB, "howPublishedCombobox");
     281           0 :     get(pInstitutionLB, "institutionCombobox");
     282           0 :     get(pJournalLB, "journalCombobox");
     283           0 :     get(pNoteLB, "noteCombobox");
     284           0 :     get(pAnnoteLB, "annoteCombobox");
     285           0 :     get(pNumberLB, "numberCombobox");
     286           0 :     get(pOrganizationsLB, "organizationCombobox");
     287           0 :     get(pPagesLB, "pagesCombobox");
     288           0 :     get(pPublisherLB, "publisherCombobox");
     289           0 :     get(pAddressLB, "addressCombobox");
     290           0 :     get(pSchoolLB, "schoolCombobox");
     291           0 :     get(pSeriesLB, "seriesCombobox");
     292           0 :     get(pReportTypeLB, "reportTypeCombobox");
     293           0 :     get(pVolumeLB, "volumeCombobox");
     294           0 :     get(pURLLB, "URLCombobox");
     295           0 :     get(pCustom1LB, "custom1Combobox");
     296           0 :     get(pCustom2LB, "custom2Combobox");
     297           0 :     get(pCustom3LB, "custom3Combobox");
     298           0 :     get(pCustom4LB, "custom4Combobox");
     299           0 :     get(pCustom5LB, "custom5Combobox");
     300             : 
     301           0 :     pOKBT->SetClickHdl(LINK(this, MappingDialog_Impl, OkHdl));
     302           0 :     OUString sTitle = GetText();
     303           0 :     sTitle = sTitle.replaceFirst("%1", pDatMan->getActiveDataTable());
     304           0 :     SetText(sTitle);
     305             : 
     306           0 :     aListBoxes[0] = pIdentifierLB;
     307           0 :     aListBoxes[1] = pAuthorityTypeLB;
     308           0 :     aListBoxes[2] = pAuthorLB;
     309           0 :     aListBoxes[3] = pTitleLB;
     310           0 :     aListBoxes[4] = pYearLB;
     311           0 :     aListBoxes[5] = pISBNLB;
     312           0 :     aListBoxes[6] = pBooktitleLB;
     313           0 :     aListBoxes[7] = pChapterLB;
     314           0 :     aListBoxes[8] = pEditionLB;
     315           0 :     aListBoxes[9] = pEditorLB;
     316           0 :     aListBoxes[10] = pHowpublishedLB;
     317           0 :     aListBoxes[11] = pInstitutionLB;
     318           0 :     aListBoxes[12] = pJournalLB;
     319           0 :     aListBoxes[13] = pMonthLB;
     320           0 :     aListBoxes[14] = pNoteLB;
     321           0 :     aListBoxes[15] = pAnnoteLB;
     322           0 :     aListBoxes[16] = pNumberLB;
     323           0 :     aListBoxes[17] = pOrganizationsLB;
     324           0 :     aListBoxes[18] = pPagesLB;
     325           0 :     aListBoxes[19] = pPublisherLB;
     326           0 :     aListBoxes[20] = pAddressLB;
     327           0 :     aListBoxes[21] = pSchoolLB;
     328           0 :     aListBoxes[22] = pSeriesLB;
     329           0 :     aListBoxes[23] = pReportTypeLB;
     330           0 :     aListBoxes[24] = pVolumeLB;
     331           0 :     aListBoxes[25] = pURLLB;
     332           0 :     aListBoxes[26] = pCustom1LB;
     333           0 :     aListBoxes[27] = pCustom2LB;
     334           0 :     aListBoxes[28] = pCustom3LB;
     335           0 :     aListBoxes[29] = pCustom4LB;
     336           0 :     aListBoxes[30] = pCustom5LB;
     337             : 
     338           0 :     aListBoxes[0]->InsertEntry(sNone);
     339           0 :     Reference< XNameAccess >  xFields = getColumns( pDatMan->getForm() );
     340             :     DBG_ASSERT(xFields.is(), "MappingDialog_Impl::MappingDialog_Impl : gave me an invalid form !");
     341           0 :     if(xFields.is())
     342             :     {
     343           0 :         Sequence< OUString > aNames = xFields->getElementNames();
     344           0 :         sal_Int32 nFieldsCount = aNames.getLength();
     345           0 :         const OUString* pNames = aNames.getConstArray();
     346             : 
     347           0 :         for(sal_Int32 nField = 0; nField < nFieldsCount; nField++)
     348           0 :             aListBoxes[0]->InsertEntry(pNames[nField]);
     349             :     }
     350             : 
     351           0 :     Link<> aLnk = LINK(this, MappingDialog_Impl, ListBoxSelectHdl);
     352             : 
     353           0 :     aListBoxes[0]->SelectEntryPos(0);
     354           0 :     aListBoxes[0]->SetSelectHdl(aLnk);
     355           0 :     for(sal_uInt16 i = 1; i < COLUMN_COUNT; i++)
     356             :     {
     357           0 :         for(sal_Int32 j = 0; j < aListBoxes[0]->GetEntryCount();j++)
     358           0 :             aListBoxes[i]->InsertEntry(aListBoxes[0]->GetEntry(j));
     359           0 :         aListBoxes[i]->SelectEntryPos(0);
     360           0 :         aListBoxes[i]->SetSelectHdl(aLnk);
     361             :     }
     362           0 :     BibConfig* pConfig = BibModul::GetConfig();
     363           0 :     BibDBDescriptor aDesc;
     364           0 :     aDesc.sDataSource = pDatMan->getActiveDataSource();
     365           0 :     aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
     366           0 :     aDesc.nCommandType = CommandType::TABLE;
     367           0 :     const Mapping* pMapping = pConfig->GetMapping(aDesc);
     368           0 :     if(pMapping)
     369             :     {
     370           0 :         for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
     371             :         {
     372           0 :             sal_uInt16 nListBoxIndex = lcl_FindLogicalName( pConfig, pMapping->aColumnPairs[nEntry].sLogicalColumnName);
     373           0 :             if(nListBoxIndex < COLUMN_COUNT)
     374             :             {
     375           0 :                 aListBoxes[nListBoxIndex]->SelectEntry(pMapping->aColumnPairs[nEntry].sRealColumnName);
     376             :             }
     377             :         }
     378           0 :     }
     379           0 : }
     380             : 
     381           0 : MappingDialog_Impl::~MappingDialog_Impl()
     382             : {
     383           0 :     disposeOnce();
     384           0 : }
     385             : 
     386           0 : void MappingDialog_Impl::dispose()
     387             : {
     388           0 :     pOKBT.clear();
     389           0 :     pIdentifierLB.clear();
     390           0 :     pAuthorityTypeLB.clear();
     391           0 :     pAuthorLB.clear();
     392           0 :     pTitleLB.clear();
     393           0 :     pMonthLB.clear();
     394           0 :     pYearLB.clear();
     395           0 :     pISBNLB.clear();
     396           0 :     pBooktitleLB.clear();
     397           0 :     pChapterLB.clear();
     398           0 :     pEditionLB.clear();
     399           0 :     pEditorLB.clear();
     400           0 :     pHowpublishedLB.clear();
     401           0 :     pInstitutionLB.clear();
     402           0 :     pJournalLB.clear();
     403           0 :     pNoteLB.clear();
     404           0 :     pAnnoteLB.clear();
     405           0 :     pNumberLB.clear();
     406           0 :     pOrganizationsLB.clear();
     407           0 :     pPagesLB.clear();
     408           0 :     pPublisherLB.clear();
     409           0 :     pAddressLB.clear();
     410           0 :     pSchoolLB.clear();
     411           0 :     pSeriesLB.clear();
     412           0 :     pReportTypeLB.clear();
     413           0 :     pVolumeLB.clear();
     414           0 :     pURLLB.clear();
     415           0 :     pCustom1LB.clear();
     416           0 :     pCustom2LB.clear();
     417           0 :     pCustom3LB.clear();
     418           0 :     pCustom4LB.clear();
     419           0 :     pCustom5LB.clear();
     420           0 :     for(auto & a : aListBoxes)
     421           0 :         a.clear();
     422           0 :     ModalDialog::dispose();
     423           0 : }
     424             : 
     425           0 : IMPL_LINK(MappingDialog_Impl, ListBoxSelectHdl, ListBox*, pListBox)
     426             : {
     427           0 :     sal_uInt16 nEntryPos = pListBox->GetSelectEntryPos();
     428           0 :     if(0 < nEntryPos)
     429             :     {
     430           0 :         for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
     431             :         {
     432           0 :             if(pListBox != aListBoxes[i] && aListBoxes[i]->GetSelectEntryPos() == nEntryPos)
     433           0 :                 aListBoxes[i]->SelectEntryPos(0);
     434             :         }
     435             :     }
     436           0 :     SetModified();
     437           0 :     return 0;
     438             : }
     439             : 
     440           0 : IMPL_LINK_NOARG(MappingDialog_Impl, OkHdl)
     441             : {
     442           0 :     if(bModified)
     443             :     {
     444           0 :         Mapping aNew;
     445           0 :         aNew.sTableName = pDatMan->getActiveDataTable();
     446           0 :         aNew.sURL = pDatMan->getActiveDataSource();
     447             : 
     448           0 :         sal_uInt16 nWriteIndex = 0;
     449           0 :         BibConfig* pConfig = BibModul::GetConfig();
     450           0 :         for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
     451             :         {
     452           0 :             OUString sSel = aListBoxes[nEntry]->GetSelectEntry();
     453           0 :             if(sSel != sNone)
     454             :             {
     455           0 :                 aNew.aColumnPairs[nWriteIndex].sRealColumnName = sSel;
     456           0 :                 aNew.aColumnPairs[nWriteIndex].sLogicalColumnName = pConfig->GetDefColumnName(nEntry);
     457           0 :                 nWriteIndex++;
     458             :             }
     459           0 :         }
     460           0 :         BibDBDescriptor aDesc;
     461           0 :         aDesc.sDataSource = pDatMan->getActiveDataSource();
     462           0 :         aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
     463           0 :         aDesc.nCommandType = CommandType::TABLE;
     464           0 :         pDatMan->ResetIdentifierMapping();
     465           0 :         pConfig->SetMapping(aDesc, &aNew);
     466             :     }
     467           0 :     EndDialog(bModified ? RET_OK : RET_CANCEL);
     468           0 :     return 0;
     469             : }
     470             : 
     471             : class DBChangeDialog_Impl : public ModalDialog
     472             : {
     473             :     VclPtr<ListBox>    m_pSelectionLB;
     474             :     DBChangeDialogConfig_Impl   aConfig;
     475             : 
     476             :     BibDataManager* pDatMan;
     477             : 
     478             :     DECL_LINK(DoubleClickHdl, SvTabListBox*);
     479             : public:
     480             :     DBChangeDialog_Impl(vcl::Window* pParent, BibDataManager* pMan );
     481             :     virtual ~DBChangeDialog_Impl();
     482             :     virtual void dispose() SAL_OVERRIDE;
     483             : 
     484             :     OUString     GetCurrentURL()const;
     485             : };
     486             : 
     487           0 : DBChangeDialog_Impl::DBChangeDialog_Impl(vcl::Window* pParent, BibDataManager* pMan )
     488             :     : ModalDialog(pParent, "ChooseDataSourceDialog",
     489             :         "modules/sbibliography/ui/choosedatasourcedialog.ui")
     490             :     ,
     491           0 :     pDatMan(pMan)
     492             : {
     493           0 :     get(m_pSelectionLB, "treeview");
     494           0 :     m_pSelectionLB->set_height_request(m_pSelectionLB->GetTextHeight() * 6);
     495             : 
     496           0 :     m_pSelectionLB->SetStyle(m_pSelectionLB->GetStyle() | WB_SORT);
     497           0 :     m_pSelectionLB->SetDoubleClickHdl( LINK(this, DBChangeDialog_Impl, DoubleClickHdl));
     498             : 
     499             :     try
     500             :     {
     501           0 :         OUString sActiveSource = pDatMan->getActiveDataSource();
     502           0 :         const Sequence< OUString >& rSources = aConfig.GetDataSourceNames();
     503           0 :         const OUString* pSourceNames = rSources.getConstArray();
     504           0 :         for (sal_Int32 i = 0; i < rSources.getLength(); ++i)
     505           0 :             m_pSelectionLB->InsertEntry(pSourceNames[i]);
     506             : 
     507           0 :         m_pSelectionLB->SelectEntry(sActiveSource);
     508             :     }
     509           0 :     catch (const Exception& e)
     510             :     {
     511             :         SAL_WARN("extensions.biblio",
     512             :             "Exception in BibDataManager::DBChangeDialog_Impl::DBChangeDialog_Impl "
     513             :             << e.Message);
     514             :     }
     515           0 : }
     516             : 
     517           0 : IMPL_LINK(DBChangeDialog_Impl, DoubleClickHdl, SvTabListBox*, /*pLB*/)
     518             : {
     519           0 :     EndDialog(RET_OK);
     520           0 :     return 0;
     521             : }
     522             : 
     523           0 : DBChangeDialog_Impl::~DBChangeDialog_Impl()
     524             : {
     525           0 :     disposeOnce();
     526           0 : }
     527             : 
     528           0 : void DBChangeDialog_Impl::dispose()
     529             : {
     530           0 :     m_pSelectionLB.clear();
     531           0 :     ModalDialog::dispose();
     532           0 : }
     533             : 
     534           0 : OUString  DBChangeDialog_Impl::GetCurrentURL()const
     535             : {
     536           0 :     return m_pSelectionLB->GetSelectEntry();
     537             : }
     538             : 
     539             : // XDispatchProvider
     540           0 : BibInterceptorHelper::BibInterceptorHelper( ::bib::BibBeamer* pBibBeamer, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch)
     541             : {
     542           0 :     if( pBibBeamer )
     543             :     {
     544           0 :         xInterception = pBibBeamer->getDispatchProviderInterception();
     545           0 :         if( xInterception.is() )
     546           0 :             xInterception->registerDispatchProviderInterceptor( this );
     547             :     }
     548           0 :     if( xDispatch.is() )
     549           0 :         xFormDispatch = xDispatch;
     550           0 : }
     551             : 
     552           0 : BibInterceptorHelper::~BibInterceptorHelper( )
     553             : {
     554           0 : }
     555             : 
     556           0 : void BibInterceptorHelper::ReleaseInterceptor()
     557             : {
     558           0 :     if ( xInterception.is() )
     559           0 :         xInterception->releaseDispatchProviderInterceptor( this );
     560           0 :     xInterception.clear();
     561           0 : }
     562             : 
     563             : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL
     564           0 :     BibInterceptorHelper::queryDispatch( const ::com::sun::star::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     565             : {
     566           0 :     Reference< XDispatch > xReturn;
     567             : 
     568           0 :     OUString aCommand( aURL.Path );
     569           0 :     if ( aCommand == "FormSlots/ConfirmDeletion" )
     570           0 :         xReturn = xFormDispatch;
     571             :     else
     572           0 :         if ( xSlaveDispatchProvider.is() )
     573           0 :             xReturn = xSlaveDispatchProvider->queryDispatch( aURL, aTargetFrameName, nSearchFlags);
     574             : 
     575           0 :     return xReturn;
     576             : }
     577             : 
     578             : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL
     579           0 :     BibInterceptorHelper::queryDispatches( const ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     580             : {
     581           0 :     Sequence< Reference< XDispatch> > aReturn( aDescripts.getLength() );
     582           0 :     Reference< XDispatch >* pReturn = aReturn.getArray();
     583           0 :     const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
     584           0 :     for ( sal_Int32 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
     585             :     {
     586           0 :         *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
     587             :     }
     588           0 :     return aReturn;
     589             : }
     590             : 
     591             : // XDispatchProviderInterceptor
     592             : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL
     593           0 :     BibInterceptorHelper::getSlaveDispatchProvider(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     594             : {
     595           0 :     return xSlaveDispatchProvider;
     596             : }
     597             : 
     598           0 : void SAL_CALL BibInterceptorHelper::setSlaveDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewSlaveDispatchProvider ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     599             : {
     600           0 :     xSlaveDispatchProvider = xNewSlaveDispatchProvider;
     601           0 : }
     602             : 
     603             : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL
     604           0 :     BibInterceptorHelper::getMasterDispatchProvider(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     605             : {
     606           0 :     return xMasterDispatchProvider;
     607             : }
     608             : 
     609           0 : void SAL_CALL BibInterceptorHelper::setMasterDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewMasterDispatchProvider ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     610             : {
     611           0 :     xMasterDispatchProvider = xNewMasterDispatchProvider;
     612           0 : }
     613             : 
     614             : 
     615             : #define STR_UID "uid"
     616           2 : OUString gGridName("theGrid");
     617           2 : OUString gViewName("theView");
     618           2 : OUString gGlobalName("theGlobals");
     619           2 : OUString gBeamerSize("theBeamerSize");
     620           2 : OUString gViewSize("theViewSize");
     621             : 
     622           0 : BibDataManager::BibDataManager()
     623           0 :     :BibDataManager_Base( GetMutex() )
     624             :     ,m_pInterceptorHelper( NULL )
     625             :     ,m_aLoadListeners(m_aMutex)
     626             :     ,pBibView( NULL )
     627           0 :     ,pToolbar(0)
     628             : {
     629           0 : }
     630             : 
     631             : 
     632           0 : BibDataManager::~BibDataManager()
     633             : {
     634           0 :     Reference< XLoadable >      xLoad( m_xForm, UNO_QUERY );
     635           0 :     Reference< XPropertySet >   xPrSet( m_xForm, UNO_QUERY );
     636           0 :     Reference< XComponent >     xComp( m_xForm, UNO_QUERY );
     637           0 :     if ( m_xForm.is() )
     638             :     {
     639           0 :         Reference< XComponent >  xConnection;
     640           0 :         xPrSet->getPropertyValue("ActiveConnection") >>= xConnection;
     641           0 :         RemoveMeAsUidListener();
     642           0 :         if (xLoad.is())
     643           0 :             xLoad->unload();
     644           0 :         if (xComp.is())
     645           0 :             xComp->dispose();
     646           0 :         if(xConnection.is())
     647           0 :             xConnection->dispose();
     648           0 :         m_xForm = NULL;
     649             :     }
     650           0 :     if( m_pInterceptorHelper )
     651             :     {
     652           0 :         m_pInterceptorHelper->ReleaseInterceptor();
     653           0 :         m_pInterceptorHelper->release();
     654           0 :         m_pInterceptorHelper = NULL;
     655           0 :     }
     656           0 : }
     657             : 
     658           0 : void BibDataManager::InsertFields(const Reference< XFormComponent > & _rxGrid)
     659             : {
     660           0 :     if ( !_rxGrid.is() )
     661           0 :         return;
     662             : 
     663             :     try
     664             :     {
     665           0 :         Reference< XNameContainer > xColContainer( _rxGrid, UNO_QUERY );
     666             :         // remove the old fields
     667           0 :         if ( xColContainer->hasElements() )
     668             :         {
     669           0 :             Sequence< OUString > aNames = xColContainer->getElementNames();
     670           0 :             const OUString* pNames = aNames.getConstArray();
     671           0 :             const OUString* pNamesEnd = pNames + aNames.getLength();
     672           0 :             for ( ; pNames != pNamesEnd; ++pNames )
     673           0 :                 xColContainer->removeByName( *pNames );
     674             :         }
     675             : 
     676           0 :         Reference< XNameAccess >  xFields = getColumns( m_xForm );
     677           0 :         if (!xFields.is())
     678           0 :             return;
     679             : 
     680           0 :         Reference< XGridColumnFactory > xColFactory( _rxGrid, UNO_QUERY );
     681             : 
     682           0 :         Reference< XPropertySet >  xField;
     683             : 
     684           0 :         Sequence< OUString > aFields( xFields->getElementNames() );
     685           0 :         const OUString* pFields = aFields.getConstArray();
     686           0 :         const OUString* pFieldsEnd = pFields + aFields.getLength();
     687             : 
     688           0 :         for ( ; pFields != pFieldsEnd; ++pFields )
     689             :         {
     690           0 :             xFields->getByName( *pFields ) >>= xField;
     691             : 
     692           0 :             OUString sCurrentModelType;
     693           0 :             const OUString sType("Type");
     694           0 :             sal_Int32 nType = 0;
     695           0 :             bool bIsFormatted           = false;
     696           0 :             sal_Bool bFormattedIsNumeric    = sal_True;
     697           0 :             xField->getPropertyValue(sType) >>= nType;
     698           0 :             switch(nType)
     699             :             {
     700             :                 case DataType::BIT:
     701             :                 case DataType::BOOLEAN:
     702           0 :                     sCurrentModelType = "CheckBox";
     703           0 :                     break;
     704             : 
     705             :                 case DataType::BINARY:
     706             :                 case DataType::VARBINARY:
     707             :                 case DataType::LONGVARBINARY:
     708             :                 case DataType::BLOB:
     709           0 :                     sCurrentModelType = "TextField";
     710           0 :                     break;
     711             : 
     712             :                 case DataType::VARCHAR:
     713             :                 case DataType::LONGVARCHAR:
     714             :                 case DataType::CHAR:
     715             :                 case DataType::CLOB:
     716           0 :                     bFormattedIsNumeric = sal_False;
     717             :                     // _NO_ break !
     718             :                 default:
     719           0 :                     sCurrentModelType = "FormattedField";
     720           0 :                     bIsFormatted = true;
     721           0 :                     break;
     722             :             }
     723             : 
     724           0 :             Reference< XPropertySet >  xCurrentCol = xColFactory->createColumn(sCurrentModelType);
     725           0 :             if (bIsFormatted)
     726             :             {
     727           0 :                 OUString sFormatKey("FormatKey");
     728           0 :                 xCurrentCol->setPropertyValue(sFormatKey, xField->getPropertyValue(sFormatKey));
     729           0 :                 Any aFormatted(&bFormattedIsNumeric, cppu::UnoType<bool>::get());
     730           0 :                 xCurrentCol->setPropertyValue("TreatAsNumber", aFormatted);
     731             :             }
     732           0 :             Any aColName = makeAny( *pFields );
     733           0 :             xCurrentCol->setPropertyValue(FM_PROP_CONTROLSOURCE,    aColName);
     734           0 :             xCurrentCol->setPropertyValue(FM_PROP_LABEL, aColName);
     735             : 
     736           0 :             xColContainer->insertByName( *pFields, makeAny( xCurrentCol ) );
     737           0 :         }
     738             :     }
     739           0 :     catch (const Exception&)
     740             :     {
     741             :         OSL_FAIL("Exception in BibDataManager::InsertFields");
     742             :     }
     743             : }
     744             : 
     745           0 : Reference< awt::XControlModel > BibDataManager::updateGridModel()
     746             : {
     747           0 :     return updateGridModel( m_xForm );
     748             : }
     749             : 
     750           0 : Reference< awt::XControlModel > BibDataManager::updateGridModel(const Reference< XForm > & xDbForm)
     751             : {
     752             :     try
     753             :     {
     754           0 :         Reference< XPropertySet >  aFormPropSet( xDbForm, UNO_QUERY );
     755           0 :         OUString sName;
     756           0 :         aFormPropSet->getPropertyValue("Command") >>= sName;
     757             : 
     758           0 :         if ( !m_xGridModel.is() )
     759             :         {
     760           0 :             m_xGridModel = createGridModel( gGridName );
     761             : 
     762           0 :             Reference< XNameContainer >  xNameCont(xDbForm, UNO_QUERY);
     763           0 :             xNameCont->insertByName( sName, makeAny( m_xGridModel ) );
     764             :         }
     765             : 
     766             :         // insert the fields
     767           0 :         Reference< XFormComponent > xFormComp( m_xGridModel, UNO_QUERY );
     768           0 :         InsertFields( xFormComp );
     769             :     }
     770           0 :     catch (const Exception&)
     771             :     {
     772             :         OSL_FAIL("::updateGridModel: something went wrong !");
     773             :     }
     774             : 
     775           0 :     return m_xGridModel;
     776             : }
     777             : 
     778           0 : Reference< XForm >  BibDataManager::createDatabaseForm(BibDBDescriptor& rDesc)
     779             : {
     780           0 :     Reference< XForm >  xResult;
     781             :     try
     782             :     {
     783           0 :         Reference< XMultiServiceFactory >  xMgr = comphelper::getProcessServiceFactory();
     784           0 :         m_xForm = Reference< XForm > ( xMgr->createInstance( "com.sun.star.form.component.Form" ), UNO_QUERY );
     785             : 
     786           0 :         Reference< XPropertySet >  aPropertySet( m_xForm, UNO_QUERY );
     787             : 
     788           0 :         aDataSourceURL = rDesc.sDataSource;
     789           0 :         if(aPropertySet.is())
     790             :         {
     791           0 :             Any aVal;
     792           0 :             aVal <<= (sal_Int32)ResultSetType::SCROLL_INSENSITIVE;
     793           0 :             aPropertySet->setPropertyValue("ResultSetType",aVal );
     794           0 :             aVal <<= (sal_Int32)ResultSetConcurrency::READ_ONLY;
     795           0 :             aPropertySet->setPropertyValue("ResultSetConcurrency", aVal);
     796             : 
     797             :             //Caching for Performance
     798           0 :             aVal <<= (sal_Int32)50;
     799           0 :             aPropertySet->setPropertyValue("FetchSize", aVal);
     800             : 
     801           0 :             Reference< XConnection >    xConnection = getConnection(rDesc.sDataSource);
     802           0 :             aVal <<= xConnection;
     803           0 :             aPropertySet->setPropertyValue("ActiveConnection", aVal);
     804             : 
     805           0 :             Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
     806           0 :             Reference< XNameAccess >  xTables = xSupplyTables.is() ?
     807           0 :                                 xSupplyTables->getTables() : Reference< XNameAccess > ();
     808             : 
     809           0 :             Sequence< OUString > aTableNameSeq;
     810           0 :             if (xTables.is())
     811           0 :                 aTableNameSeq = xTables->getElementNames();
     812             : 
     813           0 :             if(aTableNameSeq.getLength() > 0)
     814             :             {
     815           0 :                 const OUString* pTableNames = aTableNameSeq.getConstArray();
     816           0 :                 if(!rDesc.sTableOrQuery.isEmpty())
     817           0 :                     aActiveDataTable = rDesc.sTableOrQuery;
     818             :                 else
     819             :                 {
     820           0 :                     rDesc.sTableOrQuery = aActiveDataTable = pTableNames[0];
     821           0 :                     rDesc.nCommandType = CommandType::TABLE;
     822             :                 }
     823             : 
     824           0 :                 aVal <<= aActiveDataTable;
     825           0 :                 aPropertySet->setPropertyValue("Command", aVal);
     826           0 :                 aVal <<= rDesc.nCommandType;
     827           0 :                 aPropertySet->setPropertyValue("CommandType", aVal);
     828             : 
     829             : 
     830           0 :                 Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
     831           0 :                 aQuoteChar = xMetaData->getIdentifierQuoteString();
     832             : 
     833           0 :                 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
     834           0 :                 if ( xFactory.is() )
     835           0 :                     m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
     836             : 
     837           0 :                 OUString aString("SELECT * FROM ");
     838             : 
     839           0 :                 OUString sCatalog, sSchema, sName;
     840           0 :                 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
     841           0 :                 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
     842             : 
     843           0 :                 m_xParser->setElementaryQuery(aString);
     844           0 :                 BibConfig* pConfig = BibModul::GetConfig();
     845           0 :                 pConfig->setQueryField(getQueryField());
     846           0 :                 startQueryWith(pConfig->getQueryText());
     847             : 
     848           0 :                 xResult = m_xForm;
     849           0 :             }
     850           0 :         }
     851             :     }
     852           0 :     catch (const Exception&)
     853             :     {
     854             :         OSL_FAIL("::createDatabaseForm: something went wrong !");
     855             :     }
     856             : 
     857           0 :     return xResult;
     858             : }
     859             : 
     860           0 : Sequence< OUString > BibDataManager::getDataSources()
     861             : {
     862           0 :     Sequence< OUString > aTableNameSeq;
     863             : 
     864             :     try
     865             :     {
     866           0 :         Reference< XTablesSupplier >  xSupplyTables( getConnection( m_xForm ), UNO_QUERY );
     867           0 :         Reference< XNameAccess >  xTables;
     868           0 :         if (xSupplyTables.is())
     869           0 :             xTables = xSupplyTables->getTables();
     870           0 :         if (xTables.is())
     871           0 :             aTableNameSeq = xTables->getElementNames();
     872             :     }
     873           0 :     catch (const Exception&)
     874             :     {
     875             :         OSL_FAIL("::getDataSources: something went wrong !");
     876             :     }
     877             : 
     878           0 :     return aTableNameSeq;
     879             : }
     880             : 
     881             : 
     882           0 : void BibDataManager::setFilter(const OUString& rQuery)
     883             : {
     884           0 :     if(!m_xParser.is())
     885           0 :         return;
     886             :     try
     887             :     {
     888           0 :         m_xParser->setFilter( rQuery );
     889           0 :         OUString aQuery = m_xParser->getFilter();
     890           0 :         Reference< XPropertySet >  xFormProps( m_xForm, UNO_QUERY_THROW );
     891           0 :         xFormProps->setPropertyValue( "Filter", makeAny( aQuery ) );
     892           0 :         xFormProps->setPropertyValue( "ApplyFilter", makeAny( sal_True ) );
     893           0 :         reload();
     894             :     }
     895           0 :     catch (const Exception&)
     896             :     {
     897             :         DBG_UNHANDLED_EXCEPTION();
     898             :     }
     899             : 
     900             : 
     901             : }
     902             : 
     903           0 : OUString BibDataManager::getFilter()
     904             : {
     905             : 
     906           0 :     OUString aQueryString;
     907             :     try
     908             :     {
     909           0 :         Reference< XPropertySet > xFormProps( m_xForm, UNO_QUERY_THROW );
     910           0 :         OSL_VERIFY( xFormProps->getPropertyValue( "Filter"  ) >>= aQueryString );
     911             :     }
     912           0 :     catch (const Exception&)
     913             :     {
     914             :         DBG_UNHANDLED_EXCEPTION();
     915             :     }
     916             : 
     917             : 
     918           0 :     return aQueryString;
     919             : 
     920             : }
     921             : 
     922           0 : Sequence< OUString > BibDataManager::getQueryFields()
     923             : {
     924           0 :     Sequence< OUString > aFieldSeq;
     925           0 :     Reference< XNameAccess >  xFields = getColumns( m_xForm );
     926           0 :     if (xFields.is())
     927           0 :         aFieldSeq = xFields->getElementNames();
     928           0 :     return aFieldSeq;
     929             : }
     930             : 
     931           0 : OUString BibDataManager::getQueryField()
     932             : {
     933           0 :     BibConfig* pConfig = BibModul::GetConfig();
     934           0 :     OUString aFieldString = pConfig->getQueryField();
     935           0 :     if(aFieldString.isEmpty())
     936             :     {
     937           0 :         Sequence< OUString > aSeq = getQueryFields();
     938           0 :         const OUString* pFields = aSeq.getConstArray();
     939           0 :         if(aSeq.getLength()>0)
     940             :         {
     941           0 :             aFieldString=pFields[0];
     942           0 :         }
     943             :     }
     944           0 :     return aFieldString;
     945             : }
     946             : 
     947           0 : void BibDataManager::startQueryWith(const OUString& rQuery)
     948             : {
     949           0 :     BibConfig* pConfig = BibModul::GetConfig();
     950           0 :     pConfig->setQueryText( rQuery );
     951             : 
     952           0 :     OUString aQueryString;
     953           0 :     if(!rQuery.isEmpty())
     954             :     {
     955           0 :         aQueryString=aQuoteChar;
     956           0 :         aQueryString+=getQueryField();
     957           0 :         aQueryString+=aQuoteChar;
     958           0 :         aQueryString+=" like '";
     959           0 :         OUString sQuery(rQuery);
     960           0 :         sQuery = sQuery.replaceAll("?","_");
     961           0 :         sQuery = sQuery.replaceAll("*","%");
     962           0 :         aQueryString += sQuery;
     963           0 :         aQueryString+="%'";
     964             :     }
     965           0 :     setFilter(aQueryString);
     966           0 : }
     967             : 
     968           0 : void BibDataManager::setActiveDataSource(const OUString& rURL)
     969             : {
     970           0 :     OUString sTmp(aDataSourceURL);
     971           0 :     aDataSourceURL = rURL;
     972             : 
     973           0 :     Reference< XPropertySet >  aPropertySet( m_xForm, UNO_QUERY );
     974           0 :     if(aPropertySet.is())
     975             :     {
     976           0 :         unload();
     977             : 
     978           0 :         Reference< XComponent >  xOldConnection;
     979           0 :         aPropertySet->getPropertyValue("ActiveConnection") >>= xOldConnection;
     980             : 
     981           0 :         Reference< XConnection >    xConnection = getConnection(rURL);
     982           0 :         if(!xConnection.is())
     983             :         {
     984           0 :             aDataSourceURL = sTmp;
     985           0 :             return;
     986             :         }
     987           0 :         Any aVal; aVal <<= xConnection;
     988           0 :         aPropertySet->setPropertyValue("ActiveConnection", aVal);
     989           0 :         Reference< XMultiServiceFactory >   xFactory(xConnection, UNO_QUERY);
     990           0 :         if ( xFactory.is() )
     991           0 :             m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
     992             : 
     993           0 :         if(xOldConnection.is())
     994           0 :             xOldConnection->dispose();
     995             : 
     996           0 :         Sequence< OUString > aTableNameSeq;
     997           0 :         Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
     998           0 :         if(xSupplyTables.is())
     999             :         {
    1000           0 :             Reference< XNameAccess >  xAccess = xSupplyTables->getTables();
    1001           0 :             aTableNameSeq = xAccess->getElementNames();
    1002             :         }
    1003           0 :         if(aTableNameSeq.getLength() > 0)
    1004             :         {
    1005           0 :             const OUString* pTableNames = aTableNameSeq.getConstArray();
    1006           0 :             aActiveDataTable = pTableNames[0];
    1007           0 :             aVal <<= aActiveDataTable;
    1008           0 :             aPropertySet->setPropertyValue("Command", aVal);
    1009           0 :             aPropertySet->setPropertyValue("CommandType", makeAny(CommandType::TABLE));
    1010             :             //Caching for Performance
    1011           0 :             aVal <<= (sal_Int32)50;
    1012           0 :             aPropertySet->setPropertyValue("FetchSize", aVal);
    1013           0 :             OUString aString("SELECT * FROM ");
    1014             :             // quote the table name which may contain catalog.schema.table
    1015           0 :             Reference<XDatabaseMetaData> xMetaData(xConnection->getMetaData(),UNO_QUERY);
    1016           0 :             aQuoteChar = xMetaData->getIdentifierQuoteString();
    1017             : 
    1018           0 :             OUString sCatalog, sSchema, sName;
    1019           0 :             ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
    1020           0 :             aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
    1021             : 
    1022           0 :             m_xParser->setElementaryQuery(aString);
    1023           0 :             BibConfig* pConfig = BibModul::GetConfig();
    1024           0 :             pConfig->setQueryField(getQueryField());
    1025           0 :             startQueryWith(pConfig->getQueryText());
    1026           0 :             setActiveDataTable(aActiveDataTable);
    1027             :         }
    1028           0 :         FeatureStateEvent aEvent;
    1029           0 :         util::URL aURL;
    1030           0 :         aEvent.IsEnabled  = sal_True;
    1031           0 :         aEvent.Requery    = sal_False;
    1032           0 :         aEvent.FeatureDescriptor = getActiveDataTable();
    1033             : 
    1034           0 :         aEvent.State = makeAny( getDataSources() );
    1035             : 
    1036           0 :         if(pToolbar)
    1037             :         {
    1038           0 :             aURL.Complete =".uno:Bib/source";
    1039           0 :             aEvent.FeatureURL = aURL;
    1040           0 :             pToolbar->statusChanged( aEvent );
    1041             :         }
    1042             : 
    1043           0 :         updateGridModel();
    1044           0 :         load();
    1045           0 :     }
    1046             : }
    1047             : 
    1048             : 
    1049           0 : void BibDataManager::setActiveDataTable(const OUString& rTable)
    1050             : {
    1051           0 :     ResetIdentifierMapping();
    1052             :     try
    1053             :     {
    1054           0 :         Reference< XPropertySet >  aPropertySet( m_xForm, UNO_QUERY );
    1055             : 
    1056           0 :         if(aPropertySet.is())
    1057             :         {
    1058           0 :             Reference< XConnection >    xConnection = getConnection( m_xForm );
    1059           0 :             Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
    1060           0 :             Reference< XNameAccess > xAccess = xSupplyTables->getTables();
    1061           0 :             Sequence< OUString > aTableNameSeq = xAccess->getElementNames();
    1062           0 :             sal_uInt32 nCount = aTableNameSeq.getLength();
    1063             : 
    1064           0 :             const OUString* pTableNames = aTableNameSeq.getConstArray();
    1065           0 :             const OUString* pTableNamesEnd = pTableNames + nCount;
    1066             : 
    1067           0 :             for ( ; pTableNames != pTableNamesEnd; ++pTableNames )
    1068             :             {
    1069           0 :                 if ( rTable == *pTableNames )
    1070             :                 {
    1071           0 :                     aActiveDataTable = rTable;
    1072           0 :                     Any aVal; aVal <<= rTable;
    1073           0 :                     aPropertySet->setPropertyValue( "Command", aVal );
    1074           0 :                     break;
    1075             :                 }
    1076             :             }
    1077           0 :             if (pTableNames != pTableNamesEnd)
    1078             :             {
    1079           0 :                 Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
    1080           0 :                 aQuoteChar = xMetaData->getIdentifierQuoteString();
    1081             : 
    1082           0 :                 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
    1083           0 :                 if ( xFactory.is() )
    1084           0 :                     m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
    1085             : 
    1086           0 :                 OUString aString("SELECT * FROM ");
    1087             : 
    1088           0 :                 OUString sCatalog, sSchema, sName;
    1089           0 :                 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
    1090           0 :                 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
    1091             : 
    1092           0 :                 m_xParser->setElementaryQuery(aString);
    1093             : 
    1094           0 :                 BibConfig* pConfig = BibModul::GetConfig();
    1095           0 :                 pConfig->setQueryField(getQueryField());
    1096           0 :                 startQueryWith(pConfig->getQueryText());
    1097             : 
    1098           0 :                 BibDBDescriptor aDesc;
    1099           0 :                 aDesc.sDataSource = aDataSourceURL;
    1100           0 :                 aDesc.sTableOrQuery = aActiveDataTable;
    1101           0 :                 aDesc.nCommandType = CommandType::TABLE;
    1102           0 :                 BibModul::GetConfig()->SetBibliographyURL(aDesc);
    1103           0 :             }
    1104           0 :         }
    1105             :     }
    1106           0 :     catch (const Exception&)
    1107             :     {
    1108             :         OSL_FAIL("::setActiveDataTable: something went wrong !");
    1109             :     }
    1110           0 : }
    1111             : 
    1112             : 
    1113           0 : void SAL_CALL BibDataManager::load(  ) throw (RuntimeException, std::exception)
    1114             : {
    1115           0 :     if ( isLoaded() )
    1116             :         // nothing to do
    1117           0 :         return;
    1118             : 
    1119           0 :     Reference< XLoadable > xFormAsLoadable( m_xForm, UNO_QUERY );
    1120             :     DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::load: invalid form!");
    1121           0 :     if ( xFormAsLoadable.is() )
    1122             :     {
    1123           0 :         xFormAsLoadable->load();
    1124           0 :         SetMeAsUidListener();
    1125             : 
    1126           0 :         EventObject aEvt( static_cast< XWeak* >( this ) );
    1127           0 :         m_aLoadListeners.notifyEach( &XLoadListener::loaded, aEvt );
    1128           0 :     }
    1129             : }
    1130             : 
    1131             : 
    1132           0 : void SAL_CALL BibDataManager::unload(  ) throw (RuntimeException, std::exception)
    1133             : {
    1134           0 :     if ( !isLoaded() )
    1135             :         // nothing to do
    1136           0 :         return;
    1137             : 
    1138           0 :     Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
    1139             :     DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::unload: invalid form!");
    1140           0 :     if ( xFormAsLoadable.is() )
    1141             :     {
    1142           0 :         EventObject aEvt( static_cast< XWeak* >( this ) );
    1143             : 
    1144             :         {
    1145           0 :             m_aLoadListeners.notifyEach( &XLoadListener::unloading, aEvt );
    1146             :         }
    1147             : 
    1148           0 :         RemoveMeAsUidListener();
    1149           0 :         xFormAsLoadable->unload();
    1150             : 
    1151             :         {
    1152           0 :             m_aLoadListeners.notifyEach( &XLoadListener::unloaded, aEvt );
    1153           0 :         }
    1154           0 :     }
    1155             : }
    1156             : 
    1157             : 
    1158           0 : void SAL_CALL BibDataManager::reload(  ) throw (RuntimeException, std::exception)
    1159             : {
    1160           0 :     if ( !isLoaded() )
    1161             :         // nothing to do
    1162           0 :         return;
    1163             : 
    1164           0 :     Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
    1165             :     DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::unload: invalid form!");
    1166           0 :     if ( xFormAsLoadable.is() )
    1167             :     {
    1168           0 :         EventObject aEvt( static_cast< XWeak* >( this ) );
    1169             : 
    1170             :         {
    1171           0 :             m_aLoadListeners.notifyEach( &XLoadListener::reloading, aEvt );
    1172             :         }
    1173             : 
    1174           0 :         xFormAsLoadable->reload();
    1175             : 
    1176             :         {
    1177           0 :             m_aLoadListeners.notifyEach( &XLoadListener::reloaded, aEvt );
    1178           0 :         }
    1179           0 :     }
    1180             : }
    1181             : 
    1182             : 
    1183           0 : sal_Bool SAL_CALL BibDataManager::isLoaded(  ) throw (RuntimeException, std::exception)
    1184             : {
    1185           0 :     Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
    1186             :     DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::isLoaded: invalid form!");
    1187             : 
    1188           0 :     bool bLoaded = false;
    1189           0 :     if ( xFormAsLoadable.is() )
    1190           0 :         bLoaded = xFormAsLoadable->isLoaded();
    1191           0 :     return bLoaded;
    1192             : }
    1193             : 
    1194             : 
    1195           0 : void SAL_CALL BibDataManager::addLoadListener( const Reference< XLoadListener >& aListener ) throw (RuntimeException, std::exception)
    1196             : {
    1197           0 :     m_aLoadListeners.addInterface( aListener );
    1198           0 : }
    1199             : 
    1200             : 
    1201           0 : void SAL_CALL BibDataManager::removeLoadListener( const Reference< XLoadListener >& aListener ) throw (RuntimeException, std::exception)
    1202             : {
    1203           0 :     m_aLoadListeners.removeInterface( aListener );
    1204           0 : }
    1205             : 
    1206             : 
    1207           0 : Reference< awt::XControlModel > BibDataManager::createGridModel(const OUString& rName)
    1208             : {
    1209           0 :     Reference< awt::XControlModel > xModel;
    1210             : 
    1211             :     try
    1212             :     {
    1213             :         // create the control model
    1214           0 :         Reference< XMultiServiceFactory >  xMgr = ::comphelper::getProcessServiceFactory();
    1215           0 :         Reference< XInterface >  xObject = xMgr->createInstance("com.sun.star.form.component.GridControl");
    1216           0 :         xModel=Reference< awt::XControlModel > ( xObject, UNO_QUERY );
    1217             : 
    1218             :         // set the
    1219           0 :         Reference< XPropertySet > xPropSet( xModel, UNO_QUERY );
    1220           0 :         xPropSet->setPropertyValue( "Name", makeAny( rName ) );
    1221             : 
    1222             :         // set the name of the to-be-created control
    1223           0 :         OUString aControlName("com.sun.star.form.control.InteractionGridControl");
    1224           0 :         Any aAny; aAny <<= aControlName;
    1225           0 :         xPropSet->setPropertyValue( "DefaultControl",aAny );
    1226             : 
    1227             :         // the helpURL
    1228           0 :         OUString uProp("HelpURL");
    1229           0 :         Reference< XPropertySetInfo > xPropInfo = xPropSet->getPropertySetInfo();
    1230           0 :         if (xPropInfo->hasPropertyByName(uProp))
    1231             :         {
    1232           0 :             xPropSet->setPropertyValue(
    1233           0 :                 uProp, makeAny<OUString>(INET_HID_SCHEME HID_BIB_DB_GRIDCTRL));
    1234           0 :         }
    1235             :     }
    1236           0 :     catch (const Exception&)
    1237             :     {
    1238             :         OSL_FAIL("::createGridModel: something went wrong !");
    1239             :     }
    1240             : 
    1241           0 :     return xModel;
    1242             : }
    1243             : 
    1244           0 : OUString BibDataManager::getControlName(sal_Int32 nFormatKey )
    1245             : {
    1246           0 :     OUString aResStr;
    1247           0 :     switch (nFormatKey)
    1248             :     {
    1249             :         case DataType::BIT:
    1250             :         case DataType::BOOLEAN:
    1251           0 :             aResStr="CheckBox";
    1252           0 :             break;
    1253             :         case DataType::TINYINT:
    1254             :         case DataType::SMALLINT:
    1255             :         case DataType::INTEGER:
    1256           0 :             aResStr="NumericField";
    1257           0 :             break;
    1258             :         case DataType::REAL:
    1259             :         case DataType::DOUBLE:
    1260             :         case DataType::NUMERIC:
    1261             :         case DataType::DECIMAL:
    1262           0 :             aResStr="FormattedField";
    1263           0 :             break;
    1264             :         case DataType::TIMESTAMP:
    1265           0 :             aResStr="FormattedField";
    1266           0 :             break;
    1267             :         case DataType::DATE:
    1268           0 :             aResStr="DateField";
    1269           0 :             break;
    1270             :         case DataType::TIME:
    1271           0 :             aResStr="TimeField";
    1272           0 :             break;
    1273             :         case DataType::CHAR:
    1274             :         case DataType::VARCHAR:
    1275             :         case DataType::LONGVARCHAR:
    1276             :         default:
    1277           0 :             aResStr="TextField";
    1278           0 :             break;
    1279             :     }
    1280           0 :     return aResStr;
    1281             : }
    1282             : 
    1283           0 : Reference< awt::XControlModel > BibDataManager::loadControlModel(
    1284             :                     const OUString& rName, bool bForceListBox)
    1285             : {
    1286           0 :     Reference< awt::XControlModel > xModel;
    1287           0 :     OUString aName("View_");
    1288           0 :     aName += rName;
    1289             : 
    1290             :     try
    1291             :     {
    1292           0 :         Reference< XNameAccess >  xFields = getColumns( m_xForm );
    1293           0 :         if (!xFields.is())
    1294           0 :             return xModel;
    1295           0 :         Reference< XPropertySet >  xField;
    1296             : 
    1297           0 :         Any aElement;
    1298             : 
    1299           0 :         if(xFields->hasByName(rName))
    1300             :         {
    1301           0 :             aElement = xFields->getByName(rName);
    1302           0 :             aElement >>= xField;
    1303           0 :             Reference< XPropertySetInfo >  xInfo = xField.is() ? xField->getPropertySetInfo() : Reference< XPropertySetInfo > ();
    1304             : 
    1305           0 :             const OUString sType("Type");
    1306           0 :             sal_Int32 nFormatKey = 0;
    1307           0 :             xField->getPropertyValue(sType) >>= nFormatKey;
    1308             : 
    1309           0 :             OUString aInstanceName("com.sun.star.form.component.");
    1310             : 
    1311           0 :             if (bForceListBox)
    1312           0 :                 aInstanceName += "ListBox";
    1313             :             else
    1314           0 :                 aInstanceName += getControlName(nFormatKey);
    1315             : 
    1316           0 :             Reference< XComponentContext >  xContext = comphelper::getProcessComponentContext();
    1317           0 :             Reference< XInterface >  xObject = xContext->getServiceManager()->createInstanceWithContext(aInstanceName, xContext);
    1318           0 :             xModel=Reference< awt::XControlModel > ( xObject, UNO_QUERY );
    1319           0 :             Reference< XPropertySet >  xPropSet( xModel, UNO_QUERY );
    1320           0 :             Any aFieldName; aFieldName <<= aName;
    1321             : 
    1322           0 :             xPropSet->setPropertyValue( FM_PROP_NAME,aFieldName);
    1323           0 :             xPropSet->setPropertyValue( FM_PROP_CONTROLSOURCE, makeAny( rName ) );
    1324           0 :             xPropSet->setPropertyValue("NativeWidgetLook", makeAny( true ) );
    1325             : 
    1326           0 :             if (bForceListBox)
    1327             :             {
    1328           0 :                 uno::Any aAny;
    1329             : 
    1330             :                 //uno::Reference< beans::XPropertySet >  xPropSet(xControl, UNO_QUERY);
    1331           0 :                 aAny <<= (sal_Int16)1;
    1332           0 :                 xPropSet->setPropertyValue("BoundColumn", aAny);
    1333           0 :                 ListSourceType eSet = ListSourceType_VALUELIST;
    1334           0 :                 aAny.setValue( &eSet, ::cppu::UnoType<ListSourceType>::get() );
    1335           0 :                 xPropSet->setPropertyValue("ListSourceType", aAny);
    1336             : 
    1337           0 :                 uno::Sequence<OUString> aListSource(TYPE_COUNT);
    1338           0 :                 OUString* pListSourceArr = aListSource.getArray();
    1339             :                 //pListSourceArr[0] = "select TypeName, TypeIndex from TypeNms";
    1340           0 :                 for(sal_Int32 i = 0; i < TYPE_COUNT; ++i)
    1341           0 :                     pListSourceArr[i] = OUString::number(i);
    1342           0 :                 aAny.setValue(&aListSource, cppu::UnoType<uno::Sequence<OUString>>::get());
    1343             : 
    1344           0 :                 xPropSet->setPropertyValue("ListSource", aAny);
    1345             : 
    1346           0 :                 uno::Sequence<OUString> aValues(TYPE_COUNT + 1);
    1347           0 :                 OUString* pValuesArr = aValues.getArray();
    1348           0 :                 pValuesArr[0] = BIB_RESSTR(ST_TYPE_ARTICLE);
    1349           0 :                 pValuesArr[1] = BIB_RESSTR(ST_TYPE_BOOK);
    1350           0 :                 pValuesArr[2] = BIB_RESSTR(ST_TYPE_BOOKLET);
    1351           0 :                 pValuesArr[3] = BIB_RESSTR(ST_TYPE_CONFERENCE);
    1352           0 :                 pValuesArr[4] = BIB_RESSTR(ST_TYPE_INBOOK );
    1353           0 :                 pValuesArr[5] = BIB_RESSTR(ST_TYPE_INCOLLECTION);
    1354           0 :                 pValuesArr[6] = BIB_RESSTR(ST_TYPE_INPROCEEDINGS);
    1355           0 :                 pValuesArr[7] = BIB_RESSTR(ST_TYPE_JOURNAL       );
    1356           0 :                 pValuesArr[8] = BIB_RESSTR(ST_TYPE_MANUAL    );
    1357           0 :                 pValuesArr[9] = BIB_RESSTR(ST_TYPE_MASTERSTHESIS);
    1358           0 :                 pValuesArr[10] = BIB_RESSTR(ST_TYPE_MISC      );
    1359           0 :                 pValuesArr[11] = BIB_RESSTR(ST_TYPE_PHDTHESIS );
    1360           0 :                 pValuesArr[12] = BIB_RESSTR(ST_TYPE_PROCEEDINGS   );
    1361           0 :                 pValuesArr[13] = BIB_RESSTR(ST_TYPE_TECHREPORT    );
    1362           0 :                 pValuesArr[14] = BIB_RESSTR(ST_TYPE_UNPUBLISHED   );
    1363           0 :                 pValuesArr[15] = BIB_RESSTR(ST_TYPE_EMAIL     );
    1364           0 :                 pValuesArr[16] = BIB_RESSTR(ST_TYPE_WWW           );
    1365           0 :                 pValuesArr[17] = BIB_RESSTR(ST_TYPE_CUSTOM1       );
    1366           0 :                 pValuesArr[18] = BIB_RESSTR(ST_TYPE_CUSTOM2       );
    1367           0 :                 pValuesArr[19] = BIB_RESSTR(ST_TYPE_CUSTOM3       );
    1368           0 :                 pValuesArr[20] = BIB_RESSTR(ST_TYPE_CUSTOM4       );
    1369           0 :                 pValuesArr[21] = BIB_RESSTR(ST_TYPE_CUSTOM5       );
    1370             :                 // empty string if an invalid value no values is set
    1371           0 :                 pValuesArr[TYPE_COUNT].clear();
    1372             : 
    1373           0 :                 aAny.setValue(&aValues, cppu::UnoType<uno::Sequence<OUString>>::get());
    1374             : 
    1375           0 :                 xPropSet->setPropertyValue("StringItemList", aAny);
    1376             : 
    1377           0 :                 sal_Bool bTrue = sal_True;
    1378           0 :                 aAny.setValue( &bTrue, cppu::UnoType<bool>::get() );
    1379           0 :                 xPropSet->setPropertyValue( "Dropdown", aAny );
    1380             :             }
    1381             : 
    1382           0 :             Reference< XFormComponent >  aFormComp(xModel,UNO_QUERY );
    1383             : 
    1384           0 :             Reference< XNameContainer >  xNameCont( m_xForm, UNO_QUERY );
    1385           0 :             xNameCont->insertByName(aName, makeAny( aFormComp ) );
    1386             : 
    1387             :             // now if the form where we inserted the new model is already loaded, notify the model of this
    1388             :             // Note that this implementation below is a HACK as it relies on the fact that the model adds itself
    1389             :             // as load listener to its parent, which is an implementation detail of the model.
    1390             :             //
    1391             :             // the better solution would be the following:
    1392             :             // in the current scenario, we insert a control model into a form. This results in the control model
    1393             :             // adding itself as load listener to the form. Now, the form should realize that it's already loaded
    1394             :             // and notify the model (which it knows as XLoadListener only) immediately. This seems to make sense.
    1395             :             // (as an anologon to the XStatusListener semantics).
    1396             :             //
    1397             :             // But this would be way too risky for this last-day fix here.
    1398           0 :             Reference< XLoadable > xLoad( m_xForm, UNO_QUERY );
    1399           0 :             if ( xLoad.is() && xLoad->isLoaded() )
    1400             :             {
    1401           0 :                 Reference< XLoadListener > xListener( aFormComp, UNO_QUERY );
    1402           0 :                 if ( xListener.is() )
    1403             :                 {
    1404           0 :                     EventObject aLoadSource;
    1405           0 :                     aLoadSource.Source = xLoad;
    1406           0 :                     xListener->loaded( aLoadSource );
    1407           0 :                 }
    1408           0 :             }
    1409           0 :         }
    1410             :     }
    1411           0 :     catch (const Exception&)
    1412             :     {
    1413             :         OSL_FAIL("::loadControlModel: something went wrong !");
    1414             :     }
    1415           0 :     return xModel;
    1416             : }
    1417             : 
    1418           0 : void SAL_CALL BibDataManager::disposing()
    1419             : {
    1420           0 :     BibDataManager_Base::WeakComponentImplHelperBase::disposing();
    1421           0 : }
    1422             : 
    1423             : 
    1424           0 : void BibDataManager::disposing( const EventObject& /*Source*/ ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
    1425             : {
    1426             :     // not interested in
    1427           0 : }
    1428             : 
    1429             : 
    1430           0 : void BibDataManager::propertyChange(const beans::PropertyChangeEvent& evt) throw( RuntimeException, std::exception )
    1431             : {
    1432             :     try
    1433             :     {
    1434           0 :         if(evt.PropertyName == FM_PROP_VALUE)
    1435             :         {
    1436           0 :             if( evt.NewValue.getValueType() == cppu::UnoType<io::XInputStream>::get())
    1437             :             {
    1438             :                 Reference< io::XDataInputStream >  xStream(
    1439           0 :                     *static_cast<const Reference< io::XInputStream > *>(evt.NewValue.getValue()), UNO_QUERY );
    1440           0 :                 aUID <<= xStream->readUTF();
    1441             :             }
    1442             :             else
    1443           0 :                 aUID = evt.NewValue;
    1444             : 
    1445           0 :             Reference< XRowLocate > xLocate(xBibCursor, UNO_QUERY);
    1446             :             DBG_ASSERT(xLocate.is(), "BibDataManager::propertyChange : invalid cursor !");
    1447           0 :             xLocate->moveToBookmark(aUID);
    1448             :         }
    1449             :     }
    1450           0 :     catch (const Exception&)
    1451             :     {
    1452             :         OSL_FAIL("::propertyChange: something went wrong !");
    1453             :     }
    1454           0 : }
    1455             : 
    1456             : 
    1457           0 : void BibDataManager::SetMeAsUidListener()
    1458             : {
    1459             :     try
    1460             :     {
    1461           0 :         Reference< XNameAccess >  xFields = getColumns( m_xForm );
    1462           0 :         if (!xFields.is())
    1463           0 :             return;
    1464             : 
    1465           0 :         Sequence< OUString > aFields(xFields->getElementNames());
    1466           0 :         const OUString* pFields = aFields.getConstArray();
    1467           0 :         sal_Int32 nCount=aFields.getLength();
    1468           0 :         OUString StrUID(STR_UID);
    1469           0 :         OUString theFieldName;
    1470           0 :         for( sal_Int32 i=0; i<nCount; i++ )
    1471             :         {
    1472           0 :             const OUString& rName = pFields[i];
    1473             : 
    1474           0 :             if (rName.equalsIgnoreAsciiCase(StrUID))
    1475             :             {
    1476           0 :                 theFieldName=pFields[i];
    1477           0 :                 break;
    1478             :             }
    1479             :         }
    1480             : 
    1481           0 :         if(!theFieldName.isEmpty())
    1482             :         {
    1483           0 :             Reference< XPropertySet >  xPropSet;
    1484           0 :             Any aElement;
    1485             : 
    1486           0 :             aElement = xFields->getByName(theFieldName);
    1487           0 :             xPropSet = *static_cast<Reference< XPropertySet > const *>(aElement.getValue());
    1488             : 
    1489           0 :             xPropSet->addPropertyChangeListener(FM_PROP_VALUE, this);
    1490           0 :         }
    1491             : 
    1492             :     }
    1493           0 :     catch (const Exception&)
    1494             :     {
    1495             :         OSL_FAIL("Exception in BibDataManager::SetMeAsUidListener");
    1496             :     }
    1497             : }
    1498             : 
    1499             : 
    1500           0 : void BibDataManager::RemoveMeAsUidListener()
    1501             : {
    1502             :     try
    1503             :     {
    1504           0 :         Reference< XNameAccess >  xFields = getColumns( m_xForm );
    1505           0 :         if (!xFields.is())
    1506           0 :             return;
    1507             : 
    1508             : 
    1509           0 :         Sequence< OUString > aFields(xFields->getElementNames());
    1510           0 :         const OUString* pFields = aFields.getConstArray();
    1511           0 :         sal_Int32 nCount=aFields.getLength();
    1512           0 :         OUString StrUID(STR_UID);
    1513           0 :         OUString theFieldName;
    1514           0 :         for( sal_Int32 i=0; i<nCount; i++ )
    1515             :         {
    1516           0 :             const OUString& rName = pFields[i];
    1517             : 
    1518           0 :             if (rName.equalsIgnoreAsciiCase(StrUID))
    1519             :             {
    1520           0 :                 theFieldName=pFields[i];
    1521           0 :                 break;
    1522             :             }
    1523             :         }
    1524             : 
    1525           0 :         if(!theFieldName.isEmpty())
    1526             :         {
    1527           0 :             Reference< XPropertySet >  xPropSet;
    1528           0 :             Any aElement;
    1529             : 
    1530           0 :             aElement = xFields->getByName(theFieldName);
    1531           0 :             xPropSet = *static_cast<Reference< XPropertySet > const *>(aElement.getValue());
    1532             : 
    1533           0 :             xPropSet->removePropertyChangeListener(FM_PROP_VALUE, this);
    1534           0 :         }
    1535             : 
    1536             :     }
    1537           0 :     catch (const Exception&)
    1538             :     {
    1539             :         OSL_FAIL("Exception in BibDataManager::RemoveMeAsUidListener");
    1540             :     }
    1541             : }
    1542             : 
    1543           0 : void BibDataManager::CreateMappingDialog(vcl::Window* pParent)
    1544             : {
    1545           0 :     VclPtrInstance< MappingDialog_Impl > pDlg(pParent, this);
    1546           0 :     if(RET_OK == pDlg->Execute() && pBibView)
    1547             :     {
    1548           0 :         reload();
    1549           0 :     }
    1550           0 : }
    1551             : 
    1552           0 : OUString BibDataManager::CreateDBChangeDialog(vcl::Window* pParent)
    1553             : {
    1554           0 :     OUString uRet;
    1555           0 :     VclPtrInstance< DBChangeDialog_Impl > pDlg(pParent, this );
    1556           0 :     if(RET_OK == pDlg->Execute())
    1557             :     {
    1558           0 :         OUString sNewURL = pDlg->GetCurrentURL();
    1559           0 :         if(sNewURL != getActiveDataSource())
    1560             :         {
    1561           0 :             uRet = sNewURL;
    1562           0 :         }
    1563             :     }
    1564           0 :     return uRet;
    1565             : }
    1566             : 
    1567           0 : void BibDataManager::DispatchDBChangeDialog()
    1568             : {
    1569           0 :     if(pToolbar)
    1570           0 :         pToolbar->SendDispatch(TBC_BT_CHANGESOURCE, Sequence< PropertyValue >());
    1571           0 : }
    1572             : 
    1573           0 : const OUString& BibDataManager::GetIdentifierMapping()
    1574             : {
    1575           0 :     if(sIdentifierMapping.isEmpty())
    1576             :     {
    1577           0 :         BibConfig* pConfig = BibModul::GetConfig();
    1578           0 :         BibDBDescriptor aDesc;
    1579           0 :         aDesc.sDataSource = getActiveDataSource();
    1580           0 :         aDesc.sTableOrQuery = getActiveDataTable();
    1581           0 :         aDesc.nCommandType = CommandType::TABLE;
    1582           0 :         const Mapping* pMapping = pConfig->GetMapping(aDesc);
    1583           0 :         sIdentifierMapping = pConfig->GetDefColumnName(IDENTIFIER_POS);
    1584           0 :         if(pMapping)
    1585             :         {
    1586           0 :             for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
    1587             :             {
    1588           0 :                 if(pMapping->aColumnPairs[nEntry].sLogicalColumnName == sIdentifierMapping)
    1589             :                 {
    1590           0 :                     sIdentifierMapping = pMapping->aColumnPairs[nEntry].sRealColumnName;
    1591           0 :                     break;
    1592             :                 }
    1593             :             }
    1594           0 :         }
    1595             :     }
    1596           0 :     return sIdentifierMapping;
    1597             : }
    1598             : 
    1599           0 : void BibDataManager::SetToolbar(BibToolBar* pSet)
    1600             : {
    1601           0 :     pToolbar = pSet;
    1602           0 :     if(pToolbar)
    1603           0 :         pToolbar->SetDatMan(*this);
    1604           0 : }
    1605             : 
    1606           0 : uno::Reference< form::runtime::XFormController > BibDataManager::GetFormController()
    1607             : {
    1608           0 :     if(!m_xFormCtrl.is())
    1609             :     {
    1610           0 :         Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
    1611           0 :         m_xFormCtrl = form::runtime::FormController::create(xContext);
    1612           0 :         m_xFormCtrl->setModel(uno::Reference< awt::XTabControllerModel > (getForm(), UNO_QUERY));
    1613           0 :         m_xFormDispatch = uno::Reference< frame::XDispatch > ( m_xFormCtrl, UNO_QUERY);
    1614             :     }
    1615           0 :     return m_xFormCtrl;
    1616             : }
    1617             : 
    1618           0 : void BibDataManager::RegisterInterceptor( ::bib::BibBeamer* pBibBeamer)
    1619             : {
    1620             :     DBG_ASSERT( !m_pInterceptorHelper, "BibDataManager::RegisterInterceptor: called twice!" );
    1621             : 
    1622           0 :     if( pBibBeamer )
    1623           0 :         m_pInterceptorHelper = new BibInterceptorHelper( pBibBeamer, m_xFormDispatch);
    1624           0 :     if( m_pInterceptorHelper )
    1625           0 :         m_pInterceptorHelper->acquire();
    1626           0 : }
    1627             : 
    1628             : 
    1629           0 : bool BibDataManager::HasActiveConnection()const
    1630             : {
    1631           0 :     bool bRet = false;
    1632           0 :     Reference< XPropertySet >   xPrSet( m_xForm, UNO_QUERY );
    1633           0 :     if( xPrSet.is() )
    1634             :     {
    1635           0 :         Reference< XComponent >  xConnection;
    1636           0 :         xPrSet->getPropertyValue("ActiveConnection") >>= xConnection;
    1637           0 :         bRet = xConnection.is();
    1638             :     }
    1639           0 :     return bRet;
    1640             : }
    1641             : 
    1642           0 : bool BibDataManager::HasActiveConnection()
    1643             : {
    1644           0 :     return getConnection( m_xForm ).is();
    1645           6 : }
    1646             : 
    1647             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11