1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AppControllerDnD.cxx,v $
10 * $Revision: 1.26.6.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBAUI_APPCONTROLLER_HXX
35 #include "AppController.hxx"
37 #ifndef _COMPHELPER_SEQUENCE_HXX_
38 #include <comphelper/sequence.hxx>
40 #ifndef _COMPHELPER_PROPERTY_HXX_
41 #include <comphelper/property.hxx>
43 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
44 #include "dbustrings.hrc"
46 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
47 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
49 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
50 #include <com/sun/star/sdbcx/XAppend.hpp>
52 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
53 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
55 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
56 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
58 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
59 #include <com/sun/star/container/XNameContainer.hpp>
61 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
62 #include <com/sun/star/uno/XNamingService.hpp>
64 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
65 #include <com/sun/star/sdbc/XDataSource.hpp>
67 #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
68 #include <com/sun/star/frame/XStorable.hpp>
70 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
71 #include <com/sun/star/container/XChild.hpp>
73 #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMECONTAINER_HPP_
74 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
76 #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
77 #include <com/sun/star/sdbc/DataType.hpp>
79 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
80 #include <com/sun/star/sdb/CommandType.hpp>
82 #ifndef _COM_SUN_STAR_SDB_XBOOKMARKSSUPPLIER_HPP_
83 #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
85 #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
86 #include <com/sun/star/sdb/SQLContext.hpp>
88 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
89 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
91 #ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
92 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
94 #ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_
95 #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
97 #ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
98 #include <com/sun/star/sdbcx/XDrop.hpp>
100 #ifndef _TOOLS_DEBUG_HXX
101 #include <tools/debug.hxx>
104 #include <tools/urlobj.hxx>
106 #ifndef _UNOTOOLS_UCBHELPER_HXX
107 #include <unotools/ucbhelper.hxx>
109 #ifndef DBAUI_DLGSAVE_HXX
110 #include "dlgsave.hxx"
112 #ifndef _COMPHELPER_TYPES_HXX_
113 #include <comphelper/types.hxx>
115 #ifndef _SV_MSGBOX_HXX
116 #include <vcl/msgbox.hxx>
118 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
119 #include <cppuhelper/typeprovider.hxx>
121 #ifndef _CPPUHELPER_EXC_HLP_HXX_
122 #include <cppuhelper/exc_hlp.hxx>
124 #ifndef _DBHELPER_DBEXCEPTION_HXX_
125 #include <connectivity/dbexception.hxx>
127 #ifndef _SV_WAITOBJ_HXX
128 #include <vcl/waitobj.hxx>
130 #ifndef _RTL_USTRBUF_HXX_
131 #include <rtl/ustrbuf.hxx>
133 #ifndef DBAUI_APPVIEW_HXX
134 #include "AppView.hxx"
136 #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
137 #include <svx/dataaccessdescriptor.hxx>
139 #ifndef SVX_DBAOBJECTEX_HXX
140 #include <svx/dbaobjectex.hxx>
142 #ifndef DBACCESS_UI_BROWSER_ID_HXX
143 #include "browserids.hxx"
145 #ifndef _DBAU_REGHELPER_HXX_
146 #include "dbu_reghelper.hxx"
148 #ifndef _DBU_APP_HRC_
149 #include "dbu_app.hrc"
152 #include <vcl/menu.hxx>
154 #ifndef _COMPHELPER_UNO3_HXX_
155 #include <comphelper/uno3.hxx>
157 #ifndef _SV_SVAPP_HXX //autogen
158 #include <vcl/svapp.hxx>
160 #ifndef _SVLBOXITM_HXX
161 #include <svtools/svlbitm.hxx>
163 #ifndef _DBAUI_LISTVIEWITEMS_HXX_
164 #include "listviewitems.hxx"
166 #ifndef DBAUI_APPDETAILVIEW_HXX
167 #include "AppDetailView.hxx"
169 #ifndef _DBAUI_LINKEDDOCUMENTS_HXX_
170 #include "linkeddocuments.hxx"
172 #ifndef _SV_LSTBOX_HXX
173 #include <vcl/lstbox.hxx>
175 #ifndef _DBHELPER_DBEXCEPTION_HXX_
176 #include <connectivity/dbexception.hxx>
178 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
179 #include <connectivity/dbtools.hxx>
181 #ifndef _DBAUI_SQLMESSAGE_HXX_
182 #include "sqlmessage.hxx"
185 #include <tools/string.hxx>
187 #ifndef DBAUI_DBEXCHANGE_HXX
188 #include "dbexchange.hxx"
190 #ifndef DBAUI_TOOLS_HXX
191 #include "UITools.hxx"
194 #ifndef _SVTREEBOX_HXX
195 #include <svtools/svtreebx.hxx>
197 #ifndef _COM_SUN_STAR_SDB_XREPORTDOCUMENTSSUPPLIER_HPP_
198 #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
200 #ifndef _COM_SUN_STAR_SDB_XFORMDOCUMENTSSUPPLIER_HPP_
201 #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
203 #ifndef _FILEDLGHELPER_HXX
204 #include <sfx2/filedlghelper.hxx>
206 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
207 #include <svtools/pathoptions.hxx>
209 #ifndef _SFX_DOCFILT_HACK_HXX
210 #include <sfx2/docfilt.hxx>
212 #ifndef _SVT_FILEVIEW_HXX
213 #include <svtools/fileview.hxx>
215 #ifndef TOOLS_DIAGNOSE_EX_H
216 #include <tools/diagnose_ex.h>
218 #ifndef DBACCESS_SOURCE_UI_MISC_DEFAULTOBJECTNAMECHECK_HXX
219 #include "defaultobjectnamecheck.hxx"
221 #ifndef _VOS_MUTEX_HXX_
222 #include <vos/mutex.hxx>
224 #include "subcomponentmanager.hxx"
226 //........................................................................
229 //........................................................................
230 using namespace ::dbtools
;
231 using namespace ::svx
;
232 using namespace ::svtools
;
233 using namespace ::com::sun::star::uno
;
234 using namespace ::com::sun::star::task
;
235 using namespace ::com::sun::star::beans
;
236 using namespace ::com::sun::star::lang
;
237 using namespace ::com::sun::star::container
;
238 using namespace ::com::sun::star::sdb
;
239 using namespace ::com::sun::star::sdbc
;
240 using namespace ::com::sun::star::sdbcx
;
241 using namespace ::com::sun::star::frame
;
242 using namespace ::com::sun::star::ucb
;
243 using namespace ::com::sun::star::util
;
245 // -----------------------------------------------------------------------------
246 void OApplicationController::deleteTables(const ::std::vector
< ::rtl::OUString
>& _rList
)
248 SharedConnection
xConnection( ensureConnection() );
250 Reference
<XTablesSupplier
> xSup(xConnection
,UNO_QUERY
);
251 OSL_ENSURE(xSup
.is(),"OApplicationController::deleteTable: no XTablesSuppier!");
254 Reference
<XNameAccess
> xTables
= xSup
->getTables();
255 Reference
<XDrop
> xDrop(xTables
,UNO_QUERY
);
258 bool bConfirm
= true;
259 ::std::vector
< ::rtl::OUString
>::const_iterator aEnd
= _rList
.end();
260 for (::std::vector
< ::rtl::OUString
>::const_iterator aIter
= _rList
.begin(); aIter
!= aEnd
; ++aIter
)
262 ::rtl::OUString sTableName
= *aIter
;
264 sal_Int32 nResult
= RET_YES
;
266 nResult
= ::dbaui::askForUserAction(getView(),STR_TITLE_CONFIRM_DELETION
,STR_QUERY_DELETE_TABLE
,_rList
.size() > 1 && (aIter
+1) != _rList
.end(),sTableName
);
268 bool bUserConfirmedDelete
=
269 ( RET_YES
== nResult
)
270 || ( RET_ALL
== nResult
);
271 if ( bUserConfirmedDelete
&& m_pSubComponentManager
->closeSubFrames( sTableName
, E_TABLE
) )
273 SQLExceptionInfo aErrorInfo
;
276 if ( xTables
->hasByName(sTableName
) )
277 xDrop
->dropByName(sTableName
);
280 Reference
<XViewsSupplier
> xViewsSup(xConnection
,UNO_QUERY
);
282 Reference
<XNameAccess
> xViews
;
283 if ( xViewsSup
.is() )
285 xViews
= xViewsSup
->getViews();
286 if ( xViews
.is() && xViews
->hasByName(sTableName
) )
288 xDrop
.set(xViews
,UNO_QUERY
);
290 xDrop
->dropByName(sTableName
);
295 catch(SQLContext
& e
) { aErrorInfo
= e
; }
296 catch(SQLWarning
& e
) { aErrorInfo
= e
; }
297 catch(SQLException
& e
) { aErrorInfo
= e
; }
298 catch(WrappedTargetException
& e
)
301 if(e
.TargetException
>>= aSql
)
304 OSL_ENSURE(sal_False
, "OApplicationController::implDropTable: something strange happended!");
306 catch( const Exception
& )
308 DBG_UNHANDLED_EXCEPTION();
311 if ( aErrorInfo
.isValid() )
312 showError(aErrorInfo
);
314 if ( RET_ALL
== nResult
)
323 String
sMessage(ModuleRes(STR_MISSING_TABLES_XDROP
));
324 ErrorBox
aError(getView(), WB_OK
, sMessage
);
329 // -----------------------------------------------------------------------------
330 void OApplicationController::deleteObjects( ElementType _eType
, const ::std::vector
< ::rtl::OUString
>& _rList
, bool _bConfirm
)
332 Reference
< XNameContainer
> xNames( getElements( _eType
), UNO_QUERY
);
333 Reference
< XHierarchicalNameContainer
> xHierarchyName( xNames
, UNO_QUERY
);
336 ByteString sDialogPosition
;
337 svtools::QueryDeleteResult_Impl eResult
= _bConfirm
? svtools::QUERYDELETE_YES
: svtools::QUERYDELETE_ALL
;
339 // The list of elements to delete is allowed to contain related elements: A given element may
340 // be the ancestor or child of another element from the list.
341 // We want to ensure that ancestors get deleted first, so we normalize the list in this respect.
342 // #i33353# - 2004-09-27 - fs@openoffice.org
343 ::std::set
< ::rtl::OUString
> aDeleteNames
;
344 // Note that this implicitly uses ::std::less< ::rtl::OUString > a comparison operation, which
345 // results in lexicographical order, which is exactly what we need, because "foo" is *before*
346 // any "foo/bar" in this order.
348 _rList
.begin(), _rList
.end(),
349 ::std::insert_iterator
< ::std::set
< ::rtl::OUString
> >( aDeleteNames
, aDeleteNames
.begin() )
352 ::std::set
< ::rtl::OUString
>::size_type nCount
= aDeleteNames
.size();
353 for ( ::std::set
< ::rtl::OUString
>::size_type nObjectsLeft
= nCount
; !aDeleteNames
.empty(); )
355 ::std::set
< ::rtl::OUString
>::iterator aThisRound
= aDeleteNames
.begin();
357 if ( eResult
!= svtools::QUERYDELETE_ALL
)
359 svtools::QueryDeleteDlg_Impl
aDlg( getView(), *aThisRound
);
361 if ( sDialogPosition
.Len() )
362 aDlg
.SetWindowState( sDialogPosition
);
364 if ( nObjectsLeft
> 1 )
365 aDlg
.EnableAllButton();
367 if ( aDlg
.Execute() == RET_OK
)
368 eResult
= aDlg
.GetResult();
372 sDialogPosition
= aDlg
.GetWindowState( );
375 bool bSuccess
= false;
377 bool bUserConfirmedDelete
=
378 ( eResult
== svtools::QUERYDELETE_ALL
)
379 || ( eResult
== svtools::QUERYDELETE_YES
);
381 if ( bUserConfirmedDelete
382 && ( ( _eType
== E_QUERY
) ? m_pSubComponentManager
->closeSubFrames( *aThisRound
, _eType
) : true )
387 if ( xHierarchyName
.is() )
388 xHierarchyName
->removeByHierarchicalName( *aThisRound
);
390 xNames
->removeByName( *aThisRound
);
394 // now that we removed the element, care for all it's child elements
395 // which may also be a part of the list
396 // #i33353# - 2004-09-27 - fs@openoffice.org
397 OSL_ENSURE( aThisRound
->getLength() - 1 >= 0, "OApplicationController::deleteObjects: empty name?" );
398 ::rtl::OUStringBuffer
sSmallestSiblingName( *aThisRound
);
399 sSmallestSiblingName
.append( (sal_Unicode
)( '/' + 1) );
401 ::std::set
< ::rtl::OUString
>::iterator aUpperChildrenBound
= aDeleteNames
.lower_bound( sSmallestSiblingName
.makeStringAndClear() );
402 for ( ::std::set
< ::rtl::OUString
>::iterator aObsolete
= aThisRound
;
403 aObsolete
!= aUpperChildrenBound
;
406 #if OSL_DEBUG_LEVEL > 0
407 ::rtl::OUString sObsoleteName
= *aObsolete
;
409 ::std::set
< ::rtl::OUString
>::iterator aNextObsolete
= aObsolete
; ++aNextObsolete
;
410 aDeleteNames
.erase( aObsolete
);
412 aObsolete
= aNextObsolete
;
415 catch(const SQLException
&)
417 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
419 catch(WrappedTargetException
& e
)
422 if ( e
.TargetException
>>= aSql
)
423 showError( SQLExceptionInfo( e
.TargetException
) );
425 OSL_ENSURE( sal_False
, "OApplicationController::deleteObjects: something strange happended!" );
427 catch( const Exception
& )
429 DBG_UNHANDLED_EXCEPTION();
435 // okay, this object could not be deleted (or the user did not want to delete it),
436 // but continue with the rest
437 aDeleteNames
.erase( aThisRound
);
443 // -----------------------------------------------------------------------------
444 void OApplicationController::deleteEntries()
446 ::vos::OGuard
aSolarGuard(Application::GetSolarMutex());
447 ::osl::MutexGuard
aGuard( getMutex() );
449 if ( getContainer() )
451 ::std::vector
< ::rtl::OUString
> aList
;
452 getSelectionElementNames(aList
);
453 ElementType eType
= getContainer()->getElementType();
460 deleteObjects( E_QUERY
, aList
, true );
463 deleteObjects( E_FORM
, aList
, true );
466 deleteObjects( E_REPORT
, aList
, true );
473 // -----------------------------------------------------------------------------
474 const SharedConnection
& OApplicationController::ensureConnection( ::dbtools::SQLExceptionInfo
* _pErrorInfo
)
476 ::vos::OGuard
aSolarGuard(Application::GetSolarMutex());
477 ::osl::MutexGuard
aGuard( getMutex() );
479 if ( !m_xDataSourceConnection
.is() )
481 WaitObject
aWO(getView());
482 String
sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE
) );
483 sConnectingContext
.SearchAndReplaceAscii("$name$", getStrippedDatabaseName());
485 m_xDataSourceConnection
.reset( connect( getDatabaseName(), sConnectingContext
, _pErrorInfo
) );
486 if ( m_xDataSourceConnection
.is() )
488 SQLExceptionInfo aError
;
491 m_xMetaData
= m_xDataSourceConnection
->getMetaData();
493 catch( const SQLException
& )
495 aError
= ::cppu::getCaughtException();
497 catch( const Exception
& )
499 DBG_UNHANDLED_EXCEPTION();
501 if ( aError
.isValid() )
505 *_pErrorInfo
= aError
;
514 return m_xDataSourceConnection
;
516 // -----------------------------------------------------------------------------
517 sal_Bool
OApplicationController::isDataSourceReadOnly() const
519 Reference
<XStorable
> xStore(m_xModel
,UNO_QUERY
);
520 return !xStore
.is() || xStore
->isReadonly();
522 // -----------------------------------------------------------------------------
523 sal_Bool
OApplicationController::isConnectionReadOnly() const
525 sal_Bool bIsConnectionReadOnly
= sal_True
;
526 if ( m_xMetaData
.is() )
530 bIsConnectionReadOnly
= m_xMetaData
->isReadOnly();
532 catch(const SQLException
&)
534 DBG_UNHANDLED_EXCEPTION();
537 // TODO check configuration
538 return bIsConnectionReadOnly
;
540 // -----------------------------------------------------------------------------
541 Reference
< XNameAccess
> OApplicationController::getElements( ElementType _eType
)
543 Reference
< XNameAccess
> xElements
;
550 Reference
< XReportDocumentsSupplier
> xSupp( m_xModel
, UNO_QUERY_THROW
);
551 xElements
.set( xSupp
->getReportDocuments(), UNO_SET_THROW
);
557 Reference
< XFormDocumentsSupplier
> xSupp( m_xModel
, UNO_QUERY_THROW
);
558 xElements
.set( xSupp
->getFormDocuments(), UNO_SET_THROW
);
564 xElements
.set( getQueryDefintions(), UNO_QUERY_THROW
);
570 if ( m_xDataSourceConnection
.is() )
572 Reference
< XTablesSupplier
> xSup( getConnection(), UNO_QUERY_THROW
);
573 xElements
.set( xSup
->getTables(), UNO_SET_THROW
);
582 catch(const Exception
&)
584 DBG_UNHANDLED_EXCEPTION();
589 // -----------------------------------------------------------------------------
590 void OApplicationController::getSelectionElementNames(::std::vector
< ::rtl::OUString
>& _rNames
) const
592 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
593 ::osl::MutexGuard
aGuard( getMutex() );
595 OSL_ENSURE(getContainer(),"View isn't valid! -> GPF");
597 getContainer()->getSelectionElementNames( _rNames
);
600 // -----------------------------------------------------------------------------
601 ::std::auto_ptr
< OLinkedDocumentsAccess
> OApplicationController::getDocumentsAccess( ElementType _eType
)
603 OSL_ENSURE( ( _eType
== E_TABLE
) || ( _eType
== E_QUERY
) || ( _eType
== E_FORM
) || ( _eType
== E_REPORT
),
604 "OApplicationController::getDocumentsAccess: only forms and reports are supported here!" );
606 SharedConnection
xConnection( ensureConnection() );
607 Reference
< XNameAccess
> xDocContainer
;
609 if ( ( _eType
== E_FORM
) | ( _eType
== E_REPORT
) )
611 xDocContainer
.set( getElements( _eType
) );
612 OSL_ENSURE( xDocContainer
.is(), "OApplicationController::getDocumentsAccess: invalid container!" );
615 ::std::auto_ptr
< OLinkedDocumentsAccess
> pDocuments( new OLinkedDocumentsAccess(
616 getView(), m_aCurrentFrame
.getFrame(), getORB(), xDocContainer
, xConnection
, getDatabaseName()
620 // -----------------------------------------------------------------------------
621 TransferableHelper
* OApplicationController::copyObject()
625 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
626 ::osl::MutexGuard
aGuard( getMutex() );
628 ElementType eType
= getContainer()->getElementType();
629 TransferableHelper
* pData
= NULL
;
635 SharedConnection
xConnection( ensureConnection() );
636 Reference
< XDatabaseMetaData
> xMetaData
;
637 if ( xConnection
.is() )
638 xMetaData
= xConnection
->getMetaData();
640 ::rtl::OUString sName
= getContainer()->getQualifiedName( NULL
);
641 if ( sName
.getLength() )
643 ::rtl::OUString sDataSource
= getDatabaseName();
645 if ( eType
== E_TABLE
)
647 pData
= new ODataClipboard(sDataSource
, CommandType::TABLE
, sName
, xConnection
, getNumberFormatter(xConnection
,getORB()), getORB());
651 pData
= new ODataClipboard(sDataSource
, CommandType::QUERY
, sName
, getNumberFormatter(xConnection
,getORB()), getORB());
659 ::std::vector
< ::rtl::OUString
> aList
;
660 getSelectionElementNames(aList
);
661 Reference
< XHierarchicalNameAccess
> xElements(getElements(eType
),UNO_QUERY
);
662 if ( xElements
.is() && !aList
.empty() )
664 Reference
< XContent
> xContent(xElements
->getByHierarchicalName(*aList
.begin()),UNO_QUERY
);
665 pData
= new OComponentTransferable( getDatabaseName(), xContent
);
673 // the owner ship goes to ODataClipboards
676 catch(const SQLException
&)
678 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
680 catch( const Exception
& )
682 DBG_UNHANDLED_EXCEPTION();
686 // -----------------------------------------------------------------------------
687 sal_Bool
OApplicationController::paste( ElementType _eType
,const ::svx::ODataAccessDescriptor
& _rPasteData
,const String
& _sParentFolder
,sal_Bool _bMove
)
691 if ( _eType
== E_QUERY
)
693 sal_Int32 nCommandType
= CommandType::TABLE
;
694 if ( _rPasteData
.has(daCommandType
) )
695 _rPasteData
[daCommandType
] >>= nCommandType
;
697 if ( CommandType::QUERY
== nCommandType
|| CommandType::COMMAND
== nCommandType
)
699 // read all nescessary data
701 ::rtl::OUString sCommand
;
702 sal_Bool bEscapeProcessing
= sal_True
;
704 _rPasteData
[daCommand
] >>= sCommand
;
705 if ( _rPasteData
.has(daEscapeProcessing
) )
706 _rPasteData
[daEscapeProcessing
] >>= bEscapeProcessing
;
708 // plausibility check
709 sal_Bool bValidDescriptor
= sal_False
;
710 ::rtl::OUString sDataSourceName
= _rPasteData
.getDataSource();
711 if (CommandType::QUERY
== nCommandType
)
712 bValidDescriptor
= sDataSourceName
.getLength() && sCommand
.getLength();
713 else if (CommandType::COMMAND
== nCommandType
)
714 bValidDescriptor
= (0 != sCommand
.getLength());
715 if (!bValidDescriptor
)
717 DBG_ERROR("OApplicationController::paste: invalid descriptor!");
721 // the target object name (as we'll suggest it to the user)
722 ::rtl::OUString sTargetName
;
725 if ( CommandType::QUERY
== nCommandType
)
726 sTargetName
= sCommand
;
728 if ( !sTargetName
.getLength() )
730 String sDefaultName
= String( ModuleRes( STR_QRY_TITLE
) );
731 sDefaultName
= sDefaultName
.GetToken( 0, ' ' );
733 Reference
< XNameAccess
> xQueries( getQueryDefintions(), UNO_QUERY_THROW
);
734 sTargetName
= ::dbtools::createUniqueName( xQueries
, sDefaultName
, sal_False
);
737 catch(const Exception
&)
739 DBG_UNHANDLED_EXCEPTION();
742 Reference
< XPropertySet
> xQuery
;
743 if (CommandType::QUERY
== nCommandType
)
745 // need to extract the statement and the escape processing flag from the query object
746 sal_Bool bSuccess
= sal_False
;
749 // the concrete query
750 Reference
< XQueryDefinitionsSupplier
> xSourceQuerySup(
751 getDataSourceByName( sDataSourceName
, getView(), getORB(), NULL
),
753 Reference
< XNameAccess
> xQueries( xSourceQuerySup
->getQueryDefinitions(), UNO_SET_THROW
);
754 if ( xQueries
->hasByName( sCommand
) )
756 xQuery
.set( xQueries
->getByName(sCommand
), UNO_QUERY_THROW
);
760 catch(SQLException
&) { throw; } // caught and handled by the outer catch
761 catch( const Exception
& )
763 DBG_UNHANDLED_EXCEPTION();
768 DBG_ERROR("OApplicationController::paste: could not extract the source query object!");
769 // TODO: maybe this is worth an error message to be displayed to the user ....
775 Reference
< XNameContainer
> xDestQueries(getQueryDefintions(), UNO_QUERY
);
776 Reference
< XSingleServiceFactory
> xQueryFactory(xDestQueries
, UNO_QUERY
);
777 if (!xQueryFactory
.is())
779 DBG_ERROR("OApplicationController::paste: invalid destination query container!");
783 // here we have everything needed to create a new query object ...
784 // ... ehm, except a new name
787 DynamicTableOrQueryNameCheck
aNameChecker( getConnection(), CommandType::QUERY
);
788 ::dbtools::SQLExceptionInfo aDummy
;
789 bool bNeedAskForName
= ( sCommand
.getLength() == 0 )
790 /* we did not have a source name, so the target name was auto-generated */
791 || ( !aNameChecker
.isNameValid( sTargetName
, aDummy
) );
792 /* name is invalid in the target DB (e.g. because it already
793 has a /table/ with that name) */
794 if ( bNeedAskForName
)
796 OSaveAsDlg
aAskForName( getView(),
802 SAD_ADDITIONAL_DESCRIPTION
| SAD_TITLE_PASTE_AS
);
803 if ( RET_OK
!= aAskForName
.Execute() )
804 // cancelled by the user
806 sTargetName
= aAskForName
.getName();
809 // create a new object
810 Reference
< XPropertySet
> xNewQuery(xQueryFactory
->createInstance(), UNO_QUERY
);
811 DBG_ASSERT(xNewQuery
.is(), "OApplicationController::paste: invalid object created by factory!");
816 ::comphelper::copyProperties(xQuery
,xNewQuery
);
819 xNewQuery
->setPropertyValue(PROPERTY_COMMAND
,makeAny(sCommand
));
820 xNewQuery
->setPropertyValue(PROPERTY_ESCAPE_PROCESSING
,makeAny(bEscapeProcessing
));
823 xDestQueries
->insertByName( sTargetName
, makeAny(xNewQuery
) );
824 xNewQuery
.set(xDestQueries
->getByName( sTargetName
),UNO_QUERY
);
825 if ( xQuery
.is() && xNewQuery
.is() )
827 Reference
<XColumnsSupplier
> xSrcColSup(xQuery
,UNO_QUERY
);
828 Reference
<XColumnsSupplier
> xDstColSup(xNewQuery
,UNO_QUERY
);
829 if ( xSrcColSup
.is() && xDstColSup
.is() )
831 Reference
<XNameAccess
> xSrcNameAccess
= xSrcColSup
->getColumns();
832 Reference
<XNameAccess
> xDstNameAccess
= xDstColSup
->getColumns();
833 Reference
<XDataDescriptorFactory
> xFac(xDstNameAccess
,UNO_QUERY
);
834 Reference
<XAppend
> xAppend(xFac
,UNO_QUERY
);
835 if ( xSrcNameAccess
.is() && xDstNameAccess
.is() && xSrcNameAccess
->hasElements() && xAppend
.is() )
837 Reference
<XPropertySet
> xDstProp(xFac
->createDataDescriptor());
839 Sequence
< ::rtl::OUString
> aSeq
= xSrcNameAccess
->getElementNames();
840 const ::rtl::OUString
* pIter
= aSeq
.getConstArray();
841 const ::rtl::OUString
* pEnd
= pIter
+ aSeq
.getLength();
842 for( ; pIter
!= pEnd
; ++pIter
)
844 Reference
<XPropertySet
> xSrcProp(xSrcNameAccess
->getByName(*pIter
),UNO_QUERY
);
845 ::comphelper::copyProperties(xSrcProp
,xDstProp
);
846 xAppend
->appendByDescriptor(xDstProp
);
854 OSL_TRACE("There should be a sequence in it!");
857 else if ( _rPasteData
.has(daComponent
) ) // forms or reports
859 Reference
<XContent
> xContent
;
860 _rPasteData
[daComponent
] >>= xContent
;
861 return insertHierachyElement(_eType
,_sParentFolder
,Reference
<XNameAccess
>(xContent
,UNO_QUERY
).is(),xContent
,_bMove
);
864 catch(const SQLException
&) { showError( SQLExceptionInfo( ::cppu::getCaughtException() ) ); }
865 catch(const Exception
& )
867 DBG_UNHANDLED_EXCEPTION();
871 // -----------------------------------------------------------------------------
872 Reference
<XNameContainer
> OApplicationController::getQueryDefintions() const
874 Reference
<XQueryDefinitionsSupplier
> xSet(m_xDataSource
,UNO_QUERY
);
875 Reference
<XNameContainer
> xNames
;
878 xNames
.set(xSet
->getQueryDefinitions(),UNO_QUERY
);
882 // -----------------------------------------------------------------------------
883 void OApplicationController::getSupportedFormats(ElementType _eType
,::std::vector
<SotFormatStringId
>& _rFormatIds
) const
888 _rFormatIds
.push_back(SOT_FORMATSTR_ID_DBACCESS_TABLE
);
889 _rFormatIds
.push_back(SOT_FORMAT_RTF
);
890 _rFormatIds
.push_back(SOT_FORMATSTR_ID_HTML
);
893 _rFormatIds
.push_back(SOT_FORMATSTR_ID_DBACCESS_QUERY
);
899 // -----------------------------------------------------------------------------
900 sal_Bool
OApplicationController::isTableFormat() const
902 return m_aTableCopyHelper
.isTableFormat(getViewClipboard());
904 // -----------------------------------------------------------------------------
905 sal_Bool
OApplicationController::copyTagTable(OTableCopyHelper::DropDescriptor
& _rDesc
, sal_Bool _bCheck
)
907 // first get the dest connection
908 ::osl::MutexGuard
aGuard( getMutex() );
910 SharedConnection
xConnection( ensureConnection() );
911 if ( !xConnection
.is() )
914 return m_aTableCopyHelper
.copyTagTable( _rDesc
, _bCheck
, xConnection
);
916 // -----------------------------------------------------------------------------
917 IMPL_LINK( OApplicationController
, OnAsyncDrop
, void*, /*NOTINTERESTEDIN*/ )
920 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
921 ::osl::MutexGuard
aGuard( getMutex() );
924 if ( m_aAsyncDrop
.nType
== E_TABLE
)
926 SharedConnection
xConnection( ensureConnection() );
927 if ( xConnection
.is() )
928 m_aTableCopyHelper
.asyncCopyTagTable( m_aAsyncDrop
, getDatabaseName(), xConnection
);
932 if ( paste(m_aAsyncDrop
.nType
,m_aAsyncDrop
.aDroppedData
,m_aAsyncDrop
.aUrl
,m_aAsyncDrop
.nAction
== DND_ACTION_MOVE
)
933 && m_aAsyncDrop
.nAction
== DND_ACTION_MOVE
)
935 Reference
<XContent
> xContent
;
936 m_aAsyncDrop
.aDroppedData
[daComponent
] >>= xContent
;
937 ::std::vector
< ::rtl::OUString
> aList
;
938 sal_Int32 nIndex
= 0;
939 ::rtl::OUString sName
= xContent
->getIdentifier()->getContentIdentifier();
940 ::rtl::OUString sErase
= sName
.getToken(0,'/',nIndex
); // we don't want to have the "private:forms" part
943 aList
.push_back(sName
.copy(sErase
.getLength() + 1));
944 deleteObjects( m_aAsyncDrop
.nType
, aList
, false );
949 m_aAsyncDrop
.aDroppedData
.clear();
953 //........................................................................
955 //........................................................................