1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
28 // .......................................................................
31 // .......................................................................
33 #define UNODIALOG_PROPERTY_ID_ALIASES 100
34 #define UNODIALOG_PROPERTY_ALIASES "FieldMapping"
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
;
42 //=========================================================================
43 //= OAddressBookSourceDialogUno
44 //=========================================================================
45 typedef OGenericUnoDialog OAddressBookSourceDialogUnoBase
;
46 class OAddressBookSourceDialogUno
47 :public OAddressBookSourceDialogUnoBase
48 ,public ::comphelper::OPropertyArrayUsageHelper
< OAddressBookSourceDialogUno
>
51 Sequence
< AliasProgrammaticPair
> m_aAliases
;
52 Reference
< XDataSource
> m_xDataSource
;
53 OUString m_sDataSourceName
;
57 OAddressBookSourceDialogUno(const Reference
< XComponentContext
>& _rxORB
);
61 virtual Sequence
<sal_Int8
> SAL_CALL
getImplementationId( ) throw(RuntimeException
);
64 virtual OUString SAL_CALL
getImplementationName() throw(RuntimeException
);
65 virtual ::comphelper::StringSequence SAL_CALL
getSupportedServiceNames() throw(RuntimeException
);
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
>&);
74 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw(RuntimeException
);
75 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
77 // OPropertyArrayUsageHelper
78 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
80 virtual void SAL_CALL
initialize(const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
);
83 // OGenericUnoDialog overridables
84 virtual Dialog
* createDialog(Window
* _pParent
);
86 virtual void implInitialize(const com::sun::star::uno::Any
& _rValue
);
88 virtual void executedDialog(sal_Int16 _nExecutionResult
);
92 //=========================================================================
93 //= OAddressBookSourceDialogUno
94 //=========================================================================
95 Reference
< XInterface
> SAL_CALL
OAddressBookSourceDialogUno_CreateInstance( const Reference
< XMultiServiceFactory
>& _rxFactory
)
97 return OAddressBookSourceDialogUno::Create(_rxFactory
);
100 //-------------------------------------------------------------------------
101 OAddressBookSourceDialogUno::OAddressBookSourceDialogUno(const Reference
< XComponentContext
>& _rxORB
)
102 :OGenericUnoDialog(_rxORB
)
104 registerProperty(OUString(UNODIALOG_PROPERTY_ALIASES
), UNODIALOG_PROPERTY_ID_ALIASES
, PropertyAttribute::READONLY
,
105 &m_aAliases
, getCppuType(&m_aAliases
));
108 //-------------------------------------------------------------------------
109 Sequence
<sal_Int8
> SAL_CALL
OAddressBookSourceDialogUno::getImplementationId( ) throw(RuntimeException
)
111 static ::cppu::OImplementationId aId
;
112 return aId
.getImplementationId();
115 //-------------------------------------------------------------------------
116 Reference
< XInterface
> SAL_CALL
OAddressBookSourceDialogUno::Create(const Reference
< XMultiServiceFactory
>& _rxFactory
)
118 return *(new OAddressBookSourceDialogUno( comphelper::getComponentContext(_rxFactory
)));
121 //-------------------------------------------------------------------------
122 OUString SAL_CALL
OAddressBookSourceDialogUno::getImplementationName() throw(RuntimeException
)
124 return getImplementationName_Static();
127 //-------------------------------------------------------------------------
128 OUString
OAddressBookSourceDialogUno::getImplementationName_Static() throw(RuntimeException
)
130 return OUString( "com.sun.star.comp.svtools.OAddressBookSourceDialogUno" );
133 //-------------------------------------------------------------------------
134 ::comphelper::StringSequence SAL_CALL
OAddressBookSourceDialogUno::getSupportedServiceNames() throw(RuntimeException
)
136 return getSupportedServiceNames_Static();
139 //-------------------------------------------------------------------------
140 ::comphelper::StringSequence
OAddressBookSourceDialogUno::getSupportedServiceNames_Static() throw(RuntimeException
)
142 ::comphelper::StringSequence
aSupported(1);
143 aSupported
.getArray()[0] = "com.sun.star.ui.AddressBookSourceDialog";
147 //-------------------------------------------------------------------------
148 Reference
<XPropertySetInfo
> SAL_CALL
OAddressBookSourceDialogUno::getPropertySetInfo() throw(RuntimeException
)
150 Reference
<XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
154 //-------------------------------------------------------------------------
155 ::cppu::IPropertyArrayHelper
& OAddressBookSourceDialogUno::getInfoHelper()
157 return *getArrayHelper();
160 //------------------------------------------------------------------------------
161 ::cppu::IPropertyArrayHelper
* OAddressBookSourceDialogUno::createArrayHelper( ) const
163 Sequence
< Property
> aProps
;
164 describeProperties(aProps
);
165 return new ::cppu::OPropertyArrayHelper(aProps
);
168 //------------------------------------------------------------------------------
169 void OAddressBookSourceDialogUno::executedDialog(sal_Int16 _nExecutionResult
)
171 OAddressBookSourceDialogUnoBase::executedDialog(_nExecutionResult
);
173 if ( _nExecutionResult
)
175 static_cast< AddressBookSourceDialog
* >( m_pDialog
)->getFieldMapping( m_aAliases
);
177 //------------------------------------------------------------------------------
178 void SAL_CALL
OAddressBookSourceDialogUno::initialize(const Sequence
< Any
>& rArguments
) throw(Exception
, RuntimeException
)
180 if( rArguments
.getLength() == 5 )
182 Reference
<com::sun::star::awt::XWindow
> xParentWindow
;
183 Reference
<com::sun::star::beans::XPropertySet
> xDataSource
;
184 OUString sDataSourceName
;
187 if ( (rArguments
[0] >>= xParentWindow
)
188 && (rArguments
[1] >>= xDataSource
)
189 && (rArguments
[2] >>= sDataSourceName
)
190 && (rArguments
[3] >>= sCommand
)
191 && (rArguments
[4] >>= sTitle
) )
194 // convert the parameters for creating the dialog to PropertyValues
195 Sequence
< Any
> aArguments(5);
196 Any
* pArguments
= aArguments
.getArray();
198 *pArguments
++ <<= PropertyValue(OUString( "ParentWindow" ), -1, makeAny( xParentWindow
), PropertyState_DIRECT_VALUE
);
199 // the data source to use
200 *pArguments
++ <<= PropertyValue(OUString( "DataSource" ), -1, makeAny( xDataSource
), PropertyState_DIRECT_VALUE
);
201 *pArguments
++ <<= PropertyValue(OUString( "DataSourceName" ), -1, makeAny( sDataSourceName
), PropertyState_DIRECT_VALUE
);
203 *pArguments
++ <<= PropertyValue(OUString( "Command" ), -1, makeAny( sCommand
), PropertyState_DIRECT_VALUE
);
205 *pArguments
++ <<= PropertyValue(OUString( "Title" ), -1, makeAny( sTitle
), PropertyState_DIRECT_VALUE
);
206 OGenericUnoDialog::initialize(aArguments
);
210 OGenericUnoDialog::initialize(rArguments
);
212 //------------------------------------------------------------------------------
213 void OAddressBookSourceDialogUno::implInitialize(const com::sun::star::uno::Any
& _rValue
)
216 if (_rValue
>>= aVal
)
218 if (aVal
.Name
.equalsAscii("DataSource"))
220 #if OSL_DEBUG_LEVEL > 0
223 aVal
.Value
>>= m_xDataSource
;
224 OSL_ENSURE( bSuccess
, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSource!" );
228 if (aVal
.Name
.equalsAscii("DataSourceName"))
230 #if OSL_DEBUG_LEVEL > 0
233 aVal
.Value
>>= m_sDataSourceName
;
234 OSL_ENSURE( bSuccess
, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSourceName!" );
238 if (aVal
.Name
.equalsAscii("Command"))
240 #if OSL_DEBUG_LEVEL > 0
243 aVal
.Value
>>= m_sTable
;
244 OSL_ENSURE( bSuccess
, "OAddressBookSourceDialogUno::implInitialize: invalid type for Command!" );
249 OAddressBookSourceDialogUnoBase::implInitialize( _rValue
);
252 //------------------------------------------------------------------------------
253 Dialog
* OAddressBookSourceDialogUno::createDialog(Window
* _pParent
)
255 if ( m_xDataSource
.is() && !m_sTable
.isEmpty() )
256 return new AddressBookSourceDialog(_pParent
, m_aContext
, m_xDataSource
, m_sDataSourceName
, m_sTable
, m_aAliases
);
258 return new AddressBookSourceDialog( _pParent
, m_aContext
);
261 // .......................................................................
263 // .......................................................................
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */