Tag: cws_src680_kaddrbook
User: kendy   
Date: 05/11/29 15:54:42

Modified:
 /dba/dbaccess/source/ui/app/
  AppController.cxx

Log:
 RESYNC: (1.20-1.24); FILE MERGED

File Changes:

Directory: /dba/dbaccess/source/ui/app/
=======================================

File [changed]: AppController.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/app/AppController.cxx?r1=1.20.82.1&r2=1.20.82.2
Delta lines:  +170 -218
-----------------------
--- AppController.cxx   29 Aug 2005 08:51:30 -0000      1.20.82.1
+++ AppController.cxx   29 Nov 2005 23:54:39 -0000      1.20.82.2
@@ -1,22 +1,20 @@
 /*************************************************************************
  *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
  *  $RCSfile$
  *
  *  $Revision$
  *
  *  last change: $Author$ $Date$
  *
- *  The Contents of this file are made available subject to the terms of
- *  either of the following licenses
- *
- *         - GNU Lesser General Public License Version 2.1
- *         - Sun Industry Standards Source License Version 1.1
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
  *
- *  Sun Microsystems Inc., October, 2000
  *
  *  GNU Lesser General Public License Version 2.1
  *  =============================================
- *  Copyright 2000 by Sun Microsystems, Inc.
+ *    Copyright 2005 by Sun Microsystems, Inc.
  *  901 San Antonio Road, Palo Alto, CA 94303, USA
  *
  *  This library is free software; you can redistribute it and/or
@@ -33,41 +31,15 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  *  MA  02111-1307  USA
  *
- *
- *  Sun Industry Standards Source License Version 1.1
- *  =================================================
- *  The contents of this file are subject to the Sun Industry Standards
- *  Source License Version 1.1 (the "License"); You may not use this file
- *  except in compliance with the License. You may obtain a copy of the
- *  License at http://www.openoffice.org/license.html.
- *
- *  Software provided under this License is provided on an "AS IS" basis,
- *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
- *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
- *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
- *  See the License for the specific provisions governing your rights and
- *  obligations concerning the Software.
- *
- *  The Initial Developer of the Original Code is: Sun Microsystems, Inc..
- *
- *  Copyright: 2000 by Sun Microsystems, Inc.
- *
- *  All Rights Reserved.
- *
- *  Contributor(s): Ocke Janssen
- *
- *
  ************************************************************************/
 
 #ifndef DBAUI_APPCONTROLLER_HXX
 #include "AppController.hxx"
 #endif
-#ifndef _COMPHELPER_SEQUENCE_HXX_
-#include <comphelper/sequence.hxx>
-#endif
 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
 #include "dbustrings.hrc"
 #endif
+/** === begin UNO includes === **/
 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
 #include <com/sun/star/container/XNameContainer.hpp>
 #endif
@@ -123,15 +95,17 @@
 #ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_
 #include <com/sun/star/util/XModifiable.hpp>
 #endif
-#ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_
-#include <com/sun/star/util/XCloseable.hpp>
-#endif
-#ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
-#include <com/sun/star/sdbcx/XDrop.hpp>
-#endif
 #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
 #include <com/sun/star/frame/XStorable.hpp>
 #endif
+#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UTIL_XFLUSHABLE_HPP_
+#include <com/sun/star/util/XFlushable.hpp>
+#endif
+/** === end UNO includes === **/
+
 #ifndef _TOOLS_DEBUG_HXX
 #include <tools/debug.hxx>
 #endif
@@ -258,12 +232,12 @@
 #ifndef INCLUDED_SVTOOLS_HISTORYOPTIONS_HXX
 #include <svtools/historyoptions.hxx>
 #endif
-#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
-#include <com/sun/star/frame/FrameSearchFlag.hpp>
-#endif
 #ifndef SVTOOLS_FILENOTATION_HXX_
 #include <svtools/filenotation.hxx>
 #endif
+#ifndef _COMPHELPER_SEQUENCE_HXX_
+#include <comphelper/sequence.hxx>
+#endif
 #ifndef _DBACCESS_SLOTID_HRC_
 #include "dbaccess_slotid.hrc"
 #endif
@@ -344,6 +318,7 @@
 //====================================================================
 //= OApplicationController
 //====================================================================
