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 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
29 #define EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
30 
31 #include <vcl/dialog.hxx>
32 #include <vcl/fixed.hxx>
33 #ifndef _SV_BUTTON_HXX
34 #include <vcl/button.hxx>
35 #endif
36 
37 /** === begin UNO includes === **/
38 #include <com/sun/star/form/XForm.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/sdbc/XConnection.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 /** === end UNO includes === **/
43 
44 #include <memory>
45 
46 //............................................................................
47 namespace pcr
48 {
49 //............................................................................
50 
51     class FieldLinkRow;
52     //========================================================================
53     //= FormLinkDialog
54     //========================================================================
55     class FormLinkDialog : public ModalDialog
56     {
57     private:
58         FixedText                       m_aExplanation;
59         FixedText                       m_aDetailLabel;
60         FixedText                       m_aMasterLabel;
61         ::std::auto_ptr< FieldLinkRow > m_aRow1;
62         ::std::auto_ptr< FieldLinkRow > m_aRow2;
63         ::std::auto_ptr< FieldLinkRow > m_aRow3;
64         ::std::auto_ptr< FieldLinkRow > m_aRow4;
65         OKButton                        m_aOK;
66         CancelButton                    m_aCancel;
67         HelpButton                      m_aHelp;
68         PushButton                      m_aSuggest;
69 
70         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
71                                         m_xORB;
72         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
73                                         m_xDetailForm;
74         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
75                                         m_xMasterForm;
76 
77         ::com::sun::star::uno::Sequence< ::rtl::OUString >
78                                         m_aRelationDetailColumns;
79         ::com::sun::star::uno::Sequence< ::rtl::OUString >
80                                         m_aRelationMasterColumns;
81 
82         ::rtl::OUString                 m_sDetailLabel;
83         ::rtl::OUString                 m_sMasterLabel;
84 
85     public:
86         FormLinkDialog(
87             Window* _pParent,
88             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDetailForm,
89             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxMasterForm,
90             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
91             const ::rtl::OUString& _sExplanation = ::rtl::OUString(),
92             const ::rtl::OUString& _sDetailLabel = ::rtl::OUString(),
93             const ::rtl::OUString& _sMasterLabel = ::rtl::OUString()
94         );
95         ~FormLinkDialog( );
96 
97         // Dialog overridables
98         virtual short   Execute();
99 
100     private:
101         DECL_LINK( OnSuggest,          void*         );
102         DECL_LINK( OnFieldChanged,     FieldLinkRow* );
103         DECL_LINK( OnInitialize, void*         );
104 
105         void        updateOkButton();
106         void        initializeFieldLists();
107         void        initializeColumnLabels();
108         void        initializeLinks();
109         void        initializeSuggest();
110         void        commitLinkPairs();
111 
112         void        initializeFieldRowsFrom(
113                         ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rDetailFields,
114                         ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rMasterFields
115                     );
116 
117         String      getFormDataSourceType(
118                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm
119                     ) const SAL_THROW(());
120 
121         void        getFormFields(
122                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm,
123                             ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rNames
124                     ) const SAL_THROW(());
125 
126         void        ensureFormConnection(
127                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps,
128                             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& /* [out] */ _rxConnection
129                     ) const SAL_THROW(( ::com::sun::star::uno::Exception ));
130 
131         void        getConnectionMetaData(
132                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps,
133                             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& /* [out] */ _rxMeta
134                     ) const SAL_THROW(( ::com::sun::star::uno::Exception ));
135 
136         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
137                     getCanonicUnderlyingTable( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps ) const;
138         sal_Bool    getExistingRelation(
139                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxLHS,
140                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxRHS,
141                         ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rLeftFields,
142                         ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rRightFields
143                     ) const;
144     };
145 
146 //............................................................................
147 }   // namespace pcr
148 //............................................................................
149 
150 #endif // EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
151