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