34#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
35#include <com/sun/star/sdbcx/XKeysSupplier.hpp>
36#include <com/sun/star/sdbcx/KeyType.hpp>
37#include <com/sun/star/container/XNameAccess.hpp>
38#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
39#include <com/sun/star/sdbc/XRowSet.hpp>
40#include <com/sun/star/sdb/CommandType.hpp>
41#include <com/sun/star/sdb/SQLContext.hpp>
42#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
68 FieldLinkRow(std::unique_ptr<weld::ComboBox> xDetailColumn,
69 std::unique_ptr<weld::ComboBox> xMasterColumn);
99 std::unique_ptr<weld::ComboBox> xMasterColumn)
100 : m_xDetailColumn(
std::move(xDetailColumn))
101 , m_xMasterColumn(
std::move(xMasterColumn))
111 const OUString* pFieldName = _rFieldNames.getConstArray();
112 const OUString* pFieldNameEnd = pFieldName + _rFieldNames.getLength();
113 for ( ; pFieldName != pFieldNameEnd; ++pFieldName )
121 return !_rName.isEmpty();
132 m_aLinkChangeHandler.Call( *
this );
138 const Reference< XPropertySet >& _rxMasterForm,
const Reference< XComponentContext >& _rxContext,
139 const OUString& _sExplanation,
140 OUString _sDetailLabel,
141 OUString _sMasterLabel)
142 : GenericDialogController(_pParent,
"modules/spropctrlr/ui/formlinksdialog.ui",
"FormLinks")
144 , m_xDetailForm( _rxDetailForm )
145 , m_xMasterForm( _rxMasterForm )
146 , m_sDetailLabel(
std::move(_sDetailLabel))
147 , m_sMasterLabel(
std::move(_sMasterLabel))
148 , m_xExplanation(m_xBuilder->weld_label(
"explanationLabel"))
149 , m_xDetailLabel(m_xBuilder->weld_label(
"detailLabel"))
150 , m_xMasterLabel(m_xBuilder->weld_label(
"masterLabel"))
151 , m_xRow1(
std::make_unique<
FieldLinkRow>(m_xBuilder->weld_combo_box(
"detailCombobox1"),
152 m_xBuilder->weld_combo_box(
"masterCombobox1")))
153 , m_xRow2(
std::make_unique<
FieldLinkRow>(m_xBuilder->weld_combo_box(
"detailCombobox2"),
154 m_xBuilder->weld_combo_box(
"masterCombobox2")))
155 , m_xRow3(
std::make_unique<
FieldLinkRow>(m_xBuilder->weld_combo_box(
"detailCombobox3"),
156 m_xBuilder->weld_combo_box(
"masterCombobox3")))
157 , m_xRow4(
std::make_unique<
FieldLinkRow>(m_xBuilder->weld_combo_box(
"detailCombobox4"),
158 m_xBuilder->weld_combo_box(
"masterCombobox4")))
159 , m_xOK(m_xBuilder->weld_button(
"ok"))
160 , m_xSuggest(m_xBuilder->weld_button(
"suggestButton"))
168 if ( !_sExplanation.isEmpty() )
189 std::vector< OUString > aDetailFields; aDetailFields.reserve( 4 );
190 std::vector< OUString > aMasterFields; aMasterFields.reserve( 4 );
198 OUString sDetailField, sMasterField;
201 if ( sDetailField.isEmpty() && sMasterField.isEmpty() )
204 aDetailFields.push_back( sDetailField );
205 aMasterFields.push_back( sMasterField );
220 "caught an exception while setting the properties!");
226 short nResult = GenericDialogController::run();
236 Sequence< OUString > sDetailFields;
239 Sequence< OUString > sMasterFields;
258 if ( sDetailType.isEmpty() )
270 if ( sMasterType.isEmpty() )
284 _rDetailFields.resize( 4 );
285 _rMasterFields.resize( 4 );
290 for ( sal_Int32
i = 0;
i < 4; ++
i )
302 Sequence< OUString > aDetailFields;
303 Sequence< OUString > aMasterFields;
311 std::vector< OUString > aDetailFields1;
313 std::vector< OUString > aMasterFields1;
335 for ( sal_Int32
i = 0; (
i < 4 ) && bEnable; ++
i )
337 OUString sNotInterestedInRightNow;
344 m_xOK->set_sensitive(bEnable);
355 sal_Int32 nCommandType = CommandType::COMMAND;
361 if ( ( nCommandType == CommandType::TABLE )
362 || ( nCommandType == CommandType::QUERY )
375 _rNames.realloc( 0 );
383 OSL_ENSURE( _rxForm.is(),
"FormLinkDialog::getFormFields: invalid form!" );
385 sal_Int32 nCommandType = CommandType::COMMAND;
390 Reference< XConnection > xConnection;
393 _rNames = ::dbtools::getFieldNamesByCommandDescriptor(
400 catch (
const SQLContext& e) { aErrorInfo = e; }
401 catch (
const SQLWarning& e) { aErrorInfo = e; }
402 catch (
const SQLException& e ) { aErrorInfo = e; }
405 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"FormLinkDialog::getFormFields: caught a non-SQL exception!" );
411 OUString sErrorMessage;
413 sErrorMessage =
PcrRes(STR_ERROR_RETRIEVING_COLUMNS);
414 sErrorMessage = sErrorMessage.replaceFirst(
"#", sCommand);
418 aContext.Message = sErrorMessage;
419 aContext.NextException = aErrorInfo.
get();
425 OSL_PRECOND( _rxFormProps.is(),
"FormLinkDialog::ensureFormConnection: invalid form!" );
426 if ( !_rxFormProps.is() )
431 if ( !_rxConnection.is() )
432 _rxConnection = ::dbtools::connectRowset( Reference< XRowSet >( _rxFormProps, UNO_QUERY ),
m_xContext,
nullptr );
438 if ( _rxFormProps.is() )
440 Reference< XConnection > xConnection;
441 if ( !::dbtools::isEmbeddedInDatabase( _rxFormProps, xConnection ) )
443 if ( xConnection.is() )
444 _rxMeta = xConnection->getMetaData();
451 Reference< XPropertySet > xTable;
454 Reference< XTablesSupplier > xTablesInForm( ::dbtools::getCurrentSettingsComposer( _rxFormProps,
m_xContext,
nullptr ), UNO_QUERY );
455 Reference< XNameAccess > xTables;
456 if ( xTablesInForm.is() )
457 xTables = xTablesInForm->getTables();
458 Sequence< OUString > aTableNames;
460 aTableNames = xTables->getElementNames();
462 if ( aTableNames.getLength() == 1 )
464 xTables->getByName( aTableNames[ 0 ] ) >>= xTable;
465 OSL_ENSURE( xTable.is(),
"FormLinkDialog::getCanonicUnderlyingTable: invalid table!" );
478 std::vector< OUString >& _rLeftFields, std::vector< OUString >& _rRightFields )
482 Reference< XKeysSupplier > xSuppKeys( _rxLHS, UNO_QUERY );
483 Reference< XIndexAccess > xKeys;
484 if ( xSuppKeys.is() )
485 xKeys = xSuppKeys->getKeys();
489 Reference< XPropertySet > xKey;
490 Reference< XColumnsSupplier > xKeyColSupp( xKey, UNO_QUERY );
491 Reference< XIndexAccess > xKeyColumns;
492 Reference< XPropertySet > xKeyColumn;
493 OUString sColumnName, sRelatedColumnName;
495 const sal_Int32 keyCount = xKeys->getCount();
496 for ( sal_Int32 key = 0; key < keyCount; ++key )
498 xKeys->getByIndex( key ) >>= xKey;
499 sal_Int32 nKeyType = 0;
500 xKey->getPropertyValue(
"Type") >>= nKeyType;
501 if ( nKeyType != KeyType::FOREIGN )
505 xKeyColSupp.set(xKey, css::uno::UNO_QUERY);
506 if ( xKeyColSupp.is() )
507 xKeyColumns.set(xKeyColSupp->getColumns(), css::uno::UNO_QUERY);
508 OSL_ENSURE( xKeyColumns.is(),
"FormLinkDialog::getExistingRelation: could not obtain the columns for the key!" );
510 if ( !xKeyColumns.is() )
513 const sal_Int32 columnCount = xKeyColumns->getCount();
514 _rLeftFields.resize( columnCount );
515 _rRightFields.resize( columnCount );
516 for ( sal_Int32 column = 0; column < columnCount; ++column )
519 xKeyColumns->getByIndex( column ) >>= xKeyColumn;
520 OSL_ENSURE( xKeyColumn.is(),
"FormLinkDialog::getExistingRelation: invalid key column!" );
521 if ( xKeyColumn.is() )
523 xKeyColumn->getPropertyValue(
PROPERTY_NAME ) >>= sColumnName;
524 xKeyColumn->getPropertyValue(
"RelatedColumn") >>= sRelatedColumnName;
526 _rLeftFields[ column ] = sColumnName;
527 _rRightFields[ column ] = sRelatedColumnName;
538 return ( !_rLeftFields.empty() ) && ( !_rLeftFields[ 0 ].isEmpty() );
550 OUString sMasterDS, sDetailDS;
553 bool bEnable = ( sMasterDS == sDetailDS );
558 Reference< XDatabaseMetaData > xMeta;
560 OSL_ENSURE( xMeta.is(),
"FormLinkDialog::initializeSuggest: unable to retrieve the meta data for the connection!" );
563 bEnable = xMeta.is() && xMeta->supportsIntegrityEnhancementFacility();
572 Reference< XPropertySet > xDetailTable, xMasterTable;
577 bEnable = xDetailTable.is() && xMasterTable.is();
587 "extensions.propctrlr",
588 "FormLinkDialog::initializeSuggest: nonsense!" );
612 initializeFieldRowsFrom( m_aRelationDetailColumns, m_aRelationMasterColumns );
622 initializeColumnLabels();
623 initializeFieldLists();
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
void fillList(LinkParticipant _eWhich, const Sequence< OUString > &_rFieldNames)
std::unique_ptr< weld::ComboBox > m_xDetailColumn
void SetLinkChangeHandler(const Link< FieldLinkRow &, void > &_rHdl)
Link< FieldLinkRow &, void > m_aLinkChangeHandler
FieldLinkRow(std::unique_ptr< weld::ComboBox > xDetailColumn, std::unique_ptr< weld::ComboBox > xMasterColumn)
bool GetFieldName(LinkParticipant _eWhich, OUString &_rName) const
retrieves the selected field name for either the master or the detail field
std::unique_ptr< weld::ComboBox > m_xMasterColumn
DECL_LINK(OnFieldNameChanged, weld::ComboBox &, void)
void SetFieldName(LinkParticipant _eWhich, const OUString &_rName)
virtual OUString get_active_text() const=0
virtual void set_entry_text(const OUString &rStr)=0
void append_text(const OUString &rStr)
std::shared_ptr< weld::Dialog > m_xDialog
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XComponentContext > m_xContext
#define LINK(Instance, Class, Member)
#define SAL_WARN_IF(condition, area, stream)
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
a property handler for any virtual string properties
OUString PcrRes(TranslateId aId)
IMPL_LINK_NOARG(OBrowserLine, OnButtonFocus, weld::Widget &, void)