1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
22 
23 #include <vcl/weld.hxx>
24 
25 #include <com/sun/star/form/XForm.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/sdbc/XConnection.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 
31 #include <memory>
32 
33 
34 namespace pcr
35 {
36     class FieldLinkRow;
37 
38     //= FormLinkDialog
39 
40     class FormLinkDialog : public weld::GenericDialogController
41     {
42     private:
43         css::uno::Reference< css::uno::XComponentContext >
44                                         m_xContext;
45         css::uno::Reference< css::beans::XPropertySet >
46                                         m_xDetailForm;
47         css::uno::Reference< css::beans::XPropertySet >
48                                         m_xMasterForm;
49 
50         std::vector< OUString >         m_aRelationDetailColumns;
51         std::vector< OUString >         m_aRelationMasterColumns;
52 
53         OUString                 m_sDetailLabel;
54         OUString                 m_sMasterLabel;
55 
56         std::unique_ptr<weld::Label> m_xExplanation;
57         std::unique_ptr<weld::Label> m_xDetailLabel;
58         std::unique_ptr<weld::Label> m_xMasterLabel;
59         std::unique_ptr<FieldLinkRow> m_xRow1;
60         std::unique_ptr<FieldLinkRow> m_xRow2;
61         std::unique_ptr<FieldLinkRow> m_xRow3;
62         std::unique_ptr<FieldLinkRow> m_xRow4;
63         std::unique_ptr<weld::Button> m_xOK;
64         std::unique_ptr<weld::Button> m_xSuggest;
65 
66     public:
67         FormLinkDialog(
68             weld::Window* _pParent,
69             const css::uno::Reference< css::beans::XPropertySet >& _rxDetailForm,
70             const css::uno::Reference< css::beans::XPropertySet >& _rxMasterForm,
71             const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
72             const OUString& _sExplanation = OUString(),
73             const OUString& _sDetailLabel = OUString(),
74             const OUString& _sMasterLabel = OUString()
75         );
76 
77         virtual ~FormLinkDialog() override;
78 
79         // Dialog overridables
80         virtual short run() override;
81 
82     private:
83         DECL_LINK( OnSuggest,    weld::Button&, void );
84         DECL_LINK( OnFieldChanged, FieldLinkRow&, void );
85         DECL_LINK( OnInitialize, void*, void);
86 
87         void        updateOkButton();
88         void        initializeFieldLists();
89         void        initializeColumnLabels();
90         void        initializeLinks();
91         void        initializeSuggest();
92         void        commitLinkPairs();
93 
94         void        initializeFieldRowsFrom(
95                         std::vector< OUString >& _rDetailFields,
96                         std::vector< OUString >& _rMasterFields
97                     );
98 
99         static OUString getFormDataSourceType(
100                         const css::uno::Reference< css::beans::XPropertySet >& _rxForm
101                     );
102 
103         void        getFormFields(
104                         const css::uno::Reference< css::beans::XPropertySet >& _rxForm,
105                             css::uno::Sequence< OUString >& /* [out] */ _rNames
106                     ) const;
107 
108         void        ensureFormConnection(
109                         const css::uno::Reference< css::beans::XPropertySet >& _rxFormProps,
110                             css::uno::Reference< css::sdbc::XConnection >& /* [out] */ _rxConnection
111                     ) const;
112 
113         static void getConnectionMetaData(
114                         const css::uno::Reference< css::beans::XPropertySet >& _rxFormProps,
115                             css::uno::Reference< css::sdbc::XDatabaseMetaData >& /* [out] */ _rxMeta
116                     );
117 
118         css::uno::Reference< css::beans::XPropertySet >
119                     getCanonicUnderlyingTable( const css::uno::Reference< css::beans::XPropertySet >& _rxFormProps ) const;
120         static bool getExistingRelation(
121                         const css::uno::Reference< css::beans::XPropertySet >& _rxLHS,
122                         const css::uno::Reference< css::beans::XPropertySet >& _rxRHS,
123                         std::vector< OUString >& /* [out] */ _rLeftFields,
124                         std::vector< OUString >& /* [out] */ _rRightFields
125                     );
126     };
127 
128 }   // namespace pcr
129 
130 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
131 
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
133