+DBG_NAME(OApplicationController)
 //--------------------------------------------------------------------
 OApplicationController::OApplicationController(const Reference< 
XMultiServiceFactory >& _rxORB)
        :OApplicationController_CBASE( _rxORB )
@@ -356,6 +331,8 @@
        ,m_eOldType(E_NONE)
     ,m_aTableCopyHelper(this)
 {
+    DBG_CTOR(OApplicationController,NULL);
+
        m_aTypeCollection.initUserDriverTypes(_rxORB);
 }
 
//------------------------------------------------------------------------------
@@ -370,35 +347,43 @@
        }
        ::std::auto_ptr< Window> aTemp(m_pView);
        m_pView = NULL;
+
+    DBG_DTOR(OApplicationController,NULL);
 }
 //--------------------------------------------------------------------
 
IMPLEMENT_FORWARD_XTYPEPROVIDER2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
 
IMPLEMENT_FORWARD_XINTERFACE2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
-//-------------------------------------------------------------------------
-void OApplicationController::disconnect(Reference< XConnection >& _xConnection)
-{
-       ::comphelper::disposeComponent( _xConnection );
-       stopConnectionListening(_xConnection);
-
-       InvalidateAll();
-}
 // 
-----------------------------------------------------------------------------
-void OApplicationController::clearConnections()
+void OApplicationController::disconnect()
 {
+    if ( m_xDataSourceConnection.is() )
+           stopConnectionListening( m_xDataSourceConnection );
+
        try
        {
-               TDataSourceConnections::iterator aIter = 
m_aDataSourceConnections.begin();
-               TDataSourceConnections::iterator aEnd = 
m_aDataSourceConnections.end();
-               for (; aIter != aEnd; ++aIter)
-               {
-                       stopConnectionListening(aIter->second);
-                       ::comphelper::disposeComponent(aIter->second);
-               }
+        // temporary (hopefully!) hack for #i55274#
+        Reference< XFlushable > xFlush( m_xDataSourceConnection, UNO_QUERY );
+        if ( xFlush.is() )
+            xFlush->flush();
+    }
+    catch( const Exception& e )
+    {
+    #if OSL_DEBUG_LEVEL > 0
+        ::rtl::OString sMessage( "OApplicationController::disconnect: caught 
an exception!\n" );
+        sMessage += "message:\n";
+        sMessage += ::rtl::OString( e.Message.getStr(), e.Message.getLength(), 
osl_getThreadTextEncoding() );
+        OSL_ENSURE( false, sMessage );
+    #else
+        e; // make compiler happy
+    #endif
        }
-       catch(Exception)
-       {}
-       m_aDataSourceConnections.clear();
+
+    m_xDataSourceConnection.clear();
+    m_xMetaData.clear();
+
+       InvalidateAll();
 }
+
 //--------------------------------------------------------------------
 void SAL_CALL OApplicationController::disposing()
 {
@@ -416,7 +401,7 @@
                m_pClipbordNotifier = NULL;
        }
 
-       clearConnections();
+       disconnect();
        try
        {
                Reference < XFrame > xFrame;
@@ -430,7 +415,7 @@
                        m_xDataSource = NULL;
                }
 
-               Reference< XModifyBroadcaster >  xBroadcaster(m_xModel, 
UNO_QUERY);
+               Reference< XModifyBroadcaster > xBroadcaster( m_xModel, 
UNO_QUERY );
                if ( xBroadcaster.is() )
                        
xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
 
@@ -452,11 +437,10 @@
                                                getStrippedDatabaseName(),
                                                ::rtl::OUString() );
             }
-                       m_xModel->disconnectController( this );
-                       // forces the data source to reload
-               }
 
