tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / dbaccess / source / ui / dlg / RelationDlg.cxx
blobc1bba08df1c526aa00483e897a1fcd28aff28a21
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <RelationDlg.hxx>
22 #include <com/sun/star/sdbc/KeyRule.hpp>
23 #include <com/sun/star/sdbc/SQLException.hpp>
25 #include <comphelper/diagnose_ex.hxx>
26 #include <JoinDesignView.hxx>
27 #include <JoinController.hxx>
28 #include <connectivity/dbexception.hxx>
29 #include <connectivity/dbtools.hxx>
30 #include <RTableConnectionData.hxx>
31 #include <RelationControl.hxx>
32 #include <cppuhelper/exc_hlp.hxx>
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::dbaui;
37 using namespace ::dbtools;
39 ORelationDialog::ORelationDialog( OJoinTableView* pParent,
40 const TTableConnectionData::value_type& pConnectionData,
41 bool bAllowTableSelect )
42 : GenericDialogController(pParent->GetFrameWeld(),
43 u"dbaccess/ui/relationdialog.ui"_ustr, u"RelationDialog"_ustr)
44 , m_pParent(pParent)
45 , m_pOrigConnData(pConnectionData)
46 , m_bTriedOneUpdate(false)
47 , m_xRB_NoCascUpd(m_xBuilder->weld_radio_button(u"addaction"_ustr))
48 , m_xRB_CascUpd(m_xBuilder->weld_radio_button(u"addcascade"_ustr))
49 , m_xRB_CascUpdNull(m_xBuilder->weld_radio_button(u"addnull"_ustr))
50 , m_xRB_CascUpdDefault(m_xBuilder->weld_radio_button(u"adddefault"_ustr))
51 , m_xRB_NoCascDel(m_xBuilder->weld_radio_button(u"delaction"_ustr))
52 , m_xRB_CascDel(m_xBuilder->weld_radio_button(u"delcascade"_ustr))
53 , m_xRB_CascDelNull(m_xBuilder->weld_radio_button(u"delnull"_ustr))
54 , m_xRB_CascDelDefault(m_xBuilder->weld_radio_button(u"deldefault"_ustr))
55 , m_xPB_OK(m_xBuilder->weld_button(u"ok"_ustr))
57 // Copy connection
58 m_pConnData = pConnectionData->NewInstance();
59 m_pConnData->CopyFrom( *pConnectionData );
61 Init(m_pConnData);
62 m_xTableControl.reset(new OTableListBoxControl(m_xBuilder.get(), &pParent->GetTabWinMap(), this));
64 m_xPB_OK->connect_clicked(LINK(this, ORelationDialog, OKClickHdl));
66 m_xTableControl->Init( m_pConnData );
67 if ( bAllowTableSelect )
68 m_xTableControl->fillListBoxes();
69 else
70 m_xTableControl->fillAndDisable(pConnectionData);
72 m_xTableControl->lateInit();
74 m_xTableControl->NotifyCellChange();
77 ORelationDialog::~ORelationDialog()
81 void ORelationDialog::Init(const TTableConnectionData::value_type& _pConnectionData)
83 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(_pConnectionData.get());
84 // Update Rules
85 switch (pConnData->GetUpdateRules())
87 case KeyRule::NO_ACTION:
88 case KeyRule::RESTRICT:
89 m_xRB_NoCascUpd->set_active(true);
90 break;
92 case KeyRule::CASCADE:
93 m_xRB_CascUpd->set_active(true);
94 break;
96 case KeyRule::SET_NULL:
97 m_xRB_CascUpdNull->set_active(true);
98 break;
99 case KeyRule::SET_DEFAULT:
100 m_xRB_CascUpdDefault->set_active(true);
101 break;
104 // Delete Rules
105 switch (pConnData->GetDeleteRules())
107 case KeyRule::NO_ACTION:
108 case KeyRule::RESTRICT:
109 m_xRB_NoCascDel->set_active(true);
110 break;
112 case KeyRule::CASCADE:
113 m_xRB_CascDel->set_active(true);
114 break;
116 case KeyRule::SET_NULL:
117 m_xRB_CascDelNull->set_active(true);
118 break;
119 case KeyRule::SET_DEFAULT:
120 m_xRB_CascDelDefault->set_active(true);
121 break;
125 IMPL_LINK_NOARG(ORelationDialog, OKClickHdl, weld::Button&, void)
127 // Read out RadioButtons
128 sal_uInt16 nAttrib = 0;
130 // Delete Rules
131 if( m_xRB_NoCascDel->get_active() )
132 nAttrib |= KeyRule::NO_ACTION;
133 if( m_xRB_CascDel->get_active() )
134 nAttrib |= KeyRule::CASCADE;
135 if( m_xRB_CascDelNull->get_active() )
136 nAttrib |= KeyRule::SET_NULL;
137 if( m_xRB_CascDelDefault->get_active() )
138 nAttrib |= KeyRule::SET_DEFAULT;
140 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(m_pConnData.get());
141 pConnData->SetDeleteRules( nAttrib );
143 // Update Rules
144 nAttrib = 0;
145 if( m_xRB_NoCascUpd->get_active() )
146 nAttrib |= KeyRule::NO_ACTION;
147 if( m_xRB_CascUpd->get_active() )
148 nAttrib |= KeyRule::CASCADE;
149 if( m_xRB_CascUpdNull->get_active() )
150 nAttrib |= KeyRule::SET_NULL;
151 if( m_xRB_CascUpdDefault->get_active() )
152 nAttrib |= KeyRule::SET_DEFAULT;
153 pConnData->SetUpdateRules( nAttrib );
155 m_xTableControl->SaveModified();
157 //// if the ComboBoxes for the table selection are enabled (constructor with bAllowTableSelect==sal_True),
158 //// then I must also put the table names into the connection
159 //m_pConnData->SetSourceWinName(m_xTableControl->getSourceWinName());
160 //m_pConnData->SetDestWinName(m_xTableControl->getDestWinName());
162 // try to create the relation
165 ORelationTableConnectionData* pOrigConnData = static_cast<ORelationTableConnectionData*>(m_pOrigConnData.get());
166 if ( *pConnData == *pOrigConnData || pConnData->Update())
168 m_pOrigConnData->CopyFrom( *m_pConnData );
169 m_xDialog->response(RET_OK);
170 return;
173 catch( const SQLException& )
175 ::dbtools::showError(SQLExceptionInfo(::cppu::getCaughtException()),
176 m_xDialog->GetXWindow(),
177 m_pParent->getDesignView()->getController().getORB());
179 catch( const Exception& )
181 DBG_UNHANDLED_EXCEPTION("dbaccess");
184 m_bTriedOneUpdate = true;
185 // this means that the original connection may be lost (if m_pConnData was not a newly created but an
186 // existent conn to be modified), which we reflect by returning RET_NO (see ::Execute)
188 // try again
189 Init(m_pConnData);
190 m_xTableControl->Init( m_pConnData );
191 m_xTableControl->lateInit();
194 short ORelationDialog::run()
196 short nResult = GenericDialogController::run();
197 if ((nResult != RET_OK) && m_bTriedOneUpdate)
198 return RET_NO;
200 return nResult;
203 void ORelationDialog::setValid(bool _bValid)
205 m_xPB_OK->set_sensitive(_bValid);
208 void ORelationDialog::notifyConnectionChange()
210 Init(m_pConnData);
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */