LibreOffice Module dbaccess (master) 1
RelationDlg.cxx
Go to the documentation of this file.
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#include <RelationDlg.hxx>
21
22#include <com/sun/star/sdbc/KeyRule.hpp>
23#include <com/sun/star/sdbc/SQLException.hpp>
24
26#include <JoinDesignView.hxx>
27#include <JoinController.hxx>
31#include <RelationControl.hxx>
33
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::sdbc;
36using namespace ::com::sun::star::container;
37using namespace ::com::sun::star::beans;
38using namespace ::dbaui;
39using namespace ::dbtools;
40
41ORelationDialog::ORelationDialog( OJoinTableView* pParent,
42 const TTableConnectionData::value_type& pConnectionData,
43 bool bAllowTableSelect )
44 : GenericDialogController(pParent->GetFrameWeld(),
45 "dbaccess/ui/relationdialog.ui", "RelationDialog")
46 , m_pParent(pParent)
47 , m_pOrigConnData(pConnectionData)
48 , m_bTriedOneUpdate(false)
49 , m_xRB_NoCascUpd(m_xBuilder->weld_radio_button("addaction"))
50 , m_xRB_CascUpd(m_xBuilder->weld_radio_button("addcascade"))
51 , m_xRB_CascUpdNull(m_xBuilder->weld_radio_button("addnull"))
52 , m_xRB_CascUpdDefault(m_xBuilder->weld_radio_button("adddefault"))
53 , m_xRB_NoCascDel(m_xBuilder->weld_radio_button("delaction"))
54 , m_xRB_CascDel(m_xBuilder->weld_radio_button("delcascade"))
55 , m_xRB_CascDelNull(m_xBuilder->weld_radio_button("delnull"))
56 , m_xRB_CascDelDefault(m_xBuilder->weld_radio_button("deldefault"))
57 , m_xPB_OK(m_xBuilder->weld_button("ok"))
58{
59 // Copy connection
60 m_pConnData = pConnectionData->NewInstance();
61 m_pConnData->CopyFrom( *pConnectionData );
62
64 m_xTableControl.reset(new OTableListBoxControl(m_xBuilder.get(), &pParent->GetTabWinMap(), this));
65
66 m_xPB_OK->connect_clicked(LINK(this, ORelationDialog, OKClickHdl));
67
69 if ( bAllowTableSelect )
70 m_xTableControl->fillListBoxes();
71 else
72 m_xTableControl->fillAndDisable(pConnectionData);
73
74 m_xTableControl->lateInit();
75
76 m_xTableControl->NotifyCellChange();
77}
78
80{
81}
82
83void ORelationDialog::Init(const TTableConnectionData::value_type& _pConnectionData)
84{
85 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(_pConnectionData.get());
86 // Update Rules
87 switch (pConnData->GetUpdateRules())
88 {
89 case KeyRule::NO_ACTION:
90 case KeyRule::RESTRICT:
91 m_xRB_NoCascUpd->set_active(true);
92 break;
93
94 case KeyRule::CASCADE:
95 m_xRB_CascUpd->set_active(true);
96 break;
97
98 case KeyRule::SET_NULL:
99 m_xRB_CascUpdNull->set_active(true);
100 break;
101 case KeyRule::SET_DEFAULT:
102 m_xRB_CascUpdDefault->set_active(true);
103 break;
104 }
105
106 // Delete Rules
107 switch (pConnData->GetDeleteRules())
108 {
109 case KeyRule::NO_ACTION:
110 case KeyRule::RESTRICT:
111 m_xRB_NoCascDel->set_active(true);
112 break;
113
114 case KeyRule::CASCADE:
115 m_xRB_CascDel->set_active(true);
116 break;
117
118 case KeyRule::SET_NULL:
119 m_xRB_CascDelNull->set_active(true);
120 break;
121 case KeyRule::SET_DEFAULT:
122 m_xRB_CascDelDefault->set_active(true);
123 break;
124 }
125}
126
127IMPL_LINK_NOARG(ORelationDialog, OKClickHdl, weld::Button&, void)
128{
129 // Read out RadioButtons
130 sal_uInt16 nAttrib = 0;
131
132 // Delete Rules
133 if( m_xRB_NoCascDel->get_active() )
134 nAttrib |= KeyRule::NO_ACTION;
135 if( m_xRB_CascDel->get_active() )
136 nAttrib |= KeyRule::CASCADE;
137 if( m_xRB_CascDelNull->get_active() )
138 nAttrib |= KeyRule::SET_NULL;
139 if( m_xRB_CascDelDefault->get_active() )
140 nAttrib |= KeyRule::SET_DEFAULT;
141
142 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(m_pConnData.get());
143 pConnData->SetDeleteRules( nAttrib );
144
145 // Update Rules
146 nAttrib = 0;
147 if( m_xRB_NoCascUpd->get_active() )
148 nAttrib |= KeyRule::NO_ACTION;
149 if( m_xRB_CascUpd->get_active() )
150 nAttrib |= KeyRule::CASCADE;
151 if( m_xRB_CascUpdNull->get_active() )
152 nAttrib |= KeyRule::SET_NULL;
153 if( m_xRB_CascUpdDefault->get_active() )
154 nAttrib |= KeyRule::SET_DEFAULT;
155 pConnData->SetUpdateRules( nAttrib );
156
157 m_xTableControl->SaveModified();
158
161 //m_pConnData->SetSourceWinName(m_xTableControl->getSourceWinName());
162 //m_pConnData->SetDestWinName(m_xTableControl->getDestWinName());
163
164 // try to create the relation
165 try
166 {
167 ORelationTableConnectionData* pOrigConnData = static_cast<ORelationTableConnectionData*>(m_pOrigConnData.get());
168 if ( *pConnData == *pOrigConnData || pConnData->Update())
169 {
170 m_pOrigConnData->CopyFrom( *m_pConnData );
171 m_xDialog->response(RET_OK);
172 return;
173 }
174 }
175 catch( const SQLException& )
176 {
177 ::dbtools::showError(SQLExceptionInfo(::cppu::getCaughtException()),
178 m_xDialog->GetXWindow(),
179 m_pParent->getDesignView()->getController().getORB());
180 }
181 catch( const Exception& )
182 {
183 DBG_UNHANDLED_EXCEPTION("dbaccess");
184 }
185
186 m_bTriedOneUpdate = true;
187 // this means that the original connection may be lost (if m_pConnData was not a newly created but an
188 // existent conn to be modified), which we reflect by returning RET_NO (see ::Execute)
189
190 // try again
191 Init(m_pConnData);
192 m_xTableControl->Init( m_pConnData );
193 m_xTableControl->lateInit();
194}
195
197{
198 short nResult = GenericDialogController::run();
199 if ((nResult != RET_OK) && m_bTriedOneUpdate)
200 return RET_NO;
201
202 return nResult;
203}
204
206{
207 m_xPB_OK->set_sensitive(_bValid);
208}
209
211{
213}
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
OTableWindowMap & GetTabWinMap()
std::unique_ptr< weld::RadioButton > m_xRB_CascUpd
Definition: RelationDlg.hxx:39
std::unique_ptr< weld::RadioButton > m_xRB_CascDel
Definition: RelationDlg.hxx:43
std::unique_ptr< OTableListBoxControl > m_xTableControl
Definition: RelationDlg.hxx:48
virtual ~ORelationDialog() override
Definition: RelationDlg.cxx:79
std::unique_ptr< weld::RadioButton > m_xRB_CascUpdNull
Definition: RelationDlg.hxx:40
std::unique_ptr< weld::RadioButton > m_xRB_NoCascUpd
Definition: RelationDlg.hxx:38
std::unique_ptr< weld::Button > m_xPB_OK
Definition: RelationDlg.hxx:46
void Init(const TTableConnectionData::value_type &_pConnectionData)
Definition: RelationDlg.cxx:83
virtual void setValid(bool _bValid) override
setValid set the valid inside, can be used for OK buttons
std::unique_ptr< weld::RadioButton > m_xRB_CascDelNull
Definition: RelationDlg.hxx:44
virtual void notifyConnectionChange() override
notifyConnectionChange is callback which is called when the table selection has changed and a new con...
virtual short run() override
TTableConnectionData::value_type m_pConnData
Definition: RelationDlg.hxx:34
std::unique_ptr< weld::RadioButton > m_xRB_CascDelDefault
Definition: RelationDlg.hxx:45
std::unique_ptr< weld::RadioButton > m_xRB_CascUpdDefault
Definition: RelationDlg.hxx:41
std::unique_ptr< weld::RadioButton > m_xRB_NoCascDel
Definition: RelationDlg.hxx:42
std::unique_ptr< weld::Builder > m_xBuilder
void Init()
#define DBG_UNHANDLED_EXCEPTION(...)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
@ Exception
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
RET_OK
RET_NO