-               m_xModel = NULL;
+            m_aModelConnector.clear();
+            m_xModel.clear();
+               }
        }
        catch(Exception)
        {
@@ -469,7 +453,7 @@
 //--------------------------------------------------------------------
 sal_Bool OApplicationController::Construct(Window* _pParent)
 {
-       m_pView = new 
OApplicationView(_pParent,getORB(),this,this,this,this,this,this);
+       m_pView = new 
OApplicationView(_pParent,getORB(),this,this,this,this,this,this,m_ePreviewMode);
        m_pView->SetUniqueId(UID_APP_VIEW);
        
        // late construction
@@ -498,12 +482,6 @@
        if ( getView() )
                getView()->enableSeparator( );
 
-       if ( getContainer() && m_ePreviewMode != 
getContainer()->getPreviewMode() )
-               getContainer()->switchPreview(m_ePreviewMode);
-
-//     if ( getContainer() && m_xDataSource.is() )
-//             getContainer()->setStatusInformations(m_xDataSource);
-
        // now that we have a view we can create the clipboard listener
        m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( 
getView() );
        m_aSystemClipboard.StartClipboardListening( );
@@ -525,24 +503,23 @@
        Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
        if ( xCon.is() )
        {
+        DBG_ASSERT( ( m_xDataSourceConnection == xCon ) && getContainer() && ( 
getContainer()->getElementType() == E_TABLE ),
+            "OApplicationController::disposing: the below code will ignore 
this call - why?" );
+
                if ( getContainer() && getContainer()->getElementType() == 
E_TABLE )
                {
-                       TDataSourceConnections::iterator aIter = 
m_aDataSourceConnections.begin();
-                       TDataSourceConnections::iterator aEnd = 
m_aDataSourceConnections.end();
-                       for (;aIter != aEnd ; ++aIter)
-                       {
-                               if ( aIter->second.is() && aIter->second == 
xCon )
+            if ( m_xDataSourceConnection == xCon )
                                {
                                        getContainer()->clearPages();
-                    m_aDataSourceConnections.erase(aIter);
-                                       break;
-                               }
+                m_xDataSourceConnection.clear();
+                m_xMetaData.clear();
                        }
                }
        }
        else if ( _rSource.Source == m_xModel )
        {
-               m_xModel = NULL;
+               m_xModel.clear();
+        m_aModelConnector.clear();
        }
        else if ( _rSource.Source == m_xDataSource )
        {
@@ -653,7 +630,7 @@
                                                aReturn.bEnabled = 
!isDataSourceReadOnly() && 
getViewClipboard().HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY);
                                                break;
                                        default:
-                                               aReturn.bEnabled = 
!isDataSourceReadOnly() && 
OComponentTransferable::canExtractComponentDescriptor(getViewClipboard().GetDataFlavorExVector());
+                                               aReturn.bEnabled = 
!isDataSourceReadOnly() && 
OComponentTransferable::canExtractComponentDescriptor(getViewClipboard().GetDataFlavorExVector(),getContainer()->getElementType()
 == E_FORM);
                                }
                                break;
                        case SID_DB_APP_PASTE_SPECIAL:
@@ -711,7 +688,7 @@
                                aReturn.bEnabled = !isDataSourceReadOnly() && 
!isConnectionReadOnly();
                                if ( aReturn.bEnabled )
                                {
-                                       Reference<XViewsSupplier> 
xViewsSup(getActiveConnection(),UNO_QUERY);
+                                       Reference<XViewsSupplier> xViewsSup( 
getConnection(), UNO_QUERY );
                                        aReturn.bEnabled = xViewsSup.is();
                                }
                                break;
@@ -794,21 +771,19 @@
                                aReturn.bEnabled = !isDataSourceReadOnly();
                                break;
                        case SID_DB_APP_REFRESH_TABLES:
-                               aReturn.bEnabled = 
getContainer()->getElementType() == E_TABLE && getActiveConnection().is();
+                               aReturn.bEnabled = 
getContainer()->getElementType() == E_TABLE && isConnected();
                                break;
                        case SID_DB_APP_DSPROPS:
                                if ( aReturn.bEnabled = m_xDataSource.is() )
                                {
-                                       static ODsnTypeCollection 
aTypeCollection;
-                                       DATASOURCE_TYPE eType = 
aTypeCollection.getType(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
+                                       DATASOURCE_TYPE eType = 
m_aTypeCollection.getType(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
                                        aReturn.bEnabled = DST_EMBEDDED != 
eType && DST_MOZILLA != eType && DST_EVOLUTION != eType && DST_KAB != eType && 
DST_OUTLOOK != eType && DST_OUTLOOKEXP != eType;
                                }
                                break;
                        case SID_DB_APP_DSCONNECTION_TYPE:
                                if ( aReturn.bEnabled = !isDataSourceReadOnly() 
&& m_xDataSource.is() )
                                {
-                                       static ODsnTypeCollection 
aTypeCollection;
-                                       DATASOURCE_TYPE eType = 
aTypeCollection.getType(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
+                                       DATASOURCE_TYPE eType = 
m_aTypeCollection.getType(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
                                        aReturn.bEnabled = DST_EMBEDDED != 
eType;
                                }
                                break;
@@ -827,8 +802,7 @@
                                        aReturn.bEnabled = eType == E_QUERY && 
getContainer()->getSelectionCount() > 0;
                                        if ( aReturn.bEnabled )
                                        {
-                                               Reference<XConnection> 
xConnection = getActiveConnection();
-                                               Reference<XViewsSupplier> 
xViewSup(xConnection,UNO_QUERY);
+                                               Reference<XViewsSupplier> 
xViewSup( getConnection(), UNO_QUERY );
                                                aReturn.bEnabled = 
xViewSup.is() && Reference<XAppend>(xViewSup->getViews(),UNO_QUERY).is();
                                        }
                                }
@@ -980,13 +954,10 @@
                                        switch( eType )
                                        {
                                                case E_TABLE:
-                            {
-                                Reference<XConnection> xDestConnection;
-                                           ensureConnection(xDestConnection);
-                                                           
m_aTableCopyHelper.pasteTable( aTransferData , getDatabaseName() , 
xDestConnection);
-                            }
+                            m_aTableCopyHelper.pasteTable( aTransferData , 
getDatabaseName(), ensureConnection() );
                                                        break;
                                                case E_QUERY:
+                            if ( 
getViewClipboard().HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY) )
                                                        paste( 
E_QUERY,ODataAccessObjectTransferable::extractObjectDescriptor(aTransferData) );
                                                        break;
                                                default:
@@ -1193,8 +1164,7 @@
                        case ID_NEW_VIEW_DESIGN:
                        case SID_DB_NEW_VIEW_SQL:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection);
+                    SharedConnection xConnection( ensureConnection() );
                                        if ( xConnection.is() )
                                        {
                                                OQueryDesignAccess 
aHelper(getORB(),sal_True,SID_DB_NEW_VIEW_SQL == _nId );
@@ -1240,20 +1210,18 @@
                                break;
                        case SID_DB_APP_DSRELDESIGN:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection);
+                                       SharedConnection xConnection( 
ensureConnection() );
                                        if ( xConnection.is() )
                                        {
                                                ORelationDesignAccess 
aHelper(getORB());
-                                               Reference< XComponent > 
xComponent(aHelper.create(Reference<XDataSource>(m_xDataSource,UNO_QUERY), 
getActiveConnection()),UNO_QUERY);
+                                               Reference< XComponent > 
xComponent(aHelper.create(Reference<XDataSource>(m_xDataSource,UNO_QUERY), 
xConnection),UNO_QUERY);
                                                
addDocumentListener(xComponent,NULL);
                                        }
                                }
                                break;
                        case SID_DB_APP_DSUSERADMIN:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection);
+                                       SharedConnection xConnection( 
ensureConnection() );
                                        if ( xConnection.is() )
                                                
openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.UserAdministrationDialog")));
                                }
@@ -1279,8 +1247,7 @@
                                break;
                        case ID_DIRECT_SQL:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection);
