1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "admininvokationimpl.hxx"
21 #include <tools/debug.hxx>
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
24 #include <com/sun/star/awt/XWindow.hpp>
25 #include <com/sun/star/sdbc/DriverManager.hpp>
26 #include <vcl/stdtext.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include "abpresid.hrc"
29 #include "componentmodule.hxx"
30 #include <vcl/waitobj.hxx>
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::beans
;
41 using namespace ::com::sun::star::awt
;
42 using namespace ::com::sun::star::ui::dialogs
;
43 using namespace ::com::sun::star::sdbc
;
45 OAdminDialogInvokation::OAdminDialogInvokation(const Reference
< XComponentContext
>& _rxContext
,
46 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxDataSource
47 , vcl::Window
* _pMessageParent
)
48 :m_xContext(_rxContext
)
49 ,m_xDataSource(_rxDataSource
)
50 ,m_pMessageParent(_pMessageParent
)
52 DBG_ASSERT(m_xContext
.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid service factory!");
53 DBG_ASSERT(m_xDataSource
.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid preferred name!");
54 DBG_ASSERT(m_pMessageParent
, "OAdminDialogInvokation::OAdminDialogInvokation: invalid message parent!");
58 bool OAdminDialogInvokation::invokeAdministration( bool _bFixedType
)
65 // the service name of the administration dialog
66 static const char s_sAdministrationServiceName
[] = "com.sun.star.sdb.DatasourceAdministrationDialog";
67 static const char s_sDataSourceTypeChangeDialog
[] = "com.sun.star.sdb.DataSourceTypeChangeDialog";
69 // the parameters for the call
70 Sequence
< Any
> aArguments(3);
71 Any
* pArguments
= aArguments
.getArray();
74 Reference
< XWindow
> xDialogParent
= VCLUnoHelper::GetInterface(m_pMessageParent
);
75 *pArguments
++ <<= PropertyValue(OUString("ParentWindow"), -1, makeAny(xDialogParent
), PropertyState_DIRECT_VALUE
);
77 // the title of the dialog
78 OUString
sAdminDialogTitle(ModuleRes(RID_STR_ADMINDIALOGTITLE
).toString());
79 *pArguments
++ <<= PropertyValue(OUString("Title"), -1, makeAny(sAdminDialogTitle
), PropertyState_DIRECT_VALUE
);
81 // the name of the new data source
82 *pArguments
++ <<= PropertyValue(OUString("InitialSelection"), -1, makeAny(m_xDataSource
), PropertyState_DIRECT_VALUE
);
85 Reference
< XExecutableDialog
> xDialog
;
87 // creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded)
88 // so we display a wait cursor
89 WaitObject
aWaitCursor(m_pMessageParent
);
90 Reference
<XInterface
> x
= m_xContext
->getServiceManager()->createInstanceWithArgumentsAndContext(_bFixedType
? OUString(s_sAdministrationServiceName
) : OUString(s_sDataSourceTypeChangeDialog
), aArguments
, m_xContext
);
91 xDialog
= Reference
< XExecutableDialog
>( x
, UNO_QUERY
);
93 // just for a smoother UI: What the dialog does upon execution, is (amongst other things) creating
94 // the DriverManager service
95 // If this context has never been accessed before, this may be expensive (it includes loading of
96 // at least one library).
97 // As this wizard is intended to run on the first office start, it is very likely that the
98 // context needs to be freshly created
99 // Thus, we access the context here (within the WaitCursor), which means the user sees a waitcursor
100 // while his/her office blocks a few seconds ....
101 DriverManager::create( m_xContext
);
106 if (xDialog
->execute())
110 ShowServiceNotAvailableError(m_pMessageParent
, s_sAdministrationServiceName
, true);
112 catch(const Exception
&)
114 OSL_FAIL("OAdminDialogInvokation::invokeAdministration: caught an exception while executing the dialog!");
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */