20#include <com/sun/star/container/XNameAccess.hpp>
21#include <com/sun/star/sdbc/XConnection.hpp>
22#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
23#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
24#include <com/sun/star/sdb/DatabaseContext.hpp>
25#include <com/sun/star/sdb/XQueriesSupplier.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
29#include <com/sun/star/container/XContainerListener.hpp>
32#include <osl/diagnose.h>
40#include <bitmaps.hlst>
64 virtual void SAL_CALL
elementInserted(
const ContainerEvent& Event )
override;
65 virtual void SAL_CALL
elementRemoved(
const ContainerEvent& Event )
override;
66 virtual void SAL_CALL
elementReplaced(
const ContainerEvent& Event )
override;
67 virtual void SAL_CALL
disposing(
const EventObject& Source )
override;
73 Reference<XConnection>
GetConnection(
const OUString& rSourceName);
113 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
122 Reference<XConnection> xRet;
131 : m_bInitialized(false)
132 , m_bShowColumns(false)
134 , m_xTreeView(
std::move(xTreeView))
135 , m_xScratchIter(m_xTreeView->make_iterator())
149 Sequence< OUString > aDBNames =
m_pImpl->GetContext()->getElementNames();
153 auto [
begin,
end] = asNonConstRange(aDBNames);
156 [&sort](OUString
const &
x, OUString
const &
y)
157 {
return sort.compare(
x,
y) < 0; });
159 OUString aImg(RID_BMP_DB);
160 for (
const OUString& rDBName : std::as_const(aDBNames))
185 if (!m_xTreeView->iter_has_child(rParent))
187 if (m_xTreeView->get_iter_depth(rParent))
191 std::unique_ptr<weld::TreeIter> xGrandParent(m_xTreeView->make_iterator(&rParent));
192 m_xTreeView->iter_parent(*xGrandParent);
193 OUString sSourceName = m_xTreeView->get_text(*xGrandParent);
194 OUString sTableName = m_xTreeView->get_text(rParent);
196 if(!
m_pImpl->GetContext()->hasByName(sSourceName))
198 Reference<XConnection> xConnection =
m_pImpl->GetConnection(sSourceName);
199 bool bTable = m_xTreeView->get_id(rParent).isEmpty();
200 Reference<XColumnsSupplier> xColsSupplier;
203 Reference<XTablesSupplier> xTSupplier(xConnection, UNO_QUERY);
206 Reference<XNameAccess> xTables = xTSupplier->getTables();
207 OSL_ENSURE(xTables->hasByName(sTableName),
"table not available anymore?");
210 Any aTable = xTables->getByName(sTableName);
211 Reference<XPropertySet> xPropSet;
213 xColsSupplier.set(xPropSet, UNO_QUERY);
222 Reference<XQueriesSupplier> xQSupplier(xConnection, UNO_QUERY);
225 Reference<XNameAccess> xQueries = xQSupplier->getQueries();
226 OSL_ENSURE(xQueries->hasByName(sTableName),
"table not available anymore?");
229 Any aQuery = xQueries->getByName(sTableName);
230 Reference<XPropertySet> xPropSet;
232 xColsSupplier.set(xPropSet, UNO_QUERY);
240 if(xColsSupplier.is())
242 Reference <XNameAccess> xCols = xColsSupplier->getColumns();
243 const Sequence< OUString>
aColNames = xCols->getElementNames();
244 for (
const OUString& rColName :
aColNames)
246 m_xTreeView->append(&rParent, rColName);
258 OUString sSourceName = m_xTreeView->get_text(rParent);
259 if (!
m_pImpl->GetContext()->hasByName(sSourceName))
261 Reference<XConnection> xConnection =
m_pImpl->GetConnection(sSourceName);
262 if (xConnection.is())
264 Reference<XTablesSupplier> xTSupplier(xConnection, UNO_QUERY);
267 Reference<XNameAccess> xTables = xTSupplier->getTables();
268 const Sequence< OUString> aTableNames = xTables->getElementNames();
269 OUString aImg(RID_BMP_DBTABLE);
270 for (
const OUString& rTableName : aTableNames)
272 m_xTreeView->insert(&rParent, -1, &rTableName,
nullptr,
273 nullptr,
nullptr, m_bShowColumns, m_xScratchIter.get());
274 m_xTreeView->set_image(*m_xScratchIter, aImg);
278 Reference<XQueriesSupplier> xQSupplier(xConnection, UNO_QUERY);
281 Reference<XNameAccess> xQueries = xQSupplier->getQueries();
282 const Sequence< OUString> aQueryNames = xQueries->getElementNames();
283 OUString aImg(RID_BMP_DBQUERY);
284 for (
const OUString& rQueryName : aQueryNames)
287 OUString
sId(OUString::number(1));
288 m_xTreeView->insert(&rParent, -1, &rQueryName, &
sId,
289 nullptr,
nullptr, m_bShowColumns, m_xScratchIter.get());
290 m_xTreeView->set_image(*m_xScratchIter, aImg);
306 std::unique_ptr<weld::TreeIter> xIter(
m_xTreeView->make_iterator());
317 *pbIsTable =
m_xTreeView->get_id(*xIter).isEmpty();
327void SwDBTreeList::Select(std::u16string_view rDBName, std::u16string_view rTableName, std::u16string_view rColumnName)
329 std::unique_ptr<weld::TreeIter> xParent(
m_xTreeView->make_iterator());
337 if (rTableName.empty() && rColumnName.empty())
346 m_xTreeView->set_children_on_demand(*xParent,
false);
347 RequestingChildrenHdl(*xParent);
350 std::unique_ptr<weld::TreeIter> xChild(
m_xTreeView->make_iterator(xParent.get()));
363 bool bNoChild =
false;
368 m_xTreeView->set_children_on_demand(*xParent,
false);
369 RequestingChildrenHdl(*xParent);
398 }
while (
m_xTreeView->iter_next_sibling(*xParent));
424 OUString sColumnName;
425 const OUString sDBName(
GetDBName(sTableName, sColumnName));
429 std::unique_ptr<weld::TreeIter> xIter(
m_xTreeView->make_iterator());
430 std::unique_ptr<weld::TreeIter> xChild(
m_xTreeView->make_iterator());
448 if (!sDBName.isEmpty())
450 Select(sDBName, sTableName, sColumnName);
static const AllSettings & GetSettings()
css::uno::Reference< css::sdbc::XConnection > const & RegisterConnection(OUString const &rSource)
create and store or find an already stored connection to a data source for use in SwFieldMgr and SwDB...
static css::uno::Reference< css::sdbc::XDataSource > getDataSourceAsParent(const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const OUString &_sDataSourceName)
try to get the data source from the given connection through the XChild interface.
SwWrtShell * GetWrtShell()
void SetWrtShell(SwWrtShell &rSh)
virtual void SAL_CALL elementRemoved(const ContainerEvent &Event) override
virtual ~SwDBTreeList_Impl() override
Reference< XConnection > GetConnection(const OUString &rSourceName)
virtual void SAL_CALL elementReplaced(const ContainerEvent &Event) override
Reference< XDatabaseContext > m_xDatabaseContext
virtual void SAL_CALL elementInserted(const ContainerEvent &Event) override
const Reference< XDatabaseContext > & GetContext() const
virtual void SAL_CALL disposing(const EventObject &Source) override
void AddDataSource(const OUString &rSource)
SwDBTreeList(std::unique_ptr< weld::TreeView > xTreeView)
SAL_DLLPRIVATE void InitTreeList()
void Select(std::u16string_view rDBName, std::u16string_view rTableName, std::u16string_view rColumnName)
void ShowColumns(bool bShowCol)
void SetWrtShell(SwWrtShell &rSh)
rtl::Reference< SwDBTreeList_Impl > m_pImpl
std::unique_ptr< weld::TreeIter > m_xScratchIter
OUString GetDBName(OUString &rTableName, OUString &rColumnName, sal_Bool *pbIsTable=nullptr)
std::unique_ptr< weld::TreeView > m_xTreeView
SwDBManager * GetDBManager() const
For evaluation of DB fields (new DB-manager).
Used by the UI to modify the document model.
virtual bool iter_parent(TreeIter &rIter) const=0
virtual int get_iter_depth(const TreeIter &rIter) const=0
IMPL_LINK(SwDBTreeList, RequestingChildrenHdl, const weld::TreeIter &, rParent, bool)
#define LINK(Instance, Class, Member)
const LanguageTag & getLocale()
Reference< XComponentContext > getProcessComponentContext()
enumrange< T >::Iterator begin(enumrange< T >)
const Color aColNames[SC_RANGECOLORS]