12a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52a97ec55SAndrew Rist  * distributed with this work for additional information
62a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
82a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
92a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
102a97ec55SAndrew Rist  *
112a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122a97ec55SAndrew Rist  *
132a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
142a97ec55SAndrew Rist  * software distributed under the License is distributed on an
152a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
172a97ec55SAndrew Rist  * specific language governing permissions and limitations
182a97ec55SAndrew Rist  * under the License.
192a97ec55SAndrew Rist  *
202a97ec55SAndrew Rist  *************************************************************/
212a97ec55SAndrew Rist 
222a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include "admininvokationimpl.hxx"
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
29cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
30cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
31cdf0e10cSrcweir #include <vcl/stdtext.hxx>
32cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
33*b63233d8Sdamjan #include <toolkit/helper/vclunohelper.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #ifndef EXTENSIONS_ABPRESID_HRC
36cdf0e10cSrcweir #include "abpresid.hrc"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #include "componentmodule.hxx"
39cdf0e10cSrcweir #include <vcl/waitobj.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //.........................................................................
43cdf0e10cSrcweir namespace abp
44cdf0e10cSrcweir {
45cdf0e10cSrcweir //.........................................................................
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
49cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
50cdf0e10cSrcweir 	using namespace ::com::sun::star::awt;
51cdf0e10cSrcweir 	using namespace ::com::sun::star::ui::dialogs;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	//=====================================================================
54cdf0e10cSrcweir 	//= OAdminDialogInvokation
55cdf0e10cSrcweir 	//=====================================================================
56cdf0e10cSrcweir 	//---------------------------------------------------------------------
OAdminDialogInvokation(const Reference<XMultiServiceFactory> & _rxORB,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> _xDataSource,Window * _pMessageParent)57cdf0e10cSrcweir 	OAdminDialogInvokation::OAdminDialogInvokation(const Reference< XMultiServiceFactory >& _rxORB
58cdf0e10cSrcweir 					, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > _xDataSource
59cdf0e10cSrcweir 					, Window* _pMessageParent)
60cdf0e10cSrcweir 		:m_xORB(_rxORB)
61cdf0e10cSrcweir 		,m_xDataSource(_xDataSource)
62cdf0e10cSrcweir 		,m_pMessageParent(_pMessageParent)
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 		DBG_ASSERT(m_xORB.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid service factory!");
65cdf0e10cSrcweir 		DBG_ASSERT(m_xDataSource.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid preferred name!");
66cdf0e10cSrcweir 		DBG_ASSERT(m_pMessageParent, "OAdminDialogInvokation::OAdminDialogInvokation: invalid message parent!");
67cdf0e10cSrcweir 	}
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	//---------------------------------------------------------------------
invokeAdministration(sal_Bool _bFixedType)70cdf0e10cSrcweir 	sal_Bool OAdminDialogInvokation::invokeAdministration( sal_Bool _bFixedType )
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 		if (!m_xORB.is())
73cdf0e10cSrcweir 			return sal_False;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 		try
76cdf0e10cSrcweir 		{
77cdf0e10cSrcweir 			// the service name of the administration dialog
78cdf0e10cSrcweir 			const static ::rtl::OUString s_sAdministrationServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DatasourceAdministrationDialog"));
79cdf0e10cSrcweir 			const static ::rtl::OUString s_sDataSourceTypeChangeDialog = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DataSourceTypeChangeDialog"));
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 			// the parameters for the call
82cdf0e10cSrcweir 			Sequence< Any > aArguments(3);
83cdf0e10cSrcweir 			Any* pArguments = aArguments.getArray();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 			// the parent window
86cdf0e10cSrcweir 			Reference< XWindow > xDialogParent = VCLUnoHelper::GetInterface(m_pMessageParent);
87cdf0e10cSrcweir 			*pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("ParentWindow"), -1, makeAny(xDialogParent), PropertyState_DIRECT_VALUE);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 			// the title of the dialog
90cdf0e10cSrcweir 			String sAdminDialogTitle(ModuleRes(RID_STR_ADMINDIALOGTITLE));
91cdf0e10cSrcweir 			*pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("Title"), -1, makeAny(::rtl::OUString(sAdminDialogTitle)), PropertyState_DIRECT_VALUE);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 			// the name of the new data source
94cdf0e10cSrcweir 			*pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("InitialSelection"), -1, makeAny(m_xDataSource), PropertyState_DIRECT_VALUE);
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 			// create the dialog
97cdf0e10cSrcweir 			Reference< XExecutableDialog > xDialog;
98cdf0e10cSrcweir 			{
99cdf0e10cSrcweir 				// creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded)
100cdf0e10cSrcweir 				// so we display a wait cursor
101cdf0e10cSrcweir 				WaitObject aWaitCursor(m_pMessageParent);
102cdf0e10cSrcweir 				xDialog = Reference< XExecutableDialog >( m_xORB->createInstanceWithArguments( _bFixedType ? s_sAdministrationServiceName : s_sDataSourceTypeChangeDialog, aArguments ), UNO_QUERY );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 				// just for a smoother UI: What the dialog does upon execution, is (amongst other things) creating
105cdf0e10cSrcweir 				// the DriverManager service
106cdf0e10cSrcweir 				// If this context has never been accessed before, this may be expensive (it includes loading of
107cdf0e10cSrcweir 				// at least one library).
108cdf0e10cSrcweir 				// As this wizard is intended to run on the first office start, it is very likely that the
109cdf0e10cSrcweir 				// context needs to be freshly created
110cdf0e10cSrcweir 				// Thus, we access the context here (within the WaitCursor), which means the user sees a waitcursor
111cdf0e10cSrcweir 				// while his/her office blocks a few seconds ....
112cdf0e10cSrcweir 				m_xORB->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.sdbc.DriverManager" ) );
113cdf0e10cSrcweir 			}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 			if (xDialog.is())
116cdf0e10cSrcweir 			{	// execute it
117cdf0e10cSrcweir 				if (xDialog->execute())
118cdf0e10cSrcweir 					return sal_True;
119cdf0e10cSrcweir 			}
120cdf0e10cSrcweir 			else
121cdf0e10cSrcweir 				ShowServiceNotAvailableError(m_pMessageParent, s_sAdministrationServiceName, sal_True);
122cdf0e10cSrcweir 		}
123cdf0e10cSrcweir 		catch(const Exception&)
124cdf0e10cSrcweir 		{
125cdf0e10cSrcweir 			DBG_ERROR("OAdminDialogInvokation::invokeAdministration: caught an exception while executing the dialog!");
126cdf0e10cSrcweir 		}
127cdf0e10cSrcweir 		return sal_False;
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir //.........................................................................
131cdf0e10cSrcweir }	// namespace abp
132cdf0e10cSrcweir //.........................................................................
133cdf0e10cSrcweir 
134