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