summaryrefslogtreecommitdiff
path: root/dbaccess/source/ui/misc
diff options
context:
space:
mode:
authorFrank Schoenheit [fs] <frank.schoenheit@sun.com>2010-01-11 12:15:28 +0100
committerFrank Schoenheit [fs] <frank.schoenheit@sun.com>2010-01-11 12:15:28 +0100
commit0e793ea5d3e758ed431065b675a79c17a9f15ef7 (patch)
tree7038bd404feff100f3e5e5ab955046f462fd3e66 /dbaccess/source/ui/misc
parentf5531281dc390ac3e74888f078eac7a87b586095 (diff)
dba33f: #i108038# (re-)add Selection support to the Copy Table Wizard
Diffstat (limited to 'dbaccess/source/ui/misc')
-rw-r--r--dbaccess/source/ui/misc/TableCopyHelper.cxx122
-rw-r--r--dbaccess/source/ui/misc/TokenWriter.cxx87
2 files changed, 106 insertions, 103 deletions
diff --git a/dbaccess/source/ui/misc/TableCopyHelper.cxx b/dbaccess/source/ui/misc/TableCopyHelper.cxx
index 4b1258677037..f0ac851b58b7 100644
--- a/dbaccess/source/ui/misc/TableCopyHelper.cxx
+++ b/dbaccess/source/ui/misc/TableCopyHelper.cxx
@@ -163,21 +163,15 @@ using namespace ::com::sun::star::ucb;
OTableCopyHelper::OTableCopyHelper(OGenericUnoController* _pControler)
:m_pController(_pControler)
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OTableCopyHelper::OTableCopyHelper" );
}
// -----------------------------------------------------------------------------
-void OTableCopyHelper::insertTable(sal_Int32 _nCommandType
- ,const Reference<XConnection>& _xSrcConnection
- ,const Sequence< Any >& _aSelection
- ,sal_Bool _bBookmarkSelection
- ,const ::rtl::OUString& _sCommand
- ,const ::rtl::OUString& _sSrcDataSourceName
- ,const ::rtl::OUString& _sDestDataSourceName
- ,const Reference<XConnection>& _xDestConnection)
+void OTableCopyHelper::insertTable( const ::rtl::OUString& i_rSourceDataSource, const Reference<XConnection>& i_rSourceConnection,
+ const ::rtl::OUString& i_rCommand, const sal_Int32 i_nCommandType,
+ const Reference< XResultSet >& i_rSourceRows, const Sequence< Any >& i_rSelection, const sal_Bool i_bBookmarkSelection,
+ const ::rtl::OUString& i_rDestDataSource, const Reference<XConnection>& i_rDestConnection)
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OTableCopyHelper::insertTable" );
- if ( CommandType::QUERY != _nCommandType && CommandType::TABLE != _nCommandType )
+ if ( CommandType::QUERY != i_nCommandType && CommandType::TABLE != i_nCommandType )
{
DBG_ERROR( "OTableCopyHelper::insertTable: invalid call (no supported format found)!" );
return;
@@ -185,11 +179,11 @@ void OTableCopyHelper::insertTable(sal_Int32 _nCommandType
try
{
- Reference<XConnection> xSrcConnection( _xSrcConnection );
- if ( _sSrcDataSourceName == _sDestDataSourceName )
- xSrcConnection = _xDestConnection;
+ Reference<XConnection> xSrcConnection( i_rSourceConnection );
+ if ( i_rSourceDataSource == i_rDestDataSource )
+ xSrcConnection = i_rDestConnection;
- if ( !xSrcConnection.is() || !_xDestConnection.is() )
+ if ( !xSrcConnection.is() || !i_rDestConnection.is() )
{
OSL_ENSURE( false, "OTableCopyHelper::insertTable: no connection/s!" );
return;
@@ -200,14 +194,15 @@ void OTableCopyHelper::insertTable(sal_Int32 _nCommandType
Reference< XDataAccessDescriptorFactory > xFactory( DataAccessDescriptorFactory::get( aContext.getUNOContext() ) );
Reference< XPropertySet > xSource( xFactory->createDataAccessDescriptor(), UNO_SET_THROW );
- xSource->setPropertyValue( PROPERTY_COMMAND_TYPE, makeAny( _nCommandType ) );
- xSource->setPropertyValue( PROPERTY_COMMAND, makeAny( _sCommand ) );
+ xSource->setPropertyValue( PROPERTY_COMMAND_TYPE, makeAny( i_nCommandType ) );
+ xSource->setPropertyValue( PROPERTY_COMMAND, makeAny( i_rCommand ) );
xSource->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( xSrcConnection ) );
- xSource->setPropertyValue( PROPERTY_SELECTION, makeAny( _aSelection ) );
- xSource->setPropertyValue( PROPERTY_BOOKMARK_SELECTION, makeAny( _bBookmarkSelection ) );
+ xSource->setPropertyValue( PROPERTY_RESULT_SET, makeAny( i_rSourceRows ) );
+ xSource->setPropertyValue( PROPERTY_SELECTION, makeAny( i_rSelection ) );
+ xSource->setPropertyValue( PROPERTY_BOOKMARK_SELECTION, makeAny( i_bBookmarkSelection ) );
Reference< XPropertySet > xDest( xFactory->createDataAccessDescriptor(), UNO_SET_THROW );
- xDest->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( _xDestConnection ) );
+ xDest->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( i_rDestConnection ) );
Reference< XCopyTableWizard > xWizard( CopyTableWizard::create( aContext.getUNOContext(), xSource, xDest ), UNO_SET_THROW );
@@ -230,72 +225,62 @@ void OTableCopyHelper::insertTable(sal_Int32 _nCommandType
}
// -----------------------------------------------------------------------------
-void OTableCopyHelper::pasteTable( const ::svx::ODataAccessDescriptor& _rPasteData, const ::rtl::OUString& _sDestDataSourceName,
- const SharedConnection& _xDestConnection )
+void OTableCopyHelper::pasteTable( const ::svx::ODataAccessDescriptor& _rPasteData, const ::rtl::OUString& i_rDestDataSourceName,
+ const SharedConnection& i_rDestConnection )
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OTableCopyHelper::pasteTable" );
- Reference<XConnection> xSrcConnection;
- ::rtl::OUString sCommand,
- sSrcDataSourceName = _rPasteData.getDataSource();
+ ::rtl::OUString sSrcDataSourceName = _rPasteData.getDataSource();
+
+ ::rtl::OUString sCommand;
+ _rPasteData[ daCommand ] >>= sCommand;
- _rPasteData[daCommand] >>= sCommand;
+ Reference<XConnection> xSrcConnection;
if ( _rPasteData.has(daConnection) )
- _rPasteData[daConnection] >>= xSrcConnection;
-#if OSL_DEBUG_LEVEL > 0
+ {
+ OSL_VERIFY( _rPasteData[daConnection] >>= xSrcConnection );
+ }
+
+ Reference< XResultSet > xResultSet;
if ( _rPasteData.has(daCursor) )
{
- Reference< XResultSet > xSrcRs;
- _rPasteData[daCursor] >>= xSrcRs;
- OSL_ENSURE( !xSrcRs.is(), "OTableCopyHelper::pasteTable: source result set not supported anymore!" );
- // There was a time where we supported passing a result set as shortcut to the source
- // object. That is, we do not need to create an own result set we already have one.
- // Since we UNOized the Copy Table Wizard (#i81658#), we removed this support, since it
- // contradicted the semantics of DataAccessDescriptor.ResultSet.
- //
- // This shouldn't be a problem, since there seems to be no client which actually
- // passed a result set here.
- // However, if there still is, we probably need to introduce an (undocumented?) property
- // at the DataAccessDescriptor, which takes this "source result set".
+ OSL_VERIFY( _rPasteData[ daCursor ] >>= xResultSet );
}
- if ( _rPasteData.has( daSelection ) || _rPasteData.has( daBookmarkSelection ) )
+ Sequence< Any > aSelection;
+ if ( _rPasteData.has( daSelection ) )
{
- OSL_ENSURE( false, "OTableCopyHelper::pasteTable: bookmark/selection not supported anymore!" );
- // similar notes here: Selection and BookmarkSelection are not supported in the UNOized
- // copy table wizard anymore (it doesn't make sense without support for a source result set),
- // and there seem to be no clients which actually use it. So, instead of implementing an
- // unused case, we dropped this here.
+ OSL_VERIFY( _rPasteData[ daSelection ] >>= aSelection );
+ OSL_ENSURE( _rPasteData.has( daBookmarkSelection ), "OTableCopyHelper::pasteTable: you should specify BookmarkSelection, too, to be on the safe side!" );
}
-#endif
- // paste into the tables
+
+ sal_Bool bBookmarkSelection( sal_True );
+ if ( _rPasteData.has( daBookmarkSelection ) )
+ {
+ OSL_VERIFY( _rPasteData[ daBookmarkSelection ] >>= bBookmarkSelection );
+ }
+ OSL_ENSURE( bBookmarkSelection, "OTableCopyHelper::pasteTable: working with selection-indicies (instead of bookmarks) is error-prone, and thus deprecated!" );
+
sal_Int32 nCommandType = CommandType::COMMAND;
if ( _rPasteData.has(daCommandType) )
_rPasteData[daCommandType] >>= nCommandType;
- insertTable( nCommandType
- ,xSrcConnection
- ,Sequence< Any >()
- ,sal_False
- ,sCommand
- ,sSrcDataSourceName
- ,_sDestDataSourceName
- ,_xDestConnection);
+ insertTable( sSrcDataSourceName, xSrcConnection, sCommand, nCommandType,
+ xResultSet, aSelection, bBookmarkSelection,
+ i_rDestDataSourceName, i_rDestConnection );
}
// -----------------------------------------------------------------------------
void OTableCopyHelper::pasteTable( SotFormatStringId _nFormatId
,const TransferableDataHelper& _rTransData
- ,const ::rtl::OUString& _sDestDataSourceName
+ ,const ::rtl::OUString& i_rDestDataSource
,const SharedConnection& _xConnection)
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OTableCopyHelper::pasteTable" );
if ( _nFormatId == SOT_FORMATSTR_ID_DBACCESS_TABLE || _nFormatId == SOT_FORMATSTR_ID_DBACCESS_QUERY )
{
if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(_rTransData.GetDataFlavorExVector()) )
{
::svx::ODataAccessDescriptor aPasteData = ODataAccessObjectTransferable::extractObjectDescriptor(_rTransData);
- pasteTable( aPasteData,_sDestDataSourceName,_xConnection);
+ pasteTable( aPasteData,i_rDestDataSource,_xConnection);
}
}
else if ( _rTransData.HasFormat(_nFormatId) )
@@ -329,22 +314,20 @@ void OTableCopyHelper::pasteTable( SotFormatStringId _nFormatId
// -----------------------------------------------------------------------------
void OTableCopyHelper::pasteTable( const TransferableDataHelper& _rTransData
- ,const ::rtl::OUString& _sDestDataSourceName
+ ,const ::rtl::OUString& i_rDestDataSource
,const SharedConnection& _xConnection)
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OTableCopyHelper::pasteTable" );
if ( _rTransData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE) || _rTransData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY) )
- pasteTable( SOT_FORMATSTR_ID_DBACCESS_TABLE,_rTransData,_sDestDataSourceName,_xConnection);
+ pasteTable( SOT_FORMATSTR_ID_DBACCESS_TABLE,_rTransData,i_rDestDataSource,_xConnection);
else if ( _rTransData.HasFormat(SOT_FORMATSTR_ID_HTML) )
- pasteTable( SOT_FORMATSTR_ID_HTML,_rTransData,_sDestDataSourceName,_xConnection);
+ pasteTable( SOT_FORMATSTR_ID_HTML,_rTransData,i_rDestDataSource,_xConnection);
else if ( _rTransData.HasFormat(SOT_FORMAT_RTF) )
- pasteTable( SOT_FORMAT_RTF,_rTransData,_sDestDataSourceName,_xConnection);
+ pasteTable( SOT_FORMAT_RTF,_rTransData,i_rDestDataSource,_xConnection);
}
// -----------------------------------------------------------------------------
sal_Bool OTableCopyHelper::copyTagTable(OTableCopyHelper::DropDescriptor& _rDesc, sal_Bool _bCheck,const SharedConnection& _xConnection)
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OTableCopyHelper::copyTagTable" );
Reference<XEventListener> xEvt;
ODatabaseImportExport* pImport = NULL;
if ( _rDesc.bHtml )
@@ -367,7 +350,6 @@ sal_Bool OTableCopyHelper::copyTagTable(OTableCopyHelper::DropDescriptor& _rDesc
// -----------------------------------------------------------------------------
sal_Bool OTableCopyHelper::isTableFormat(const TransferableDataHelper& _rClipboard) const
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OTableCopyHelper::isTableFormat" );
sal_Bool bTableFormat = _rClipboard.HasFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE)
|| _rClipboard.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY)
|| _rClipboard.HasFormat(SOT_FORMAT_RTF)
@@ -380,7 +362,6 @@ sal_Bool OTableCopyHelper::copyTagTable(const TransferableDataHelper& _aDroppedD
,DropDescriptor& _rAsyncDrop
,const SharedConnection& _xConnection)
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OTableCopyHelper::copyTagTable" );
sal_Bool bRet = sal_False;
sal_Bool bHtml = _aDroppedData.HasFormat(SOT_FORMATSTR_ID_HTML);
if ( bHtml || _aDroppedData.HasFormat(SOT_FORMAT_RTF) )
@@ -413,10 +394,9 @@ sal_Bool OTableCopyHelper::copyTagTable(const TransferableDataHelper& _aDroppedD
}
// -----------------------------------------------------------------------------
void OTableCopyHelper::asyncCopyTagTable( DropDescriptor& _rDesc
- ,const ::rtl::OUString& _sDestDataSourceName
+ ,const ::rtl::OUString& i_rDestDataSource
,const SharedConnection& _xConnection)
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OTableCopyHelper::asyncCopyTagTable" );
if ( _rDesc.aHtmlRtfStorage.Is() )
{
copyTagTable(_rDesc,sal_False,_xConnection);
@@ -427,7 +407,7 @@ void OTableCopyHelper::asyncCopyTagTable( DropDescriptor& _rDesc
::utl::UCBContentHelper::Kill(aURL.GetMainURL(INetURLObject::NO_DECODE));
}
else if ( !_rDesc.bError )
- pasteTable(_rDesc.aDroppedData,_sDestDataSourceName,_xConnection);
+ pasteTable(_rDesc.aDroppedData,i_rDestDataSource,_xConnection);
else
m_pController->showError(SQLException(String(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE)),*m_pController,::rtl::OUString::createFromAscii("S1000") ,0,Any()));
}
diff --git a/dbaccess/source/ui/misc/TokenWriter.cxx b/dbaccess/source/ui/misc/TokenWriter.cxx
index d872590b3763..a3dc2e6e1e96 100644
--- a/dbaccess/source/ui/misc/TokenWriter.cxx
+++ b/dbaccess/source/ui/misc/TokenWriter.cxx
@@ -104,6 +104,7 @@ ODatabaseImportExport::ODatabaseImportExport(const ::svx::ODataAccessDescriptor&
const Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
const String& rExchange)
:m_xFormatter(_rxNumberF)
+ ,m_bBookmarkSelection( NULL )
,m_xFactory(_rM)
,m_nCommandType(CommandType::TABLE)
,m_bNeedToReInitialize(sal_False)
@@ -133,7 +134,8 @@ ODatabaseImportExport::ODatabaseImportExport(const ::svx::ODataAccessDescriptor&
// import data
ODatabaseImportExport::ODatabaseImportExport( const ::dbtools::SharedConnection& _rxConnection,
const Reference< XNumberFormatter >& _rxNumberF, const Reference< XMultiServiceFactory >& _rM )
- :m_xConnection(_rxConnection)
+ :m_bBookmarkSelection( NULL )
+ ,m_xConnection(_rxConnection)
,m_xFormatter(_rxNumberF)
,m_xFactory(_rM)
,m_nCommandType(::com::sun::star::sdb::CommandType::TABLE)
@@ -187,6 +189,7 @@ void ODatabaseImportExport::dispose()
m_xResultSetMetaData.clear();
m_xResultSet.clear();
m_xRow.clear();
+ m_xRowLocate.clear();
m_xFormatter.clear();
}
// -----------------------------------------------------------------------------
@@ -231,20 +234,37 @@ void ODatabaseImportExport::impl_initFromDescriptor( const ODataAccessDescriptor
if (xComponent.is() && xEvt.is())
xComponent->addEventListener(xEvt);
}
- if(_aDataDescriptor.has(daSelection))
- _aDataDescriptor[daSelection] >>= m_aSelection;
- sal_Bool bBookmarkSelection = sal_True; // the default if not present
+ if ( _aDataDescriptor.has( daSelection ) )
+ _aDataDescriptor[ daSelection ] >>= m_aSelection;
+
if ( _aDataDescriptor.has( daBookmarkSelection ) )
+ _aDataDescriptor[ daBookmarkSelection ] >>= m_bBookmarkSelection;
+
+ if ( _aDataDescriptor.has( daCursor ) )
{
- _aDataDescriptor[ daBookmarkSelection ] >>= bBookmarkSelection;
- DBG_ASSERT( !bBookmarkSelection, "ODatabaseImportExport::ODatabaseImportExport: bookmarked selection not yet supported!" );
+ _aDataDescriptor[ daCursor ] >>= m_xResultSet;
+ m_xRowLocate.set( m_xResultSet, UNO_QUERY );
}
+ if ( m_aSelection.getLength() != 0 )
+ {
+ if ( !m_xResultSet.is() )
+ {
+ OSL_ENSURE( false, "ODatabaseImportExport::impl_initFromDescriptor: selection without result set is nonsense!" );
+ m_aSelection.realloc( 0 );
+ }
+ }
- if(_aDataDescriptor.has(daCursor))
- _aDataDescriptor[daCursor] >>= m_xResultSet;
- } // if ( !_bPlusDefaultInit )
+ if ( m_aSelection.getLength() != 0 )
+ {
+ if ( m_bBookmarkSelection && !m_xRowLocate.is() )
+ {
+ OSL_ENSURE( false, "ODatabaseImportExport::impl_initFromDescriptor: no XRowLocate -> no bookmars!" );
+ m_aSelection.realloc( 0 );
+ }
+ }
+ }
else
initialize();
@@ -314,19 +334,14 @@ void ODatabaseImportExport::initialize()
// the result set may be already set with the datadescriptor
if ( !m_xResultSet.is() )
{
- m_xResultSet.set(m_xFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.sdb.RowSet")),UNO_QUERY);
- Reference<XPropertySet > xProp(m_xResultSet,UNO_QUERY);
- if(xProp.is())
- {
- xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( m_xConnection.getTyped() ) );
- xProp->setPropertyValue(PROPERTY_COMMAND_TYPE,makeAny(m_nCommandType));
- xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(m_sName));
- Reference<XRowSet> xRowSet(xProp,UNO_QUERY);
- xRowSet->execute();
- }
- else
- OSL_ENSURE(sal_False, "ODatabaseImportExport::initialize: could not instantiate a rowset!");
- } // if ( !m_xResultSet.is() )
+ m_xResultSet.set( m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.sdb.RowSet" ) ), UNO_QUERY );
+ Reference< XPropertySet > xProp( m_xResultSet, UNO_QUERY_THROW );
+ xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( m_xConnection.getTyped() ) );
+ xProp->setPropertyValue( PROPERTY_COMMAND_TYPE, makeAny( m_nCommandType ) );
+ xProp->setPropertyValue( PROPERTY_COMMAND, makeAny( m_sName ) );
+ Reference< XRowSet > xRowSet( xProp, UNO_QUERY );
+ xRowSet->execute();
+ }
impl_initializeRowMember_throw();
}
catch(Exception& )
@@ -375,7 +390,8 @@ void ODatabaseImportExport::impl_initializeRowMember_throw()
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseImportExport::impl_initializeRowMember_throw" );
if ( !m_xRow.is() && m_xResultSet.is() )
{
- m_xRow.set(m_xResultSet,UNO_QUERY);
+ m_xRow.set( m_xResultSet, UNO_QUERY );
+ m_xRowLocate.set( m_xResultSet, UNO_QUERY );
m_xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(m_xRow,UNO_QUERY)->getMetaData();
Reference<XColumnsSupplier> xSup(m_xResultSet,UNO_QUERY_THROW);
m_xRowSetColumns.set(xSup->getColumns(),UNO_QUERY_THROW);
@@ -570,22 +586,29 @@ BOOL ORTFImportExport::Write()
Reference< XRowSet > xRowSet(m_xRow,UNO_QUERY);
sal_Int32 k=1;
sal_Int32 kk=0;
- if(m_aSelection.getLength())
+ if ( m_aSelection.getLength() )
{
const Any* pSelIter = m_aSelection.getConstArray();
const Any* pEnd = pSelIter + m_aSelection.getLength();
+
sal_Bool bContinue = sal_True;
- for(;pSelIter != pEnd && bContinue;++pSelIter)
+ for( ; pSelIter != pEnd && bContinue; ++pSelIter )
{
- sal_Int32 nPos = -1;
- *pSelIter >>= nPos;
- OSL_ENSURE(nPos != -1,"Invalid posiotion!");
- bContinue = (m_xResultSet->absolute(nPos));
- if ( bContinue )
- appendRow(pHorzChar,nCount,k,kk);
+ if ( m_bBookmarkSelection )
+ {
+ bContinue = m_xRowLocate->moveToBookmark( *pSelIter );
+ }
+ else
+ {
+ sal_Int32 nPos = -1;
+ OSL_VERIFY( *pSelIter >>= nPos );
+ bContinue = ( m_xResultSet->absolute( nPos ) );
+ }
+ if ( bContinue )
+ appendRow( pHorzChar, nCount, k, kk );
}
- } // if(m_aSelection.getLength())
+ }
else
{
m_xResultSet->beforeFirst(); // set back before the first row