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
25*b63233d8Sdamjan #include "precompiled_dbui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "AppController.hxx"
28cdf0e10cSrcweir #include "AppDetailView.hxx"
29cdf0e10cSrcweir #include "AppView.hxx"
30cdf0e10cSrcweir #include "dbaccess_slotid.hrc"
31cdf0e10cSrcweir #include "dbu_app.hrc"
32cdf0e10cSrcweir #include "dbustrings.hrc"
33cdf0e10cSrcweir #include "defaultobjectnamecheck.hxx"
34cdf0e10cSrcweir #include "dlgsave.hxx"
35cdf0e10cSrcweir #include "UITools.hxx"
36cdf0e10cSrcweir #include "subcomponentmanager.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /** === begin UNO includes === **/
39cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
40cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
41cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
43cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
44cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
47cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sdbcx/XRename.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sdb/ErrorCondition.hpp>
50cdf0e10cSrcweir #include <com/sun/star/sdb/application/DatabaseObject.hpp>
51cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
52cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
53cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
54cdf0e10cSrcweir #include <com/sun/star/ucb/Command.hpp>
55cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
56cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandProcessor.hpp>
57cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
58cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
59cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
60cdf0e10cSrcweir #include <com/sun/star/util/XRefreshable.hpp>
61cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
62cdf0e10cSrcweir /** === end UNO includes === **/
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
65cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
66cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
67cdf0e10cSrcweir #include <connectivity/sqlerror.hxx>
68cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
69cdf0e10cSrcweir #include <sfx2/mailmodelapi.hxx>
70cdf0e10cSrcweir #include <svx/dbaexchange.hxx>
71*b63233d8Sdamjan #include <toolkit/helper/vclunohelper.hxx>
72cdf0e10cSrcweir #include <tools/diagnose_ex.h>
73cdf0e10cSrcweir #include <tools/urlobj.hxx>
74cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
75cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
76cdf0e10cSrcweir #include <vcl/svapp.hxx>
77cdf0e10cSrcweir #include <vcl/waitobj.hxx>
78cdf0e10cSrcweir #include <vos/mutex.hxx>
79cdf0e10cSrcweir 
80cdf0e10cSrcweir //........................................................................
81cdf0e10cSrcweir namespace dbaui
82cdf0e10cSrcweir {
83cdf0e10cSrcweir using namespace ::dbtools;
84cdf0e10cSrcweir using namespace ::connectivity;
85cdf0e10cSrcweir using namespace ::svx;
86cdf0e10cSrcweir using namespace ::com::sun::star;
87cdf0e10cSrcweir using namespace ::com::sun::star::uno;
88cdf0e10cSrcweir using namespace ::com::sun::star::awt;
89cdf0e10cSrcweir using namespace ::com::sun::star::util;
90cdf0e10cSrcweir using namespace ::com::sun::star::frame;
91cdf0e10cSrcweir using namespace ::com::sun::star::lang;
92cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
93cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
94cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
95cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
96cdf0e10cSrcweir using namespace ::com::sun::star::beans;
97cdf0e10cSrcweir using namespace ::com::sun::star::container;
98cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir /** === begin UNO using === **/
101cdf0e10cSrcweir using ::com::sun::star::util::XCloseable;
102cdf0e10cSrcweir using ::com::sun::star::ui::XContextMenuInterceptor;
103cdf0e10cSrcweir /** === end UNO using === **/
104cdf0e10cSrcweir 
105cdf0e10cSrcweir namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
106cdf0e10cSrcweir namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir //........................................................................
109cdf0e10cSrcweir // -----------------------------------------------------------------------------
110cdf0e10cSrcweir 
111cdf0e10cSrcweir class CloseChecker : public ::cppu::WeakImplHelper1< com::sun::star::lang::XEventListener >
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     bool    m_bClosed;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir public:
CloseChecker()116cdf0e10cSrcweir     CloseChecker()
117cdf0e10cSrcweir         :m_bClosed( false )
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
~CloseChecker()121cdf0e10cSrcweir     virtual ~CloseChecker()
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir 
isClosed()125cdf0e10cSrcweir 	bool isClosed()
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		return true;
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	// interface XEventListener
disposing(const EventObject &)131cdf0e10cSrcweir     virtual void SAL_CALL disposing( const EventObject& /*Source*/ ) throw( RuntimeException )
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         m_bClosed = true;
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir };
137cdf0e10cSrcweir // -----------------------------------------------------------------------------
convertToView(const::rtl::OUString & _sName)138cdf0e10cSrcweir void OApplicationController::convertToView(const ::rtl::OUString& _sName)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir 	try
141cdf0e10cSrcweir 	{
142cdf0e10cSrcweir 		SharedConnection xConnection( getConnection() );
143cdf0e10cSrcweir 		Reference< XQueriesSupplier > xSup( xConnection, UNO_QUERY_THROW );
144cdf0e10cSrcweir 		Reference< XNameAccess > xQueries( xSup->getQueries(), UNO_QUERY_THROW );
145cdf0e10cSrcweir 		Reference< XPropertySet > xSourceObject( xQueries->getByName( _sName ), UNO_QUERY_THROW );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         Reference< XTablesSupplier > xTablesSup( xConnection, UNO_QUERY_THROW );
148cdf0e10cSrcweir 		Reference< XNameAccess > xTables( xTablesSup->getTables(), UNO_QUERY_THROW );
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 		Reference< XDatabaseMetaData  > xMeta = xConnection->getMetaData();
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 		String aName = String(ModuleRes(STR_TBL_TITLE));
153cdf0e10cSrcweir 		aName = aName.GetToken(0,' ');
154cdf0e10cSrcweir 		String aDefaultName = ::dbaui::createDefaultName(xMeta,xTables,aName);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         DynamicTableOrQueryNameCheck aNameChecker( xConnection, CommandType::TABLE );
157cdf0e10cSrcweir 		OSaveAsDlg aDlg( getView(), CommandType::TABLE, getORB(), xConnection, aDefaultName, aNameChecker );
158cdf0e10cSrcweir 		if ( aDlg.Execute() == RET_OK )
159cdf0e10cSrcweir 		{
160cdf0e10cSrcweir 			::rtl::OUString sName = aDlg.getName();
161cdf0e10cSrcweir 			::rtl::OUString sCatalog = aDlg.getCatalog();
162cdf0e10cSrcweir 			::rtl::OUString sSchema	 = aDlg.getSchema();
163cdf0e10cSrcweir 			::rtl::OUString sNewName(
164cdf0e10cSrcweir 			    ::dbtools::composeTableName( xMeta, sCatalog, sSchema, sName, sal_False, ::dbtools::eInTableDefinitions ) );
165cdf0e10cSrcweir 			Reference<XPropertySet> xView = ::dbaui::createView(sNewName,xConnection,xSourceObject);
166cdf0e10cSrcweir 			if ( !xView.is() )
167cdf0e10cSrcweir 				throw SQLException(String(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE)),*this,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
168cdf0e10cSrcweir 			getContainer()->elementAdded(E_TABLE,sNewName,makeAny(xView));
169cdf0e10cSrcweir 		}
170cdf0e10cSrcweir 	}
171cdf0e10cSrcweir 	catch(const SQLException& )
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 	catch( const Exception& )
176cdf0e10cSrcweir 	{
177cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir }
180cdf0e10cSrcweir // -----------------------------------------------------------------------------
pasteFormat(sal_uInt32 _nFormatId)181cdf0e10cSrcweir void OApplicationController::pasteFormat(sal_uInt32 _nFormatId)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir 	if ( _nFormatId )
184cdf0e10cSrcweir 	{
185cdf0e10cSrcweir 		try
186cdf0e10cSrcweir 		{
187cdf0e10cSrcweir 			const TransferableDataHelper& rClipboard = getViewClipboard();
188cdf0e10cSrcweir 			ElementType eType = getContainer()->getElementType();
189cdf0e10cSrcweir 			if ( eType == E_TABLE )
190cdf0e10cSrcweir             {
191cdf0e10cSrcweir                 m_aTableCopyHelper.pasteTable( _nFormatId, rClipboard, getDatabaseName(), ensureConnection() );
192cdf0e10cSrcweir             }
193cdf0e10cSrcweir 			else
194cdf0e10cSrcweir 				paste( eType, ODataAccessObjectTransferable::extractObjectDescriptor( rClipboard ) );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 		}
197cdf0e10cSrcweir 		catch( const Exception& )
198cdf0e10cSrcweir 		{
199cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
200cdf0e10cSrcweir 		}
201cdf0e10cSrcweir 	}
202cdf0e10cSrcweir }
203cdf0e10cSrcweir // -----------------------------------------------------------------------------
openDataSourceAdminDialog()204cdf0e10cSrcweir void OApplicationController::openDataSourceAdminDialog()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir 	openDialog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DatasourceAdministrationDialog" ) ) );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir // -----------------------------------------------------------------------------
openDialog(const::rtl::OUString & _sServiceName)210cdf0e10cSrcweir void OApplicationController::openDialog( const ::rtl::OUString& _sServiceName )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	try
213cdf0e10cSrcweir 	{
214cdf0e10cSrcweir 		::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
215cdf0e10cSrcweir 		::osl::MutexGuard aGuard( getMutex() );
216cdf0e10cSrcweir 		WaitObject aWO(getView());
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 		Sequence< Any > aArgs(3);
219cdf0e10cSrcweir         sal_Int32 nArgPos = 0;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 		Reference< ::com::sun::star::awt::XWindow> xWindow = getTopMostContainerWindow();
222cdf0e10cSrcweir 		if ( !xWindow.is() )
223cdf0e10cSrcweir 		{
224cdf0e10cSrcweir 			DBG_ASSERT( getContainer(), "OApplicationController::Construct: have no view!" );
225cdf0e10cSrcweir 			if ( getContainer() )
226cdf0e10cSrcweir 				xWindow = VCLUnoHelper::GetInterface(getView()->Window::GetParent());
227cdf0e10cSrcweir 		}
228cdf0e10cSrcweir 		// the parent window
229cdf0e10cSrcweir 		aArgs[nArgPos++] <<= PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow")),
230cdf0e10cSrcweir 									0,
231cdf0e10cSrcweir 									makeAny(xWindow),
232cdf0e10cSrcweir 									PropertyState_DIRECT_VALUE);
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 		// the initial selection
235cdf0e10cSrcweir 		::rtl::OUString sInitialSelection;
236cdf0e10cSrcweir 		if ( getContainer() )
237cdf0e10cSrcweir     		sInitialSelection = getDatabaseName();
238cdf0e10cSrcweir         if ( sInitialSelection.getLength() )
239cdf0e10cSrcweir         {
240cdf0e10cSrcweir 		    aArgs[ nArgPos++ ] <<= PropertyValue(
241cdf0e10cSrcweir 			    ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InitialSelection" ) ), 0,
242cdf0e10cSrcweir 			    makeAny( sInitialSelection ), PropertyState_DIRECT_VALUE );
243cdf0e10cSrcweir         }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir         SharedConnection xConnection( getConnection() );
246cdf0e10cSrcweir         if ( xConnection.is() )
247cdf0e10cSrcweir         {
248cdf0e10cSrcweir 			aArgs[ nArgPos++ ] <<= PropertyValue(
249cdf0e10cSrcweir 				PROPERTY_ACTIVE_CONNECTION, 0,
250cdf0e10cSrcweir 				makeAny( xConnection ), PropertyState_DIRECT_VALUE );
251cdf0e10cSrcweir         }
252cdf0e10cSrcweir         aArgs.realloc( nArgPos );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 		// create the dialog
255cdf0e10cSrcweir 		Reference< XExecutableDialog > xAdminDialog;
256cdf0e10cSrcweir 		xAdminDialog = Reference< XExecutableDialog >(
257cdf0e10cSrcweir 			getORB()->createInstanceWithArguments(_sServiceName,aArgs), UNO_QUERY);
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 		// execute it
260cdf0e10cSrcweir 		if (xAdminDialog.is())
261cdf0e10cSrcweir 			xAdminDialog->execute();
262cdf0e10cSrcweir 	}
263cdf0e10cSrcweir 	catch( const Exception& )
264cdf0e10cSrcweir 	{
265cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
266cdf0e10cSrcweir 	}
267cdf0e10cSrcweir }
268cdf0e10cSrcweir // -----------------------------------------------------------------------------
openTableFilterDialog()269cdf0e10cSrcweir void OApplicationController::openTableFilterDialog()
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	openDialog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.TableFilterDialog" ) ) );
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir // -----------------------------------------------------------------------------
refreshTables()275cdf0e10cSrcweir void OApplicationController::refreshTables()
276cdf0e10cSrcweir {
277cdf0e10cSrcweir 	if ( getContainer() && getContainer()->getDetailView() )
278cdf0e10cSrcweir 	{
279cdf0e10cSrcweir 		WaitObject aWO(getView());
280cdf0e10cSrcweir 		OSL_ENSURE(getContainer()->getElementType() == E_TABLE,"Only allowed when the tables container is selected!");
281cdf0e10cSrcweir 		try
282cdf0e10cSrcweir 		{
283cdf0e10cSrcweir 			Reference<XRefreshable> xRefresh(getElements(E_TABLE),UNO_QUERY);
284cdf0e10cSrcweir 			if ( xRefresh.is() )
285cdf0e10cSrcweir 				xRefresh->refresh();
286cdf0e10cSrcweir 		}
287cdf0e10cSrcweir 		catch(const Exception&)
288cdf0e10cSrcweir 		{
289cdf0e10cSrcweir 			OSL_ENSURE(0,"Could not refresh tables!");
290cdf0e10cSrcweir 		}
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 		getContainer()->getDetailView()->clearPages(sal_False);
293cdf0e10cSrcweir 		getContainer()->getDetailView()->createTablesPage( ensureConnection() );
294cdf0e10cSrcweir 	}
295cdf0e10cSrcweir }
296cdf0e10cSrcweir // -----------------------------------------------------------------------------
openDirectSQLDialog()297cdf0e10cSrcweir void OApplicationController::openDirectSQLDialog()
298cdf0e10cSrcweir {
299cdf0e10cSrcweir 	openDialog( SERVICE_SDB_DIRECTSQLDIALOG );
300cdf0e10cSrcweir }
301cdf0e10cSrcweir // -----------------------------------------------------------------------------
propertyChange(const PropertyChangeEvent & evt)302cdf0e10cSrcweir void SAL_CALL OApplicationController::propertyChange( const PropertyChangeEvent& evt ) throw (RuntimeException)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
305cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
306cdf0e10cSrcweir 	if ( evt.PropertyName == PROPERTY_USER )
307cdf0e10cSrcweir     {
308cdf0e10cSrcweir         m_bNeedToReconnect = sal_True;
309cdf0e10cSrcweir 		InvalidateFeature(SID_DB_APP_STATUS_USERNAME);
310cdf0e10cSrcweir     }
311cdf0e10cSrcweir 	else if ( evt.PropertyName == PROPERTY_URL )
312cdf0e10cSrcweir 	{
313cdf0e10cSrcweir         m_bNeedToReconnect = sal_True;
314cdf0e10cSrcweir 		InvalidateFeature(SID_DB_APP_STATUS_DBNAME);
315cdf0e10cSrcweir 		InvalidateFeature(SID_DB_APP_STATUS_TYPE);
316cdf0e10cSrcweir 		InvalidateFeature(SID_DB_APP_STATUS_HOSTNAME);
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir     else if ( PROPERTY_NAME == evt.PropertyName )
319cdf0e10cSrcweir     {
320cdf0e10cSrcweir         const ElementType eType = getContainer()->getElementType();
321cdf0e10cSrcweir         if ( eType == E_FORM || eType == E_REPORT )
322cdf0e10cSrcweir 		{
323cdf0e10cSrcweir             ::rtl::OUString sOldName,sNewName;
324cdf0e10cSrcweir             evt.OldValue >>= sOldName;
325cdf0e10cSrcweir             evt.NewValue >>= sNewName;
326cdf0e10cSrcweir 
327cdf0e10cSrcweir             // if the old name is empty, then this is a newly inserted content. We're notified of it via the
328cdf0e10cSrcweir             // elementInserted method, so there's no need to handle it here.
329cdf0e10cSrcweir 
330cdf0e10cSrcweir             if ( sOldName.getLength() )
331cdf0e10cSrcweir             {
332cdf0e10cSrcweir                 Reference<XChild> xChild(evt.Source,UNO_QUERY);
333cdf0e10cSrcweir                 if ( xChild.is() )
334cdf0e10cSrcweir                 {
335cdf0e10cSrcweir                     Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
336cdf0e10cSrcweir 			        if ( xContent.is() )
337cdf0e10cSrcweir 				        sOldName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sOldName;
338cdf0e10cSrcweir                 }
339cdf0e10cSrcweir 
340cdf0e10cSrcweir                 getContainer()->elementReplaced( eType , sOldName, sNewName );
341cdf0e10cSrcweir             }
342cdf0e10cSrcweir         }
343cdf0e10cSrcweir     }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 	EventObject aEvt;
346cdf0e10cSrcweir 	aEvt.Source = m_xModel;
347cdf0e10cSrcweir 	modified(aEvt);
348cdf0e10cSrcweir }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir // -----------------------------------------------------------------------------
getDataSource()351cdf0e10cSrcweir Reference< XDataSource > SAL_CALL OApplicationController::getDataSource() throw (RuntimeException)
352cdf0e10cSrcweir {
353cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
354cdf0e10cSrcweir     Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
355cdf0e10cSrcweir     return xDataSource;
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir // -----------------------------------------------------------------------------
getApplicationMainWindow()359cdf0e10cSrcweir Reference< XWindow > SAL_CALL OApplicationController::getApplicationMainWindow() throw (RuntimeException)
360cdf0e10cSrcweir {
361cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
362cdf0e10cSrcweir     Reference< XFrame > xFrame( getFrame(), UNO_QUERY_THROW );
363cdf0e10cSrcweir     Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
364cdf0e10cSrcweir     return xWindow;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir // -----------------------------------------------------------------------------
getSubComponents()368cdf0e10cSrcweir Sequence< Reference< XComponent > > SAL_CALL OApplicationController::getSubComponents() throw (RuntimeException)
369cdf0e10cSrcweir {
370cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
371cdf0e10cSrcweir     return m_pSubComponentManager->getSubComponents();
372cdf0e10cSrcweir }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir // -----------------------------------------------------------------------------
getActiveConnection()375cdf0e10cSrcweir Reference< XConnection > SAL_CALL OApplicationController::getActiveConnection() throw (RuntimeException)
376cdf0e10cSrcweir {
377cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
378cdf0e10cSrcweir     return m_xDataSourceConnection.getTyped();
379cdf0e10cSrcweir }
380cdf0e10cSrcweir 
381cdf0e10cSrcweir // -----------------------------------------------------------------------------
isConnected()382cdf0e10cSrcweir ::sal_Bool SAL_CALL OApplicationController::isConnected(  ) throw (RuntimeException)
383cdf0e10cSrcweir {
384cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
385cdf0e10cSrcweir     return m_xDataSourceConnection.is();
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir // -----------------------------------------------------------------------------
connect()389cdf0e10cSrcweir void SAL_CALL OApplicationController::connect(  ) throw (SQLException, RuntimeException)
390cdf0e10cSrcweir {
391cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
392cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     SQLExceptionInfo aError;
395cdf0e10cSrcweir     SharedConnection xConnection = ensureConnection( &aError );
396cdf0e10cSrcweir     if ( !xConnection.is() )
397cdf0e10cSrcweir     {
398cdf0e10cSrcweir         if ( aError.isValid() )
399cdf0e10cSrcweir             aError.doThrow();
400cdf0e10cSrcweir 
401cdf0e10cSrcweir         // no particular error, but nonetheless could not connect -> throw a generic exception
402cdf0e10cSrcweir 		String sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
403cdf0e10cSrcweir 		sConnectingContext.SearchAndReplaceAscii( "$name$", getStrippedDatabaseName() );
404cdf0e10cSrcweir         ::dbtools::throwGenericSQLException( sConnectingContext, *this );
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir // -----------------------------------------------------------------------------
identifySubComponent(const Reference<XComponent> & i_rSubComponent)409cdf0e10cSrcweir beans::Pair< ::sal_Int32, ::rtl::OUString > SAL_CALL OApplicationController::identifySubComponent( const Reference< XComponent >& i_rSubComponent ) throw (IllegalArgumentException, RuntimeException)
410cdf0e10cSrcweir {
411cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
412cdf0e10cSrcweir 
413cdf0e10cSrcweir     sal_Int32 nType = -1;
414cdf0e10cSrcweir     ::rtl::OUString sName;
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     if ( !m_pSubComponentManager->lookupSubComponent( i_rSubComponent, sName, nType ) )
417cdf0e10cSrcweir         throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
418cdf0e10cSrcweir 
419cdf0e10cSrcweir     if ( nType == SID_DB_APP_DSRELDESIGN )
420cdf0e10cSrcweir         // this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such
421cdf0e10cSrcweir         // value for the relation design. /me thinks we should change the API definition here ...
422cdf0e10cSrcweir         nType = -1;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir     return beans::Pair< ::sal_Int32, ::rtl::OUString >( nType, sName );
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir // -----------------------------------------------------------------------------
closeSubComponents()428cdf0e10cSrcweir ::sal_Bool SAL_CALL OApplicationController::closeSubComponents(  ) throw (RuntimeException)
429cdf0e10cSrcweir {
430cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
431cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
432cdf0e10cSrcweir     return m_pSubComponentManager->closeSubComponents();
433cdf0e10cSrcweir }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 
436cdf0e10cSrcweir // -----------------------------------------------------------------------------
437cdf0e10cSrcweir namespace
438cdf0e10cSrcweir {
lcl_objectType2ElementType(const sal_Int32 _nObjectType)439cdf0e10cSrcweir     ElementType lcl_objectType2ElementType( const sal_Int32 _nObjectType )
440cdf0e10cSrcweir     {
441cdf0e10cSrcweir         ElementType eType( E_NONE );
442cdf0e10cSrcweir         switch ( _nObjectType )
443cdf0e10cSrcweir         {
444cdf0e10cSrcweir         case DatabaseObject::TABLE:  eType = E_TABLE;   break;
445cdf0e10cSrcweir         case DatabaseObject::QUERY:  eType = E_QUERY;   break;
446cdf0e10cSrcweir         case DatabaseObject::FORM:   eType = E_FORM;    break;
447cdf0e10cSrcweir         case DatabaseObject::REPORT: eType = E_REPORT;  break;
448cdf0e10cSrcweir         default:
449cdf0e10cSrcweir             OSL_ENSURE( false, "lcl_objectType2ElementType: unsupported object type!" );
450cdf0e10cSrcweir                 // this should have been caught earlier
451cdf0e10cSrcweir         }
452cdf0e10cSrcweir         return eType;
453cdf0e10cSrcweir     }
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir // -----------------------------------------------------------------------------
impl_validateObjectTypeAndName_throw(const sal_Int32 _nObjectType,const::boost::optional<::rtl::OUString> & i_rObjectName)457cdf0e10cSrcweir void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< ::rtl::OUString >& i_rObjectName )
458cdf0e10cSrcweir {
459cdf0e10cSrcweir     // ensure we're connected
460cdf0e10cSrcweir     if ( !isConnected() )
461cdf0e10cSrcweir     {
462cdf0e10cSrcweir         SQLError aError( getORB() );
463cdf0e10cSrcweir         aError.raiseException( ErrorCondition::DB_NOT_CONNECTED, *this );
464cdf0e10cSrcweir     }
465cdf0e10cSrcweir 
466cdf0e10cSrcweir     // ensure a proper object type
467cdf0e10cSrcweir     if  (   ( _nObjectType != DatabaseObject::TABLE )
468cdf0e10cSrcweir         &&  ( _nObjectType != DatabaseObject::QUERY )
469cdf0e10cSrcweir         &&  ( _nObjectType != DatabaseObject::FORM )
470cdf0e10cSrcweir         &&  ( _nObjectType != DatabaseObject::REPORT )
471cdf0e10cSrcweir         )
472cdf0e10cSrcweir         throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
473cdf0e10cSrcweir 
474cdf0e10cSrcweir     if ( !i_rObjectName )
475cdf0e10cSrcweir         return;
476cdf0e10cSrcweir 
477cdf0e10cSrcweir     // ensure an existing object
478cdf0e10cSrcweir     Reference< XNameAccess > xContainer( getElements( lcl_objectType2ElementType( _nObjectType ) ) );
479cdf0e10cSrcweir     if ( !xContainer.is() )
480cdf0e10cSrcweir         // all possible reasons for this (e.g. not being connected currently) should
481cdf0e10cSrcweir         // have been handled before
482cdf0e10cSrcweir         throw RuntimeException( ::rtl::OUString(), *this );
483cdf0e10cSrcweir 
484cdf0e10cSrcweir     bool bExistentObject = false;
485cdf0e10cSrcweir     switch ( _nObjectType )
486cdf0e10cSrcweir     {
487cdf0e10cSrcweir     case DatabaseObject::TABLE:
488cdf0e10cSrcweir     case DatabaseObject::QUERY:
489cdf0e10cSrcweir         bExistentObject = xContainer->hasByName( *i_rObjectName );
490cdf0e10cSrcweir         break;
491cdf0e10cSrcweir     case DatabaseObject::FORM:
492cdf0e10cSrcweir     case DatabaseObject::REPORT:
493cdf0e10cSrcweir     {
494cdf0e10cSrcweir         Reference< XHierarchicalNameAccess > xHierarchy( xContainer, UNO_QUERY_THROW );
495cdf0e10cSrcweir         bExistentObject = xHierarchy->hasByHierarchicalName( *i_rObjectName );
496cdf0e10cSrcweir     }
497cdf0e10cSrcweir     break;
498cdf0e10cSrcweir     }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir     if ( !bExistentObject )
501cdf0e10cSrcweir         throw NoSuchElementException( *i_rObjectName, *this );
502cdf0e10cSrcweir }
503cdf0e10cSrcweir 
504cdf0e10cSrcweir // -----------------------------------------------------------------------------
loadComponent(::sal_Int32 _ObjectType,const::rtl::OUString & _ObjectName,::sal_Bool _ForEditing)505cdf0e10cSrcweir Reference< XComponent > SAL_CALL OApplicationController::loadComponent( ::sal_Int32 _ObjectType,
506cdf0e10cSrcweir     const ::rtl::OUString& _ObjectName, ::sal_Bool _ForEditing ) throw (IllegalArgumentException, NoSuchElementException, SQLException, RuntimeException)
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     return loadComponentWithArguments( _ObjectType, _ObjectName, _ForEditing, Sequence< PropertyValue >() );
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir // -----------------------------------------------------------------------------
loadComponentWithArguments(::sal_Int32 _ObjectType,const::rtl::OUString & _ObjectName,::sal_Bool _ForEditing,const Sequence<PropertyValue> & _Arguments)512cdf0e10cSrcweir Reference< XComponent > SAL_CALL OApplicationController::loadComponentWithArguments( ::sal_Int32 _ObjectType,
513cdf0e10cSrcweir     const ::rtl::OUString& _ObjectName, ::sal_Bool _ForEditing, const Sequence< PropertyValue >& _Arguments ) throw (IllegalArgumentException, NoSuchElementException, SQLException, RuntimeException)
514cdf0e10cSrcweir {
515cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
516cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
517cdf0e10cSrcweir 
518cdf0e10cSrcweir     impl_validateObjectTypeAndName_throw( _ObjectType, _ObjectName );
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     Reference< XComponent > xComponent( openElementWithArguments(
521cdf0e10cSrcweir         _ObjectName,
522cdf0e10cSrcweir         lcl_objectType2ElementType( _ObjectType ),
523cdf0e10cSrcweir         _ForEditing ? E_OPEN_DESIGN : E_OPEN_NORMAL,
524cdf0e10cSrcweir         _ForEditing ? SID_DB_APP_EDIT : SID_DB_APP_OPEN,
525cdf0e10cSrcweir         ::comphelper::NamedValueCollection( _Arguments )
526cdf0e10cSrcweir     ) );
527cdf0e10cSrcweir 
528cdf0e10cSrcweir     return xComponent;
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir // -----------------------------------------------------------------------------
createComponent(::sal_Int32 i_nObjectType,Reference<XComponent> & o_DocumentDefinition)532cdf0e10cSrcweir Reference< XComponent > SAL_CALL OApplicationController::createComponent( ::sal_Int32 i_nObjectType, Reference< XComponent >& o_DocumentDefinition  ) throw (IllegalArgumentException, SQLException, RuntimeException)
533cdf0e10cSrcweir {
534cdf0e10cSrcweir     return createComponentWithArguments( i_nObjectType, Sequence< PropertyValue >(), o_DocumentDefinition );
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir // -----------------------------------------------------------------------------
createComponentWithArguments(::sal_Int32 i_nObjectType,const Sequence<PropertyValue> & i_rArguments,Reference<XComponent> & o_DocumentDefinition)538cdf0e10cSrcweir Reference< XComponent > SAL_CALL OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType, const Sequence< PropertyValue >& i_rArguments, Reference< XComponent >& o_DocumentDefinition ) throw (IllegalArgumentException, SQLException, RuntimeException)
539cdf0e10cSrcweir {
540cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
541cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
542cdf0e10cSrcweir 
543cdf0e10cSrcweir     impl_validateObjectTypeAndName_throw( i_nObjectType, ::boost::optional< ::rtl::OUString >() );
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     Reference< XComponent > xComponent( newElement(
546cdf0e10cSrcweir         lcl_objectType2ElementType( i_nObjectType ),
547cdf0e10cSrcweir         ::comphelper::NamedValueCollection( i_rArguments ),
548cdf0e10cSrcweir         o_DocumentDefinition
549cdf0e10cSrcweir     ) );
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     return xComponent;
552cdf0e10cSrcweir }
553cdf0e10cSrcweir 
554cdf0e10cSrcweir // -----------------------------------------------------------------------------
registerContextMenuInterceptor(const Reference<XContextMenuInterceptor> & _Interceptor)555cdf0e10cSrcweir void SAL_CALL OApplicationController::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
556cdf0e10cSrcweir {
557cdf0e10cSrcweir     if ( _Interceptor.is() )
558cdf0e10cSrcweir         m_aContextMenuInterceptors.addInterface( _Interceptor );
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir // -----------------------------------------------------------------------------
releaseContextMenuInterceptor(const Reference<XContextMenuInterceptor> & _Interceptor)562cdf0e10cSrcweir void SAL_CALL OApplicationController::releaseContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
563cdf0e10cSrcweir {
564cdf0e10cSrcweir     m_aContextMenuInterceptors.removeInterface( _Interceptor );
565cdf0e10cSrcweir }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir // -----------------------------------------------------------------------------
previewChanged(sal_Int32 _nMode)568cdf0e10cSrcweir void OApplicationController::previewChanged( sal_Int32 _nMode )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
571cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 	if ( m_xDataSource.is() && !isDataSourceReadOnly() )
574cdf0e10cSrcweir 	{
575cdf0e10cSrcweir 		try
576cdf0e10cSrcweir 		{
577cdf0e10cSrcweir             ::comphelper::NamedValueCollection aLayoutInfo( m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) );
578cdf0e10cSrcweir             sal_Int32 nOldMode = aLayoutInfo.getOrDefault( "Preview", _nMode );
579cdf0e10cSrcweir             if ( nOldMode != _nMode )
580cdf0e10cSrcweir             {
581cdf0e10cSrcweir                 aLayoutInfo.put( "Preview", _nMode );
582cdf0e10cSrcweir 				m_xDataSource->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aLayoutInfo.getPropertyValues() ) );
583cdf0e10cSrcweir             }
584cdf0e10cSrcweir 		}
585cdf0e10cSrcweir 		catch ( const Exception& )
586cdf0e10cSrcweir 		{
587cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
588cdf0e10cSrcweir 		}
589cdf0e10cSrcweir 	}
590cdf0e10cSrcweir 	InvalidateFeature(SID_DB_APP_DISABLE_PREVIEW);
591cdf0e10cSrcweir 	InvalidateFeature(SID_DB_APP_VIEW_DOCINFO_PREVIEW);
592cdf0e10cSrcweir 	InvalidateFeature(SID_DB_APP_VIEW_DOC_PREVIEW);
593cdf0e10cSrcweir }
594cdf0e10cSrcweir // -----------------------------------------------------------------------------
595cdf0e10cSrcweir //void OApplicationController::updateTitle()
596cdf0e10cSrcweir //{
597cdf0e10cSrcweir //	::rtl::OUString sName = getStrippedDatabaseName();
598cdf0e10cSrcweir //
599cdf0e10cSrcweir //	String sTitle = String(ModuleRes(STR_APP_TITLE));
600cdf0e10cSrcweir //	sName = sName + sTitle;
601cdf0e10cSrcweir //#ifdef DBG_UTIL
602cdf0e10cSrcweir //    ::rtl::OUString aDefault;
603cdf0e10cSrcweir //	sName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ["));
604cdf0e10cSrcweir //    sName += utl::Bootstrap::getBuildIdData( aDefault );
605cdf0e10cSrcweir //	sName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
606cdf0e10cSrcweir //#endif
607cdf0e10cSrcweir //}
608cdf0e10cSrcweir // -----------------------------------------------------------------------------
askToReconnect()609cdf0e10cSrcweir void OApplicationController::askToReconnect()
610cdf0e10cSrcweir {
611cdf0e10cSrcweir 	if ( m_bNeedToReconnect )
612cdf0e10cSrcweir 	{
613cdf0e10cSrcweir 		m_bNeedToReconnect = sal_False;
614cdf0e10cSrcweir 		sal_Bool bClear = sal_True;
615cdf0e10cSrcweir 		if ( !m_pSubComponentManager->empty() )
616cdf0e10cSrcweir 		{
617cdf0e10cSrcweir 			QueryBox aQry(getView(), ModuleRes(APP_CLOSEDOCUMENTS));
618cdf0e10cSrcweir 			switch (aQry.Execute())
619cdf0e10cSrcweir 			{
620cdf0e10cSrcweir 				case RET_YES:
621cdf0e10cSrcweir 					closeSubComponents();
622cdf0e10cSrcweir 					break;
623cdf0e10cSrcweir 				default:
624cdf0e10cSrcweir 					bClear = sal_False;
625cdf0e10cSrcweir 					break;
626cdf0e10cSrcweir 			}
627cdf0e10cSrcweir 		}
628cdf0e10cSrcweir 		if ( bClear )
629cdf0e10cSrcweir 		{
630cdf0e10cSrcweir 			ElementType eType = getContainer()->getElementType();
631cdf0e10cSrcweir 			disconnect();
632cdf0e10cSrcweir 			getContainer()->getDetailView()->clearPages(sal_False);
633cdf0e10cSrcweir 			getContainer()->selectContainer(E_NONE); // invalidate the old selection
634cdf0e10cSrcweir             m_eCurrentType = E_NONE;
635cdf0e10cSrcweir 			getContainer()->selectContainer(eType); // reselect the current one again
636cdf0e10cSrcweir 		}
637cdf0e10cSrcweir 	}
638cdf0e10cSrcweir }
639cdf0e10cSrcweir 
640cdf0e10cSrcweir // -----------------------------------------------------------------------------
getDatabaseName() const641cdf0e10cSrcweir ::rtl::OUString OApplicationController::getDatabaseName() const
642cdf0e10cSrcweir {
643cdf0e10cSrcweir     ::rtl::OUString sDatabaseName;
644cdf0e10cSrcweir     try
645cdf0e10cSrcweir     {
646cdf0e10cSrcweir         if ( m_xDataSource.is() )
647cdf0e10cSrcweir         {
648cdf0e10cSrcweir             OSL_VERIFY( m_xDataSource->getPropertyValue( PROPERTY_NAME ) >>= sDatabaseName );
649cdf0e10cSrcweir         }
650cdf0e10cSrcweir     }
651cdf0e10cSrcweir     catch ( const Exception& )
652cdf0e10cSrcweir     {
653cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
654cdf0e10cSrcweir     }
655cdf0e10cSrcweir     return sDatabaseName;
656cdf0e10cSrcweir }
657cdf0e10cSrcweir 
658cdf0e10cSrcweir // -----------------------------------------------------------------------------
getStrippedDatabaseName() const659cdf0e10cSrcweir ::rtl::OUString OApplicationController::getStrippedDatabaseName() const
660cdf0e10cSrcweir {
661cdf0e10cSrcweir     ::rtl::OUString sDatabaseName;
662cdf0e10cSrcweir 	return ::dbaui::getStrippedDatabaseName( m_xDataSource, sDatabaseName );
663cdf0e10cSrcweir }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir // -----------------------------------------------------------------------------
onDocumentOpened(const::rtl::OUString & _rName,const sal_Int32 _nType,const ElementOpenMode _eMode,const Reference<XComponent> & _xDocument,const Reference<XComponent> & _rxDefinition)666cdf0e10cSrcweir void OApplicationController::onDocumentOpened( const ::rtl::OUString& _rName, const sal_Int32 _nType,
667cdf0e10cSrcweir         const ElementOpenMode _eMode, const Reference< XComponent >& _xDocument, const Reference< XComponent >& _rxDefinition )
668cdf0e10cSrcweir {
669cdf0e10cSrcweir 	if ( !_xDocument.is() )
670cdf0e10cSrcweir         return;
671cdf0e10cSrcweir 
672cdf0e10cSrcweir     try
673cdf0e10cSrcweir     {
674cdf0e10cSrcweir         OSL_ENSURE( _xDocument.is(), "OApplicationController::onDocumentOpened: is there any *valid* scenario where this fails?" );
675cdf0e10cSrcweir         m_pSubComponentManager->onSubComponentOpened( _rName, _nType, _eMode, _xDocument.is() ? _xDocument : _rxDefinition );
676cdf0e10cSrcweir 
677cdf0e10cSrcweir         if ( _rxDefinition.is() )
678cdf0e10cSrcweir         {
679cdf0e10cSrcweir             Reference< XPropertySet > xProp( _rxDefinition, UNO_QUERY_THROW );
680cdf0e10cSrcweir             Reference< XPropertySetInfo > xPSI( xProp->getPropertySetInfo(), UNO_SET_THROW );
681cdf0e10cSrcweir             xProp->addPropertyChangeListener( PROPERTY_NAME, static_cast< XPropertyChangeListener* >( this ) );
682cdf0e10cSrcweir         }
683cdf0e10cSrcweir     }
684cdf0e10cSrcweir 	catch( const Exception& )
685cdf0e10cSrcweir 	{
686cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
687cdf0e10cSrcweir 	}
688cdf0e10cSrcweir }
689cdf0e10cSrcweir // -----------------------------------------------------------------------------
insertHierachyElement(ElementType _eType,const String & _sParentFolder,sal_Bool _bCollection,const Reference<XContent> & _xContent,sal_Bool _bMove)690cdf0e10cSrcweir sal_Bool OApplicationController::insertHierachyElement(ElementType _eType,const String& _sParentFolder,sal_Bool _bCollection,const Reference<XContent>& _xContent,sal_Bool _bMove)
691cdf0e10cSrcweir {
692cdf0e10cSrcweir 	Reference<XHierarchicalNameContainer> xNames(getElements(_eType), UNO_QUERY);
693cdf0e10cSrcweir 	return dbaui::insertHierachyElement(getView()
694cdf0e10cSrcweir                            ,getORB()
695cdf0e10cSrcweir 						   ,xNames
696cdf0e10cSrcweir 						   ,_sParentFolder
697cdf0e10cSrcweir 						   ,_eType == E_FORM
698cdf0e10cSrcweir 						   ,_bCollection
699cdf0e10cSrcweir 						   ,_xContent
700cdf0e10cSrcweir 						   ,_bMove);
701cdf0e10cSrcweir }
702cdf0e10cSrcweir // -----------------------------------------------------------------------------
isRenameDeleteAllowed(ElementType _eType,sal_Bool _bDelete) const703cdf0e10cSrcweir sal_Bool OApplicationController::isRenameDeleteAllowed(ElementType _eType,sal_Bool _bDelete) const
704cdf0e10cSrcweir {
705cdf0e10cSrcweir 	ElementType eType = getContainer()->getElementType();
706cdf0e10cSrcweir 	sal_Bool bEnabled = !isDataSourceReadOnly() && eType == _eType;
707cdf0e10cSrcweir 	if ( bEnabled )
708cdf0e10cSrcweir 	{
709cdf0e10cSrcweir 
710cdf0e10cSrcweir 		if ( E_TABLE == eType )
711cdf0e10cSrcweir 			bEnabled = !isConnectionReadOnly() && getContainer()->isALeafSelected();
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 		sal_Bool bCompareRes = sal_False;
714cdf0e10cSrcweir 		if ( _bDelete )
715cdf0e10cSrcweir 			bCompareRes = getContainer()->getSelectionCount() > 0;
716cdf0e10cSrcweir 		else
717cdf0e10cSrcweir 		{
718cdf0e10cSrcweir 			bCompareRes = getContainer()->getSelectionCount() == 1;
719cdf0e10cSrcweir 			if ( bEnabled && bCompareRes && E_TABLE == eType )
720cdf0e10cSrcweir 			{
721cdf0e10cSrcweir 				::std::vector< ::rtl::OUString> aList;
722cdf0e10cSrcweir 				getSelectionElementNames(aList);
723cdf0e10cSrcweir 
724cdf0e10cSrcweir 				try
725cdf0e10cSrcweir 				{
726cdf0e10cSrcweir 					Reference< XNameAccess > xContainer = const_cast<OApplicationController*>(this)->getElements(eType);
727cdf0e10cSrcweir                     bEnabled = (xContainer.is() && xContainer->hasByName(*aList.begin()));
728cdf0e10cSrcweir 					if ( bEnabled )
729cdf0e10cSrcweir 						bEnabled = Reference<XRename>(xContainer->getByName(*aList.begin()),UNO_QUERY).is();
730cdf0e10cSrcweir 				}
731cdf0e10cSrcweir 				catch(Exception&)
732cdf0e10cSrcweir 				{
733cdf0e10cSrcweir 					bEnabled = sal_False;
734cdf0e10cSrcweir 				}
735cdf0e10cSrcweir 			}
736cdf0e10cSrcweir 		}
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 		bEnabled = bEnabled && bCompareRes;
739cdf0e10cSrcweir 	}
740cdf0e10cSrcweir 	return bEnabled;
741cdf0e10cSrcweir }
742cdf0e10cSrcweir // -----------------------------------------------------------------------------
onLoadedMenu(const Reference<::com::sun::star::frame::XLayoutManager> & _xLayoutManager)743cdf0e10cSrcweir void OApplicationController::onLoadedMenu(const Reference< ::com::sun::star::frame::XLayoutManager >& _xLayoutManager)
744cdf0e10cSrcweir {
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 	if ( _xLayoutManager.is() )
747cdf0e10cSrcweir 	{
748cdf0e10cSrcweir 		static ::rtl::OUString s_sStatusbar(RTL_CONSTASCII_USTRINGPARAM("private:resource/statusbar/statusbar"));
749cdf0e10cSrcweir 		_xLayoutManager->createElement( s_sStatusbar );
750cdf0e10cSrcweir 		_xLayoutManager->requestElement( s_sStatusbar );
751cdf0e10cSrcweir 
752cdf0e10cSrcweir 	    if ( getContainer() )
753cdf0e10cSrcweir         {
754cdf0e10cSrcweir             // we need to share the "mnemonic space":
755cdf0e10cSrcweir             MnemonicGenerator aMnemonicGenerator;
756cdf0e10cSrcweir             // - the menu already has mnemonics
757cdf0e10cSrcweir             SystemWindow* pSystemWindow = getContainer()->GetSystemWindow();
758cdf0e10cSrcweir             MenuBar* pMenu = pSystemWindow ? pSystemWindow->GetMenuBar() : NULL;
759cdf0e10cSrcweir             if ( pMenu )
760cdf0e10cSrcweir             {
761cdf0e10cSrcweir                 sal_uInt16 nMenuItems = pMenu->GetItemCount();
762cdf0e10cSrcweir                 for ( sal_uInt16 i = 0; i < nMenuItems; ++i )
763cdf0e10cSrcweir                     aMnemonicGenerator.RegisterMnemonic( pMenu->GetItemText( pMenu->GetItemId( i ) ) );
764cdf0e10cSrcweir             }
765cdf0e10cSrcweir             // - the icons should use automatic ones
766cdf0e10cSrcweir     	    getContainer()->createIconAutoMnemonics( aMnemonicGenerator );
767cdf0e10cSrcweir             // - as well as the entries in the task pane
768cdf0e10cSrcweir             getContainer()->setTaskExternalMnemonics( aMnemonicGenerator );
769cdf0e10cSrcweir         }
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 	    Execute( SID_DB_APP_VIEW_FORMS, Sequence< PropertyValue >() );
772cdf0e10cSrcweir 		InvalidateAll();
773cdf0e10cSrcweir 	}
774cdf0e10cSrcweir }
775cdf0e10cSrcweir // -----------------------------------------------------------------------------
doAction(sal_uInt16 _nId,ElementOpenMode _eOpenMode)776cdf0e10cSrcweir void OApplicationController::doAction(sal_uInt16 _nId ,ElementOpenMode _eOpenMode)
777cdf0e10cSrcweir {
778cdf0e10cSrcweir 	::std::vector< ::rtl::OUString> aList;
779cdf0e10cSrcweir 	getSelectionElementNames(aList);
780cdf0e10cSrcweir 	ElementType eType = getContainer()->getElementType();
781cdf0e10cSrcweir     ::comphelper::NamedValueCollection aArguments;
782cdf0e10cSrcweir     ElementOpenMode eOpenMode = _eOpenMode;
783cdf0e10cSrcweir     if ( eType == E_REPORT && E_OPEN_FOR_MAIL == _eOpenMode )
784cdf0e10cSrcweir     {
785cdf0e10cSrcweir         aArguments.put("Hidden",true);
786cdf0e10cSrcweir         eOpenMode = E_OPEN_NORMAL;
787cdf0e10cSrcweir     }
788cdf0e10cSrcweir 
789cdf0e10cSrcweir 	::std::vector< ::std::pair< ::rtl::OUString ,Reference< XModel > > > aCompoments;
790cdf0e10cSrcweir 	::std::vector< ::rtl::OUString>::iterator aEnd = aList.end();
791cdf0e10cSrcweir 	for (::std::vector< ::rtl::OUString>::iterator aIter = aList.begin(); aIter != aEnd; ++aIter)
792cdf0e10cSrcweir 	{
793cdf0e10cSrcweir 		if ( SID_DB_APP_CONVERTTOVIEW == _nId )
794cdf0e10cSrcweir 			convertToView(*aIter);
795cdf0e10cSrcweir 		else
796cdf0e10cSrcweir         {
797cdf0e10cSrcweir             Reference< XModel > xModel( openElementWithArguments( *aIter, eType, eOpenMode, _nId,aArguments ), UNO_QUERY );
798cdf0e10cSrcweir 			aCompoments.push_back( ::std::pair< ::rtl::OUString, Reference< XModel > >( *aIter, xModel ) );
799cdf0e10cSrcweir         }
800cdf0e10cSrcweir 	}
801cdf0e10cSrcweir 
802cdf0e10cSrcweir 	// special handling for mail, if more than one document is selected attach them all
803cdf0e10cSrcweir 	if ( _eOpenMode == E_OPEN_FOR_MAIL )
804cdf0e10cSrcweir 	{
805cdf0e10cSrcweir 
806cdf0e10cSrcweir 		::std::vector< ::std::pair< ::rtl::OUString ,Reference< XModel > > >::iterator componentIter = aCompoments.begin();
807cdf0e10cSrcweir 		::std::vector< ::std::pair< ::rtl::OUString ,Reference< XModel > > >::iterator componentEnd = aCompoments.end();
808cdf0e10cSrcweir         ::rtl::OUString aDocTypeString;
809cdf0e10cSrcweir         SfxMailModel aSendMail;
810cdf0e10cSrcweir 		SfxMailModel::SendMailResult eResult = SfxMailModel::SEND_MAIL_OK;
811cdf0e10cSrcweir 		for (; componentIter != componentEnd && SfxMailModel::SEND_MAIL_OK == eResult; ++componentIter)
812cdf0e10cSrcweir         {
813cdf0e10cSrcweir             try
814cdf0e10cSrcweir             {
815cdf0e10cSrcweir 			    Reference< XModel > xModel(componentIter->second,UNO_QUERY);
816cdf0e10cSrcweir 
817cdf0e10cSrcweir                 // Send document as e-Mail using stored/default type
818cdf0e10cSrcweir                 eResult = aSendMail.AttachDocument(aDocTypeString,xModel,componentIter->first);
819cdf0e10cSrcweir                 ::comphelper::disposeComponent(xModel);
820cdf0e10cSrcweir             }
821cdf0e10cSrcweir             catch(const Exception&)
822cdf0e10cSrcweir             {
823cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
824cdf0e10cSrcweir             }
825cdf0e10cSrcweir 		}
826cdf0e10cSrcweir 		if ( !aSendMail.IsEmpty() )
827cdf0e10cSrcweir 			aSendMail.Send( getFrame() );
828cdf0e10cSrcweir 	}
829cdf0e10cSrcweir }
830cdf0e10cSrcweir // -----------------------------------------------------------------------------
getElementType(const Reference<XContainer> & _xContainer) const831cdf0e10cSrcweir ElementType OApplicationController::getElementType(const Reference< XContainer >& _xContainer) const
832cdf0e10cSrcweir {
833cdf0e10cSrcweir 	ElementType eRet = E_NONE;
834cdf0e10cSrcweir 	Reference<XServiceInfo> xServiceInfo(_xContainer,UNO_QUERY);
835cdf0e10cSrcweir 	if ( xServiceInfo.is() )
836cdf0e10cSrcweir 	{
837cdf0e10cSrcweir 		if ( xServiceInfo->supportsService(SERVICE_SDBCX_TABLES) )
838cdf0e10cSrcweir 			eRet = E_TABLE;
839cdf0e10cSrcweir 		else if ( xServiceInfo->supportsService(SERVICE_NAME_FORM_COLLECTION) )
840cdf0e10cSrcweir 			eRet = E_FORM;
841cdf0e10cSrcweir 		else if ( xServiceInfo->supportsService(SERVICE_NAME_REPORT_COLLECTION) )
842cdf0e10cSrcweir 			eRet = E_REPORT;
843cdf0e10cSrcweir 		else
844cdf0e10cSrcweir 			eRet = E_QUERY;
845cdf0e10cSrcweir 	}
846cdf0e10cSrcweir 	return eRet;
847cdf0e10cSrcweir }
848cdf0e10cSrcweir 
849cdf0e10cSrcweir //........................................................................
850cdf0e10cSrcweir }	// namespace dbaui
851cdf0e10cSrcweir //........................................................................
852