Line data Source code
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 :
20 : #include "svtools/genericunodialog.hxx"
21 : #include <svtools/addresstemplate.hxx>
22 : #include <comphelper/extract.hxx>
23 : #include <cppuhelper/typeprovider.hxx>
24 : #include <comphelper/property.hxx>
25 : #include <comphelper/processfactory.hxx>
26 : #include <com/sun/star/sdbc/XDataSource.hpp>
27 :
28 : // .......................................................................
29 : namespace svt
30 : {
31 : // .......................................................................
32 :
33 : #define UNODIALOG_PROPERTY_ID_ALIASES 100
34 : #define UNODIALOG_PROPERTY_ALIASES "FieldMapping"
35 :
36 : using namespace com::sun::star::uno;
37 : using namespace com::sun::star::lang;
38 : using namespace com::sun::star::util;
39 : using namespace com::sun::star::beans;
40 : using namespace com::sun::star::sdbc;
41 :
42 : //=========================================================================
43 : //= OAddressBookSourceDialogUno
44 : //=========================================================================
45 : typedef OGenericUnoDialog OAddressBookSourceDialogUnoBase;
46 0 : class OAddressBookSourceDialogUno
47 : :public OAddressBookSourceDialogUnoBase
48 : ,public ::comphelper::OPropertyArrayUsageHelper< OAddressBookSourceDialogUno >
49 : {
50 : protected:
51 : Sequence< AliasProgrammaticPair > m_aAliases;
52 : Reference< XDataSource > m_xDataSource;
53 : OUString m_sDataSourceName;
54 : OUString m_sTable;
55 :
56 : protected:
57 : OAddressBookSourceDialogUno(const Reference< XComponentContext >& _rxORB);
58 :
59 : public:
60 : // XTypeProvider
61 : virtual Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(RuntimeException);
62 :
63 : // XServiceInfo
64 : virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
65 : virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(RuntimeException);
66 :
67 : // XServiceInfo - static methods
68 : static Sequence< OUString > getSupportedServiceNames_Static(void) throw( RuntimeException );
69 : static OUString getImplementationName_Static(void) throw( RuntimeException );
70 : static Reference< XInterface >
71 : SAL_CALL Create(const Reference< com::sun::star::lang::XMultiServiceFactory >&);
72 :
73 : // XPropertySet
74 : virtual Reference< XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(RuntimeException);
75 : virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
76 :
77 : // OPropertyArrayUsageHelper
78 : virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
79 :
80 : virtual void SAL_CALL initialize(const Sequence< Any >& aArguments) throw(Exception, RuntimeException);
81 :
82 : protected:
83 : // OGenericUnoDialog overridables
84 : virtual Dialog* createDialog(Window* _pParent);
85 :
86 : virtual void implInitialize(const com::sun::star::uno::Any& _rValue);
87 :
88 : virtual void executedDialog(sal_Int16 _nExecutionResult);
89 : };
90 :
91 :
92 : //=========================================================================
93 : //= OAddressBookSourceDialogUno
94 : //=========================================================================
95 0 : Reference< XInterface > SAL_CALL OAddressBookSourceDialogUno_CreateInstance( const Reference< XMultiServiceFactory >& _rxFactory)
96 : {
97 0 : return OAddressBookSourceDialogUno::Create(_rxFactory);
98 : }
99 :
100 : //-------------------------------------------------------------------------
101 0 : OAddressBookSourceDialogUno::OAddressBookSourceDialogUno(const Reference< XComponentContext >& _rxORB)
102 0 : :OGenericUnoDialog(_rxORB)
103 : {
104 : registerProperty(OUString(UNODIALOG_PROPERTY_ALIASES), UNODIALOG_PROPERTY_ID_ALIASES, PropertyAttribute::READONLY,
105 0 : &m_aAliases, getCppuType(&m_aAliases));
106 0 : }
107 :
108 : //-------------------------------------------------------------------------
109 0 : Sequence<sal_Int8> SAL_CALL OAddressBookSourceDialogUno::getImplementationId( ) throw(RuntimeException)
110 : {
111 0 : static ::cppu::OImplementationId aId;
112 0 : return aId.getImplementationId();
113 : }
114 :
115 : //-------------------------------------------------------------------------
116 0 : Reference< XInterface > SAL_CALL OAddressBookSourceDialogUno::Create(const Reference< XMultiServiceFactory >& _rxFactory)
117 : {
118 0 : return *(new OAddressBookSourceDialogUno( comphelper::getComponentContext(_rxFactory)));
119 : }
120 :
121 : //-------------------------------------------------------------------------
122 0 : OUString SAL_CALL OAddressBookSourceDialogUno::getImplementationName() throw(RuntimeException)
123 : {
124 0 : return getImplementationName_Static();
125 : }
126 :
127 : //-------------------------------------------------------------------------
128 0 : OUString OAddressBookSourceDialogUno::getImplementationName_Static() throw(RuntimeException)
129 : {
130 0 : return OUString( "com.sun.star.comp.svtools.OAddressBookSourceDialogUno" );
131 : }
132 :
133 : //-------------------------------------------------------------------------
134 0 : ::comphelper::StringSequence SAL_CALL OAddressBookSourceDialogUno::getSupportedServiceNames() throw(RuntimeException)
135 : {
136 0 : return getSupportedServiceNames_Static();
137 : }
138 :
139 : //-------------------------------------------------------------------------
140 0 : ::comphelper::StringSequence OAddressBookSourceDialogUno::getSupportedServiceNames_Static() throw(RuntimeException)
141 : {
142 0 : ::comphelper::StringSequence aSupported(1);
143 0 : aSupported.getArray()[0] = OUString( "com.sun.star.ui.AddressBookSourceDialog" );
144 0 : return aSupported;
145 : }
146 :
147 : //-------------------------------------------------------------------------
148 0 : Reference<XPropertySetInfo> SAL_CALL OAddressBookSourceDialogUno::getPropertySetInfo() throw(RuntimeException)
149 : {
150 0 : Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
151 0 : return xInfo;
152 : }
153 :
154 : //-------------------------------------------------------------------------
155 0 : ::cppu::IPropertyArrayHelper& OAddressBookSourceDialogUno::getInfoHelper()
156 : {
157 0 : return *getArrayHelper();
158 : }
159 :
160 : //------------------------------------------------------------------------------
161 0 : ::cppu::IPropertyArrayHelper* OAddressBookSourceDialogUno::createArrayHelper( ) const
162 : {
163 0 : Sequence< Property > aProps;
164 0 : describeProperties(aProps);
165 0 : return new ::cppu::OPropertyArrayHelper(aProps);
166 : }
167 :
168 : //------------------------------------------------------------------------------
169 0 : void OAddressBookSourceDialogUno::executedDialog(sal_Int16 _nExecutionResult)
170 : {
171 0 : OAddressBookSourceDialogUnoBase::executedDialog(_nExecutionResult);
172 :
173 0 : if ( _nExecutionResult )
174 0 : if ( m_pDialog )
175 0 : static_cast< AddressBookSourceDialog* >( m_pDialog )->getFieldMapping( m_aAliases );
176 0 : }
177 : //------------------------------------------------------------------------------
178 0 : void SAL_CALL OAddressBookSourceDialogUno::initialize(const Sequence< Any >& rArguments) throw(Exception, RuntimeException)
179 : {
180 0 : if( rArguments.getLength() == 5 )
181 : {
182 0 : Reference<com::sun::star::awt::XWindow> xParentWindow;
183 0 : Reference<com::sun::star::beans::XPropertySet> xDataSource;
184 0 : OUString sDataSourceName;
185 0 : OUString sCommand;
186 0 : OUString sTitle;
187 0 : if ( (rArguments[0] >>= xParentWindow)
188 0 : && (rArguments[1] >>= xDataSource)
189 0 : && (rArguments[2] >>= sDataSourceName)
190 0 : && (rArguments[3] >>= sCommand)
191 0 : && (rArguments[4] >>= sTitle) )
192 : {
193 :
194 : // convert the parameters for creating the dialog to PropertyValues
195 0 : Sequence< Any > aArguments(5);
196 0 : Any* pArguments = aArguments.getArray();
197 : // the parent window
198 0 : *pArguments++ <<= PropertyValue(OUString( "ParentWindow" ), -1, makeAny( xParentWindow ), PropertyState_DIRECT_VALUE);
199 : // the data source to use
200 0 : *pArguments++ <<= PropertyValue(OUString( "DataSource" ), -1, makeAny( xDataSource ), PropertyState_DIRECT_VALUE);
201 0 : *pArguments++ <<= PropertyValue(OUString( "DataSourceName" ), -1, makeAny( sDataSourceName ), PropertyState_DIRECT_VALUE);
202 : // the table to use
203 0 : *pArguments++ <<= PropertyValue(OUString( "Command" ), -1, makeAny( sCommand ), PropertyState_DIRECT_VALUE);
204 : // the title
205 0 : *pArguments++ <<= PropertyValue(OUString( "Title" ), -1, makeAny( sTitle ), PropertyState_DIRECT_VALUE);
206 0 : OGenericUnoDialog::initialize(aArguments);
207 0 : return;
208 0 : }
209 : }
210 0 : OGenericUnoDialog::initialize(rArguments);
211 : }
212 : //------------------------------------------------------------------------------
213 0 : void OAddressBookSourceDialogUno::implInitialize(const com::sun::star::uno::Any& _rValue)
214 : {
215 0 : PropertyValue aVal;
216 0 : if (_rValue >>= aVal)
217 : {
218 0 : if (0 == aVal.Name.compareToAscii("DataSource"))
219 : {
220 : #if OSL_DEBUG_LEVEL > 0
221 : sal_Bool bSuccess =
222 : #endif
223 0 : aVal.Value >>= m_xDataSource;
224 : OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSource!" );
225 0 : return;
226 : }
227 :
228 0 : if (0 == aVal.Name.compareToAscii("DataSourceName"))
229 : {
230 : #if OSL_DEBUG_LEVEL > 0
231 : sal_Bool bSuccess =
232 : #endif
233 0 : aVal.Value >>= m_sDataSourceName;
234 : OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSourceName!" );
235 0 : return;
236 : }
237 :
238 0 : if (0 == aVal.Name.compareToAscii("Command"))
239 : {
240 : #if OSL_DEBUG_LEVEL > 0
241 : sal_Bool bSuccess =
242 : #endif
243 0 : aVal.Value >>= m_sTable;
244 : OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for Command!" );
245 0 : return;
246 : }
247 : }
248 :
249 0 : OAddressBookSourceDialogUnoBase::implInitialize( _rValue );
250 : }
251 :
252 : //------------------------------------------------------------------------------
253 0 : Dialog* OAddressBookSourceDialogUno::createDialog(Window* _pParent)
254 : {
255 0 : if ( m_xDataSource.is() && !m_sTable.isEmpty() )
256 0 : return new AddressBookSourceDialog(_pParent, m_aContext, m_xDataSource, m_sDataSourceName, m_sTable, m_aAliases );
257 : else
258 0 : return new AddressBookSourceDialog( _pParent, m_aContext );
259 : }
260 :
261 : // .......................................................................
262 465 : } // namespace svt
263 : // .......................................................................
264 :
265 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|