LibreOffice Module dbaccess (master) 1
AppDetailView.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 "AppDetailView.hxx"
21#include <osl/diagnose.h>
22#include <helpids.h>
23#include <strings.hrc>
24#include "AppView.hxx"
25#include <com/sun/star/ui/XUIConfigurationManager.hpp>
26#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
27#include <com/sun/star/ui/XImageManager.hpp>
28#include <com/sun/star/ui/ImageType.hpp>
29#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
30#include <com/sun/star/graphic/XGraphic.hpp>
31#include <com/sun/star/util/URL.hpp>
32#include <core_resource.hxx>
33#include <vcl/svapp.hxx>
36#include <algorithm>
37#include <dbtreelistbox.hxx>
38#include "AppController.hxx"
39
40using namespace ::dbaui;
41using namespace ::com::sun::star::uno;
42using namespace ::com::sun::star::sdbc;
43using namespace ::com::sun::star::sdbcx;
44using namespace ::com::sun::star::lang;
45using namespace ::com::sun::star::ucb;
46using namespace ::com::sun::star::graphic;
47using namespace ::com::sun::star::ui;
48using namespace ::com::sun::star::container;
49using namespace ::com::sun::star::beans;
50using ::com::sun::star::util::URL;
51using ::com::sun::star::sdb::application::NamedDatabaseObject;
52
53TaskEntry::TaskEntry( const char* _pAsciiUNOCommand, TranslateId _pHelpID, TranslateId pTitleResourceID, bool _bHideWhenDisabled )
54 :sUNOCommand( OUString::createFromAscii( _pAsciiUNOCommand ) )
55 ,pHelpID( _pHelpID )
56 ,sTitle( DBA_RES(pTitleResourceID) )
57 ,bHideWhenDisabled( _bHideWhenDisabled )
58{
59}
60
62{
63 TranslateId pHelpTextId;
64 int nCurEntry = m_xTreeView->get_selected_index();
65 if (nCurEntry != -1)
66 pHelpTextId = weld::fromId<TaskEntry*>(m_xTreeView->get_id(nCurEntry))->pHelpID;
67 setHelpText(pHelpTextId);
68}
69
70IMPL_LINK(OTasksWindow, onSelected, weld::TreeView&, rTreeView, bool)
71{
72 m_nCursorIndex = rTreeView.get_cursor_index();
73 if (m_nCursorIndex != -1)
74 {
76 aCommand.Complete = weld::fromId<TaskEntry*>(rTreeView.get_id(m_nCursorIndex))->sUNOCommand;
77 getDetailView()->getBorderWin().getView()->getAppController().executeChecked( aCommand, Sequence< PropertyValue >() );
78 }
79 return true;
80}
81
83{
84 if (!m_xTreeView)
85 return;
86 m_xTreeView->grab_focus();
87}
88
90{
91 return m_xTreeView && m_xTreeView->has_focus();
92}
93
94IMPL_LINK_NOARG(OTasksWindow, FocusInHdl, weld::Widget&, void)
95{
96 m_xTreeView->select(m_nCursorIndex != -1 ? m_nCursorIndex : 0);
97}
98
99IMPL_LINK_NOARG(OTasksWindow, FocusOutHdl, weld::Widget&, void)
100{
101 m_nCursorIndex = m_xTreeView->get_cursor_index();
102 m_xTreeView->unselect_all();
103}
104
105IMPL_LINK_NOARG(OTasksWindow, OnEntrySelectHdl, weld::TreeView&, void)
106{
107 m_nCursorIndex = m_xTreeView->get_cursor_index();
108 updateHelpText();
109}
110
112 : OChildWindow(pParent, "dbaccess/ui/taskwindow.ui", "TaskWindow")
113 , m_xTreeView(m_xBuilder->weld_tree_view("treeview"))
114 , m_xDescription(m_xBuilder->weld_label("description"))
115 , m_xHelpText(m_xBuilder->weld_text_view("helptext"))
116 , m_pDetailView(pDetailView)
117 , m_nCursorIndex(-1)
118{
119 m_xContainer->set_stack_background();
120
122 m_xTreeView->connect_row_activated(LINK(this, OTasksWindow, onSelected));
123 m_xTreeView->connect_changed(LINK(this, OTasksWindow, OnEntrySelectHdl));
124 m_xTreeView->connect_focus_in(LINK(this, OTasksWindow, FocusInHdl));
125 m_xTreeView->connect_focus_out(LINK(this, OTasksWindow, FocusOutHdl));
126 // an arbitrary small size it's allowed to shrink to
127 m_xTreeView->set_size_request(42, 42);
128
129 m_xHelpText->set_help_id(HID_APP_HELP_TEXT);
131}
132
134{
135 Clear();
136}
137
139{
140 if (pId)
141 m_xHelpText->set_text(DBA_RES(pId));
142 else
143 m_xHelpText->set_text(OUString());
144}
145
147{
148 Clear();
149
150 try
151 {
153 theModuleUIConfigurationManagerSupplier::get( getDetailView()->getBorderWin().getView()->getORB() );
154 Reference< XUIConfigurationManager > xUIConfigMgr = xModuleCfgMgrSupplier->getUIConfigurationManager(
155 "com.sun.star.sdb.OfficeDatabaseDocument"
156 );
157 Reference< XImageManager > xImageMgr( xUIConfigMgr->getImageManager(), UNO_QUERY );
158
159 // copy the commands so we can use them with the config managers
160 Sequence< OUString > aCommands( _rList.size() );
161 OUString* pCommands = aCommands.getArray();
162 for (auto const& copyTask : _rList)
163 {
164 *pCommands = copyTask.sUNOCommand;
165 ++pCommands;
166 }
167
168 Sequence< Reference< XGraphic> > aImages = xImageMgr->getImages(
169 ImageType::SIZE_DEFAULT | ImageType::COLOR_NORMAL ,
170 aCommands
171 );
172
173 const Reference< XGraphic >* pImages( aImages.getConstArray() );
174
175 size_t nIndex = 0;
176 for (auto const& task : _rList)
177 {
178 OUString sId = weld::toId(new TaskEntry(task));
179 m_xTreeView->append(sId, task.sTitle);
180 m_xTreeView->set_image(nIndex++, *pImages++);
181 }
182 }
183 catch(Exception&)
184 {
185 }
186
187 m_xTreeView->unselect_all();
189 Enable(!_rList.empty());
190}
191
193{
194 m_xTreeView->all_foreach([this](weld::TreeIter& rEntry){
195 TaskEntry* pUserData = weld::fromId<TaskEntry*>(m_xTreeView->get_id(rEntry));
196 delete pUserData;
197 return false;
198 });
199
200 m_xTreeView->clear();
201}
202
204 PreviewMode ePreviewMode)
205 : m_xBuilder(Application::CreateBuilder(pParent, "dbaccess/ui/appdetailwindow.ui"))
206 , m_xContainer(m_xBuilder->weld_container("AppDetailWindow"))
207 , m_xHorzSplitter(m_xBuilder->weld_paned("splitter"))
208 , m_xTasksParent(m_xBuilder->weld_container("tasks"))
209 , m_xContainerParent(m_xBuilder->weld_container("container"))
210 , m_xTasks(new dbaui::OTitleWindow(m_xTasksParent.get(), STR_TASKS))
211 , m_xTitleContainer(new dbaui::OTitleWindow(m_xContainerParent.get(), TranslateId()))
212 , m_rBorderWin(rBorder)
213{
214 m_xControlHelper = std::make_shared<OAppDetailPageHelper>(m_xTitleContainer->getChildContainer(), m_rBorderWin, ePreviewMode);
215 m_xTitleContainer->setChildWindow(m_xControlHelper);
216
217 std::shared_ptr<OChildWindow> xTasks = std::make_shared<OTasksWindow>(m_xTasks->getChildContainer(), this);
219 m_xTasks->setChildWindow(xTasks);
220}
221
223{
224}
225
227{
228 m_aExternalMnemonics = rMnemonics;
229}
230
232{
233 impl_createPage( E_TABLE, _xConnection, nullptr );
234}
235
237{
238 impl_createPage( _eType, nullptr, _xContainer );
239}
240
242 const Reference< XNameAccess >& _rxNonTableElements )
243{
244 // get the data for the pane
245 const TaskPaneData& rData = impl_getTaskPaneData( _eType );
247
248 // enable the pane as a whole, depending on the availability of the first command
249 OSL_ENSURE( !rData.aTasks.empty(), "OApplicationDetailView::impl_createPage: no tasks at all!?" );
250 bool bEnabled = !rData.aTasks.empty()
251 && getBorderWin().getView()->getCommandController().isCommandEnabled( rData.aTasks[0].sUNOCommand );
252 getTasksWindow().Enable( bEnabled );
253 m_xTitleContainer->setTitle(rData.pTitleId);
254
255 // let our helper create the object list
256 if ( _eType == E_TABLE )
257 GetControlHelper()->createTablesPage( _rxConnection );
258 else
259 GetControlHelper()->createPage( _eType, _rxNonTableElements );
260}
261
263{
264 TaskEntryList& rList( _rData.aTasks );
265 rList.clear(); rList.reserve( 4 );
266
267 switch ( _eType )
268 {
269 case E_TABLE:
270 rList.emplace_back( ".uno:DBNewTable", RID_STR_TABLES_HELP_TEXT_DESIGN, RID_STR_NEW_TABLE );
271 rList.emplace_back( ".uno:DBNewTableAutoPilot", RID_STR_TABLES_HELP_TEXT_WIZARD, RID_STR_NEW_TABLE_AUTO );
272 rList.emplace_back( ".uno:DBNewView", RID_STR_VIEWS_HELP_TEXT_DESIGN, RID_STR_NEW_VIEW, true );
273 _rData.pTitleId = RID_STR_TABLES_CONTAINER;
274 break;
275
276 case E_FORM:
277 rList.emplace_back( ".uno:DBNewForm", RID_STR_FORMS_HELP_TEXT, RID_STR_NEW_FORM );
278 rList.emplace_back( ".uno:DBNewFormAutoPilot", RID_STR_FORMS_HELP_TEXT_WIZARD, RID_STR_NEW_FORM_AUTO );
279 _rData.pTitleId = RID_STR_FORMS_CONTAINER;
280 break;
281
282 case E_REPORT:
283 rList.emplace_back( ".uno:DBNewReport", RID_STR_REPORT_HELP_TEXT, RID_STR_NEW_REPORT, true );
284 rList.emplace_back( ".uno:DBNewReportAutoPilot", RID_STR_REPORTS_HELP_TEXT_WIZARD, RID_STR_NEW_REPORT_AUTO );
285 _rData.pTitleId = RID_STR_REPORTS_CONTAINER;
286 break;
287
288 case E_QUERY:
289 rList.emplace_back( ".uno:DBNewQuery", RID_STR_QUERIES_HELP_TEXT, RID_STR_NEW_QUERY );
290 rList.emplace_back( ".uno:DBNewQueryAutoPilot", RID_STR_QUERIES_HELP_TEXT_WIZARD, RID_STR_NEW_QUERY_AUTO );
291 rList.emplace_back( ".uno:DBNewQuerySql", RID_STR_QUERIES_HELP_TEXT_SQL, RID_STR_NEW_QUERY_SQL );
292 _rData.pTitleId = RID_STR_QUERIES_CONTAINER;
293 break;
294
295 default:
296 OSL_FAIL( "OApplicationDetailView::impl_fillTaskPaneData: illegal element type!" );
297 }
298
299 // remove the entries which are not enabled currently
300 for (TaskEntryList::iterator pTask = rList.begin(); pTask != rList.end();)
301 {
302 if ( pTask->bHideWhenDisabled
303 && !getBorderWin().getView()->getCommandController().isCommandEnabled( pTask->sUNOCommand )
304 )
305 pTask = rList.erase( pTask );
306 else
307 {
308 ++pTask;
309 }
310 }
311}
312
314{
315 if ( m_aTaskPaneData.empty() )
316 m_aTaskPaneData.resize( size_t(E_ELEMENT_TYPE_COUNT) );
317 OSL_ENSURE( ( _eType >= 0 ) && ( _eType < E_ELEMENT_TYPE_COUNT ), "OApplicationDetailView::impl_getTaskPaneData: illegal element type!" );
318 TaskPaneData& rData = m_aTaskPaneData[ _eType ];
319
320 //oj: do not check, otherwise extensions will only be visible after a reload.
321 impl_fillTaskPaneData( _eType, rData );
322
323 return rData;
324}
325
327{
328 return GetControlHelper()->getQualifiedName( _pEntry );
329}
330
332{
333 return OAppDetailPageHelper::isLeaf(rTreeView, rEntry);
334}
335
337{
339}
340
342{
344}
345
347{
349}
350
352{
354}
355
357{
358 return GetControlHelper()->isFilled();
359}
360
362{
364}
365
367{
368 if ( _bTaskAlso )
371}
372
374{
376}
377
379{
381}
382
383void OApplicationDetailView::getSelectionElementNames( std::vector< OUString>& _rNames ) const
384{
386}
387
389{
390 GetControlHelper()->describeCurrentSelectionForControl(rControl, out_rSelectedObjects);
391}
392
394{
395 GetControlHelper()->describeCurrentSelectionForType( _eType, _out_rSelectedObjects );
396}
397
399{
401}
402
404{
405 return GetControlHelper()->adjustMenuPosition(rControl, rPos);
406}
407
409{
410 GetControlHelper()->selectElements( _aNames );
411}
412
413std::unique_ptr<weld::TreeIter> OApplicationDetailView::getEntry(const Point& rPoint) const
414{
415 return GetControlHelper()->getEntry(rPoint);
416}
417
419{
420 return false;
421}
422
424{
425 return true;
426}
427
429
431
433
435
436std::unique_ptr<weld::TreeIter> OApplicationDetailView::elementAdded(ElementType _eType,const OUString& _rName, const Any& _rObject )
437{
438 return GetControlHelper()->elementAdded(_eType, _rName, _rObject);
439}
440
441void OApplicationDetailView::elementRemoved(ElementType _eType,const OUString& _rName )
442{
443 GetControlHelper()->elementRemoved(_eType,_rName );
444}
445
447 ,const OUString& _rOldName
448 ,const OUString& _rNewName )
449{
450 GetControlHelper()->elementReplaced( _eType, _rOldName, _rNewName );
451}
452
454{
456}
457
459{
461}
462
464{
466}
467
469{
470 GetControlHelper()->showPreview(_xContent);
471}
472
473void OApplicationDetailView::showPreview( const OUString& _sDataSourceName,
474 const OUString& _sName,
475 bool _bTable)
476{
477 GetControlHelper()->showPreview(_sDataSourceName,_sName,_bTable);
478}
479
481{
482 return GetControlHelper()->isSortUp();
483}
484
486{
488 if (!pCurrent)
489 return nullptr;
490 return &pCurrent->getListBox();
491}
492
494{
495 return static_cast<OAppDetailPageHelper*>(m_xControlHelper.get());
496}
497
499{
500 return static_cast<const OAppDetailPageHelper*>(m_xControlHelper.get());
501}
502
504{
505 return m_xHorzSplitter->has_focus() ||
506 m_xTasks->HasChildPathFocus() ||
507 m_xTitleContainer->HasChildPathFocus();
508}
509
510/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TreeListBox & getListBox() const
virtual bool isCommandEnabled(sal_uInt16 _nCommandId) const =0
checks if the given Command is enabled
virtual bool isDataSourceReadOnly() const =0
checks if the selected data source is read only
OApplicationView * getView() const
Definition: AppView.hxx:59
void sortUp()
sorts all entries descending
static bool isLeaf(const weld::TreeView &rTreeView, const weld::TreeIter &rEntry)
returns if an entry is a leaf
void sortDown()
sorts all entries ascending
bool isSortUp() const
returns <TRUE> if it sorts ascending
PreviewMode getPreviewMode() const
returns the preview mode
OUString getQualifiedName(const weld::TreeIter *_pEntry) const
return the qualified name.
void elementReplaced(ElementType eType, const OUString &_rOldName, const OUString &_rNewName)
replaces an objects name with a new one
vcl::Window * getMenuParent() const
get the menu parent window for the given control
sal_Int32 getSelectionCount()
returns the count of selected entries
bool isALeafSelected() const
returns if one of the selected entries is a leaf
void selectAll()
select all entries in the visible control
std::unique_ptr< weld::TreeIter > getEntry(const Point &rPosPixel) const
bool isFilled() const
returns <TRUE> when a detail page was filled
DBTreeViewBase * getCurrentView() const
returns the current visible tree list box
void adjustMenuPosition(const weld::TreeView &rControl, ::Point &rPos) const
void elementRemoved(ElementType _eType, const OUString &_rName)
removes an element from the detail page.
bool isPreviewEnabled() const
<TRUE> if the preview is enabled
sal_Int32 getElementCount() const
returns the count of entries
std::unique_ptr< weld::TreeIter > elementAdded(ElementType eType, const OUString &rName, const css::uno::Any &rObject)
adds a new object to the detail page.
void getSelectionElementNames(std::vector< OUString > &_rNames) const
returns the element names which are selected
void createPage(ElementType _eType, const css::uno::Reference< css::container::XNameAccess > &_xContainer)
creates the page for the specific type.
void describeCurrentSelectionForType(const ElementType _eType, css::uno::Sequence< css::sdb::application::NamedDatabaseObject > &_out_rSelectedObjects)
describes the current selection for the given ElementType
void selectElements(const css::uno::Sequence< OUString > &_aNames)
select all names on the currently selected container.
ElementType getElementType() const
return the element of currently select entry
void showPreview(const css::uno::Reference< css::ucb::XContent > &_xContent)
shows the Preview of the content when it is enabled.
void switchPreview(PreviewMode _eMode, bool _bForce=false)
switches to the given preview mode
void describeCurrentSelectionForControl(const weld::TreeView &rControl, css::uno::Sequence< css::sdb::application::NamedDatabaseObject > &_out_rSelectedObjects)
describes the current selection for the given control
void clearPages()
clears the detail pages
void createTablesPage(const css::uno::Reference< css::sdbc::XConnection > &_xConnection)
creates the tables page
sal_Int32 getElementCount() const
returns the count of entries
std::unique_ptr< weld::TreeIter > getEntry(const Point &rPosPixel) const
void impl_createPage(ElementType _eType, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::container::XNameAccess > &_rxNonTableElements)
void createPage(ElementType _eType, const css::uno::Reference< css::container::XNameAccess > &_xContainer)
creates the page for the specific type.
void impl_fillTaskPaneData(ElementType _eType, TaskPaneData &_rData) const
std::vector< TaskPaneData > m_aTaskPaneData
std::shared_ptr< OChildWindow > m_xControlHelper
void createTablesPage(const css::uno::Reference< css::sdbc::XConnection > &_xConnection)
creates the tables page
static bool isLeaf(const weld::TreeView &rTreeView, const weld::TreeIter &rEntry)
returns if an entry is a leaf
void selectAll()
select all entries in the detail page
OUString getQualifiedName(const weld::TreeIter *_pEntry) const
return the qualified name.
sal_Int32 getSelectionCount()
returns the count of selected entries
const OAppDetailPageHelper * GetControlHelper() const
void setTaskExternalMnemonics(MnemonicGenerator const &_rMnemonics)
void elementRemoved(ElementType _eType, const OUString &_rName)
removes an element from the detail page.
void sortUp()
sort the entries in the detail page up
PreviewMode getPreviewMode() const
returns the preview mode
std::unique_ptr< weld::Paned > m_xHorzSplitter
const TaskPaneData & impl_getTaskPaneData(ElementType _eType)
OTasksWindow & getTasksWindow() const
ElementType getElementType() const
return the element of currently select entry
std::unique_ptr< weld::TreeIter > elementAdded(ElementType eType, const OUString &rName, const css::uno::Any &rObject)
adds a new object to the detail page.
vcl::Window * getMenuParent() const
get the menu parent window for the given control
void selectElements(const css::uno::Sequence< OUString > &_aNames)
select all names on the currently selected container.
void describeCurrentSelectionForControl(const weld::TreeView &rControl, css::uno::Sequence< css::sdb::application::NamedDatabaseObject > &_out_rSelectedObjects)
describes the current selection for the given control
bool isALeafSelected() const
returns if one of the selected entries is a leaf
bool isPreviewEnabled() const
<TRUE> if the preview is enabled
OAppBorderWindow & getBorderWin() const
bool isFilled() const
returns <TRUE> when a detail page was filled
MnemonicGenerator m_aExternalMnemonics
void clearPages(bool _bTaskAlso=true)
clears the detail pages.
void showPreview(const css::uno::Reference< css::ucb::XContent > &_xContent)
shows the Preview of the content when it is enabled.
OAppBorderWindow & m_rBorderWin
void describeCurrentSelectionForType(const ElementType _eType, css::uno::Sequence< css::sdb::application::NamedDatabaseObject > &_out_rSelectedObjects)
describes the current selection for the given ElementType
void elementReplaced(ElementType eType, const OUString &_rOldName, const OUString &_rNewName)
replaces an objects name with a new one
bool isSortUp() const
returns <TRUE> if it sorts ascending
std::unique_ptr< OTitleWindow > m_xTasks
void sortDown()
sort the entries in the detail page down
std::unique_ptr< OTitleWindow > m_xTitleContainer
void switchPreview(PreviewMode _eMode)
switches to the given preview mode
OApplicationDetailView(weld::Container *pParent, OAppBorderWindow &rBorder, PreviewMode ePreviewMode)
void adjustMenuPosition(const weld::TreeView &rControl, ::Point &rPos) const
TreeListBox * getTreeWindow() const
void getSelectionElementNames(std::vector< OUString > &_rNames) const
returns the element names which are selected
void Enable(bool bEnable)
Definition: ChildWindow.hxx:30
std::unique_ptr< weld::Container > m_xContainer
Definition: ChildWindow.hxx:21
IController & getCommandController() const
Definition: dataview.hxx:70
void setHelpText(TranslateId pId)
OTasksWindow(weld::Container *pParent, OApplicationDetailView *pDetailView)
virtual void GrabFocus() override
void fillTaskEntryList(const TaskEntryList &_rList)
fills the Creation listbox with the necessary strings and images
OApplicationDetailView * getDetailView() const
std::unique_ptr< weld::Label > m_xDescription
virtual bool HasChildPathFocus() const override
std::unique_ptr< weld::TextView > m_xHelpText
std::unique_ptr< weld::TreeView > m_xTreeView
#define DBA_RES(id)
constexpr OUStringLiteral HID_APP_DESCRIPTION_TEXT
Definition: helpids.h:95
constexpr OUStringLiteral HID_APP_CREATION_LIST
Definition: helpids.h:90
constexpr OUStringLiteral HID_APP_HELP_TEXT
Definition: helpids.h:94
sal_Int32 nIndex
@ Exception
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
@ E_ELEMENT_TYPE_COUNT
std::vector< TaskEntry > TaskEntryList
SwView * getView(const uno::Reference< frame::XModel > &xModel)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
OUString toId(const void *pValue)
Reference< XNameAccess > m_xContainer
Definition: objectnames.cxx:80
TaskEntryList aTasks
the tasks available in the pane
TranslateId pTitleId
the resource ID for the title of the pane
OUString aCommand
OUString sId
Definition: unodatbr.cxx:1040