Tag: cws_src680_hsqlcsv User: fs Date: 2006/10/19 03:16:32 Modified: dba/dbaccess/source/ext/hsqldb/linkedtableeditor.cxx dba/dbaccess/source/ext/hsqldb/linkedtableeditor.hxx
Log: #i69526# connection between the actual settings of the table, and the items of the dialog File Changes: Directory: /dba/dbaccess/source/ext/hsqldb/ =========================================== File [changed]: linkedtableeditor.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ext/hsqldb/linkedtableeditor.cxx?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +378 -4 --------------------- --- linkedtableeditor.cxx 20 Sep 2006 09:09:31 -0000 1.1.2.2 +++ linkedtableeditor.cxx 19 Oct 2006 10:16:29 -0000 1.1.2.3 @@ -4,9 +4,9 @@ * * $RCSfile: linkedtableeditor.cxx,v $ * - * $Revision: 1.1.2.2 $ + * $Revision: 1.1.2.3 $ * - * last change: $Author: fs $ $Date: 2006/09/20 09:09:31 $ + * last change: $Author: fs $ $Date: 2006/10/19 10:16:29 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -45,30 +45,404 @@ #ifndef DBACCESS_HSQL_MODULE_HXX #include "hsql_module.hxx" #endif +#ifndef DBACCESS_LTE_ITEMS_HXX +#include "lte_items.hxx" +#endif +#ifndef DBACCESS_TEXTTABLESETTINGS_HXX +#include "texttablesettings.hxx" +#endif /** === begin UNO includes === **/ +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#endif /** === end UNO includes === **/ +#ifndef _SFXSTRITEM_HXX +#include <svtools/stritem.hxx> +#endif +#ifndef _SFXENUMITEM_HXX +#include <svtools/eitem.hxx> +#endif +#ifndef _SFXINTITEM_HXX +#include <svtools/intitem.hxx> +#endif + +#ifndef _SV_MSGBOX_HXX +#include <vcl/msgbox.hxx> +#endif + +#include <vector> +#include <boost/shared_ptr.hpp> + //........................................................................ namespace hsqlui { //........................................................................ /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::sdbc::XConnection; + using ::com::sun::star::lang::IllegalArgumentException; /** === end UNO using === **/ + //========================================================================= + //= IItemPersistence + //========================================================================= + class SAL_NO_VTABLE IItemPersistence + { + public: + /// returns the slot ID which the instance is reponsible for + virtual SlotId getSlotId() const = 0; + + /// stores the given pool item value to whatever backend the instances is connected to + virtual void storeItemValue( const SfxPoolItem& _rItem ) = 0; + + /** loads the value for which the instances is responsible, and puts it into the + given item set + */ + virtual void loadItemValue( SfxItemSet& _rSet ) = 0; + + virtual ~IItemPersistence(); + }; + typedef ::boost::shared_ptr< IItemPersistence > PItemPersistence; + typedef ::std::vector< PItemPersistence > ItemPersistenceArray; + + //------------------------------------------------------------------------- + IItemPersistence::~IItemPersistence() + { + } + + //------------------------------------------------------------------------- + struct StoreItemValue : public ::std::unary_function< PItemPersistence, void > + { + private: + const SfxItemSet& m_rSet; + + public: + StoreItemValue( const SfxItemSet& _rSet ) : m_rSet( _rSet ) { } + + void operator()( const PItemPersistence& _rItem ) + { + _rItem->storeItemValue( m_rSet.Get( m_rSet.GetPool()->GetWhich( _rItem->getSlotId() ) ) ); + } + }; + + //------------------------------------------------------------------------- + struct LoadItemValue : public ::std::unary_function< PItemPersistence, void > + { + private: + SfxItemSet& m_rSet; + + public: + LoadItemValue( SfxItemSet& _rSet ) : m_rSet( _rSet ) { } + + void operator()( const PItemPersistence& _rItem ) + { + _rItem->loadItemValue( m_rSet ); + } + }; + + //========================================================================= + //= StringSettingDescriptor + //========================================================================= + class TableSettingPersistence : public IItemPersistence + { + private: + SlotId m_nSlotId; + TextTableSettings& m_rSettings; + + protected: + const TextTableSettings& getSettings() const { return m_rSettings; } + TextTableSettings& getSettings() { return m_rSettings; } + + protected: + TableSettingPersistence( TextTableSettings& _rSettings, SlotId _nSlotId ) + :m_rSettings( _rSettings ) + ,m_nSlotId( _nSlotId ) + { + } + + public: + // IItemPersistence overridables + virtual SlotId getSlotId() const; + }; + + //------------------------------------------------------------------------- + SlotId TableSettingPersistence::getSlotId() const + { + return m_nSlotId; + } + + //========================================================================= + //= BooleanTableSetting + //========================================================================= + class BooleanTableSetting : public TableSettingPersistence + { + public: + typedef bool (TextTableSettings::*GetValueFunc)() const; + typedef void (TextTableSettings::*SetValueFunc)( bool ); + + private: + GetValueFunc m_pGetter; + SetValueFunc m_pSetter; + + public: + BooleanTableSetting( TextTableSettings& _rSettings, SlotId _nSlotId, + GetValueFunc _pGetter, SetValueFunc _pSetter ) + :TableSettingPersistence( _rSettings, _nSlotId ) + ,m_pGetter( _pGetter ) + ,m_pSetter( _pSetter ) + { + } + + public: + // IItemPersistence overridables + virtual void storeItemValue( const SfxPoolItem& _rItem ); + virtual void loadItemValue( SfxItemSet& _rSet ); + }; + + //------------------------------------------------------------------------- + void BooleanTableSetting::storeItemValue( const SfxPoolItem& _rItem ) + { + const SfxBoolItem& rBoolItem = dynamic_cast< const SfxBoolItem& >( _rItem ); + (getSettings().*m_pSetter)( rBoolItem.GetValue() ); + } + + //------------------------------------------------------------------------- + void BooleanTableSetting::loadItemValue( SfxItemSet& _rSet ) + { + bool bValue = (getSettings().*m_pGetter)(); + _rSet.Put( SfxBoolItem( getSlotId(), bValue ) ); + } + + //========================================================================= + //= StringTableSetting + //========================================================================= + class StringTableSetting : public TableSettingPersistence + { + public: + typedef ::rtl::OUString (TextTableSettings::*GetValueFunc)() const; + typedef void (TextTableSettings::*SetValueFunc)( const ::rtl::OUString& ); + + private: + GetValueFunc m_pGetter; + SetValueFunc m_pSetter; + + public: + StringTableSetting( TextTableSettings& _rSettings, SlotId _nSlotId, + GetValueFunc _pGetter, SetValueFunc _pSetter ) + :TableSettingPersistence( _rSettings, _nSlotId ) + ,m_pGetter( _pGetter ) + ,m_pSetter( _pSetter ) + { + } + + public: + // IItemPersistence overridables + virtual void storeItemValue( const SfxPoolItem& _rItem ); + virtual void loadItemValue( SfxItemSet& _rSet ); + }; + + //------------------------------------------------------------------------- + void StringTableSetting::storeItemValue( const SfxPoolItem& _rItem ) + { + const SfxStringItem& rStringItem = dynamic_cast< const SfxStringItem& >( _rItem ); + (getSettings().*m_pSetter)( rStringItem.GetValue() ); + } + + //------------------------------------------------------------------------- + void StringTableSetting::loadItemValue( SfxItemSet& _rSet ) + { + ::rtl::OUString sValue = (getSettings().*m_pGetter)(); + _rSet.Put( SfxStringItem( getSlotId(), sValue ) ); + } + + //========================================================================= + //= TextEncodingSetting + //========================================================================= + class TextEncodingSetting : public TableSettingPersistence + { + public: + TextEncodingSetting( TextTableSettings& _rSettings, SlotId _nSlotId ) + :TableSettingPersistence( _rSettings, _nSlotId ) + { + } + + public: + // IItemPersistence overridables + virtual void storeItemValue( const SfxPoolItem& _rItem ); + virtual void loadItemValue( SfxItemSet& _rSet ); + }; + + //------------------------------------------------------------------------- + void TextEncodingSetting::storeItemValue( const SfxPoolItem& _rItem ) + { + const SfxUInt16Item& rEncodingItem = dynamic_cast< const SfxUInt16Item& >( _rItem ); + rtl_TextEncoding eEncoding = static_cast< rtl_TextEncoding >( rEncodingItem.GetValue() ); + + const char* pMimeEncoding = rtl_getMimeCharsetFromTextEncoding( eEncoding ); + OSL_ENSURE( pMimeEncoding, "TextEncodingSetting::storeItemValue: unable to find a MIME name for the selected text encoding!" ); + + String sMimeEncoding = String::CreateFromAscii( pMimeEncoding ? pMimeEncoding : "ascii" ); + getSettings().setEncoding( sMimeEncoding ); + } + + //------------------------------------------------------------------------- + void TextEncodingSetting::loadItemValue( SfxItemSet& _rSet ) + { + ::rtl::OUString sEncoding( getSettings().getEncoding() ); + ::rtl::OString sMimeEncoding( sEncoding.getStr(), sEncoding.getLength(), RTL_TEXTENCODING_ASCII_US ); + rtl_TextEncoding eMimeEncoding = rtl_getTextEncodingFromMimeCharset( sMimeEncoding.getStr() ); + OSL_ENSURE( eMimeEncoding != RTL_TEXTENCODING_DONTKNOW, "TextEncodingSetting::loadItemValue: invalid current encoding!" ); + if ( eMimeEncoding == RTL_TEXTENCODING_DONTKNOW ) + eMimeEncoding = RTL_TEXTENCODING_ASCII_US; + + _rSet.Put( SfxUInt16Item( getSlotId(), eMimeEncoding ) ); + } + + //========================================================================= + void lcl_createItemPersistences( TextTableSettings& _rSettings, ItemPersistenceArray& _rAll ) + { + _rAll.clear(); + _rAll.push_back( PItemPersistence( new StringTableSetting ( _rSettings, LSID_FILE_PATH, &TextTableSettings::getFilePath, &TextTableSettings::setFilePath ) ) ); + _rAll.push_back( PItemPersistence( new BooleanTableSetting( _rSettings, LSID_HEADER_LINE, &TextTableSettings::getIgnoreFirstLine, &TextTableSettings::setIgnoreFirstLine ) ) ); + _rAll.push_back( PItemPersistence( new TextEncodingSetting( _rSettings, LSID_ENCODING ) ) ); + _rAll.push_back( PItemPersistence( new StringTableSetting ( _rSettings, LSID_FIELD_SEPARATOR, &TextTableSettings::getFieldSeparator, &TextTableSettings::setFieldSeparator) ) ); + _rAll.push_back( PItemPersistence( new BooleanTableSetting( _rSettings, LSID_ALL_QUOTED, &TextTableSettings::getAllQuoted, &TextTableSettings::setAllQuoted ) ) ); + } + //===================================================================== //= LinkedTableEditor //===================================================================== //--------------------------------------------------------------------- - LinkedTableEditor::LinkedTableEditor( Window* _pParent ) - :SfxTabDialog( _pParent, HsqlResId( DLG_LINKED_TABLE_EDITOR ) ) + LinkedTableEditor::LinkedTableEditor( Window* _pParent, const Reference< XConnection >& _rxConnection, + const ::rtl::OUString& _rTableName, SfxItemSet& _rItemSet ) + :SfxTabDialog( _pParent, HsqlResId( DLG_LINKED_TABLE_EDITOR ), &_rItemSet ) { AddTabPage( TP_TEXT_FILE, String( ResId( STR_PAGETITLE_TEXT_FILE ) ), &TextFilePage::Create, NULL ); AddTabPage( TP_FORMAT, String( ResId( STR_PAGETITLE_FORMAT ) ), &FormatPage::Create, NULL ); AddTabPage( TP_FIELDS, String( ResId( STR_PAGETITLE_FIELDS ) ), &FieldsPage::Create, NULL ); FreeResource(); + + OSL_PRECOND( _rxConnection.is() && _rTableName.getLength(), + "LinkedTableEditor::LinkedTableEditor: invalid arguments!" ); + if ( !_rxConnection.is() || !_rTableName.getLength() ) + throw IllegalArgumentException(); + + m_pTableSettings.reset( new TextTableSettings( _rxConnection, _rTableName ) ); + impl_initItemSet( *m_pTableSettings, _rItemSet ); + } + + //--------------------------------------------------------------------- + LinkedTableEditor::~LinkedTableEditor() + { + } + + //------------------------------------------------------------------------- + short LinkedTableEditor::Ok() + { + short nResult = SfxTabDialog::Ok(); + if ( nResult != RET_OK ) + return nResult; + + const SfxItemSet* pOutput = GetOutputItemSet(); + OSL_ENSURE( pOutput, "LinkedTableEditor::Ok: no output items?" ); + if ( !pOutput ) + return RET_CANCEL; + + if ( !impl_applyItemSet( *pOutput, *m_pTableSettings ) ) + return RET_CANCEL; + + return nResult; + } + + //------------------------------------------------------------------------- + SfxItemSet* LinkedTableEditor::createItemSet( SfxItemSet*& _rpSet, SfxItemPool*& _rpPool, SfxPoolItem**& _rppDefaults ) + { + // just to be sure .... + _rpSet = NULL; + _rpPool = NULL; + _rppDefaults = NULL; + + // create and initialize the defaults + _rppDefaults = new SfxPoolItem*[ LSID_ITEM_COUNT ]; + SfxPoolItem** pDefault = _rppDefaults; // want to modify this without affecting the out param _rppDefaults + *pDefault++ = new SfxStringItem( LSID_FILE_PATH, String() ); + *pDefault++ = new SfxBoolItem( LSID_RELATIVE_PATH, TRUE ); + *pDefault++ = new SfxBoolItem( LSID_HEADER_LINE, TRUE ); + *pDefault++ = new SfxUInt16Item( LSID_ENCODING, RTL_TEXTENCODING_ASCII_US ); + *pDefault++ = new SfxStringItem( LSID_FIELD_SEPARATOR, String() ); + *pDefault++ = new SfxBoolItem( LSID_ALL_QUOTED, TRUE ); + + // create the pool + static SfxItemInfo __READONLY_DATA aItemInfos[ LSID_ITEM_COUNT ] = + { + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } + }; + + _rpPool = new SfxItemPool( + String::CreateFromAscii( "LinkedTableEditorItemPool" ), + LSID_FIRST_ITEM_ID, + LSID_LAST_ITEM_ID, + aItemInfos, + _rppDefaults + ); + _rpPool->FreezeIdRanges(); + + // and, finally, the set + _rpSet = new SfxItemSet( *_rpPool, sal_True ); + + return _rpSet; + } + + //------------------------------------------------------------------------- + void LinkedTableEditor::destroyItemSet( SfxItemSet*& _rpSet, SfxItemPool*& _rpPool, SfxPoolItem**& _rppDefaults ) + { + // _first_ delete the set (refering the pool) + if (_rpSet) + { + delete _rpSet; + _rpSet = NULL; + } + + // delete the pool + if (_rpPool) + { + _rpPool->ReleaseDefaults( sal_True ); + delete _rpPool; + _rpPool = NULL; + } + + // reset the defaults ptr + _rppDefaults = NULL; + // no need to explicitly delete the defaults, this has been done by the ReleaseDefaults + } + + //------------------------------------------------------------------------- + void LinkedTableEditor::impl_initItemSet( TextTableSettings& _rSettings, SfxItemSet& _rSet ) + { + ItemPersistenceArray aItemTranslators; + lcl_createItemPersistences( _rSettings, aItemTranslators ); + ::std::for_each( aItemTranslators.begin(), aItemTranslators.end(), LoadItemValue( _rSet ) ); + } + + //------------------------------------------------------------------------- + bool LinkedTableEditor::impl_applyItemSet( const SfxItemSet& _rSet, TextTableSettings& _rSettings ) + { + ItemPersistenceArray aItemTranslators; + lcl_createItemPersistences( _rSettings, aItemTranslators ); + ::std::for_each( aItemTranslators.begin(), aItemTranslators.end(), StoreItemValue( _rSet ) ); + + // TODO: error handling + + return true; } //........................................................................ File [changed]: linkedtableeditor.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ext/hsqldb/linkedtableeditor.hxx?r1=1.1.2.1&r2=1.1.2.2 Delta lines: +30 -4 -------------------- --- linkedtableeditor.hxx 14 Sep 2006 12:24:33 -0000 1.1.2.1 +++ linkedtableeditor.hxx 19 Oct 2006 10:16:29 -0000 1.1.2.2 @@ -4,9 +4,9 @@ * * $RCSfile: linkedtableeditor.hxx,v $ * - * $Revision: 1.1.2.1 $ + * $Revision: 1.1.2.2 $ * - * last change: $Author: fs $ $Date: 2006/09/14 12:24:33 $ + * last change: $Author: fs $ $Date: 2006/10/19 10:16:29 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -37,24 +37,50 @@ #define DBACCESS_LINKEDTABLEEDITOR_HXX /** === begin UNO includes === **/ +#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ +#include <com/sun/star/sdbc/XConnection.hpp> +#endif /** === end UNO includes === **/ #ifndef _SFXTABDLG_HXX #include <sfx2/tabdlg.hxx> #endif +#include <memory> + //........................................................................ namespace hsqlui { //........................................................................ + class TextTableSettings; //===================================================================== //= LinkedTableEditor //===================================================================== class LinkedTableEditor : public SfxTabDialog { + private: + ::std::auto_ptr< TextTableSettings > m_pTableSettings; + public: - LinkedTableEditor( Window* _pParent ); + LinkedTableEditor( + Window* _pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, + const ::rtl::OUString& _rTableName, + SfxItemSet& _rItemSet + ); + ~LinkedTableEditor(); + + public: + static SfxItemSet* createItemSet( SfxItemSet*& _rpSet, SfxItemPool*& _rpPool, SfxPoolItem**& _rppDefaults ); + static void destroyItemSet( SfxItemSet*& _rpSet, SfxItemPool*& _rpPool, SfxPoolItem**& _rppDefaults ); + + // SfxTabDialog overridables + virtual short Ok(); + + private: + static void impl_initItemSet( TextTableSettings& _rSettings, SfxItemSet& _rSet ); + static bool impl_applyItemSet( const SfxItemSet& _rSet, TextTableSettings& _rSettings ); }; //........................................................................ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
