LCOV - code coverage report
Current view: top level - extensions/source/bibliography - datman.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 792 0.0 %
Date: 2014-04-14 Functions: 0 69 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10