+                                       SharedConnection xConnection( 
ensureConnection() );
                                        if ( xConnection.is() )
                                                openDirectSQLDialog();
                                }
@@ -1368,8 +1335,6 @@
                                                                                
         CommandGroup::INSERT );
     implDescribeSupportedFeature( ".uno:DBNewView",          
ID_NEW_VIEW_DESIGN,        CommandGroup::INSERT );
     implDescribeSupportedFeature( ".uno:DBNewViewSQL",       
SID_DB_NEW_VIEW_SQL,       CommandGroup::INSERT );
-    implDescribeSupportedFeature( ".uno:DBNewViewAutoPilot", 
ID_NEW_VIEW_DESIGN_AUTO_PILOT,
-                                                                               
         CommandGroup::INSERT );
 
     implDescribeSupportedFeature( ".uno:DBDelete",           
SID_DB_APP_DELETE,         CommandGroup::EDIT );
        implDescribeSupportedFeature( ".uno:Delete",                     
SID_DB_APP_DELETE,         CommandGroup::EDIT );
@@ -1426,16 +1391,16 @@
     implDescribeSupportedFeature( ".uno:DBShowDocPreview",   
SID_DB_APP_VIEW_DOC_PREVIEW,
                                                                                
         CommandGroup::VIEW );
 
