Tag: cws_src680_dba24d
User: fs      
Date: 2007-11-12 12:14:47+0000
Modified:
   dba/dbaccess/source/ui/uno/copytablewizard.cxx

Log:
 #i81658# call the listeners

File Changes:

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

File [changed]: copytablewizard.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/uno/copytablewizard.cxx?r1=1.1.2.2&r2=1.1.2.3
Delta lines:  +105 -25
----------------------
--- copytablewizard.cxx 2007-11-08 21:30:20+0000        1.1.2.2
+++ copytablewizard.cxx 2007-11-12 12:14:45+0000        1.1.2.3
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: copytablewizard.cxx,v $
  *
- *  $Revision: 1.1.2.2 $
+ *  $Revision: 1.1.2.3 $
  *
- *  last change: $Author: fs $ $Date: 2007/11/08 21:30:20 $
+ *  last change: $Author: fs $ $Date: 2007/11/12 12:14:45 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -43,6 +43,7 @@
 /** === begin UNO includes === **/
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/sdb/application/XCopyTableWizard.hpp>
+#include <com/sun/star/sdb/application/CopyTableContinuation.hpp>
 #include <com/sun/star/sdb/application/CopyTableOperation.hpp>
 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
 #include <com/sun/star/lang/NotInitializedException.hpp>
@@ -74,6 +75,7 @@
 #include <cppuhelper/implbase1.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <svtools/genericunodialog.hxx>
+#include <tools/diagnose_ex.h>
 #include <unotools/sharedunocomponent.hxx>
 #include <vcl/msgbox.hxx>
 #include <vcl/waitobj.hxx>
@@ -99,6 +101,7 @@
     using ::com::sun::star::beans::Property;
     using ::com::sun::star::sdb::application::XCopyTableWizard;
     using ::com::sun::star::sdb::application::XCopyTableListener;
+    using ::com::sun::star::sdb::application::CopyTableRowEvent;
     using ::com::sun::star::beans::Optional;
     using ::com::sun::star::lang::IllegalArgumentException;
     using ::com::sun::star::ucb::AlreadyInitializedException;
@@ -130,6 +133,7 @@
     using ::com::sun::star::sdbc::SQLException;
        /** === end UNO using === **/
     namespace CopyTableOperation = 
::com::sun::star::sdb::application::CopyTableOperation;
+    namespace CopyTableContinuation = 
::com::sun::star::sdb::application::CopyTableContinuation;
     namespace CommandType = ::com::sun::star::sdb::CommandType;
     namespace DataType = ::com::sun::star::sdbc::DataType;
 
@@ -186,6 +190,7 @@
 
     protected:
            CopyTableWizard( const Reference< XMultiServiceFactory >& _rxORB );
+        ~CopyTableWizard();
 
         // OGenericUnoDialog overridables
            virtual Dialog*     createDialog( Window* _pParent );
@@ -272,7 +277,20 @@
         void    impl_copyRows_throw(
                     const Reference< XResultSet >& _rxSourceResultSet,
                     const Reference< XPropertySet >& _rxDestTable
-                ) const;
+                );
+
+        /** processes an error which occured during copying
+
+            First, all listeners are ask. If a listener tells to cancel or 
continue copying, this is reported to the
+            method's caller. If a listener tells to ask the user, this is 
done, and the user's decision is
+            reported to the method's caller.
+
+            @return
+                <TRUE/> if and only if copying should be continued.
+        */
+        bool    impl_processCopyError_nothrow(
+                    const CopyTableRowEvent& _rEvent );
+
 private:
         ::comphelper::ComponentContext  m_aContext;
 
@@ -337,6 +355,11 @@
     }
 
     //-------------------------------------------------------------------------
+    CopyTableWizard::~CopyTableWizard()
+    {
+    }
+
+    //-------------------------------------------------------------------------
     Reference< XInterface > CopyTableWizard::Create( const Reference< 
XMultiServiceFactory >& _rxFactory )
     {
            return *( new CopyTableWizard( _rxFactory ) );
@@ -448,6 +471,7 @@
     void SAL_CALL CopyTableWizard::addCopyTableListener( const Reference< 
XCopyTableListener >& _rxListener ) throw (RuntimeException)
     {
         CopyTableAccessGuard aGuard( *this );
+        if ( _rxListener.is() )
         m_aCopyTableListeners.addInterface( _rxListener );
     }
     
@@ -455,6 +479,7 @@
     void SAL_CALL CopyTableWizard::removeCopyTableListener( const Reference< 
XCopyTableListener >& _rxListener ) throw (RuntimeException)
     {
         CopyTableAccessGuard aGuard( *this );
+        if ( _rxListener.is() )
         m_aCopyTableListeners.removeInterface( _rxListener );
     }
     
@@ -851,12 +876,66 @@
     }
 
     //-------------------------------------------------------------------------
