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 <com/sun/star/sdbc/XDataSource.hpp>
26 :
27 : // .......................................................................
28 : namespace svt
29 : {
30 : // .......................................................................
31 :
32 : #define UNODIALOG_PROPERTY_ID_ALIASES 100
33 : #define UNODIALOG_PROPERTY_ALIASES "FieldMapping"
34 :
35 : using namespace com::sun::star::uno;
36 : using namespace com::sun::star::lang;
37 : using namespace com::sun::star::util;
38 : using namespace com::sun::star::beans;
39 : using namespace com::sun::star::sdbc;
40 :
41 : //=========================================================================
42 : //= OAddressBookSourceDialogUno
43 : //=========================================================================
44 : typedef OGenericUnoDialog OAddressBookSourceDialogUnoBase;
45 0 : class OAddressBookSourceDialogUno
46 : :public OAddressBookSourceDialogUnoBase
47 : ,public ::comphelper::OPropertyArrayUsageHelper< OAddressBookSourceDialogUno >
48 : {
49 : protected:
50 : Sequence< AliasProgrammaticPair > m_aAliases;
51 : Reference< XDataSource > m_xDataSource;
52 : ::rtl::OUString m_sDataSourceName;
53 : ::rtl::OUString m_sTable;
54 :
55 : protected:
56 : OAddressBookSourceDialogUno(const Reference< XMultiServiceFactory >& _rxORB);
57 :
58 : public:
59 : // XTypeProvider
60 : virtual Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(RuntimeException);
61 :
62 : // XServiceInfo
63 : virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
64 : virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(RuntimeException);
65 :
66 : // XServiceInfo - static methods
67 : static Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( RuntimeException );
68 : static ::rtl::OUString getImplementationName_Static(void) throw( RuntimeException );
69 : static Reference< XInterface >
70 : SAL_CALL Create(const Reference< com::sun::star::lang::XMultiServiceFactory >&);
71 :
72 : // XPropertySet
73 : virtual Reference< XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(RuntimeException);
74 : virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
75 :
76 : // OPropertyArrayUsageHelper
77 : virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
78 :
79 : protected:
80 : // OGenericUnoDialog overridables
81 : virtual Dialog* createDialog(Window* _pParent);
82 :
83 : virtual void implInitialize(const com::sun::star::uno::Any& _rValue);
84 :
85 : virtual void executedDialog(sal_Int16 _nExecutionResult);
86 : };
87 :
88 :
89 : //=========================================================================
90 : //= OAddressBookSourceDialogUno
91 : //=========================================================================
92 0 : Reference< XInterface > SAL_CALL OAddressBookSourceDialogUno_CreateInstance( const Reference< XMultiServiceFactory >& _rxFactory)
93 : {
94 0 : return OAddressBookSourceDialogUno::Create(_rxFactory);
95 : }
96 :
97 : //-------------------------------------------------------------------------
98 0 : OAddressBookSourceDialogUno::OAddressBookSourceDialogUno(const Reference< XMultiServiceFactory >& _rxORB)
99 0 : :OGenericUnoDialog(_rxORB)
100 : {
101 : registerProperty(::rtl::OUString(UNODIALOG_PROPERTY_ALIASES), UNODIALOG_PROPERTY_ID_ALIASES, PropertyAttribute::READONLY,
102 0 : &m_aAliases, getCppuType(&m_aAliases));
103 0 : }
104 :
105 : //-------------------------------------------------------------------------
106 0 : Sequence<sal_Int8> SAL_CALL OAddressBookSourceDialogUno::getImplementationId( ) throw(RuntimeException)
107 : {
108 0 : static ::cppu::OImplementationId aId;
109 0 : return aId.getImplementationId();
110 : }
111 :
112 : //-------------------------------------------------------------------------
113 0 : Reference< XInterface > SAL_CALL OAddressBookSourceDialogUno::Create(const Reference< XMultiServiceFactory >& _rxFactory)
114 : {
115 0 : return *(new OAddressBookSourceDialogUno(_rxFactory));
116 : }
117 :
118 : //-------------------------------------------------------------------------
119 0 : ::rtl::OUString SAL_CALL OAddressBookSourceDialogUno::getImplementationName() throw(RuntimeException)
120 : {
121 0 : return getImplementationName_Static();
122 : }
123 :
124 : //-------------------------------------------------------------------------
125 0 : ::rtl::OUString OAddressBookSourceDialogUno::getImplementationName_Static() throw(RuntimeException)
126 : {
127 0 : return ::rtl::OUString( "com.sun.star.comp.svtools.OAddressBookSourceDialogUno" );
128 : }
129 :
130 : //-------------------------------------------------------------------------
131 0 : ::comphelper::StringSequence SAL_CALL OAddressBookSourceDialogUno::getSupportedServiceNames() throw(RuntimeException)
132 : {
133 0 : return getSupportedServiceNames_Static();
134 : }
135 :
136 : //-------------------------------------------------------------------------
137 0 : ::comphelper::StringSequence OAddressBookSourceDialogUno::getSupportedServiceNames_Static() throw(RuntimeException)
138 : {
139 0 : ::comphelper::StringSequence aSupported(1);
140 0 : aSupported.getArray()[0] = ::rtl::OUString( "com.sun.star.ui.AddressBookSourceDialog" );
141 0 : return aSupported;
142 : }
143 :
144 : //-------------------------------------------------------------------------
145 0 : Reference<XPropertySetInfo> SAL_CALL OAddressBookSourceDialogUno::getPropertySetInfo() throw(RuntimeException)
146 : {
147 0 : Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
148 0 : return xInfo;
149 : }
150 :
151 : //-------------------------------------------------------------------------
152 0 : ::cppu::IPropertyArrayHelper& OAddressBookSourceDialogUno::getInfoHelper()
153 : {
154 0 : return *const_cast<OAddressBookSourceDialogUno*>(this)->getArrayHelper();
155 : }
156 :
157 : //------------------------------------------------------------------------------
158 0 : ::cppu::IPropertyArrayHelper* OAddressBookSourceDialogUno::createArrayHelper( ) const
159 : {
160 0 : Sequence< Property > aProps;
161 0 : describeProperties(aProps);
162 0 : return new ::cppu::OPropertyArrayHelper(aProps);
163 : }
164 :
165 : //------------------------------------------------------------------------------
166 0 : void OAddressBookSourceDialogUno::executedDialog(sal_Int16 _nExecutionResult)
167 : {
168 0 : OAddressBookSourceDialogUnoBase::executedDialog(_nExecutionResult);
169 :
170 0 : if ( _nExecutionResult )
171 0 : if ( m_pDialog )
172 0 : static_cast< AddressBookSourceDialog* >( m_pDialog )->getFieldMapping( m_aAliases );
173 0 : }
174 :
175 : //------------------------------------------------------------------------------
176 0 : void OAddressBookSourceDialogUno::implInitialize(const com::sun::star::uno::Any& _rValue)
177 : {
178 0 : PropertyValue aVal;
179 0 : if (_rValue >>= aVal)
180 : {
181 0 : if (0 == aVal.Name.compareToAscii("DataSource"))
182 : {
183 : #if OSL_DEBUG_LEVEL > 0
184 : sal_Bool bSuccess =
185 : #endif
186 0 : aVal.Value >>= m_xDataSource;
187 : OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSource!" );
188 : return;
189 : }
190 :
191 0 : if (0 == aVal.Name.compareToAscii("DataSourceName"))
192 : {
193 : #if OSL_DEBUG_LEVEL > 0
194 : sal_Bool bSuccess =
195 : #endif
196 0 : aVal.Value >>= m_sDataSourceName;
197 : OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSourceName!" );
198 : return;
199 : }
200 :
201 0 : if (0 == aVal.Name.compareToAscii("Command"))
202 : {
203 : #if OSL_DEBUG_LEVEL > 0
204 : sal_Bool bSuccess =
205 : #endif
206 0 : aVal.Value >>= m_sTable;
207 : OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for Command!" );
208 : return;
209 : }
210 : }
211 :
212 0 : OAddressBookSourceDialogUnoBase::implInitialize( _rValue );
213 : }
214 :
215 : //------------------------------------------------------------------------------
216 0 : Dialog* OAddressBookSourceDialogUno::createDialog(Window* _pParent)
217 : {
218 0 : if ( m_xDataSource.is() && !m_sTable.isEmpty() )
219 0 : return new AddressBookSourceDialog(_pParent, m_aContext.getLegacyServiceFactory(), m_xDataSource, m_sDataSourceName, m_sTable, m_aAliases );
220 : else
221 0 : return new AddressBookSourceDialog( _pParent, m_aContext.getLegacyServiceFactory() );
222 : }
223 :
224 : // .......................................................................
225 : } // namespace svt
226 : // .......................................................................
227 :
228 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|