fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / dlg / RelationDlg.cxx
blob50913994c2985c5b53c60ce9c61f3c1513a1ed8c
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 <vcl/wrkwin.hxx>
24 #include <vcl/svapp.hxx>
25 #include "dbu_dlg.hrc"
26 #include "dbaccess_helpid.hrc"
27 #include <com/sun/star/sdbc/KeyRule.hpp>
29 #include <tools/debug.hxx>
30 #include <tools/diagnose_ex.h>
31 #include "UITools.hxx"
32 #include "JoinDesignView.hxx"
33 #include "JoinController.hxx"
34 #include <connectivity/dbexception.hxx>
35 #include "RTableConnectionData.hxx"
36 #include "RelationControl.hxx"
37 #include <cppuhelper/exc_hlp.hxx>
38 #include <comphelper/processfactory.hxx>
40 #include <algorithm>
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::sdbc;
44 using namespace ::com::sun::star::container;
45 using namespace ::com::sun::star::beans;
46 using namespace ::dbaui;
47 using namespace ::dbtools;
49 // class ORelationDialog
50 ORelationDialog::ORelationDialog( OJoinTableView* pParent,
51 const TTableConnectionData::value_type& pConnectionData,
52 bool bAllowTableSelect )
53 : ModalDialog(pParent, "RelationDialog",
54 "dbaccess/ui/relationdialog.ui")
55 , m_pTableMap(&pParent->GetTabWinMap())
56 , m_pOrigConnData(pConnectionData)
57 , m_bTriedOneUpdate(false)
59 get(m_pRB_NoCascUpd, "addaction");
60 get(m_pRB_CascUpd, "addcascade");
61 get(m_pRB_CascUpdNull, "addnull");
62 get(m_pRB_CascUpdDefault, "adddefault");
63 get(m_pRB_NoCascDel, "delaction");
64 get(m_pRB_CascDel, "delcascade");
65 get(m_pRB_CascDelNull, "delnull");
66 get(m_pRB_CascDelDefault, "deldefault");
67 get(m_pPB_OK, "ok");
69 m_xConnection = pParent->getDesignView()->getController().getConnection();
71 // Connection kopieren
72 m_pConnData.reset( static_cast<ORelationTableConnectionData*>(pConnectionData->NewInstance()) );
73 m_pConnData->CopyFrom( *pConnectionData );
75 Init(m_pConnData);
76 m_xTableControl.reset( new OTableListBoxControl(this, m_pTableMap, this) );
78 m_pPB_OK->SetClickHdl( LINK(this, ORelationDialog, OKClickHdl) );
80 m_xTableControl->Init( m_pConnData );
81 if ( bAllowTableSelect )
82 m_xTableControl->fillListBoxes();
83 else
84 m_xTableControl->fillAndDisable(pConnectionData);
86 m_xTableControl->lateInit();
88 m_xTableControl->NotifyCellChange();
91 ORelationDialog::~ORelationDialog()
93 disposeOnce();
96 void ORelationDialog::dispose()
98 m_pRB_NoCascUpd.clear();
99 m_pRB_CascUpd.clear();
100 m_pRB_CascUpdNull.clear();
101 m_pRB_CascUpdDefault.clear();
102 m_pRB_NoCascDel.clear();
103 m_pRB_CascDel.clear();
104 m_pRB_CascDelNull.clear();
105 m_pRB_CascDelDefault.clear();
106 m_pPB_OK.clear();
107 ModalDialog::dispose();
111 void ORelationDialog::Init(const TTableConnectionData::value_type& _pConnectionData)
113 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(_pConnectionData.get());
114 // Update Rules
115 switch (pConnData->GetUpdateRules())
117 case KeyRule::NO_ACTION:
118 case KeyRule::RESTRICT:
119 m_pRB_NoCascUpd->Check( true );
120 break;
122 case KeyRule::CASCADE:
123 m_pRB_CascUpd->Check( true );
124 break;
126 case KeyRule::SET_NULL:
127 m_pRB_CascUpdNull->Check( true );
128 break;
129 case KeyRule::SET_DEFAULT:
130 m_pRB_CascUpdDefault->Check( true );
131 break;
134 // Delete Rules
135 switch (pConnData->GetDeleteRules())
137 case KeyRule::NO_ACTION:
138 case KeyRule::RESTRICT:
139 m_pRB_NoCascDel->Check( true );
140 break;
142 case KeyRule::CASCADE:
143 m_pRB_CascDel->Check( true );
144 break;
146 case KeyRule::SET_NULL:
147 m_pRB_CascDelNull->Check( true );
148 break;
149 case KeyRule::SET_DEFAULT:
150 m_pRB_CascDelDefault->Check( true );
151 break;
155 IMPL_LINK( ORelationDialog, OKClickHdl, Button*, /*pButton*/ )
157 // RadioButtons auslesen
158 sal_uInt16 nAttrib = 0;
160 // Delete Rules
161 if( m_pRB_NoCascDel->IsChecked() )
162 nAttrib |= KeyRule::NO_ACTION;
163 if( m_pRB_CascDel->IsChecked() )
164 nAttrib |= KeyRule::CASCADE;
165 if( m_pRB_CascDelNull->IsChecked() )
166 nAttrib |= KeyRule::SET_NULL;
167 if( m_pRB_CascDelDefault->IsChecked() )
168 nAttrib |= KeyRule::SET_DEFAULT;
170 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(m_pConnData.get());
171 pConnData->SetDeleteRules( nAttrib );
173 // Update Rules
174 nAttrib = 0;
175 if( m_pRB_NoCascUpd->IsChecked() )
176 nAttrib |= KeyRule::NO_ACTION;
177 if( m_pRB_CascUpd->IsChecked() )
178 nAttrib |= KeyRule::CASCADE;
179 if( m_pRB_CascUpdNull->IsChecked() )
180 nAttrib |= KeyRule::SET_NULL;
181 if( m_pRB_CascUpdDefault->IsChecked() )
182 nAttrib |= KeyRule::SET_DEFAULT;
183 pConnData->SetUpdateRules( nAttrib );
185 m_xTableControl->SaveModified();
187 //// wenn die ComboBoxen fuer die Tabellenauswahl enabled sind (Constructor mit bAllowTableSelect==sal_True), dann muss ich in die
188 //// Connection auch die Tabellennamen stecken
189 //m_pConnData->SetSourceWinName(m_xTableControl->getSourceWinName());
190 //m_pConnData->SetDestWinName(m_xTableControl->getDestWinName());
192 // try to create the relation
195 ORelationTableConnectionData* pOrigConnData = static_cast<ORelationTableConnectionData*>(m_pOrigConnData.get());
196 if ( *pConnData == *pOrigConnData || pConnData->Update())
198 m_pOrigConnData->CopyFrom( *m_pConnData );
199 EndDialog( RET_OK );
200 return 0L;
203 catch( const SQLException& )
205 ::dbaui::showError( SQLExceptionInfo( ::cppu::getCaughtException() ),
206 this,
207 static_cast<OJoinTableView*>(GetParent())->getDesignView()->getController().getORB());
209 catch( const Exception& )
211 DBG_UNHANDLED_EXCEPTION();
214 m_bTriedOneUpdate = true;
215 // this means that the original connection may be lost (if m_pConnData was not a newly created but an
216 // existent conn to be modified), which we reflect by returning RET_NO (see ::Execute)
218 // try again
219 Init(m_pConnData);
220 m_xTableControl->Init( m_pConnData );
221 m_xTableControl->lateInit();
223 return 0;
226 short ORelationDialog::Execute()
228 short nResult = ModalDialog::Execute();
229 if ((nResult != RET_OK) && m_bTriedOneUpdate)
230 return RET_NO;
232 return nResult;
235 TTableConnectionData::value_type ORelationDialog::getConnectionData() const
237 return m_pConnData;
240 void ORelationDialog::setValid(bool _bValid)
242 m_pPB_OK->Enable(_bValid);
245 void ORelationDialog::notifyConnectionChange()
247 Init(m_pConnData);
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */