1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifndef DBAUI_WIZ_COLUMNSELECT_HXX 32*cdf0e10cSrcweir #include "WColumnSelect.hxx" 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #ifndef _DBU_MISC_HRC_ 35*cdf0e10cSrcweir #include "dbu_misc.hrc" 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX 38*cdf0e10cSrcweir #include <tools/debug.hxx> 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #ifndef DBAUI_WIZARD_PAGES_HRC 41*cdf0e10cSrcweir #include "WizardPages.hrc" 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #ifndef DBAUI_WIZ_COPYTABLEDIALOG_HXX 44*cdf0e10cSrcweir #include "WCopyTable.hxx" 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_ 47*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> 48*cdf0e10cSrcweir #endif 49*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_ 50*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 51*cdf0e10cSrcweir #endif 52*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_ 53*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp> 54*cdf0e10cSrcweir #endif 55*cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_ 56*cdf0e10cSrcweir #include "moduledbu.hxx" 57*cdf0e10cSrcweir #endif 58*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ 59*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 60*cdf0e10cSrcweir #endif 61*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ 62*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp> 63*cdf0e10cSrcweir #endif 64*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_APPLICATION_COPYTABLEOPERATION_HPP_ 65*cdf0e10cSrcweir #include <com/sun/star/sdb/application/CopyTableOperation.hpp> 66*cdf0e10cSrcweir #endif 67*cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 68*cdf0e10cSrcweir #include "dbustrings.hrc" 69*cdf0e10cSrcweir #endif 70*cdf0e10cSrcweir #include <functional> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 73*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 74*cdf0e10cSrcweir using namespace ::com::sun::star::container; 75*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 76*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 77*cdf0e10cSrcweir using namespace dbaui; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir namespace CopyTableOperation = ::com::sun::star::sdb::application::CopyTableOperation; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // ----------------------------------------------------------------------- 82*cdf0e10cSrcweir String OWizColumnSelect::GetTitle() const { return String(ModuleRes(STR_WIZ_COLUMN_SELECT_TITEL)); } 83*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 84*cdf0e10cSrcweir OWizardPage::OWizardPage( Window* pParent, const ResId& rResId ) 85*cdf0e10cSrcweir : TabPage(pParent,rResId) 86*cdf0e10cSrcweir ,m_pParent(static_cast<OCopyTableWizard*>(pParent)) 87*cdf0e10cSrcweir ,m_bFirstTime(sal_True) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir //======================================================================== 91*cdf0e10cSrcweir // OWizColumnSelect 92*cdf0e10cSrcweir DBG_NAME(OWizColumnSelect); 93*cdf0e10cSrcweir //======================================================================== 94*cdf0e10cSrcweir OWizColumnSelect::OWizColumnSelect( Window* pParent) 95*cdf0e10cSrcweir :OWizardPage( pParent, ModuleRes( TAB_WIZ_COLUMN_SELECT )) 96*cdf0e10cSrcweir ,m_flColumns( this, ModuleRes( FL_COLUMN_SELECT ) ) 97*cdf0e10cSrcweir ,m_lbOrgColumnNames( this, ModuleRes( LB_ORG_COLUMN_NAMES ) ) 98*cdf0e10cSrcweir ,m_ibColumn_RH( this, ModuleRes( IB_COLUMN_RH ) ) 99*cdf0e10cSrcweir ,m_ibColumns_RH( this, ModuleRes( IB_COLUMNS_RH ) ) 100*cdf0e10cSrcweir ,m_ibColumn_LH( this, ModuleRes( IB_COLUMN_LH ) ) 101*cdf0e10cSrcweir ,m_ibColumns_LH( this, ModuleRes( IB_COLUMNS_LH ) ) 102*cdf0e10cSrcweir ,m_lbNewColumnNames( this, ModuleRes( LB_NEW_COLUMN_NAMES ) ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir DBG_CTOR(OWizColumnSelect,NULL); 105*cdf0e10cSrcweir m_ibColumn_RH.SetClickHdl(LINK(this,OWizColumnSelect,ButtonClickHdl)); 106*cdf0e10cSrcweir m_ibColumn_LH.SetClickHdl(LINK(this,OWizColumnSelect,ButtonClickHdl)); 107*cdf0e10cSrcweir m_ibColumns_RH.SetClickHdl(LINK(this,OWizColumnSelect,ButtonClickHdl)); 108*cdf0e10cSrcweir m_ibColumns_LH.SetClickHdl(LINK(this,OWizColumnSelect,ButtonClickHdl)); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir m_lbOrgColumnNames.EnableMultiSelection(sal_True); 111*cdf0e10cSrcweir m_lbNewColumnNames.EnableMultiSelection(sal_True); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir m_lbOrgColumnNames.SetDoubleClickHdl(LINK(this,OWizColumnSelect,ListDoubleClickHdl)); 114*cdf0e10cSrcweir m_lbNewColumnNames.SetDoubleClickHdl(LINK(this,OWizColumnSelect,ListDoubleClickHdl)); 115*cdf0e10cSrcweir FreeResource(); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir // ----------------------------------------------------------------------- 118*cdf0e10cSrcweir OWizColumnSelect::~OWizColumnSelect() 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir DBG_DTOR(OWizColumnSelect,NULL); 121*cdf0e10cSrcweir while ( m_lbNewColumnNames.GetEntryCount() ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir void* pData = m_lbNewColumnNames.GetEntryData(0); 124*cdf0e10cSrcweir if ( pData ) 125*cdf0e10cSrcweir delete static_cast<OFieldDescription*>(pData); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir m_lbNewColumnNames.RemoveEntry(0); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir m_lbNewColumnNames.Clear(); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir // ----------------------------------------------------------------------- 133*cdf0e10cSrcweir void OWizColumnSelect::Reset() 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir // urspr"unglichen zustand wiederherstellen 136*cdf0e10cSrcweir DBG_CHKTHIS(OWizColumnSelect,NULL); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir clearListBox(m_lbOrgColumnNames); 139*cdf0e10cSrcweir clearListBox(m_lbNewColumnNames); 140*cdf0e10cSrcweir m_pParent->m_mNameMapping.clear(); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // insert the source columns in the left listbox 143*cdf0e10cSrcweir const ODatabaseExport::TColumnVector* pSrcColumns = m_pParent->getSrcVector(); 144*cdf0e10cSrcweir ODatabaseExport::TColumnVector::const_iterator aIter = pSrcColumns->begin(); 145*cdf0e10cSrcweir ODatabaseExport::TColumnVector::const_iterator aEnd = pSrcColumns->end(); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir for(;aIter != aEnd;++aIter) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir sal_uInt16 nPos = m_lbOrgColumnNames.InsertEntry((*aIter)->first); 150*cdf0e10cSrcweir m_lbOrgColumnNames.SetEntryData(nPos,(*aIter)->second); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // m_pParent->clearDestColumns(); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir if(m_lbOrgColumnNames.GetEntryCount()) 156*cdf0e10cSrcweir m_lbOrgColumnNames.SelectEntryPos(0); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir m_bFirstTime = sal_False; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir // ----------------------------------------------------------------------- 161*cdf0e10cSrcweir void OWizColumnSelect::ActivatePage( ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir DBG_CHKTHIS(OWizColumnSelect,NULL); 164*cdf0e10cSrcweir // if there are no dest columns reset the left side with the origibnal columns 165*cdf0e10cSrcweir if(m_pParent->getDestColumns()->size() == 0) 166*cdf0e10cSrcweir Reset(); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir clearListBox(m_lbNewColumnNames); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir const ODatabaseExport::TColumnVector* pDestColumns = m_pParent->getDestVector(); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir ODatabaseExport::TColumnVector::const_iterator aIter = pDestColumns->begin(); 173*cdf0e10cSrcweir ODatabaseExport::TColumnVector::const_iterator aEnd = pDestColumns->end(); 174*cdf0e10cSrcweir for(;aIter != aEnd;++aIter) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir sal_uInt16 nPos = m_lbNewColumnNames.InsertEntry((*aIter)->first); 177*cdf0e10cSrcweir m_lbNewColumnNames.SetEntryData(nPos,new OFieldDescription(*((*aIter)->second))); 178*cdf0e10cSrcweir m_lbOrgColumnNames.RemoveEntry((*aIter)->first); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir m_pParent->GetOKButton().Enable(m_lbNewColumnNames.GetEntryCount() != 0); 181*cdf0e10cSrcweir m_pParent->EnableButton(OCopyTableWizard::WIZARD_NEXT,m_lbNewColumnNames.GetEntryCount() && m_pParent->getOperation() != CopyTableOperation::AppendData); 182*cdf0e10cSrcweir m_ibColumns_RH.GrabFocus(); 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir // ----------------------------------------------------------------------- 185*cdf0e10cSrcweir sal_Bool OWizColumnSelect::LeavePage() 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir DBG_CHKTHIS(OWizColumnSelect,NULL); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // m_pParent->getColumns()->clear(); 190*cdf0e10cSrcweir m_pParent->clearDestColumns(); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir for(sal_uInt16 i=0 ; i< m_lbNewColumnNames.GetEntryCount();++i) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir OFieldDescription* pField = static_cast<OFieldDescription*>(m_lbNewColumnNames.GetEntryData(i)); 195*cdf0e10cSrcweir OSL_ENSURE(pField,"The field information can not be null!"); 196*cdf0e10cSrcweir m_pParent->insertColumn(i,pField); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir clearListBox(m_lbNewColumnNames); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir if ( m_pParent->GetPressedButton() == OCopyTableWizard::WIZARD_NEXT 203*cdf0e10cSrcweir || m_pParent->GetPressedButton() == OCopyTableWizard::WIZARD_FINISH 204*cdf0e10cSrcweir ) 205*cdf0e10cSrcweir return m_pParent->getDestColumns()->size() != 0; 206*cdf0e10cSrcweir else 207*cdf0e10cSrcweir return sal_True; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir // ----------------------------------------------------------------------- 210*cdf0e10cSrcweir IMPL_LINK( OWizColumnSelect, ButtonClickHdl, Button *, pButton ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir MultiListBox *pLeft = NULL; 213*cdf0e10cSrcweir MultiListBox *pRight = NULL; 214*cdf0e10cSrcweir sal_Bool bAll = sal_False; 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir if(pButton == &m_ibColumn_RH) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir pLeft = &m_lbOrgColumnNames; 219*cdf0e10cSrcweir pRight = &m_lbNewColumnNames; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir else if(pButton == &m_ibColumn_LH) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir pLeft = &m_lbNewColumnNames; 224*cdf0e10cSrcweir pRight = &m_lbOrgColumnNames; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir else if(pButton == &m_ibColumns_RH) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir pLeft = &m_lbOrgColumnNames; 229*cdf0e10cSrcweir pRight = &m_lbNewColumnNames; 230*cdf0e10cSrcweir bAll = sal_True; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir else if(pButton == &m_ibColumns_LH) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir pLeft = &m_lbNewColumnNames; 235*cdf0e10cSrcweir pRight = &m_lbOrgColumnNames; 236*cdf0e10cSrcweir bAll = sal_True; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir // else ???? 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir Reference< XDatabaseMetaData > xMetaData( m_pParent->m_xDestConnection->getMetaData() ); 241*cdf0e10cSrcweir ::rtl::OUString sExtraChars = xMetaData->getExtraNameCharacters(); 242*cdf0e10cSrcweir sal_Int32 nMaxNameLen = m_pParent->getMaxColumnNameLength(); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir ::comphelper::TStringMixEqualFunctor aCase(xMetaData->supportsMixedCaseQuotedIdentifiers()); 245*cdf0e10cSrcweir ::std::vector< ::rtl::OUString> aRightColumns; 246*cdf0e10cSrcweir fillColumns(pRight,aRightColumns); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir String aColumnName; 249*cdf0e10cSrcweir if(!bAll) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir for(sal_uInt16 i=0; i < pLeft->GetSelectEntryCount(); ++i) 252*cdf0e10cSrcweir moveColumn(pRight,pLeft,aRightColumns,pLeft->GetSelectEntry(i),sExtraChars,nMaxNameLen,aCase); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir for(sal_uInt16 j=pLeft->GetSelectEntryCount(); j ; --j) 255*cdf0e10cSrcweir pLeft->RemoveEntry(pLeft->GetSelectEntry(j-1)); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir else 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir sal_uInt16 nEntries = pLeft->GetEntryCount(); 260*cdf0e10cSrcweir for(sal_uInt16 i=0; i < nEntries; ++i) 261*cdf0e10cSrcweir moveColumn(pRight,pLeft,aRightColumns,pLeft->GetEntry(i),sExtraChars,nMaxNameLen,aCase); 262*cdf0e10cSrcweir for(sal_uInt16 j=pLeft->GetEntryCount(); j ; --j) 263*cdf0e10cSrcweir pLeft->RemoveEntry(j-1); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir enableButtons(); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir if(m_lbOrgColumnNames.GetEntryCount()) 269*cdf0e10cSrcweir m_lbOrgColumnNames.SelectEntryPos(0); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir return 0; 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir // ----------------------------------------------------------------------- 274*cdf0e10cSrcweir IMPL_LINK( OWizColumnSelect, ListDoubleClickHdl, MultiListBox *, pListBox ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir MultiListBox *pLeft,*pRight; 277*cdf0e10cSrcweir if(pListBox == &m_lbOrgColumnNames) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir pLeft = &m_lbOrgColumnNames; 280*cdf0e10cSrcweir pRight = &m_lbNewColumnNames; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir else 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir pRight = &m_lbOrgColumnNames; 285*cdf0e10cSrcweir pLeft = &m_lbNewColumnNames; 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 289*cdf0e10cSrcweir // Wenn Datenbank PrimaryKeys verarbeiten kann, PrimaryKey anlegen 290*cdf0e10cSrcweir Reference< XDatabaseMetaData > xMetaData( m_pParent->m_xDestConnection->getMetaData() ); 291*cdf0e10cSrcweir ::rtl::OUString sExtraChars = xMetaData->getExtraNameCharacters(); 292*cdf0e10cSrcweir sal_Int32 nMaxNameLen = m_pParent->getMaxColumnNameLength(); 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir ::comphelper::TStringMixEqualFunctor aCase(xMetaData->supportsMixedCaseQuotedIdentifiers()); 295*cdf0e10cSrcweir ::std::vector< ::rtl::OUString> aRightColumns; 296*cdf0e10cSrcweir fillColumns(pRight,aRightColumns); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir String aColumnName; 299*cdf0e10cSrcweir for(sal_uInt16 i=0; i < pLeft->GetSelectEntryCount(); ++i) 300*cdf0e10cSrcweir moveColumn(pRight,pLeft,aRightColumns,pLeft->GetSelectEntry(i),sExtraChars,nMaxNameLen,aCase); 301*cdf0e10cSrcweir for(sal_uInt16 j=pLeft->GetSelectEntryCount(); j ; --j) 302*cdf0e10cSrcweir pLeft->RemoveEntry(pLeft->GetSelectEntry(j-1)); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir enableButtons(); 305*cdf0e10cSrcweir return 0; 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 308*cdf0e10cSrcweir void OWizColumnSelect::clearListBox(MultiListBox& _rListBox) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir while(_rListBox.GetEntryCount()) 311*cdf0e10cSrcweir _rListBox.RemoveEntry(0); 312*cdf0e10cSrcweir _rListBox.Clear(); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 315*cdf0e10cSrcweir void OWizColumnSelect::fillColumns(ListBox* pRight,::std::vector< ::rtl::OUString> &_rRightColumns) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir sal_uInt16 nCount = pRight->GetEntryCount(); 318*cdf0e10cSrcweir _rRightColumns.reserve(nCount); 319*cdf0e10cSrcweir for(sal_uInt16 i=0; i < nCount;++i) 320*cdf0e10cSrcweir _rRightColumns.push_back(pRight->GetEntry(i)); 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 323*cdf0e10cSrcweir void OWizColumnSelect::createNewColumn( ListBox* _pListbox, 324*cdf0e10cSrcweir OFieldDescription* _pSrcField, 325*cdf0e10cSrcweir ::std::vector< ::rtl::OUString>& _rRightColumns, 326*cdf0e10cSrcweir const ::rtl::OUString& _sColumnName, 327*cdf0e10cSrcweir const ::rtl::OUString& _sExtraChars, 328*cdf0e10cSrcweir sal_Int32 _nMaxNameLen, 329*cdf0e10cSrcweir const ::comphelper::TStringMixEqualFunctor& _aCase) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir ::rtl::OUString sConvertedName = m_pParent->convertColumnName(TMultiListBoxEntryFindFunctor(&_rRightColumns,_aCase), 332*cdf0e10cSrcweir _sColumnName, 333*cdf0e10cSrcweir _sExtraChars, 334*cdf0e10cSrcweir _nMaxNameLen); 335*cdf0e10cSrcweir OFieldDescription* pNewField = new OFieldDescription(*_pSrcField); 336*cdf0e10cSrcweir pNewField->SetName(sConvertedName); 337*cdf0e10cSrcweir sal_Bool bNotConvert = sal_True; 338*cdf0e10cSrcweir pNewField->SetType(m_pParent->convertType(_pSrcField->getSpecialTypeInfo(),bNotConvert)); 339*cdf0e10cSrcweir if ( !m_pParent->supportsPrimaryKey() ) 340*cdf0e10cSrcweir pNewField->SetPrimaryKey(sal_False); 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir _pListbox->SetEntryData(_pListbox->InsertEntry(sConvertedName),pNewField); 343*cdf0e10cSrcweir _rRightColumns.push_back(sConvertedName); 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir if ( !bNotConvert ) 346*cdf0e10cSrcweir m_pParent->showColumnTypeNotSupported(sConvertedName); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 349*cdf0e10cSrcweir void OWizColumnSelect::moveColumn( ListBox* _pRight, 350*cdf0e10cSrcweir ListBox* _pLeft, 351*cdf0e10cSrcweir ::std::vector< ::rtl::OUString>& _rRightColumns, 352*cdf0e10cSrcweir const ::rtl::OUString& _sColumnName, 353*cdf0e10cSrcweir const ::rtl::OUString& _sExtraChars, 354*cdf0e10cSrcweir sal_Int32 _nMaxNameLen, 355*cdf0e10cSrcweir const ::comphelper::TStringMixEqualFunctor& _aCase) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir if(_pRight == &m_lbNewColumnNames) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir // we copy the column into the new format for the dest 360*cdf0e10cSrcweir OFieldDescription* pSrcField = static_cast<OFieldDescription*>(_pLeft->GetEntryData(_pLeft->GetEntryPos(String(_sColumnName)))); 361*cdf0e10cSrcweir createNewColumn(_pRight,pSrcField,_rRightColumns,_sColumnName,_sExtraChars,_nMaxNameLen,_aCase); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir else 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir // find the new column in the dest name mapping to obtain the old column 366*cdf0e10cSrcweir OCopyTableWizard::TNameMapping::iterator aIter = ::std::find_if(m_pParent->m_mNameMapping.begin(),m_pParent->m_mNameMapping.end(), 367*cdf0e10cSrcweir ::std::compose1( 368*cdf0e10cSrcweir ::std::bind2nd(_aCase, _sColumnName), 369*cdf0e10cSrcweir ::std::select2nd<OCopyTableWizard::TNameMapping::value_type>()) 370*cdf0e10cSrcweir ); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir DBG_ASSERT(aIter != m_pParent->m_mNameMapping.end(),"Column must be defined"); 373*cdf0e10cSrcweir if ( aIter == m_pParent->m_mNameMapping.end() ) 374*cdf0e10cSrcweir return; // do nothing 375*cdf0e10cSrcweir const ODatabaseExport::TColumns* pSrcColumns = m_pParent->getSourceColumns(); 376*cdf0e10cSrcweir ODatabaseExport::TColumns::const_iterator aSrcIter = pSrcColumns->find((*aIter).first); 377*cdf0e10cSrcweir if ( aSrcIter != pSrcColumns->end() ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir // we need also the old position of this column to insert it back on that position again 380*cdf0e10cSrcweir const ODatabaseExport::TColumnVector* pSrcVector = m_pParent->getSrcVector(); 381*cdf0e10cSrcweir ODatabaseExport::TColumnVector::const_iterator aPos = ::std::find(pSrcVector->begin(),pSrcVector->end(),aSrcIter); 382*cdf0e10cSrcweir OSL_ENSURE( aPos != pSrcVector->end(),"Invalid position for the iterator here!"); 383*cdf0e10cSrcweir ODatabaseExport::TColumnVector::size_type nPos = (aPos - pSrcVector->begin()) - adjustColumnPosition(_pLeft, _sColumnName, (aPos - pSrcVector->begin()), _aCase); 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir _pRight->SetEntryData( _pRight->InsertEntry( (*aIter).first, sal::static_int_cast< sal_uInt16 >(nPos)),aSrcIter->second ); 386*cdf0e10cSrcweir _rRightColumns.push_back((*aIter).first); 387*cdf0e10cSrcweir m_pParent->removeColumnNameFromNameMap(_sColumnName); 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 392*cdf0e10cSrcweir // Simply returning fields back to their original position is 393*cdf0e10cSrcweir // not enough. We need to take into acccount what fields have 394*cdf0e10cSrcweir // been removed earlier and adjust accordingly. Based on the 395*cdf0e10cSrcweir // algorithm employed in moveColumn(). 396*cdf0e10cSrcweir sal_uInt16 OWizColumnSelect::adjustColumnPosition( ListBox* _pLeft, 397*cdf0e10cSrcweir const ::rtl::OUString& _sColumnName, 398*cdf0e10cSrcweir ODatabaseExport::TColumnVector::size_type nCurrentPos, 399*cdf0e10cSrcweir const ::comphelper::TStringMixEqualFunctor& _aCase) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir sal_uInt16 nAdjustedPos = 0; 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir // if returning all entries to their original position, 404*cdf0e10cSrcweir // then there is no need to adjust the positions. 405*cdf0e10cSrcweir if (m_ibColumns_LH.HasFocus()) 406*cdf0e10cSrcweir return nAdjustedPos; 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir sal_uInt16 nCount = _pLeft->GetEntryCount(); 409*cdf0e10cSrcweir ::rtl::OUString sColumnString; 410*cdf0e10cSrcweir for(sal_uInt16 i=0; i < nCount; ++i) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir sColumnString = _pLeft->GetEntry(i); 413*cdf0e10cSrcweir if(_sColumnName != sColumnString) 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir // find the new column in the dest name mapping to obtain the old column 416*cdf0e10cSrcweir OCopyTableWizard::TNameMapping::iterator aIter = ::std::find_if(m_pParent->m_mNameMapping.begin(),m_pParent->m_mNameMapping.end(), 417*cdf0e10cSrcweir ::std::compose1( 418*cdf0e10cSrcweir ::std::bind2nd(_aCase, sColumnString), 419*cdf0e10cSrcweir ::std::select2nd<OCopyTableWizard::TNameMapping::value_type>()) 420*cdf0e10cSrcweir ); 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir DBG_ASSERT(aIter != m_pParent->m_mNameMapping.end(),"Column must be defined"); 423*cdf0e10cSrcweir const ODatabaseExport::TColumns* pSrcColumns = m_pParent->getSourceColumns(); 424*cdf0e10cSrcweir ODatabaseExport::TColumns::const_iterator aSrcIter = pSrcColumns->find((*aIter).first); 425*cdf0e10cSrcweir if ( aSrcIter != pSrcColumns->end() ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir // we need also the old position of this column to insert it back on that position again 428*cdf0e10cSrcweir const ODatabaseExport::TColumnVector* pSrcVector = m_pParent->getSrcVector(); 429*cdf0e10cSrcweir ODatabaseExport::TColumnVector::const_iterator aPos = ::std::find(pSrcVector->begin(),pSrcVector->end(),aSrcIter); 430*cdf0e10cSrcweir ODatabaseExport::TColumnVector::size_type nPos = aPos - pSrcVector->begin(); 431*cdf0e10cSrcweir if( nPos < nCurrentPos) 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir nAdjustedPos++; 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir return nAdjustedPos; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 442*cdf0e10cSrcweir void OWizColumnSelect::enableButtons() 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir sal_Bool bEntries = m_lbNewColumnNames.GetEntryCount() != 0; 445*cdf0e10cSrcweir if(!bEntries) 446*cdf0e10cSrcweir m_pParent->m_mNameMapping.clear(); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir m_pParent->GetOKButton().Enable(bEntries); 449*cdf0e10cSrcweir m_pParent->EnableButton(OCopyTableWizard::WIZARD_NEXT,bEntries && m_pParent->getOperation() != CopyTableOperation::AppendData); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 452*cdf0e10cSrcweir 453