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