1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "admininvokationimpl.hxx"
31 #include <tools/debug.hxx>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
34 #include <com/sun/star/awt/XWindow.hpp>
35 #include <vcl/stdtext.hxx>
36 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
37 #include <toolkit/unohlp.hxx>
39 #ifndef EXTENSIONS_ABPRESID_HRC
40 #include "abpresid.hrc"
42 #include "componentmodule.hxx"
43 #include <vcl/waitobj.hxx>
46 //.........................................................................
49 //.........................................................................
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::lang
;
53 using namespace ::com::sun::star::beans
;
54 using namespace ::com::sun::star::awt
;
55 using namespace ::com::sun::star::ui::dialogs
;
57 //=====================================================================
58 //= OAdminDialogInvokation
59 //=====================================================================
60 //---------------------------------------------------------------------
61 OAdminDialogInvokation::OAdminDialogInvokation(const Reference
< XMultiServiceFactory
>& _rxORB
62 , const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> _xDataSource
63 , Window
* _pMessageParent
)
65 ,m_xDataSource(_xDataSource
)
66 ,m_pMessageParent(_pMessageParent
)
68 DBG_ASSERT(m_xORB
.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid service factory!");
69 DBG_ASSERT(m_xDataSource
.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid preferred name!");
70 DBG_ASSERT(m_pMessageParent
, "OAdminDialogInvokation::OAdminDialogInvokation: invalid message parent!");
73 //---------------------------------------------------------------------
74 sal_Bool
OAdminDialogInvokation::invokeAdministration( sal_Bool _bFixedType
)
81 // the service name of the administration dialog
82 const static ::rtl::OUString s_sAdministrationServiceName
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DatasourceAdministrationDialog"));
83 const static ::rtl::OUString s_sDataSourceTypeChangeDialog
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DataSourceTypeChangeDialog"));
85 // the parameters for the call
86 Sequence
< Any
> aArguments(3);
87 Any
* pArguments
= aArguments
.getArray();
90 Reference
< XWindow
> xDialogParent
= VCLUnoHelper::GetInterface(m_pMessageParent
);
91 *pArguments
++ <<= PropertyValue(::rtl::OUString::createFromAscii("ParentWindow"), -1, makeAny(xDialogParent
), PropertyState_DIRECT_VALUE
);
93 // the title of the dialog
94 String
sAdminDialogTitle(ModuleRes(RID_STR_ADMINDIALOGTITLE
));
95 *pArguments
++ <<= PropertyValue(::rtl::OUString::createFromAscii("Title"), -1, makeAny(::rtl::OUString(sAdminDialogTitle
)), PropertyState_DIRECT_VALUE
);
97 // the name of the new data source
98 *pArguments
++ <<= PropertyValue(::rtl::OUString::createFromAscii("InitialSelection"), -1, makeAny(m_xDataSource
), PropertyState_DIRECT_VALUE
);
101 Reference
< XExecutableDialog
> xDialog
;
103 // creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded)
104 // so we display a wait cursor
105 WaitObject
aWaitCursor(m_pMessageParent
);
106 xDialog
= Reference
< XExecutableDialog
>( m_xORB
->createInstanceWithArguments( _bFixedType
? s_sAdministrationServiceName
: s_sDataSourceTypeChangeDialog
, aArguments
), UNO_QUERY
);
108 // just for a smoother UI: What the dialog does upon execution, is (amongst other things) creating
109 // the DriverManager service
110 // If this context has never been accessed before, this may be expensive (it includes loading of
111 // at least one library).
112 // As this wizard is intended to run on the first office start, it is very likely that the
113 // context needs to be freshly created
114 // Thus, we access the context here (within the WaitCursor), which means the user sees a waitcursor
115 // while his/her office blocks a few seconds ....
116 m_xORB
->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.sdbc.DriverManager" ) );
121 if (xDialog
->execute())
125 ShowServiceNotAvailableError(m_pMessageParent
, s_sAdministrationServiceName
, sal_True
);
127 catch(const Exception
&)
129 DBG_ERROR("OAdminDialogInvokation::invokeAdministration: caught an exception while executing the dialog!");
134 //.........................................................................
136 //.........................................................................