1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/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>
51 #include "bibresid.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>
60 #include <connectivity/dbtools.hxx>
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
;
75 constexpr OUStringLiteral FM_PROP_LABEL
= u
"Label";
76 constexpr OUStringLiteral FM_PROP_CONTROLSOURCE
= u
"DataField";
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 !");
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
&)
120 static Reference
< XConnection
> getConnection(const Reference
< XInterface
> & xRowSet
)
122 Reference
< XConnection
> xConn
;
125 Reference
< XPropertySet
> xFormProps(xRowSet
, UNO_QUERY
);
126 if (!xFormProps
.is())
129 xConn
.set(xFormProps
->getPropertyValue("ActiveConnection"), UNO_QUERY
);
132 SAL_INFO("extensions.biblio", "no active connection");
135 catch (const Exception
&)
137 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
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())
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) !");
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");
183 class MappingDialog_Impl
: public weld::GenericDialogController
185 BibDataManager
* pDatMan
;
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);
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
))
245 MappingDialog_Impl::MappingDialog_Impl(weld::Window
* pParent
, BibDataManager
* pMan
)
246 : GenericDialogController(pParent
, "modules/sbibliography/ui/mappingdialog.ui", "MappingDialog")
248 , sNone(BibResId(RID_BIB_STR_NONE
))
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 !");
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
);
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();
367 for(auto & pListBoxe
: aListBoxes
)
369 if (&rListBox
!= pListBoxe
&& pListBoxe
->get_active() == nEntryPos
)
370 pListBoxe
->set_active(0);
376 IMPL_LINK_NOARG(MappingDialog_Impl
, OkHdl
, weld::Button
&, void)
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();
391 aNew
.aColumnPairs
[nWriteIndex
].sRealColumnName
= sSel
;
392 aNew
.aColumnPairs
[nWriteIndex
].sLogicalColumnName
= pConfig
->GetDefColumnName(nEntry
);
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
);
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);
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
);
450 OUString
DBChangeDialog_Impl::GetCurrentURL()const
452 return m_xSelectionLB
->get_selected_text();
456 BibInterceptorHelper::BibInterceptorHelper( const ::bib::BibBeamer
* pBibBeamer
, css::uno::Reference
< css::frame::XDispatch
> const & xDispatch
)
460 xInterception
= pBibBeamer
->getDispatchProviderInterception();
461 if( xInterception
.is() )
462 xInterception
->registerDispatchProviderInterceptor( this );
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
;
488 if ( xSlaveDispatchProvider
.is() )
489 xReturn
= xSlaveDispatchProvider
->queryDispatch( aURL
, aTargetFrameName
, nSearchFlags
);
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
);
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 :BibDataManager_Base( GetMutex() )
534 ,m_aLoadListeners(m_aMutex
)
541 BibDataManager::~BibDataManager()
543 Reference
< XLoadable
> xLoad( m_xForm
, UNO_QUERY
);
544 Reference
< XPropertySet
> xPrSet( m_xForm
, UNO_QUERY
);
545 Reference
< XComponent
> xComp( m_xForm
, UNO_QUERY
);
548 Reference
< XComponent
> xConnection
;
549 xPrSet
->getPropertyValue("ActiveConnection") >>= xConnection
;
555 xConnection
->dispose();
558 if( m_xInterceptorHelper
.is() )
560 m_xInterceptorHelper
->ReleaseInterceptor();
561 m_xInterceptorHelper
.clear();
565 void BibDataManager::InsertFields(const Reference
< XFormComponent
> & _rxGrid
)
572 Reference
< XNameContainer
> xColContainer( _rxGrid
, UNO_QUERY
);
573 // remove the old fields
574 if ( xColContainer
->hasElements() )
576 const Sequence
<OUString
> aOldNames
= xColContainer
->getElementNames();
577 for ( const OUString
& rName
: aOldNames
)
578 xColContainer
->removeByName( rName
);
581 Reference
< XNameAccess
> xFields
= getColumns( m_xForm
);
585 Reference
< XGridColumnFactory
> xColFactory( _rxGrid
, UNO_QUERY
);
587 Reference
< XPropertySet
> xField
;
589 const Sequence
<OUString
> aFieldNames
= xFields
->getElementNames();
590 for ( const OUString
& rField
: aFieldNames
)
592 xFields
->getByName( rField
) >>= xField
;
594 OUString sCurrentModelType
;
596 bool bIsFormatted
= false;
597 bool bFormattedIsNumeric
= true;
598 xField
->getPropertyValue("Type") >>= nType
;
602 case DataType::BOOLEAN
:
603 sCurrentModelType
= "CheckBox";
606 case DataType::BINARY
:
607 case DataType::VARBINARY
:
608 case DataType::LONGVARBINARY
:
610 sCurrentModelType
= "TextField";
613 case DataType::VARCHAR
:
614 case DataType::LONGVARCHAR
:
617 bFormattedIsNumeric
= false;
620 sCurrentModelType
= "FormattedField";
625 Reference
< XPropertySet
> xCurrentCol
= xColFactory
->createColumn(sCurrentModelType
);
628 OUString
sFormatKey("FormatKey");
629 xCurrentCol
->setPropertyValue(sFormatKey
, xField
->getPropertyValue(sFormatKey
));
630 Any
aFormatted(bFormattedIsNumeric
);
631 xCurrentCol
->setPropertyValue("TreatAsNumber", aFormatted
);
633 Any aColName
= makeAny( rField
);
634 xCurrentCol
->setPropertyValue(FM_PROP_CONTROLSOURCE
, aColName
);
635 xCurrentCol
->setPropertyValue(FM_PROP_LABEL
, aColName
);
637 xColContainer
->insertByName( rField
, makeAny( xCurrentCol
) );
640 catch (const Exception
&)
642 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
646 Reference
< awt::XControlModel
> BibDataManager::updateGridModel()
648 return updateGridModel( m_xForm
);
651 Reference
< awt::XControlModel
> const & BibDataManager::updateGridModel(const Reference
< XForm
> & xDbForm
)
655 Reference
< XPropertySet
> aFormPropSet( xDbForm
, UNO_QUERY
);
657 aFormPropSet
->getPropertyValue("Command") >>= sName
;
659 if ( !m_xGridModel
.is() )
661 m_xGridModel
= createGridModel( gGridName
);
663 Reference
< XNameContainer
> xNameCont(xDbForm
, UNO_QUERY
);
664 xNameCont
->insertByName( sName
, makeAny( m_xGridModel
) );
668 Reference
< XFormComponent
> xFormComp( m_xGridModel
, UNO_QUERY
);
669 InsertFields( xFormComp
);
671 catch (const Exception
&)
673 OSL_FAIL("::updateGridModel: something went wrong !");
679 Reference
< XForm
> BibDataManager::createDatabaseForm(BibDBDescriptor
& rDesc
)
681 Reference
< XForm
> xResult
;
684 Reference
< XMultiServiceFactory
> xMgr
= comphelper::getProcessServiceFactory();
685 m_xForm
.set( xMgr
->createInstance( "com.sun.star.form.component.Form" ), UNO_QUERY
);
687 Reference
< XPropertySet
> aPropertySet( m_xForm
, UNO_QUERY
);
689 aDataSourceURL
= rDesc
.sDataSource
;
690 if(aPropertySet
.is())
693 aVal
<<= sal_Int32(ResultSetType::SCROLL_INSENSITIVE
);
694 aPropertySet
->setPropertyValue("ResultSetType",aVal
);
695 aVal
<<= sal_Int32(ResultSetConcurrency::READ_ONLY
);
696 aPropertySet
->setPropertyValue("ResultSetConcurrency", aVal
);
698 //Caching for Performance
699 aVal
<<= sal_Int32(50);
700 aPropertySet
->setPropertyValue("FetchSize", aVal
);
702 Reference
< XConnection
> xConnection
= getConnection(rDesc
.sDataSource
);
703 aVal
<<= xConnection
;
704 aPropertySet
->setPropertyValue("ActiveConnection", aVal
);
706 Reference
< XTablesSupplier
> xSupplyTables(xConnection
, UNO_QUERY
);
707 Reference
< XNameAccess
> xTables
= xSupplyTables
.is() ?
708 xSupplyTables
->getTables() : Reference
< XNameAccess
> ();
710 Sequence
< OUString
> aTableNameSeq
;
712 aTableNameSeq
= xTables
->getElementNames();
714 if(aTableNameSeq
.hasElements())
716 if(!rDesc
.sTableOrQuery
.isEmpty())
717 aActiveDataTable
= rDesc
.sTableOrQuery
;
720 rDesc
.sTableOrQuery
= aActiveDataTable
= aTableNameSeq
[0];
721 rDesc
.nCommandType
= CommandType::TABLE
;
724 aVal
<<= aActiveDataTable
;
725 aPropertySet
->setPropertyValue("Command", aVal
);
726 aVal
<<= rDesc
.nCommandType
;
727 aPropertySet
->setPropertyValue("CommandType", aVal
);
730 Reference
< XDatabaseMetaData
> xMetaData
= xConnection
->getMetaData();
731 aQuoteChar
= xMetaData
->getIdentifierQuoteString();
733 Reference
< XMultiServiceFactory
> xFactory(xConnection
, UNO_QUERY
);
735 m_xParser
.set( xFactory
->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY
);
737 OUString
aString("SELECT * FROM ");
739 OUString sCatalog
, sSchema
, sName
;
740 ::dbtools::qualifiedNameComponents( xMetaData
, aActiveDataTable
, sCatalog
, sSchema
, sName
, ::dbtools::EComposeRule::InDataManipulation
);
741 aString
+= ::dbtools::composeTableNameForSelect( xConnection
, sCatalog
, sSchema
, sName
);
743 m_xParser
->setElementaryQuery(aString
);
744 BibConfig
* pConfig
= BibModul::GetConfig();
745 pConfig
->setQueryField(getQueryField());
746 startQueryWith(pConfig
->getQueryText());
752 catch (const Exception
&)
754 OSL_FAIL("::createDatabaseForm: something went wrong !");
760 Sequence
< OUString
> BibDataManager::getDataSources() const
762 Sequence
< OUString
> aTableNameSeq
;
766 Reference
< XTablesSupplier
> xSupplyTables( getConnection( m_xForm
), UNO_QUERY
);
767 Reference
< XNameAccess
> xTables
;
768 if (xSupplyTables
.is())
769 xTables
= xSupplyTables
->getTables();
771 aTableNameSeq
= xTables
->getElementNames();
773 catch (const Exception
&)
775 OSL_FAIL("::getDataSources: something went wrong !");
778 return aTableNameSeq
;
782 void BibDataManager::setFilter(const OUString
& rQuery
)
788 m_xParser
->setFilter( rQuery
);
789 OUString aQuery
= m_xParser
->getFilter();
790 Reference
< XPropertySet
> xFormProps( m_xForm
, UNO_QUERY_THROW
);
791 xFormProps
->setPropertyValue( "Filter", makeAny( aQuery
) );
792 xFormProps
->setPropertyValue( "ApplyFilter", makeAny( true ) );
795 catch (const Exception
&)
797 DBG_UNHANDLED_EXCEPTION("extensions.biblio");
803 OUString
BibDataManager::getFilter() const
806 OUString aQueryString
;
809 Reference
< XPropertySet
> xFormProps( m_xForm
, UNO_QUERY_THROW
);
810 OSL_VERIFY( xFormProps
->getPropertyValue( "Filter" ) >>= aQueryString
);
812 catch (const Exception
&)
814 DBG_UNHANDLED_EXCEPTION("extensions.biblio");
822 Sequence
< OUString
> BibDataManager::getQueryFields() const
824 Sequence
< OUString
> aFieldSeq
;
825 Reference
< XNameAccess
> xFields
= getColumns( m_xForm
);
827 aFieldSeq
= xFields
->getElementNames();
831 OUString
BibDataManager::getQueryField() const
833 BibConfig
* pConfig
= BibModul::GetConfig();
834 OUString aFieldString
= pConfig
->getQueryField();
835 if(aFieldString
.isEmpty())
837 const Sequence
< OUString
> aSeq
= getQueryFields();
838 if(aSeq
.hasElements())
840 aFieldString
=aSeq
[0];
846 void BibDataManager::startQueryWith(const OUString
& rQuery
)
848 BibConfig
* pConfig
= BibModul::GetConfig();
849 pConfig
->setQueryText( rQuery
);
851 OUString aQueryString
;
852 if(!rQuery
.isEmpty())
854 aQueryString
=aQuoteChar
+ getQueryField() + aQuoteChar
+ " like '";
855 OUString sQuery
= rQuery
.replaceAll("?","_").replaceAll("*","%");
856 aQueryString
+= sQuery
+ "%'";
858 setFilter(aQueryString
);
861 void BibDataManager::setActiveDataSource(const OUString
& rURL
)
863 OUString
sTmp(aDataSourceURL
);
864 aDataSourceURL
= rURL
;
866 Reference
< XPropertySet
> aPropertySet( m_xForm
, UNO_QUERY
);
867 if(!aPropertySet
.is())
872 Reference
< XComponent
> xOldConnection
;
873 aPropertySet
->getPropertyValue("ActiveConnection") >>= xOldConnection
;
875 Reference
< XConnection
> xConnection
= getConnection(rURL
);
876 if(!xConnection
.is())
878 aDataSourceURL
= sTmp
;
881 Any aVal
; aVal
<<= xConnection
;
882 aPropertySet
->setPropertyValue("ActiveConnection", aVal
);
883 Reference
< XMultiServiceFactory
> xFactory(xConnection
, UNO_QUERY
);
885 m_xParser
.set( xFactory
->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY
);
887 if(xOldConnection
.is())
888 xOldConnection
->dispose();
890 Sequence
< OUString
> aTableNameSeq
;
891 Reference
< XTablesSupplier
> xSupplyTables(xConnection
, UNO_QUERY
);
892 if(xSupplyTables
.is())
894 Reference
< XNameAccess
> xAccess
= xSupplyTables
->getTables();
895 aTableNameSeq
= xAccess
->getElementNames();
897 if(aTableNameSeq
.hasElements())
899 aActiveDataTable
= aTableNameSeq
[0];
900 aVal
<<= aActiveDataTable
;
901 aPropertySet
->setPropertyValue("Command", aVal
);
902 aPropertySet
->setPropertyValue("CommandType", makeAny(CommandType::TABLE
));
903 //Caching for Performance
904 aVal
<<= sal_Int32(50);
905 aPropertySet
->setPropertyValue("FetchSize", aVal
);
906 OUString
aString("SELECT * FROM ");
907 // quote the table name which may contain catalog.schema.table
908 Reference
<XDatabaseMetaData
> xMetaData
= xConnection
->getMetaData();
909 aQuoteChar
= xMetaData
->getIdentifierQuoteString();
911 OUString sCatalog
, sSchema
, sName
;
912 ::dbtools::qualifiedNameComponents( xMetaData
, aActiveDataTable
, sCatalog
, sSchema
, sName
, ::dbtools::EComposeRule::InDataManipulation
);
913 aString
+= ::dbtools::composeTableNameForSelect( xConnection
, sCatalog
, sSchema
, sName
);
915 m_xParser
->setElementaryQuery(aString
);
916 BibConfig
* pConfig
= BibModul::GetConfig();
917 pConfig
->setQueryField(getQueryField());
918 startQueryWith(pConfig
->getQueryText());
919 setActiveDataTable(aActiveDataTable
);
921 FeatureStateEvent aEvent
;
923 aEvent
.IsEnabled
= true;
924 aEvent
.Requery
= false;
925 aEvent
.FeatureDescriptor
= getActiveDataTable();
927 aEvent
.State
<<= getDataSources();
931 aURL
.Complete
=".uno:Bib/source";
932 aEvent
.FeatureURL
= aURL
;
933 pToolbar
->statusChanged( aEvent
);
941 void BibDataManager::setActiveDataTable(const OUString
& rTable
)
943 ResetIdentifierMapping();
946 Reference
< XPropertySet
> aPropertySet( m_xForm
, UNO_QUERY
);
948 if(aPropertySet
.is())
950 Reference
< XConnection
> xConnection
= getConnection( m_xForm
);
951 Reference
< XTablesSupplier
> xSupplyTables(xConnection
, UNO_QUERY
);
952 Reference
< XNameAccess
> xAccess
= xSupplyTables
->getTables();
953 Sequence
< OUString
> aTableNameSeq
= xAccess
->getElementNames();
954 sal_uInt32 nCount
= aTableNameSeq
.getLength();
956 const OUString
* pTableNames
= aTableNameSeq
.getConstArray();
957 const OUString
* pTableNamesEnd
= pTableNames
+ nCount
;
959 for ( ; pTableNames
!= pTableNamesEnd
; ++pTableNames
)
961 if ( rTable
== *pTableNames
)
963 aActiveDataTable
= rTable
;
964 Any aVal
; aVal
<<= rTable
;
965 aPropertySet
->setPropertyValue( "Command", aVal
);
969 if (pTableNames
!= pTableNamesEnd
)
971 Reference
< XDatabaseMetaData
> xMetaData
= xConnection
->getMetaData();
972 aQuoteChar
= xMetaData
->getIdentifierQuoteString();
974 Reference
< XMultiServiceFactory
> xFactory(xConnection
, UNO_QUERY
);
976 m_xParser
.set( xFactory
->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY
);
978 OUString
aString("SELECT * FROM ");
980 OUString sCatalog
, sSchema
, sName
;
981 ::dbtools::qualifiedNameComponents( xMetaData
, aActiveDataTable
, sCatalog
, sSchema
, sName
, ::dbtools::EComposeRule::InDataManipulation
);
982 aString
+= ::dbtools::composeTableNameForSelect( xConnection
, sCatalog
, sSchema
, sName
);
984 m_xParser
->setElementaryQuery(aString
);
986 BibConfig
* pConfig
= BibModul::GetConfig();
987 pConfig
->setQueryField(getQueryField());
988 startQueryWith(pConfig
->getQueryText());
990 BibDBDescriptor aDesc
;
991 aDesc
.sDataSource
= aDataSourceURL
;
992 aDesc
.sTableOrQuery
= aActiveDataTable
;
993 aDesc
.nCommandType
= CommandType::TABLE
;
994 BibModul::GetConfig()->SetBibliographyURL(aDesc
);
998 catch (const Exception
&)
1000 OSL_FAIL("::setActiveDataTable: something went wrong !");
1005 void SAL_CALL
BibDataManager::load( )
1011 Reference
< XLoadable
> xFormAsLoadable( m_xForm
, UNO_QUERY
);
1012 DBG_ASSERT( xFormAsLoadable
.is() || !m_xForm
.is(), "BibDataManager::load: invalid form!");
1013 if ( xFormAsLoadable
.is() )
1015 xFormAsLoadable
->load();
1017 EventObject
aEvt( static_cast< XWeak
* >( this ) );
1018 m_aLoadListeners
.notifyEach( &XLoadListener::loaded
, aEvt
);
1023 void SAL_CALL
BibDataManager::unload( )
1029 Reference
< XLoadable
>xFormAsLoadable( m_xForm
, UNO_QUERY
);
1030 DBG_ASSERT( xFormAsLoadable
.is() || !m_xForm
.is(), "BibDataManager::unload: invalid form!");
1031 if ( !xFormAsLoadable
.is() )
1034 EventObject
aEvt( static_cast< XWeak
* >( this ) );
1037 m_aLoadListeners
.notifyEach( &XLoadListener::unloading
, aEvt
);
1040 xFormAsLoadable
->unload();
1043 m_aLoadListeners
.notifyEach( &XLoadListener::unloaded
, aEvt
);
1048 void SAL_CALL
BibDataManager::reload( )
1054 Reference
< XLoadable
>xFormAsLoadable( m_xForm
, UNO_QUERY
);
1055 DBG_ASSERT( xFormAsLoadable
.is() || !m_xForm
.is(), "BibDataManager::unload: invalid form!");
1056 if ( !xFormAsLoadable
.is() )
1059 EventObject
aEvt( static_cast< XWeak
* >( this ) );
1062 m_aLoadListeners
.notifyEach( &XLoadListener::reloading
, aEvt
);
1065 xFormAsLoadable
->reload();
1068 m_aLoadListeners
.notifyEach( &XLoadListener::reloaded
, aEvt
);
1073 sal_Bool SAL_CALL
BibDataManager::isLoaded( )
1075 Reference
< XLoadable
>xFormAsLoadable( m_xForm
, UNO_QUERY
);
1076 DBG_ASSERT( xFormAsLoadable
.is() || !m_xForm
.is(), "BibDataManager::isLoaded: invalid form!");
1078 bool bLoaded
= false;
1079 if ( xFormAsLoadable
.is() )
1080 bLoaded
= xFormAsLoadable
->isLoaded();
1085 void SAL_CALL
BibDataManager::addLoadListener( const Reference
< XLoadListener
>& aListener
)
1087 m_aLoadListeners
.addInterface( aListener
);
1091 void SAL_CALL
BibDataManager::removeLoadListener( const Reference
< XLoadListener
>& aListener
)
1093 m_aLoadListeners
.removeInterface( aListener
);
1097 Reference
< awt::XControlModel
> BibDataManager::createGridModel(const OUString
& rName
)
1099 Reference
< awt::XControlModel
> xModel
;
1103 // create the control model
1104 Reference
< XMultiServiceFactory
> xMgr
= ::comphelper::getProcessServiceFactory();
1105 Reference
< XInterface
> xObject
= xMgr
->createInstance("com.sun.star.form.component.GridControl");
1106 xModel
.set( xObject
, UNO_QUERY
);
1109 Reference
< XPropertySet
> xPropSet( xModel
, UNO_QUERY
);
1110 xPropSet
->setPropertyValue( "Name", makeAny( rName
) );
1112 // set the name of the to-be-created control
1113 Any
aAny(OUString("com.sun.star.form.control.InteractionGridControl"));
1114 xPropSet
->setPropertyValue( "DefaultControl",aAny
);
1117 OUString
uProp("HelpURL");
1118 Reference
< XPropertySetInfo
> xPropInfo
= xPropSet
->getPropertySetInfo();
1119 if (xPropInfo
->hasPropertyByName(uProp
))
1121 xPropSet
->setPropertyValue(
1122 uProp
, makeAny
<OUString
>(INET_HID_SCHEME
+ HID_BIB_DB_GRIDCTRL
));
1125 catch (const Exception
&)
1127 OSL_FAIL("::createGridModel: something went wrong !");
1133 OUString
BibDataManager::getControlName(sal_Int32 nFormatKey
)
1139 case DataType::BOOLEAN
:
1142 case DataType::TINYINT
:
1143 case DataType::SMALLINT
:
1144 case DataType::INTEGER
:
1145 aResStr
="NumericField";
1147 case DataType::REAL
:
1148 case DataType::DOUBLE
:
1149 case DataType::NUMERIC
:
1150 case DataType::DECIMAL
:
1151 aResStr
="FormattedField";
1153 case DataType::TIMESTAMP
:
1154 aResStr
="FormattedField";
1156 case DataType::DATE
:
1157 aResStr
="DateField";
1159 case DataType::TIME
:
1160 aResStr
="TimeField";
1162 case DataType::CHAR
:
1163 case DataType::VARCHAR
:
1164 case DataType::LONGVARCHAR
:
1166 aResStr
="TextField";
1172 Reference
< awt::XControlModel
> BibDataManager::loadControlModel(
1173 const OUString
& rName
, bool bForceListBox
)
1175 Reference
< awt::XControlModel
> xModel
;
1176 OUString aName
= "View_" + rName
;
1180 Reference
< XNameAccess
> xFields
= getColumns( m_xForm
);
1183 Reference
< XPropertySet
> xField
;
1187 if(xFields
->hasByName(rName
))
1189 aElement
= xFields
->getByName(rName
);
1190 aElement
>>= xField
;
1192 sal_Int32 nFormatKey
= 0;
1193 xField
->getPropertyValue("Type") >>= nFormatKey
;
1195 OUString
aInstanceName("com.sun.star.form.component.");
1198 aInstanceName
+= "ListBox";
1200 aInstanceName
+= getControlName(nFormatKey
);
1202 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
1203 Reference
< XInterface
> xObject
= xContext
->getServiceManager()->createInstanceWithContext(aInstanceName
, xContext
);
1204 xModel
.set( xObject
, UNO_QUERY
);
1205 Reference
< XPropertySet
> xPropSet( xModel
, UNO_QUERY
);
1206 Any aFieldName
; aFieldName
<<= aName
;
1208 xPropSet
->setPropertyValue( FM_PROP_NAME
,aFieldName
);
1209 xPropSet
->setPropertyValue( FM_PROP_CONTROLSOURCE
, makeAny( rName
) );
1210 xPropSet
->setPropertyValue("NativeWidgetLook", makeAny( true ) );
1216 //uno::Reference< beans::XPropertySet > xPropSet(xControl, UNO_QUERY);
1217 aAny
<<= sal_Int16(1);
1218 xPropSet
->setPropertyValue("BoundColumn", aAny
);
1219 aAny
<<= ListSourceType_VALUELIST
;
1220 xPropSet
->setPropertyValue("ListSourceType", aAny
);
1222 uno::Sequence
<OUString
> aListSource(TYPE_COUNT
);
1223 OUString
* pListSourceArr
= aListSource
.getArray();
1224 //pListSourceArr[0] = "select TypeName, TypeIndex from TypeNms";
1225 for(sal_Int32 i
= 0; i
< TYPE_COUNT
; ++i
)
1226 pListSourceArr
[i
] = OUString::number(i
);
1227 aAny
<<= aListSource
;
1229 xPropSet
->setPropertyValue("ListSource", aAny
);
1231 uno::Sequence
<OUString
> aValues(TYPE_COUNT
+ 1);
1232 OUString
* pValuesArr
= aValues
.getArray();
1233 pValuesArr
[0] = BibResId(ST_TYPE_ARTICLE
);
1234 pValuesArr
[1] = BibResId(ST_TYPE_BOOK
);
1235 pValuesArr
[2] = BibResId(ST_TYPE_BOOKLET
);
1236 pValuesArr
[3] = BibResId(ST_TYPE_CONFERENCE
);
1237 pValuesArr
[4] = BibResId(ST_TYPE_INBOOK
);
1238 pValuesArr
[5] = BibResId(ST_TYPE_INCOLLECTION
);
1239 pValuesArr
[6] = BibResId(ST_TYPE_INPROCEEDINGS
);
1240 pValuesArr
[7] = BibResId(ST_TYPE_JOURNAL
);
1241 pValuesArr
[8] = BibResId(ST_TYPE_MANUAL
);
1242 pValuesArr
[9] = BibResId(ST_TYPE_MASTERSTHESIS
);
1243 pValuesArr
[10] = BibResId(ST_TYPE_MISC
);
1244 pValuesArr
[11] = BibResId(ST_TYPE_PHDTHESIS
);
1245 pValuesArr
[12] = BibResId(ST_TYPE_PROCEEDINGS
);
1246 pValuesArr
[13] = BibResId(ST_TYPE_TECHREPORT
);
1247 pValuesArr
[14] = BibResId(ST_TYPE_UNPUBLISHED
);
1248 pValuesArr
[15] = BibResId(ST_TYPE_EMAIL
);
1249 pValuesArr
[16] = BibResId(ST_TYPE_WWW
);
1250 pValuesArr
[17] = BibResId(ST_TYPE_CUSTOM1
);
1251 pValuesArr
[18] = BibResId(ST_TYPE_CUSTOM2
);
1252 pValuesArr
[19] = BibResId(ST_TYPE_CUSTOM3
);
1253 pValuesArr
[20] = BibResId(ST_TYPE_CUSTOM4
);
1254 pValuesArr
[21] = BibResId(ST_TYPE_CUSTOM5
);
1255 // empty string if an invalid value no values is set
1256 pValuesArr
[TYPE_COUNT
].clear();
1260 xPropSet
->setPropertyValue("StringItemList", aAny
);
1262 xPropSet
->setPropertyValue( "Dropdown", Any(true) );
1265 Reference
< XFormComponent
> aFormComp(xModel
,UNO_QUERY
);
1267 Reference
< XNameContainer
> xNameCont( m_xForm
, UNO_QUERY
);
1268 xNameCont
->insertByName(aName
, makeAny( aFormComp
) );
1270 // now if the form where we inserted the new model is already loaded, notify the model of this
1271 // Note that this implementation below is a HACK as it relies on the fact that the model adds itself
1272 // as load listener to its parent, which is an implementation detail of the model.
1274 // the better solution would be the following:
1275 // in the current scenario, we insert a control model into a form. This results in the control model
1276 // adding itself as load listener to the form. Now, the form should realize that it's already loaded
1277 // and notify the model (which it knows as XLoadListener only) immediately. This seems to make sense.
1278 // (as an analogon to the XStatusListener semantics).
1280 // But this would be way too risky for this last-day fix here.
1281 Reference
< XLoadable
> xLoad( m_xForm
, UNO_QUERY
);
1282 if ( xLoad
.is() && xLoad
->isLoaded() )
1284 Reference
< XLoadListener
> xListener( aFormComp
, UNO_QUERY
);
1285 if ( xListener
.is() )
1287 EventObject aLoadSource
;
1288 aLoadSource
.Source
= xLoad
;
1289 xListener
->loaded( aLoadSource
);
1294 catch (const Exception
&)
1296 OSL_FAIL("::loadControlModel: something went wrong !");
1301 void BibDataManager::CreateMappingDialog(weld::Window
* pParent
)
1303 MappingDialog_Impl
aDlg(pParent
, this);
1304 if (RET_OK
== aDlg
.run() && pBibView
)
1310 OUString
BibDataManager::CreateDBChangeDialog(weld::Window
* pParent
)
1313 DBChangeDialog_Impl
aDlg(pParent
, this);
1314 if (aDlg
.run() == RET_OK
)
1316 OUString sNewURL
= aDlg
.GetCurrentURL();
1317 if(sNewURL
!= getActiveDataSource())
1325 void BibDataManager::DispatchDBChangeDialog()
1328 pToolbar
->SendDispatch(pToolbar
->GetChangeSourceId(), Sequence
< PropertyValue
>());
1331 const OUString
& BibDataManager::GetIdentifierMapping()
1333 if(sIdentifierMapping
.isEmpty())
1335 BibConfig
* pConfig
= BibModul::GetConfig();
1336 BibDBDescriptor aDesc
;
1337 aDesc
.sDataSource
= getActiveDataSource();
1338 aDesc
.sTableOrQuery
= getActiveDataTable();
1339 aDesc
.nCommandType
= CommandType::TABLE
;
1340 const Mapping
* pMapping
= pConfig
->GetMapping(aDesc
);
1341 sIdentifierMapping
= pConfig
->GetDefColumnName(IDENTIFIER_POS
);
1344 for(const auto & aColumnPair
: pMapping
->aColumnPairs
)
1346 if(aColumnPair
.sLogicalColumnName
== sIdentifierMapping
)
1348 sIdentifierMapping
= aColumnPair
.sRealColumnName
;
1354 return sIdentifierMapping
;
1357 void BibDataManager::SetToolbar(BibToolBar
* pSet
)
1361 pToolbar
->SetDatMan(*this);
1364 uno::Reference
< form::runtime::XFormController
> const & BibDataManager::GetFormController()
1366 if(!m_xFormCtrl
.is())
1368 Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
1369 m_xFormCtrl
= form::runtime::FormController::create(xContext
);
1370 m_xFormCtrl
->setModel(uno::Reference
< awt::XTabControllerModel
> (getForm(), UNO_QUERY
));
1371 m_xFormDispatch
.set( m_xFormCtrl
, UNO_QUERY
);
1376 void BibDataManager::RegisterInterceptor( const ::bib::BibBeamer
* pBibBeamer
)
1378 DBG_ASSERT( !m_xInterceptorHelper
.is(), "BibDataManager::RegisterInterceptor: called twice!" );
1381 m_xInterceptorHelper
= new BibInterceptorHelper( pBibBeamer
, m_xFormDispatch
);
1385 bool BibDataManager::HasActiveConnection() const
1387 return getConnection( m_xForm
).is();
1390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */