22#include <osl/diagnose.h>
24#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
25#include <core_resource.hxx>
26#include <com/sun/star/sdb/application/CopyTableOperation.hpp>
35namespace CopyTableOperation = ::com::sun::star::sdb::application::CopyTableOperation;
37OUString OWizColumnSelect::GetTitle()
const {
return DBA_RES(STR_WIZ_COLUMN_SELECT_TITLE); }
52 :
OWizardPage(pPage, pWizard,
"dbaccess/ui/applycolpage.ui",
"ApplyColPage")
53 , m_xOrgColumnNames(m_xBuilder->weld_tree_view(
"from"))
54 , m_xColumn_RH(m_xBuilder->weld_button(
"colrh"))
55 , m_xColumns_RH(m_xBuilder->weld_button(
"colsrh"))
56 , m_xColumn_LH(m_xBuilder->weld_button(
"collh"))
57 , m_xColumns_LH(m_xBuilder->weld_button(
"colslh"))
58 , m_xNewColumnNames(m_xBuilder->weld_tree_view(
"to"))
86 m_pParent->m_mNameMapping.clear();
91 for (
auto const& column : rSrcColumns)
100 m_bFirstTime =
false;
106 if(m_pParent->getDestColumns().empty())
120 for (
auto const& column : rDestColumns)
122 if (rSrcColumns.find(column->first) != rSrcColumns.end())
132 m_pParent->EnableNextButton(
m_xNewColumnNames->n_children() && m_pParent->getOperation() != CopyTableOperation::AppendData);
139 m_pParent->clearDestColumns();
144 OSL_ENSURE(pField,
"The field information can not be null!");
145 m_pParent->insertColumn(
i,pField);
153 return !m_pParent->getDestColumns().empty();
164 if (&rButton == m_xColumn_RH.get())
166 pLeft = m_xOrgColumnNames.get();
167 pRight = m_xNewColumnNames.get();
169 else if (&rButton == m_xColumn_LH.get())
171 pLeft = m_xNewColumnNames.get();
172 pRight = m_xOrgColumnNames.get();
174 else if (&rButton == m_xColumns_RH.get())
176 pLeft = m_xOrgColumnNames.get();
177 pRight = m_xNewColumnNames.get();
180 else if (&rButton == m_xColumns_LH.get())
182 pLeft = m_xNewColumnNames.get();
183 pRight = m_xOrgColumnNames.get();
187 if (!pLeft || !pRight)
191 OUString sExtraChars = xMetaData->getExtraNameCharacters();
192 sal_Int32 nMaxNameLen = m_pParent->getMaxColumnNameLength();
195 std::vector< OUString> aRightColumns;
196 fillColumns(pRight,aRightColumns);
201 std::sort(aRows.begin(), aRows.end());
203 for (
auto it = aRows.begin(); it != aRows.end(); ++it)
204 moveColumn(pRight,pLeft,aRightColumns,pLeft->
get_text(*it),sExtraChars,nMaxNameLen,aCase);
206 for (
auto it = aRows.rbegin(); it != aRows.rend(); ++it)
211 const sal_Int32 nEntries = pLeft->
n_children();
212 for(sal_Int32
i=0;
i < nEntries; ++
i)
213 moveColumn(pRight,pLeft,aRightColumns,pLeft->
get_text(
i),sExtraChars,nMaxNameLen,aCase);
220 if (m_xOrgColumnNames->n_children())
221 m_xOrgColumnNames->select(0);
227 if (&rListBox == m_xOrgColumnNames.get())
229 pLeft = m_xOrgColumnNames.get();
230 pRight = m_xNewColumnNames.get();
234 pRight = m_xOrgColumnNames.get();
235 pLeft = m_xNewColumnNames.get();
240 OUString sExtraChars = xMetaData->getExtraNameCharacters();
241 sal_Int32 nMaxNameLen = m_pParent->getMaxColumnNameLength();
244 std::vector< OUString> aRightColumns;
245 fillColumns(pRight,aRightColumns);
248 std::sort(aRows.begin(), aRows.end());
250 for (
auto it = aRows.begin(); it != aRows.end(); ++it)
251 moveColumn(pRight,pLeft,aRightColumns,pLeft->
get_text(*it),sExtraChars,nMaxNameLen,aCase);
253 for (
auto it = aRows.rbegin(); it != aRows.rend(); ++it)
269 _rRightColumns.reserve(
nCount);
271 _rRightColumns.push_back(pRight->
get_text(
i));
276 std::vector< OUString>& _rRightColumns,
277 const OUString& _sColumnName,
278 std::u16string_view _sExtraChars,
279 sal_Int32 _nMaxNameLen,
280 const ::comphelper::UStringMixEqual& _aCase)
287 pNewField->
SetName(sConvertedName);
288 bool bNotConvert =
true;
290 if ( !m_pParent->supportsPrimaryKey() )
294 _rRightColumns.push_back(sConvertedName);
297 m_pParent->showColumnTypeNotSupported(sConvertedName);
302 std::vector< OUString>& _rRightColumns,
303 const OUString& _sColumnName,
304 std::u16string_view _sExtraChars,
305 sal_Int32 _nMaxNameLen,
306 const ::comphelper::UStringMixEqual& _aCase)
312 createNewColumn(_pRight,pSrcField,_rRightColumns,_sColumnName,_sExtraChars,_nMaxNameLen,_aCase);
317 OCopyTableWizard::TNameMapping::const_iterator aIter = std::find_if(m_pParent->m_mNameMapping.begin(),m_pParent->m_mNameMapping.end(),
318 [&_aCase, &_sColumnName] (
const OCopyTableWizard::TNameMapping::value_type& nameMap) {
319 return _aCase(nameMap.second, _sColumnName);
322 OSL_ENSURE(aIter != m_pParent->m_mNameMapping.end(),
"Column must be defined");
323 if ( aIter == m_pParent->m_mNameMapping.end() )
326 ODatabaseExport::TColumns::const_iterator aSrcIter = rSrcColumns.find((*aIter).first);
327 if ( aSrcIter != rSrcColumns.end() )
331 ODatabaseExport::TColumnVector::const_iterator aPos = std::find(rSrcVector.begin(), rSrcVector.end(), aSrcIter);
332 OSL_ENSURE( aPos != rSrcVector.end(),
"Invalid position for the iterator here!");
333 ODatabaseExport::TColumnVector::size_type
nPos = (aPos - rSrcVector.begin()) -
adjustColumnPosition(_pLeft, _sColumnName, (aPos - rSrcVector.begin()), _aCase);
336 const OUString& rStr = (*aIter).first;
337 _pRight->
insert(
nullptr,
nPos, &rStr, &
sId,
nullptr,
nullptr,
false,
nullptr);
338 _rRightColumns.push_back(rStr);
339 m_pParent->removeColumnNameFromNameMap(_sColumnName);
349 std::u16string_view _sColumnName,
350 ODatabaseExport::TColumnVector::size_type nCurrentPos,
351 const ::comphelper::UStringMixEqual& _aCase)
353 sal_Int32 nAdjustedPos = 0;
361 OUString sColumnString;
365 if(_sColumnName != sColumnString)
368 OCopyTableWizard::TNameMapping::const_iterator aIter = std::find_if(m_pParent->m_mNameMapping.begin(),m_pParent->m_mNameMapping.end(),
369 [&_aCase, &sColumnString] (
const OCopyTableWizard::TNameMapping::value_type& nameMap) {
370 return _aCase(nameMap.second, sColumnString);
373 OSL_ENSURE(aIter != m_pParent->m_mNameMapping.end(),
"Column must be defined");
375 ODatabaseExport::TColumns::const_iterator aSrcIter = rSrcColumns.find((*aIter).first);
376 if ( aSrcIter != rSrcColumns.end() )
380 ODatabaseExport::TColumnVector::const_iterator aPos = std::find(rSrcVector.begin(), rSrcVector.end(), aSrcIter);
381 ODatabaseExport::TColumnVector::size_type
nPos = aPos - rSrcVector.begin();
382 if(
nPos < nCurrentPos)
397 m_pParent->m_mNameMapping.clear();
399 m_pParent->GetOKButton().set_sensitive(bEntries);
400 m_pParent->EnableNextButton(bEntries && m_pParent->getOperation() != CopyTableOperation::AppendData);
std::map< OUString, OFieldDescription *, ::comphelper::UStringMixLess > TColumns
std::vector< TColumns::const_iterator > TColumnVector
void SetPrimaryKey(bool _bPKey)
void SetType(const TOTypeInfoSP &_pType)
void SetName(const OUString &_rName)
TOTypeInfoSP getSpecialTypeInfo() const
std::unique_ptr< weld::TreeView > m_xOrgColumnNames
virtual void Activate() override
std::unique_ptr< weld::Button > m_xColumn_RH
std::unique_ptr< weld::Button > m_xColumns_RH
void createNewColumn(weld::TreeView *_pListbox, OFieldDescription const *_pSrcField, std::vector< OUString > &_rRightColumns, const OUString &_sColumnName, std::u16string_view _sExtraChars, sal_Int32 _nMaxNameLen, const ::comphelper::UStringMixEqual &_aCase)
virtual void Reset() override
virtual ~OWizColumnSelect() override
void moveColumn(weld::TreeView *_pRight, weld::TreeView const *_pLeft, std::vector< OUString > &_rRightColumns, const OUString &_sColumnName, std::u16string_view _sExtraChars, sal_Int32 _nMaxNameLen, const ::comphelper::UStringMixEqual &_aCase)
virtual bool LeavePage() override
sal_Int32 adjustColumnPosition(weld::TreeView const *_pLeft, std::u16string_view _sColumnName, ODatabaseExport::TColumnVector::size_type nCurrentPos, const ::comphelper::UStringMixEqual &_aCase)
std::unique_ptr< weld::Button > m_xColumns_LH
static void clearListBox(weld::TreeView &_rListBox)
std::unique_ptr< weld::Button > m_xColumn_LH
std::unique_ptr< weld::TreeView > m_xNewColumnNames
static void fillColumns(weld::TreeView const *pRight, std::vector< OUString > &_rRightColumns)
virtual ~OWizardPage() override
OWizardPage(weld::Container *pPage, weld::DialogController *pController, const OUString &rUIXMLDescription, const OUString &rID)
virtual int find_text(const OUString &rText) const=0
virtual OUString get_text(int row, int col=-1) const=0
virtual int n_children() const=0
virtual void insert(const TreeIter *pParent, int pos, const OUString *pStr, const OUString *pId, const OUString *pIconName, VirtualDevice *pImageSurface, bool bChildrenOnDemand, TreeIter *pRet)=0
void append(TreeIter *pRet=nullptr)
virtual void remove(int pos)=0
virtual std::vector< int > get_selected_rows() const=0
virtual OUString get_id(int pos) const=0
#define LINK(Instance, Class, Member)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
OUString toId(const void *pValue)