22#include <core_resource.hxx>
28#include <com/sun/star/frame/XUntitledNumbers.hpp>
29#include <com/sun/star/container/XChild.hpp>
30#include <com/sun/star/sdb/XDocumentDataSource.hpp>
31#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
32#include <com/sun/star/sdbc/XDataSource.hpp>
33#include <com/sun/star/util/NumberFormatter.hpp>
34#include <com/sun/star/lang/IllegalArgumentException.hpp>
41#include <rtl/ustrbuf.hxx>
52 using ::com::sun::star::uno::Any;
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::beans::XPropertySet;
55 using ::com::sun::star::uno::Sequence;
56 using ::com::sun::star::uno::Type;
57 using ::com::sun::star::uno::XComponentContext;
58 using ::com::sun::star::sdbc::XConnection;
59 using ::com::sun::star::uno::UNO_QUERY;
60 using ::com::sun::star::container::XChild;
61 using ::com::sun::star::sdbc::XDataSource;
62 using ::com::sun::star::util::NumberFormatter;
63 using ::com::sun::star::util::XNumberFormatter;
64 using ::com::sun::star::util::XNumberFormatsSupplier;
65 using ::com::sun::star::frame::XFrame;
66 using ::com::sun::star::uno::Exception;
67 using ::com::sun::star::lang::EventObject;
68 using ::com::sun::star::beans::PropertyValue;
69 using ::com::sun::star::frame::XModel;
70 using ::com::sun::star::sdb::XOfficeDatabaseDocument;
71 using ::com::sun::star::awt::XWindow;
72 using ::com::sun::star::sdbc::XDatabaseMetaData;
73 using ::com::sun::star::sdb::XDocumentDataSource;
74 using ::com::sun::star::document::XEmbeddedScripts;
75 using ::com::sun::star::lang::IllegalArgumentException;
76 using ::com::sun::star::uno::UNO_SET_THROW;
77 using ::com::sun::star::uno::UNO_QUERY_THROW;
78 using ::com::sun::star::frame::XUntitledNumbers;
82 class DataSourceHolder
89 explicit DataSourceHolder(
const Reference< XDataSource >& _rxDataSource)
92 Reference< XDocumentDataSource > xDocDS(
m_xDataSource, UNO_QUERY );
100 const Reference< XPropertySet >& getDataSourceProps()
const {
return m_xDataSourceProps; }
101 const Reference< XOfficeDatabaseDocument >& getDatabaseDocument()
const {
return m_xDocument; }
156 "DBSubComponentController_Impl::documentHasScriptSupport: not completely initialized, yet - don't know!?" );
163 "DBSubComponentController_Impl::setDocumentScriptSupport: already initialized!" );
183 const ::comphelper::NamedValueCollection& rArguments( getInitParams() );
188 if ( !xConnection.is() )
189 ::dbtools::isEmbeddedInDatabase( getModel(), xConnection );
191 if ( xConnection.is() )
194 bool bShowError =
true;
204 throw IllegalArgumentException();
212 if (
m_pImpl->documentHasScriptSupport() )
217 return DBSubComponentController_Base::queryInterface( _rType );
223 if ( !
m_pImpl->documentHasScriptSupport() )
226 auto newEnd = std::remove_if(
begin,
end,
236 DBG_ASSERT( !
isConnected(),
"DBSubComponentController::initializeConnection: not to be called when already connected!" );
243 startConnectionListening(
m_pImpl->m_xConnection );
249 OSL_PRECOND( !
m_pImpl->m_aDataSource.is(),
"DBSubComponentController::initializeConnection: already a data source in this phase?" );
253 if ( xConnAsChild.is() )
254 xDS.set( xConnAsChild->getParent(), UNO_QUERY );
257 m_pImpl->m_aDataSource = DataSourceHolder(xDS);
259 SAL_WARN_IF( !
m_pImpl->m_aDataSource.is(),
"dbaccess.ui",
"DBSubComponentController::initializeConnection: unable to obtain the data source object!" );
264 m_pImpl->m_nDocStartNumber = 1;
265 if ( xUntitledProvider.is() )
266 m_pImpl->m_nDocStartNumber = xUntitledProvider->leaseNumber(
static_cast< XWeak*
>(
this ) );
276 DBG_ASSERT( !
m_pImpl->m_sDataSourceName.isEmpty(),
"DBSubComponentController::initializeConnection: invalid data source name!" );
280 m_pImpl->m_xFormatter.set(NumberFormatter::create(getORB()), UNO_QUERY_THROW);
281 m_pImpl->m_xFormatter->attachNumberFormatsSupplier(xSupplier);
283 OSL_ENSURE(
m_pImpl->m_xFormatter.is(),
"No NumberFormatter!");
293 OSL_ENSURE(!
m_pImpl->m_bSuspended,
"Cannot reconnect while suspended!");
295 stopConnectionListening(
m_pImpl->m_xConnection );
296 m_pImpl->m_aSdbMetaData.reset(
nullptr );
297 m_pImpl->m_xConnection.clear();
300 bool bReConnect =
true;
304 VclMessageType::Question, VclButtonsType::YesNo,
305 DBA_RES(STR_QUERY_CONNECTION_LOST)));
306 bReConnect = (
RET_YES == xQuery->run());
322 stopConnectionListening(
m_pImpl->m_xConnection);
323 m_pImpl->m_aSdbMetaData.reset(
nullptr );
324 m_pImpl->m_xConnection.clear();
338 DBSubComponentController_Base::disposing();
344 m_pImpl->m_aDataSource.clear();
352 && !getBroadcastHelper().bInDispose
353 && !getBroadcastHelper().bDisposed
367 DBSubComponentController_Base::disposing( _rSource );
383 return m_pImpl->m_aCurrentError.isValid();
388 return m_pImpl->m_aCurrentError;
398 m_pImpl->m_bSuspended = bSuspend;
407 if ( !_rxModel.is() )
409 if ( !DBSubComponentController_Base::attachModel( _rxModel ) )
412 m_pImpl->m_bNotAttached =
false;
413 if (
m_pImpl->m_nDocStartNumber == 1 )
414 releaseNumberForComponent();
417 m_pImpl->m_nDocStartNumber = 1;
418 if ( xUntitledProvider.is() )
419 m_pImpl->m_nDocStartNumber = xUntitledProvider->leaseNumber(
static_cast< XWeak*
>(
this ) );
432 DBSubComponentController_Base::Execute( _nId, _rArgs );
433 InvalidateFeature( _nId );
440 if ( xDataSourceProps.is() )
446 OUString aMessage(
DBA_RES(RID_STR_CONNECTION_LOST));
452 pWin =
getView()->Window::GetParent();
455 VclMessageType::Info, VclButtonsType::Ok, aMessage));
475 m_pImpl->m_bEditable = _bEditable;
480 return m_pImpl->m_aSdbMetaData;
485 return m_pImpl->m_xConnection.is();
494 xMeta.set(
m_pImpl->m_xConnection->getMetaData(), UNO_SET_THROW );
505 return m_pImpl->m_aDataSource.getDataSourceProps();
510 return m_pImpl->m_aDataSource.is();
530 ::osl::MutexGuard aGuard(
getMutex() );
531 if ( m_bExternalTitle )
532 return impl_getTitleHelper_throw()->getTitle ();
534 OUStringBuffer sTitle;
538 sTitle.append( xTitle->getTitle() +
" : ");
540 sTitle.append( getPrivateTitle() );
541 return sTitle.makeStringAndClear();
546 return m_pImpl->m_nDocStartNumber;
551 ::osl::MutexGuard aGuard(
getMutex() );
552 if ( !
m_pImpl->documentHasScriptSupport() )
560 ::osl::MutexGuard aGuard(
getMutex() );
561 m_pImpl->m_aModifyListeners.addInterface( i_Listener );
566 ::osl::MutexGuard aGuard(
getMutex() );
567 m_pImpl->m_aModifyListeners.removeInterface( i_Listener );
572 ::osl::MutexGuard aGuard(
getMutex() );
578 ::osl::ClearableMutexGuard aGuard(
getMutex() );
580 if (
m_pImpl->m_bModified ==
bool(i_bModified) )
583 m_pImpl->m_bModified = i_bModified;
586 EventObject
aEvent( *
this );
588 m_pImpl->m_aModifyListeners.notifyEach( &XModifyListener::modified,
aEvent );
#define ID_BROWSER_SAVEDOC
#define ID_BROWSER_SAVEASDOC
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
css::uno::Type const & get()
css::uno::Reference< css::sdbc::XDatabaseMetaData > getMetaData() const
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &_rType) override
void connectionLostMessage() const
shows an info box with the string conntection lost.
sal_Int32 getCurrentStartNumber() const
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual sal_Bool SAL_CALL attachModel(const css::uno::Reference< css::frame::XModel > &xModel) override
css::uno::Reference< css::util::XNumberFormatter > const & getNumberFormatter() const
returns the number formatter
virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override
void appendError(const OUString &_rErrorMessage)
appends an error in the current environment.
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void losingConnection()
called when our connection is being disposed
DBSubComponentController(const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
const css::uno::Reference< css::sdbc::XConnection > & getConnection() const
gives access to the currently used connection
virtual void reconnect(bool _bUI)
virtual void SAL_CALL setModified(sal_Bool bModified) override
const ::dbtools::SQLExceptionInfo & getError() const
returns the current error
virtual void SAL_CALL disposing() override
virtual ~DBSubComponentController() override
virtual sal_Bool SAL_CALL isModified() override
OUString getDataSourceName() const
void displayError()
displays the current error, or does nothing if there is no current error
::std::unique_ptr< DBSubComponentController_Impl > m_pImpl
virtual css::uno::Reference< css::frame::XModel > getPrivateModel() const override
virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
void setEditable(bool _bEditable)
css::uno::Reference< css::frame::XModel > getDatabaseDocument() const
void clearError()
clears the error state.
virtual void impl_onModifyChanged()
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void impl_initialize() override
bool impl_isModified() const
virtual OUString SAL_CALL getTitle() override
void initializeConnection(const css::uno::Reference< css::sdbc::XConnection > &_rxForeignConn)
forces usage of a connection which we do not own
const css::uno::Reference< css::beans::XPropertySet > & getDataSource() const
bool haveDataSource() const
virtual css::uno::Reference< css::document::XEmbeddedScripts > SAL_CALL getScriptContainer() override
const ::dbtools::DatabaseMetaData & getSdbMetaData() const
provides access to the SDB-level database meta data of the current connection
virtual void impl_initialize()
weld::Window * GetFrameWeld() const
Reference< XPropertySet > m_xDataSourceProps
Reference< XDataSource > m_xDataSource
Reference< XOfficeDatabaseDocument > m_xDocument
#define DBG_ASSERT(sCon, aError)
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN_IF(condition, area, stream)
css::uno::Reference< css::uno::XInterface > getDataSource(const css::uno::Reference< css::uno::XInterface > &_rxDependentObject)
::cppu::ImplInheritanceHelper< OGenericUnoController, css::document::XScriptInvocationContext, css::util::XModifiable > DBSubComponentController_Base
::osl::Mutex & getMutex()
enumrange< T >::Iterator begin(enumrange< T >)
SwView * getView(const uno::Reference< frame::XModel > &xModel)
constexpr OUStringLiteral PROPERTY_ACTIVE_CONNECTION(u"ActiveConnection")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
::comphelper::OInterfaceContainerHelper3< css::util::XModifyListener > m_aModifyListeners
::std::optional< bool > m_aDocScriptSupport
DBSubComponentController_Impl(osl::Mutex &i_rMutex)
bool documentHasScriptSupport() const
sal_Int32 m_nDocStartNumber
SharedConnection m_xConnection
OUString m_sDataSourceName
Reference< XNumberFormatter > m_xFormatter
::dbtools::DatabaseMetaData m_aSdbMetaData
void setDocumentScriptSupport(const bool _bSupport)
::dbtools::SQLExceptionInfo m_aCurrentError
DataSourceHolder m_aDataSource