22#include <com/sun/star/lang/XMultiServiceFactory.hpp>
23#include <com/sun/star/sdb/DatabaseContext.hpp>
24#include <com/sun/star/sdb/CommandType.hpp>
36#include <bitmaps.hlst>
46 "ExchangeDatabasesDialog")
47 , m_pSh(rVw.GetWrtShellPtr())
48 , m_xUsedDBTLB(m_xBuilder->weld_tree_view(
"inuselb"))
49 , m_xAvailDBTLB(new
SwDBTreeList(m_xBuilder->weld_tree_view(
"availablelb")))
50 , m_xAddDBPB(m_xBuilder->weld_button(
"browse"))
51 , m_xDocDBNameFT(m_xBuilder->weld_label(
"dbnameft"))
52 , m_xDefineBT(m_xBuilder->weld_button(
"ok"))
54 int nWidth =
m_xUsedDBTLB->get_approximate_digit_width() * 25;
66 m_xUsedDBTLB->set_selection_mode(SelectionMode::Multiple);
79 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
80 Reference<XDatabaseContext> xDBContext = DatabaseContext::create(xContext);
85 Sequence< OUString > aDBNames = xDBContext->getElementNames();
86 auto aAllDBNames = comphelper::sequenceToContainer<std::vector<OUString>>(aDBNames);
88 std::vector<OUString> aDBNameList;
91 size_t nCount = aDBNameList.size();
93 std::unique_ptr<weld::TreeIter> xFirst;
95 for(
size_t k = 0; k <
nCount; k++)
99 xFirst = std::move(xLast);
116 sal_Int32 nCommandType = sUserData.toInt32();
118 const OUString & rToInsert ( nCommandType ? RID_BMP_DBQUERY : RID_BMP_DBTABLE );
120 std::unique_ptr<weld::TreeIter> xIter(
m_xUsedDBTLB->make_iterator());
129 std::unique_ptr<weld::TreeIter> xChild(
m_xUsedDBTLB->make_iterator(xIter.get()));
139 m_xUsedDBTLB->insert(xIter.get(), -1, &sTableName, &sUserData,
nullptr,
nullptr,
147 m_xUsedDBTLB->insert(
nullptr, -1, &sDBName,
nullptr,
nullptr,
nullptr,
150 m_xUsedDBTLB->insert(xIter.get(), -1, &sTableName, &sUserData,
nullptr,
nullptr,
163 short nRet = SfxDialogController::run();
171 std::vector<OUString> aDBNames;
176 std::unique_ptr<weld::TreeIter> xIter(m_xUsedDBTLB->make_iterator(&rEntry));
177 m_xUsedDBTLB->iter_parent(*xIter);
178 OUString sTmp(m_xUsedDBTLB->get_text(*xIter) +
179 OUStringChar(DB_DELIM) + m_xUsedDBTLB->get_text(rEntry) + OUStringChar(DB_DELIM) +
180 m_xUsedDBTLB->get_id(rEntry));
181 aDBNames.push_back(sTmp);
188 OUString sColumnName;
190 const OUString DBName(
m_xAvailDBTLB->GetDBName(sTableName, sColumnName, &bIsTable));
191 const OUString sTemp = DBName
195 + OUString::number(bIsTable
197 : CommandType::QUERY);
205 OUString sColumnName;
208 aData.sDataSource = m_xAvailDBTLB->GetDBName(sTableName, sColumnName, &bIsTable);
209 aData.sCommand = sTableName;
210 aData.nCommandType = bIsTable ? 0 : 1;
211 m_pSh->ChgDBData(
aData);
212 ShowDBName(m_pSh->GetDBData());
223 bool bEnable =
false;
224 std::unique_ptr<weld::TreeIter> xIter(
m_xAvailDBTLB->make_iterator());
251 if (!sNewDB.isEmpty())
253 m_xAvailDBTLB->AddDataSource(sNewDB);
Reference< XExecutableDialog > m_xDialog
IMPL_LINK_NOARG(SwChangeDBDlg, ButtonHdl, weld::Button &, void)
SwChangeDBDlg(SwView const &rVw)
std::unique_ptr< weld::TreeIter > Insert(std::u16string_view rDBName)
std::unique_ptr< weld::TreeView > m_xUsedDBTLB
std::unique_ptr< weld::Label > m_xDocDBNameFT
virtual ~SwChangeDBDlg() override
virtual short run() override
std::unique_ptr< SwDBTreeList > m_xAvailDBTLB
std::unique_ptr< weld::Button > m_xDefineBT
void ShowDBName(const SwDBData &rDBData)
std::unique_ptr< weld::Button > m_xAddDBPB
static OUString LoadAndRegisterDataSource(weld::Window *pParent, SwDocShell *pDocShell=nullptr)
Loads a data source from file and registers it.
void StartAllAction()
For all views of this document.
void ChangeDBFields(const std::vector< OUString > &rOldNames, const OUString &rNewName)
SwDBData const & GetDBData() const
Database information.
void GetAllUsedDB(std::vector< OUString > &rDBNameList, std::vector< OUString > const *pAllDBNames)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
#define LINK(Instance, Class, Member)
constexpr OUStringLiteral aData
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OUString SwResId(TranslateId aId)