Update ooo320-m1
[ooovba.git] / dbaccess / source / ext / macromigration / macromigrationwizard.cxx
blob77643b8c16ffc7b36d1c74f7bef402675364f670
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: macromigrationwizard.cxx,v $
10 * $Revision: 1.3.2.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "dbmm_module.hxx"
35 #include "macromigrationdialog.hxx"
37 /** === begin UNO includes === **/
38 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
39 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
40 #include <com/sun/star/frame/XStorable.hpp>
41 /** === end UNO includes === **/
43 #include <comphelper/componentcontext.hxx>
44 #include <svtools/genericunodialog.hxx>
46 //........................................................................
47 namespace dbmm
49 //........................................................................
51 /** === begin UNO using === **/
52 using ::com::sun::star::uno::Reference;
53 using ::com::sun::star::uno::XInterface;
54 using ::com::sun::star::uno::UNO_QUERY;
55 using ::com::sun::star::uno::UNO_QUERY_THROW;
56 using ::com::sun::star::uno::UNO_SET_THROW;
57 using ::com::sun::star::uno::Exception;
58 using ::com::sun::star::uno::RuntimeException;
59 using ::com::sun::star::uno::Any;
60 using ::com::sun::star::uno::makeAny;
61 using ::com::sun::star::uno::XComponentContext;
62 using ::com::sun::star::uno::Sequence;
63 using ::com::sun::star::beans::XPropertySetInfo;
64 using ::com::sun::star::beans::Property;
65 using ::com::sun::star::ucb::AlreadyInitializedException;
66 using ::com::sun::star::sdb::XOfficeDatabaseDocument;
67 using ::com::sun::star::lang::IllegalArgumentException;
68 using ::com::sun::star::frame::XStorable;
69 /** === end UNO using === **/
71 //====================================================================
72 //= MacroMigrationDialogService
73 //====================================================================
74 class MacroMigrationDialogService;
75 typedef ::svt::OGenericUnoDialog MacroMigrationDialogService_Base;
76 typedef ::comphelper::OPropertyArrayUsageHelper< MacroMigrationDialogService > MacroMigrationDialogService_PBase;
78 class MacroMigrationDialogService
79 :public MacroMigrationDialogService_Base
80 ,public MacroMigrationDialogService_PBase
81 ,public MacroMigrationModuleClient
83 public:
84 MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext );
86 // XTypeProvider
87 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException);
89 // XServiceInfo
90 virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
91 virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
93 // XInitialization
94 virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments ) throw(com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
96 // XPropertySet
97 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw(RuntimeException);
98 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
100 // OPropertyArrayUsageHelper
101 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
103 // helper for factories
104 static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& _rxContext );
105 static ::rtl::OUString SAL_CALL getImplementationName_static() throw(RuntimeException);
106 static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static() throw(RuntimeException);
108 protected:
109 ~MacroMigrationDialogService();
111 protected:
112 virtual Dialog* createDialog( Window* _pParent );
113 virtual void destroyDialog();
115 private:
116 ::comphelper::ComponentContext m_aContext;
117 Reference< XOfficeDatabaseDocument > m_xDocument;
120 //====================================================================
121 //= MacroMigrationDialogService
122 //====================================================================
123 //--------------------------------------------------------------------
124 MacroMigrationDialogService::MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext )
125 :MacroMigrationDialogService_Base( _rxContext )
126 ,m_aContext( _rxContext )
128 m_bNeedInitialization = true;
131 //--------------------------------------------------------------------
132 MacroMigrationDialogService::~MacroMigrationDialogService()
134 // we do this here cause the base class' call to destroyDialog won't reach us anymore : we're within an dtor,
135 // so this virtual-method-call the base class does does not work, we're already dead then ...
136 if ( m_pDialog )
138 ::osl::MutexGuard aGuard( m_aMutex );
139 if ( m_pDialog )
140 destroyDialog();
144 //--------------------------------------------------------------------
145 Reference< XInterface > SAL_CALL MacroMigrationDialogService::Create( const Reference< XComponentContext >& _rxContext )
147 return *(new MacroMigrationDialogService( _rxContext ) );
150 //--------------------------------------------------------------------
151 Dialog* MacroMigrationDialogService::createDialog( Window* _pParent )
153 return new MacroMigrationDialog( _pParent, m_aContext, m_xDocument );
156 //--------------------------------------------------------------------
157 void MacroMigrationDialogService::destroyDialog()
159 MacroMigrationDialogService_Base::destroyDialog();
162 //--------------------------------------------------------------------
163 Sequence< sal_Int8 > SAL_CALL MacroMigrationDialogService::getImplementationId() throw(RuntimeException)
165 static ::cppu::OImplementationId* pId = NULL;
166 if ( !pId )
168 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
169 if ( !pId )
171 static ::cppu::OImplementationId aId;
172 pId = &aId;
175 return pId->getImplementationId();
178 //--------------------------------------------------------------------
179 ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName_static() throw(RuntimeException)
181 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dbaccess.macromigration.MacroMigrationDialogService" ) );
184 //--------------------------------------------------------------------
185 Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames_static() throw(RuntimeException)
187 Sequence< ::rtl::OUString > aServices(1);
188 aServices[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.application.MacroMigrationWizard" ) );
189 return aServices;
192 //--------------------------------------------------------------------
193 ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName() throw(RuntimeException)
195 return getImplementationName_static();
198 //--------------------------------------------------------------------
199 Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames() throw(RuntimeException)
201 return getSupportedServiceNames_static();
204 //--------------------------------------------------------------------
205 void SAL_CALL MacroMigrationDialogService::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException)
207 ::osl::MutexGuard aGuard( m_aMutex );
208 if ( m_bInitialized )
209 throw AlreadyInitializedException( ::rtl::OUString(), *this );
211 if ( _rArguments.getLength() != 1 )
212 throw IllegalArgumentException(
213 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid number of initialization arguments. Expected 1." ) ),
214 // TODO: resource
215 *this,
219 m_xDocument.set( _rArguments[0], UNO_QUERY );
220 if ( !m_xDocument.is() )
221 throw IllegalArgumentException(
222 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No database document found in the initializatin arguments." ) ),
223 // TODO: resource
224 *this,
228 Reference< XStorable > xDocStor( m_xDocument, UNO_QUERY_THROW );
229 if ( xDocStor->isReadonly() )
230 throw IllegalArgumentException(
231 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Not applicable to read-only documents." ) ),
232 // TODO: resource
233 *this,
237 m_bInitialized = true;
240 //--------------------------------------------------------------------
241 Reference< XPropertySetInfo > SAL_CALL MacroMigrationDialogService::getPropertySetInfo() throw(RuntimeException)
243 return createPropertySetInfo( getInfoHelper() );
246 //--------------------------------------------------------------------
247 ::cppu::IPropertyArrayHelper& SAL_CALL MacroMigrationDialogService::getInfoHelper()
249 return *const_cast< MacroMigrationDialogService* >( this )->getArrayHelper();
252 //--------------------------------------------------------------------
253 ::cppu::IPropertyArrayHelper* MacroMigrationDialogService::createArrayHelper( ) const
255 Sequence< Property > aProps;
256 describeProperties( aProps );
257 return new ::cppu::OPropertyArrayHelper( aProps );
260 //--------------------------------------------------------------------
261 void createRegistryInfo_MacroMigrationDialogService()
263 static OAutoRegistration< MacroMigrationDialogService > aAutoRegistration;
266 //........................................................................
267 } // namespace dbmm
268 //........................................................................