-       implDescribeSupportedFeature( ".uno:DBDSImport",                
SID_DB_APP_DSIMPORT);
-       implDescribeSupportedFeature( ".uno:DBDSExport",                
SID_DB_APP_DSEXPORT);
-
-       implDescribeSupportedFeature( ".uno:DBDBAdmin",                 
SID_DB_APP_DBADMIN);
+    // this one should not appear under Tools->Customize->Keyboard
+       implDescribeSupportedFeature( ".uno:DBDSImport",                
SID_DB_APP_DSIMPORT, CommandGroup::INTERNAL);
+       implDescribeSupportedFeature( ".uno:DBDSExport",                
SID_DB_APP_DSEXPORT, CommandGroup::INTERNAL);
+       implDescribeSupportedFeature( ".uno:DBDBAdmin",                 
SID_DB_APP_DBADMIN, CommandGroup::INTERNAL);
 
        // status info
-       implDescribeSupportedFeature( ".uno:DBStatusType",              
SID_DB_APP_STATUS_TYPE);
-       implDescribeSupportedFeature( ".uno:DBStatusDBName",    
SID_DB_APP_STATUS_DBNAME);
-       implDescribeSupportedFeature( ".uno:DBStatusUserName",  
SID_DB_APP_STATUS_USERNAME);
-       implDescribeSupportedFeature( ".uno:DBStatusHostName",  
SID_DB_APP_STATUS_HOSTNAME);
+       implDescribeSupportedFeature( ".uno:DBStatusType",              
SID_DB_APP_STATUS_TYPE, CommandGroup::INTERNAL);
+       implDescribeSupportedFeature( ".uno:DBStatusDBName",    
SID_DB_APP_STATUS_DBNAME, CommandGroup::INTERNAL);
+       implDescribeSupportedFeature( ".uno:DBStatusUserName",  
SID_DB_APP_STATUS_USERNAME, CommandGroup::INTERNAL);
+       implDescribeSupportedFeature( ".uno:DBStatusHostName",  
SID_DB_APP_STATUS_HOSTNAME, CommandGroup::INTERNAL);
 }
 // 
-----------------------------------------------------------------------------
 OApplicationView*      OApplicationController::getContainer() const
@@ -1464,13 +1429,12 @@
                {
                        ::rtl::OUString sName;
                        _rEvent.Accessor >>= sName;
-                       Reference<XConnection> xConnection;
                        ElementType eType = getElementType(xContainer);
 
                        switch( eType )
                        {
                                case E_TABLE:
-                                       ensureConnection(xConnection);
+                                       ensureConnection();
                                        break;
                                case E_FORM:
                                case E_REPORT:
@@ -1481,7 +1445,7 @@
                                        }
                                        break;
                        }
-                       
getContainer()->elementAdded(eType,sName,_rEvent.Element,xConnection);
+                       
getContainer()->elementAdded(eType,sName,_rEvent.Element,getConnection());
                }
        }
 }
@@ -1497,12 +1461,11 @@
                OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
                ::rtl::OUString sName;
                _rEvent.Accessor >>= sName;
-               Reference<XConnection> xConnection;
                ElementType eType = getElementType(xContainer);
                switch( eType )
                {
                        case E_TABLE:
-                               ensureConnection(xConnection);
+                               ensureConnection();
                                break;
                        case E_FORM:
                        case E_REPORT:
@@ -1515,7 +1478,7 @@
                                }
                                break;
                }
-               getContainer()->elementRemoved(eType,sName,xConnection);
+               getContainer()->elementRemoved(eType,sName,getConnection());
        }
 }
 // 