+    bool CopyTableWizard::impl_processCopyError_nothrow( const 
CopyTableRowEvent& _rEvent )
+    {
+        Reference< XCopyTableListener > xListener;
+        try
+        {
+            ::cppu::OInterfaceIteratorHelper aIter( m_aCopyTableListeners );
+            while ( aIter.hasMoreElements() )
+            {
+                xListener.set( aIter.next(), UNO_QUERY_THROW );
+                sal_Int16 nListenerChoice = xListener->copyRowError( _rEvent );
+                switch ( nListenerChoice )
+                {
+                case CopyTableContinuation::Proceed:            return true;   
 // continue copying
+                case CopyTableContinuation::CallNextHandler:    continue;      
 // continue the loop, ask next listener
+                case CopyTableContinuation::Cancel:             return false;  
 // cancel copying
+                case CopyTableContinuation::AskUser:            break;         
 // stop asking the listeners, ask the user
+
+                default:
+                    OSL_ENSURE( false, 
"CopyTableWizard::impl_processCopyError_nothrow: invalid listener response!" );
+                    // ask next listener
+                    continue;
+                }
+            }
+        }
+        catch( const Exception& )
+        {
+               DBG_UNHANDLED_EXCEPTION();
+        }
+
+        // no listener felt responsible for the error, or a listener told to 
ask the user
+
+        // TODO: interaction handler
+        String sAskIfContinue = String( ModuleRes( 
STR_ERROR_OCCURED_WHILE_COPYING ) );
+        String sTitle = String( ModuleRes( STR_STAT_WARNING ) );
+
+        ::dbtools::SQLExceptionInfo aInfo( _rEvent.Error );
+        OSQLMessageBox aDlg(
+            impl_getDialog_throw().GetParent(),
+            sTitle,
+            sAskIfContinue,
+            WB_YES_NO | WB_DEF_YES,
+            OSQLMessageBox::Warning,
+            aInfo.isValid() ? &aInfo : NULL
+        );
+
+        if ( aDlg.Execute() == RET_YES )
+            // continue copying
+            return true;
+
+        // cancel copying
+        return false;
+    }
+
+    //-------------------------------------------------------------------------
     void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& 
_rxSourceResultSet,
-        const Reference< XPropertySet >& _rxDestTable ) const
+        const Reference< XPropertySet >& _rxDestTable )
     {
         OSL_PRECOND( m_xDestConnection.is(), 
"CopyTableWizard::impl_copyRows_throw: illegal call!" );
         if ( !m_xDestConnection.is() )
-            throw RuntimeException( ::rtl::OUString(), *const_cast< 
CopyTableWizard* >( this ) );
+            throw RuntimeException( ::rtl::OUString(), *this );
 
         Reference< XDatabaseMetaData > xDestMetaData( 
m_xDestConnection->getMetaData(), UNO_QUERY_THROW );
 
@@ -873,7 +952,7 @@
             ::dbtools::throwGenericSQLException(
                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "The copy 
source's result set must support bookmarks." ) ),
                 // TODO: resource: STR_CTW_COPY_SOURCE_NEEDS_BOOKMARKS
-                *const_cast< CopyTableWizard* >( this )
+                *this
             );
         }
 
@@ -897,6 +976,11 @@
         const Any* pSelectedRow = m_aSourceSelection.getConstArray();
         const Any* pSelEnd      = pSelectedRow + 
m_aSourceSelection.getLength();
         bool bContinue = false;
+
+        CopyTableRowEvent aCopyEvent;
+        aCopyEvent.Source = *this;
+        aCopyEvent.SourceData = _rxSourceResultSet;
+
         do // loop as long as there are more rows or the selection ends
         {
             bContinue = false;
@@ -927,9 +1011,12 @@
             sal_Bool bInsertAutoIncrement = sal_True;
             ODatabaseExport::TPositions::const_iterator aPosIter = 
aColumnMapping.begin();
 
-            ::dbtools::SQLExceptionInfo aInfo;
+            aCopyEvent.Error.clear();
             try
             {
+                // notify listeners
+                m_aCopyTableListeners.notifyEach( 
&XCopyTableListener::copyingRow, aCopyEvent );
+
                 sal_Int32 nDestColumn( 0 );
                 sal_Int32 nSourceColumn( 1 );
                 ValueTransfer aTransfer( nSourceColumn, nDestColumn, 
aSourceColTypes, xRow, xStatementParams );
@@ -956,7 +1043,7 @@
                         ::dbtools::throwSQLException(
                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"Internal error: invalid column type index." ) ),
                             ::dbtools::SQL_INVALID_DESCRIPTOR_INDEX,
-                            *const_cast< CopyTableWizard* >( this )
+                            *this
                         );
                     }
 
@@ -1029,31 +1116,24 @@
                             ::dbtools::throwSQLException(
                                 aMessage,
                                 ::dbtools::SQL_INVALID_SQL_DATA_TYPE,
-                                *const_cast< CopyTableWizard* >( this )
+                                *this
                             );
                         }
                     }
                     ++nSourceColumn;
                 }
                 xStatement->executeUpdate();
+
+                // notify listeners
+                m_aCopyTableListeners.notifyEach( 
&XCopyTableListener::copiedRow, aCopyEvent );
             }
-            catch( const SQLException& )
+            catch( const Exception& )
             {
-                aInfo = ::cppu::getCaughtException();
+                aCopyEvent.Error = ::cppu::getCaughtException();
             }
 
-            if ( aInfo.isValid() )
-            {
-                String sAskIfContinue = String( ModuleRes( 
STR_ERROR_OCCURED_WHILE_COPYING ) );
-                String sTitle = String( ModuleRes( STR_STAT_WARNING ) );
-
-                OSQLMessageBox aDlg( rWizard.GetParent(), sTitle, 
sAskIfContinue, WB_YES_NO | WB_DEF_YES, OSQLMessageBox::Warning, &aInfo );
-                // TODO: interaction handler
-                if ( aDlg.Execute() != RET_YES )
-                {
-                    aInfo.doThrow();
-                }
-            }
+            if ( aCopyEvent.Error.hasValue() )
+                bContinue = impl_processCopyError_nothrow( aCopyEvent );
         }
         while( bContinue );
     }




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

Reply via email to