Avoid potential negative array index access to cached text.
[LibreOffice.git] / extensions / source / bibliography / datman.cxx
bloba15a3e889c180dda1c41afa6c5cf6caa0e80de5e
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 <sal/config.h>
22 #include <o3tl/any.hxx>
23 #include <sal/log.hxx>
24 #include <comphelper/diagnose_ex.hxx>
25 #include <comphelper/processfactory.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>
60 #include <connectivity/dbtools.hxx>
61 #include <memory>
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::beans;
65 using namespace ::com::sun::star::container;
66 using namespace ::com::sun::star::uno;
67 using namespace ::com::sun::star::sdb;
68 using namespace ::com::sun::star::sdbc;
69 using namespace ::com::sun::star::sdbcx;
70 using namespace ::com::sun::star::form;
71 using namespace ::com::sun::star::frame;
72 using namespace ::com::sun::star::lang;
74 // PropertyNames
75 constexpr OUStringLiteral FM_PROP_LABEL = u"Label";
76 constexpr OUString FM_PROP_CONTROLSOURCE = u"DataField"_ustr;
77 constexpr OUStringLiteral FM_PROP_NAME = u"Name";
79 static Reference< XConnection > getConnection(const OUString& _rURL)
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))
88 DBG_ASSERT(xNamingContext.is(), "::getDataSource : no NamingService interface on the sdb::DatabaseAccessContext !");
89 try
91 xDataSource.set(xNamingContext->getRegisteredObject(_rURL), UNO_QUERY);
93 catch (const Exception&)
95 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
98 // build the connection from the data source
99 Reference< XConnection > xConn;
100 if (xDataSource.is())
102 // need user/pwd for this
103 Reference< XCompletedConnection > xComplConn(xDataSource, UNO_QUERY);
106 Reference<task::XInteractionHandler> xIHdl( task::InteractionHandler::createWithParent(xContext, nullptr), UNO_QUERY_THROW);
107 xConn = xComplConn->connectWithCompletion(xIHdl);
109 catch (const SQLException&)
111 // TODO : a real error handling
113 catch (const Exception&)
117 return xConn;
120 static Reference< XConnection > getConnection(const Reference< XInterface > & xRowSet)
122 Reference< XConnection > xConn;
125 Reference< XPropertySet > xFormProps(xRowSet, UNO_QUERY);
126 if (!xFormProps.is())
127 return xConn;
129 xConn.set(xFormProps->getPropertyValue("ActiveConnection"), UNO_QUERY);
130 if (!xConn.is())
132 SAL_INFO("extensions.biblio", "no active connection");
135 catch (const Exception&)
137 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
140 return xConn;
143 static Reference< XNameAccess > getColumns(const Reference< XForm > & _rxForm)
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();
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())
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();
171 catch (const Exception&)
173 TOOLS_WARN_EXCEPTION( "extensions.biblio", "::getColumns");
178 return xReturn;
181 namespace {
183 class MappingDialog_Impl : public weld::GenericDialogController
185 BibDataManager* pDatMan;
187 OUString sNone;
188 bool bModified;
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];
225 DECL_LINK(OkHdl, weld::Button&, void);
226 DECL_LINK(ListBoxSelectHdl, weld::ComboBox&, void);
228 public:
229 MappingDialog_Impl(weld::Window* pParent, BibDataManager* pDatMan);
234 static sal_uInt16 lcl_FindLogicalName(BibConfig const * pConfig ,
235 std::u16string_view rLogicalColumnName)
237 for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
239 if(rLogicalColumnName == pConfig->GetDefColumnName(i))
240 return i;
242 return USHRT_MAX;
245 MappingDialog_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"))
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);
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();
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())
327 const Sequence<OUString> aFieldNames = xFields->getElementNames();
328 for(const OUString& rName : aFieldNames)
329 aListBoxes[0]->append_text(rName);
332 Link<weld::ComboBox&,void> aLnk = LINK(this, MappingDialog_Impl, ListBoxSelectHdl);
334 aListBoxes[0]->set_active(0);
335 aListBoxes[0]->connect_changed(aLnk);
336 for(sal_uInt16 i = 1; i < COLUMN_COUNT; i++)
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);
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)
351 for(const auto & aColumnPair : pMapping->aColumnPairs)
353 sal_uInt16 nListBoxIndex = lcl_FindLogicalName( pConfig, aColumnPair.sLogicalColumnName);
354 if(nListBoxIndex < COLUMN_COUNT)
356 aListBoxes[nListBoxIndex]->set_active_text(aColumnPair.sRealColumnName);
362 IMPL_LINK(MappingDialog_Impl, ListBoxSelectHdl, weld::ComboBox&, rListBox, void)
364 const sal_Int32 nEntryPos = rListBox.get_active();
365 if (0 < nEntryPos)
367 for(auto & pListBoxe : aListBoxes)
369 if (&rListBox != pListBoxe && pListBoxe->get_active() == nEntryPos)
370 pListBoxe->set_active(0);
373 bModified = true;
376 IMPL_LINK_NOARG(MappingDialog_Impl, OkHdl, weld::Button&, void)
378 if(bModified)
380 Mapping aNew;
381 aNew.sTableName = pDatMan->getActiveDataTable();
382 aNew.sURL = pDatMan->getActiveDataSource();
384 sal_uInt16 nWriteIndex = 0;
385 BibConfig* pConfig = BibModul::GetConfig();
386 for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
388 OUString sSel = aListBoxes[nEntry]->get_active_text();
389 if(sSel != sNone)
391 aNew.aColumnPairs[nWriteIndex].sRealColumnName = sSel;
392 aNew.aColumnPairs[nWriteIndex].sLogicalColumnName = pConfig->GetDefColumnName(nEntry);
393 nWriteIndex++;
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);
403 m_xDialog->response(bModified ? RET_OK : RET_CANCEL);
406 namespace {
408 class DBChangeDialog_Impl : public weld::GenericDialogController
410 DBChangeDialogConfig_Impl aConfig;
412 std::unique_ptr<weld::TreeView> m_xSelectionLB;
414 DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
415 public:
416 DBChangeDialog_Impl(weld::Window* pParent, const BibDataManager* pMan);
418 OUString GetCurrentURL()const;
423 DBChangeDialog_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"))
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();
433 OUString sActiveSource = pDatMan->getActiveDataSource();
434 for (const OUString& rSourceName : aConfig.GetDataSourceNames())
435 m_xSelectionLB->append_text(rSourceName);
436 m_xSelectionLB->select_text(sActiveSource);
438 catch (const Exception&)
440 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
444 IMPL_LINK_NOARG(DBChangeDialog_Impl, DoubleClickHdl, weld::TreeView&, bool)
446 m_xDialog->response(RET_OK);
447 return true;
450 OUString DBChangeDialog_Impl::GetCurrentURL()const
452 return m_xSelectionLB->get_selected_text();
455 // XDispatchProvider
456 BibInterceptorHelper::BibInterceptorHelper( const ::bib::BibBeamer* pBibBeamer, css::uno::Reference< css::frame::XDispatch > const & xDispatch)
458 if( pBibBeamer )
460 xInterception = pBibBeamer->getDispatchProviderInterception();
461 if( xInterception.is() )
462 xInterception->registerDispatchProviderInterceptor( this );
464 if( xDispatch.is() )
465 xFormDispatch = xDispatch;
468 BibInterceptorHelper::~BibInterceptorHelper( )
472 void BibInterceptorHelper::ReleaseInterceptor()
474 if ( xInterception.is() )
475 xInterception->releaseDispatchProviderInterceptor( this );
476 xInterception.clear();
479 css::uno::Reference< css::frame::XDispatch > SAL_CALL
480 BibInterceptorHelper::queryDispatch( const css::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
482 Reference< XDispatch > xReturn;
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);
491 return xReturn;
494 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL
495 BibInterceptorHelper::queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& aDescripts )
497 Sequence< Reference< XDispatch> > aReturn( aDescripts.getLength() );
498 Reference< XDispatch >* pReturn = aReturn.getArray();
499 for ( const DispatchDescriptor& rDescript : aDescripts )
501 *pReturn++ = queryDispatch( rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags );
503 return aReturn;
506 // XDispatchProviderInterceptor
507 css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL
508 BibInterceptorHelper::getSlaveDispatchProvider( )
510 return xSlaveDispatchProvider;
513 void SAL_CALL BibInterceptorHelper::setSlaveDispatchProvider( const css::uno::Reference< css::frame::XDispatchProvider >& xNewSlaveDispatchProvider )
515 xSlaveDispatchProvider = xNewSlaveDispatchProvider;
518 css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL
519 BibInterceptorHelper::getMasterDispatchProvider( )
521 return xMasterDispatchProvider;
524 void SAL_CALL BibInterceptorHelper::setMasterDispatchProvider( const css::uno::Reference< css::frame::XDispatchProvider >& xNewMasterDispatchProvider )
526 xMasterDispatchProvider = xNewMasterDispatchProvider;
530 constexpr OUStringLiteral gGridName(u"theGrid");
532 BibDataManager::BibDataManager()
533 :pBibView( nullptr )
534 ,pToolbar(nullptr)
539 BibDataManager::~BibDataManager()
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() )
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;
556 if( m_xInterceptorHelper.is() )
558 m_xInterceptorHelper->ReleaseInterceptor();
559 m_xInterceptorHelper.clear();
563 void BibDataManager::InsertFields(const Reference< XFormComponent > & _rxGrid)
565 if ( !_rxGrid.is() )
566 return;
570 Reference< XNameContainer > xColContainer( _rxGrid, UNO_QUERY );
571 // remove the old fields
572 if ( xColContainer->hasElements() )
574 const Sequence<OUString> aOldNames = xColContainer->getElementNames();
575 for ( const OUString& rName : aOldNames )
576 xColContainer->removeByName( rName );
579 Reference< XNameAccess > xFields = getColumns( m_xForm );
580 if (!xFields.is())
581 return;
583 Reference< XGridColumnFactory > xColFactory( _rxGrid, UNO_QUERY );
585 Reference< XPropertySet > xField;
587 const Sequence<OUString> aFieldNames = xFields->getElementNames();
588 for ( const OUString& rField : aFieldNames )
590 xFields->getByName( rField ) >>= xField;
592 OUString sCurrentModelType;
593 sal_Int32 nType = 0;
594 bool bIsFormatted = false;
595 bool bFormattedIsNumeric = true;
596 xField->getPropertyValue("Type") >>= nType;
597 switch(nType)
599 case DataType::BIT:
600 case DataType::BOOLEAN:
601 sCurrentModelType = "CheckBox";
602 break;
604 case DataType::BINARY:
605 case DataType::VARBINARY:
606 case DataType::LONGVARBINARY:
607 case DataType::BLOB:
608 sCurrentModelType = "TextField";
609 break;
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;
623 Reference< XPropertySet > xCurrentCol = xColFactory->createColumn(sCurrentModelType);
624 if (bIsFormatted)
626 OUString sFormatKey("FormatKey");
627 xCurrentCol->setPropertyValue(sFormatKey, xField->getPropertyValue(sFormatKey));
628 Any aFormatted(bFormattedIsNumeric);
629 xCurrentCol->setPropertyValue("TreatAsNumber", aFormatted);
631 Any aColName( rField );
632 xCurrentCol->setPropertyValue(FM_PROP_CONTROLSOURCE, aColName);
633 xCurrentCol->setPropertyValue(FM_PROP_LABEL, aColName);
635 xColContainer->insertByName( rField, Any( xCurrentCol ) );
638 catch (const Exception&)
640 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
644 Reference< awt::XControlModel > BibDataManager::updateGridModel()
646 return updateGridModel( m_xForm );
649 Reference< awt::XControlModel > const & BibDataManager::updateGridModel(const Reference< XForm > & xDbForm)
653 Reference< XPropertySet > aFormPropSet( xDbForm, UNO_QUERY );
654 OUString sName;
655 aFormPropSet->getPropertyValue("Command") >>= sName;
657 if ( !m_xGridModel.is() )
659 m_xGridModel = createGridModel( gGridName );
661 Reference< XNameContainer > xNameCont(xDbForm, UNO_QUERY);
662 xNameCont->insertByName( sName, Any( m_xGridModel ) );
665 // insert the fields
666 Reference< XFormComponent > xFormComp( m_xGridModel, UNO_QUERY );
667 InsertFields( xFormComp );
669 catch (const Exception&)
671 OSL_FAIL("::updateGridModel: something went wrong !");
674 return m_xGridModel;
677 Reference< XForm > BibDataManager::createDatabaseForm(BibDBDescriptor& rDesc)
679 Reference< XForm > xResult;
682 Reference< XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
683 m_xForm.set( xMgr->createInstance( "com.sun.star.form.component.Form" ), UNO_QUERY );
685 Reference< XPropertySet > aPropertySet( m_xForm, UNO_QUERY );
687 aDataSourceURL = rDesc.sDataSource;
688 if(aPropertySet.is())
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);
696 //Caching for Performance
697 aVal <<= sal_Int32(50);
698 aPropertySet->setPropertyValue("FetchSize", aVal);
700 Reference< XConnection > xConnection = getConnection(rDesc.sDataSource);
701 aVal <<= xConnection;
702 aPropertySet->setPropertyValue("ActiveConnection", aVal);
704 Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
705 Reference< XNameAccess > xTables = xSupplyTables.is() ?
706 xSupplyTables->getTables() : Reference< XNameAccess > ();
708 Sequence< OUString > aTableNameSeq;
709 if (xTables.is())
710 aTableNameSeq = xTables->getElementNames();
712 if(aTableNameSeq.hasElements())
714 if(!rDesc.sTableOrQuery.isEmpty())
715 aActiveDataTable = rDesc.sTableOrQuery;
716 else
718 rDesc.sTableOrQuery = aActiveDataTable = aTableNameSeq[0];
719 rDesc.nCommandType = CommandType::TABLE;
722 aVal <<= aActiveDataTable;
723 aPropertySet->setPropertyValue("Command", aVal);
724 aVal <<= rDesc.nCommandType;
725 aPropertySet->setPropertyValue("CommandType", aVal);
728 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
729 aQuoteChar = xMetaData->getIdentifierQuoteString();
731 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
732 if ( xFactory.is() )
733 m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
735 OUString aString("SELECT * FROM ");
737 OUString sCatalog, sSchema, sName;
738 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation );
739 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
741 m_xParser->setElementaryQuery(aString);
742 BibConfig* pConfig = BibModul::GetConfig();
743 pConfig->setQueryField(getQueryField());
744 startQueryWith(pConfig->getQueryText());
746 xResult = m_xForm;
750 catch (const Exception&)
752 OSL_FAIL("::createDatabaseForm: something went wrong !");
755 return xResult;
758 Sequence< OUString > BibDataManager::getDataSources() const
760 Sequence< OUString > aTableNameSeq;
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();
771 catch (const Exception&)
773 OSL_FAIL("::getDataSources: something went wrong !");
776 return aTableNameSeq;
780 void BibDataManager::setFilter(const OUString& rQuery)
782 if(!m_xParser.is())
783 return;
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();
793 catch (const Exception&)
795 DBG_UNHANDLED_EXCEPTION("extensions.biblio");
801 OUString BibDataManager::getFilter() const
804 OUString aQueryString;
807 Reference< XPropertySet > xFormProps( m_xForm, UNO_QUERY_THROW );
808 OSL_VERIFY( xFormProps->getPropertyValue( "Filter" ) >>= aQueryString );
810 catch (const Exception&)
812 DBG_UNHANDLED_EXCEPTION("extensions.biblio");
816 return aQueryString;
820 Sequence< OUString > BibDataManager::getQueryFields() const
822 Sequence< OUString > aFieldSeq;
823 Reference< XNameAccess > xFields = getColumns( m_xForm );
824 if (xFields.is())
825 aFieldSeq = xFields->getElementNames();
826 return aFieldSeq;
829 OUString BibDataManager::getQueryField() const
831 BibConfig* pConfig = BibModul::GetConfig();
832 OUString aFieldString = pConfig->getQueryField();
833 if(aFieldString.isEmpty())
835 const Sequence< OUString > aSeq = getQueryFields();
836 if(aSeq.hasElements())
838 aFieldString=aSeq[0];
841 return aFieldString;
844 void BibDataManager::startQueryWith(const OUString& rQuery)
846 BibConfig* pConfig = BibModul::GetConfig();
847 pConfig->setQueryText( rQuery );
849 OUString aQueryString;
850 if(!rQuery.isEmpty())
852 aQueryString=aQuoteChar + getQueryField() + aQuoteChar + " like '";
853 OUString sQuery = rQuery.replaceAll("?","_").replaceAll("*","%");
854 aQueryString += sQuery + "%'";
856 setFilter(aQueryString);
859 void BibDataManager::setActiveDataSource(const OUString& rURL)
861 OUString sTmp(aDataSourceURL);
862 aDataSourceURL = rURL;
864 Reference< XPropertySet > aPropertySet( m_xForm, UNO_QUERY );
865 if(!aPropertySet.is())
866 return;
868 unload();
870 Reference< XComponent > xOldConnection;
871 aPropertySet->getPropertyValue("ActiveConnection") >>= xOldConnection;
873 Reference< XConnection > xConnection = getConnection(rURL);
874 if(!xConnection.is())
876 aDataSourceURL = sTmp;
877 return;
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 );
885 if(xOldConnection.is())
886 xOldConnection->dispose();
888 Sequence< OUString > aTableNameSeq;
889 Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
890 if(xSupplyTables.is())
892 Reference< XNameAccess > xAccess = xSupplyTables->getTables();
893 aTableNameSeq = xAccess->getElementNames();
895 if(aTableNameSeq.hasElements())
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();
909 OUString sCatalog, sSchema, sName;
910 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation );
911 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
913 m_xParser->setElementaryQuery(aString);
914 BibConfig* pConfig = BibModul::GetConfig();
915 pConfig->setQueryField(getQueryField());
916 startQueryWith(pConfig->getQueryText());
917 setActiveDataTable(aActiveDataTable);
919 FeatureStateEvent aEvent;
920 util::URL aURL;
921 aEvent.IsEnabled = true;
922 aEvent.Requery = false;
923 aEvent.FeatureDescriptor = getActiveDataTable();
925 aEvent.State <<= getDataSources();
927 if(pToolbar)
929 aURL.Complete =".uno:Bib/source";
930 aEvent.FeatureURL = aURL;
931 pToolbar->statusChanged( aEvent );
934 updateGridModel();
935 load();
939 void BibDataManager::setActiveDataTable(const OUString& rTable)
941 ResetIdentifierMapping();
944 Reference< XPropertySet > aPropertySet( m_xForm, UNO_QUERY );
946 if(aPropertySet.is())
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();
954 const OUString* pTableNames = aTableNameSeq.getConstArray();
955 const OUString* pTableNamesEnd = pTableNames + nCount;
957 for ( ; pTableNames != pTableNamesEnd; ++pTableNames )
959 if ( rTable == *pTableNames )
961 aActiveDataTable = rTable;
962 Any aVal; aVal <<= rTable;
963 aPropertySet->setPropertyValue( "Command", aVal );
964 break;
967 if (pTableNames != pTableNamesEnd)
969 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
970 aQuoteChar = xMetaData->getIdentifierQuoteString();
972 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
973 if ( xFactory.is() )
974 m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
976 OUString aString("SELECT * FROM ");
978 OUString sCatalog, sSchema, sName;
979 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation );
980 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
982 m_xParser->setElementaryQuery(aString);
984 BibConfig* pConfig = BibModul::GetConfig();
985 pConfig->setQueryField(getQueryField());
986 startQueryWith(pConfig->getQueryText());
988 BibDBDescriptor aDesc;
989 aDesc.sDataSource = aDataSourceURL;
990 aDesc.sTableOrQuery = aActiveDataTable;
991 aDesc.nCommandType = CommandType::TABLE;
992 BibModul::GetConfig()->SetBibliographyURL(aDesc);
996 catch (const Exception&)
998 OSL_FAIL("::setActiveDataTable: something went wrong !");
1003 void SAL_CALL BibDataManager::load( )
1005 if ( isLoaded() )
1006 // nothing to do
1007 return;
1009 Reference< XLoadable > xFormAsLoadable( m_xForm, UNO_QUERY );
1010 DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::load: invalid form!");
1011 if ( xFormAsLoadable.is() )
1013 xFormAsLoadable->load();
1015 std::unique_lock g(m_aMutex);
1016 EventObject aEvt( static_cast< XWeak* >( this ) );
1017 m_aLoadListeners.notifyEach( g, &XLoadListener::loaded, aEvt );
1022 void SAL_CALL BibDataManager::unload( )
1024 if ( !isLoaded() )
1025 // nothing to do
1026 return;
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;
1033 EventObject aEvt( static_cast< XWeak* >( this ) );
1036 std::unique_lock g(m_aMutex);
1037 m_aLoadListeners.notifyEach( g, &XLoadListener::unloading, aEvt );
1040 xFormAsLoadable->unload();
1043 std::unique_lock g(m_aMutex);
1044 m_aLoadListeners.notifyEach( g, &XLoadListener::unloaded, aEvt );
1049 void SAL_CALL BibDataManager::reload( )
1051 if ( !isLoaded() )
1052 // nothing to do
1053 return;
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;
1060 EventObject aEvt( static_cast< XWeak* >( this ) );
1063 std::unique_lock g(m_aMutex);
1064 m_aLoadListeners.notifyEach( g, &XLoadListener::reloading, aEvt );
1067 xFormAsLoadable->reload();
1070 std::unique_lock g(m_aMutex);
1071 m_aLoadListeners.notifyEach( g, &XLoadListener::reloaded, aEvt );
1076 sal_Bool SAL_CALL BibDataManager::isLoaded( )
1078 Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
1079 DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::isLoaded: invalid form!");
1081 bool bLoaded = false;
1082 if ( xFormAsLoadable.is() )
1083 bLoaded = xFormAsLoadable->isLoaded();
1084 return bLoaded;
1088 void SAL_CALL BibDataManager::addLoadListener( const Reference< XLoadListener >& aListener )
1090 std::unique_lock g(m_aMutex);
1091 m_aLoadListeners.addInterface( g, aListener );
1095 void SAL_CALL BibDataManager::removeLoadListener( const Reference< XLoadListener >& aListener )
1097 std::unique_lock g(m_aMutex);
1098 m_aLoadListeners.removeInterface( g, aListener );
1102 Reference< awt::XControlModel > BibDataManager::createGridModel(const OUString& rName)
1104 Reference< awt::XControlModel > xModel;
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 );
1113 // set the
1114 Reference< XPropertySet > xPropSet( xModel, UNO_QUERY );
1115 xPropSet->setPropertyValue( "Name", Any( rName ) );
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 );
1121 // the helpURL
1122 OUString uProp("HelpURL");
1123 Reference< XPropertySetInfo > xPropInfo = xPropSet->getPropertySetInfo();
1124 if (xPropInfo->hasPropertyByName(uProp))
1126 xPropSet->setPropertyValue(
1127 uProp, Any(OUString(INET_HID_SCHEME + HID_BIB_DB_GRIDCTRL)));
1130 catch (const Exception&)
1132 OSL_FAIL("::createGridModel: something went wrong !");
1135 return xModel;
1138 OUString BibDataManager::getControlName(sal_Int32 nFormatKey )
1140 OUString aResStr;
1141 switch (nFormatKey)
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;
1174 return aResStr;
1177 Reference< awt::XControlModel > BibDataManager::loadControlModel(
1178 const OUString& rName, bool bForceListBox)
1180 Reference< awt::XControlModel > xModel;
1181 OUString aName = "View_" + rName;
1185 Reference< XNameAccess > xFields = getColumns( m_xForm );
1186 if (!xFields.is())
1187 return xModel;
1188 Reference< XPropertySet > xField;
1190 Any aElement;
1192 if(xFields->hasByName(rName))
1194 aElement = xFields->getByName(rName);
1195 aElement >>= xField;
1197 sal_Int32 nFormatKey = 0;
1198 xField->getPropertyValue("Type") >>= nFormatKey;
1200 OUString aInstanceName("com.sun.star.form.component.");
1202 if (bForceListBox)
1203 aInstanceName += "ListBox";
1204 else
1205 aInstanceName += getControlName(nFormatKey);
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;
1213 xPropSet->setPropertyValue( FM_PROP_NAME,aFieldName);
1214 xPropSet->setPropertyValue( FM_PROP_CONTROLSOURCE, Any( rName ) );
1215 xPropSet->setPropertyValue("NativeWidgetLook", Any( true ) );
1217 if (bForceListBox)
1219 uno::Any aAny;
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);
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;
1234 xPropSet->setPropertyValue("ListSource", aAny);
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();
1263 aAny <<= aValues;
1265 xPropSet->setPropertyValue("StringItemList", aAny);
1267 xPropSet->setPropertyValue( "Dropdown", Any(true) );
1270 Reference< XFormComponent > aFormComp(xModel,UNO_QUERY );
1272 Reference< XNameContainer > xNameCont( m_xForm, UNO_QUERY );
1273 xNameCont->insertByName(aName, Any( aFormComp ) );
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.
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).
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() )
1289 Reference< XLoadListener > xListener( aFormComp, UNO_QUERY );
1290 if ( xListener.is() )
1292 EventObject aLoadSource;
1293 aLoadSource.Source = xLoad;
1294 xListener->loaded( aLoadSource );
1299 catch (const Exception&)
1301 OSL_FAIL("::loadControlModel: something went wrong !");
1303 return xModel;
1306 void BibDataManager::CreateMappingDialog(weld::Window* pParent)
1308 MappingDialog_Impl aDlg(pParent, this);
1309 if (RET_OK == aDlg.run() && pBibView)
1311 reload();
1315 OUString BibDataManager::CreateDBChangeDialog(weld::Window* pParent)
1317 OUString uRet;
1318 DBChangeDialog_Impl aDlg(pParent, this);
1319 if (aDlg.run() == RET_OK)
1321 OUString sNewURL = aDlg.GetCurrentURL();
1322 if(sNewURL != getActiveDataSource())
1324 uRet = sNewURL;
1327 return uRet;
1330 void BibDataManager::DispatchDBChangeDialog()
1332 if (pToolbar)
1333 pToolbar->SendDispatch(pToolbar->GetChangeSourceId(), Sequence< PropertyValue >());
1336 const OUString& BibDataManager::GetIdentifierMapping()
1338 if(sIdentifierMapping.isEmpty())
1340 BibConfig* pConfig = BibModul::GetConfig();
1341 BibDBDescriptor aDesc;
1342 aDesc.sDataSource = getActiveDataSource();
1343 aDesc.sTableOrQuery = getActiveDataTable();
1344 aDesc.nCommandType = CommandType::TABLE;
1345 const Mapping* pMapping = pConfig->GetMapping(aDesc);
1346 sIdentifierMapping = pConfig->GetDefColumnName(IDENTIFIER_POS);
1347 if(pMapping)
1349 for(const auto & aColumnPair : pMapping->aColumnPairs)
1351 if(aColumnPair.sLogicalColumnName == sIdentifierMapping)
1353 sIdentifierMapping = aColumnPair.sRealColumnName;
1354 break;
1359 return sIdentifierMapping;
1362 void BibDataManager::SetToolbar(BibToolBar* pSet)
1364 pToolbar = pSet;
1365 if(pToolbar)
1366 pToolbar->SetDatMan(*this);
1369 uno::Reference< form::runtime::XFormController > const & BibDataManager::GetFormController()
1371 if(!m_xFormCtrl.is())
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);
1378 return m_xFormCtrl;
1381 void BibDataManager::RegisterInterceptor( const ::bib::BibBeamer* pBibBeamer)
1383 DBG_ASSERT( !m_xInterceptorHelper.is(), "BibDataManager::RegisterInterceptor: called twice!" );
1385 if( pBibBeamer )
1386 m_xInterceptorHelper = new BibInterceptorHelper( pBibBeamer, m_xFormDispatch);
1390 bool BibDataManager::HasActiveConnection() const
1392 return getConnection( m_xForm ).is();
1395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */