1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
25 #define EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
26 
27 #include <vcl/dialog.hxx>
28 #include <vcl/fixed.hxx>
29 #ifndef _SV_BUTTON_HXX
30 #include <vcl/button.hxx>
31 #endif
32 
33 /** === begin UNO includes === **/
34 #include <com/sun/star/form/XForm.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/sdbc/XConnection.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 /** === end UNO includes === **/
39 
40 #include <memory>
41 
42 //............................................................................
43 namespace pcr
44 {
45 //............................................................................
46 
47     class FieldLinkRow;
48     //========================================================================
49     //= FormLinkDialog
50     //========================================================================
51     class FormLinkDialog : public ModalDialog
52     {
53     private:
54         FixedText                       m_aExplanation;
55         FixedText                       m_aDetailLabel;
56         FixedText                       m_aMasterLabel;
57         ::std::auto_ptr< FieldLinkRow > m_aRow1;
58         ::std::auto_ptr< FieldLinkRow > m_aRow2;
59         ::std::auto_ptr< FieldLinkRow > m_aRow3;
60         ::std::auto_ptr< FieldLinkRow > m_aRow4;
61         OKButton                        m_aOK;
62         CancelButton                    m_aCancel;
63         HelpButton                      m_aHelp;
64         PushButton                      m_aSuggest;
65 
66         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
67                                         m_xORB;
68         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
69                                         m_xDetailForm;
70         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
71                                         m_xMasterForm;
72 
73         ::com::sun::star::uno::Sequence< ::rtl::OUString >
74                                         m_aRelationDetailColumns;
75         ::com::sun::star::uno::Sequence< ::rtl::OUString >
76                                         m_aRelationMasterColumns;
77 
78         ::rtl::OUString                 m_sDetailLabel;
79         ::rtl::OUString                 m_sMasterLabel;
80 
81     public:
82         FormLinkDialog(
83             Window* _pParent,
84             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDetailForm,
85             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxMasterForm,
86             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
87             const ::rtl::OUString& _sExplanation = ::rtl::OUString(),
88             const ::rtl::OUString& _sDetailLabel = ::rtl::OUString(),
89             const ::rtl::OUString& _sMasterLabel = ::rtl::OUString()
90         );
91         ~FormLinkDialog( );
92 
93         // Dialog overridables
94         virtual short   Execute();
95 
96     private:
97         DECL_LINK( OnSuggest,          void*         );
98         DECL_LINK( OnFieldChanged,     FieldLinkRow* );
99         DECL_LINK( OnInitialize, void*         );
100 
101         void        updateOkButton();
102         void        initializeFieldLists();
103         void        initializeColumnLabels();
104         void        initializeLinks();
105         void        initializeSuggest();
106         void        commitLinkPairs();
107 
108         void        initializeFieldRowsFrom(
109                         ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rDetailFields,
110                         ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rMasterFields
111                     );
112 
113         String      getFormDataSourceType(
114                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm
115                     ) const SAL_THROW(());
116 
117         void        getFormFields(
118                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm,
119                             ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rNames
120                     ) const SAL_THROW(());
121 
122         void        ensureFormConnection(
123                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps,
124                             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& /* [out] */ _rxConnection
125                     ) const SAL_THROW(( ::com::sun::star::uno::Exception ));
126 
127         void        getConnectionMetaData(
128                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps,
129                             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& /* [out] */ _rxMeta
130                     ) const SAL_THROW(( ::com::sun::star::uno::Exception ));
131 
132         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
133                     getCanonicUnderlyingTable( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps ) const;
134         sal_Bool    getExistingRelation(
135                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxLHS,
136                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxRHS,
137                         ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rLeftFields,
138                         ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rRightFields
139                     ) const;
140     };
141 
142 //............................................................................
143 }   // namespace pcr
144 //............................................................................
145 
146 #endif // EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
147