LibreOffice Module dbaccess (master) 1
JoinController.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 <browserids.hxx>
21#include <com/sun/star/sdbc/XRow.hpp>
23#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
24#include <JoinController.hxx>
25#include <TableWindowData.hxx>
26#include <TableWindow.hxx>
28#include <adtabdlg.hxx>
29#include <vcl/svapp.hxx>
30#include <osl/mutex.hxx>
31#include <osl/diagnose.h>
32
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::io;
35using namespace ::com::sun::star::beans;
36using namespace ::com::sun::star::frame;
37using namespace ::com::sun::star::util;
38using namespace ::com::sun::star::lang;
39using namespace ::com::sun::star::container;
40using namespace ::com::sun::star::sdbc;
41using namespace ::com::sun::star::sdb;
42using namespace ::com::sun::star::ui::dialogs;
43using namespace ::dbtools;
44using namespace ::comphelper;
45
46namespace dbaui
47{
48
49// AddTableDialogContext
51{
53
54public:
55 explicit AddTableDialogContext( OJoinController& _rController )
56 :m_rController( _rController )
57 {
58 }
59
61
62 // IAddTableDialogContext
63 virtual css::uno::Reference< css::sdbc::XConnection >
64 getConnection() const override;
65 virtual bool allowViews() const override;
66 virtual bool allowQueries() const override;
67 virtual bool allowAddition() const override;
68 virtual void addTableWindow( const OUString& _rQualifiedTableName, const OUString& _rAliasName ) override;
69 virtual void onWindowClosing() override;
70
71private:
73};
74
76{
77 return m_rController.getConnection();
78}
79
81{
83}
84
86{
88}
89
91{
93}
94
95void AddTableDialogContext::addTableWindow( const OUString& _rQualifiedTableName, const OUString& _rAliasName )
96{
97 getTableView()->AddTabWin( _rQualifiedTableName, _rAliasName, true );
98}
99
101{
102 if (!m_rController.getView())
103 return;
104 m_rController.InvalidateFeature( ID_BROWSER_ADDTABLE );
105 m_rController.getView()->GrabFocus();
106}
107
109{
112 return nullptr;
113}
114
115// OJoinController
116
119{
120}
121
123{
124}
125
127{
128 return static_cast< OJoinDesignView* >( getView() );
129}
130
132{
134 {
135 m_xAddTableDialog->response(RET_CLOSE);
136 m_xAddTableDialog.reset();
137 }
138
140
141 clearView();
142
144 m_vTableData.clear();
145}
146
148{
149 OJoinController_BASE::reconnect( _bUI );
150 if ( isConnected() && m_xAddTableDialog )
151 m_xAddTableDialog->Update();
152}
153
155{
156 OJoinController_BASE::impl_onModifyChanged();
157 InvalidateFeature( SID_RELATION_ADD_RELATION );
158}
159
161{
162 // the data for the window
163 const TTableWindowData::value_type& pData = pTabWin->GetData();
164 OSL_ENSURE(pData != nullptr, "SaveTabWinPosSize : TabWin has no data !");
165
166 // set Position & Size of data anew (with current window parameters)
167 Point aPos = pTabWin->GetPosPixel();
168 aPos.AdjustX(nOffsetX );
169 aPos.AdjustY(nOffsetY );
170 pData->SetPosition(aPos);
171 pData->SetSize(pTabWin->GetSizePixel());
172
173}
174
176{
177 FeatureState aReturn;
178 // (disabled automatically)
179 aReturn.bEnabled = true;
180
181 switch (_nId)
182 {
184 aReturn.bChecked = isEditable();
185 break;
187 aReturn.bEnabled = ( getView() != nullptr )
188 && const_cast< OJoinController* >( this )->getJoinView()->getTableView()->IsAddAllowed();
189 aReturn.bChecked = aReturn.bEnabled && m_xAddTableDialog;
190 if ( aReturn.bEnabled )
192 break;
193
194 default:
195 aReturn = OJoinController_BASE::GetState(_nId);
196 }
197 return aReturn;
198}
199
201{
202 if (!m_pDialogContext)
203 {
204 OJoinController* pNonConstThis = const_cast< OJoinController* >( this );
205 pNonConstThis->m_pDialogContext.reset( new AddTableDialogContext( *pNonConstThis ) );
206 }
207 assert(m_pDialogContext && "always exists at this point");
208 return *m_pDialogContext;
209}
210
211void OJoinController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
212{
213 switch(_nId)
214 {
216 if(isEditable())
217 { // the state should be changed to not editable
218 switch (saveModified())
219 {
220 case RET_CANCEL:
221 // don't change anything here so return
222 return;
223 case RET_NO:
224 reset();
225 setModified(false); // and we are not modified yet
226 break;
227 default:
228 break;
229 }
230 }
231 setEditable(!isEditable());
232 getJoinView()->setReadOnly(!isEditable());
233 InvalidateAll();
234 return;
237 {
238 m_xAddTableDialog->response(RET_CLOSE);
239 getView()->GrabFocus();
240 }
241 else
242 {
244 }
245 break;
246 default:
248 }
249 InvalidateFeature(_nId);
250}
251
253{
254 assert(!m_xAddTableDialog);
255 m_xAddTableDialog = std::make_shared<OAddTableDlg>(getFrameWeld(), impl_getDialogContext());
256 {
257 weld::WaitObject aWaitCursor(getFrameWeld());
258 m_xAddTableDialog->Update();
259 }
260 weld::DialogController::runAsync(m_xAddTableDialog, [this](sal_Int32 /*nResult*/){
261 m_xAddTableDialog->OnClose();
262 m_xAddTableDialog.reset();
263 });
264}
265
267{
268 // Deletion and recreation of the old implementation with the current model is not correct anymore:
269 // The TabWins have a pointer to their data, but they are managed by me. When I delete the old ones, the TabWins suddenly have a pointer to objects, which no longer exist.
270 // If the TabWins had a SetData, I could save that effort... but they don't, further I also would still have to set information anew, which actually didn't change.
271 // So I don't delete the TabWinDatas, but only update them.
272 OSL_ENSURE(m_vTableData.size() == pTabWinList->size(),
273 "OJoinController::SaveTabWinsPosSize : inconsistent state : should have as many TabWinDatas as TabWins !");
274
275 for (auto const& tabWin : *pTabWinList)
276 SaveTabWinPosSize(tabWin.second, nOffsetX, nOffsetY);
277}
278
279void OJoinController::removeConnectionData(const TTableConnectionData::value_type& _pData)
280{
282}
283
285{
286 OJoinController_BASE::describeSupportedFeatures();
287 implDescribeSupportedFeature( ".uno:Redo", ID_BROWSER_REDO, CommandGroup::EDIT );
288 implDescribeSupportedFeature( ".uno:Save", ID_BROWSER_SAVEDOC, CommandGroup::DOCUMENT );
289 implDescribeSupportedFeature( ".uno:Undo", ID_BROWSER_UNDO, CommandGroup::EDIT );
290 implDescribeSupportedFeature( ".uno:AddTable", ID_BROWSER_ADDTABLE,CommandGroup::EDIT );
291 implDescribeSupportedFeature( ".uno:EditDoc", ID_BROWSER_EDITDOC, CommandGroup::EDIT );
292 implDescribeSupportedFeature( ".uno:GetUndoStrings", SID_GETUNDOSTRINGS );
293 implDescribeSupportedFeature( ".uno:GetRedoStrings", SID_GETREDOSTRINGS );
294}
295
297{
298 if ( getBroadcastHelper().bInDispose || getBroadcastHelper().bDisposed )
299 return true;
300
301 SolarMutexGuard aSolarGuard;
302 ::osl::MutexGuard aGuard( getMutex() );
303 if ( getView() && getView()->IsInModalMode() )
304 return false;
305 bool bCheck = true;
306 if ( _bSuspend )
307 {
308 bCheck = saveModified() != RET_CANCEL;
309 if ( bCheck )
310 OSingleDocumentController::suspend(_bSuspend);
311 }
312 return bCheck;
313}
314
315void OJoinController::loadTableWindows( const ::comphelper::NamedValueCollection& i_rViewSettings )
316{
317 m_vTableData.clear();
318
320
321 Sequence< PropertyValue > aWindowData;
322 aWindowData = i_rViewSettings.getOrDefault( "Tables", aWindowData );
323
324 const PropertyValue* pTablesIter = aWindowData.getConstArray();
325 const PropertyValue* pTablesEnd = pTablesIter + aWindowData.getLength();
326 for ( ; pTablesIter != pTablesEnd; ++pTablesIter )
327 {
328 ::comphelper::NamedValueCollection aSingleTableData( pTablesIter->Value );
329 loadTableWindow( aSingleTableData );
330 }
332 {
334 }
335}
336
337void OJoinController::loadTableWindow( const ::comphelper::NamedValueCollection& i_rTableWindowSettings )
338{
339 sal_Int32 nX = -1, nY = -1, nHeight = -1, nWidth = -1;
340
341 OUString sComposedName,sTableName,sWindowName;
342 bool bShowAll = false;
343
344 sComposedName = i_rTableWindowSettings.getOrDefault( "ComposedName", sComposedName );
345 sTableName = i_rTableWindowSettings.getOrDefault( "TableName", sTableName );
346 sWindowName = i_rTableWindowSettings.getOrDefault( "WindowName", sWindowName );
347 nY = i_rTableWindowSettings.getOrDefault( "WindowTop", nY );
348 nX = i_rTableWindowSettings.getOrDefault( "WindowLeft", nX );
349 nWidth = i_rTableWindowSettings.getOrDefault( "WindowWidth", nWidth );
350 nHeight = i_rTableWindowSettings.getOrDefault( "WindowHeight", nHeight );
351 bShowAll = i_rTableWindowSettings.getOrDefault( "ShowAll", bShowAll );
352
353 TTableWindowData::value_type pData = createTableWindowData(sComposedName,sTableName,sWindowName);
354 if ( pData )
355 {
356 pData->SetPosition(Point(nX,nY));
357 pData->SetSize( Size( nWidth, nHeight ) );
358 pData->ShowAll(bShowAll);
359 m_vTableData.push_back(pData);
360 if ( m_aMinimumTableViewSize.X() < (nX+nWidth) )
361 m_aMinimumTableViewSize.setX( nX+nWidth );
362 if ( m_aMinimumTableViewSize.Y() < (nY+nHeight) )
363 m_aMinimumTableViewSize.setY( nY+nHeight );
364 }
365}
366
368{
369 if ( m_vTableData.empty() )
370 return;
371
373
374 sal_Int32 i = 1;
375 for (auto const& elem : m_vTableData)
376 {
378 aWindowData.put( "ComposedName", elem->GetComposedName() );
379 aWindowData.put( "TableName", elem->GetTableName() );
380 aWindowData.put( "WindowName", elem->GetWinName() );
381 aWindowData.put( "WindowTop", static_cast<sal_Int32>(elem->GetPosition().Y()) );
382 aWindowData.put( "WindowLeft", static_cast<sal_Int32>(elem->GetPosition().X()) );
383 aWindowData.put( "WindowWidth", static_cast<sal_Int32>(elem->GetSize().Width()) );
384 aWindowData.put( "WindowHeight", static_cast<sal_Int32>(elem->GetSize().Height()) );
385 aWindowData.put( "ShowAll", elem->IsShowAll() );
386
387 const OUString sTableName( "Table" + OUString::number( i++ ) );
388 aAllTablesData.put( sTableName, aWindowData.getPropertyValues() );
389 }
390
391 o_rViewSettings.put( "Tables", aAllTablesData.getPropertyValues() );
392}
393
394TTableWindowData::value_type OJoinController::createTableWindowData(const OUString& _sComposedName,const OUString& _sTableName,const OUString& _sWindowName)
395{
396 OJoinDesignView* pView = getJoinView();
397 if( pView )
398 return pView->getTableView()->createTableWindowData(_sComposedName,_sTableName,_sWindowName);
399 OSL_FAIL("We should never ever reach this point!");
400
401 return TTableWindowData::value_type();
402}
403
404} // namespace dbaui
405
406/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sComposedName
#define ID_BROWSER_EDITDOC
Definition: browserids.hxx:26
#define ID_BROWSER_ADDTABLE
Definition: browserids.hxx:53
#define ID_BROWSER_SAVEDOC
Definition: browserids.hxx:32
#define ID_BROWSER_UNDO
Definition: browserids.hxx:35
#define ID_BROWSER_REDO
Definition: browserids.hxx:31
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long X() const
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
virtual void addTableWindow(const OUString &_rQualifiedTableName, const OUString &_rAliasName) override
virtual bool allowAddition() const override
AddTableDialogContext(OJoinController &_rController)
OJoinTableView * getTableView() const
virtual bool allowQueries() const override
virtual void onWindowClosing() override
virtual bool allowViews() const override
OJoinController & m_rController
virtual css::uno::Reference< css::sdbc::XConnection > getConnection() const override
static OUString getDialogTitleForContext(IAddTableDialogContext const &_rContext)
Definition: adtabdlg.cxx:455
std::unique_ptr< AddTableDialogContext > m_pDialogContext
void removeConnectionData(const TTableConnectionData::value_type &_pData)
erase the data in the data vector
void loadTableWindows(const ::comphelper::NamedValueCollection &i_rViewSettings)
loads the information for the windows.
virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
std::shared_ptr< OAddTableDlg > m_xAddTableDialog
virtual void reset()=0
TTableWindowData::value_type createTableWindowData(const OUString &_sComposedName, const OUString &_sTableName, const OUString &_sWindowName)
virtual ~OJoinController() override
void loadTableWindow(const ::comphelper::NamedValueCollection &i_rTableWindowSettings)
loads the information for one window.
OJoinController(const css::uno::Reference< css::uno::XComponentContext > &_rM)
virtual bool allowQueries() const =0
determines whether or not it's allowed for queries to participate in the game
virtual short saveModified()=0
void saveTableWindows(::comphelper::NamedValueCollection &o_rViewSettings) const
saves the TableWindows structure in a sequence of property values
virtual void reconnect(bool _bUI) override
void SaveTabWinsPosSize(OJoinTableView::OTableWindowMap *pTabWinList, tools::Long nOffsetX, tools::Long nOffsetY)
virtual FeatureState GetState(sal_uInt16 nId) const override
virtual void impl_onModifyChanged() override
static void SaveTabWinPosSize(OTableWindow const *pTabWin, tools::Long nOffsetX, tools::Long nOffsetY)
virtual void describeSupportedFeatures() override
virtual void SAL_CALL disposing() override
AddTableDialogContext & impl_getDialogContext() const
TTableConnectionData m_vTableConnectionData
virtual OJoinDesignView * getJoinView()
provides access to the OJoinDesignView belonging to the controller, which might or might not be the d...
virtual bool allowViews() const =0
determines whether or not it's allowed for database views to participate in the game
virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override
TTableWindowData m_vTableData
OScrollWindowHelper * getScrollHelper() const
OJoinTableView * getTableView() const
virtual void setReadOnly(bool _bReadOnly)
TTableWindowData::value_type createTableWindowData(const OUString &_rComposedName, const OUString &_sTableName, const OUString &_rWinName)
std::map< OUString, VclPtr< OTableWindow > > OTableWindowMap
virtual bool IsAddAllowed()
virtual void AddTabWin(const OUString &_rComposedName, const OUString &rWinName, bool bNewTable=false)
void resetRange(const Point &_aSize)
virtual void SAL_CALL disposing() override
virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
virtual FeatureState GetState(sal_uInt16 nId) const override
const TTableWindowData::value_type & GetData() const
virtual Point GetPosPixel() const
virtual Size GetSizePixel() const
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
std::unique_ptr< sal_Int32[]> pData
::osl::Mutex & getMutex()
int i
SwView * getView(const uno::Reference< frame::XModel > &xModel)
long Long
describes the state of a feature
std::optional< bool > bChecked
std::optional< OUString > sTitle
unsigned char sal_Bool
RET_CLOSE
RET_CANCEL
RET_NO