LibreOffice Module svtools (master) 1
addrtempuno.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
24#include <com/sun/star/awt/XWindow.hpp>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/util/AliasProgrammaticPair.hpp>
27#include <com/sun/star/sdbc/XDataSource.hpp>
28#include <vcl/svapp.hxx>
29
30using namespace svt;
31
32namespace {
33
34#define UNODIALOG_PROPERTY_ID_ALIASES 100
35constexpr OUStringLiteral UNODIALOG_PROPERTY_ALIASES = u"FieldMapping";
36
37 using namespace css::uno;
38 using namespace css::lang;
39 using namespace css::util;
40 using namespace css::beans;
41 using namespace css::sdbc;
42
43 class OAddressBookSourceDialogUno
44 :public OGenericUnoDialog
45 ,public ::comphelper::OPropertyArrayUsageHelper< OAddressBookSourceDialogUno >
46 {
47 private:
50 OUString m_sDataSourceName;
51 OUString m_sTable;
52
53 public:
54 explicit OAddressBookSourceDialogUno(const Reference< XComponentContext >& _rxORB);
55
56 // XTypeProvider
57 virtual Sequence<sal_Int8> SAL_CALL getImplementationId( ) override;
58
59 // XServiceInfo
60 virtual OUString SAL_CALL getImplementationName() override;
61 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
62
63 // XPropertySet
64 virtual Reference< XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
65 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
66
67 // OPropertyArrayUsageHelper
68 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
69
70 virtual void SAL_CALL initialize(const Sequence< Any >& aArguments) override;
71
72 protected:
73 // OGenericUnoDialog overridables
74 virtual std::unique_ptr<weld::DialogController> createDialog(const css::uno::Reference<css::awt::XWindow>& rParent) override;
75
76 virtual void implInitialize(const css::uno::Any& _rValue) override;
77
78 virtual void executedDialog(sal_Int16 _nExecutionResult) override;
79 };
80
81
82 OAddressBookSourceDialogUno::OAddressBookSourceDialogUno(const Reference< XComponentContext >& _rxORB)
83 :OGenericUnoDialog(_rxORB)
84 {
85 registerProperty(UNODIALOG_PROPERTY_ALIASES, UNODIALOG_PROPERTY_ID_ALIASES, PropertyAttribute::READONLY,
86 &m_aAliases, cppu::UnoType<decltype(m_aAliases)>::get());
87 }
88
89
90 Sequence<sal_Int8> SAL_CALL OAddressBookSourceDialogUno::getImplementationId( )
91 {
92 return css::uno::Sequence<sal_Int8>();
93 }
94
95
96 OUString SAL_CALL OAddressBookSourceDialogUno::getImplementationName()
97 {
98 return "com.sun.star.comp.svtools.OAddressBookSourceDialogUno";
99 }
100
101
102 css::uno::Sequence<OUString> SAL_CALL OAddressBookSourceDialogUno::getSupportedServiceNames()
103 {
104 return { "com.sun.star.ui.AddressBookSourceDialog" };
105 }
106
107
108 Reference<XPropertySetInfo> SAL_CALL OAddressBookSourceDialogUno::getPropertySetInfo()
109 {
110 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
111 return xInfo;
112 }
113
114 ::cppu::IPropertyArrayHelper& OAddressBookSourceDialogUno::getInfoHelper()
115 {
116 return *getArrayHelper();
117 }
118
119 ::cppu::IPropertyArrayHelper* OAddressBookSourceDialogUno::createArrayHelper( ) const
120 {
122 describeProperties(aProps);
123 return new ::cppu::OPropertyArrayHelper(aProps);
124 }
125
126 void OAddressBookSourceDialogUno::executedDialog(sal_Int16 _nExecutionResult)
127 {
128 OGenericUnoDialog::executedDialog(_nExecutionResult);
129
130 if ( _nExecutionResult && m_xDialog )
131 static_cast<AddressBookSourceDialog*>(m_xDialog.get())->getFieldMapping(m_aAliases);
132 }
133
134 void SAL_CALL OAddressBookSourceDialogUno::initialize(const Sequence< Any >& rArguments)
135 {
136 if( rArguments.getLength() == 5 )
137 {
138 Reference<css::awt::XWindow> xParentWindow;
140 OUString sDataSourceName;
141 OUString sCommand;
142 OUString sTitle;
143 if ( (rArguments[0] >>= xParentWindow)
144 && (rArguments[1] >>= xDataSource)
145 && (rArguments[2] >>= sDataSourceName)
146 && (rArguments[3] >>= sCommand)
147 && (rArguments[4] >>= sTitle) )
148 {
149
150 // convert the parameters for creating the dialog to PropertyValues
152 {
153 {"ParentWindow", Any(xParentWindow)},
154 {"DataSource", Any(xDataSource)},
155 {"DataSourceName", Any(sDataSourceName)},
156 {"Command", Any(sCommand)}, // the table to use
157 {"Title", Any(sTitle)}
158 }));
159 OGenericUnoDialog::initialize(aArguments);
160 return;
161 }
162 }
163 OGenericUnoDialog::initialize(rArguments);
164 }
165
166 void OAddressBookSourceDialogUno::implInitialize(const css::uno::Any& _rValue)
167 {
168 PropertyValue aVal;
169 if (_rValue >>= aVal)
170 {
171 if (aVal.Name == "DataSource")
172 {
173 bool bSuccess = aVal.Value >>= m_xDataSource;
174 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSource!" );
175 return;
176 }
177
178 if (aVal.Name == "DataSourceName")
179 {
180 bool bSuccess = aVal.Value >>= m_sDataSourceName;
181 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSourceName!" );
182 return;
183 }
184
185 if (aVal.Name == "Command")
186 {
187 bool bSuccess = aVal.Value >>= m_sTable;
188 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for Command!" );
189 return;
190 }
191 }
192
193 OGenericUnoDialog::implInitialize( _rValue );
194 }
195
196 std::unique_ptr<weld::DialogController> OAddressBookSourceDialogUno::createDialog(const css::uno::Reference<css::awt::XWindow>& rParent)
197 {
198 weld::Window* pParent = Application::GetFrameWeld(rParent);
199 if ( m_xDataSource.is() && !m_sTable.isEmpty() )
200 return std::make_unique<AddressBookSourceDialog>(pParent, m_aContext, m_xDataSource, m_sDataSourceName, m_sTable, m_aAliases);
201 return std::make_unique<AddressBookSourceDialog>(pParent, m_aContext);
202 }
203}
204
205extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
207 css::uno::XComponentContext * context,
208 css::uno::Sequence<css::uno::Any> const &)
209{
210 return cppu::acquire(new OAddressBookSourceDialogUno(context));
211}
212
213/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
MapString2String m_aAliases
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svtools_OAddressBookSourceDialogUno_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define UNODIALOG_PROPERTY_ID_ALIASES
Definition: addrtempuno.cxx:34
Reference< XExecutableDialog > m_xDialog
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const=0
abstract base class for implementing UNO objects representing dialogs (com.sun.star....
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override=0
virtual std::unique_ptr< weld::DialogController > createDialog(const css::uno::Reference< css::awt::XWindow > &rParent)=0
create the concrete dialog instance.
virtual void executedDialog(sal_Int16)
called after the dialog has been executed
virtual OUString SAL_CALL getImplementationName() override=0
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override=0
virtual void implInitialize(const css::uno::Any &_rValue)
smaller form of <method>initialize</method>.
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Reference< XDataSource > m_xDataSource
float u
Sequence< PropertyValue > aArguments
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)