bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / bibliography / datman.cxx
blobad8215500d9a826a5ebc8c40913d2718eac5ee8b
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 <tools/diagnose_ex.h>
25 #include <comphelper/processfactory.hxx>
26 #include <com/sun/star/io/XPersistObject.hpp>
27 #include <com/sun/star/sdbc/ResultSetType.hpp>
28 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
29 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
30 #include <com/sun/star/sdbcx/XRowLocate.hpp>
31 #include <com/sun/star/sdbc/DataType.hpp>
32 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
33 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
34 #include <com/sun/star/sdb/XDatabaseEnvironment.hpp>
35 #include <com/sun/star/uno/XNamingService.hpp>
36 #include <com/sun/star/sdbc/XDataSource.hpp>
37 #include <com/sun/star/sdb/CommandType.hpp>
38 #include <com/sun/star/sdb/DatabaseContext.hpp>
39 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
40 #include <com/sun/star/sdbc/XConnection.hpp>
41 #include <com/sun/star/sdb/XCompletedConnection.hpp>
42 #include <com/sun/star/sdbc/SQLException.hpp>
43 #include <com/sun/star/task/InteractionHandler.hpp>
44 #include <com/sun/star/form/ListSourceType.hpp>
45 #include <com/sun/star/form/XLoadable.hpp>
46 #include <com/sun/star/form/runtime/FormController.hpp>
47 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
48 #include <com/sun/star/form/XGridColumnFactory.hpp>
49 #include <com/sun/star/io/XDataInputStream.hpp>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/container/XNameContainer.hpp>
52 #include <svl/urihelper.hxx>
53 #include <tools/debug.hxx>
54 #include "datman.hxx"
55 #include "bibresid.hxx"
56 #include "bibmod.hxx"
57 #include "bibview.hxx"
58 #include "bibprop.hxx"
59 #include "toolbar.hxx"
60 #include "bibconfig.hxx"
61 #include "bibbeam.hxx"
62 #include "general.hxx"
63 #include <strings.hrc>
64 #include <helpids.h>
65 #include <connectivity/dbtools.hxx>
66 #include <memory>
68 using namespace ::com::sun::star;
69 using namespace ::com::sun::star::beans;
70 using namespace ::com::sun::star::container;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::sdb;
73 using namespace ::com::sun::star::sdbc;
74 using namespace ::com::sun::star::sdbcx;
75 using namespace ::com::sun::star::form;
76 using namespace ::com::sun::star::frame;
77 using namespace ::com::sun::star::lang;
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 OSL_FAIL("Exception caught in ODatabaseContext::getRegisteredObject()");
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 OSL_FAIL("exception in getConnection");
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 css::uno::Any ex( cppu::getCaughtException() );
174 SAL_WARN( "extensions.biblio", "::getColumns : caught an exception. " << exceptionToString(ex));
179 return xReturn;
182 class MappingDialog_Impl : public weld::GenericDialogController
184 BibDataManager* pDatMan;
186 OUString sNone;
187 bool bModified;
189 std::unique_ptr<weld::Button> m_xOKBT;
190 std::unique_ptr<weld::ComboBox> m_xIdentifierLB;
191 std::unique_ptr<weld::ComboBox> m_xAuthorityTypeLB;
192 std::unique_ptr<weld::ComboBox> m_xAuthorLB;
193 std::unique_ptr<weld::ComboBox> m_xTitleLB;
194 std::unique_ptr<weld::ComboBox> m_xMonthLB;
195 std::unique_ptr<weld::ComboBox> m_xYearLB;
196 std::unique_ptr<weld::ComboBox> m_xISBNLB;
197 std::unique_ptr<weld::ComboBox> m_xBooktitleLB;
198 std::unique_ptr<weld::ComboBox> m_xChapterLB;
199 std::unique_ptr<weld::ComboBox> m_xEditionLB;
200 std::unique_ptr<weld::ComboBox> m_xEditorLB;
201 std::unique_ptr<weld::ComboBox> m_xHowpublishedLB;
202 std::unique_ptr<weld::ComboBox> m_xInstitutionLB;
203 std::unique_ptr<weld::ComboBox> m_xJournalLB;
204 std::unique_ptr<weld::ComboBox> m_xNoteLB;
205 std::unique_ptr<weld::ComboBox> m_xAnnoteLB;
206 std::unique_ptr<weld::ComboBox> m_xNumberLB;
207 std::unique_ptr<weld::ComboBox> m_xOrganizationsLB;
208 std::unique_ptr<weld::ComboBox> m_xPagesLB;
209 std::unique_ptr<weld::ComboBox> m_xPublisherLB;
210 std::unique_ptr<weld::ComboBox> m_xAddressLB;
211 std::unique_ptr<weld::ComboBox> m_xSchoolLB;
212 std::unique_ptr<weld::ComboBox> m_xSeriesLB;
213 std::unique_ptr<weld::ComboBox> m_xReportTypeLB;
214 std::unique_ptr<weld::ComboBox> m_xVolumeLB;
215 std::unique_ptr<weld::ComboBox> m_xURLLB;
216 std::unique_ptr<weld::ComboBox> m_xCustom1LB;
217 std::unique_ptr<weld::ComboBox> m_xCustom2LB;
218 std::unique_ptr<weld::ComboBox> m_xCustom3LB;
219 std::unique_ptr<weld::ComboBox> m_xCustom4LB;
220 std::unique_ptr<weld::ComboBox> m_xCustom5LB;
221 weld::ComboBox* aListBoxes[COLUMN_COUNT];
223 DECL_LINK(OkHdl, weld::Button&, void);
224 DECL_LINK(ListBoxSelectHdl, weld::ComboBox&, void);
226 public:
227 MappingDialog_Impl(weld::Window* pParent, BibDataManager* pDatMan);
230 static sal_uInt16 lcl_FindLogicalName(BibConfig const * pConfig ,
231 const OUString& rLogicalColumnName)
233 for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
235 if(rLogicalColumnName == pConfig->GetDefColumnName(i))
236 return i;
238 return USHRT_MAX;
241 MappingDialog_Impl::MappingDialog_Impl(weld::Window* pParent, BibDataManager* pMan)
242 : GenericDialogController(pParent, "modules/sbibliography/ui/mappingdialog.ui", "MappingDialog")
243 , pDatMan(pMan)
244 , sNone(BibResId(RID_BIB_STR_NONE))
245 , bModified(false)
246 , m_xOKBT(m_xBuilder->weld_button("ok"))
247 , m_xIdentifierLB(m_xBuilder->weld_combo_box("identifierCombobox"))
248 , m_xAuthorityTypeLB(m_xBuilder->weld_combo_box("authorityTypeCombobox"))
249 , m_xAuthorLB(m_xBuilder->weld_combo_box("authorCombobox"))
250 , m_xTitleLB(m_xBuilder->weld_combo_box("titleCombobox"))
251 , m_xMonthLB(m_xBuilder->weld_combo_box("monthCombobox"))
252 , m_xYearLB(m_xBuilder->weld_combo_box("yearCombobox"))
253 , m_xISBNLB(m_xBuilder->weld_combo_box("ISBNCombobox"))
254 , m_xBooktitleLB(m_xBuilder->weld_combo_box("bookTitleCombobox"))
255 , m_xChapterLB(m_xBuilder->weld_combo_box("chapterCombobox"))
256 , m_xEditionLB(m_xBuilder->weld_combo_box("editionCombobox"))
257 , m_xEditorLB(m_xBuilder->weld_combo_box("editorCombobox"))
258 , m_xHowpublishedLB(m_xBuilder->weld_combo_box("howPublishedCombobox"))
259 , m_xInstitutionLB(m_xBuilder->weld_combo_box("institutionCombobox"))
260 , m_xJournalLB(m_xBuilder->weld_combo_box("journalCombobox"))
261 , m_xNoteLB(m_xBuilder->weld_combo_box("noteCombobox"))
262 , m_xAnnoteLB(m_xBuilder->weld_combo_box("annoteCombobox"))
263 , m_xNumberLB(m_xBuilder->weld_combo_box("numberCombobox"))
264 , m_xOrganizationsLB(m_xBuilder->weld_combo_box("organizationCombobox"))
265 , m_xPagesLB(m_xBuilder->weld_combo_box("pagesCombobox"))
266 , m_xPublisherLB(m_xBuilder->weld_combo_box("publisherCombobox"))
267 , m_xAddressLB(m_xBuilder->weld_combo_box("addressCombobox"))
268 , m_xSchoolLB(m_xBuilder->weld_combo_box("schoolCombobox"))
269 , m_xSeriesLB(m_xBuilder->weld_combo_box("seriesCombobox"))
270 , m_xReportTypeLB(m_xBuilder->weld_combo_box("reportTypeCombobox"))
271 , m_xVolumeLB(m_xBuilder->weld_combo_box("volumeCombobox"))
272 , m_xURLLB(m_xBuilder->weld_combo_box("URLCombobox"))
273 , m_xCustom1LB(m_xBuilder->weld_combo_box("custom1Combobox"))
274 , m_xCustom2LB(m_xBuilder->weld_combo_box("custom2Combobox"))
275 , m_xCustom3LB(m_xBuilder->weld_combo_box("custom3Combobox"))
276 , m_xCustom4LB(m_xBuilder->weld_combo_box("custom4Combobox"))
277 , m_xCustom5LB(m_xBuilder->weld_combo_box("custom5Combobox"))
279 m_xOKBT->connect_clicked(LINK(this, MappingDialog_Impl, OkHdl));
280 OUString sTitle = m_xDialog->get_title();
281 sTitle = sTitle.replaceFirst("%1", pDatMan->getActiveDataTable());
282 m_xDialog->set_title(sTitle);
284 aListBoxes[0] = m_xIdentifierLB.get();
285 aListBoxes[1] = m_xAuthorityTypeLB.get();
286 aListBoxes[2] = m_xAuthorLB.get();
287 aListBoxes[3] = m_xTitleLB.get();
288 aListBoxes[4] = m_xYearLB.get();
289 aListBoxes[5] = m_xISBNLB.get();
290 aListBoxes[6] = m_xBooktitleLB.get();
291 aListBoxes[7] = m_xChapterLB.get();
292 aListBoxes[8] = m_xEditionLB.get();
293 aListBoxes[9] = m_xEditorLB.get();
294 aListBoxes[10] = m_xHowpublishedLB.get();
295 aListBoxes[11] = m_xInstitutionLB.get();
296 aListBoxes[12] = m_xJournalLB.get();
297 aListBoxes[13] = m_xMonthLB.get();
298 aListBoxes[14] = m_xNoteLB.get();
299 aListBoxes[15] = m_xAnnoteLB.get();
300 aListBoxes[16] = m_xNumberLB.get();
301 aListBoxes[17] = m_xOrganizationsLB.get();
302 aListBoxes[18] = m_xPagesLB.get();
303 aListBoxes[19] = m_xPublisherLB.get();
304 aListBoxes[20] = m_xAddressLB.get();
305 aListBoxes[21] = m_xSchoolLB.get();
306 aListBoxes[22] = m_xSeriesLB.get();
307 aListBoxes[23] = m_xReportTypeLB.get();
308 aListBoxes[24] = m_xVolumeLB.get();
309 aListBoxes[25] = m_xURLLB.get();
310 aListBoxes[26] = m_xCustom1LB.get();
311 aListBoxes[27] = m_xCustom2LB.get();
312 aListBoxes[28] = m_xCustom3LB.get();
313 aListBoxes[29] = m_xCustom4LB.get();
314 aListBoxes[30] = m_xCustom5LB.get();
316 aListBoxes[0]->append_text(sNone);
317 Reference< XNameAccess > xFields = getColumns( pDatMan->getForm() );
318 DBG_ASSERT(xFields.is(), "MappingDialog_Impl::MappingDialog_Impl : gave me an invalid form !");
319 if (xFields.is())
321 for(const OUString& rName : xFields->getElementNames())
322 aListBoxes[0]->append_text(rName);
325 Link<weld::ComboBox&,void> aLnk = LINK(this, MappingDialog_Impl, ListBoxSelectHdl);
327 aListBoxes[0]->set_active(0);
328 aListBoxes[0]->connect_changed(aLnk);
329 for(sal_uInt16 i = 1; i < COLUMN_COUNT; i++)
331 for(sal_Int32 j = 0, nEntryCount = aListBoxes[0]->get_count(); j < nEntryCount; ++j)
332 aListBoxes[i]->append_text(aListBoxes[0]->get_text(j));
333 aListBoxes[i]->set_active(0);
334 aListBoxes[i]->connect_changed(aLnk);
336 BibConfig* pConfig = BibModul::GetConfig();
337 BibDBDescriptor aDesc;
338 aDesc.sDataSource = pDatMan->getActiveDataSource();
339 aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
340 aDesc.nCommandType = CommandType::TABLE;
341 const Mapping* pMapping = pConfig->GetMapping(aDesc);
342 if(pMapping)
344 for(const auto & aColumnPair : pMapping->aColumnPairs)
346 sal_uInt16 nListBoxIndex = lcl_FindLogicalName( pConfig, aColumnPair.sLogicalColumnName);
347 if(nListBoxIndex < COLUMN_COUNT)
349 aListBoxes[nListBoxIndex]->set_active_text(aColumnPair.sRealColumnName);
355 IMPL_LINK(MappingDialog_Impl, ListBoxSelectHdl, weld::ComboBox&, rListBox, void)
357 const sal_Int32 nEntryPos = rListBox.get_active();
358 if (0 < nEntryPos)
360 for(auto & pListBoxe : aListBoxes)
362 if (&rListBox != pListBoxe && pListBoxe->get_active() == nEntryPos)
363 pListBoxe->set_active(0);
366 bModified = true;
369 IMPL_LINK_NOARG(MappingDialog_Impl, OkHdl, weld::Button&, void)
371 if(bModified)
373 Mapping aNew;
374 aNew.sTableName = pDatMan->getActiveDataTable();
375 aNew.sURL = pDatMan->getActiveDataSource();
377 sal_uInt16 nWriteIndex = 0;
378 BibConfig* pConfig = BibModul::GetConfig();
379 for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
381 OUString sSel = aListBoxes[nEntry]->get_active_text();
382 if(sSel != sNone)
384 aNew.aColumnPairs[nWriteIndex].sRealColumnName = sSel;
385 aNew.aColumnPairs[nWriteIndex].sLogicalColumnName = pConfig->GetDefColumnName(nEntry);
386 nWriteIndex++;
389 BibDBDescriptor aDesc;
390 aDesc.sDataSource = pDatMan->getActiveDataSource();
391 aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
392 aDesc.nCommandType = CommandType::TABLE;
393 pDatMan->ResetIdentifierMapping();
394 pConfig->SetMapping(aDesc, &aNew);
396 m_xDialog->response(bModified ? RET_OK : RET_CANCEL);
399 class DBChangeDialog_Impl : public weld::GenericDialogController
401 DBChangeDialogConfig_Impl aConfig;
402 BibDataManager* pDatMan;
404 std::unique_ptr<weld::TreeView> m_xSelectionLB;
406 DECL_LINK(DoubleClickHdl, weld::TreeView&, void);
407 public:
408 DBChangeDialog_Impl(weld::Window* pParent, BibDataManager* pMan);
410 OUString GetCurrentURL()const;
413 DBChangeDialog_Impl::DBChangeDialog_Impl(weld::Window* pParent, BibDataManager* pMan )
414 : GenericDialogController(pParent, "modules/sbibliography/ui/choosedatasourcedialog.ui", "ChooseDataSourceDialog")
415 , pDatMan(pMan)
416 , m_xSelectionLB(m_xBuilder->weld_tree_view("treeview"))
418 m_xSelectionLB->set_size_request(-1, m_xSelectionLB->get_height_rows(6));
419 m_xSelectionLB->connect_row_activated(LINK(this, DBChangeDialog_Impl, DoubleClickHdl));
420 m_xSelectionLB->make_sorted();
424 OUString sActiveSource = pDatMan->getActiveDataSource();
425 for (const OUString& rSourceName : aConfig.GetDataSourceNames())
426 m_xSelectionLB->append_text(rSourceName);
427 m_xSelectionLB->select_text(sActiveSource);
429 catch (const Exception& e)
431 SAL_WARN("extensions.biblio",
432 "Exception in BibDataManager::DBChangeDialog_Impl::DBChangeDialog_Impl "
433 << e);
437 IMPL_LINK_NOARG(DBChangeDialog_Impl, DoubleClickHdl, weld::TreeView&, void)
439 m_xDialog->response(RET_OK);
442 OUString DBChangeDialog_Impl::GetCurrentURL()const
444 return m_xSelectionLB->get_selected_text();
447 // XDispatchProvider
448 BibInterceptorHelper::BibInterceptorHelper( ::bib::BibBeamer* pBibBeamer, css::uno::Reference< css::frame::XDispatch > const & xDispatch)
450 if( pBibBeamer )
452 xInterception = pBibBeamer->getDispatchProviderInterception();
453 if( xInterception.is() )
454 xInterception->registerDispatchProviderInterceptor( this );
456 if( xDispatch.is() )
457 xFormDispatch = xDispatch;
460 BibInterceptorHelper::~BibInterceptorHelper( )
464 void BibInterceptorHelper::ReleaseInterceptor()
466 if ( xInterception.is() )
467 xInterception->releaseDispatchProviderInterceptor( this );
468 xInterception.clear();
471 css::uno::Reference< css::frame::XDispatch > SAL_CALL
472 BibInterceptorHelper::queryDispatch( const css::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
474 Reference< XDispatch > xReturn;
476 OUString aCommand( aURL.Path );
477 if ( aCommand == "FormSlots/ConfirmDeletion" )
478 xReturn = xFormDispatch;
479 else
480 if ( xSlaveDispatchProvider.is() )
481 xReturn = xSlaveDispatchProvider->queryDispatch( aURL, aTargetFrameName, nSearchFlags);
483 return xReturn;
486 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL
487 BibInterceptorHelper::queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& aDescripts )
489 Sequence< Reference< XDispatch> > aReturn( aDescripts.getLength() );
490 Reference< XDispatch >* pReturn = aReturn.getArray();
491 for ( const DispatchDescriptor& rDescript : aDescripts )
493 *pReturn++ = queryDispatch( rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags );
495 return aReturn;
498 // XDispatchProviderInterceptor
499 css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL
500 BibInterceptorHelper::getSlaveDispatchProvider( )
502 return xSlaveDispatchProvider;
505 void SAL_CALL BibInterceptorHelper::setSlaveDispatchProvider( const css::uno::Reference< css::frame::XDispatchProvider >& xNewSlaveDispatchProvider )
507 xSlaveDispatchProvider = xNewSlaveDispatchProvider;
510 css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL
511 BibInterceptorHelper::getMasterDispatchProvider( )
513 return xMasterDispatchProvider;
516 void SAL_CALL BibInterceptorHelper::setMasterDispatchProvider( const css::uno::Reference< css::frame::XDispatchProvider >& xNewMasterDispatchProvider )
518 xMasterDispatchProvider = xNewMasterDispatchProvider;
522 OUString const gGridName("theGrid");
523 OUString const gViewName("theView");
524 OUString const gGlobalName("theGlobals");
525 OUString const gBeamerSize("theBeamerSize");
526 OUString const gViewSize("theViewSize");
528 BibDataManager::BibDataManager()
529 :BibDataManager_Base( GetMutex() )
530 ,m_aLoadListeners(m_aMutex)
531 ,pBibView( nullptr )
532 ,pToolbar(nullptr)
537 BibDataManager::~BibDataManager()
539 Reference< XLoadable > xLoad( m_xForm, UNO_QUERY );
540 Reference< XPropertySet > xPrSet( m_xForm, UNO_QUERY );
541 Reference< XComponent > xComp( m_xForm, UNO_QUERY );
542 if ( m_xForm.is() )
544 Reference< XComponent > xConnection;
545 xPrSet->getPropertyValue("ActiveConnection") >>= xConnection;
546 if (xLoad.is())
547 xLoad->unload();
548 if (xComp.is())
549 xComp->dispose();
550 if(xConnection.is())
551 xConnection->dispose();
552 m_xForm = nullptr;
554 if( m_xInterceptorHelper.is() )
556 m_xInterceptorHelper->ReleaseInterceptor();
557 m_xInterceptorHelper.clear();
561 void BibDataManager::InsertFields(const Reference< XFormComponent > & _rxGrid)
563 if ( !_rxGrid.is() )
564 return;
568 Reference< XNameContainer > xColContainer( _rxGrid, UNO_QUERY );
569 // remove the old fields
570 if ( xColContainer->hasElements() )
572 for ( OUString& rName : xColContainer->getElementNames() )
573 xColContainer->removeByName( rName );
576 Reference< XNameAccess > xFields = getColumns( m_xForm );
577 if (!xFields.is())
578 return;
580 Reference< XGridColumnFactory > xColFactory( _rxGrid, UNO_QUERY );
582 Reference< XPropertySet > xField;
584 for ( const OUString& rField : xFields->getElementNames() )
586 xFields->getByName( rField ) >>= xField;
588 OUString sCurrentModelType;
589 const OUString sType("Type");
590 sal_Int32 nType = 0;
591 bool bIsFormatted = false;
592 bool bFormattedIsNumeric = true;
593 xField->getPropertyValue(sType) >>= nType;
594 switch(nType)
596 case DataType::BIT:
597 case DataType::BOOLEAN:
598 sCurrentModelType = "CheckBox";
599 break;
601 case DataType::BINARY:
602 case DataType::VARBINARY:
603 case DataType::LONGVARBINARY:
604 case DataType::BLOB:
605 sCurrentModelType = "TextField";
606 break;
608 case DataType::VARCHAR:
609 case DataType::LONGVARCHAR:
610 case DataType::CHAR:
611 case DataType::CLOB:
612 bFormattedIsNumeric = false;
613 [[fallthrough]];
614 default:
615 sCurrentModelType = "FormattedField";
616 bIsFormatted = true;
617 break;
620 Reference< XPropertySet > xCurrentCol = xColFactory->createColumn(sCurrentModelType);
621 if (bIsFormatted)
623 OUString sFormatKey("FormatKey");
624 xCurrentCol->setPropertyValue(sFormatKey, xField->getPropertyValue(sFormatKey));
625 Any aFormatted(bFormattedIsNumeric);
626 xCurrentCol->setPropertyValue("TreatAsNumber", aFormatted);
628 Any aColName = makeAny( rField );
629 xCurrentCol->setPropertyValue(FM_PROP_CONTROLSOURCE, aColName);
630 xCurrentCol->setPropertyValue(FM_PROP_LABEL, aColName);
632 xColContainer->insertByName( rField, makeAny( xCurrentCol ) );
635 catch (const Exception&)
637 OSL_FAIL("Exception in BibDataManager::InsertFields");
641 Reference< awt::XControlModel > BibDataManager::updateGridModel()
643 return updateGridModel( m_xForm );
646 Reference< awt::XControlModel > const & BibDataManager::updateGridModel(const Reference< XForm > & xDbForm)
650 Reference< XPropertySet > aFormPropSet( xDbForm, UNO_QUERY );
651 OUString sName;
652 aFormPropSet->getPropertyValue("Command") >>= sName;
654 if ( !m_xGridModel.is() )
656 m_xGridModel = createGridModel( gGridName );
658 Reference< XNameContainer > xNameCont(xDbForm, UNO_QUERY);
659 xNameCont->insertByName( sName, makeAny( m_xGridModel ) );
662 // insert the fields
663 Reference< XFormComponent > xFormComp( m_xGridModel, UNO_QUERY );
664 InsertFields( xFormComp );
666 catch (const Exception&)
668 OSL_FAIL("::updateGridModel: something went wrong !");
671 return m_xGridModel;
674 Reference< XForm > BibDataManager::createDatabaseForm(BibDBDescriptor& rDesc)
676 Reference< XForm > xResult;
679 Reference< XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
680 m_xForm.set( xMgr->createInstance( "com.sun.star.form.component.Form" ), UNO_QUERY );
682 Reference< XPropertySet > aPropertySet( m_xForm, UNO_QUERY );
684 aDataSourceURL = rDesc.sDataSource;
685 if(aPropertySet.is())
687 Any aVal;
688 aVal <<= sal_Int32(ResultSetType::SCROLL_INSENSITIVE);
689 aPropertySet->setPropertyValue("ResultSetType",aVal );
690 aVal <<= sal_Int32(ResultSetConcurrency::READ_ONLY);
691 aPropertySet->setPropertyValue("ResultSetConcurrency", aVal);
693 //Caching for Performance
694 aVal <<= sal_Int32(50);
695 aPropertySet->setPropertyValue("FetchSize", aVal);
697 Reference< XConnection > xConnection = getConnection(rDesc.sDataSource);
698 aVal <<= xConnection;
699 aPropertySet->setPropertyValue("ActiveConnection", aVal);
701 Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
702 Reference< XNameAccess > xTables = xSupplyTables.is() ?
703 xSupplyTables->getTables() : Reference< XNameAccess > ();
705 Sequence< OUString > aTableNameSeq;
706 if (xTables.is())
707 aTableNameSeq = xTables->getElementNames();
709 if(aTableNameSeq.hasElements())
711 if(!rDesc.sTableOrQuery.isEmpty())
712 aActiveDataTable = rDesc.sTableOrQuery;
713 else
715 rDesc.sTableOrQuery = aActiveDataTable = aTableNameSeq[0];
716 rDesc.nCommandType = CommandType::TABLE;
719 aVal <<= aActiveDataTable;
720 aPropertySet->setPropertyValue("Command", aVal);
721 aVal <<= rDesc.nCommandType;
722 aPropertySet->setPropertyValue("CommandType", aVal);
725 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
726 aQuoteChar = xMetaData->getIdentifierQuoteString();
728 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
729 if ( xFactory.is() )
730 m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
732 OUString aString("SELECT * FROM ");
734 OUString sCatalog, sSchema, sName;
735 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation );
736 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
738 m_xParser->setElementaryQuery(aString);
739 BibConfig* pConfig = BibModul::GetConfig();
740 pConfig->setQueryField(getQueryField());
741 startQueryWith(pConfig->getQueryText());
743 xResult = m_xForm;
747 catch (const Exception&)
749 OSL_FAIL("::createDatabaseForm: something went wrong !");
752 return xResult;
755 Sequence< OUString > BibDataManager::getDataSources()
757 Sequence< OUString > aTableNameSeq;
761 Reference< XTablesSupplier > xSupplyTables( getConnection( m_xForm ), UNO_QUERY );
762 Reference< XNameAccess > xTables;
763 if (xSupplyTables.is())
764 xTables = xSupplyTables->getTables();
765 if (xTables.is())
766 aTableNameSeq = xTables->getElementNames();
768 catch (const Exception&)
770 OSL_FAIL("::getDataSources: something went wrong !");
773 return aTableNameSeq;
777 void BibDataManager::setFilter(const OUString& rQuery)
779 if(!m_xParser.is())
780 return;
783 m_xParser->setFilter( rQuery );
784 OUString aQuery = m_xParser->getFilter();
785 Reference< XPropertySet > xFormProps( m_xForm, UNO_QUERY_THROW );
786 xFormProps->setPropertyValue( "Filter", makeAny( aQuery ) );
787 xFormProps->setPropertyValue( "ApplyFilter", makeAny( true ) );
788 reload();
790 catch (const Exception&)
792 DBG_UNHANDLED_EXCEPTION("extensions.biblio");
798 OUString BibDataManager::getFilter()
801 OUString aQueryString;
804 Reference< XPropertySet > xFormProps( m_xForm, UNO_QUERY_THROW );
805 OSL_VERIFY( xFormProps->getPropertyValue( "Filter" ) >>= aQueryString );
807 catch (const Exception&)
809 DBG_UNHANDLED_EXCEPTION("extensions.biblio");
813 return aQueryString;
817 Sequence< OUString > BibDataManager::getQueryFields()
819 Sequence< OUString > aFieldSeq;
820 Reference< XNameAccess > xFields = getColumns( m_xForm );
821 if (xFields.is())
822 aFieldSeq = xFields->getElementNames();
823 return aFieldSeq;
826 OUString BibDataManager::getQueryField()
828 BibConfig* pConfig = BibModul::GetConfig();
829 OUString aFieldString = pConfig->getQueryField();
830 if(aFieldString.isEmpty())
832 const Sequence< OUString > aSeq = getQueryFields();
833 if(aSeq.hasElements())
835 aFieldString=aSeq[0];
838 return aFieldString;
841 void BibDataManager::startQueryWith(const OUString& rQuery)
843 BibConfig* pConfig = BibModul::GetConfig();
844 pConfig->setQueryText( rQuery );
846 OUString aQueryString;
847 if(!rQuery.isEmpty())
849 aQueryString=aQuoteChar;
850 aQueryString+=getQueryField();
851 aQueryString+=aQuoteChar;
852 aQueryString+=" like '";
853 OUString sQuery = rQuery.replaceAll("?","_").replaceAll("*","%");
854 aQueryString += sQuery;
855 aQueryString+="%'";
857 setFilter(aQueryString);
860 void BibDataManager::setActiveDataSource(const OUString& rURL)
862 OUString sTmp(aDataSourceURL);
863 aDataSourceURL = rURL;
865 Reference< XPropertySet > aPropertySet( m_xForm, UNO_QUERY );
866 if(aPropertySet.is())
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", makeAny(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(),UNO_QUERY);
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();
940 void BibDataManager::setActiveDataTable(const OUString& rTable)
942 ResetIdentifierMapping();
945 Reference< XPropertySet > aPropertySet( m_xForm, UNO_QUERY );
947 if(aPropertySet.is())
949 Reference< XConnection > xConnection = getConnection( m_xForm );
950 Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
951 Reference< XNameAccess > xAccess = xSupplyTables->getTables();
952 Sequence< OUString > aTableNameSeq = xAccess->getElementNames();
953 sal_uInt32 nCount = aTableNameSeq.getLength();
955 const OUString* pTableNames = aTableNameSeq.getConstArray();
956 const OUString* pTableNamesEnd = pTableNames + nCount;
958 for ( ; pTableNames != pTableNamesEnd; ++pTableNames )
960 if ( rTable == *pTableNames )
962 aActiveDataTable = rTable;
963 Any aVal; aVal <<= rTable;
964 aPropertySet->setPropertyValue( "Command", aVal );
965 break;
968 if (pTableNames != pTableNamesEnd)
970 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
971 aQuoteChar = xMetaData->getIdentifierQuoteString();
973 Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
974 if ( xFactory.is() )
975 m_xParser.set( xFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY );
977 OUString aString("SELECT * FROM ");
979 OUString sCatalog, sSchema, sName;
980 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation );
981 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
983 m_xParser->setElementaryQuery(aString);
985 BibConfig* pConfig = BibModul::GetConfig();
986 pConfig->setQueryField(getQueryField());
987 startQueryWith(pConfig->getQueryText());
989 BibDBDescriptor aDesc;
990 aDesc.sDataSource = aDataSourceURL;
991 aDesc.sTableOrQuery = aActiveDataTable;
992 aDesc.nCommandType = CommandType::TABLE;
993 BibModul::GetConfig()->SetBibliographyURL(aDesc);
997 catch (const Exception&)
999 OSL_FAIL("::setActiveDataTable: something went wrong !");
1004 void SAL_CALL BibDataManager::load( )
1006 if ( isLoaded() )
1007 // nothing to do
1008 return;
1010 Reference< XLoadable > xFormAsLoadable( m_xForm, UNO_QUERY );
1011 DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::load: invalid form!");
1012 if ( xFormAsLoadable.is() )
1014 xFormAsLoadable->load();
1016 EventObject aEvt( static_cast< XWeak* >( this ) );
1017 m_aLoadListeners.notifyEach( &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() )
1032 EventObject aEvt( static_cast< XWeak* >( this ) );
1035 m_aLoadListeners.notifyEach( &XLoadListener::unloading, aEvt );
1038 xFormAsLoadable->unload();
1041 m_aLoadListeners.notifyEach( &XLoadListener::unloaded, aEvt );
1047 void SAL_CALL BibDataManager::reload( )
1049 if ( !isLoaded() )
1050 // nothing to do
1051 return;
1053 Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
1054 DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::unload: invalid form!");
1055 if ( xFormAsLoadable.is() )
1057 EventObject aEvt( static_cast< XWeak* >( this ) );
1060 m_aLoadListeners.notifyEach( &XLoadListener::reloading, aEvt );
1063 xFormAsLoadable->reload();
1066 m_aLoadListeners.notifyEach( &XLoadListener::reloaded, aEvt );
1072 sal_Bool SAL_CALL BibDataManager::isLoaded( )
1074 Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
1075 DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::isLoaded: invalid form!");
1077 bool bLoaded = false;
1078 if ( xFormAsLoadable.is() )
1079 bLoaded = xFormAsLoadable->isLoaded();
1080 return bLoaded;
1084 void SAL_CALL BibDataManager::addLoadListener( const Reference< XLoadListener >& aListener )
1086 m_aLoadListeners.addInterface( aListener );
1090 void SAL_CALL BibDataManager::removeLoadListener( const Reference< XLoadListener >& aListener )
1092 m_aLoadListeners.removeInterface( aListener );
1096 Reference< awt::XControlModel > BibDataManager::createGridModel(const OUString& rName)
1098 Reference< awt::XControlModel > xModel;
1102 // create the control model
1103 Reference< XMultiServiceFactory > xMgr = ::comphelper::getProcessServiceFactory();
1104 Reference< XInterface > xObject = xMgr->createInstance("com.sun.star.form.component.GridControl");
1105 xModel.set( xObject, UNO_QUERY );
1107 // set the
1108 Reference< XPropertySet > xPropSet( xModel, UNO_QUERY );
1109 xPropSet->setPropertyValue( "Name", makeAny( rName ) );
1111 // set the name of the to-be-created control
1112 Any aAny(OUString("com.sun.star.form.control.InteractionGridControl"));
1113 xPropSet->setPropertyValue( "DefaultControl",aAny );
1115 // the helpURL
1116 OUString uProp("HelpURL");
1117 Reference< XPropertySetInfo > xPropInfo = xPropSet->getPropertySetInfo();
1118 if (xPropInfo->hasPropertyByName(uProp))
1120 xPropSet->setPropertyValue(
1121 uProp, makeAny<OUString>(INET_HID_SCHEME HID_BIB_DB_GRIDCTRL));
1124 catch (const Exception&)
1126 OSL_FAIL("::createGridModel: something went wrong !");
1129 return xModel;
1132 OUString BibDataManager::getControlName(sal_Int32 nFormatKey )
1134 OUString aResStr;
1135 switch (nFormatKey)
1137 case DataType::BIT:
1138 case DataType::BOOLEAN:
1139 aResStr="CheckBox";
1140 break;
1141 case DataType::TINYINT:
1142 case DataType::SMALLINT:
1143 case DataType::INTEGER:
1144 aResStr="NumericField";
1145 break;
1146 case DataType::REAL:
1147 case DataType::DOUBLE:
1148 case DataType::NUMERIC:
1149 case DataType::DECIMAL:
1150 aResStr="FormattedField";
1151 break;
1152 case DataType::TIMESTAMP:
1153 aResStr="FormattedField";
1154 break;
1155 case DataType::DATE:
1156 aResStr="DateField";
1157 break;
1158 case DataType::TIME:
1159 aResStr="TimeField";
1160 break;
1161 case DataType::CHAR:
1162 case DataType::VARCHAR:
1163 case DataType::LONGVARCHAR:
1164 default:
1165 aResStr="TextField";
1166 break;
1168 return aResStr;
1171 Reference< awt::XControlModel > BibDataManager::loadControlModel(
1172 const OUString& rName, bool bForceListBox)
1174 Reference< awt::XControlModel > xModel;
1175 OUString aName("View_");
1176 aName += rName;
1180 Reference< XNameAccess > xFields = getColumns( m_xForm );
1181 if (!xFields.is())
1182 return xModel;
1183 Reference< XPropertySet > xField;
1185 Any aElement;
1187 if(xFields->hasByName(rName))
1189 aElement = xFields->getByName(rName);
1190 aElement >>= xField;
1192 const OUString sType("Type");
1193 sal_Int32 nFormatKey = 0;
1194 xField->getPropertyValue(sType) >>= nFormatKey;
1196 OUString aInstanceName("com.sun.star.form.component.");
1198 if (bForceListBox)
1199 aInstanceName += "ListBox";
1200 else
1201 aInstanceName += getControlName(nFormatKey);
1203 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
1204 Reference< XInterface > xObject = xContext->getServiceManager()->createInstanceWithContext(aInstanceName, xContext);
1205 xModel.set( xObject, UNO_QUERY );
1206 Reference< XPropertySet > xPropSet( xModel, UNO_QUERY );
1207 Any aFieldName; aFieldName <<= aName;
1209 xPropSet->setPropertyValue( FM_PROP_NAME,aFieldName);
1210 xPropSet->setPropertyValue( FM_PROP_CONTROLSOURCE, makeAny( rName ) );
1211 xPropSet->setPropertyValue("NativeWidgetLook", makeAny( true ) );
1213 if (bForceListBox)
1215 uno::Any aAny;
1217 //uno::Reference< beans::XPropertySet > xPropSet(xControl, UNO_QUERY);
1218 aAny <<= sal_Int16(1);
1219 xPropSet->setPropertyValue("BoundColumn", aAny);
1220 aAny <<= ListSourceType_VALUELIST;
1221 xPropSet->setPropertyValue("ListSourceType", aAny);
1223 uno::Sequence<OUString> aListSource(TYPE_COUNT);
1224 OUString* pListSourceArr = aListSource.getArray();
1225 //pListSourceArr[0] = "select TypeName, TypeIndex from TypeNms";
1226 for(sal_Int32 i = 0; i < TYPE_COUNT; ++i)
1227 pListSourceArr[i] = OUString::number(i);
1228 aAny <<= aListSource;
1230 xPropSet->setPropertyValue("ListSource", aAny);
1232 uno::Sequence<OUString> aValues(TYPE_COUNT + 1);
1233 OUString* pValuesArr = aValues.getArray();
1234 pValuesArr[0] = BibResId(ST_TYPE_ARTICLE);
1235 pValuesArr[1] = BibResId(ST_TYPE_BOOK);
1236 pValuesArr[2] = BibResId(ST_TYPE_BOOKLET);
1237 pValuesArr[3] = BibResId(ST_TYPE_CONFERENCE);
1238 pValuesArr[4] = BibResId(ST_TYPE_INBOOK );
1239 pValuesArr[5] = BibResId(ST_TYPE_INCOLLECTION);
1240 pValuesArr[6] = BibResId(ST_TYPE_INPROCEEDINGS);
1241 pValuesArr[7] = BibResId(ST_TYPE_JOURNAL );
1242 pValuesArr[8] = BibResId(ST_TYPE_MANUAL );
1243 pValuesArr[9] = BibResId(ST_TYPE_MASTERSTHESIS);
1244 pValuesArr[10] = BibResId(ST_TYPE_MISC );
1245 pValuesArr[11] = BibResId(ST_TYPE_PHDTHESIS );
1246 pValuesArr[12] = BibResId(ST_TYPE_PROCEEDINGS );
1247 pValuesArr[13] = BibResId(ST_TYPE_TECHREPORT );
1248 pValuesArr[14] = BibResId(ST_TYPE_UNPUBLISHED );
1249 pValuesArr[15] = BibResId(ST_TYPE_EMAIL );
1250 pValuesArr[16] = BibResId(ST_TYPE_WWW );
1251 pValuesArr[17] = BibResId(ST_TYPE_CUSTOM1 );
1252 pValuesArr[18] = BibResId(ST_TYPE_CUSTOM2 );
1253 pValuesArr[19] = BibResId(ST_TYPE_CUSTOM3 );
1254 pValuesArr[20] = BibResId(ST_TYPE_CUSTOM4 );
1255 pValuesArr[21] = BibResId(ST_TYPE_CUSTOM5 );
1256 // empty string if an invalid value no values is set
1257 pValuesArr[TYPE_COUNT].clear();
1259 aAny <<= aValues;
1261 xPropSet->setPropertyValue("StringItemList", aAny);
1263 xPropSet->setPropertyValue( "Dropdown", Any(true) );
1266 Reference< XFormComponent > aFormComp(xModel,UNO_QUERY );
1268 Reference< XNameContainer > xNameCont( m_xForm, UNO_QUERY );
1269 xNameCont->insertByName(aName, makeAny( aFormComp ) );
1271 // now if the form where we inserted the new model is already loaded, notify the model of this
1272 // Note that this implementation below is a HACK as it relies on the fact that the model adds itself
1273 // as load listener to its parent, which is an implementation detail of the model.
1275 // the better solution would be the following:
1276 // in the current scenario, we insert a control model into a form. This results in the control model
1277 // adding itself as load listener to the form. Now, the form should realize that it's already loaded
1278 // and notify the model (which it knows as XLoadListener only) immediately. This seems to make sense.
1279 // (as an analogon to the XStatusListener semantics).
1281 // But this would be way too risky for this last-day fix here.
1282 Reference< XLoadable > xLoad( m_xForm, UNO_QUERY );
1283 if ( xLoad.is() && xLoad->isLoaded() )
1285 Reference< XLoadListener > xListener( aFormComp, UNO_QUERY );
1286 if ( xListener.is() )
1288 EventObject aLoadSource;
1289 aLoadSource.Source = xLoad;
1290 xListener->loaded( aLoadSource );
1295 catch (const Exception&)
1297 OSL_FAIL("::loadControlModel: something went wrong !");
1299 return xModel;
1302 void BibDataManager::CreateMappingDialog(weld::Window* pParent)
1304 MappingDialog_Impl aDlg(pParent, this);
1305 if (RET_OK == aDlg.run() && pBibView)
1307 reload();
1311 OUString BibDataManager::CreateDBChangeDialog(weld::Window* pParent)
1313 OUString uRet;
1314 DBChangeDialog_Impl aDlg(pParent, this);
1315 if (aDlg.run() == RET_OK)
1317 OUString sNewURL = aDlg.GetCurrentURL();
1318 if(sNewURL != getActiveDataSource())
1320 uRet = sNewURL;
1323 return uRet;
1326 void BibDataManager::DispatchDBChangeDialog()
1328 if (pToolbar)
1329 pToolbar->SendDispatch(pToolbar->GetChangeSourceId(), Sequence< PropertyValue >());
1332 const OUString& BibDataManager::GetIdentifierMapping()
1334 if(sIdentifierMapping.isEmpty())
1336 BibConfig* pConfig = BibModul::GetConfig();
1337 BibDBDescriptor aDesc;
1338 aDesc.sDataSource = getActiveDataSource();
1339 aDesc.sTableOrQuery = getActiveDataTable();
1340 aDesc.nCommandType = CommandType::TABLE;
1341 const Mapping* pMapping = pConfig->GetMapping(aDesc);
1342 sIdentifierMapping = pConfig->GetDefColumnName(IDENTIFIER_POS);
1343 if(pMapping)
1345 for(const auto & aColumnPair : pMapping->aColumnPairs)
1347 if(aColumnPair.sLogicalColumnName == sIdentifierMapping)
1349 sIdentifierMapping = aColumnPair.sRealColumnName;
1350 break;
1355 return sIdentifierMapping;
1358 void BibDataManager::SetToolbar(BibToolBar* pSet)
1360 pToolbar = pSet;
1361 if(pToolbar)
1362 pToolbar->SetDatMan(*this);
1365 uno::Reference< form::runtime::XFormController > const & BibDataManager::GetFormController()
1367 if(!m_xFormCtrl.is())
1369 Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
1370 m_xFormCtrl = form::runtime::FormController::create(xContext);
1371 m_xFormCtrl->setModel(uno::Reference< awt::XTabControllerModel > (getForm(), UNO_QUERY));
1372 m_xFormDispatch.set( m_xFormCtrl, UNO_QUERY);
1374 return m_xFormCtrl;
1377 void BibDataManager::RegisterInterceptor( ::bib::BibBeamer* pBibBeamer)
1379 DBG_ASSERT( !m_xInterceptorHelper.is(), "BibDataManager::RegisterInterceptor: called twice!" );
1381 if( pBibBeamer )
1382 m_xInterceptorHelper = new BibInterceptorHelper( pBibBeamer, m_xFormDispatch);
1386 bool BibDataManager::HasActiveConnection()
1388 return getConnection( m_xForm ).is();
1391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */