LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/extensions/source/bibliography - datman.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 808 0.7 %
Date: 2013-07-09 Functions: 2 69 2.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <osl/mutex.hxx>
      21             : #include <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             :     String          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             :     ~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(BibResId(ST_NONE)),
     364           0 :     bModified(sal_False)
     365             : {
     366           0 :     FreeResource();
     367             : 
     368           0 :     aIdentifierFT.SetText(String(         BibResId( ST_IDENTIFIER    )));
     369           0 :     aAuthorityTypeFT.SetText(String(      BibResId( ST_AUTHTYPE )));
     370           0 :     aAuthorFT.SetText(String(             BibResId( ST_AUTHOR        )));
     371           0 :     aTitleFT.SetText(String(              BibResId( ST_TITLE         )));
     372           0 :     aMonthFT.SetText(String(              BibResId( ST_MONTH         )));
     373           0 :     aYearFT.SetText(String(               BibResId( ST_YEAR          )));
     374           0 :     aISBNFT.SetText(String(               BibResId( ST_ISBN          )));
     375           0 :     aBooktitleFT.SetText(String(          BibResId( ST_BOOKTITLE     )));
     376           0 :     aChapterFT.SetText(String(            BibResId( ST_CHAPTER       )));
     377           0 :     aEditionFT.SetText(String(            BibResId( ST_EDITION       )));
     378           0 :     aEditorFT.SetText(String(             BibResId( ST_EDITOR        )));
     379           0 :     aHowpublishedFT.SetText(String(       BibResId( ST_HOWPUBLISHED  )));
     380           0 :     aInstitutionFT.SetText(String(        BibResId( ST_INSTITUTION   )));
     381           0 :     aJournalFT.SetText(String(            BibResId( ST_JOURNAL       )));
     382           0 :     aNoteFT.SetText(String(               BibResId( ST_NOTE          )));
     383           0 :     aAnnoteFT.SetText(String(             BibResId( ST_ANNOTE        )));
     384           0 :     aNumberFT.SetText(String(             BibResId( ST_NUMBER        )));
     385           0 :     aOrganizationsFT.SetText(String(      BibResId( ST_ORGANIZATION )));
     386           0 :     aPagesFT.SetText(String(              BibResId( ST_PAGE         )));
     387           0 :     aPublisherFT.SetText(String(          BibResId( ST_PUBLISHER     )));
     388           0 :     aAddressFT.SetText(String(            BibResId( ST_ADDRESS       )));
     389           0 :     aSchoolFT.SetText(String(             BibResId( ST_SCHOOL        )));
     390           0 :     aSeriesFT.SetText(String(             BibResId( ST_SERIES        )));
     391           0 :     aReportTypeFT.SetText(String(         BibResId( ST_REPORT    )));
     392           0 :     aVolumeFT.SetText(String(             BibResId( ST_VOLUME        )));
     393           0 :     aURLFT.SetText(String(                BibResId( ST_URL           )));
     394           0 :     aCustom1FT.SetText(String(            BibResId( ST_CUSTOM1       )));
     395           0 :     aCustom2FT.SetText(String(            BibResId( ST_CUSTOM2       )));
     396           0 :     aCustom3FT.SetText(String(            BibResId( ST_CUSTOM3       )));
     397           0 :     aCustom4FT.SetText(String(            BibResId( ST_CUSTOM4       )));
     398           0 :     aCustom5FT.SetText(String(            BibResId( ST_CUSTOM5       )));
     399             : 
     400           0 :     aOKBT.SetClickHdl(LINK(this, MappingDialog_Impl, OkHdl));
     401           0 :     String sTitle = GetText();
     402           0 :     sTitle.SearchAndReplace(OUString("%1"), pDatMan->getActiveDataTable(), 0);
     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 = String(pDatMan->getActiveDataTable());
     504           0 :         aNew.sURL = String(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 :             String 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             :     OKButton        aOKBT;
     532             :     CancelButton    aCancelBT;
     533             :     HelpButton      aHelpBT;
     534             :     FixedLine       aSelectionGB;
     535             :     SvTabListBox    aSelectionLB;
     536             :     HeaderBar       aSelectionHB;
     537             :     DBChangeDialogConfig_Impl   aConfig;
     538             :     String          aEntryST;
     539             :     String          aURLST;
     540             : 
     541             :     BibDataManager* pDatMan;
     542             : 
     543             :     DECL_LINK(DoubleClickHdl, SvTabListBox*);
     544             : public:
     545             :     DBChangeDialog_Impl(Window* pParent, BibDataManager* pMan );
     546             :     ~DBChangeDialog_Impl();
     547             : 
     548             :     String      GetCurrentURL()const;
     549             : };
     550             : 
     551           0 : DBChangeDialog_Impl::DBChangeDialog_Impl(Window* pParent, BibDataManager* pMan ) :
     552             :     ModalDialog(pParent, BibResId(RID_DLG_DBCHANGE) ),
     553             :     aOKBT(this,         BibResId( BT_OK     )),
     554             :     aCancelBT(this,     BibResId( BT_CANCEL )),
     555             :     aHelpBT(this,       BibResId( BT_HELP       )),
     556             :     aSelectionGB(this,  BibResId( GB_SELECTION )),
     557             :     aSelectionLB(this,  BibResId( LB_SELECTION )),
     558             :     aSelectionHB(this,  BibResId( HB_SELECTION )),
     559             :     aEntryST(BibResId(ST_ENTRY)),
     560             :     aURLST( BibResId(ST_URL)),
     561           0 :     pDatMan(pMan)
     562             : {
     563           0 :     FreeResource();
     564           0 :     aSelectionLB.SetDoubleClickHdl( LINK(this, DBChangeDialog_Impl, DoubleClickHdl));
     565             :     try
     566             :     {
     567           0 :         ::Size aSize = aSelectionHB.GetSizePixel();
     568             :         long nTabs[2];
     569           0 :         nTabs[0] = 1;// Number of Tabs
     570           0 :         nTabs[1] = aSize.Width() / 4;
     571             : 
     572           0 :         aSelectionHB.SetStyle(aSelectionHB.GetStyle()|WB_STDHEADERBAR);
     573           0 :         aSelectionHB.InsertItem( 1, aEntryST, aSize.Width());
     574           0 :         aSelectionHB.SetSizePixel(aSelectionHB.CalcWindowSizePixel());
     575           0 :         aSelectionHB.Show();
     576             : 
     577           0 :         aSelectionLB.SetTabs( &nTabs[0], MAP_PIXEL );
     578           0 :         aSelectionLB.SetStyle(aSelectionLB.GetStyle()|WB_CLIPCHILDREN|WB_SORT);
     579           0 :         aSelectionLB.GetModel()->SetSortMode(SortAscending);
     580             : 
     581           0 :         OUString sActiveSource = pDatMan->getActiveDataSource();
     582           0 :         const Sequence< OUString >& rSources = aConfig.GetDataSourceNames();
     583           0 :         const OUString* pSourceNames = rSources.getConstArray();
     584           0 :         for(int i = 0; i < rSources.getLength(); i++)
     585             :         {
     586           0 :             SvTreeListEntry* pEntry = aSelectionLB.InsertEntry(pSourceNames[i]);
     587           0 :             if(pSourceNames[i] == sActiveSource)
     588             :             {
     589           0 :                 aSelectionLB.Select(pEntry);
     590             :             }
     591             :         }
     592           0 :         aSelectionLB.GetModel()->Resort();
     593             :     }
     594           0 :     catch (const Exception&)
     595             :     {
     596             :         OSL_FAIL("Exception in BibDataManager::DBChangeDialog_Impl::DBChangeDialog_Impl");
     597             :     }
     598           0 : }
     599             : 
     600           0 : IMPL_LINK(DBChangeDialog_Impl, DoubleClickHdl, SvTabListBox*, /*pLB*/)
     601             : {
     602           0 :     EndDialog(RET_OK);
     603           0 :     return 0;
     604             : }
     605             : 
     606           0 : DBChangeDialog_Impl::~DBChangeDialog_Impl()
     607             : {
     608           0 : }
     609             : 
     610           0 : String  DBChangeDialog_Impl::GetCurrentURL()const
     611             : {
     612           0 :     String sRet;
     613           0 :     SvTreeListEntry* pEntry = aSelectionLB.FirstSelected();
     614           0 :     if(pEntry)
     615             :     {
     616           0 :         sRet = aSelectionLB.GetEntryText(pEntry, 0);
     617             :     }
     618           0 :     return sRet;
     619             : }
     620             : 
     621             : // XDispatchProvider
     622           0 : BibInterceptorHelper::BibInterceptorHelper( ::bib::BibBeamer* pBibBeamer, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch)
     623             : {
     624           0 :     if( pBibBeamer )
     625             :     {
     626           0 :         xInterception = pBibBeamer->getDispatchProviderInterception();
     627           0 :         if( xInterception.is() )
     628           0 :             xInterception->registerDispatchProviderInterceptor( this );
     629             :     }
     630           0 :     if( xDispatch.is() )
     631           0 :         xFormDispatch = xDispatch;
     632           0 : }
     633             : 
     634           0 : BibInterceptorHelper::~BibInterceptorHelper( )
     635             : {
     636           0 : }
     637             : 
     638           0 : void BibInterceptorHelper::ReleaseInterceptor()
     639             : {
     640           0 :     if ( xInterception.is() )
     641           0 :         xInterception->releaseDispatchProviderInterceptor( this );
     642           0 :     xInterception.clear();
     643           0 : }
     644             : 
     645             : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL
     646           0 :     BibInterceptorHelper::queryDispatch( const ::com::sun::star::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags ) throw (::com::sun::star::uno::RuntimeException)
     647             : {
     648           0 :     Reference< XDispatch > xReturn;
     649             : 
     650           0 :     String aCommand( aURL.Path );
     651           0 :     if ( aCommand.EqualsAscii("FormSlots/ConfirmDeletion") )
     652           0 :         xReturn = xFormDispatch;
     653             :     else
     654           0 :         if ( xSlaveDispatchProvider.is() )
     655           0 :             xReturn = xSlaveDispatchProvider->queryDispatch( aURL, aTargetFrameName, nSearchFlags);
     656             : 
     657           0 :     return xReturn;
     658             : }
     659             : 
     660             : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL
     661           0 :     BibInterceptorHelper::queryDispatches( const ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw (::com::sun::star::uno::RuntimeException)
     662             : {
     663           0 :     Sequence< Reference< XDispatch> > aReturn( aDescripts.getLength() );
     664           0 :     Reference< XDispatch >* pReturn = aReturn.getArray();
     665           0 :     const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
     666           0 :     for ( sal_Int16 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
     667             :     {
     668           0 :         *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
     669             :     }
     670           0 :     return aReturn;
     671             : }
     672             : 
     673             : // XDispatchProviderInterceptor
     674             : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL
     675           0 :     BibInterceptorHelper::getSlaveDispatchProvider(  ) throw (::com::sun::star::uno::RuntimeException)
     676             : {
     677           0 :     return xSlaveDispatchProvider;
     678             : }
     679             : 
     680           0 : void SAL_CALL BibInterceptorHelper::setSlaveDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewSlaveDispatchProvider ) throw (::com::sun::star::uno::RuntimeException)
     681             : {
     682           0 :     xSlaveDispatchProvider = xNewSlaveDispatchProvider;
     683           0 : }
     684             : 
     685             : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL
     686           0 :     BibInterceptorHelper::getMasterDispatchProvider(  ) throw (::com::sun::star::uno::RuntimeException)
     687             : {
     688           0 :     return xMasterDispatchProvider;
     689             : }
     690             : 
     691           0 : void SAL_CALL BibInterceptorHelper::setMasterDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewMasterDispatchProvider ) throw (::com::sun::star::uno::RuntimeException)
     692             : {
     693           0 :     xMasterDispatchProvider = xNewMasterDispatchProvider;
     694           0 : }
     695             : 
     696             : //-----------------------------------------------------------------------------
     697             : #define STR_UID "uid"
     698           1 : OUString gGridName("theGrid");
     699           1 : OUString gViewName("theView");
     700           1 : OUString gGlobalName("theGlobals");
     701           1 : OUString gBeamerSize("theBeamerSize");
     702           1 : OUString gViewSize("theViewSize");
     703             : 
     704           0 : BibDataManager::BibDataManager()
     705           0 :     :BibDataManager_Base( GetMutex() )
     706             :     ,m_pInterceptorHelper( NULL )
     707             :     ,m_aLoadListeners(m_aMutex)
     708             :     ,pBibView( NULL )
     709           0 :     ,pToolbar(0)
     710             : {
     711           0 : }
     712             : 
     713             : 
     714           0 : BibDataManager::~BibDataManager()
     715             : {
     716           0 :     Reference< XLoadable >      xLoad( m_xForm, UNO_QUERY );
     717           0 :     Reference< XPropertySet >   xPrSet( m_xForm, UNO_QUERY );
     718           0 :     Reference< XComponent >     xComp( m_xForm, UNO_QUERY );
     719           0 :     if ( m_xForm.is() )
     720             :     {
     721           0 :         Reference< XComponent >  xConnection;
     722           0 :         xPrSet->getPropertyValue("ActiveConnection") >>= xConnection;
     723           0 :         RemoveMeAsUidListener();
     724           0 :         if (xLoad.is())
     725           0 :             xLoad->unload();
     726           0 :         if (xComp.is())
     727           0 :             xComp->dispose();
     728           0 :         if(xConnection.is())
     729           0 :             xConnection->dispose();
     730           0 :         m_xForm = NULL;
     731             :     }
     732           0 :     if( m_pInterceptorHelper )
     733             :     {
     734           0 :         m_pInterceptorHelper->ReleaseInterceptor();
     735           0 :         m_pInterceptorHelper->release();
     736           0 :         m_pInterceptorHelper = NULL;
     737           0 :     }
     738           0 : }
     739             : //------------------------------------------------------------------------
     740           0 : void BibDataManager::InsertFields(const Reference< XFormComponent > & _rxGrid)
     741             : {
     742           0 :     if ( !_rxGrid.is() )
     743           0 :         return;
     744             : 
     745             :     try
     746             :     {
     747           0 :         Reference< XNameContainer > xColContainer( _rxGrid, UNO_QUERY );
     748             :         // remove the old fields
     749           0 :         if ( xColContainer->hasElements() )
     750             :         {
     751           0 :             Sequence< OUString > aNames = xColContainer->getElementNames();
     752           0 :             const OUString* pNames = aNames.getConstArray();
     753           0 :             const OUString* pNamesEnd = pNames + aNames.getLength();
     754           0 :             for ( ; pNames != pNamesEnd; ++pNames )
     755           0 :                 xColContainer->removeByName( *pNames );
     756             :         }
     757             : 
     758           0 :         Reference< XNameAccess >  xFields = getColumns( m_xForm );
     759           0 :         if (!xFields.is())
     760           0 :             return;
     761             : 
     762           0 :         Reference< XGridColumnFactory > xColFactory( _rxGrid, UNO_QUERY );
     763             : 
     764           0 :         Reference< XPropertySet >  xField;
     765             : 
     766           0 :         Sequence< OUString > aFields( xFields->getElementNames() );
     767           0 :         const OUString* pFields = aFields.getConstArray();
     768           0 :         const OUString* pFieldsEnd = pFields + aFields.getLength();
     769             : 
     770           0 :         for ( ; pFields != pFieldsEnd; ++pFields )
     771             :         {
     772           0 :             xFields->getByName( *pFields ) >>= xField;
     773             : 
     774           0 :             OUString sCurrentModelType;
     775           0 :             const OUString sType("Type");
     776           0 :             sal_Int32 nType = 0;
     777           0 :             sal_Bool bIsFormatted           = sal_False;
     778           0 :             sal_Bool bFormattedIsNumeric    = sal_True;
     779           0 :             xField->getPropertyValue(sType) >>= nType;
     780           0 :             switch(nType)
     781             :             {
     782             :                 case DataType::BIT:
     783             :                 case DataType::BOOLEAN:
     784           0 :                     sCurrentModelType = "CheckBox";
     785           0 :                     break;
     786             : 
     787             :                 case DataType::BINARY:
     788             :                 case DataType::VARBINARY:
     789             :                 case DataType::LONGVARBINARY:
     790             :                 case DataType::BLOB:
     791           0 :                     sCurrentModelType = "TextField";
     792           0 :                     break;
     793             : 
     794             :                 case DataType::VARCHAR:
     795             :                 case DataType::LONGVARCHAR:
     796             :                 case DataType::CHAR:
     797             :                 case DataType::CLOB:
     798           0 :                     bFormattedIsNumeric = sal_False;
     799             :                     // _NO_ break !
     800             :                 default:
     801           0 :                     sCurrentModelType = "FormattedField";
     802           0 :                     bIsFormatted = sal_True;
     803           0 :                     break;
     804             :             }
     805             : 
     806           0 :             Reference< XPropertySet >  xCurrentCol = xColFactory->createColumn(sCurrentModelType);
     807           0 :             if (bIsFormatted)
     808             :             {
     809           0 :                 OUString sFormatKey("FormatKey");
     810           0 :                 xCurrentCol->setPropertyValue(sFormatKey, xField->getPropertyValue(sFormatKey));
     811           0 :                 Any aFormatted(&bFormattedIsNumeric, ::getBooleanCppuType());
     812           0 :                 xCurrentCol->setPropertyValue("TreatAsNumber", aFormatted);
     813             :             }
     814           0 :             Any aColName = makeAny( *pFields );
     815           0 :             xCurrentCol->setPropertyValue(FM_PROP_CONTROLSOURCE,    aColName);
     816           0 :             xCurrentCol->setPropertyValue(FM_PROP_LABEL, aColName);
     817             : 
     818           0 :             xColContainer->insertByName( *pFields, makeAny( xCurrentCol ) );
     819           0 :         }
     820             :     }
     821           0 :     catch (const Exception&)
     822             :     {
     823             :         OSL_FAIL("Exception in BibDataManager::InsertFields");
     824             :     }
     825             : }
     826             : 
     827           0 : Reference< awt::XControlModel > BibDataManager::updateGridModel()
     828             : {
     829           0 :     return updateGridModel( m_xForm );
     830             : }
     831             : 
     832           0 : Reference< awt::XControlModel > BibDataManager::updateGridModel(const Reference< XForm > & xDbForm)
     833             : {
     834             :     try
     835             :     {
     836           0 :         Reference< XPropertySet >  aFormPropSet( xDbForm, UNO_QUERY );
     837           0 :         OUString sName;
     838           0 :         aFormPropSet->getPropertyValue("Command") >>= sName;
     839             : 
     840           0 :         if ( !m_xGridModel.is() )
     841             :         {
     842           0 :             m_xGridModel = createGridModel( gGridName );
     843             : 
     844           0 :             Reference< XNameContainer >  xNameCont(xDbForm, UNO_QUERY);
     845           0 :             xNameCont->insertByName( sName, makeAny( m_xGridModel ) );
     846             :         }
     847             : 
     848             :         // insert the fields
     849           0 :         Reference< XFormComponent > xFormComp( m_xGridModel, UNO_QUERY );
     850           0 :         InsertFields( xFormComp );
     851             :     }
     852           0 :     catch (const Exception&)
     853             :     {
     854             :         OSL_FAIL("::updateGridModel: something went wrong !");
     855             :     }
     856             : 
     857           0 :     return m_xGridModel;
     858             : }
     859             : 
     860           0 : Reference< XForm >  BibDataManager::createDatabaseForm(BibDBDescriptor& rDesc)
     861             : {
     862           0 :     Reference< XForm >  xResult;
     863             :     try
     864             :     {
     865           0 :         Reference< XMultiServiceFactory >  xMgr = comphelper::getProcessServiceFactory();
     866           0 :         m_xForm = Reference< XForm > ( xMgr->createInstance( "com.sun.star.form.component.Form" ), UNO_QUERY );
     867             : 
     868           0 :         Reference< XPropertySet >  aPropertySet( m_xForm, UNO_QUERY );
     869             : 
     870           0 :         aDataSourceURL = rDesc.sDataSource;
     871           0 :         if(aPropertySet.is())
     872             :         {
     873           0 :             Any aVal;
     874           0 :             aVal <<= (sal_Int32)ResultSetType::SCROLL_INSENSITIVE;
     875           0 :             aPropertySet->setPropertyValue("ResultSetType",aVal );
     876           0 :             aVal <<= (sal_Int32)ResultSetConcurrency::READ_ONLY;
     877           0 :             aPropertySet->setPropertyValue("ResultSetConcurrency", aVal);
     878             : 
     879             :             //Caching for Performance
     880           0 :             aVal <<= (sal_Int32)50;
     881           0 :             aPropertySet->setPropertyValue("FetchSize", aVal);
     882             : 
     883           0 :             Reference< XConnection >    xConnection = getConnection(rDesc.sDataSource);
     884           0 :             aVal <<= xConnection;
     885           0 :             aPropertySet->setPropertyValue("ActiveConnection", aVal);
     886             : 
     887           0 :             Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
     888           0 :             Reference< XNameAccess >  xTables = xSupplyTables.is() ?
     889           0 :                                 xSupplyTables->getTables() : Reference< XNameAccess > ();
     890             : 
     891           0 :             Sequence< OUString > aTableNameSeq;
     892           0 :             if (xTables.is())
     893           0 :                 aTableNameSeq = xTables->getElementNames();
     894             : 
     895           0 :             if(aTableNameSeq.getLength() > 0)
     896             :             {
     897           0 :                 const OUString* pTableNames = aTableNameSeq.getConstArray();
     898           0 :                 if(!rDesc.sTableOrQuery.isEmpty())
     899           0 :                     aActiveDataTable = rDesc.sTableOrQuery;
     900             :                 else
     901             :                 {
     902           0 :                     rDesc.sTableOrQuery = aActiveDataTable = pTableNames[0];
     903           0 :                     rDesc.nCommandType = CommandType::TABLE;
     904             :                 }
     905             : 
     906           0 :                 aVal <<= aActiveDataTable;
     907           0 :                 aPropertySet->setPropertyValue("Command", aVal);
     908           0 :                 aVal <<= rDesc.nCommandType;
     909           0 :                 aPropertySet->setPropertyValue("CommandType", aVal);
     910             : 
     911             : 
     912           0 :                 Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
     913           0 :                 aQuoteChar = xMetaData->getIdentifierQuoteString();
     914             : 
     915           0 :                 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
     916           0 :                 if ( xFactory.is() )
     917           0 :                     m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
     918             : 
     919           0 :                 OUString aString("SELECT * FROM ");
     920             : 
     921           0 :                 OUString sCatalog, sSchema, sName;
     922           0 :                 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
     923           0 :                 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
     924             : 
     925           0 :                 m_xParser->setElementaryQuery(aString);
     926           0 :                 BibConfig* pConfig = BibModul::GetConfig();
     927           0 :                 pConfig->setQueryField(getQueryField());
     928           0 :                 startQueryWith(pConfig->getQueryText());
     929             : 
     930           0 :                 xResult = m_xForm;
     931           0 :             }
     932           0 :         }
     933             :     }
     934           0 :     catch (const Exception&)
     935             :     {
     936             :         OSL_FAIL("::createDatabaseForm: something went wrong !");
     937             :     }
     938             : 
     939           0 :     return xResult;
     940             : }
     941             : //------------------------------------------------------------------------
     942           0 : Sequence< OUString > BibDataManager::getDataSources()
     943             : {
     944           0 :     Sequence< OUString > aTableNameSeq;
     945             : 
     946             :     try
     947             :     {
     948           0 :         Reference< XTablesSupplier >  xSupplyTables( getConnection( m_xForm ), UNO_QUERY );
     949           0 :         Reference< XNameAccess >  xTables;
     950           0 :         if (xSupplyTables.is())
     951           0 :             xTables = xSupplyTables->getTables();
     952           0 :         if (xTables.is())
     953           0 :             aTableNameSeq = xTables->getElementNames();
     954             :     }
     955           0 :     catch (const Exception&)
     956             :     {
     957             :         OSL_FAIL("::getDataSources: something went wrong !");
     958             :     }
     959             : 
     960           0 :     return aTableNameSeq;
     961             : }
     962             : //------------------------------------------------------------------------
     963           0 : OUString BibDataManager::getActiveDataTable()
     964             : {
     965           0 :     return aActiveDataTable;
     966             : }
     967             : //------------------------------------------------------------------------
     968           0 : void BibDataManager::setFilter(const OUString& rQuery)
     969             : {
     970           0 :     if(!m_xParser.is())
     971           0 :         return;
     972             :     try
     973             :     {
     974           0 :         m_xParser->setFilter( rQuery );
     975           0 :         OUString aQuery = m_xParser->getFilter();
     976           0 :         Reference< XPropertySet >  xFormProps( m_xForm, UNO_QUERY_THROW );
     977           0 :         xFormProps->setPropertyValue( "Filter", makeAny( aQuery ) );
     978           0 :         xFormProps->setPropertyValue( "ApplyFilter", makeAny( sal_True ) );
     979           0 :         reload();
     980             :     }
     981           0 :     catch (const Exception&)
     982             :     {
     983             :         DBG_UNHANDLED_EXCEPTION();
     984             :     }
     985             : 
     986             : 
     987             : }
     988             : //------------------------------------------------------------------------
     989           0 : OUString BibDataManager::getFilter()
     990             : {
     991             : 
     992           0 :     OUString aQueryString;
     993             :     try
     994             :     {
     995           0 :         Reference< XPropertySet > xFormProps( m_xForm, UNO_QUERY_THROW );
     996           0 :         OSL_VERIFY( xFormProps->getPropertyValue( "Filter"  ) >>= aQueryString );
     997             :     }
     998           0 :     catch (const Exception&)
     999             :     {
    1000             :         DBG_UNHANDLED_EXCEPTION();
    1001             :     }
    1002             : 
    1003             : 
    1004           0 :     return aQueryString;
    1005             : 
    1006             : }
    1007             : //------------------------------------------------------------------------
    1008           0 : Sequence< OUString > BibDataManager::getQueryFields()
    1009             : {
    1010           0 :     Sequence< OUString > aFieldSeq;
    1011           0 :     Reference< XNameAccess >  xFields = getColumns( m_xForm );
    1012           0 :     if (xFields.is())
    1013           0 :         aFieldSeq = xFields->getElementNames();
    1014           0 :     return aFieldSeq;
    1015             : }
    1016             : //------------------------------------------------------------------------
    1017           0 : OUString BibDataManager::getQueryField()
    1018             : {
    1019           0 :     BibConfig* pConfig = BibModul::GetConfig();
    1020           0 :     OUString aFieldString = pConfig->getQueryField();
    1021           0 :     if(aFieldString.isEmpty())
    1022             :     {
    1023           0 :         Sequence< OUString > aSeq = getQueryFields();
    1024           0 :         const OUString* pFields = aSeq.getConstArray();
    1025           0 :         if(aSeq.getLength()>0)
    1026             :         {
    1027           0 :             aFieldString=pFields[0];
    1028           0 :         }
    1029             :     }
    1030           0 :     return aFieldString;
    1031             : }
    1032             : //------------------------------------------------------------------------
    1033           0 : void BibDataManager::startQueryWith(const OUString& rQuery)
    1034             : {
    1035           0 :     BibConfig* pConfig = BibModul::GetConfig();
    1036           0 :     pConfig->setQueryText( rQuery );
    1037             : 
    1038           0 :     OUString aQueryString;
    1039           0 :     if(!rQuery.isEmpty())
    1040             :     {
    1041           0 :         aQueryString=aQuoteChar;
    1042           0 :         aQueryString+=getQueryField();
    1043           0 :         aQueryString+=aQuoteChar;
    1044           0 :         aQueryString+=" like '";
    1045           0 :         String sQuery(rQuery);
    1046           0 :         sQuery.SearchAndReplaceAll('?','_');
    1047           0 :         sQuery.SearchAndReplaceAll('*','%');
    1048           0 :         aQueryString += sQuery;
    1049           0 :         aQueryString+="%'";
    1050             :     }
    1051           0 :     setFilter(aQueryString);
    1052           0 : }
    1053             : 
    1054           0 : void BibDataManager::setActiveDataSource(const OUString& rURL)
    1055             : {
    1056           0 :     OUString sTmp(aDataSourceURL);
    1057           0 :     aDataSourceURL = rURL;
    1058             : 
    1059           0 :     Reference< XPropertySet >  aPropertySet( m_xForm, UNO_QUERY );
    1060           0 :     if(aPropertySet.is())
    1061             :     {
    1062           0 :         unload();
    1063             : 
    1064           0 :         Reference< XComponent >  xOldConnection;
    1065           0 :         aPropertySet->getPropertyValue("ActiveConnection") >>= xOldConnection;
    1066             : 
    1067           0 :         Reference< XConnection >    xConnection = getConnection(rURL);
    1068           0 :         if(!xConnection.is())
    1069             :         {
    1070           0 :             aDataSourceURL = sTmp;
    1071           0 :             return;
    1072             :         }
    1073           0 :         Any aVal; aVal <<= xConnection;
    1074           0 :         aPropertySet->setPropertyValue("ActiveConnection", aVal);
    1075           0 :         Reference< XMultiServiceFactory >   xFactory(xConnection, UNO_QUERY);
    1076           0 :         if ( xFactory.is() )
    1077           0 :             m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
    1078             : 
    1079           0 :         if(xOldConnection.is())
    1080           0 :             xOldConnection->dispose();
    1081             : 
    1082           0 :         Sequence< OUString > aTableNameSeq;
    1083           0 :         Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
    1084           0 :         if(xSupplyTables.is())
    1085             :         {
    1086           0 :             Reference< XNameAccess >  xAccess = xSupplyTables->getTables();
    1087           0 :             aTableNameSeq = xAccess->getElementNames();
    1088             :         }
    1089           0 :         if(aTableNameSeq.getLength() > 0)
    1090             :         {
    1091           0 :             const OUString* pTableNames = aTableNameSeq.getConstArray();
    1092           0 :             aActiveDataTable = pTableNames[0];
    1093           0 :             aVal <<= aActiveDataTable;
    1094           0 :             aPropertySet->setPropertyValue("Command", aVal);
    1095           0 :             aPropertySet->setPropertyValue("CommandType", makeAny(CommandType::TABLE));
    1096             :             //Caching for Performance
    1097           0 :             aVal <<= (sal_Int32)50;
    1098           0 :             aPropertySet->setPropertyValue("FetchSize", aVal);
    1099           0 :             OUString aString("SELECT * FROM ");
    1100             :             // quote the table name which may contain catalog.schema.table
    1101           0 :             Reference<XDatabaseMetaData> xMetaData(xConnection->getMetaData(),UNO_QUERY);
    1102           0 :             aQuoteChar = xMetaData->getIdentifierQuoteString();
    1103             : 
    1104           0 :             OUString sCatalog, sSchema, sName;
    1105           0 :             ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
    1106           0 :             aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
    1107             : 
    1108           0 :             m_xParser->setElementaryQuery(aString);
    1109           0 :             BibConfig* pConfig = BibModul::GetConfig();
    1110           0 :             pConfig->setQueryField(getQueryField());
    1111           0 :             startQueryWith(pConfig->getQueryText());
    1112           0 :             setActiveDataTable(aActiveDataTable);
    1113             :         }
    1114           0 :         FeatureStateEvent aEvent;
    1115           0 :         util::URL aURL;
    1116           0 :         aEvent.IsEnabled  = sal_True;
    1117           0 :         aEvent.Requery    = sal_False;
    1118           0 :         aEvent.FeatureDescriptor = getActiveDataTable();
    1119             : 
    1120           0 :         aEvent.State = makeAny( getDataSources() );
    1121             : 
    1122           0 :         if(pToolbar)
    1123             :         {
    1124           0 :             aURL.Complete =".uno:Bib/source";
    1125           0 :             aEvent.FeatureURL = aURL;
    1126           0 :             pToolbar->statusChanged( aEvent );
    1127             :         }
    1128             : 
    1129           0 :         updateGridModel();
    1130           0 :         load();
    1131           0 :     }
    1132             : }
    1133             : 
    1134             : 
    1135           0 : void BibDataManager::setActiveDataTable(const OUString& rTable)
    1136             : {
    1137           0 :     ResetIdentifierMapping();
    1138             :     try
    1139             :     {
    1140           0 :         Reference< XPropertySet >  aPropertySet( m_xForm, UNO_QUERY );
    1141             : 
    1142           0 :         if(aPropertySet.is())
    1143             :         {
    1144           0 :             Reference< XConnection >    xConnection = getConnection( m_xForm );
    1145           0 :             Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
    1146           0 :             Reference< XNameAccess > xAccess = xSupplyTables->getTables();
    1147           0 :             Sequence< OUString > aTableNameSeq = xAccess->getElementNames();
    1148           0 :             sal_uInt32 nCount = aTableNameSeq.getLength();
    1149             : 
    1150           0 :             const OUString* pTableNames = aTableNameSeq.getConstArray();
    1151           0 :             const OUString* pTableNamesEnd = pTableNames + nCount;
    1152             : 
    1153           0 :             for ( ; pTableNames != pTableNamesEnd; ++pTableNames )
    1154             :             {
    1155           0 :                 if ( rTable == *pTableNames )
    1156             :                 {
    1157           0 :                     aActiveDataTable = rTable;
    1158           0 :                     Any aVal; aVal <<= rTable;
    1159           0 :                     aPropertySet->setPropertyValue( "Command", aVal );
    1160           0 :                     break;
    1161             :                 }
    1162             :             }
    1163           0 :             if (pTableNames != pTableNamesEnd)
    1164             :             {
    1165           0 :                 Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
    1166           0 :                 aQuoteChar = xMetaData->getIdentifierQuoteString();
    1167             : 
    1168           0 :                 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
    1169           0 :                 if ( xFactory.is() )
    1170           0 :                     m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
    1171             : 
    1172           0 :                 OUString aString("SELECT * FROM ");
    1173             : 
    1174           0 :                 OUString sCatalog, sSchema, sName;
    1175           0 :                 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
    1176           0 :                 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
    1177             : 
    1178           0 :                 m_xParser->setElementaryQuery(aString);
    1179             : 
    1180           0 :                 BibConfig* pConfig = BibModul::GetConfig();
    1181           0 :                 pConfig->setQueryField(getQueryField());
    1182           0 :                 startQueryWith(pConfig->getQueryText());
    1183             : 
    1184           0 :                 BibDBDescriptor aDesc;
    1185           0 :                 aDesc.sDataSource = aDataSourceURL;
    1186           0 :                 aDesc.sTableOrQuery = aActiveDataTable;
    1187           0 :                 aDesc.nCommandType = CommandType::TABLE;
    1188           0 :                 BibModul::GetConfig()->SetBibliographyURL(aDesc);
    1189           0 :             }
    1190           0 :         }
    1191             :     }
    1192           0 :     catch (const Exception&)
    1193             :     {
    1194             :         OSL_FAIL("::setActiveDataTable: something went wrong !");
    1195             :     }
    1196           0 : }
    1197             : 
    1198             : //------------------------------------------------------------------------
    1199           0 : void SAL_CALL BibDataManager::load(  ) throw (RuntimeException)
    1200             : {
    1201           0 :     if ( isLoaded() )
    1202             :         // nothing to do
    1203           0 :         return;
    1204             : 
    1205           0 :     Reference< XLoadable > xFormAsLoadable( m_xForm, UNO_QUERY );
    1206             :     DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::load: invalid form!");
    1207           0 :     if ( xFormAsLoadable.is() )
    1208             :     {
    1209           0 :         xFormAsLoadable->load();
    1210           0 :         SetMeAsUidListener();
    1211             : 
    1212           0 :         EventObject aEvt( static_cast< XWeak* >( this ) );
    1213           0 :         m_aLoadListeners.notifyEach( &XLoadListener::loaded, aEvt );
    1214           0 :     }
    1215             : }
    1216             : 
    1217             : //------------------------------------------------------------------------
    1218           0 : void SAL_CALL BibDataManager::unload(  ) throw (RuntimeException)
    1219             : {
    1220           0 :     if ( !isLoaded() )
    1221             :         // nothing to do
    1222           0 :         return;
    1223             : 
    1224           0 :     Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
    1225             :     DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::unload: invalid form!");
    1226           0 :     if ( xFormAsLoadable.is() )
    1227             :     {
    1228           0 :         EventObject aEvt( static_cast< XWeak* >( this ) );
    1229             : 
    1230             :         {
    1231           0 :             m_aLoadListeners.notifyEach( &XLoadListener::unloading, aEvt );
    1232             :         }
    1233             : 
    1234           0 :         RemoveMeAsUidListener();
    1235           0 :         xFormAsLoadable->unload();
    1236             : 
    1237             :         {
    1238           0 :             m_aLoadListeners.notifyEach( &XLoadListener::unloaded, aEvt );
    1239           0 :         }
    1240           0 :     }
    1241             : }
    1242             : 
    1243             : //------------------------------------------------------------------------
    1244           0 : void SAL_CALL BibDataManager::reload(  ) throw (RuntimeException)
    1245             : {
    1246           0 :     if ( !isLoaded() )
    1247             :         // nothing to do
    1248           0 :         return;
    1249             : 
    1250           0 :     Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
    1251             :     DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::unload: invalid form!");
    1252           0 :     if ( xFormAsLoadable.is() )
    1253             :     {
    1254           0 :         EventObject aEvt( static_cast< XWeak* >( this ) );
    1255             : 
    1256             :         {
    1257           0 :             m_aLoadListeners.notifyEach( &XLoadListener::reloading, aEvt );
    1258             :         }
    1259             : 
    1260           0 :         xFormAsLoadable->reload();
    1261             : 
    1262             :         {
    1263           0 :             m_aLoadListeners.notifyEach( &XLoadListener::reloaded, aEvt );
    1264           0 :         }
    1265           0 :     }
    1266             : }
    1267             : 
    1268             : //------------------------------------------------------------------------
    1269           0 : sal_Bool SAL_CALL BibDataManager::isLoaded(  ) throw (RuntimeException)
    1270             : {
    1271           0 :     Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
    1272             :     DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::isLoaded: invalid form!");
    1273             : 
    1274           0 :     sal_Bool bLoaded = sal_False;
    1275           0 :     if ( xFormAsLoadable.is() )
    1276           0 :         bLoaded = xFormAsLoadable->isLoaded();
    1277           0 :     return bLoaded;
    1278             : }
    1279             : 
    1280             : //------------------------------------------------------------------------
    1281           0 : void SAL_CALL BibDataManager::addLoadListener( const Reference< XLoadListener >& aListener ) throw (RuntimeException)
    1282             : {
    1283           0 :     m_aLoadListeners.addInterface( aListener );
    1284           0 : }
    1285             : 
    1286             : //------------------------------------------------------------------------
    1287           0 : void SAL_CALL BibDataManager::removeLoadListener( const Reference< XLoadListener >& aListener ) throw (RuntimeException)
    1288             : {
    1289           0 :     m_aLoadListeners.removeInterface( aListener );
    1290           0 : }
    1291             : 
    1292             : //------------------------------------------------------------------------
    1293           0 : Reference< awt::XControlModel > BibDataManager::createGridModel(const OUString& rName)
    1294             : {
    1295           0 :     Reference< awt::XControlModel > xModel;
    1296             : 
    1297             :     try
    1298             :     {
    1299             :         // create the control model
    1300           0 :         Reference< XMultiServiceFactory >  xMgr = ::comphelper::getProcessServiceFactory();
    1301           0 :         Reference< XInterface >  xObject = xMgr->createInstance("com.sun.star.form.component.GridControl");
    1302           0 :         xModel=Reference< awt::XControlModel > ( xObject, UNO_QUERY );
    1303             : 
    1304             :         // set the
    1305           0 :         Reference< XPropertySet > xPropSet( xModel, UNO_QUERY );
    1306           0 :         xPropSet->setPropertyValue( "Name", makeAny( rName ) );
    1307             : 
    1308             :         // set the name of the to-be-created control
    1309           0 :         OUString aControlName("com.sun.star.form.control.InteractionGridControl");
    1310           0 :         Any aAny; aAny <<= aControlName;
    1311           0 :         xPropSet->setPropertyValue( "DefaultControl",aAny );
    1312             : 
    1313             :         // the helpURL
    1314           0 :         OUString uProp("HelpURL");
    1315           0 :         Reference< XPropertySetInfo > xPropInfo = xPropSet->getPropertySetInfo();
    1316           0 :         if (xPropInfo->hasPropertyByName(uProp))
    1317             :         {
    1318           0 :             OUString sId( INET_HID_SCHEME );
    1319           0 :             sId += OUString::createFromAscii( HID_BIB_DB_GRIDCTRL );
    1320           0 :             xPropSet->setPropertyValue( uProp, makeAny( sId ) );
    1321           0 :         }
    1322             :     }
    1323           0 :     catch (const Exception&)
    1324             :     {
    1325             :         OSL_FAIL("::createGridModel: something went wrong !");
    1326             :     }
    1327             : 
    1328           0 :     return xModel;
    1329             : }
    1330             : //------------------------------------------------------------------------
    1331           0 : OUString BibDataManager::getControlName(sal_Int32 nFormatKey )
    1332             : {
    1333           0 :     OUString aResStr;
    1334           0 :     switch (nFormatKey)
    1335             :     {
    1336             :         case DataType::BIT:
    1337             :         case DataType::BOOLEAN:
    1338           0 :             aResStr="CheckBox";
    1339           0 :             break;
    1340             :         case DataType::TINYINT:
    1341             :         case DataType::SMALLINT:
    1342             :         case DataType::INTEGER:
    1343           0 :             aResStr="NumericField";   ;
    1344           0 :             break;
    1345             :         case DataType::REAL:
    1346             :         case DataType::DOUBLE:
    1347             :         case DataType::NUMERIC:
    1348             :         case DataType::DECIMAL:
    1349           0 :             aResStr="FormattedField";
    1350           0 :             break;
    1351             :         case DataType::TIMESTAMP:
    1352           0 :             aResStr="FormattedField";
    1353           0 :             break;
    1354             :         case DataType::DATE:
    1355           0 :             aResStr="DateField";
    1356           0 :             break;
    1357             :         case DataType::TIME:
    1358           0 :             aResStr="TimeField";
    1359           0 :             break;
    1360             :         case DataType::CHAR:
    1361             :         case DataType::VARCHAR:
    1362             :         case DataType::LONGVARCHAR:
    1363             :         default:
    1364           0 :             aResStr="TextField";
    1365           0 :             break;
    1366             :     }
    1367           0 :     return aResStr;
    1368             : }
    1369             : //------------------------------------------------------------------------
    1370           0 : Reference< awt::XControlModel > BibDataManager::loadControlModel(
    1371             :                     const OUString& rName, sal_Bool bForceListBox)
    1372             : {
    1373           0 :     Reference< awt::XControlModel > xModel;
    1374           0 :     OUString aName("View_");
    1375           0 :     aName += rName;
    1376             : 
    1377             :     try
    1378             :     {
    1379           0 :         Reference< XNameAccess >  xFields = getColumns( m_xForm );
    1380           0 :         if (!xFields.is())
    1381           0 :             return xModel;
    1382           0 :         Reference< XPropertySet >  xField;
    1383             : 
    1384           0 :         Any aElement;
    1385             : 
    1386           0 :         if(xFields->hasByName(rName))
    1387             :         {
    1388           0 :             aElement = xFields->getByName(rName);
    1389           0 :             aElement >>= xField;
    1390           0 :             Reference< XPropertySetInfo >  xInfo = xField.is() ? xField->getPropertySetInfo() : Reference< XPropertySetInfo > ();
    1391             : 
    1392           0 :             const OUString sType("Type");
    1393           0 :             sal_Int32 nFormatKey = 0;
    1394           0 :             xField->getPropertyValue(sType) >>= nFormatKey;
    1395             : 
    1396           0 :             OUString aInstanceName("com.sun.star.form.component.");
    1397             : 
    1398           0 :             if (bForceListBox)
    1399           0 :                 aInstanceName += "ListBox";
    1400             :             else
    1401           0 :                 aInstanceName += getControlName(nFormatKey);
    1402             : 
    1403           0 :             Reference< XComponentContext >  xContext = comphelper::getProcessComponentContext();
    1404           0 :             Reference< XInterface >  xObject = xContext->getServiceManager()->createInstanceWithContext(aInstanceName, xContext);
    1405           0 :             xModel=Reference< awt::XControlModel > ( xObject, UNO_QUERY );
    1406           0 :             Reference< XPropertySet >  xPropSet( xModel, UNO_QUERY );
    1407           0 :             Any aFieldName; aFieldName <<= aName;
    1408             : 
    1409           0 :             xPropSet->setPropertyValue( FM_PROP_NAME,aFieldName);
    1410           0 :             xPropSet->setPropertyValue( FM_PROP_CONTROLSOURCE, makeAny( rName ) );
    1411           0 :             xPropSet->setPropertyValue("NativeWidgetLook", makeAny( (sal_Bool)sal_True ) );
    1412             : 
    1413           0 :             Reference< XFormComponent >  aFormComp(xModel,UNO_QUERY );
    1414             : 
    1415           0 :             Reference< XNameContainer >  xNameCont( m_xForm, UNO_QUERY );
    1416           0 :             xNameCont->insertByName(aName, makeAny( aFormComp ) );
    1417             : 
    1418             :             // now if the form where we inserted the new model is already loaded, notify the model of this
    1419             :             // Note that this implementation below is a HACK as it relies on the fact that the model adds itself
    1420             :             // as load listener to it's parent, which is an implementation detail of the model.
    1421             :             //
    1422             :             // the better solution would be the following:
    1423             :             // in the current scenario, we insert a control model into a form. This results in the control model
    1424             :             // adding itself as load listener to the form. Now, the form should realize that it's already loaded
    1425             :             // and notify the model (which it knows as XLoadListener only) immediately. This seems to make sense.
    1426             :             // (as an anologon to the XStatusListener semantics).
    1427             :             //
    1428             :             // But this would be way too risky for this last-day fix here.
    1429           0 :             Reference< XLoadable > xLoad( m_xForm, UNO_QUERY );
    1430           0 :             if ( xLoad.is() && xLoad->isLoaded() )
    1431             :             {
    1432           0 :                 Reference< XLoadListener > xListener( aFormComp, UNO_QUERY );
    1433           0 :                 if ( xListener.is() )
    1434             :                 {
    1435           0 :                     EventObject aLoadSource;
    1436           0 :                     aLoadSource.Source = xLoad;
    1437           0 :                     xListener->loaded( aLoadSource );
    1438           0 :                 }
    1439           0 :             }
    1440           0 :         }
    1441             :     }
    1442           0 :     catch (const Exception&)
    1443             :     {
    1444             :         OSL_FAIL("::loadControlModel: something went wrong !");
    1445             :     }
    1446           0 :     return xModel;
    1447             : }
    1448             : //------------------------------------------------------------------------
    1449           0 : void SAL_CALL BibDataManager::disposing()
    1450             : {
    1451           0 :     BibDataManager_Base::WeakComponentImplHelperBase::disposing();
    1452           0 : }
    1453             : 
    1454             : //------------------------------------------------------------------------
    1455           0 : void BibDataManager::disposing( const EventObject& /*Source*/ ) throw( ::com::sun::star::uno::RuntimeException )
    1456             : {
    1457             :     // not interested in
    1458           0 : }
    1459             : 
    1460             : //------------------------------------------------------------------------
    1461           0 : void BibDataManager::propertyChange(const beans::PropertyChangeEvent& evt) throw( RuntimeException )
    1462             : {
    1463             :     try
    1464             :     {
    1465           0 :         if(evt.PropertyName == FM_PROP_VALUE)
    1466             :         {
    1467           0 :             if( evt.NewValue.getValueType() == ::getCppuType((Reference<io::XInputStream>*)0) )
    1468             :             {
    1469             :                 Reference< io::XDataInputStream >  xStream(
    1470           0 :                     *(const Reference< io::XInputStream > *)evt.NewValue.getValue(), UNO_QUERY );
    1471           0 :                 aUID <<= xStream->readUTF();
    1472             :             }
    1473             :             else
    1474           0 :                 aUID = evt.NewValue;
    1475             : 
    1476           0 :             Reference< XRowLocate > xLocate(xBibCursor, UNO_QUERY);
    1477             :             DBG_ASSERT(xLocate.is(), "BibDataManager::propertyChange : invalid cursor !");
    1478           0 :             xLocate->moveToBookmark(aUID);
    1479             :         }
    1480             :     }
    1481           0 :     catch (const Exception&)
    1482             :     {
    1483             :         OSL_FAIL("::propertyChange: something went wrong !");
    1484             :     }
    1485           0 : }
    1486             : 
    1487             : //------------------------------------------------------------------------
    1488           0 : void BibDataManager::SetMeAsUidListener()
    1489             : {
    1490             :     try
    1491             :     {
    1492           0 :         Reference< XNameAccess >  xFields = getColumns( m_xForm );
    1493           0 :         if (!xFields.is())
    1494           0 :             return;
    1495             : 
    1496           0 :         Sequence< OUString > aFields(xFields->getElementNames());
    1497           0 :         const OUString* pFields = aFields.getConstArray();
    1498           0 :         sal_Int32 nCount=aFields.getLength();
    1499           0 :         OUString StrUID(STR_UID);
    1500           0 :         OUString theFieldName;
    1501           0 :         for( sal_Int32 i=0; i<nCount; i++ )
    1502             :         {
    1503           0 :             String aName= pFields[i];
    1504             : 
    1505           0 :             if(aName.EqualsIgnoreCaseAscii(StrUID))
    1506             :             {
    1507           0 :                 theFieldName=pFields[i];
    1508           0 :                 break;
    1509             :             }
    1510           0 :         }
    1511             : 
    1512           0 :         if(!theFieldName.isEmpty())
    1513             :         {
    1514           0 :             Reference< XPropertySet >  xPropSet;
    1515           0 :             Any aElement;
    1516             : 
    1517           0 :             aElement = xFields->getByName(theFieldName);
    1518           0 :             xPropSet = *(Reference< XPropertySet > *)aElement.getValue();
    1519             : 
    1520           0 :             xPropSet->addPropertyChangeListener(FM_PROP_VALUE, this);
    1521           0 :         }
    1522             : 
    1523             :     }
    1524           0 :     catch (const Exception&)
    1525             :     {
    1526             :         OSL_FAIL("Exception in BibDataManager::SetMeAsUidListener");
    1527             :     }
    1528             : }
    1529             : 
    1530             : //------------------------------------------------------------------------
    1531           0 : void BibDataManager::RemoveMeAsUidListener()
    1532             : {
    1533             :     try
    1534             :     {
    1535           0 :         Reference< XNameAccess >  xFields = getColumns( m_xForm );
    1536           0 :         if (!xFields.is())
    1537           0 :             return;
    1538             : 
    1539             : 
    1540           0 :         Sequence< OUString > aFields(xFields->getElementNames());
    1541           0 :         const OUString* pFields = aFields.getConstArray();
    1542           0 :         sal_Int32 nCount=aFields.getLength();
    1543           0 :         OUString StrUID(STR_UID);
    1544           0 :         OUString theFieldName;
    1545           0 :         for( sal_Int32 i=0; i<nCount; i++ )
    1546             :         {
    1547           0 :             String aName= pFields[i];
    1548             : 
    1549           0 :             if(aName.EqualsIgnoreCaseAscii(StrUID))
    1550             :             {
    1551           0 :                 theFieldName=pFields[i];
    1552           0 :                 break;
    1553             :             }
    1554           0 :         }
    1555             : 
    1556           0 :         if(!theFieldName.isEmpty())
    1557             :         {
    1558           0 :             Reference< XPropertySet >  xPropSet;
    1559           0 :             Any aElement;
    1560             : 
    1561           0 :             aElement = xFields->getByName(theFieldName);
    1562           0 :             xPropSet = *(Reference< XPropertySet > *)aElement.getValue();
    1563             : 
    1564           0 :             xPropSet->removePropertyChangeListener(FM_PROP_VALUE, this);
    1565           0 :         }
    1566             : 
    1567             :     }
    1568           0 :     catch (const Exception&)
    1569             :     {
    1570             :         OSL_FAIL("Exception in BibDataManager::RemoveMeAsUidListener");
    1571             :     }
    1572             : }
    1573             : 
    1574           0 : void BibDataManager::CreateMappingDialog(Window* pParent)
    1575             : {
    1576           0 :     MappingDialog_Impl* pDlg = new MappingDialog_Impl(pParent, this);
    1577           0 :     if(RET_OK == pDlg->Execute() && pBibView)
    1578             :     {
    1579           0 :         reload();
    1580             :     }
    1581           0 :     delete pDlg;
    1582           0 : }
    1583             : 
    1584           0 : OUString BibDataManager::CreateDBChangeDialog(Window* pParent)
    1585             : {
    1586           0 :     OUString uRet;
    1587           0 :     DBChangeDialog_Impl * pDlg = new DBChangeDialog_Impl(pParent, this );
    1588           0 :     if(RET_OK == pDlg->Execute())
    1589             :     {
    1590           0 :         String sNewURL = pDlg->GetCurrentURL();
    1591           0 :         if(sNewURL != String(getActiveDataSource()))
    1592             :         {
    1593           0 :             uRet = sNewURL;
    1594           0 :         }
    1595             :     }
    1596           0 :     delete pDlg;
    1597           0 :     return uRet;
    1598             : }
    1599             : 
    1600           0 : void BibDataManager::DispatchDBChangeDialog()
    1601             : {
    1602           0 :     if(pToolbar)
    1603           0 :         pToolbar->SendDispatch(TBC_BT_CHANGESOURCE, Sequence< PropertyValue >());
    1604           0 : }
    1605             : 
    1606           0 : const OUString& BibDataManager::GetIdentifierMapping()
    1607             : {
    1608           0 :     if(sIdentifierMapping.isEmpty())
    1609             :     {
    1610           0 :         BibConfig* pConfig = BibModul::GetConfig();
    1611           0 :         BibDBDescriptor aDesc;
    1612           0 :         aDesc.sDataSource = getActiveDataSource();
    1613           0 :         aDesc.sTableOrQuery = getActiveDataTable();
    1614           0 :         aDesc.nCommandType = CommandType::TABLE;
    1615           0 :         const Mapping* pMapping = pConfig->GetMapping(aDesc);
    1616           0 :         sIdentifierMapping = pConfig->GetDefColumnName(IDENTIFIER_POS);
    1617           0 :         if(pMapping)
    1618             :         {
    1619           0 :             for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
    1620             :             {
    1621           0 :                 if(pMapping->aColumnPairs[nEntry].sLogicalColumnName == sIdentifierMapping)
    1622             :                 {
    1623           0 :                     sIdentifierMapping = pMapping->aColumnPairs[nEntry].sRealColumnName;
    1624           0 :                     break;
    1625             :                 }
    1626             :             }
    1627           0 :         }
    1628             :     }
    1629           0 :     return sIdentifierMapping;
    1630             : }
    1631             : 
    1632           0 : void BibDataManager::SetToolbar(BibToolBar* pSet)
    1633             : {
    1634           0 :     pToolbar = pSet;
    1635           0 :     if(pToolbar)
    1636           0 :         pToolbar->SetDatMan(*this);
    1637           0 : }
    1638             : 
    1639           0 : uno::Reference< form::runtime::XFormController > BibDataManager::GetFormController()
    1640             : {
    1641           0 :     if(!m_xFormCtrl.is())
    1642             :     {
    1643           0 :         Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
    1644           0 :         m_xFormCtrl = form::runtime::FormController::create(xContext);
    1645           0 :         m_xFormCtrl->setModel(uno::Reference< awt::XTabControllerModel > (getForm(), UNO_QUERY));
    1646           0 :         m_xFormDispatch = uno::Reference< frame::XDispatch > ( m_xFormCtrl, UNO_QUERY);
    1647             :     }
    1648           0 :     return m_xFormCtrl;
    1649             : }
    1650             : 
    1651           0 : void BibDataManager::RegisterInterceptor( ::bib::BibBeamer* pBibBeamer)
    1652             : {
    1653             :     DBG_ASSERT( !m_pInterceptorHelper, "BibDataManager::RegisterInterceptor: called twice!" );
    1654             : 
    1655           0 :     if( pBibBeamer )
    1656           0 :         m_pInterceptorHelper = new BibInterceptorHelper( pBibBeamer, m_xFormDispatch);
    1657           0 :     if( m_pInterceptorHelper )
    1658           0 :         m_pInterceptorHelper->acquire();
    1659           0 : }
    1660             : 
    1661             : 
    1662           0 : sal_Bool BibDataManager::HasActiveConnection()const
    1663             : {
    1664           0 :     sal_Bool bRet = sal_False;
    1665           0 :     Reference< XPropertySet >   xPrSet( m_xForm, UNO_QUERY );
    1666           0 :     if( xPrSet.is() )
    1667             :     {
    1668           0 :         Reference< XComponent >  xConnection;
    1669           0 :         xPrSet->getPropertyValue("ActiveConnection") >>= xConnection;
    1670           0 :         bRet = xConnection.is();
    1671             :     }
    1672           0 :     return bRet;
    1673             : }
    1674             : 
    1675           0 : sal_Bool BibDataManager::HasActiveConnection()
    1676             : {
    1677           0 :     return getConnection( m_xForm ).is();
    1678           3 : }
    1679             : 
    1680             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10