/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
OWizColumnSelect::~OWizColumnSelect()
{ while (m_xNewColumnNames->n_children())
{ delete weld::fromId<OFieldDescription*>(m_xNewColumnNames->get_id(0));
m_xNewColumnNames->remove(0);
}
}
void OWizColumnSelect::Reset()
{ // restore original state
clearListBox(*m_xOrgColumnNames);
clearListBox(*m_xNewColumnNames);
m_pParent->m_mNameMapping.clear();
// insert the source columns in the left listbox const ODatabaseExport::TColumnVector& rSrcColumns = m_pParent->getSrcVector();
if (m_xOrgColumnNames->n_children())
m_xOrgColumnNames->select(0);
m_bFirstTime = false;
}
void OWizColumnSelect::Activate( )
{ // if there are no dest columns reset the left side with the original columns if(m_pParent->getDestColumns().empty())
Reset();
// tdf#113923, the added columns must exist in the table // in the case where: // 1: we enabled the creation of a primary key // 2: we come back here from the "Back" button of the next page, // we want to avoid to list the new column generated in the next page const ODatabaseExport::TColumns& rSrcColumns = m_pParent->getSourceColumns();
for (autoconst& column : rDestColumns)
{ if (rSrcColumns.find(column->first) != rSrcColumns.end())
{
OUString sId(weld::toId(new OFieldDescription(*(column->second))));
m_xNewColumnNames->append(sId, column->first); int nRemove = m_xOrgColumnNames->find_text(column->first); if (nRemove != -1)
m_xOrgColumnNames->remove(nRemove);
}
}
m_pParent->GetOKButton().set_sensitive(m_xNewColumnNames->n_children() != 0);
m_pParent->EnableNextButton(m_xNewColumnNames->n_children() && m_pParent->getOperation() != CopyTableOperation::AppendData);
m_xColumns_RH->grab_focus();
}
bool OWizColumnSelect::LeavePage()
{
m_pParent->clearDestColumns();
for(sal_Int32 i=0 ; i< m_xNewColumnNames->n_children();++i)
{
OFieldDescription* pField = weld::fromId<OFieldDescription*>(m_xNewColumnNames->get_id(i));
OSL_ENSURE(pField,"The field information can not be null!");
m_pParent->insertColumn(i,pField);
}
// If database is able to process PrimaryKeys, set PrimaryKey
Reference< XDatabaseMetaData > xMetaData( m_pParent->m_xDestConnection->getMetaData() );
OUString sExtraChars = xMetaData->getExtraNameCharacters();
sal_Int32 nMaxNameLen = m_pParent->getMaxColumnNameLength();
if ( !bNotConvert )
m_pParent->showColumnTypeNotSupported(sConvertedName);
}
void OWizColumnSelect::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)
{ if(_pRight == m_xNewColumnNames.get())
{ // we copy the column into the new format for the dest
OFieldDescription* pSrcField = weld::fromId<OFieldDescription*>(_pLeft->get_id(_pLeft->find_text(_sColumnName)));
createNewColumn(_pRight,pSrcField,_rRightColumns,_sColumnName,_sExtraChars,_nMaxNameLen,_aCase);
} else
{ // find the new column in the dest name mapping to obtain the old column
OCopyTableWizard::TNameMapping::const_iterator aIter = std::find_if(m_pParent->m_mNameMapping.begin(),m_pParent->m_mNameMapping.end(),
[&_aCase, &_sColumnName] (const OCopyTableWizard::TNameMapping::value_type& nameMap) { return _aCase(nameMap.second, _sColumnName);
});
OSL_ENSURE(aIter != m_pParent->m_mNameMapping.end(),"Column must be defined"); if ( aIter == m_pParent->m_mNameMapping.end() ) return; // do nothing const ODatabaseExport::TColumns& rSrcColumns = m_pParent->getSourceColumns();
ODatabaseExport::TColumns::const_iterator aSrcIter = rSrcColumns.find((*aIter).first); if ( aSrcIter != rSrcColumns.end() )
{ // we need also the old position of this column to insert it back on that position again const ODatabaseExport::TColumnVector& rSrcVector = m_pParent->getSrcVector();
ODatabaseExport::TColumnVector::const_iterator aPos = std::find(rSrcVector.begin(), rSrcVector.end(), aSrcIter);
OSL_ENSURE( aPos != rSrcVector.end(),"Invalid position for the iterator here!");
ODatabaseExport::TColumnVector::size_type nPos = (aPos - rSrcVector.begin()) - adjustColumnPosition(_pLeft, _sColumnName, (aPos - rSrcVector.begin()), _aCase);
// Simply returning fields back to their original position is // not enough. We need to take into account what fields have // been removed earlier and adjust accordingly. Based on the // algorithm employed in moveColumn().
sal_Int32 OWizColumnSelect::adjustColumnPosition(weld::TreeView const * _pLeft,
std::u16string_view _sColumnName,
ODatabaseExport::TColumnVector::size_type nCurrentPos, const ::comphelper::UStringMixEqual& _aCase)
{
sal_Int32 nAdjustedPos = 0;
// if returning all entries to their original position, // then there is no need to adjust the positions. if (m_xColumns_LH->has_focus()) return nAdjustedPos;
const sal_Int32 nCount = _pLeft->n_children();
OUString sColumnString; for(sal_Int32 i=0; i < nCount; ++i)
{
sColumnString = _pLeft->get_text(i); if(_sColumnName != sColumnString)
{ // find the new column in the dest name mapping to obtain the old column
OCopyTableWizard::TNameMapping::const_iterator aIter = std::find_if(m_pParent->m_mNameMapping.begin(),m_pParent->m_mNameMapping.end(),
[&_aCase, &sColumnString] (const OCopyTableWizard::TNameMapping::value_type& nameMap) { return _aCase(nameMap.second, sColumnString);
});
OSL_ENSURE(aIter != m_pParent->m_mNameMapping.end(),"Column must be defined"); const ODatabaseExport::TColumns& rSrcColumns = m_pParent->getSourceColumns();
ODatabaseExport::TColumns::const_iterator aSrcIter = rSrcColumns.find((*aIter).first); if ( aSrcIter != rSrcColumns.end() )
{ // we need also the old position of this column to insert it back on that position again const ODatabaseExport::TColumnVector& rSrcVector = m_pParent->getSrcVector();
ODatabaseExport::TColumnVector::const_iterator aPos = std::find(rSrcVector.begin(), rSrcVector.end(), aSrcIter);
ODatabaseExport::TColumnVector::size_type nPos = aPos - rSrcVector.begin(); if( nPos < nCurrentPos)
{
nAdjustedPos++;
}
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.