LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/bibliography - datman.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 804 0.0 %
Date: 2012-12-27 Functions: 0 69 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10