Tag: cws_src680_qiq User: fs Date: 06/05/19 03:54:39 Modified: /dba/dbaccess/source/ui/dlg/ sqlmessage.cxx
Log: during #i51143#: display the More button only if there is more to display File Changes: Directory: /dba/dbaccess/source/ui/dlg/ ======================================= File [changed]: sqlmessage.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/dlg/sqlmessage.cxx?r1=1.20.118.3&r2=1.20.118.4 Delta lines: +313 -143 ----------------------- --- sqlmessage.cxx 11 May 2006 11:26:56 -0000 1.20.118.3 +++ sqlmessage.cxx 19 May 2006 10:54:36 -0000 1.20.118.4 @@ -4,9 +4,9 @@ * * $RCSfile: sqlmessage.cxx,v $ * - * $Revision: 1.20.118.3 $ + * $Revision: 1.20.118.4 $ * - * last change: $Author: fs $ $Date: 2006/05/11 11:26:56 $ + * last change: $Author: fs $ $Date: 2006/05/19 10:54:36 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -95,6 +95,221 @@ { //......................................................................... +namespace +{ + //------------------------------------------------------------------------------ + class IImageProvider + { + public: + virtual Image getImage( bool _highContrast ) const = 0; + + virtual ~IImageProvider() { } + }; + + //------------------------------------------------------------------------------ + class ILabelProvider + { + public: + virtual String getLabel() const = 0; + + virtual ~ILabelProvider() { }; + }; + + //------------------------------------------------------------------------------ + class ImageProvider : public IImageProvider + { + private: + USHORT m_defaultImageID; + USHORT m_highContrastImageID; + + mutable Image m_defaultImage; + mutable Image m_highContrastImage; + + public: + ImageProvider( USHORT _defaultImageID, USHORT _highContrastImageID ) + :m_defaultImageID( _defaultImageID ) + ,m_highContrastImageID( _highContrastImageID ) + { + } + + virtual Image getImage( bool _highContrast ) const + { + if ( _highContrast ) + { + if ( !m_highContrastImage ) + m_highContrastImage = Image( ModuleRes( m_highContrastImageID ) ); + return m_highContrastImage; + } + + if ( !m_defaultImage ) + m_defaultImage = Image( ModuleRes( m_defaultImageID ) ); + return m_defaultImage; + } + }; + + //------------------------------------------------------------------------------ + class LabelProvider : public ILabelProvider + { + private: + String m_label; + public: + LabelProvider( USHORT _labelResourceID ) + :m_label( ModuleRes( _labelResourceID ) ) + { + } + + virtual String getLabel() const + { + return m_label; + } + }; + + //------------------------------------------------------------------------------ + class ProviderFactory + { + private: + mutable ::boost::shared_ptr< IImageProvider > m_pErrorImage; + mutable ::boost::shared_ptr< IImageProvider > m_pWarningsImage; + mutable ::boost::shared_ptr< IImageProvider > m_pInfoImage; + mutable ::boost::shared_ptr< ILabelProvider > m_pErrorLabel; + mutable ::boost::shared_ptr< ILabelProvider > m_pWarningsLabel; + mutable ::boost::shared_ptr< ILabelProvider > m_pInfoLabel; + + public: + ProviderFactory() + { + } + + ::boost::shared_ptr< IImageProvider > getImageProvider( SQLExceptionInfo::TYPE _eType ) const + { + ::boost::shared_ptr< IImageProvider >* ppProvider( &m_pErrorImage ); + USHORT nNormalImageID( BMP_EXCEPTION_ERROR ); + USHORT nHCImageID( BMP_EXCEPTION_ERROR_SCH ); + + switch ( _eType ) + { + case SQLExceptionInfo::SQL_WARNING: + ppProvider = &m_pWarningsImage; + nNormalImageID = BMP_EXCEPTION_WARNING; + nHCImageID = BMP_EXCEPTION_WARNING_SCH; + break; + + case SQLExceptionInfo::SQL_CONTEXT: + ppProvider = &m_pInfoImage; + nNormalImageID = BMP_EXCEPTION_INFO; + nHCImageID = BMP_EXCEPTION_INFO_SCH; + break; + } + + if ( !ppProvider->get() ) + ppProvider->reset( new ImageProvider( nNormalImageID, nHCImageID ) ); + return *ppProvider; + } + + ::boost::shared_ptr< ILabelProvider > getLabelProvider( SQLExceptionInfo::TYPE _eType, bool _bSubLabel ) const + { + ::boost::shared_ptr< ILabelProvider >* ppProvider( &m_pErrorLabel ); + USHORT nLabelID( STR_EXCEPTION_ERROR ); + + switch ( _eType ) + { + case SQLExceptionInfo::SQL_WARNING: + ppProvider = &m_pWarningsLabel; + nLabelID = STR_EXCEPTION_WARNING; + break; + + case SQLExceptionInfo::SQL_CONTEXT: + ppProvider = &m_pInfoLabel; + nLabelID = _bSubLabel ? STR_EXCEPTION_DETAILS : STR_EXCEPTION_INFO; + break; + } + + if ( !ppProvider->get() ) + ppProvider->reset( new LabelProvider( nLabelID ) ); + return *ppProvider; + } + + }; + + //------------------------------------------------------------------------------ + /// a stripped version of the SQLException, packed for displaying + struct ExceptionDisplayInfo + { + SQLExceptionInfo::TYPE eType; + + ::boost::shared_ptr< IImageProvider > pImageProvider; + ::boost::shared_ptr< ILabelProvider > pLabelProvider; + + bool bSubEntry; + + String sMessage; + String sSQLState; + String sErrorCode; + + ExceptionDisplayInfo() : bSubEntry( false ), eType( SQLExceptionInfo::UNDEFINED ) { } + ExceptionDisplayInfo( SQLExceptionInfo::TYPE _eType ) : bSubEntry( false ), eType( _eType ) { } + }; + + typedef ::std::vector< ExceptionDisplayInfo > ExceptionDisplayChain; + + //------------------------------------------------------------------------------ + void lcl_buildExceptionChain( const SQLExceptionInfo& _rErrorInfo, const ProviderFactory& _rFactory, ExceptionDisplayChain& _out_rChain ) + { + { + ExceptionDisplayChain empty; + _out_rChain.swap( empty ); + } + + SQLExceptionIteratorHelper iter( _rErrorInfo ); + while ( iter.hasMoreElements() ) + { + // current chain element + SQLExceptionInfo aCurrentElement; + iter.next( aCurrentElement ); + + const SQLException* pCurrentError = (const SQLException*)aCurrentElement; + DBG_ASSERT( pCurrentError, "lcl_buildExceptionChain: iterator failure!" ); + // hasMoreElements should not have returned <TRUE/> in this case + + ExceptionDisplayInfo aDisplayInfo( aCurrentElement.getType() ); + + aDisplayInfo.sMessage = pCurrentError->Message; + aDisplayInfo.sSQLState = pCurrentError->SQLState; + if ( pCurrentError->ErrorCode ) + aDisplayInfo.sErrorCode = String::CreateFromInt32( pCurrentError->ErrorCode ); + + aDisplayInfo.pImageProvider = _rFactory.getImageProvider( aCurrentElement.getType() ); + aDisplayInfo.pLabelProvider = _rFactory.getLabelProvider( aCurrentElement.getType(), false ); + + _out_rChain.push_back( aDisplayInfo ); + + if ( aCurrentElement.getType() == SQLExceptionInfo::SQL_CONTEXT ) + { + const SQLContext* pContext = (const SQLContext*)aCurrentElement; + if ( pContext->Details.getLength() ) + { + ExceptionDisplayInfo aSubInfo( aCurrentElement.getType() ); + + aSubInfo.sMessage = pContext->Details; + aSubInfo.pImageProvider = _rFactory.getImageProvider( aCurrentElement.getType() ); + aDisplayInfo.pLabelProvider = _rFactory.getLabelProvider( aCurrentElement.getType(), true ); + + _out_rChain.push_back( aSubInfo ); + } + } + } + } + + //------------------------------------------------------------------------------ + void lcl_insertExceptionEntry( SvTreeListBox& _rList, bool _bHiContrast, size_t _nElementPos, const ExceptionDisplayInfo& _rEntry ) + { + Image aEntryImage( _rEntry.pImageProvider->getImage( _bHiContrast ) ); + SvLBoxEntry* pListEntry = + _rList.InsertEntry( _rEntry.pLabelProvider->getLabel(), aEntryImage, aEntryImage ); + pListEntry->SetUserData( reinterpret_cast< void* >( _nElementPos ) ); + } +} + //============================================================================== class OExceptionChainDialog : public ModalDialog { @@ -108,8 +323,10 @@ String m_sStatusLabel; String m_sErrorCodeLabel; + ExceptionDisplayChain m_aExceptions; + public: - OExceptionChainDialog(Window* pParent, const Any& _rStart); + OExceptionChainDialog( Window* pParent, const ExceptionDisplayChain& _rExceptions ); ~OExceptionChainDialog(); protected: @@ -118,7 +335,7 @@ DBG_NAME(OExceptionChainDialog) //------------------------------------------------------------------------------ -OExceptionChainDialog::OExceptionChainDialog(Window* pParent, const Any& _rStart) +OExceptionChainDialog::OExceptionChainDialog( Window* pParent, const ExceptionDisplayChain& _rExceptions ) :ModalDialog(pParent, ModuleRes(DLG_SQLEXCEPTIONCHAIN)) ,m_aFrame (this, ResId(FL_DETAILS)) ,m_aListLabel (this, ResId(FT_ERRORLIST)) @@ -126,13 +343,10 @@ ,m_aDescLabel (this, ResId(FT_DESCRIPTION)) ,m_aExceptionText (this, ResId(ME_DESCRIPTION)) ,m_aOK (this, ResId(PB_OK)) + ,m_aExceptions( _rExceptions ) { DBG_CTOR(OExceptionChainDialog,NULL); - String sErrorLabel(ResId(STR_EXCEPTION_ERROR)); - String sWarningLabel(ResId(STR_EXCEPTION_WARNING)); - String sInfoLabel(ResId(STR_EXCEPTION_INFO)); - String sDetailsLabel(ResId(STR_EXCEPTION_DETAILS)); m_sStatusLabel = String( ResId( STR_EXCEPTION_STATUS ) ); m_sErrorCodeLabel = String( ResId( STR_EXCEPTION_ERRORCODE ) ); @@ -144,96 +358,41 @@ m_aExceptionList.SetWindowBits(WB_HASLINES | WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HSCROLL); m_aExceptionList.SetSelectHdl(LINK(this, OExceptionChainDialog, OnExceptionSelected)); - sal_Bool bHiContrast = isHiContrast(this); - m_aExceptionList.SetNodeDefaultImages( ); - m_aExceptionText.SetReadOnly(sal_True); - SQLExceptionInfo aInfo(_rStart); - DBG_ASSERT(aInfo.isValid(), "OExceptionChainDialog::OExceptionChainDialog : invalid chain start !"); - SQLExceptionIteratorHelper aIter(aInfo); - - Image aErrorImage ( ModuleRes( bHiContrast ? BMP_EXCEPTION_ERROR_SCH : BMP_EXCEPTION_ERROR)), - aWarningImage( ModuleRes( bHiContrast ? BMP_EXCEPTION_WARNING_SCH : BMP_EXCEPTION_WARNING)), - aInfoImage ( ModuleRes( bHiContrast ? BMP_EXCEPTION_INFO_SCH : BMP_EXCEPTION_INFO)); - bool bHave22018 = false; + bool bHiContrast = isHiContrast( this ); + size_t elementPos = 0; - SQLExceptionInfo aCurrent; - while (aIter.hasMoreElements()) - { - aIter.next(aCurrent); - if (aCurrent.isValid()) - { - const SQLException* pCurrentException = (const SQLException*)aCurrent; - bHave22018 = pCurrentException->SQLState.equalsAscii( "22018" ); - - SvLBoxEntry* pListEntry = NULL; - SQLExceptionInfo* pUserData = new SQLExceptionInfo(aCurrent); - - switch (aCurrent.getType()) - { - case SQLExceptionInfo::SQL_EXCEPTION: - { - pListEntry = m_aExceptionList.InsertEntry(sErrorLabel, aErrorImage, aErrorImage); - const SQLException* pException = (const SQLException*)aCurrent; - } - break; - - case SQLExceptionInfo::SQL_WARNING: - pListEntry = m_aExceptionList.InsertEntry(sWarningLabel, aWarningImage, aWarningImage); - break; - - case SQLExceptionInfo::SQL_CONTEXT: + for ( ExceptionDisplayChain::const_iterator loop = m_aExceptions.begin(); + loop != m_aExceptions.end(); + ++loop, ++elementPos + ) { - pListEntry = m_aExceptionList.InsertEntry(sInfoLabel, aInfoImage, aInfoImage); - const SQLContext* pContext = (const SQLContext*)aCurrent; - if (pContext->Details.getLength()) - { - SvLBoxEntry* pDetailsEntry = m_aExceptionList.InsertEntry(sDetailsLabel, aInfoImage, aInfoImage, pListEntry); - pDetailsEntry->SetUserData(pUserData); - m_aExceptionList.Expand(pListEntry); - } - } - break; - - default: - DBG_ERROR("OExceptionChainDialog::OExceptionChainDialog : valid SQLException but unknown type !"); - break; - } - if ( pListEntry ) - pListEntry->SetUserData( pUserData ); - else - delete (SQLExceptionInfo*)pUserData; - } + lcl_insertExceptionEntry( m_aExceptionList, bHiContrast, elementPos, *loop ); + bHave22018 = loop->sSQLState.EqualsAscii( "22018" ); } // if the error has the code 22018, then add an additional explanation // #i24021# / 2004-10-14 / [EMAIL PROTECTED] if ( bHave22018 ) { - SvLBoxEntry* pExplanation = m_aExceptionList.InsertEntry( sInfoLabel, aInfoImage, aInfoImage ); + ProviderFactory aProviderFactory; - SQLContext aExplanation; - aExplanation.Message = String( ModuleRes( STR_EXPLAN_STRINGCONVERSION_ERROR ) ); + ExceptionDisplayInfo aInfo22018; + aInfo22018.sMessage = String( ModuleRes( STR_EXPLAN_STRINGCONVERSION_ERROR ) ); + aInfo22018.pLabelProvider = aProviderFactory.getLabelProvider( SQLExceptionInfo::SQL_CONTEXT, false ); + aInfo22018.pImageProvider = aProviderFactory.getImageProvider( SQLExceptionInfo::SQL_CONTEXT ); + m_aExceptions.push_back( aInfo22018 ); - pExplanation->SetUserData( new SQLExceptionInfo( aExplanation ) ); + lcl_insertExceptionEntry( m_aExceptionList, bHiContrast, m_aExceptions.size() - 1, aInfo22018 ); } } //------------------------------------------------------------------------------ OExceptionChainDialog::~OExceptionChainDialog() { - SvLBoxEntry* pLoop = m_aExceptionList.First(); - while (pLoop) - { - if (!m_aExceptionList.GetParent(pLoop)) - // it's not the "details" entry for an SQLContext object - delete static_cast<SQLExceptionInfo*>(pLoop->GetUserData()); - pLoop = m_aExceptionList.Next(pLoop); - } - DBG_DTOR(OExceptionChainDialog,NULL); } @@ -243,46 +402,55 @@ SvLBoxEntry* pSelected = m_aExceptionList.FirstSelected(); DBG_ASSERT(!pSelected || !m_aExceptionList.NextSelected(pSelected), "OExceptionChainDialog::OnExceptionSelected : multi selection ?"); - if (!pSelected) - m_aExceptionText.SetText(UniString()); - else - { - SQLExceptionInfo aInfo(*(const SQLExceptionInfo*)pSelected->GetUserData()); - const SQLException* pException = (const SQLException*)aInfo; - String sText; - if ( ( aInfo.getType() == SQLExceptionInfo::SQL_CONTEXT ) - && ( m_aExceptionList.GetParent( pSelected ) != NULL ) - ) - { - sText = static_cast< const SQLContext* >( pException )->Details; - } - else + + if ( pSelected ) { - if ( pException->SQLState.getLength() ) + size_t pos = reinterpret_cast< size_t >( pSelected->GetUserData() ); + const ExceptionDisplayInfo& aExceptionInfo( m_aExceptions[ pos ] ); + + if ( aExceptionInfo.sSQLState.Len() ) { sText += m_sStatusLabel; sText.AppendAscii(": "); - sText += pException->SQLState.getStr(); + sText += aExceptionInfo.sSQLState; sText.AppendAscii("\n"); } - if ( pException->ErrorCode ) + + if ( aExceptionInfo.sErrorCode.Len() ) { sText += m_sErrorCodeLabel; sText.AppendAscii(": "); - sText += String::CreateFromInt32( pException->ErrorCode ); + sText += aExceptionInfo.sErrorCode; sText.AppendAscii("\n"); } + if ( sText.Len() ) sText.AppendAscii( "\n" ); - sText += String( pException->Message ); + + sText += aExceptionInfo.sMessage; } + m_aExceptionText.SetText(sText); - } return 0L; } +//============================================================================== +//= SQLMessageBox_Impl +//============================================================================== +struct SQLMessageBox_Impl +{ + ExceptionDisplayChain aDisplayInfo; + + SQLMessageBox_Impl( const SQLExceptionInfo& _rExceptionInfo ) + { + // transform the exception chain to a form more suitable for displaying it here + ProviderFactory aProviderFactory; + lcl_buildExceptionChain( _rExceptionInfo, aProviderFactory, aDisplayInfo ); + } +}; + //------------------------------------------------------------------------------ namespace { @@ -323,23 +491,21 @@ //------------------------------------------------------------------------------ void OSQLMessageBox::impl_positionControls() { + OSL_PRECOND( !m_pImpl->aDisplayInfo.empty(), "OSQLMessageBox::impl_positionControls: nothing to display at all?" ); + + const ExceptionDisplayInfo& rFirstInfo = *m_pImpl->aDisplayInfo.begin(); + const ExceptionDisplayInfo* pSecondInfo = NULL; + if ( m_pImpl->aDisplayInfo.size() > 1 ) + pSecondInfo = &m_pImpl->aDisplayInfo[1]; + // one or two texts to display? String sPrimary, sSecondary; - if ( m_aExceptionInfo.isKindOf( SQLExceptionInfo::SQL_CONTEXT ) ) + sPrimary = rFirstInfo.sMessage; + if ( pSecondInfo ) { - SQLContext aContext; - OSL_VERIFY( m_aExceptionInfo.get() >>= aContext ); - sPrimary = aContext.Message; - sSecondary = aContext.Details; - } - else - { - SQLException aError; - OSL_VERIFY( m_aExceptionInfo.get() >>= aError ); - sPrimary = aError.Message; - - if ( aError.NextException >>= aError ) - sSecondary = aError.Message; + bool bFirstElementIsContext = ( rFirstInfo.eType == SQLExceptionInfo::SQL_CONTEXT ); + if ( !bFirstElementIsContext || ( pSecondInfo->bSubEntry ) ) + sSecondary = pSecondInfo->sMessage; } // image @@ -435,9 +601,7 @@ //------------------------------------------------------------------------------ void OSQLMessageBox::impl_addDetailsButton() { - SQLException aError; - OSL_VERIFY( m_aExceptionInfo.get() >>= aError ); - bool bMoreDetailsAvailable = aError.NextException.hasValue(); + bool bMoreDetailsAvailable = m_pImpl->aDisplayInfo.size() > 1; if ( bMoreDetailsAvailable ) { AddButton( BUTTON_MORE, BUTTONID_MORE, 0 ); @@ -462,7 +626,7 @@ MessageType eType( _eImage ); if ( eType == AUTO ) { - switch ( m_aExceptionInfo.getType() ) + switch ( m_pImpl->aDisplayInfo[0].eType ) { case SQLExceptionInfo::SQL_EXCEPTION: eType = Error; break; case SQLExceptionInfo::SQL_WARNING: eType = Warning; break; @@ -482,7 +646,7 @@ ,m_aInfoImage(this) ,m_aTitle(this,WB_WORDBREAK | WB_LEFT) ,m_aMessage(this,WB_WORDBREAK | WB_LEFT) - ,m_aExceptionInfo( _rError ) + ,m_pImpl( new SQLMessageBox_Impl( SQLExceptionInfo( _rError ) ) ) { Construct( _nStyle, _eImage ); } @@ -493,7 +657,7 @@ ,m_aInfoImage( this ) ,m_aTitle( this, WB_WORDBREAK | WB_LEFT ) ,m_aMessage( this, WB_WORDBREAK | WB_LEFT ) - ,m_aExceptionInfo( _rException ) + ,m_pImpl( new SQLMessageBox_Impl( _rException ) ) { Construct( _nStyle, _eImage ); } @@ -508,15 +672,21 @@ SQLContext aError; aError.Message = _rTitle; aError.Details = _rMessage; - m_aExceptionInfo = aError; + + m_pImpl.reset( new SQLMessageBox_Impl( SQLExceptionInfo( aError ) ) ); Construct( _nStyle, _eImage ); } //-------------------------------------------------------------------------- +OSQLMessageBox::~OSQLMessageBox() +{ +} + +//-------------------------------------------------------------------------- IMPL_LINK( OSQLMessageBox, ButtonClickHdl, Button *, pButton ) { - OExceptionChainDialog aDlg( this, m_aExceptionInfo.get() ); + OExceptionChainDialog aDlg( this, m_pImpl->aDisplayInfo ); aDlg.Execute(); return 0; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
