1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svtools.hxx" 30 #include "svtools/genericunodialog.hxx" 31 #include <svtools/addresstemplate.hxx> 32 #include <comphelper/extract.hxx> 33 #include <cppuhelper/typeprovider.hxx> 34 #include <comphelper/property.hxx> 35 #include <com/sun/star/sdbc/XDataSource.hpp> 36 37 class SfxItemSet; 38 class SfxItemPool; 39 class SfxPoolItem; 40 41 // ....................................................................... 42 namespace svt 43 { 44 // ....................................................................... 45 46 #define UNODIALOG_PROPERTY_ID_ALIASES 100 47 #define UNODIALOG_PROPERTY_ALIASES "FieldMapping" 48 49 using namespace com::sun::star::uno; 50 using namespace com::sun::star::lang; 51 using namespace com::sun::star::util; 52 using namespace com::sun::star::beans; 53 using namespace com::sun::star::sdbc; 54 55 //========================================================================= 56 //= OAddressBookSourceDialogUno 57 //========================================================================= 58 typedef OGenericUnoDialog OAddressBookSourceDialogUnoBase; 59 class OAddressBookSourceDialogUno 60 :public OAddressBookSourceDialogUnoBase 61 ,public ::comphelper::OPropertyArrayUsageHelper< OAddressBookSourceDialogUno > 62 { 63 protected: 64 Sequence< AliasProgrammaticPair > m_aAliases; 65 Reference< XDataSource > m_xDataSource; 66 ::rtl::OUString m_sDataSourceName; 67 ::rtl::OUString m_sTable; 68 69 protected: 70 OAddressBookSourceDialogUno(const Reference< XMultiServiceFactory >& _rxORB); 71 72 public: 73 // XTypeProvider 74 virtual Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(RuntimeException); 75 76 // XServiceInfo 77 virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException); 78 virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(RuntimeException); 79 80 // XServiceInfo - static methods 81 static Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( RuntimeException ); 82 static ::rtl::OUString getImplementationName_Static(void) throw( RuntimeException ); 83 static Reference< XInterface > 84 SAL_CALL Create(const Reference< com::sun::star::lang::XMultiServiceFactory >&); 85 86 // XPropertySet 87 virtual Reference< XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(RuntimeException); 88 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 89 90 // OPropertyArrayUsageHelper 91 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 92 93 protected: 94 // OGenericUnoDialog overridables 95 virtual Dialog* createDialog(Window* _pParent); 96 97 virtual void implInitialize(const com::sun::star::uno::Any& _rValue); 98 99 virtual void executedDialog(sal_Int16 _nExecutionResult); 100 }; 101 102 103 //========================================================================= 104 //= OAddressBookSourceDialogUno 105 //========================================================================= 106 Reference< XInterface > SAL_CALL OAddressBookSourceDialogUno_CreateInstance( const Reference< XMultiServiceFactory >& _rxFactory) 107 { 108 return OAddressBookSourceDialogUno::Create(_rxFactory); 109 } 110 111 //------------------------------------------------------------------------- 112 OAddressBookSourceDialogUno::OAddressBookSourceDialogUno(const Reference< XMultiServiceFactory >& _rxORB) 113 :OGenericUnoDialog(_rxORB) 114 { 115 registerProperty(::rtl::OUString::createFromAscii(UNODIALOG_PROPERTY_ALIASES), UNODIALOG_PROPERTY_ID_ALIASES, PropertyAttribute::READONLY, 116 &m_aAliases, getCppuType(&m_aAliases)); 117 } 118 119 //------------------------------------------------------------------------- 120 Sequence<sal_Int8> SAL_CALL OAddressBookSourceDialogUno::getImplementationId( ) throw(RuntimeException) 121 { 122 static ::cppu::OImplementationId aId; 123 return aId.getImplementationId(); 124 } 125 126 //------------------------------------------------------------------------- 127 Reference< XInterface > SAL_CALL OAddressBookSourceDialogUno::Create(const Reference< XMultiServiceFactory >& _rxFactory) 128 { 129 return *(new OAddressBookSourceDialogUno(_rxFactory)); 130 } 131 132 //------------------------------------------------------------------------- 133 ::rtl::OUString SAL_CALL OAddressBookSourceDialogUno::getImplementationName() throw(RuntimeException) 134 { 135 return getImplementationName_Static(); 136 } 137 138 //------------------------------------------------------------------------- 139 ::rtl::OUString OAddressBookSourceDialogUno::getImplementationName_Static() throw(RuntimeException) 140 { 141 return ::rtl::OUString::createFromAscii("com.sun.star.comp.svtools.OAddressBookSourceDialogUno"); 142 } 143 144 //------------------------------------------------------------------------- 145 ::comphelper::StringSequence SAL_CALL OAddressBookSourceDialogUno::getSupportedServiceNames() throw(RuntimeException) 146 { 147 return getSupportedServiceNames_Static(); 148 } 149 150 //------------------------------------------------------------------------- 151 ::comphelper::StringSequence OAddressBookSourceDialogUno::getSupportedServiceNames_Static() throw(RuntimeException) 152 { 153 ::comphelper::StringSequence aSupported(1); 154 aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.ui.AddressBookSourceDialog"); 155 return aSupported; 156 } 157 158 //------------------------------------------------------------------------- 159 Reference<XPropertySetInfo> SAL_CALL OAddressBookSourceDialogUno::getPropertySetInfo() throw(RuntimeException) 160 { 161 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) ); 162 return xInfo; 163 } 164 165 //------------------------------------------------------------------------- 166 ::cppu::IPropertyArrayHelper& OAddressBookSourceDialogUno::getInfoHelper() 167 { 168 return *const_cast<OAddressBookSourceDialogUno*>(this)->getArrayHelper(); 169 } 170 171 //------------------------------------------------------------------------------ 172 ::cppu::IPropertyArrayHelper* OAddressBookSourceDialogUno::createArrayHelper( ) const 173 { 174 Sequence< Property > aProps; 175 describeProperties(aProps); 176 return new ::cppu::OPropertyArrayHelper(aProps); 177 } 178 179 //------------------------------------------------------------------------------ 180 void OAddressBookSourceDialogUno::executedDialog(sal_Int16 _nExecutionResult) 181 { 182 OAddressBookSourceDialogUnoBase::executedDialog(_nExecutionResult); 183 184 if ( _nExecutionResult ) 185 if ( m_pDialog ) 186 static_cast< AddressBookSourceDialog* >( m_pDialog )->getFieldMapping( m_aAliases ); 187 } 188 189 //------------------------------------------------------------------------------ 190 void OAddressBookSourceDialogUno::implInitialize(const com::sun::star::uno::Any& _rValue) 191 { 192 PropertyValue aVal; 193 if (_rValue >>= aVal) 194 { 195 if (0 == aVal.Name.compareToAscii("DataSource")) 196 { 197 #if OSL_DEBUG_LEVEL > 0 198 sal_Bool bSuccess = 199 #endif 200 aVal.Value >>= m_xDataSource; 201 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSource!" ); 202 return; 203 } 204 205 if (0 == aVal.Name.compareToAscii("DataSourceName")) 206 { 207 #if OSL_DEBUG_LEVEL > 0 208 sal_Bool bSuccess = 209 #endif 210 aVal.Value >>= m_sDataSourceName; 211 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSourceName!" ); 212 return; 213 } 214 215 if (0 == aVal.Name.compareToAscii("Command")) 216 { 217 #if OSL_DEBUG_LEVEL > 0 218 sal_Bool bSuccess = 219 #endif 220 aVal.Value >>= m_sTable; 221 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for Command!" ); 222 return; 223 } 224 } 225 226 OAddressBookSourceDialogUnoBase::implInitialize( _rValue ); 227 } 228 229 //------------------------------------------------------------------------------ 230 Dialog* OAddressBookSourceDialogUno::createDialog(Window* _pParent) 231 { 232 if ( m_xDataSource.is() && m_sTable.getLength() ) 233 return new AddressBookSourceDialog(_pParent, m_aContext.getLegacyServiceFactory(), m_xDataSource, m_sDataSourceName, m_sTable, m_aAliases ); 234 else 235 return new AddressBookSourceDialog( _pParent, m_aContext.getLegacyServiceFactory() ); 236 } 237 238 // ....................................................................... 239 } // namespace svt 240 // ....................................................................... 241 242