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_extensions.hxx" 30*cdf0e10cSrcweir #include "admininvokationimpl.hxx" 31*cdf0e10cSrcweir #include <tools/debug.hxx> 32*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 35*cdf0e10cSrcweir #include <vcl/stdtext.hxx> 36*cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 37*cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 38*cdf0e10cSrcweir #endif 39*cdf0e10cSrcweir #ifndef EXTENSIONS_ABPRESID_HRC 40*cdf0e10cSrcweir #include "abpresid.hrc" 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir #include "componentmodule.hxx" 43*cdf0e10cSrcweir #include <vcl/waitobj.hxx> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //......................................................................... 47*cdf0e10cSrcweir namespace abp 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir //......................................................................... 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 52*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 53*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 54*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 55*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir //===================================================================== 58*cdf0e10cSrcweir //= OAdminDialogInvokation 59*cdf0e10cSrcweir //===================================================================== 60*cdf0e10cSrcweir //--------------------------------------------------------------------- 61*cdf0e10cSrcweir OAdminDialogInvokation::OAdminDialogInvokation(const Reference< XMultiServiceFactory >& _rxORB 62*cdf0e10cSrcweir , const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > _xDataSource 63*cdf0e10cSrcweir , Window* _pMessageParent) 64*cdf0e10cSrcweir :m_xORB(_rxORB) 65*cdf0e10cSrcweir ,m_xDataSource(_xDataSource) 66*cdf0e10cSrcweir ,m_pMessageParent(_pMessageParent) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir DBG_ASSERT(m_xORB.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid service factory!"); 69*cdf0e10cSrcweir DBG_ASSERT(m_xDataSource.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid preferred name!"); 70*cdf0e10cSrcweir DBG_ASSERT(m_pMessageParent, "OAdminDialogInvokation::OAdminDialogInvokation: invalid message parent!"); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //--------------------------------------------------------------------- 74*cdf0e10cSrcweir sal_Bool OAdminDialogInvokation::invokeAdministration( sal_Bool _bFixedType ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir if (!m_xORB.is()) 77*cdf0e10cSrcweir return sal_False; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir try 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir // the service name of the administration dialog 82*cdf0e10cSrcweir const static ::rtl::OUString s_sAdministrationServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DatasourceAdministrationDialog")); 83*cdf0e10cSrcweir const static ::rtl::OUString s_sDataSourceTypeChangeDialog = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DataSourceTypeChangeDialog")); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir // the parameters for the call 86*cdf0e10cSrcweir Sequence< Any > aArguments(3); 87*cdf0e10cSrcweir Any* pArguments = aArguments.getArray(); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // the parent window 90*cdf0e10cSrcweir Reference< XWindow > xDialogParent = VCLUnoHelper::GetInterface(m_pMessageParent); 91*cdf0e10cSrcweir *pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("ParentWindow"), -1, makeAny(xDialogParent), PropertyState_DIRECT_VALUE); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir // the title of the dialog 94*cdf0e10cSrcweir String sAdminDialogTitle(ModuleRes(RID_STR_ADMINDIALOGTITLE)); 95*cdf0e10cSrcweir *pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("Title"), -1, makeAny(::rtl::OUString(sAdminDialogTitle)), PropertyState_DIRECT_VALUE); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // the name of the new data source 98*cdf0e10cSrcweir *pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("InitialSelection"), -1, makeAny(m_xDataSource), PropertyState_DIRECT_VALUE); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // create the dialog 101*cdf0e10cSrcweir Reference< XExecutableDialog > xDialog; 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir // creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded) 104*cdf0e10cSrcweir // so we display a wait cursor 105*cdf0e10cSrcweir WaitObject aWaitCursor(m_pMessageParent); 106*cdf0e10cSrcweir xDialog = Reference< XExecutableDialog >( m_xORB->createInstanceWithArguments( _bFixedType ? s_sAdministrationServiceName : s_sDataSourceTypeChangeDialog, aArguments ), UNO_QUERY ); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir // just for a smoother UI: What the dialog does upon execution, is (amongst other things) creating 109*cdf0e10cSrcweir // the DriverManager service 110*cdf0e10cSrcweir // If this context has never been accessed before, this may be expensive (it includes loading of 111*cdf0e10cSrcweir // at least one library). 112*cdf0e10cSrcweir // As this wizard is intended to run on the first office start, it is very likely that the 113*cdf0e10cSrcweir // context needs to be freshly created 114*cdf0e10cSrcweir // Thus, we access the context here (within the WaitCursor), which means the user sees a waitcursor 115*cdf0e10cSrcweir // while his/her office blocks a few seconds .... 116*cdf0e10cSrcweir m_xORB->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.sdbc.DriverManager" ) ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if (xDialog.is()) 120*cdf0e10cSrcweir { // execute it 121*cdf0e10cSrcweir if (xDialog->execute()) 122*cdf0e10cSrcweir return sal_True; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir else 125*cdf0e10cSrcweir ShowServiceNotAvailableError(m_pMessageParent, s_sAdministrationServiceName, sal_True); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir catch(const Exception&) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir DBG_ERROR("OAdminDialogInvokation::invokeAdministration: caught an exception while executing the dialog!"); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir return sal_False; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir //......................................................................... 135*cdf0e10cSrcweir } // namespace abp 136*cdf0e10cSrcweir //......................................................................... 137*cdf0e10cSrcweir 138