LibreOffice Module extensions (master) 1
datman.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 <sal/config.h>
21
22#include <o3tl/any.hxx>
23#include <sal/log.hxx>
26#include <com/sun/star/sdbc/ResultSetType.hpp>
27#include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
28#include <com/sun/star/sdbcx/XRowLocate.hpp>
29#include <com/sun/star/sdbc/DataType.hpp>
30#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
31#include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
32#include <com/sun/star/sdbc/XDataSource.hpp>
33#include <com/sun/star/sdb/CommandType.hpp>
34#include <com/sun/star/sdb/DatabaseContext.hpp>
35#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
36#include <com/sun/star/sdbc/XConnection.hpp>
37#include <com/sun/star/sdb/XCompletedConnection.hpp>
38#include <com/sun/star/sdbc/SQLException.hpp>
39#include <com/sun/star/task/InteractionHandler.hpp>
40#include <com/sun/star/form/ListSourceType.hpp>
41#include <com/sun/star/form/XLoadable.hpp>
42#include <com/sun/star/form/runtime/FormController.hpp>
43#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
44#include <com/sun/star/form/XGridColumnFactory.hpp>
45#include <com/sun/star/lang/XMultiServiceFactory.hpp>
46#include <com/sun/star/container/XNameContainer.hpp>
47#include <tools/debug.hxx>
48#include <tools/urlobj.hxx>
49#include <vcl/weld.hxx>
50#include "datman.hxx"
51#include "bibresid.hxx"
52#include "bibmod.hxx"
53#include "bibview.hxx"
54#include "toolbar.hxx"
55#include "bibconfig.hxx"
56#include "bibbeam.hxx"
57#include "general.hxx"
58#include <strings.hrc>
59#include <helpids.h>
61#include <memory>
62
63using namespace ::com::sun::star;
64using namespace ::com::sun::star::beans;
65using namespace ::com::sun::star::container;
66using namespace ::com::sun::star::uno;
67using namespace ::com::sun::star::sdb;
68using namespace ::com::sun::star::sdbc;
69using namespace ::com::sun::star::sdbcx;
70using namespace ::com::sun::star::form;
71using namespace ::com::sun::star::frame;
72using namespace ::com::sun::star::lang;
73
74// PropertyNames
75constexpr OUStringLiteral FM_PROP_LABEL = u"Label";
76constexpr OUStringLiteral FM_PROP_CONTROLSOURCE = u"DataField";
77constexpr OUStringLiteral FM_PROP_NAME = u"Name";
78
79static Reference< XConnection > getConnection(const OUString& _rURL)
80{
81 // first get the sdb::DataSource corresponding to the url
82 Reference< XDataSource > xDataSource;
83 // is it a favorite title ?
84 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
85 Reference< XDatabaseContext > xNamingContext = DatabaseContext::create(xContext);
86 if (xNamingContext->hasByName(_rURL))
87 {
88 DBG_ASSERT(xNamingContext.is(), "::getDataSource : no NamingService interface on the sdb::DatabaseAccessContext !");
89 try
90 {
91 xDataSource.set(xNamingContext->getRegisteredObject(_rURL), UNO_QUERY);
92 }
93 catch (const Exception&)
94 {
95 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
96 }
97 }
98 // build the connection from the data source
99 Reference< XConnection > xConn;
100 if (xDataSource.is())
101 {
102 // need user/pwd for this
103 Reference< XCompletedConnection > xComplConn(xDataSource, UNO_QUERY);
104 try
105 {
106 Reference<task::XInteractionHandler> xIHdl( task::InteractionHandler::createWithParent(xContext, nullptr), UNO_QUERY_THROW);
107 xConn = xComplConn->connectWithCompletion(xIHdl);
108 }
109 catch (const SQLException&)
110 {
111 // TODO : a real error handling
112 }
113 catch (const Exception&)
114 {
115 }
116 }
117 return xConn;
118}
119
120static Reference< XConnection > getConnection(const Reference< XInterface > & xRowSet)
121{
122 Reference< XConnection > xConn;
123 try
124 {
125 Reference< XPropertySet > xFormProps(xRowSet, UNO_QUERY);
126 if (!xFormProps.is())
127 return xConn;
128
129 xConn.set(xFormProps->getPropertyValue("ActiveConnection"), UNO_QUERY);
130 if (!xConn.is())
131 {
132 SAL_INFO("extensions.biblio", "no active connection");
133 }
134 }
135 catch (const Exception&)
136 {
137 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
138 }
139
140 return xConn;
141}
142
143static Reference< XNameAccess > getColumns(const Reference< XForm > & _rxForm)
144{
145 Reference< XNameAccess > xReturn;
146 // check if the form is alive
147 Reference< XColumnsSupplier > xSupplyCols( _rxForm, UNO_QUERY );
148 if (xSupplyCols.is())
149 xReturn = xSupplyCols->getColumns();
150
151 if (!xReturn.is() || !xReturn->getElementNames().hasElements())
152 { // no...
153 xReturn = nullptr;
154 // -> get the table the form is bound to and ask it for their columns
155 Reference< XTablesSupplier > xSupplyTables( getConnection( _rxForm ), UNO_QUERY );
156 Reference< XPropertySet > xFormProps( _rxForm, UNO_QUERY );
157 if (xFormProps.is() && xSupplyTables.is())
158 {
159 try
160 {
161 DBG_ASSERT(*o3tl::forceAccess<sal_Int32>(xFormProps->getPropertyValue("CommandType")) == CommandType::TABLE,
162 "::getColumns : invalid form (has no table as data source) !");
163 OUString sTable;
164 xFormProps->getPropertyValue("Command") >>= sTable;
165 Reference< XNameAccess > xTables = xSupplyTables->getTables();
166 if (xTables.is() && xTables->hasByName(sTable))
167 xSupplyCols.set(xTables->getByName(sTable), UNO_QUERY);
168 if (xSupplyCols.is())
169 xReturn = xSupplyCols->getColumns();
170 }
171 catch (const Exception&)
172 {
173 TOOLS_WARN_EXCEPTION( "extensions.biblio", "::getColumns");
174 }
175
176 }
177 }
178 return xReturn;
179}
180
181namespace {
182
183class MappingDialog_Impl : public weld::GenericDialogController
184{
185 BibDataManager* pDatMan;
186
187 OUString sNone;
188 bool bModified;
189
190 std::unique_ptr<weld::Button> m_xOKBT;
191 std::unique_ptr<weld::ComboBox> m_xIdentifierLB;
192 std::unique_ptr<weld::ComboBox> m_xAuthorityTypeLB;
193 std::unique_ptr<weld::ComboBox> m_xAuthorLB;
194 std::unique_ptr<weld::ComboBox> m_xTitleLB;
195 std::unique_ptr<weld::ComboBox> m_xMonthLB;
196 std::unique_ptr<weld::ComboBox> m_xYearLB;
197 std::unique_ptr<weld::ComboBox> m_xISBNLB;
198 std::unique_ptr<weld::ComboBox> m_xBooktitleLB;
199 std::unique_ptr<weld::ComboBox> m_xChapterLB;
200 std::unique_ptr<weld::ComboBox> m_xEditionLB;
201 std::unique_ptr<weld::ComboBox> m_xEditorLB;
202 std::unique_ptr<weld::ComboBox> m_xHowpublishedLB;
203 std::unique_ptr<weld::ComboBox> m_xInstitutionLB;
204 std::unique_ptr<weld::ComboBox> m_xJournalLB;
205 std::unique_ptr<weld::ComboBox> m_xNoteLB;
206 std::unique_ptr<weld::ComboBox> m_xAnnoteLB;
207 std::unique_ptr<weld::ComboBox> m_xNumberLB;
208 std::unique_ptr<weld::ComboBox> m_xOrganizationsLB;
209 std::unique_ptr<weld::ComboBox> m_xPagesLB;
210 std::unique_ptr<weld::ComboBox> m_xPublisherLB;
211 std::unique_ptr<weld::ComboBox> m_xAddressLB;
212 std::unique_ptr<weld::ComboBox> m_xSchoolLB;
213 std::unique_ptr<weld::ComboBox> m_xSeriesLB;
214 std::unique_ptr<weld::ComboBox> m_xReportTypeLB;
215 std::unique_ptr<weld::ComboBox> m_xVolumeLB;
216 std::unique_ptr<weld::ComboBox> m_xURLLB;
217 std::unique_ptr<weld::ComboBox> m_xCustom1LB;
218 std::unique_ptr<weld::ComboBox> m_xCustom2LB;
219 std::unique_ptr<weld::ComboBox> m_xCustom3LB;
220 std::unique_ptr<weld::ComboBox> m_xCustom4LB;
221 std::unique_ptr<weld::ComboBox> m_xCustom5LB;
222 std::unique_ptr<weld::ComboBox> m_xLocalURLLB;
223 weld::ComboBox* aListBoxes[COLUMN_COUNT];
224
225 DECL_LINK(OkHdl, weld::Button&, void);
226 DECL_LINK(ListBoxSelectHdl, weld::ComboBox&, void);
227
228public:
229 MappingDialog_Impl(weld::Window* pParent, BibDataManager* pDatMan);
230};
231
232}
233
234static sal_uInt16 lcl_FindLogicalName(BibConfig const * pConfig ,
235 std::u16string_view rLogicalColumnName)
236{
237 for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
238 {
239 if(rLogicalColumnName == pConfig->GetDefColumnName(i))
240 return i;
241 }
242 return USHRT_MAX;
243}
244
245MappingDialog_Impl::MappingDialog_Impl(weld::Window* pParent, BibDataManager* pMan)
246 : GenericDialogController(pParent, "modules/sbibliography/ui/mappingdialog.ui", "MappingDialog")
247 , pDatMan(pMan)
248 , sNone(BibResId(RID_BIB_STR_NONE))
249 , bModified(false)
250 , m_xOKBT(m_xBuilder->weld_button("ok"))
251 , m_xIdentifierLB(m_xBuilder->weld_combo_box("identifierCombobox"))
252 , m_xAuthorityTypeLB(m_xBuilder->weld_combo_box("authorityTypeCombobox"))
253 , m_xAuthorLB(m_xBuilder->weld_combo_box("authorCombobox"))
254 , m_xTitleLB(m_xBuilder->weld_combo_box("titleCombobox"))
255 , m_xMonthLB(m_xBuilder->weld_combo_box("monthCombobox"))
256 , m_xYearLB(m_xBuilder->weld_combo_box("yearCombobox"))
257 , m_xISBNLB(m_xBuilder->weld_combo_box("ISBNCombobox"))
258 , m_xBooktitleLB(m_xBuilder->weld_combo_box("bookTitleCombobox"))
259 , m_xChapterLB(m_xBuilder->weld_combo_box("chapterCombobox"))
260 , m_xEditionLB(m_xBuilder->weld_combo_box("editionCombobox"))
261 , m_xEditorLB(m_xBuilder->weld_combo_box("editorCombobox"))
262 , m_xHowpublishedLB(m_xBuilder->weld_combo_box("howPublishedCombobox"))
263 , m_xInstitutionLB(m_xBuilder->weld_combo_box("institutionCombobox"))
264 , m_xJournalLB(m_xBuilder->weld_combo_box("journalCombobox"))
265 , m_xNoteLB(m_xBuilder->weld_combo_box("noteCombobox"))
266 , m_xAnnoteLB(m_xBuilder->weld_combo_box("annoteCombobox"))
267 , m_xNumberLB(m_xBuilder->weld_combo_box("numberCombobox"))
268 , m_xOrganizationsLB(m_xBuilder->weld_combo_box("organizationCombobox"))
269 , m_xPagesLB(m_xBuilder->weld_combo_box("pagesCombobox"))
270 , m_xPublisherLB(m_xBuilder->weld_combo_box("publisherCombobox"))
271 , m_xAddressLB(m_xBuilder->weld_combo_box("addressCombobox"))
272 , m_xSchoolLB(m_xBuilder->weld_combo_box("schoolCombobox"))
273 , m_xSeriesLB(m_xBuilder->weld_combo_box("seriesCombobox"))
274 , m_xReportTypeLB(m_xBuilder->weld_combo_box("reportTypeCombobox"))
275 , m_xVolumeLB(m_xBuilder->weld_combo_box("volumeCombobox"))
276 , m_xURLLB(m_xBuilder->weld_combo_box("URLCombobox"))
277 , m_xCustom1LB(m_xBuilder->weld_combo_box("custom1Combobox"))
278 , m_xCustom2LB(m_xBuilder->weld_combo_box("custom2Combobox"))
279 , m_xCustom3LB(m_xBuilder->weld_combo_box("custom3Combobox"))
280 , m_xCustom4LB(m_xBuilder->weld_combo_box("custom4Combobox"))
281 , m_xCustom5LB(m_xBuilder->weld_combo_box("custom5Combobox"))
282 , m_xLocalURLLB(m_xBuilder->weld_combo_box("LocalURLCombobox"))
283{
284 m_xOKBT->connect_clicked(LINK(this, MappingDialog_Impl, OkHdl));
285 OUString sTitle = m_xDialog->get_title();
286 sTitle = sTitle.replaceFirst("%1", pDatMan->getActiveDataTable());
287 m_xDialog->set_title(sTitle);
288
289 aListBoxes[0] = m_xIdentifierLB.get();
290 aListBoxes[1] = m_xAuthorityTypeLB.get();
291 aListBoxes[2] = m_xAuthorLB.get();
292 aListBoxes[3] = m_xTitleLB.get();
293 aListBoxes[4] = m_xYearLB.get();
294 aListBoxes[5] = m_xISBNLB.get();
295 aListBoxes[6] = m_xBooktitleLB.get();
296 aListBoxes[7] = m_xChapterLB.get();
297 aListBoxes[8] = m_xEditionLB.get();
298 aListBoxes[9] = m_xEditorLB.get();
299 aListBoxes[10] = m_xHowpublishedLB.get();
300 aListBoxes[11] = m_xInstitutionLB.get();
301 aListBoxes[12] = m_xJournalLB.get();
302 aListBoxes[13] = m_xMonthLB.get();
303 aListBoxes[14] = m_xNoteLB.get();
304 aListBoxes[15] = m_xAnnoteLB.get();
305 aListBoxes[16] = m_xNumberLB.get();
306 aListBoxes[17] = m_xOrganizationsLB.get();
307 aListBoxes[18] = m_xPagesLB.get();
308 aListBoxes[19] = m_xPublisherLB.get();
309 aListBoxes[20] = m_xAddressLB.get();
310 aListBoxes[21] = m_xSchoolLB.get();
311 aListBoxes[22] = m_xSeriesLB.get();
312 aListBoxes[23] = m_xReportTypeLB.get();
313 aListBoxes[24] = m_xVolumeLB.get();
314 aListBoxes[25] = m_xURLLB.get();
315 aListBoxes[26] = m_xCustom1LB.get();
316 aListBoxes[27] = m_xCustom2LB.get();
317 aListBoxes[28] = m_xCustom3LB.get();
318 aListBoxes[29] = m_xCustom4LB.get();
319 aListBoxes[30] = m_xCustom5LB.get();
320 aListBoxes[31] = m_xLocalURLLB.get();
321
322 aListBoxes[0]->append_text(sNone);
323 Reference< XNameAccess > xFields = getColumns( pDatMan->getForm() );
324 DBG_ASSERT(xFields.is(), "MappingDialog_Impl::MappingDialog_Impl : gave me an invalid form !");
325 if (xFields.is())
326 {
327 const Sequence<OUString> aFieldNames = xFields->getElementNames();
328 for(const OUString& rName : aFieldNames)
329 aListBoxes[0]->append_text(rName);
330 }
331
332 Link<weld::ComboBox&,void> aLnk = LINK(this, MappingDialog_Impl, ListBoxSelectHdl);
333
334 aListBoxes[0]->set_active(0);
335 aListBoxes[0]->connect_changed(aLnk);
336 for(sal_uInt16 i = 1; i < COLUMN_COUNT; i++)
337 {
338 for(sal_Int32 j = 0, nEntryCount = aListBoxes[0]->get_count(); j < nEntryCount; ++j)
339 aListBoxes[i]->append_text(aListBoxes[0]->get_text(j));
340 aListBoxes[i]->set_active(0);
341 aListBoxes[i]->connect_changed(aLnk);
342 }
343 BibConfig* pConfig = BibModul::GetConfig();
344 BibDBDescriptor aDesc;
345 aDesc.sDataSource = pDatMan->getActiveDataSource();
346 aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
347 aDesc.nCommandType = CommandType::TABLE;
348 const Mapping* pMapping = pConfig->GetMapping(aDesc);
349 if(pMapping)
350 {
351 for(const auto & aColumnPair : pMapping->aColumnPairs)
352 {
353 sal_uInt16 nListBoxIndex = lcl_FindLogicalName( pConfig, aColumnPair.sLogicalColumnName);
354 if(nListBoxIndex < COLUMN_COUNT)
355 {
356 aListBoxes[nListBoxIndex]->set_active_text(aColumnPair.sRealColumnName);
357 }
358 }
359 }
360}
361
362IMPL_LINK(MappingDialog_Impl, ListBoxSelectHdl, weld::ComboBox&, rListBox, void)
363{
364 const sal_Int32 nEntryPos = rListBox.get_active();
365 if (0 < nEntryPos)
366 {
367 for(auto & pListBoxe : aListBoxes)
368 {
369 if (&rListBox != pListBoxe && pListBoxe->get_active() == nEntryPos)
370 pListBoxe->set_active(0);
371 }
372 }
373 bModified = true;
374}
375
376IMPL_LINK_NOARG(MappingDialog_Impl, OkHdl, weld::Button&, void)
377{
378 if(bModified)
379 {
380 Mapping aNew;
381 aNew.sTableName = pDatMan->getActiveDataTable();
382 aNew.sURL = pDatMan->getActiveDataSource();
383
384 sal_uInt16 nWriteIndex = 0;
385 BibConfig* pConfig = BibModul::GetConfig();
386 for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
387 {
388 OUString sSel = aListBoxes[nEntry]->get_active_text();
389 if(sSel != sNone)
390 {
391 aNew.aColumnPairs[nWriteIndex].sRealColumnName = sSel;
392 aNew.aColumnPairs[nWriteIndex].sLogicalColumnName = pConfig->GetDefColumnName(nEntry);
393 nWriteIndex++;
394 }
395 }
396 BibDBDescriptor aDesc;
397 aDesc.sDataSource = pDatMan->getActiveDataSource();
398 aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
399 aDesc.nCommandType = CommandType::TABLE;
400 pDatMan->ResetIdentifierMapping();
401 pConfig->SetMapping(aDesc, &aNew);
402 }
403 m_xDialog->response(bModified ? RET_OK : RET_CANCEL);
404}
405
406namespace {
407
408class DBChangeDialog_Impl : public weld::GenericDialogController
409{
411
412 std::unique_ptr<weld::TreeView> m_xSelectionLB;
413
414 DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
415public:
416 DBChangeDialog_Impl(weld::Window* pParent, const BibDataManager* pMan);
417
418 OUString GetCurrentURL()const;
419};
420
421}
422
423DBChangeDialog_Impl::DBChangeDialog_Impl(weld::Window* pParent, const BibDataManager* pDatMan )
424 : GenericDialogController(pParent, "modules/sbibliography/ui/choosedatasourcedialog.ui", "ChooseDataSourceDialog")
425 , m_xSelectionLB(m_xBuilder->weld_tree_view("treeview"))
426{
427 m_xSelectionLB->set_size_request(-1, m_xSelectionLB->get_height_rows(6));
428 m_xSelectionLB->connect_row_activated(LINK(this, DBChangeDialog_Impl, DoubleClickHdl));
429 m_xSelectionLB->make_sorted();
430
431 try
432 {
433 OUString sActiveSource = pDatMan->getActiveDataSource();
434 for (const OUString& rSourceName : aConfig.GetDataSourceNames())
435 m_xSelectionLB->append_text(rSourceName);
436 m_xSelectionLB->select_text(sActiveSource);
437 }
438 catch (const Exception&)
439 {
440 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
441 }
442}
443
444IMPL_LINK_NOARG(DBChangeDialog_Impl, DoubleClickHdl, weld::TreeView&, bool)
445{
446 m_xDialog->response(RET_OK);
447 return true;
448}
449
450OUString DBChangeDialog_Impl::GetCurrentURL()const
451{
452 return m_xSelectionLB->get_selected_text();
453}
454
455// XDispatchProvider
456BibInterceptorHelper::BibInterceptorHelper( const ::bib::BibBeamer* pBibBeamer, css::uno::Reference< css::frame::XDispatch > const & xDispatch)
457{
458 if( pBibBeamer )
459 {
460 xInterception = pBibBeamer->getDispatchProviderInterception();
461 if( xInterception.is() )
462 xInterception->registerDispatchProviderInterceptor( this );
463 }
464 if( xDispatch.is() )
466}
467
469{
470}
471
473{
474 if ( xInterception.is() )
475 xInterception->releaseDispatchProviderInterceptor( this );
476 xInterception.clear();
477}
478
479css::uno::Reference< css::frame::XDispatch > SAL_CALL
480 BibInterceptorHelper::queryDispatch( const css::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
481{
482 Reference< XDispatch > xReturn;
483
484 OUString aCommand( aURL.Path );
485 if ( aCommand == "FormSlots/ConfirmDeletion" )
486 xReturn = xFormDispatch;
487 else
488 if ( xSlaveDispatchProvider.is() )
489 xReturn = xSlaveDispatchProvider->queryDispatch( aURL, aTargetFrameName, nSearchFlags);
490
491 return xReturn;
492}
493
494css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL
495 BibInterceptorHelper::queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& aDescripts )
496{
497 Sequence< Reference< XDispatch> > aReturn( aDescripts.getLength() );
498 Reference< XDispatch >* pReturn = aReturn.getArray();
499 for ( const DispatchDescriptor& rDescript : aDescripts )
500 {
501 *pReturn++ = queryDispatch( rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags );
502 }
503 return aReturn;
504}
505
506// XDispatchProviderInterceptor
507css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL
509{
511}
512
513void SAL_CALL BibInterceptorHelper::setSlaveDispatchProvider( const css::uno::Reference< css::frame::XDispatchProvider >& xNewSlaveDispatchProvider )
514{
515 xSlaveDispatchProvider = xNewSlaveDispatchProvider;
516}
517
518css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL
520{
522}
523
524void SAL_CALL BibInterceptorHelper::setMasterDispatchProvider( const css::uno::Reference< css::frame::XDispatchProvider >& xNewMasterDispatchProvider )
525{
526 xMasterDispatchProvider = xNewMasterDispatchProvider;
527}
528
529
530constexpr OUStringLiteral gGridName(u"theGrid");
531
533 :pBibView( nullptr )
534 ,pToolbar(nullptr)
535{
536}
537
538
540{
541 Reference< XLoadable > xLoad( m_xForm, UNO_QUERY );
542 Reference< XPropertySet > xPrSet( m_xForm, UNO_QUERY );
543 Reference< XComponent > xComp( m_xForm, UNO_QUERY );
544 if ( m_xForm.is() )
545 {
546 Reference< XComponent > xConnection;
547 xPrSet->getPropertyValue("ActiveConnection") >>= xConnection;
548 if (xLoad.is())
549 xLoad->unload();
550 if (xComp.is())
551 xComp->dispose();
552 if(xConnection.is())
553 xConnection->dispose();
554 m_xForm = nullptr;
555 }
556 if( m_xInterceptorHelper.is() )
557 {
558 m_xInterceptorHelper->ReleaseInterceptor();
559 m_xInterceptorHelper.clear();
560 }
561}
562
563void BibDataManager::InsertFields(const Reference< XFormComponent > & _rxGrid)
564{
565 if ( !_rxGrid.is() )
566 return;
567
568 try
569 {
570 Reference< XNameContainer > xColContainer( _rxGrid, UNO_QUERY );
571 // remove the old fields
572 if ( xColContainer->hasElements() )
573 {
574 const Sequence<OUString> aOldNames = xColContainer->getElementNames();
575 for ( const OUString& rName : aOldNames )
576 xColContainer->removeByName( rName );
577 }
578
579 Reference< XNameAccess > xFields = getColumns( m_xForm );
580 if (!xFields.is())
581 return;
582
583 Reference< XGridColumnFactory > xColFactory( _rxGrid, UNO_QUERY );
584
585 Reference< XPropertySet > xField;
586
587 const Sequence<OUString> aFieldNames = xFields->getElementNames();
588 for ( const OUString& rField : aFieldNames )
589 {
590 xFields->getByName( rField ) >>= xField;
591
592 OUString sCurrentModelType;
593 sal_Int32 nType = 0;
594 bool bIsFormatted = false;
595 bool bFormattedIsNumeric = true;
596 xField->getPropertyValue("Type") >>= nType;
597 switch(nType)
598 {
599 case DataType::BIT:
600 case DataType::BOOLEAN:
601 sCurrentModelType = "CheckBox";
602 break;
603
604 case DataType::BINARY:
605 case DataType::VARBINARY:
606 case DataType::LONGVARBINARY:
607 case DataType::BLOB:
608 sCurrentModelType = "TextField";
609 break;
610
611 case DataType::VARCHAR:
612 case DataType::LONGVARCHAR:
613 case DataType::CHAR:
614 case DataType::CLOB:
615 bFormattedIsNumeric = false;
616 [[fallthrough]];
617 default:
618 sCurrentModelType = "FormattedField";
619 bIsFormatted = true;
620 break;
621 }
622
623 Reference< XPropertySet > xCurrentCol = xColFactory->createColumn(sCurrentModelType);
624 if (bIsFormatted)
625 {
626 OUString sFormatKey("FormatKey");
627 xCurrentCol->setPropertyValue(sFormatKey, xField->getPropertyValue(sFormatKey));
628 Any aFormatted(bFormattedIsNumeric);
629 xCurrentCol->setPropertyValue("TreatAsNumber", aFormatted);
630 }
631 Any aColName( rField );
632 xCurrentCol->setPropertyValue(FM_PROP_CONTROLSOURCE, aColName);
633 xCurrentCol->setPropertyValue(FM_PROP_LABEL, aColName);
634
635 xColContainer->insertByName( rField, Any( xCurrentCol ) );
636 }
637 }
638 catch (const Exception&)
639 {
640 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
641 }
642}
643
644Reference< awt::XControlModel > BibDataManager::updateGridModel()
645{
646 return updateGridModel( m_xForm );
647}
648
649Reference< awt::XControlModel > const & BibDataManager::updateGridModel(const Reference< XForm > & xDbForm)
650{
651 try
652 {
653 Reference< XPropertySet > aFormPropSet( xDbForm, UNO_QUERY );
654 OUString sName;
655 aFormPropSet->getPropertyValue("Command") >>= sName;
656
657 if ( !m_xGridModel.is() )
658 {
660
661 Reference< XNameContainer > xNameCont(xDbForm, UNO_QUERY);
662 xNameCont->insertByName( sName, Any( m_xGridModel ) );
663 }
664
665 // insert the fields
666 Reference< XFormComponent > xFormComp( m_xGridModel, UNO_QUERY );
667 InsertFields( xFormComp );
668 }
669 catch (const Exception&)
670 {
671 OSL_FAIL("::updateGridModel: something went wrong !");
672 }
673
674 return m_xGridModel;
675}
676
678{
679 Reference< XForm > xResult;
680 try
681 {
683 m_xForm.set( xMgr->createInstance( "com.sun.star.form.component.Form" ), UNO_QUERY );
684
685 Reference< XPropertySet > aPropertySet( m_xForm, UNO_QUERY );
686
688 if(aPropertySet.is())
689 {
690 Any aVal;
691 aVal <<= sal_Int32(ResultSetType::SCROLL_INSENSITIVE);
692 aPropertySet->setPropertyValue("ResultSetType",aVal );
693 aVal <<= sal_Int32(ResultSetConcurrency::READ_ONLY);
694 aPropertySet->setPropertyValue("ResultSetConcurrency", aVal);
695
696 //Caching for Performance
697 aVal <<= sal_Int32(50);
698 aPropertySet->setPropertyValue("FetchSize", aVal);
699
700 Reference< XConnection > xConnection = getConnection(rDesc.sDataSource);
701 aVal <<= xConnection;
702 aPropertySet->setPropertyValue("ActiveConnection", aVal);
703
704 Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
705 Reference< XNameAccess > xTables = xSupplyTables.is() ?
706 xSupplyTables->getTables() : Reference< XNameAccess > ();
707
708 Sequence< OUString > aTableNameSeq;
709 if (xTables.is())
710 aTableNameSeq = xTables->getElementNames();
711
712 if(aTableNameSeq.hasElements())
713 {
714 if(!rDesc.sTableOrQuery.isEmpty())
716 else
717 {
718 rDesc.sTableOrQuery = aActiveDataTable = aTableNameSeq[0];
719 rDesc.nCommandType = CommandType::TABLE;
720 }
721
722 aVal <<= aActiveDataTable;
723 aPropertySet->setPropertyValue("Command", aVal);
724 aVal <<= rDesc.nCommandType;
725 aPropertySet->setPropertyValue("CommandType", aVal);
726
727
728 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
729 aQuoteChar = xMetaData->getIdentifierQuoteString();
730
731 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
732 if ( xFactory.is() )
733 m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
734
735 OUString aString("SELECT * FROM ");
736
737 OUString sCatalog, sSchema, sName;
738 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation );
739 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
740
741 m_xParser->setElementaryQuery(aString);
742 BibConfig* pConfig = BibModul::GetConfig();
743 pConfig->setQueryField(getQueryField());
744 startQueryWith(pConfig->getQueryText());
745
746 xResult = m_xForm;
747 }
748 }
749 }
750 catch (const Exception&)
751 {
752 OSL_FAIL("::createDatabaseForm: something went wrong !");
753 }
754
755 return xResult;
756}
757
758Sequence< OUString > BibDataManager::getDataSources() const
759{
760 Sequence< OUString > aTableNameSeq;
761
762 try
763 {
764 Reference< XTablesSupplier > xSupplyTables( getConnection( m_xForm ), UNO_QUERY );
765 Reference< XNameAccess > xTables;
766 if (xSupplyTables.is())
767 xTables = xSupplyTables->getTables();
768 if (xTables.is())
769 aTableNameSeq = xTables->getElementNames();
770 }
771 catch (const Exception&)
772 {
773 OSL_FAIL("::getDataSources: something went wrong !");
774 }
775
776 return aTableNameSeq;
777}
778
779
780void BibDataManager::setFilter(const OUString& rQuery)
781{
782 if(!m_xParser.is())
783 return;
784 try
785 {
786 m_xParser->setFilter( rQuery );
787 OUString aQuery = m_xParser->getFilter();
788 Reference< XPropertySet > xFormProps( m_xForm, UNO_QUERY_THROW );
789 xFormProps->setPropertyValue( "Filter", Any( aQuery ) );
790 xFormProps->setPropertyValue( "ApplyFilter", Any( true ) );
791 reload();
792 }
793 catch (const Exception&)
794 {
795 DBG_UNHANDLED_EXCEPTION("extensions.biblio");
796 }
797
798
799}
800
802{
803
804 OUString aQueryString;
805 try
806 {
807 Reference< XPropertySet > xFormProps( m_xForm, UNO_QUERY_THROW );
808 OSL_VERIFY( xFormProps->getPropertyValue( "Filter" ) >>= aQueryString );
809 }
810 catch (const Exception&)
811 {
812 DBG_UNHANDLED_EXCEPTION("extensions.biblio");
813 }
814
815
816 return aQueryString;
817
818}
819
820Sequence< OUString > BibDataManager::getQueryFields() const
821{
822 Sequence< OUString > aFieldSeq;
823 Reference< XNameAccess > xFields = getColumns( m_xForm );
824 if (xFields.is())
825 aFieldSeq = xFields->getElementNames();
826 return aFieldSeq;
827}
828
830{
831 BibConfig* pConfig = BibModul::GetConfig();
832 OUString aFieldString = pConfig->getQueryField();
833 if(aFieldString.isEmpty())
834 {
835 const Sequence< OUString > aSeq = getQueryFields();
836 if(aSeq.hasElements())
837 {
838 aFieldString=aSeq[0];
839 }
840 }
841 return aFieldString;
842}
843
844void BibDataManager::startQueryWith(const OUString& rQuery)
845{
846 BibConfig* pConfig = BibModul::GetConfig();
847 pConfig->setQueryText( rQuery );
848
849 OUString aQueryString;
850 if(!rQuery.isEmpty())
851 {
852 aQueryString=aQuoteChar + getQueryField() + aQuoteChar + " like '";
853 OUString sQuery = rQuery.replaceAll("?","_").replaceAll("*","%");
854 aQueryString += sQuery + "%'";
855 }
856 setFilter(aQueryString);
857}
858
859void BibDataManager::setActiveDataSource(const OUString& rURL)
860{
861 OUString sTmp(aDataSourceURL);
862 aDataSourceURL = rURL;
863
864 Reference< XPropertySet > aPropertySet( m_xForm, UNO_QUERY );
865 if(!aPropertySet.is())
866 return;
867
868 unload();
869
870 Reference< XComponent > xOldConnection;
871 aPropertySet->getPropertyValue("ActiveConnection") >>= xOldConnection;
872
873 Reference< XConnection > xConnection = getConnection(rURL);
874 if(!xConnection.is())
875 {
876 aDataSourceURL = sTmp;
877 return;
878 }
879 Any aVal; aVal <<= xConnection;
880 aPropertySet->setPropertyValue("ActiveConnection", aVal);
881 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
882 if ( xFactory.is() )
883 m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
884
885 if(xOldConnection.is())
886 xOldConnection->dispose();
887
888 Sequence< OUString > aTableNameSeq;
889 Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
890 if(xSupplyTables.is())
891 {
892 Reference< XNameAccess > xAccess = xSupplyTables->getTables();
893 aTableNameSeq = xAccess->getElementNames();
894 }
895 if(aTableNameSeq.hasElements())
896 {
897 aActiveDataTable = aTableNameSeq[0];
898 aVal <<= aActiveDataTable;
899 aPropertySet->setPropertyValue("Command", aVal);
900 aPropertySet->setPropertyValue("CommandType", Any(CommandType::TABLE));
901 //Caching for Performance
902 aVal <<= sal_Int32(50);
903 aPropertySet->setPropertyValue("FetchSize", aVal);
904 OUString aString("SELECT * FROM ");
905 // quote the table name which may contain catalog.schema.table
906 Reference<XDatabaseMetaData> xMetaData = xConnection->getMetaData();
907 aQuoteChar = xMetaData->getIdentifierQuoteString();
908
909 OUString sCatalog, sSchema, sName;
910 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation );
911 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
912
913 m_xParser->setElementaryQuery(aString);
914 BibConfig* pConfig = BibModul::GetConfig();
915 pConfig->setQueryField(getQueryField());
916 startQueryWith(pConfig->getQueryText());
918 }
919 FeatureStateEvent aEvent;
920 util::URL aURL;
921 aEvent.IsEnabled = true;
922 aEvent.Requery = false;
923 aEvent.FeatureDescriptor = getActiveDataTable();
924
925 aEvent.State <<= getDataSources();
926
927 if(pToolbar)
928 {
929 aURL.Complete =".uno:Bib/source";
930 aEvent.FeatureURL = aURL;
931 pToolbar->statusChanged( aEvent );
932 }
933
935 load();
936}
937
938
939void BibDataManager::setActiveDataTable(const OUString& rTable)
940{
942 try
943 {
944 Reference< XPropertySet > aPropertySet( m_xForm, UNO_QUERY );
945
946 if(aPropertySet.is())
947 {
948 Reference< XConnection > xConnection = getConnection( m_xForm );
949 Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
950 Reference< XNameAccess > xAccess = xSupplyTables->getTables();
951 Sequence< OUString > aTableNameSeq = xAccess->getElementNames();
952 sal_uInt32 nCount = aTableNameSeq.getLength();
953
954 const OUString* pTableNames = aTableNameSeq.getConstArray();
955 const OUString* pTableNamesEnd = pTableNames + nCount;
956
957 for ( ; pTableNames != pTableNamesEnd; ++pTableNames )
958 {
959 if ( rTable == *pTableNames )
960 {
961 aActiveDataTable = rTable;
962 Any aVal; aVal <<= rTable;
963 aPropertySet->setPropertyValue( "Command", aVal );
964 break;
965 }
966 }
967 if (pTableNames != pTableNamesEnd)
968 {
969 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
970 aQuoteChar = xMetaData->getIdentifierQuoteString();
971
972 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
973 if ( xFactory.is() )
974 m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
975
976 OUString aString("SELECT * FROM ");
977
978 OUString sCatalog, sSchema, sName;
979 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation );
980 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
981
982 m_xParser->setElementaryQuery(aString);
983
984 BibConfig* pConfig = BibModul::GetConfig();
985 pConfig->setQueryField(getQueryField());
986 startQueryWith(pConfig->getQueryText());
987
988 BibDBDescriptor aDesc;
991 aDesc.nCommandType = CommandType::TABLE;
993 }
994 }
995 }
996 catch (const Exception&)
997 {
998 OSL_FAIL("::setActiveDataTable: something went wrong !");
999 }
1000}
1001
1002
1003void SAL_CALL BibDataManager::load( )
1004{
1005 if ( isLoaded() )
1006 // nothing to do
1007 return;
1008
1009 Reference< XLoadable > xFormAsLoadable( m_xForm, UNO_QUERY );
1010 DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::load: invalid form!");
1011 if ( xFormAsLoadable.is() )
1012 {
1013 xFormAsLoadable->load();
1014
1015 std::unique_lock g(m_aMutex);
1016 EventObject aEvt( static_cast< XWeak* >( this ) );
1017 m_aLoadListeners.notifyEach( g, &XLoadListener::loaded, aEvt );
1018 }
1019}
1020
1021
1023{
1024 if ( !isLoaded() )
1025 // nothing to do
1026 return;
1027
1028 Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
1029 DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::unload: invalid form!");
1030 if ( !xFormAsLoadable.is() )
1031 return;
1032
1033 EventObject aEvt( static_cast< XWeak* >( this ) );
1034
1035 {
1036 std::unique_lock g(m_aMutex);
1037 m_aLoadListeners.notifyEach( g, &XLoadListener::unloading, aEvt );
1038 }
1039
1040 xFormAsLoadable->unload();
1041
1042 {
1043 std::unique_lock g(m_aMutex);
1044 m_aLoadListeners.notifyEach( g, &XLoadListener::unloaded, aEvt );
1045 }
1046}
1047
1048
1050{
1051 if ( !isLoaded() )
1052 // nothing to do
1053 return;
1054
1055 Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
1056 DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::unload: invalid form!");
1057 if ( !xFormAsLoadable.is() )
1058 return;
1059
1060 EventObject aEvt( static_cast< XWeak* >( this ) );
1061
1062 {
1063 std::unique_lock g(m_aMutex);
1064 m_aLoadListeners.notifyEach( g, &XLoadListener::reloading, aEvt );
1065 }
1066
1067 xFormAsLoadable->reload();
1068
1069 {
1070 std::unique_lock g(m_aMutex);
1071 m_aLoadListeners.notifyEach( g, &XLoadListener::reloaded, aEvt );
1072 }
1073}
1074
1075
1077{
1078 Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
1079 DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::isLoaded: invalid form!");
1080
1081 bool bLoaded = false;
1082 if ( xFormAsLoadable.is() )
1083 bLoaded = xFormAsLoadable->isLoaded();
1084 return bLoaded;
1085}
1086
1087
1088void SAL_CALL BibDataManager::addLoadListener( const Reference< XLoadListener >& aListener )
1089{
1090 std::unique_lock g(m_aMutex);
1091 m_aLoadListeners.addInterface( g, aListener );
1092}
1093
1094
1095void SAL_CALL BibDataManager::removeLoadListener( const Reference< XLoadListener >& aListener )
1096{
1097 std::unique_lock g(m_aMutex);
1098 m_aLoadListeners.removeInterface( g, aListener );
1099}
1100
1101
1102Reference< awt::XControlModel > BibDataManager::createGridModel(const OUString& rName)
1103{
1104 Reference< awt::XControlModel > xModel;
1105
1106 try
1107 {
1108 // create the control model
1109 Reference< XMultiServiceFactory > xMgr = ::comphelper::getProcessServiceFactory();
1110 Reference< XInterface > xObject = xMgr->createInstance("com.sun.star.form.component.GridControl");
1111 xModel.set( xObject, UNO_QUERY );
1112
1113 // set the
1114 Reference< XPropertySet > xPropSet( xModel, UNO_QUERY );
1115 xPropSet->setPropertyValue( "Name", Any( rName ) );
1116
1117 // set the name of the to-be-created control
1118 Any aAny(OUString("com.sun.star.form.control.InteractionGridControl"));
1119 xPropSet->setPropertyValue( "DefaultControl",aAny );
1120
1121 // the helpURL
1122 OUString uProp("HelpURL");
1123 Reference< XPropertySetInfo > xPropInfo = xPropSet->getPropertySetInfo();
1124 if (xPropInfo->hasPropertyByName(uProp))
1125 {
1126 xPropSet->setPropertyValue(
1127 uProp, Any(OUString(INET_HID_SCHEME + HID_BIB_DB_GRIDCTRL)));
1128 }
1129 }
1130 catch (const Exception&)
1131 {
1132 OSL_FAIL("::createGridModel: something went wrong !");
1133 }
1134
1135 return xModel;
1136}
1137
1138OUString BibDataManager::getControlName(sal_Int32 nFormatKey )
1139{
1140 OUString aResStr;
1141 switch (nFormatKey)
1142 {
1143 case DataType::BIT:
1144 case DataType::BOOLEAN:
1145 aResStr="CheckBox";
1146 break;
1147 case DataType::TINYINT:
1148 case DataType::SMALLINT:
1149 case DataType::INTEGER:
1150 aResStr="NumericField";
1151 break;
1152 case DataType::REAL:
1153 case DataType::DOUBLE:
1154 case DataType::NUMERIC:
1155 case DataType::DECIMAL:
1156 aResStr="FormattedField";
1157 break;
1158 case DataType::TIMESTAMP:
1159 aResStr="FormattedField";
1160 break;
1161 case DataType::DATE:
1162 aResStr="DateField";
1163 break;
1164 case DataType::TIME:
1165 aResStr="TimeField";
1166 break;
1167 case DataType::CHAR:
1168 case DataType::VARCHAR:
1169 case DataType::LONGVARCHAR:
1170 default:
1171 aResStr="TextField";
1172 break;
1173 }
1174 return aResStr;
1175}
1176
1177Reference< awt::XControlModel > BibDataManager::loadControlModel(
1178 const OUString& rName, bool bForceListBox)
1179{
1180 Reference< awt::XControlModel > xModel;
1181 OUString aName = "View_" + rName;
1182
1183 try
1184 {
1185 Reference< XNameAccess > xFields = getColumns( m_xForm );
1186 if (!xFields.is())
1187 return xModel;
1188 Reference< XPropertySet > xField;
1189
1190 Any aElement;
1191
1192 if(xFields->hasByName(rName))
1193 {
1194 aElement = xFields->getByName(rName);
1195 aElement >>= xField;
1196
1197 sal_Int32 nFormatKey = 0;
1198 xField->getPropertyValue("Type") >>= nFormatKey;
1199
1200 OUString aInstanceName("com.sun.star.form.component.");
1201
1202 if (bForceListBox)
1203 aInstanceName += "ListBox";
1204 else
1205 aInstanceName += getControlName(nFormatKey);
1206
1207 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
1208 Reference< XInterface > xObject = xContext->getServiceManager()->createInstanceWithContext(aInstanceName, xContext);
1209 xModel.set( xObject, UNO_QUERY );
1210 Reference< XPropertySet > xPropSet( xModel, UNO_QUERY );
1211 Any aFieldName; aFieldName <<= aName;
1212
1213 xPropSet->setPropertyValue( FM_PROP_NAME,aFieldName);
1214 xPropSet->setPropertyValue( FM_PROP_CONTROLSOURCE, Any( rName ) );
1215 xPropSet->setPropertyValue("NativeWidgetLook", Any( true ) );
1216
1217 if (bForceListBox)
1218 {
1219 uno::Any aAny;
1220
1221 //uno::Reference< beans::XPropertySet > xPropSet(xControl, UNO_QUERY);
1222 aAny <<= sal_Int16(1);
1223 xPropSet->setPropertyValue("BoundColumn", aAny);
1224 aAny <<= ListSourceType_VALUELIST;
1225 xPropSet->setPropertyValue("ListSourceType", aAny);
1226
1227 uno::Sequence<OUString> aListSource(TYPE_COUNT);
1228 OUString* pListSourceArr = aListSource.getArray();
1229 //pListSourceArr[0] = "select TypeName, TypeIndex from TypeNms";
1230 for(sal_Int32 i = 0; i < TYPE_COUNT; ++i)
1231 pListSourceArr[i] = OUString::number(i);
1232 aAny <<= aListSource;
1233
1234 xPropSet->setPropertyValue("ListSource", aAny);
1235
1236 uno::Sequence<OUString> aValues(TYPE_COUNT + 1);
1237 OUString* pValuesArr = aValues.getArray();
1238 pValuesArr[0] = BibResId(ST_TYPE_ARTICLE);
1239 pValuesArr[1] = BibResId(ST_TYPE_BOOK);
1240 pValuesArr[2] = BibResId(ST_TYPE_BOOKLET);
1241 pValuesArr[3] = BibResId(ST_TYPE_CONFERENCE);
1242 pValuesArr[4] = BibResId(ST_TYPE_INBOOK );
1243 pValuesArr[5] = BibResId(ST_TYPE_INCOLLECTION);
1244 pValuesArr[6] = BibResId(ST_TYPE_INPROCEEDINGS);
1245 pValuesArr[7] = BibResId(ST_TYPE_JOURNAL );
1246 pValuesArr[8] = BibResId(ST_TYPE_MANUAL );
1247 pValuesArr[9] = BibResId(ST_TYPE_MASTERSTHESIS);
1248 pValuesArr[10] = BibResId(ST_TYPE_MISC );
1249 pValuesArr[11] = BibResId(ST_TYPE_PHDTHESIS );
1250 pValuesArr[12] = BibResId(ST_TYPE_PROCEEDINGS );
1251 pValuesArr[13] = BibResId(ST_TYPE_TECHREPORT );
1252 pValuesArr[14] = BibResId(ST_TYPE_UNPUBLISHED );
1253 pValuesArr[15] = BibResId(ST_TYPE_EMAIL );
1254 pValuesArr[16] = BibResId(ST_TYPE_WWW );
1255 pValuesArr[17] = BibResId(ST_TYPE_CUSTOM1 );
1256 pValuesArr[18] = BibResId(ST_TYPE_CUSTOM2 );
1257 pValuesArr[19] = BibResId(ST_TYPE_CUSTOM3 );
1258 pValuesArr[20] = BibResId(ST_TYPE_CUSTOM4 );
1259 pValuesArr[21] = BibResId(ST_TYPE_CUSTOM5 );
1260 // empty string if an invalid value no values is set
1261 pValuesArr[TYPE_COUNT].clear();
1262
1263 aAny <<= aValues;
1264
1265 xPropSet->setPropertyValue("StringItemList", aAny);
1266
1267 xPropSet->setPropertyValue( "Dropdown", Any(true) );
1268 }
1269
1270 Reference< XFormComponent > aFormComp(xModel,UNO_QUERY );
1271
1272 Reference< XNameContainer > xNameCont( m_xForm, UNO_QUERY );
1273 xNameCont->insertByName(aName, Any( aFormComp ) );
1274
1275 // now if the form where we inserted the new model is already loaded, notify the model of this
1276 // Note that this implementation below is a HACK as it relies on the fact that the model adds itself
1277 // as load listener to its parent, which is an implementation detail of the model.
1278 //
1279 // the better solution would be the following:
1280 // in the current scenario, we insert a control model into a form. This results in the control model
1281 // adding itself as load listener to the form. Now, the form should realize that it's already loaded
1282 // and notify the model (which it knows as XLoadListener only) immediately. This seems to make sense.
1283 // (as an analogon to the XStatusListener semantics).
1284 //
1285 // But this would be way too risky for this last-day fix here.
1286 Reference< XLoadable > xLoad( m_xForm, UNO_QUERY );
1287 if ( xLoad.is() && xLoad->isLoaded() )
1288 {
1289 Reference< XLoadListener > xListener( aFormComp, UNO_QUERY );
1290 if ( xListener.is() )
1291 {
1292 EventObject aLoadSource;
1293 aLoadSource.Source = xLoad;
1294 xListener->loaded( aLoadSource );
1295 }
1296 }
1297 }
1298 }
1299 catch (const Exception&)
1300 {
1301 OSL_FAIL("::loadControlModel: something went wrong !");
1302 }
1303 return xModel;
1304}
1305
1307{
1308 MappingDialog_Impl aDlg(pParent, this);
1309 if (RET_OK == aDlg.run() && pBibView)
1310 {
1311 reload();
1312 }
1313}
1314
1316{
1317 OUString uRet;
1318 DBChangeDialog_Impl aDlg(pParent, this);
1319 if (aDlg.run() == RET_OK)
1320 {
1321 OUString sNewURL = aDlg.GetCurrentURL();
1322 if(sNewURL != getActiveDataSource())
1323 {
1324 uRet = sNewURL;
1325 }
1326 }
1327 return uRet;
1328}
1329
1331{
1332 if (pToolbar)
1333 pToolbar->SendDispatch(pToolbar->GetChangeSourceId(), Sequence< PropertyValue >());
1334}
1335
1337{
1338 if(sIdentifierMapping.isEmpty())
1339 {
1340 BibConfig* pConfig = BibModul::GetConfig();
1341 BibDBDescriptor aDesc;
1344 aDesc.nCommandType = CommandType::TABLE;
1345 const Mapping* pMapping = pConfig->GetMapping(aDesc);
1347 if(pMapping)
1348 {
1349 for(const auto & aColumnPair : pMapping->aColumnPairs)
1350 {
1351 if(aColumnPair.sLogicalColumnName == sIdentifierMapping)
1352 {
1353 sIdentifierMapping = aColumnPair.sRealColumnName;
1354 break;
1355 }
1356 }
1357 }
1358 }
1359 return sIdentifierMapping;
1360}
1361
1363{
1364 pToolbar = pSet;
1365 if(pToolbar)
1366 pToolbar->SetDatMan(*this);
1367}
1368
1369uno::Reference< form::runtime::XFormController > const & BibDataManager::GetFormController()
1370{
1371 if(!m_xFormCtrl.is())
1372 {
1373 Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
1374 m_xFormCtrl = form::runtime::FormController::create(xContext);
1375 m_xFormCtrl->setModel(uno::Reference< awt::XTabControllerModel > (getForm(), UNO_QUERY));
1376 m_xFormDispatch.set( m_xFormCtrl, UNO_QUERY);
1377 }
1378 return m_xFormCtrl;
1379}
1380
1381void BibDataManager::RegisterInterceptor( const ::bib::BibBeamer* pBibBeamer)
1382{
1383 DBG_ASSERT( !m_xInterceptorHelper.is(), "BibDataManager::RegisterInterceptor: called twice!" );
1384
1385 if( pBibBeamer )
1387}
1388
1389
1391{
1392 return getConnection( m_xForm ).is();
1393}
1394
1395/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sSchema
OptionalString sCatalog
Reference< XExecutableDialog > m_xDialog
AnyEventRef aEvent
const char *const aFieldNames[]
#define IDENTIFIER_POS
Definition: bibconfig.hxx:32
#define COLUMN_COUNT
Definition: bibconfig.hxx:31
OUString BibResId(TranslateId aId)
Definition: bibmod.cxx:57
const Mapping * GetMapping(const BibDBDescriptor &rDesc) const
Definition: bibconfig.cxx:250
const OUString & GetDefColumnName(sal_uInt16 nIndex) const
Definition: bibconfig.hxx:121
void SetMapping(const BibDBDescriptor &rDesc, const Mapping *pMapping)
Definition: bibconfig.cxx:262
const OUString & getQueryField() const
Definition: bibconfig.hxx:130
void setQueryText(const OUString &rSet)
Definition: bibconfig.hxx:134
const OUString & getQueryText() const
Definition: bibconfig.hxx:133
void SetBibliographyURL(const BibDBDescriptor &rDesc)
Definition: bibconfig.cxx:191
void setQueryField(const OUString &rSet)
Definition: bibconfig.hxx:131
css::uno::Reference< css::frame::XDispatch > m_xFormDispatch
Definition: datman.hxx:83
VclPtr< ::bib::BibView > pBibView
Definition: datman.hxx:92
const OUString & GetIdentifierMapping()
Definition: datman.cxx:1336
virtual sal_Bool SAL_CALL isLoaded() override
Definition: datman.cxx:1076
static css::uno::Reference< css::awt::XControlModel > createGridModel(const OUString &rName)
Definition: datman.cxx:1102
const OUString & getActiveDataTable() const
Definition: datman.hxx:128
void DispatchDBChangeDialog()
Definition: datman.cxx:1330
css::uno::Reference< css::form::runtime::XFormController > m_xFormCtrl
Definition: datman.hxx:82
VclPtr< BibToolBar > pToolbar
Definition: datman.hxx:93
OUString sIdentifierMapping
Definition: datman.hxx:95
void CreateMappingDialog(weld::Window *pParent)
Definition: datman.cxx:1306
css::uno::Reference< css::form::XForm > m_xForm
Definition: datman.hxx:79
::comphelper::OInterfaceContainerHelper4< css::form::XLoadListener > m_aLoadListeners
Definition: datman.hxx:90
rtl::Reference< BibInterceptorHelper > m_xInterceptorHelper
Definition: datman.hxx:84
css::uno::Reference< css::awt::XControlModel > loadControlModel(const OUString &rName, bool bForceListBox)
Definition: datman.cxx:1177
void setActiveDataTable(const OUString &rTable)
Definition: datman.cxx:939
OUString getQueryField() const
Definition: datman.cxx:829
void ResetIdentifierMapping()
Definition: datman.hxx:157
css::uno::Sequence< OUString > getDataSources() const
Definition: datman.cxx:758
const OUString & getActiveDataSource() const
Definition: datman.hxx:125
css::uno::Reference< css::form::XForm > createDatabaseForm(BibDBDescriptor &aDesc)
Definition: datman.cxx:677
void InsertFields(const css::uno::Reference< css::form::XFormComponent > &xGrid)
Definition: datman.cxx:563
virtual void SAL_CALL unload() override
Definition: datman.cxx:1022
virtual void SAL_CALL reload() override
Definition: datman.cxx:1049
virtual void SAL_CALL removeLoadListener(const css::uno::Reference< css::form::XLoadListener > &aListener) override
Definition: datman.cxx:1095
virtual ~BibDataManager() override
Definition: datman.cxx:539
OUString CreateDBChangeDialog(weld::Window *pParent)
Definition: datman.cxx:1315
void setFilter(const OUString &rQuery)
Definition: datman.cxx:780
OUString aDataSourceURL
Definition: datman.hxx:87
OUString getFilter() const
Definition: datman.cxx:801
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xParser
Definition: datman.hxx:81
virtual void SAL_CALL load() override
Definition: datman.cxx:1003
bool HasActiveConnection() const
Definition: datman.cxx:1390
static OUString getControlName(sal_Int32 nFormatKey)
Definition: datman.cxx:1138
virtual void SAL_CALL addLoadListener(const css::uno::Reference< css::form::XLoadListener > &aListener) override
Definition: datman.cxx:1088
OUString aQuoteChar
Definition: datman.hxx:88
css::uno::Reference< css::awt::XControlModel > updateGridModel()
Definition: datman.cxx:644
const css::uno::Reference< css::form::XForm > & getForm() const
Definition: datman.hxx:139
void RegisterInterceptor(const ::bib::BibBeamer *pBibBeamer)
Definition: datman.cxx:1381
void startQueryWith(const OUString &rQuery)
Definition: datman.cxx:844
css::uno::Sequence< OUString > getQueryFields() const
Definition: datman.cxx:820
void setActiveDataSource(const OUString &rURL)
Definition: datman.cxx:859
OUString aActiveDataTable
Definition: datman.hxx:86
void SetToolbar(BibToolBar *pSet)
Definition: datman.cxx:1362
css::uno::Reference< css::form::runtime::XFormController > const & GetFormController()
Definition: datman.cxx:1369
css::uno::Reference< css::awt::XControlModel > m_xGridModel
Definition: datman.hxx:80
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider() override
Definition: datman.cxx:519
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags) override
Definition: datman.cxx:480
void ReleaseInterceptor()
Definition: datman.cxx:472
BibInterceptorHelper(const ::bib::BibBeamer *pBibBeamer, css::uno::Reference< css::frame::XDispatch > const &xDispatch)
Definition: datman.cxx:456
css::uno::Reference< css::frame::XDispatch > xFormDispatch
Definition: datman.hxx:53
css::uno::Reference< css::frame::XDispatchProvider > xSlaveDispatchProvider
Definition: datman.hxx:52
virtual void SAL_CALL setSlaveDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &xNewSlaveDispatchProvider) override
Definition: datman.cxx:513
virtual void SAL_CALL setMasterDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &xNewMasterDispatchProvider) override
Definition: datman.cxx:524
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescripts) override
Definition: datman.cxx:495
virtual ~BibInterceptorHelper() override
Definition: datman.cxx:468
css::uno::Reference< css::frame::XDispatchProviderInterception > xInterception
Definition: datman.hxx:54
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider() override
Definition: datman.cxx:508
css::uno::Reference< css::frame::XDispatchProvider > xMasterDispatchProvider
Definition: datman.hxx:51
static BibConfig * GetConfig()
Definition: bibmod.cxx:82
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(std::unique_lock< std::mutex > &rGuard, void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event) const
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
int nCount
IMPL_LINK_NOARG(MappingDialog_Impl, OkHdl, weld::Button &, void)
Definition: datman.cxx:376
IMPL_LINK(MappingDialog_Impl, ListBoxSelectHdl, weld::ComboBox &, rListBox, void)
Definition: datman.cxx:362
constexpr OUStringLiteral FM_PROP_LABEL
Definition: datman.cxx:75
constexpr OUStringLiteral FM_PROP_CONTROLSOURCE
Definition: datman.cxx:76
constexpr OUStringLiteral FM_PROP_NAME
Definition: datman.cxx:77
static Reference< XNameAccess > getColumns(const Reference< XForm > &_rxForm)
Definition: datman.cxx:143
static Reference< XConnection > getConnection(const OUString &_rURL)
Definition: datman.cxx:79
static sal_uInt16 lcl_FindLogicalName(BibConfig const *pConfig, std::u16string_view rLogicalColumnName)
Definition: datman.cxx:234
constexpr OUStringLiteral gGridName(u"theGrid")
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< XDispatch > xDispatch
URL aURL
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
float u
Reference< XSingleServiceFactory > xFactory
OUString sName
#define TYPE_COUNT
Definition: general.hxx:29
#define HID_BIB_DB_GRIDCTRL
Definition: helpids.h:64
OUString aName
uno_Mapping * pMapping
Sequence< sal_Int8 > aSeq
#define SAL_INFO(area, stream)
@ Exception
Reference< XMultiServiceFactory > getProcessServiceFactory()
Reference< XComponentContext > getProcessComponentContext()
int i
QPRO_FUNC_TYPE nType
OUString sDataSource
Definition: bibconfig.hxx:84
OUString sTableOrQuery
Definition: bibconfig.hxx:85
sal_Int32 nCommandType
Definition: bibconfig.hxx:86
OUString sTableName
Definition: bibconfig.hxx:73
OUString sURL
Definition: bibconfig.hxx:74
StringPair aColumnPairs[COLUMN_COUNT]
Definition: bibconfig.hxx:76
OUString sRealColumnName
Definition: bibconfig.hxx:67
OUString sLogicalColumnName
Definition: bibconfig.hxx:68
Reference< XModel > xModel
OUString aCommand
unsigned char sal_Bool
constexpr OUStringLiteral sNone
constexpr OUStringLiteral INET_HID_SCHEME
RET_OK
RET_CANCEL