update dev300-m58
[ooovba.git] / extensions / source / abpilot / admininvokationimpl.cxx
blob5b5bcd9a9f253480fe6d5cd8a676f032853fd638
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: admininvokationimpl.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "admininvokationimpl.hxx"
34 #include <tools/debug.hxx>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
37 #include <com/sun/star/awt/XWindow.hpp>
38 #include <vcl/stdtext.hxx>
39 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
40 #include <toolkit/unohlp.hxx>
41 #endif
42 #ifndef EXTENSIONS_ABPRESID_HRC
43 #include "abpresid.hrc"
44 #endif
45 #include "componentmodule.hxx"
46 #include <vcl/waitobj.hxx>
49 //.........................................................................
50 namespace abp
52 //.........................................................................
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::lang;
56 using namespace ::com::sun::star::beans;
57 using namespace ::com::sun::star::awt;
58 using namespace ::com::sun::star::ui::dialogs;
60 //=====================================================================
61 //= OAdminDialogInvokation
62 //=====================================================================
63 //---------------------------------------------------------------------
64 OAdminDialogInvokation::OAdminDialogInvokation(const Reference< XMultiServiceFactory >& _rxORB
65 , const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > _xDataSource
66 , Window* _pMessageParent)
67 :m_xORB(_rxORB)
68 ,m_xDataSource(_xDataSource)
69 ,m_pMessageParent(_pMessageParent)
71 DBG_ASSERT(m_xORB.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid service factory!");
72 DBG_ASSERT(m_xDataSource.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid preferred name!");
73 DBG_ASSERT(m_pMessageParent, "OAdminDialogInvokation::OAdminDialogInvokation: invalid message parent!");
76 //---------------------------------------------------------------------
77 sal_Bool OAdminDialogInvokation::invokeAdministration( sal_Bool _bFixedType )
79 if (!m_xORB.is())
80 return sal_False;
82 try
84 // the service name of the administration dialog
85 const static ::rtl::OUString s_sAdministrationServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DatasourceAdministrationDialog"));
86 const static ::rtl::OUString s_sDataSourceTypeChangeDialog = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DataSourceTypeChangeDialog"));
88 // the parameters for the call
89 Sequence< Any > aArguments(3);
90 Any* pArguments = aArguments.getArray();
92 // the parent window
93 Reference< XWindow > xDialogParent = VCLUnoHelper::GetInterface(m_pMessageParent);
94 *pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("ParentWindow"), -1, makeAny(xDialogParent), PropertyState_DIRECT_VALUE);
96 // the title of the dialog
97 String sAdminDialogTitle(ModuleRes(RID_STR_ADMINDIALOGTITLE));
98 *pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("Title"), -1, makeAny(::rtl::OUString(sAdminDialogTitle)), PropertyState_DIRECT_VALUE);
100 // the name of the new data source
101 *pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("InitialSelection"), -1, makeAny(m_xDataSource), PropertyState_DIRECT_VALUE);
103 // create the dialog
104 Reference< XExecutableDialog > xDialog;
106 // creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded)
107 // so we display a wait cursor
108 WaitObject aWaitCursor(m_pMessageParent);
109 xDialog = Reference< XExecutableDialog >( m_xORB->createInstanceWithArguments( _bFixedType ? s_sAdministrationServiceName : s_sDataSourceTypeChangeDialog, aArguments ), UNO_QUERY );
111 // just for a smoother UI: What the dialog does upon execution, is (amongst other things) creating
112 // the DriverManager service
113 // If this context has never been accessed before, this may be expensive (it includes loading of
114 // at least one library).
115 // As this wizard is intended to run on the first office start, it is very likely that the
116 // context needs to be freshly created
117 // Thus, we access the context here (within the WaitCursor), which means the user sees a waitcursor
118 // while his/her office blocks a few seconds ....
119 m_xORB->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.sdbc.DriverManager" ) );
122 if (xDialog.is())
123 { // execute it
124 if (xDialog->execute())
125 return sal_True;
127 else
128 ShowServiceNotAvailableError(m_pMessageParent, s_sAdministrationServiceName, sal_True);
130 catch(const Exception&)
132 DBG_ERROR("OAdminDialogInvokation::invokeAdministration: caught an exception while executing the dialog!");
134 return sal_False;
137 //.........................................................................
138 } // namespace abp
139 //.........................................................................