xref: /aoo41x/main/svtools/source/uno/addrtempuno.cxx (revision 5900e8ec)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #include "svtools/genericunodialog.hxx"
27cdf0e10cSrcweir #include <svtools/addresstemplate.hxx>
28cdf0e10cSrcweir #include <comphelper/extract.hxx>
29cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
30cdf0e10cSrcweir #include <comphelper/property.hxx>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir class SfxItemSet;
34cdf0e10cSrcweir class SfxItemPool;
35cdf0e10cSrcweir class SfxPoolItem;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // .......................................................................
38cdf0e10cSrcweir namespace svt
39cdf0e10cSrcweir {
40cdf0e10cSrcweir // .......................................................................
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #define UNODIALOG_PROPERTY_ID_ALIASES		100
43cdf0e10cSrcweir #define UNODIALOG_PROPERTY_ALIASES			"FieldMapping"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	using namespace com::sun::star::uno;
46cdf0e10cSrcweir 	using namespace com::sun::star::lang;
47cdf0e10cSrcweir 	using namespace com::sun::star::util;
48cdf0e10cSrcweir 	using namespace com::sun::star::beans;
49cdf0e10cSrcweir 	using namespace com::sun::star::sdbc;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	//=========================================================================
52cdf0e10cSrcweir 	//= OAddressBookSourceDialogUno
53cdf0e10cSrcweir 	//=========================================================================
54cdf0e10cSrcweir 	typedef OGenericUnoDialog OAddressBookSourceDialogUnoBase;
55cdf0e10cSrcweir 	class OAddressBookSourceDialogUno
56cdf0e10cSrcweir 			:public OAddressBookSourceDialogUnoBase
57cdf0e10cSrcweir 			,public ::comphelper::OPropertyArrayUsageHelper< OAddressBookSourceDialogUno >
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 	protected:
60cdf0e10cSrcweir 		Sequence< AliasProgrammaticPair >	m_aAliases;
61cdf0e10cSrcweir         Reference< XDataSource >            m_xDataSource;
62cdf0e10cSrcweir         ::rtl::OUString                     m_sDataSourceName;
63cdf0e10cSrcweir 		::rtl::OUString						m_sTable;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	protected:
66cdf0e10cSrcweir 		OAddressBookSourceDialogUno(const Reference< XMultiServiceFactory >& _rxORB);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	public:
69cdf0e10cSrcweir 		// XTypeProvider
70cdf0e10cSrcweir 		virtual Sequence<sal_Int8> SAL_CALL getImplementationId(  ) throw(RuntimeException);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 		// XServiceInfo
73cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
74cdf0e10cSrcweir 		virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(RuntimeException);
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 		// XServiceInfo - static methods
77cdf0e10cSrcweir 		static Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( RuntimeException );
78cdf0e10cSrcweir 		static ::rtl::OUString getImplementationName_Static(void) throw( RuntimeException );
79cdf0e10cSrcweir 		static Reference< XInterface >
80cdf0e10cSrcweir 				SAL_CALL Create(const Reference< com::sun::star::lang::XMultiServiceFactory >&);
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 		// XPropertySet
83cdf0e10cSrcweir 		virtual Reference< XPropertySetInfo>  SAL_CALL getPropertySetInfo() throw(RuntimeException);
84cdf0e10cSrcweir 		virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 		// OPropertyArrayUsageHelper
87cdf0e10cSrcweir 		virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	protected:
90cdf0e10cSrcweir 	// OGenericUnoDialog overridables
91cdf0e10cSrcweir 		virtual Dialog*	createDialog(Window* _pParent);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		virtual void implInitialize(const com::sun::star::uno::Any& _rValue);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 		virtual void executedDialog(sal_Int16 _nExecutionResult);
96cdf0e10cSrcweir 	};
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	//=========================================================================
100cdf0e10cSrcweir 	//= OAddressBookSourceDialogUno
101cdf0e10cSrcweir 	//=========================================================================
OAddressBookSourceDialogUno_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)102cdf0e10cSrcweir 	Reference< XInterface > SAL_CALL OAddressBookSourceDialogUno_CreateInstance( const Reference< XMultiServiceFactory >& _rxFactory)
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		return OAddressBookSourceDialogUno::Create(_rxFactory);
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	//-------------------------------------------------------------------------
OAddressBookSourceDialogUno(const Reference<XMultiServiceFactory> & _rxORB)108cdf0e10cSrcweir 	OAddressBookSourceDialogUno::OAddressBookSourceDialogUno(const Reference< XMultiServiceFactory >& _rxORB)
109cdf0e10cSrcweir 		:OGenericUnoDialog(_rxORB)
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		registerProperty(::rtl::OUString::createFromAscii(UNODIALOG_PROPERTY_ALIASES), UNODIALOG_PROPERTY_ID_ALIASES, PropertyAttribute::READONLY,
112cdf0e10cSrcweir 			&m_aAliases, getCppuType(&m_aAliases));
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	//-------------------------------------------------------------------------
getImplementationId()116cdf0e10cSrcweir 	Sequence<sal_Int8> SAL_CALL OAddressBookSourceDialogUno::getImplementationId(  ) throw(RuntimeException)
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir 		static ::cppu::OImplementationId aId;
119cdf0e10cSrcweir 		return aId.getImplementationId();
120cdf0e10cSrcweir 	}
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	//-------------------------------------------------------------------------
Create(const Reference<XMultiServiceFactory> & _rxFactory)123cdf0e10cSrcweir 	Reference< XInterface > SAL_CALL OAddressBookSourceDialogUno::Create(const Reference< XMultiServiceFactory >& _rxFactory)
124cdf0e10cSrcweir 	{
125cdf0e10cSrcweir 		return *(new OAddressBookSourceDialogUno(_rxFactory));
126cdf0e10cSrcweir 	}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	//-------------------------------------------------------------------------
getImplementationName()129cdf0e10cSrcweir 	::rtl::OUString SAL_CALL OAddressBookSourceDialogUno::getImplementationName() throw(RuntimeException)
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		return getImplementationName_Static();
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	//-------------------------------------------------------------------------
getImplementationName_Static()135cdf0e10cSrcweir 	::rtl::OUString OAddressBookSourceDialogUno::getImplementationName_Static() throw(RuntimeException)
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		return ::rtl::OUString::createFromAscii("com.sun.star.comp.svtools.OAddressBookSourceDialogUno");
138cdf0e10cSrcweir 	}
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	//-------------------------------------------------------------------------
getSupportedServiceNames()141cdf0e10cSrcweir 	::comphelper::StringSequence SAL_CALL OAddressBookSourceDialogUno::getSupportedServiceNames() throw(RuntimeException)
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir 		return getSupportedServiceNames_Static();
144cdf0e10cSrcweir 	}
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	//-------------------------------------------------------------------------
getSupportedServiceNames_Static()147cdf0e10cSrcweir 	::comphelper::StringSequence OAddressBookSourceDialogUno::getSupportedServiceNames_Static() throw(RuntimeException)
148cdf0e10cSrcweir 	{
149cdf0e10cSrcweir 		::comphelper::StringSequence aSupported(1);
150cdf0e10cSrcweir 		aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.ui.AddressBookSourceDialog");
151cdf0e10cSrcweir 		return aSupported;
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	//-------------------------------------------------------------------------
getPropertySetInfo()155cdf0e10cSrcweir 	Reference<XPropertySetInfo>  SAL_CALL OAddressBookSourceDialogUno::getPropertySetInfo() throw(RuntimeException)
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
158cdf0e10cSrcweir 		return xInfo;
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	//-------------------------------------------------------------------------
getInfoHelper()162cdf0e10cSrcweir 	::cppu::IPropertyArrayHelper& OAddressBookSourceDialogUno::getInfoHelper()
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		return *const_cast<OAddressBookSourceDialogUno*>(this)->getArrayHelper();
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	//------------------------------------------------------------------------------
createArrayHelper() const168cdf0e10cSrcweir 	::cppu::IPropertyArrayHelper* OAddressBookSourceDialogUno::createArrayHelper( ) const
169cdf0e10cSrcweir 	{
170cdf0e10cSrcweir 		Sequence< Property > aProps;
171cdf0e10cSrcweir 		describeProperties(aProps);
172cdf0e10cSrcweir 		return new ::cppu::OPropertyArrayHelper(aProps);
173cdf0e10cSrcweir 	}
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	//------------------------------------------------------------------------------
executedDialog(sal_Int16 _nExecutionResult)176cdf0e10cSrcweir 	void OAddressBookSourceDialogUno::executedDialog(sal_Int16 _nExecutionResult)
177cdf0e10cSrcweir 	{
178cdf0e10cSrcweir 		OAddressBookSourceDialogUnoBase::executedDialog(_nExecutionResult);
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 		if ( _nExecutionResult )
181cdf0e10cSrcweir 			if ( m_pDialog )
182cdf0e10cSrcweir 				static_cast< AddressBookSourceDialog* >( m_pDialog )->getFieldMapping( m_aAliases );
183cdf0e10cSrcweir 	}
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	//------------------------------------------------------------------------------
implInitialize(const com::sun::star::uno::Any & _rValue)186cdf0e10cSrcweir 	void OAddressBookSourceDialogUno::implInitialize(const com::sun::star::uno::Any& _rValue)
187cdf0e10cSrcweir 	{
188cdf0e10cSrcweir 		PropertyValue aVal;
189cdf0e10cSrcweir 		if (_rValue >>= aVal)
190cdf0e10cSrcweir 		{
191cdf0e10cSrcweir 			if (0 == aVal.Name.compareToAscii("DataSource"))
192cdf0e10cSrcweir 			{
193cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
194cdf0e10cSrcweir 				sal_Bool bSuccess =
195cdf0e10cSrcweir #endif
196cdf0e10cSrcweir 				aVal.Value >>= m_xDataSource;
197cdf0e10cSrcweir 				OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSource!" );
198cdf0e10cSrcweir 				return;
199cdf0e10cSrcweir 			}
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 			if (0 == aVal.Name.compareToAscii("DataSourceName"))
202cdf0e10cSrcweir 			{
203cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
204cdf0e10cSrcweir 				sal_Bool bSuccess =
205cdf0e10cSrcweir #endif
206cdf0e10cSrcweir 				aVal.Value >>= m_sDataSourceName;
207cdf0e10cSrcweir 				OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSourceName!" );
208cdf0e10cSrcweir 				return;
209cdf0e10cSrcweir             }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 			if (0 == aVal.Name.compareToAscii("Command"))
212cdf0e10cSrcweir 			{
213cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
214cdf0e10cSrcweir 				sal_Bool bSuccess =
215cdf0e10cSrcweir #endif
216cdf0e10cSrcweir 				aVal.Value >>= m_sTable;
217cdf0e10cSrcweir 				OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for Command!" );
218cdf0e10cSrcweir 				return;
219cdf0e10cSrcweir 			}
220cdf0e10cSrcweir 		}
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 		OAddressBookSourceDialogUnoBase::implInitialize( _rValue );
223cdf0e10cSrcweir 	}
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 	//------------------------------------------------------------------------------
createDialog(Window * _pParent)226cdf0e10cSrcweir 	Dialog*	OAddressBookSourceDialogUno::createDialog(Window* _pParent)
227cdf0e10cSrcweir 	{
228cdf0e10cSrcweir 		if ( m_xDataSource.is() && m_sTable.getLength() )
229cdf0e10cSrcweir 			return new AddressBookSourceDialog(_pParent, m_aContext.getLegacyServiceFactory(), m_xDataSource, m_sDataSourceName, m_sTable, m_aAliases );
230cdf0e10cSrcweir 		else
231cdf0e10cSrcweir 			return new AddressBookSourceDialog( _pParent, m_aContext.getLegacyServiceFactory() );
232cdf0e10cSrcweir 	}
233cdf0e10cSrcweir 
234cdf0e10cSrcweir // .......................................................................
235cdf0e10cSrcweir }	// namespace svt
236cdf0e10cSrcweir // .......................................................................
237cdf0e10cSrcweir 
238