-----------------------------------------------------------------------------
@@ -1540,10 +1503,12 @@
                        switch( eType )
                        {
                                case E_TABLE:
-                                       ensureConnection(xConnection);
-                                       if ( xProp.is() && xConnection.is() )
                                        {
-                                               sNewName = 
::dbaui::composeTableName(xConnection->getMetaData(),xProp,sal_False,::dbtools::eInDataManipulation);
+                                       ensureConnection();
+                                       if ( xProp.is() && m_xMetaData.is() )
+                                       {
+                                               sNewName = 
::dbaui::composeTableName(m_xMetaData,xProp,sal_False,::dbtools::eInDataManipulation);
+                                       }
                                        }
                                        break;
                                case E_FORM:
@@ -1606,9 +1571,7 @@
                {
                        try
                        {
-                               Reference<XConnection> xConnection;
-                               ensureConnection(xConnection);
-
+                               SharedConnection xConnection( 
ensureConnection() );
                                if ( xConnection.is() && 
getContainer()->getDetailView() )
                                {
                                        
getContainer()->getDetailView()->createTablesPage(xConnection);
@@ -1657,28 +1620,9 @@
        OSL_ENSURE(_pTree != NULL,"Who called me without a svtreelsiboc! ->GPF 
");
        if ( getContainer() && getContainer()->isLeaf(_pTree->GetHdlEntry()) )
        {
-               ElementType eType = getContainer()->getElementType();
-
-               Reference<XDatabaseMetaData> xMetaData;
-               if ( eType == E_TABLE )
-               {
-                       Reference<XConnection> xConnection;
-                       ensureConnection(xConnection);
-                       if ( xConnection.is() )
-                       {
                                try
                                {
-                                       xMetaData = xConnection->getMetaData();
-                               }
-                               catch(const Exception&)
-                               {
-                                       OSL_ENSURE(0,"Exception catched!");
-                               }
-                       }
-               }
-               try
-               {
-                       
openElement(getContainer()->getQualifiedName(_pTree->GetHdlEntry(),xMetaData),eType);
+                       openElement( getContainer()->getQualifiedName( 
_pTree->GetHdlEntry(), m_xMetaData ), getContainer()->getElementType() );
                }
                catch(const Exception&)
                {
@@ -1711,8 +1655,7 @@
                case E_TABLE:
                        {
                                ::std::auto_ptr< ODesignAccess> pDispatcher;
-                               Reference<XConnection> xConnection;
-                               ensureConnection(xConnection);
+                               SharedConnection xConnection( 
ensureConnection() );
                                if ( xConnection.is() )
                                {
                                        Sequence < PropertyValue > aArgs;
@@ -1751,7 +1694,7 @@
 // 
-----------------------------------------------------------------------------
 IMPL_LINK( OApplicationController, OnCreateWithPilot, void*, _pType )
 {
-    ElementType eType = (ElementType)reinterpret_cast< int >( _pType );
+    ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
     newElementWithPilot( eType );
     return 0L;
 }
@@ -1778,16 +1721,7 @@
                            {
                                    try
                                    {
-                                           Reference< XDatabaseMetaData> 
xMetaData;
-                                           if ( CommandType::TABLE == 
nCommandType )
-                                           {
-                                                   
ensureConnection(xConnection,sal_False);
-
-                                                   if ( xConnection.is() )
-                                                           xMetaData = 
xConnection->getMetaData();
-                                           }
-
-                                           sName = 
getContainer()->getQualifiedName(NULL,xMetaData);
+                                           sName = 
getContainer()->getQualifiedName( NULL, m_xMetaData );
                         OSL_ENSURE( sName.getLength(), 
"OApplicationController::newElementWithPilot: no name given!" );
                                    }
                                    catch(Exception)
@@ -1845,8 +1779,8 @@
                case E_TABLE:
                        {
                                ::std::auto_ptr< ODesignAccess> pDispatcher;
-                               Reference<XConnection> xConnection;
-                               if ( ensureConnection( xConnection ) )
+                               SharedConnection xConnection( 
ensureConnection() );
+                               if ( xConnection.is() )
                                {
                                        if ( _eType == E_TABLE )
                                        {
@@ -1897,12 +1831,13 @@
 
        Reference< XNameAccess > xContainer = 
getElements(getContainer()->getElementType());
        OSL_ENSURE(aList.size() == 1,"Invalid rename call here. More than one 
element!");
+  if ( aList.empty() )
+    return;
 
        try
        {
                if ( xContainer.is() )
                {
-                       Reference<XConnection> xConnection = 
getActiveConnection();
             ::std::auto_ptr<OSaveAsDlg> aDlg;
                        Reference<XRename> xRename;
                        ElementType eType = getContainer()->getElementType();
@@ -1944,7 +1879,8 @@
                                        }
                                        break;
                                case E_TABLE:
-                    if ( !ensureConnection( xConnection, sal_True ) )
+                    ensureConnection();
+                    if ( !getConnection().is() )
                         break;
                     // NO break
                                case E_QUERY:
@@ -1952,10 +1888,10 @@
                                        {
                                                
xRename.set(xContainer->getByName(*aList.begin()),UNO_QUERY);
                         sal_Int32 nCommandType = eType == E_QUERY ? 
CommandType::QUERY : CommandType::TABLE;
+
                                            aDlg.reset( new OSaveAsDlg(
                             getView(), nCommandType, xContainer,
-                            xConnection.is() ? xConnection->getMetaData() : 
Reference< XDatabaseMetaData >(),
-                            xConnection, *aList.begin(), SAD_TITLE_RENAME) );
+                            m_xMetaData, getConnection(), *aList.begin(), 
SAD_TITLE_RENAME) );
                                        }
                                        break;
                        }
@@ -1977,7 +1913,7 @@
                                                                ::rtl::OUString 
sCatalog = aDlg->getCatalog();
                                                                ::rtl::OUString 
sSchema  = aDlg->getSchema();
 
-                                                               
::dbtools::composeTableName(xConnection->getMetaData(),sCatalog,sSchema,sName,sNewName,sal_False,::dbtools::eInTableDefinitions);
+                                                               
::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sName, sNewName, 
sal_False, ::dbtools::eInTableDefinitions );
                                                        }
                                                        else
                                                                sNewName = 
aDlg->getName();
@@ -1994,8 +1930,8 @@
 
                                                        
xRename->rename(sNewName);
 
-                                                       if ( ! Reference< 
XNameAccess >(xRename,UNO_QUERY).is() )
-                                                               
getContainer()->elementReplaced(getContainer()->getElementType(),sOldName,sNewName,xConnection);
+                                                       if ( !Reference< 
XNameAccess >( xRename, UNO_QUERY ).is() )
+                                                               
getContainer()->elementReplaced( getContainer()->getElementType(), sOldName, 
sNewName, getConnection() );
 
                                                        bTryAgain = sal_False;
                                                }
@@ -2065,8 +2001,7 @@
                             ::rtl::OUString sName = pView->getQualifiedName( 
_pEntry,NULL);
                             if ( pView->isPreviewEnabled() )
                             {
-                                Reference<XConnection> xConnection;
-                                                           
ensureConnection(xConnection);
+                                SharedConnection xConnection( 
ensureConnection() );
                                                            if ( 
xConnection.is() )
                                                                
pView->showPreview(getDatabaseName(),xConnection,sName,sal_False);
                             }
@@ -2075,8 +2010,7 @@
                         break;
                                        case E_TABLE:
                                                {
-                                                       Reference<XConnection> 
xConnection;
-                                                       
ensureConnection(xConnection);
+                            SharedConnection xConnection( ensureConnection() );
                                                        if ( xConnection.is() )
                                                        {
                                                                ::rtl::OUString 
sName = pView->getQualifiedName( _pEntry,xConnection->getMetaData());
@@ -2222,7 +2156,7 @@
                                return DND_ACTION_COPY;
                        if ( eType == E_FORM || eType == E_REPORT )
                        {
-                               sal_Int8 nAction = 
OComponentTransferable::canExtractComponentDescriptor(_rFlavors) ? 
DND_ACTION_COPY : DND_ACTION_NONE;
+                               sal_Int8 nAction = 
OComponentTransferable::canExtractComponentDescriptor(_rFlavors,eType == 
E_FORM) ? DND_ACTION_COPY : DND_ACTION_NONE;
                                if ( nAction != DND_ACTION_NONE )
                                {
                                        SvLBoxEntry* pHitEntry = 
pView->getEntry(_rEvt.maPosPixel);
@@ -2243,8 +2177,9 @@
                                                                nAction = 
DND_ACTION_NONE;
                                                }
                                        }
-                                       else
+                                       /*else
                                                nAction = nActionAskedFor & 
DND_ACTION_COPYMOVE;
+                    */
                                }
                                return nAction;
                        }
@@ -2292,7 +2227,7 @@
                m_nAsyncDrop = Application::PostUserEvent(LINK(this, 
OApplicationController, OnAsyncDrop));
                return DND_ACTION_COPY;
        }
-       else if ( 
OComponentTransferable::canExtractComponentDescriptor(aDroppedData.GetDataFlavorExVector())
 )
+       else if ( 
OComponentTransferable::canExtractComponentDescriptor(aDroppedData.GetDataFlavorExVector(),m_aAsyncDrop.nType
 == E_FORM) )
        {
                m_aAsyncDrop.aDroppedData = 
OComponentTransferable::extractComponentDescriptor(aDroppedData);
                SvLBoxEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
@@ -2345,9 +2280,8 @@
        }
        else
        {
-        Reference<XConnection> xDestConnection;         // supports the 
service sdb::connection
-           ensureConnection( xDestConnection);
-           if ( xDestConnection.is() && 
m_aTableCopyHelper.copyTagTable(aDroppedData,m_aAsyncDrop,xDestConnection) )
+        SharedConnection xConnection( ensureConnection() );
+        if ( xConnection.is() && m_aTableCopyHelper.copyTagTable( 
aDroppedData, m_aAsyncDrop, xConnection ) )
         {
                        // asyncron because we some dialogs and we aren't 
allowed to show them while in D&D
                        m_nAsyncDrop = Application::PostUserEvent(LINK(this, 
OApplicationController, OnAsyncDrop));
@@ -2363,13 +2297,30 @@
        return m_xModel;
 }
 // 
-----------------------------------------------------------------------------
-sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel 
> & xModel) throw( RuntimeException )
+sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel 
> & _rxModel) throw( RuntimeException )
 {
-       ::osl::MutexGuard aGuard(m_aMutex);
-       m_xModel = xModel;
-    Reference<XOfficeDatabaseDocument> xOfficeDoc(m_xModel,UNO_QUERY);
+       ::osl::MutexGuard aGuard( m_aMutex );
+    Reference< XOfficeDatabaseDocument > xOfficeDoc( _rxModel, UNO_QUERY );
+    if ( !xOfficeDoc.is() && _rxModel.is() )
+    {
+        DBG_ERROR( "OApplicationController::attachModel: invalid model!" );
+        return sal_False;
+    }
+
+    DBG_ASSERT( !( m_xModel.is() && ( m_xModel != _rxModel ) ),
+        "OApplicationController::attachModel: missing implementation: setting 
a new model while we have another one!" );
+        // at least: remove as property change listener from the old 
model/data source
+
+    m_xModel = _rxModel;
+    if ( _rxModel.is() )
+        m_aModelConnector = ModelControllerConnector( _rxModel, this );
+    else
+        m_aModelConnector.clear();
+
     m_xDataSource.set(xOfficeDoc.is() ? xOfficeDoc->getDataSource() : 
Reference<XDataSource>(),UNO_QUERY);
-       if ( m_xDataSource.is() )
+       if ( !m_xDataSource.is() )
+        m_sDatabaseName = ::rtl::OUString();
+    else
        {
                try
                {
@@ -2404,10 +2355,11 @@
                }
                catch(Exception)
                {
-                       OSL_ENSURE(0,"Exception catched while set property 
listener");
+            OSL_ENSURE( false, "OApplicationController::attachModel: caught an 
exception while doing the property stuff!" );
                }
        }
-       return m_sDatabaseName.getLength() != 0;
+
+       return sal_True;
 }
 // 
-----------------------------------------------------------------------------
 void OApplicationController::containerFound( const Reference< XContainer >& 
_xContainer)




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to