1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef DBAUI_APPCONTROLLER_HXX
32*cdf0e10cSrcweir #include "AppController.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #ifndef _COMPHELPER_SEQUENCE_HXX_
35*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #ifndef _COMPHELPER_PROPERTY_HXX_
38*cdf0e10cSrcweir #include <comphelper/property.hxx>
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
41*cdf0e10cSrcweir #include "dbustrings.hrc"
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
44*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
47*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
50*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
53*cdf0e10cSrcweir #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
54*cdf0e10cSrcweir #endif
55*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
56*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
57*cdf0e10cSrcweir #endif
58*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
59*cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
60*cdf0e10cSrcweir #endif
61*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
62*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
63*cdf0e10cSrcweir #endif
64*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
65*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
66*cdf0e10cSrcweir #endif
67*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
68*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
69*cdf0e10cSrcweir #endif
70*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMECONTAINER_HPP_
71*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
72*cdf0e10cSrcweir #endif
73*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
74*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
75*cdf0e10cSrcweir #endif
76*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
77*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
78*cdf0e10cSrcweir #endif
79*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XBOOKMARKSSUPPLIER_HPP_
80*cdf0e10cSrcweir #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
81*cdf0e10cSrcweir #endif
82*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
83*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
84*cdf0e10cSrcweir #endif
85*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
86*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
87*cdf0e10cSrcweir #endif
88*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
89*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
90*cdf0e10cSrcweir #endif
91*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_
92*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
93*cdf0e10cSrcweir #endif
94*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
95*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDrop.hpp>
96*cdf0e10cSrcweir #endif
97*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
98*cdf0e10cSrcweir #include <tools/debug.hxx>
99*cdf0e10cSrcweir #endif
100*cdf0e10cSrcweir #ifndef _URLOBJ_HXX
101*cdf0e10cSrcweir #include <tools/urlobj.hxx>
102*cdf0e10cSrcweir #endif
103*cdf0e10cSrcweir #ifndef _UNOTOOLS_UCBHELPER_HXX
104*cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
105*cdf0e10cSrcweir #endif
106*cdf0e10cSrcweir #ifndef DBAUI_DLGSAVE_HXX
107*cdf0e10cSrcweir #include "dlgsave.hxx"
108*cdf0e10cSrcweir #endif
109*cdf0e10cSrcweir #ifndef _COMPHELPER_TYPES_HXX_
110*cdf0e10cSrcweir #include <comphelper/types.hxx>
111*cdf0e10cSrcweir #endif
112*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
113*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
114*cdf0e10cSrcweir #endif
115*cdf0e10cSrcweir #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
116*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
117*cdf0e10cSrcweir #endif
118*cdf0e10cSrcweir #ifndef _CPPUHELPER_EXC_HLP_HXX_
119*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
120*cdf0e10cSrcweir #endif
121*cdf0e10cSrcweir #ifndef _DBHELPER_DBEXCEPTION_HXX_
122*cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
123*cdf0e10cSrcweir #endif
124*cdf0e10cSrcweir #ifndef _SV_WAITOBJ_HXX
125*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
126*cdf0e10cSrcweir #endif
127*cdf0e10cSrcweir #ifndef _RTL_USTRBUF_HXX_
128*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
129*cdf0e10cSrcweir #endif
130*cdf0e10cSrcweir #ifndef DBAUI_APPVIEW_HXX
131*cdf0e10cSrcweir #include "AppView.hxx"
132*cdf0e10cSrcweir #endif
133*cdf0e10cSrcweir #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
134*cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
135*cdf0e10cSrcweir #endif
136*cdf0e10cSrcweir #ifndef SVX_DBAOBJECTEX_HXX
137*cdf0e10cSrcweir #include <svx/dbaobjectex.hxx>
138*cdf0e10cSrcweir #endif
139*cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
140*cdf0e10cSrcweir #include "browserids.hxx"
141*cdf0e10cSrcweir #endif
142*cdf0e10cSrcweir #ifndef _DBAU_REGHELPER_HXX_
143*cdf0e10cSrcweir #include "dbu_reghelper.hxx"
144*cdf0e10cSrcweir #endif
145*cdf0e10cSrcweir #ifndef _DBU_APP_HRC_
146*cdf0e10cSrcweir #include "dbu_app.hrc"
147*cdf0e10cSrcweir #endif
148*cdf0e10cSrcweir #ifndef _SV_MENU_HXX
149*cdf0e10cSrcweir #include <vcl/menu.hxx>
150*cdf0e10cSrcweir #endif
151*cdf0e10cSrcweir #ifndef _COMPHELPER_UNO3_HXX_
152*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
153*cdf0e10cSrcweir #endif
154*cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX //autogen
155*cdf0e10cSrcweir #include <vcl/svapp.hxx>
156*cdf0e10cSrcweir #endif
157*cdf0e10cSrcweir #ifndef _SVLBOXITM_HXX
158*cdf0e10cSrcweir #include <svtools/svlbitm.hxx>
159*cdf0e10cSrcweir #endif
160*cdf0e10cSrcweir #ifndef _DBAUI_LISTVIEWITEMS_HXX_
161*cdf0e10cSrcweir #include "listviewitems.hxx"
162*cdf0e10cSrcweir #endif
163*cdf0e10cSrcweir #ifndef DBAUI_APPDETAILVIEW_HXX
164*cdf0e10cSrcweir #include "AppDetailView.hxx"
165*cdf0e10cSrcweir #endif
166*cdf0e10cSrcweir #ifndef _DBAUI_LINKEDDOCUMENTS_HXX_
167*cdf0e10cSrcweir #include "linkeddocuments.hxx"
168*cdf0e10cSrcweir #endif
169*cdf0e10cSrcweir #ifndef _SV_LSTBOX_HXX
170*cdf0e10cSrcweir #include <vcl/lstbox.hxx>
171*cdf0e10cSrcweir #endif
172*cdf0e10cSrcweir #ifndef _DBHELPER_DBEXCEPTION_HXX_
173*cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
174*cdf0e10cSrcweir #endif
175*cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_
176*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
177*cdf0e10cSrcweir #endif
178*cdf0e10cSrcweir #ifndef _DBAUI_SQLMESSAGE_HXX_
179*cdf0e10cSrcweir #include "sqlmessage.hxx"
180*cdf0e10cSrcweir #endif
181*cdf0e10cSrcweir #ifndef _STRING_HXX
182*cdf0e10cSrcweir #include <tools/string.hxx>
183*cdf0e10cSrcweir #endif
184*cdf0e10cSrcweir #ifndef DBAUI_DBEXCHANGE_HXX
185*cdf0e10cSrcweir #include "dbexchange.hxx"
186*cdf0e10cSrcweir #endif
187*cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
188*cdf0e10cSrcweir #include "UITools.hxx"
189*cdf0e10cSrcweir #endif
190*cdf0e10cSrcweir #include <algorithm>
191*cdf0e10cSrcweir #ifndef _SVTREEBOX_HXX
192*cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
193*cdf0e10cSrcweir #endif
194*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XREPORTDOCUMENTSSUPPLIER_HPP_
195*cdf0e10cSrcweir #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
196*cdf0e10cSrcweir #endif
197*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XFORMDOCUMENTSSUPPLIER_HPP_
198*cdf0e10cSrcweir #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
199*cdf0e10cSrcweir #endif
200*cdf0e10cSrcweir #ifndef _FILEDLGHELPER_HXX
201*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
202*cdf0e10cSrcweir #endif
203*cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
204*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
205*cdf0e10cSrcweir #endif
206*cdf0e10cSrcweir #ifndef _SFX_DOCFILT_HACK_HXX
207*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
208*cdf0e10cSrcweir #endif
209*cdf0e10cSrcweir #ifndef _SVT_FILEVIEW_HXX
210*cdf0e10cSrcweir #include <svtools/fileview.hxx>
211*cdf0e10cSrcweir #endif
212*cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H
213*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
214*cdf0e10cSrcweir #endif
215*cdf0e10cSrcweir #ifndef DBACCESS_SOURCE_UI_MISC_DEFAULTOBJECTNAMECHECK_HXX
216*cdf0e10cSrcweir #include "defaultobjectnamecheck.hxx"
217*cdf0e10cSrcweir #endif
218*cdf0e10cSrcweir #ifndef _VOS_MUTEX_HXX_
219*cdf0e10cSrcweir #include <vos/mutex.hxx>
220*cdf0e10cSrcweir #endif
221*cdf0e10cSrcweir #include "subcomponentmanager.hxx"
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir //........................................................................
224*cdf0e10cSrcweir namespace dbaui
225*cdf0e10cSrcweir {
226*cdf0e10cSrcweir //........................................................................
227*cdf0e10cSrcweir using namespace ::dbtools;
228*cdf0e10cSrcweir using namespace ::svx;
229*cdf0e10cSrcweir using namespace ::svtools;
230*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
231*cdf0e10cSrcweir using namespace ::com::sun::star::task;
232*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
233*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
234*cdf0e10cSrcweir using namespace ::com::sun::star::container;
235*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
236*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
237*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
238*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
239*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
240*cdf0e10cSrcweir using namespace ::com::sun::star::util;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir // -----------------------------------------------------------------------------
243*cdf0e10cSrcweir void OApplicationController::deleteTables(const ::std::vector< ::rtl::OUString>& _rList)
244*cdf0e10cSrcweir {
245*cdf0e10cSrcweir     SharedConnection xConnection( ensureConnection() );
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	Reference<XTablesSupplier> xSup(xConnection,UNO_QUERY);
248*cdf0e10cSrcweir 	OSL_ENSURE(xSup.is(),"OApplicationController::deleteTable: no XTablesSuppier!");
249*cdf0e10cSrcweir 	if ( xSup.is() )
250*cdf0e10cSrcweir 	{
251*cdf0e10cSrcweir 		Reference<XNameAccess> xTables = xSup->getTables();
252*cdf0e10cSrcweir 		Reference<XDrop> xDrop(xTables,UNO_QUERY);
253*cdf0e10cSrcweir 		if ( xDrop.is() )
254*cdf0e10cSrcweir 		{
255*cdf0e10cSrcweir 			bool bConfirm = true;
256*cdf0e10cSrcweir 			::std::vector< ::rtl::OUString>::const_iterator aEnd = _rList.end();
257*cdf0e10cSrcweir 			for (::std::vector< ::rtl::OUString>::const_iterator aIter = _rList.begin(); aIter != aEnd; ++aIter)
258*cdf0e10cSrcweir 			{
259*cdf0e10cSrcweir 				::rtl::OUString sTableName = *aIter;
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 				sal_Int32 nResult = RET_YES;
262*cdf0e10cSrcweir 				if ( bConfirm )
263*cdf0e10cSrcweir 					nResult = ::dbaui::askForUserAction(getView(),STR_TITLE_CONFIRM_DELETION ,STR_QUERY_DELETE_TABLE,_rList.size() > 1 && (aIter+1) != _rList.end(),sTableName);
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir                 bool bUserConfirmedDelete =
266*cdf0e10cSrcweir                             ( RET_YES == nResult )
267*cdf0e10cSrcweir                         ||  ( RET_ALL == nResult );
268*cdf0e10cSrcweir 				if ( bUserConfirmedDelete && m_pSubComponentManager->closeSubFrames( sTableName, E_TABLE ) )
269*cdf0e10cSrcweir 				{
270*cdf0e10cSrcweir 					SQLExceptionInfo aErrorInfo;
271*cdf0e10cSrcweir 					try
272*cdf0e10cSrcweir 					{
273*cdf0e10cSrcweir 						if ( xTables->hasByName(sTableName) )
274*cdf0e10cSrcweir 							xDrop->dropByName(sTableName);
275*cdf0e10cSrcweir 						else
276*cdf0e10cSrcweir 						{// could be a view
277*cdf0e10cSrcweir 							Reference<XViewsSupplier> xViewsSup(xConnection,UNO_QUERY);
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 							Reference<XNameAccess> xViews;
280*cdf0e10cSrcweir 							if ( xViewsSup.is() )
281*cdf0e10cSrcweir 							{
282*cdf0e10cSrcweir 								xViews = xViewsSup->getViews();
283*cdf0e10cSrcweir 								if ( xViews.is() && xViews->hasByName(sTableName) )
284*cdf0e10cSrcweir 								{
285*cdf0e10cSrcweir 									xDrop.set(xViews,UNO_QUERY);
286*cdf0e10cSrcweir 									if ( xDrop.is() )
287*cdf0e10cSrcweir 										xDrop->dropByName(sTableName);
288*cdf0e10cSrcweir 								}
289*cdf0e10cSrcweir 							}
290*cdf0e10cSrcweir 						}
291*cdf0e10cSrcweir 					}
292*cdf0e10cSrcweir 					catch(SQLContext& e) { aErrorInfo = e; }
293*cdf0e10cSrcweir 					catch(SQLWarning& e) { aErrorInfo = e; }
294*cdf0e10cSrcweir 					catch(SQLException& e) { aErrorInfo = e; }
295*cdf0e10cSrcweir 					catch(WrappedTargetException& e)
296*cdf0e10cSrcweir 					{
297*cdf0e10cSrcweir 						SQLException aSql;
298*cdf0e10cSrcweir 						if(e.TargetException >>= aSql)
299*cdf0e10cSrcweir 							aErrorInfo = aSql;
300*cdf0e10cSrcweir 						else
301*cdf0e10cSrcweir 							OSL_ENSURE(sal_False, "OApplicationController::implDropTable: something strange happended!");
302*cdf0e10cSrcweir 					}
303*cdf0e10cSrcweir 		            catch( const Exception& )
304*cdf0e10cSrcweir 		            {
305*cdf0e10cSrcweir                         DBG_UNHANDLED_EXCEPTION();
306*cdf0e10cSrcweir 		            }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir 					if ( aErrorInfo.isValid() )
309*cdf0e10cSrcweir 						showError(aErrorInfo);
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 					if ( RET_ALL == nResult )
312*cdf0e10cSrcweir 						bConfirm = false;
313*cdf0e10cSrcweir 				}
314*cdf0e10cSrcweir 				else
315*cdf0e10cSrcweir 					break;
316*cdf0e10cSrcweir 			}
317*cdf0e10cSrcweir 		}
318*cdf0e10cSrcweir 		else
319*cdf0e10cSrcweir 		{
320*cdf0e10cSrcweir 			String sMessage(ModuleRes(STR_MISSING_TABLES_XDROP));
321*cdf0e10cSrcweir 			ErrorBox aError(getView(), WB_OK, sMessage);
322*cdf0e10cSrcweir 			aError.Execute();
323*cdf0e10cSrcweir 		}
324*cdf0e10cSrcweir 	}
325*cdf0e10cSrcweir }
326*cdf0e10cSrcweir // -----------------------------------------------------------------------------
327*cdf0e10cSrcweir void OApplicationController::deleteObjects( ElementType _eType, const ::std::vector< ::rtl::OUString>& _rList, bool _bConfirm )
328*cdf0e10cSrcweir {
329*cdf0e10cSrcweir     Reference< XNameContainer > xNames( getElements( _eType ), UNO_QUERY );
330*cdf0e10cSrcweir 	Reference< XHierarchicalNameContainer > xHierarchyName( xNames, UNO_QUERY );
331*cdf0e10cSrcweir 	if ( xNames.is() )
332*cdf0e10cSrcweir 	{
333*cdf0e10cSrcweir 		ByteString sDialogPosition;
334*cdf0e10cSrcweir 		svtools::QueryDeleteResult_Impl eResult = _bConfirm ? svtools::QUERYDELETE_YES : svtools::QUERYDELETE_ALL;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir         // The list of elements to delete is allowed to contain related elements: A given element may
337*cdf0e10cSrcweir         // be the ancestor or child of another element from the list.
338*cdf0e10cSrcweir         // We want to ensure that ancestors get deleted first, so we normalize the list in this respect.
339*cdf0e10cSrcweir         // #i33353# - 2004-09-27 - fs@openoffice.org
340*cdf0e10cSrcweir         ::std::set< ::rtl::OUString > aDeleteNames;
341*cdf0e10cSrcweir             // Note that this implicitly uses ::std::less< ::rtl::OUString > a comparison operation, which
342*cdf0e10cSrcweir             // results in lexicographical order, which is exactly what we need, because "foo" is *before*
343*cdf0e10cSrcweir             // any "foo/bar" in this order.
344*cdf0e10cSrcweir         ::std::copy(
345*cdf0e10cSrcweir             _rList.begin(), _rList.end(),
346*cdf0e10cSrcweir             ::std::insert_iterator< ::std::set< ::rtl::OUString > >( aDeleteNames, aDeleteNames.begin() )
347*cdf0e10cSrcweir         );
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir         ::std::set< ::rtl::OUString >::size_type nCount = aDeleteNames.size();
350*cdf0e10cSrcweir         for ( ::std::set< ::rtl::OUString >::size_type nObjectsLeft = nCount; !aDeleteNames.empty(); )
351*cdf0e10cSrcweir 		{
352*cdf0e10cSrcweir             ::std::set< ::rtl::OUString >::iterator  aThisRound = aDeleteNames.begin();
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 			if ( eResult != svtools::QUERYDELETE_ALL )
355*cdf0e10cSrcweir 			{
356*cdf0e10cSrcweir 				svtools::QueryDeleteDlg_Impl aDlg( getView(), *aThisRound );
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir                 if ( sDialogPosition.Len() )
359*cdf0e10cSrcweir 					aDlg.SetWindowState( sDialogPosition );
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir                 if ( nObjectsLeft > 1 )
362*cdf0e10cSrcweir 					aDlg.EnableAllButton();
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir                 if ( aDlg.Execute() == RET_OK )
365*cdf0e10cSrcweir 					eResult = aDlg.GetResult();
366*cdf0e10cSrcweir 				else
367*cdf0e10cSrcweir 					return;
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 				sDialogPosition = aDlg.GetWindowState( );
370*cdf0e10cSrcweir 			}
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir             bool bSuccess = false;
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir             bool bUserConfirmedDelete =
375*cdf0e10cSrcweir                         ( eResult == svtools::QUERYDELETE_ALL )
376*cdf0e10cSrcweir                     ||  ( eResult == svtools::QUERYDELETE_YES );
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir             if  (   bUserConfirmedDelete
379*cdf0e10cSrcweir                 &&  (   ( _eType == E_QUERY ) ? m_pSubComponentManager->closeSubFrames( *aThisRound, _eType ) : true )
380*cdf0e10cSrcweir                 )
381*cdf0e10cSrcweir 			{
382*cdf0e10cSrcweir 				try
383*cdf0e10cSrcweir 				{
384*cdf0e10cSrcweir 					if ( xHierarchyName.is() )
385*cdf0e10cSrcweir 						xHierarchyName->removeByHierarchicalName( *aThisRound );
386*cdf0e10cSrcweir 					else
387*cdf0e10cSrcweir 						xNames->removeByName( *aThisRound );
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir                     bSuccess = true;
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir                     // now that we removed the element, care for all it's child elements
392*cdf0e10cSrcweir                     // which may also be a part of the list
393*cdf0e10cSrcweir                     // #i33353# - 2004-09-27 - fs@openoffice.org
394*cdf0e10cSrcweir                     OSL_ENSURE( aThisRound->getLength() - 1 >= 0, "OApplicationController::deleteObjects: empty name?" );
395*cdf0e10cSrcweir 					::rtl::OUStringBuffer sSmallestSiblingName( *aThisRound );
396*cdf0e10cSrcweir                     sSmallestSiblingName.append( (sal_Unicode)( '/' + 1) );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir                     ::std::set< ::rtl::OUString >::iterator aUpperChildrenBound = aDeleteNames.lower_bound( sSmallestSiblingName.makeStringAndClear() );
399*cdf0e10cSrcweir                     for ( ::std::set< ::rtl::OUString >::iterator aObsolete = aThisRound;
400*cdf0e10cSrcweir                           aObsolete != aUpperChildrenBound;
401*cdf0e10cSrcweir                         )
402*cdf0e10cSrcweir                     {
403*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
404*cdf0e10cSrcweir                         ::rtl::OUString sObsoleteName = *aObsolete;
405*cdf0e10cSrcweir #endif
406*cdf0e10cSrcweir                         ::std::set< ::rtl::OUString >::iterator aNextObsolete = aObsolete; ++aNextObsolete;
407*cdf0e10cSrcweir                         aDeleteNames.erase( aObsolete );
408*cdf0e10cSrcweir                         --nObjectsLeft;
409*cdf0e10cSrcweir                         aObsolete = aNextObsolete;
410*cdf0e10cSrcweir                     }
411*cdf0e10cSrcweir 				}
412*cdf0e10cSrcweir 				catch(const SQLException&)
413*cdf0e10cSrcweir 				{
414*cdf0e10cSrcweir                     showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
415*cdf0e10cSrcweir 				}
416*cdf0e10cSrcweir 				catch(WrappedTargetException& e)
417*cdf0e10cSrcweir 				{
418*cdf0e10cSrcweir 					SQLException aSql;
419*cdf0e10cSrcweir 					if ( e.TargetException >>= aSql )
420*cdf0e10cSrcweir 						showError( SQLExceptionInfo( e.TargetException ) );
421*cdf0e10cSrcweir 					else
422*cdf0e10cSrcweir 						OSL_ENSURE( sal_False, "OApplicationController::deleteObjects: something strange happended!" );
423*cdf0e10cSrcweir 				}
424*cdf0e10cSrcweir                 catch( const Exception& )
425*cdf0e10cSrcweir                 {
426*cdf0e10cSrcweir                     DBG_UNHANDLED_EXCEPTION();
427*cdf0e10cSrcweir                 }
428*cdf0e10cSrcweir 			}
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir             if ( !bSuccess )
431*cdf0e10cSrcweir             {
432*cdf0e10cSrcweir                 // okay, this object could not be deleted (or the user did not want to delete it),
433*cdf0e10cSrcweir                 // but continue with the rest
434*cdf0e10cSrcweir                 aDeleteNames.erase( aThisRound );
435*cdf0e10cSrcweir                 --nObjectsLeft;
436*cdf0e10cSrcweir             }
437*cdf0e10cSrcweir 		}
438*cdf0e10cSrcweir 	}
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir // -----------------------------------------------------------------------------
441*cdf0e10cSrcweir void OApplicationController::deleteEntries()
442*cdf0e10cSrcweir {
443*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
444*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 	if ( getContainer() )
447*cdf0e10cSrcweir 	{
448*cdf0e10cSrcweir 		::std::vector< ::rtl::OUString> aList;
449*cdf0e10cSrcweir 		getSelectionElementNames(aList);
450*cdf0e10cSrcweir 		ElementType eType = getContainer()->getElementType();
451*cdf0e10cSrcweir 		switch(eType)
452*cdf0e10cSrcweir 		{
453*cdf0e10cSrcweir 		case E_TABLE:
454*cdf0e10cSrcweir 			deleteTables(aList);
455*cdf0e10cSrcweir 			break;
456*cdf0e10cSrcweir 		case E_QUERY:
457*cdf0e10cSrcweir 			deleteObjects( E_QUERY, aList, true );
458*cdf0e10cSrcweir 			break;
459*cdf0e10cSrcweir 		case E_FORM:
460*cdf0e10cSrcweir 			deleteObjects( E_FORM, aList, true );
461*cdf0e10cSrcweir 			break;
462*cdf0e10cSrcweir 		case E_REPORT:
463*cdf0e10cSrcweir 			deleteObjects( E_REPORT, aList, true );
464*cdf0e10cSrcweir 			break;
465*cdf0e10cSrcweir         case E_NONE:
466*cdf0e10cSrcweir             break;
467*cdf0e10cSrcweir 		}
468*cdf0e10cSrcweir 	}
469*cdf0e10cSrcweir }
470*cdf0e10cSrcweir // -----------------------------------------------------------------------------
471*cdf0e10cSrcweir const SharedConnection& OApplicationController::ensureConnection( ::dbtools::SQLExceptionInfo* _pErrorInfo )
472*cdf0e10cSrcweir {
473*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
474*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir     if ( !m_xDataSourceConnection.is() )
477*cdf0e10cSrcweir     {
478*cdf0e10cSrcweir 		WaitObject aWO(getView());
479*cdf0e10cSrcweir 		String sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
480*cdf0e10cSrcweir 		sConnectingContext.SearchAndReplaceAscii("$name$", getStrippedDatabaseName());
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir 		m_xDataSourceConnection.reset( connect( getDatabaseName(), sConnectingContext, _pErrorInfo ) );
483*cdf0e10cSrcweir         if ( m_xDataSourceConnection.is() )
484*cdf0e10cSrcweir         {
485*cdf0e10cSrcweir             SQLExceptionInfo aError;
486*cdf0e10cSrcweir             try
487*cdf0e10cSrcweir             {
488*cdf0e10cSrcweir                 m_xMetaData = m_xDataSourceConnection->getMetaData();
489*cdf0e10cSrcweir             }
490*cdf0e10cSrcweir             catch( const SQLException& )
491*cdf0e10cSrcweir             {
492*cdf0e10cSrcweir                 aError = ::cppu::getCaughtException();
493*cdf0e10cSrcweir             }
494*cdf0e10cSrcweir             catch( const Exception& )
495*cdf0e10cSrcweir             {
496*cdf0e10cSrcweir             	DBG_UNHANDLED_EXCEPTION();
497*cdf0e10cSrcweir             }
498*cdf0e10cSrcweir             if ( aError.isValid() )
499*cdf0e10cSrcweir             {
500*cdf0e10cSrcweir                 if ( _pErrorInfo )
501*cdf0e10cSrcweir                 {
502*cdf0e10cSrcweir                     *_pErrorInfo = aError;
503*cdf0e10cSrcweir                 }
504*cdf0e10cSrcweir                 else
505*cdf0e10cSrcweir                 {
506*cdf0e10cSrcweir                     showError( aError );
507*cdf0e10cSrcweir                 }
508*cdf0e10cSrcweir             }
509*cdf0e10cSrcweir         }
510*cdf0e10cSrcweir 	}
511*cdf0e10cSrcweir     return m_xDataSourceConnection;
512*cdf0e10cSrcweir }
513*cdf0e10cSrcweir // -----------------------------------------------------------------------------
514*cdf0e10cSrcweir sal_Bool OApplicationController::isDataSourceReadOnly() const
515*cdf0e10cSrcweir {
516*cdf0e10cSrcweir 	Reference<XStorable> xStore(m_xModel,UNO_QUERY);
517*cdf0e10cSrcweir 	return !xStore.is() || xStore->isReadonly();
518*cdf0e10cSrcweir }
519*cdf0e10cSrcweir // -----------------------------------------------------------------------------
520*cdf0e10cSrcweir sal_Bool OApplicationController::isConnectionReadOnly() const
521*cdf0e10cSrcweir {
522*cdf0e10cSrcweir 	sal_Bool bIsConnectionReadOnly = sal_True;
523*cdf0e10cSrcweir 	if ( m_xMetaData.is() )
524*cdf0e10cSrcweir 	{
525*cdf0e10cSrcweir 		try
526*cdf0e10cSrcweir 		{
527*cdf0e10cSrcweir 			bIsConnectionReadOnly = m_xMetaData->isReadOnly();
528*cdf0e10cSrcweir 		}
529*cdf0e10cSrcweir 		catch(const SQLException&)
530*cdf0e10cSrcweir 		{
531*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
532*cdf0e10cSrcweir 		}
533*cdf0e10cSrcweir 	}
534*cdf0e10cSrcweir 	// TODO check configuration
535*cdf0e10cSrcweir 	return bIsConnectionReadOnly;
536*cdf0e10cSrcweir }
537*cdf0e10cSrcweir // -----------------------------------------------------------------------------
538*cdf0e10cSrcweir Reference< XNameAccess > OApplicationController::getElements( ElementType _eType )
539*cdf0e10cSrcweir {
540*cdf0e10cSrcweir 	Reference< XNameAccess > xElements;
541*cdf0e10cSrcweir 	try
542*cdf0e10cSrcweir 	{
543*cdf0e10cSrcweir 		switch ( _eType )
544*cdf0e10cSrcweir 		{
545*cdf0e10cSrcweir 		case E_REPORT:
546*cdf0e10cSrcweir 		{
547*cdf0e10cSrcweir 			Reference< XReportDocumentsSupplier > xSupp( m_xModel, UNO_QUERY_THROW );
548*cdf0e10cSrcweir             xElements.set( xSupp->getReportDocuments(), UNO_SET_THROW );
549*cdf0e10cSrcweir 		}
550*cdf0e10cSrcweir 		break;
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir         case E_FORM:
553*cdf0e10cSrcweir 		{
554*cdf0e10cSrcweir 			Reference< XFormDocumentsSupplier > xSupp( m_xModel, UNO_QUERY_THROW );
555*cdf0e10cSrcweir             xElements.set( xSupp->getFormDocuments(), UNO_SET_THROW );
556*cdf0e10cSrcweir 		}
557*cdf0e10cSrcweir 		break;
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir         case E_QUERY:
560*cdf0e10cSrcweir 		{
561*cdf0e10cSrcweir 			xElements.set( getQueryDefintions(), UNO_QUERY_THROW );
562*cdf0e10cSrcweir 		}
563*cdf0e10cSrcweir 		break;
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir 		case E_TABLE:
566*cdf0e10cSrcweir 		{
567*cdf0e10cSrcweir             if ( m_xDataSourceConnection.is() )
568*cdf0e10cSrcweir 			{
569*cdf0e10cSrcweir 				Reference< XTablesSupplier > xSup( getConnection(), UNO_QUERY_THROW );
570*cdf0e10cSrcweir 				xElements.set( xSup->getTables(), UNO_SET_THROW );
571*cdf0e10cSrcweir 			}
572*cdf0e10cSrcweir 		}
573*cdf0e10cSrcweir 		break;
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir         default:
576*cdf0e10cSrcweir             break;
577*cdf0e10cSrcweir 		}
578*cdf0e10cSrcweir 	}
579*cdf0e10cSrcweir 	catch(const Exception&)
580*cdf0e10cSrcweir 	{
581*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
582*cdf0e10cSrcweir 	}
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 	return xElements;
585*cdf0e10cSrcweir }
586*cdf0e10cSrcweir // -----------------------------------------------------------------------------
587*cdf0e10cSrcweir void OApplicationController::getSelectionElementNames(::std::vector< ::rtl::OUString>& _rNames) const
588*cdf0e10cSrcweir {
589*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
590*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 	OSL_ENSURE(getContainer(),"View isn't valid! -> GPF");
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir 	getContainer()->getSelectionElementNames( _rNames );
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir // -----------------------------------------------------------------------------
598*cdf0e10cSrcweir ::std::auto_ptr< OLinkedDocumentsAccess > OApplicationController::getDocumentsAccess( ElementType _eType )
599*cdf0e10cSrcweir {
600*cdf0e10cSrcweir     OSL_ENSURE( ( _eType == E_TABLE ) || ( _eType == E_QUERY ) || ( _eType == E_FORM ) || ( _eType == E_REPORT ),
601*cdf0e10cSrcweir         "OApplicationController::getDocumentsAccess: only forms and reports are supported here!" );
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir     SharedConnection xConnection( ensureConnection() );
604*cdf0e10cSrcweir     Reference< XNameAccess > xDocContainer;
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir     if ( ( _eType == E_FORM ) | ( _eType == E_REPORT ) )
607*cdf0e10cSrcweir     {
608*cdf0e10cSrcweir         xDocContainer.set( getElements( _eType ) );
609*cdf0e10cSrcweir         OSL_ENSURE( xDocContainer.is(), "OApplicationController::getDocumentsAccess: invalid container!" );
610*cdf0e10cSrcweir     }
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir     ::std::auto_ptr< OLinkedDocumentsAccess > pDocuments( new OLinkedDocumentsAccess(
613*cdf0e10cSrcweir         getView(), this, getORB(), xDocContainer, xConnection, getDatabaseName()
614*cdf0e10cSrcweir     ) );
615*cdf0e10cSrcweir     return pDocuments;
616*cdf0e10cSrcweir }
617*cdf0e10cSrcweir // -----------------------------------------------------------------------------
618*cdf0e10cSrcweir TransferableHelper* OApplicationController::copyObject()
619*cdf0e10cSrcweir {
620*cdf0e10cSrcweir 	try
621*cdf0e10cSrcweir 	{
622*cdf0e10cSrcweir 		::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
623*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( getMutex() );
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir 		ElementType eType = getContainer()->getElementType();
626*cdf0e10cSrcweir 		TransferableHelper* pData = NULL;
627*cdf0e10cSrcweir 		switch( eType )
628*cdf0e10cSrcweir 		{
629*cdf0e10cSrcweir 			case E_TABLE:
630*cdf0e10cSrcweir 			case E_QUERY:
631*cdf0e10cSrcweir 			{
632*cdf0e10cSrcweir                 SharedConnection xConnection( ensureConnection() );
633*cdf0e10cSrcweir 				Reference< XDatabaseMetaData> xMetaData;
634*cdf0e10cSrcweir 				if ( xConnection.is() )
635*cdf0e10cSrcweir 					xMetaData = xConnection->getMetaData();
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir 				::rtl::OUString sName = getContainer()->getQualifiedName( NULL );
638*cdf0e10cSrcweir                 if ( sName.getLength() )
639*cdf0e10cSrcweir                 {
640*cdf0e10cSrcweir 				    ::rtl::OUString sDataSource	= getDatabaseName();
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir 				    if ( eType == E_TABLE )
643*cdf0e10cSrcweir 				    {
644*cdf0e10cSrcweir 					    pData = new ODataClipboard(sDataSource, CommandType::TABLE, sName, xConnection, getNumberFormatter(xConnection,getORB()), getORB());
645*cdf0e10cSrcweir 				    }
646*cdf0e10cSrcweir 				    else
647*cdf0e10cSrcweir 				    {
648*cdf0e10cSrcweir 					    pData = new ODataClipboard(sDataSource, CommandType::QUERY, sName, getNumberFormatter(xConnection,getORB()), getORB());
649*cdf0e10cSrcweir 				    }
650*cdf0e10cSrcweir                 }
651*cdf0e10cSrcweir 			}
652*cdf0e10cSrcweir 				break;
653*cdf0e10cSrcweir 			case E_FORM:
654*cdf0e10cSrcweir 			case E_REPORT:
655*cdf0e10cSrcweir 			{
656*cdf0e10cSrcweir 				::std::vector< ::rtl::OUString> aList;
657*cdf0e10cSrcweir 				getSelectionElementNames(aList);
658*cdf0e10cSrcweir 				Reference< XHierarchicalNameAccess > xElements(getElements(eType),UNO_QUERY);
659*cdf0e10cSrcweir 				if ( xElements.is() && !aList.empty() )
660*cdf0e10cSrcweir 				{
661*cdf0e10cSrcweir 					Reference< XContent> xContent(xElements->getByHierarchicalName(*aList.begin()),UNO_QUERY);
662*cdf0e10cSrcweir 					pData = new OComponentTransferable( getDatabaseName(), xContent );
663*cdf0e10cSrcweir 				}
664*cdf0e10cSrcweir 			}
665*cdf0e10cSrcweir 			break;
666*cdf0e10cSrcweir             default:
667*cdf0e10cSrcweir                 break;
668*cdf0e10cSrcweir 		}
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir 		// the owner ship goes to ODataClipboards
671*cdf0e10cSrcweir 		return pData;
672*cdf0e10cSrcweir 	}
673*cdf0e10cSrcweir     catch(const SQLException&)
674*cdf0e10cSrcweir     {
675*cdf0e10cSrcweir         showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
676*cdf0e10cSrcweir     }
677*cdf0e10cSrcweir 	catch( const Exception& )
678*cdf0e10cSrcweir 	{
679*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
680*cdf0e10cSrcweir 	}
681*cdf0e10cSrcweir 	return NULL;
682*cdf0e10cSrcweir }
683*cdf0e10cSrcweir // -----------------------------------------------------------------------------
684*cdf0e10cSrcweir sal_Bool OApplicationController::paste( ElementType _eType,const ::svx::ODataAccessDescriptor& _rPasteData,const String& _sParentFolder ,sal_Bool _bMove)
685*cdf0e10cSrcweir {
686*cdf0e10cSrcweir 	try
687*cdf0e10cSrcweir 	{
688*cdf0e10cSrcweir 		if ( _eType == E_QUERY )
689*cdf0e10cSrcweir 		{
690*cdf0e10cSrcweir 			sal_Int32 nCommandType = CommandType::TABLE;
691*cdf0e10cSrcweir 			if ( _rPasteData.has(daCommandType) )
692*cdf0e10cSrcweir 				_rPasteData[daCommandType]		>>= nCommandType;
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir 			if ( CommandType::QUERY == nCommandType || CommandType::COMMAND == nCommandType )
695*cdf0e10cSrcweir 			{
696*cdf0e10cSrcweir 				// read all nescessary data
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir 				::rtl::OUString	sCommand;
699*cdf0e10cSrcweir 				sal_Bool bEscapeProcessing = sal_True;
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir 				_rPasteData[daCommand] >>= sCommand;
702*cdf0e10cSrcweir 				if ( _rPasteData.has(daEscapeProcessing) )
703*cdf0e10cSrcweir 					_rPasteData[daEscapeProcessing]	>>= bEscapeProcessing;
704*cdf0e10cSrcweir 
705*cdf0e10cSrcweir 				// plausibility check
706*cdf0e10cSrcweir 				sal_Bool bValidDescriptor = sal_False;
707*cdf0e10cSrcweir                 ::rtl::OUString	sDataSourceName = _rPasteData.getDataSource();
708*cdf0e10cSrcweir 				if (CommandType::QUERY == nCommandType)
709*cdf0e10cSrcweir 					bValidDescriptor = sDataSourceName.getLength() && sCommand.getLength();
710*cdf0e10cSrcweir 				else if (CommandType::COMMAND == nCommandType)
711*cdf0e10cSrcweir 					bValidDescriptor = (0 != sCommand.getLength());
712*cdf0e10cSrcweir 				if (!bValidDescriptor)
713*cdf0e10cSrcweir 				{
714*cdf0e10cSrcweir 					DBG_ERROR("OApplicationController::paste: invalid descriptor!");
715*cdf0e10cSrcweir 					return sal_False;
716*cdf0e10cSrcweir 				}
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir 				// the target object name (as we'll suggest it to the user)
719*cdf0e10cSrcweir                 ::rtl::OUString sTargetName;
720*cdf0e10cSrcweir 				try
721*cdf0e10cSrcweir 				{
722*cdf0e10cSrcweir 				    if ( CommandType::QUERY == nCommandType )
723*cdf0e10cSrcweir                         sTargetName = sCommand;
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir                     if ( !sTargetName.getLength() )
726*cdf0e10cSrcweir                     {
727*cdf0e10cSrcweir                         String sDefaultName = String( ModuleRes( STR_QRY_TITLE ) );
728*cdf0e10cSrcweir                         sDefaultName = sDefaultName.GetToken( 0, ' ' );
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir                         Reference< XNameAccess > xQueries( getQueryDefintions(), UNO_QUERY_THROW );
731*cdf0e10cSrcweir 				        sTargetName = ::dbtools::createUniqueName( xQueries, sDefaultName, sal_False );
732*cdf0e10cSrcweir                     }
733*cdf0e10cSrcweir 				}
734*cdf0e10cSrcweir 				catch(const Exception&)
735*cdf0e10cSrcweir 				{
736*cdf0e10cSrcweir 					DBG_UNHANDLED_EXCEPTION();
737*cdf0e10cSrcweir 				}
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir                 Reference< XPropertySet > xQuery;
740*cdf0e10cSrcweir 				if (CommandType::QUERY == nCommandType)
741*cdf0e10cSrcweir 				{
742*cdf0e10cSrcweir 					// need to extract the statement and the escape processing flag from the query object
743*cdf0e10cSrcweir 					sal_Bool bSuccess = sal_False;
744*cdf0e10cSrcweir 					try
745*cdf0e10cSrcweir 					{
746*cdf0e10cSrcweir 						// the concrete query
747*cdf0e10cSrcweir 						Reference< XQueryDefinitionsSupplier > xSourceQuerySup(
748*cdf0e10cSrcweir                             getDataSourceByName( sDataSourceName, getView(), getORB(), NULL ),
749*cdf0e10cSrcweir                             UNO_QUERY_THROW );
750*cdf0e10cSrcweir                         Reference< XNameAccess > xQueries( xSourceQuerySup->getQueryDefinitions(), UNO_SET_THROW );
751*cdf0e10cSrcweir 						if ( xQueries->hasByName( sCommand ) )
752*cdf0e10cSrcweir 						{
753*cdf0e10cSrcweir 							xQuery.set( xQueries->getByName(sCommand), UNO_QUERY_THROW );
754*cdf0e10cSrcweir 							bSuccess = true;
755*cdf0e10cSrcweir 						}
756*cdf0e10cSrcweir 					}
757*cdf0e10cSrcweir 					catch(SQLException&) { throw; }	// caught and handled by the outer catch
758*cdf0e10cSrcweir                     catch( const Exception& )
759*cdf0e10cSrcweir                     {
760*cdf0e10cSrcweir                         DBG_UNHANDLED_EXCEPTION();
761*cdf0e10cSrcweir                     }
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir 					if (!bSuccess)
764*cdf0e10cSrcweir 					{
765*cdf0e10cSrcweir 						DBG_ERROR("OApplicationController::paste: could not extract the source query object!");
766*cdf0e10cSrcweir 						// TODO: maybe this is worth an error message to be displayed to the user ....
767*cdf0e10cSrcweir 						return sal_False;
768*cdf0e10cSrcweir 					}
769*cdf0e10cSrcweir 				}
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir 				Reference< XNameContainer > xDestQueries(getQueryDefintions(), UNO_QUERY);
773*cdf0e10cSrcweir 				Reference< XSingleServiceFactory > xQueryFactory(xDestQueries, UNO_QUERY);
774*cdf0e10cSrcweir 				if (!xQueryFactory.is())
775*cdf0e10cSrcweir 				{
776*cdf0e10cSrcweir 					DBG_ERROR("OApplicationController::paste: invalid destination query container!");
777*cdf0e10cSrcweir 					return sal_False;
778*cdf0e10cSrcweir 				}
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir 				// here we have everything needed to create a new query object ...
781*cdf0e10cSrcweir 				// ... ehm, except a new name
782*cdf0e10cSrcweir                 ensureConnection();
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir                 DynamicTableOrQueryNameCheck aNameChecker( getConnection(), CommandType::QUERY );
785*cdf0e10cSrcweir                 ::dbtools::SQLExceptionInfo aDummy;
786*cdf0e10cSrcweir                 bool bNeedAskForName =  ( sCommand.getLength() == 0 )
787*cdf0e10cSrcweir                                             /* we did not have a source name, so the target name was auto-generated */
788*cdf0e10cSrcweir                                     ||  ( !aNameChecker.isNameValid( sTargetName, aDummy ) );
789*cdf0e10cSrcweir                                             /*  name is invalid in the target DB (e.g. because it already
790*cdf0e10cSrcweir                                                 has a /table/ with that name) */
791*cdf0e10cSrcweir                 if ( bNeedAskForName )
792*cdf0e10cSrcweir                 {
793*cdf0e10cSrcweir 				    OSaveAsDlg aAskForName(	getView(),
794*cdf0e10cSrcweir 										    CommandType::QUERY,
795*cdf0e10cSrcweir                                             getORB(),
796*cdf0e10cSrcweir 										    getConnection(),
797*cdf0e10cSrcweir 										    sTargetName,
798*cdf0e10cSrcweir                                             aNameChecker,
799*cdf0e10cSrcweir 										    SAD_ADDITIONAL_DESCRIPTION | SAD_TITLE_PASTE_AS);
800*cdf0e10cSrcweir 				    if ( RET_OK != aAskForName.Execute() )
801*cdf0e10cSrcweir 					    // cancelled by the user
802*cdf0e10cSrcweir 					    return sal_False;
803*cdf0e10cSrcweir 				    sTargetName = aAskForName.getName();
804*cdf0e10cSrcweir                 }
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir 				// create a new object
807*cdf0e10cSrcweir 				Reference< XPropertySet > xNewQuery(xQueryFactory->createInstance(), UNO_QUERY);
808*cdf0e10cSrcweir 				DBG_ASSERT(xNewQuery.is(), "OApplicationController::paste: invalid object created by factory!");
809*cdf0e10cSrcweir 				if (xNewQuery.is())
810*cdf0e10cSrcweir 				{
811*cdf0e10cSrcweir 					// initialize
812*cdf0e10cSrcweir 					if ( xQuery.is() )
813*cdf0e10cSrcweir 	                    ::comphelper::copyProperties(xQuery,xNewQuery);
814*cdf0e10cSrcweir 					else
815*cdf0e10cSrcweir 					{
816*cdf0e10cSrcweir                         xNewQuery->setPropertyValue(PROPERTY_COMMAND,makeAny(sCommand));
817*cdf0e10cSrcweir                         xNewQuery->setPropertyValue(PROPERTY_ESCAPE_PROCESSING,makeAny(bEscapeProcessing));
818*cdf0e10cSrcweir                     }
819*cdf0e10cSrcweir 					// insert
820*cdf0e10cSrcweir 					xDestQueries->insertByName( sTargetName, makeAny(xNewQuery) );
821*cdf0e10cSrcweir                     xNewQuery.set(xDestQueries->getByName( sTargetName),UNO_QUERY);
822*cdf0e10cSrcweir                     if ( xQuery.is() && xNewQuery.is() )
823*cdf0e10cSrcweir                     {
824*cdf0e10cSrcweir                         Reference<XColumnsSupplier> xSrcColSup(xQuery,UNO_QUERY);
825*cdf0e10cSrcweir                         Reference<XColumnsSupplier> xDstColSup(xNewQuery,UNO_QUERY);
826*cdf0e10cSrcweir                         if ( xSrcColSup.is() && xDstColSup.is() )
827*cdf0e10cSrcweir 	                    {
828*cdf0e10cSrcweir 		                    Reference<XNameAccess> xSrcNameAccess = xSrcColSup->getColumns();
829*cdf0e10cSrcweir                             Reference<XNameAccess> xDstNameAccess = xDstColSup->getColumns();
830*cdf0e10cSrcweir                             Reference<XDataDescriptorFactory> xFac(xDstNameAccess,UNO_QUERY);
831*cdf0e10cSrcweir                             Reference<XAppend> xAppend(xFac,UNO_QUERY);
832*cdf0e10cSrcweir 		                    if ( xSrcNameAccess.is() && xDstNameAccess.is() && xSrcNameAccess->hasElements() && xAppend.is() )
833*cdf0e10cSrcweir                             {
834*cdf0e10cSrcweir                                 Reference<XPropertySet> xDstProp(xFac->createDataDescriptor());
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir                                 Sequence< ::rtl::OUString> aSeq = xSrcNameAccess->getElementNames();
837*cdf0e10cSrcweir 			                    const ::rtl::OUString* pIter = aSeq.getConstArray();
838*cdf0e10cSrcweir 			                    const ::rtl::OUString* pEnd	  = pIter + aSeq.getLength();
839*cdf0e10cSrcweir 			                    for( ; pIter != pEnd ; ++pIter)
840*cdf0e10cSrcweir 			                    {
841*cdf0e10cSrcweir 				                    Reference<XPropertySet> xSrcProp(xSrcNameAccess->getByName(*pIter),UNO_QUERY);
842*cdf0e10cSrcweir                                     ::comphelper::copyProperties(xSrcProp,xDstProp);
843*cdf0e10cSrcweir                                     xAppend->appendByDescriptor(xDstProp);
844*cdf0e10cSrcweir                                 }
845*cdf0e10cSrcweir                             }
846*cdf0e10cSrcweir                         }
847*cdf0e10cSrcweir 					}
848*cdf0e10cSrcweir 				}
849*cdf0e10cSrcweir 			}
850*cdf0e10cSrcweir 			else
851*cdf0e10cSrcweir 				OSL_TRACE("There should be a sequence in it!");
852*cdf0e10cSrcweir 			return sal_True;
853*cdf0e10cSrcweir 		}
854*cdf0e10cSrcweir 		else if ( _rPasteData.has(daComponent) ) // forms or reports
855*cdf0e10cSrcweir 		{
856*cdf0e10cSrcweir 			Reference<XContent> xContent;
857*cdf0e10cSrcweir 			_rPasteData[daComponent] >>= xContent;
858*cdf0e10cSrcweir 			return insertHierachyElement(_eType,_sParentFolder,Reference<XNameAccess>(xContent,UNO_QUERY).is(),xContent,_bMove);
859*cdf0e10cSrcweir 		}
860*cdf0e10cSrcweir 	}
861*cdf0e10cSrcweir     catch(const SQLException&) { showError( SQLExceptionInfo( ::cppu::getCaughtException() ) ); }
862*cdf0e10cSrcweir 	catch(const Exception& )
863*cdf0e10cSrcweir 	{
864*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
865*cdf0e10cSrcweir 	}
866*cdf0e10cSrcweir 	return sal_False;
867*cdf0e10cSrcweir }
868*cdf0e10cSrcweir // -----------------------------------------------------------------------------
869*cdf0e10cSrcweir Reference<XNameContainer> OApplicationController::getQueryDefintions() const
870*cdf0e10cSrcweir {
871*cdf0e10cSrcweir 	Reference<XQueryDefinitionsSupplier> xSet(m_xDataSource,UNO_QUERY);
872*cdf0e10cSrcweir 	Reference<XNameContainer> xNames;
873*cdf0e10cSrcweir 	if ( xSet.is() )
874*cdf0e10cSrcweir 	{
875*cdf0e10cSrcweir 		xNames.set(xSet->getQueryDefinitions(),UNO_QUERY);
876*cdf0e10cSrcweir 	}
877*cdf0e10cSrcweir 	return xNames;
878*cdf0e10cSrcweir }
879*cdf0e10cSrcweir // -----------------------------------------------------------------------------
880*cdf0e10cSrcweir void OApplicationController::getSupportedFormats(ElementType _eType,::std::vector<SotFormatStringId>& _rFormatIds) const
881*cdf0e10cSrcweir {
882*cdf0e10cSrcweir 	switch( _eType )
883*cdf0e10cSrcweir 	{
884*cdf0e10cSrcweir 		case E_TABLE:
885*cdf0e10cSrcweir 			_rFormatIds.push_back(SOT_FORMATSTR_ID_DBACCESS_TABLE);
886*cdf0e10cSrcweir 			_rFormatIds.push_back(SOT_FORMAT_RTF);
887*cdf0e10cSrcweir 			_rFormatIds.push_back(SOT_FORMATSTR_ID_HTML);
888*cdf0e10cSrcweir 			// run through
889*cdf0e10cSrcweir 		case E_QUERY:
890*cdf0e10cSrcweir 			_rFormatIds.push_back(SOT_FORMATSTR_ID_DBACCESS_QUERY);
891*cdf0e10cSrcweir 			break;
892*cdf0e10cSrcweir         default:
893*cdf0e10cSrcweir             break;
894*cdf0e10cSrcweir 	}
895*cdf0e10cSrcweir }
896*cdf0e10cSrcweir // -----------------------------------------------------------------------------
897*cdf0e10cSrcweir sal_Bool OApplicationController::isTableFormat()  const
898*cdf0e10cSrcweir {
899*cdf0e10cSrcweir 	return m_aTableCopyHelper.isTableFormat(getViewClipboard());
900*cdf0e10cSrcweir }
901*cdf0e10cSrcweir // -----------------------------------------------------------------------------
902*cdf0e10cSrcweir IMPL_LINK( OApplicationController, OnAsyncDrop, void*, /*NOTINTERESTEDIN*/ )
903*cdf0e10cSrcweir {
904*cdf0e10cSrcweir 	m_nAsyncDrop = 0;
905*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
906*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir 	if ( m_aAsyncDrop.nType == E_TABLE )
910*cdf0e10cSrcweir 	{
911*cdf0e10cSrcweir         SharedConnection xConnection( ensureConnection() );
912*cdf0e10cSrcweir         if ( xConnection.is() )
913*cdf0e10cSrcweir 		    m_aTableCopyHelper.asyncCopyTagTable( m_aAsyncDrop, getDatabaseName(), xConnection );
914*cdf0e10cSrcweir 	}
915*cdf0e10cSrcweir 	else
916*cdf0e10cSrcweir 	{
917*cdf0e10cSrcweir 		if ( paste(m_aAsyncDrop.nType,m_aAsyncDrop.aDroppedData,m_aAsyncDrop.aUrl,m_aAsyncDrop.nAction == DND_ACTION_MOVE)
918*cdf0e10cSrcweir 			&& m_aAsyncDrop.nAction == DND_ACTION_MOVE )
919*cdf0e10cSrcweir 		{
920*cdf0e10cSrcweir 			Reference<XContent> xContent;
921*cdf0e10cSrcweir 			m_aAsyncDrop.aDroppedData[daComponent] >>= xContent;
922*cdf0e10cSrcweir 			::std::vector< ::rtl::OUString> aList;
923*cdf0e10cSrcweir 			sal_Int32 nIndex = 0;
924*cdf0e10cSrcweir 			::rtl::OUString sName = xContent->getIdentifier()->getContentIdentifier();
925*cdf0e10cSrcweir 			::rtl::OUString sErase = sName.getToken(0,'/',nIndex); // we don't want to have the "private:forms" part
926*cdf0e10cSrcweir 			if ( nIndex != -1 )
927*cdf0e10cSrcweir 			{
928*cdf0e10cSrcweir 				aList.push_back(sName.copy(sErase.getLength() + 1));
929*cdf0e10cSrcweir 				deleteObjects( m_aAsyncDrop.nType, aList, false );
930*cdf0e10cSrcweir 			}
931*cdf0e10cSrcweir 		}
932*cdf0e10cSrcweir 	}
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir 	m_aAsyncDrop.aDroppedData.clear();
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir 	return 0L;
937*cdf0e10cSrcweir }
938*cdf0e10cSrcweir //........................................................................
939*cdf0e10cSrcweir }	// namespace dbaui
940*cdf0e10cSrcweir //........................................................................
941*cdf0e10cSrcweir 
942*cdf0e10cSrcweir 
943