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