LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - WTypeSelect.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 215 0.0 %
Date: 2014-04-11 Functions: 0 31 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "WTypeSelect.hxx"
      21             : #include "WizardPages.hrc"
      22             : #include "dbustrings.hrc"
      23             : #include <tools/diagnose_ex.h>
      24             : #include <osl/diagnose.h>
      25             : #include "FieldDescriptions.hxx"
      26             : #include "WCopyTable.hxx"
      27             : #include "dbaccess_helpid.hrc"
      28             : #include "dbu_misc.hrc"
      29             : #include <tools/stream.hxx>
      30             : #include <svtools/svparser.hxx>
      31             : #include "UITools.hxx"
      32             : #include "sqlmessage.hxx"
      33             : #include "FieldControls.hxx"
      34             : 
      35             : #include "dbaccess_slotid.hrc"
      36             : 
      37             : using namespace ::dbaui;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::container;
      41             : using namespace ::com::sun::star::util;
      42             : using namespace ::com::sun::star::sdbc;
      43             : 
      44             : // OWizTypeSelectControl
      45           0 : OWizTypeSelectControl::OWizTypeSelectControl(Window* pParent, const ResId& rResId,OTableDesignHelpBar* pHelpBar)
      46           0 :     : OFieldDescControl(pParent,rResId,pHelpBar)
      47             : {
      48             : 
      49           0 : }
      50             : 
      51           0 : OWizTypeSelectControl::~OWizTypeSelectControl()
      52             : {
      53             : 
      54           0 : }
      55             : 
      56           0 : void OWizTypeSelectControl::ActivateAggregate( EControlType eType )
      57             : {
      58           0 :     switch(eType )
      59             :     {
      60             :         case tpFormat:
      61             :         case tpDefault:
      62             :         case tpAutoIncrement:
      63             :         case tpAutoIncrementValue:
      64           0 :             break;
      65             :         default:
      66           0 :             OFieldDescControl::ActivateAggregate( eType );
      67             :     }
      68           0 : }
      69             : 
      70           0 : void OWizTypeSelectControl::DeactivateAggregate( EControlType eType )
      71             : {
      72           0 :     switch(eType )
      73             :     {
      74             :         case tpFormat:
      75             :         case tpDefault:
      76             :         case tpAutoIncrement:
      77             :         case tpAutoIncrementValue:
      78           0 :             break;
      79             :         default:
      80           0 :             OFieldDescControl::DeactivateAggregate( eType );
      81             :     }
      82           0 : }
      83             : 
      84           0 : void OWizTypeSelectControl::CellModified(long nRow, sal_uInt16 nColId )
      85             : {
      86             :     OSL_ENSURE(nRow == -1,"nRow muss -1 sein!");
      87             :     (void)nRow;
      88             : 
      89           0 :     MultiListBox &aListBox = ((OWizTypeSelect*)GetParent())->m_lbColumnNames;
      90             : 
      91           0 :     OFieldDescription* pCurFieldDescr = getCurrentFieldDescData();
      92             : 
      93           0 :     sal_uInt16 nPos = aListBox.GetEntryPos( OUString( pCurFieldDescr->GetName() ) );
      94           0 :     pCurFieldDescr = static_cast< OFieldDescription* >( aListBox.GetEntryData( nPos ) );
      95             :     OSL_ENSURE( pCurFieldDescr, "OWizTypeSelectControl::CellModified: Columnname/type not found in the listbox!" );
      96           0 :     if ( !pCurFieldDescr )
      97           0 :         return;
      98           0 :     setCurrentFieldDescData( pCurFieldDescr );
      99             : 
     100           0 :     OUString sName = pCurFieldDescr->GetName();
     101           0 :     OUString sNewName;
     102           0 :     const OPropColumnEditCtrl* pColumnName = getColumnCtrl();
     103           0 :     if ( pColumnName )
     104           0 :         sNewName = pColumnName->GetText();
     105             : 
     106           0 :     switch(nColId)
     107             :     {
     108             :         case FIELD_PROPERTY_COLUMNNAME:
     109             :             {
     110           0 :                 OCopyTableWizard* pWiz = static_cast<OCopyTableWizard*>(GetParentDialog());
     111             :                 // first we have to check if this name already exists
     112           0 :                 sal_Bool bDoubleName = sal_False;
     113           0 :                 sal_Bool bCase = sal_True;
     114           0 :                 if ( getMetaData().is() && !getMetaData()->supportsMixedCaseQuotedIdentifiers() )
     115             :                 {
     116           0 :                     bCase = sal_False;
     117           0 :                     sal_uInt16 nCount = aListBox.GetEntryCount();
     118           0 :                     for (sal_uInt16 i=0 ; !bDoubleName && i < nCount ; ++i)
     119             :                     {
     120           0 :                         OUString sEntry(aListBox.GetEntry(i));
     121           0 :                         bDoubleName = sNewName.equalsIgnoreAsciiCase(sEntry);
     122           0 :                     }
     123           0 :                     if ( !bDoubleName && pWiz->shouldCreatePrimaryKey() )
     124           0 :                         bDoubleName = sNewName.equalsIgnoreAsciiCase(pWiz->getPrimaryKeyName());
     125             : 
     126             :                 }
     127             :                 else
     128           0 :                     bDoubleName =  ((aListBox.GetEntryPos(OUString(sNewName)) != LISTBOX_ENTRY_NOTFOUND)
     129           0 :                                     || ( pWiz->shouldCreatePrimaryKey()
     130           0 :                                         &&  pWiz->getPrimaryKeyName() == sNewName) );
     131             : 
     132           0 :                 if ( bDoubleName )
     133             :                 {
     134           0 :                     OUString strMessage = ModuleRes(STR_TABLEDESIGN_DUPLICATE_NAME);
     135           0 :                     strMessage = strMessage.replaceFirst("$column$", sNewName);
     136           0 :                     pWiz->showError(strMessage);
     137           0 :                     pCurFieldDescr->SetName(sName);
     138           0 :                     DisplayData(pCurFieldDescr);
     139           0 :                     static_cast<OWizTypeSelect*>(GetParent())->setDuplicateName(sal_True);
     140           0 :                     return;
     141             :                 }
     142             : 
     143           0 :                 OUString sOldName = pCurFieldDescr->GetName();
     144           0 :                 pCurFieldDescr->SetName(sNewName);
     145           0 :                 static_cast<OWizTypeSelect*>(GetParent())->setDuplicateName(sal_False);
     146             : 
     147             :                 // now we change the name
     148           0 :                 OCopyTableWizard::TNameMapping::iterator aIter = pWiz->m_mNameMapping.begin();
     149           0 :                 OCopyTableWizard::TNameMapping::iterator aEnd  = pWiz->m_mNameMapping.end();
     150             : 
     151           0 :                 ::comphelper::UStringMixEqual aCase(bCase);
     152           0 :                 for(;aIter != aEnd;++aIter)
     153             :                 {
     154           0 :                     if ( aCase(aIter->second,sName) )
     155             :                     {
     156           0 :                         aIter->second = sNewName;
     157           0 :                         break;
     158             :                     }
     159             :                 }
     160             : 
     161           0 :                 aListBox.RemoveEntry(nPos);
     162           0 :                 aListBox.InsertEntry(pCurFieldDescr->GetName(),nPos);
     163           0 :                 aListBox.SetEntryData(nPos,pCurFieldDescr);
     164             : 
     165           0 :                 pWiz->replaceColumn(nPos,pCurFieldDescr,sOldName);
     166             :             }
     167           0 :             break;
     168             :     }
     169           0 :     saveCurrentFieldDescData();
     170             : }
     171             : 
     172           0 : ::com::sun::star::lang::Locale  OWizTypeSelectControl::GetLocale() const
     173             : {
     174           0 :     return static_cast<OWizTypeSelect*>(GetParent())->m_pParent->GetLocale();
     175             : }
     176             : 
     177           0 : Reference< XNumberFormatter > OWizTypeSelectControl::GetFormatter() const
     178             : {
     179           0 :     return static_cast<OWizTypeSelect*>(GetParent())->m_pParent->GetFormatter();
     180             : }
     181             : 
     182           0 : TOTypeInfoSP    OWizTypeSelectControl::getTypeInfo(sal_Int32 _nPos)
     183             : {
     184           0 :     return static_cast<OWizTypeSelect*>(GetParent())->m_pParent->getDestTypeInfo(_nPos);
     185             : }
     186             : 
     187           0 : const OTypeInfoMap* OWizTypeSelectControl::getTypeInfo() const
     188             : {
     189           0 :     return static_cast<OWizTypeSelect*>(GetParent())->m_pParent->getDestTypeInfo();
     190             : }
     191             : 
     192           0 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> OWizTypeSelectControl::getMetaData()
     193             : {
     194           0 :     return ((OWizTypeSelect*)GetParent())->m_pParent->m_xDestConnection->getMetaData();
     195             : }
     196             : 
     197           0 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> OWizTypeSelectControl::getConnection()
     198             : {
     199           0 :     return ((OWizTypeSelect*)GetParent())->m_pParent->m_xDestConnection;
     200             : }
     201             : 
     202           0 : sal_Bool OWizTypeSelectControl::isAutoIncrementValueEnabled() const
     203             : {
     204           0 :     return ((OWizTypeSelect*)GetParent())->m_bAutoIncrementEnabled;
     205             : }
     206             : 
     207           0 : OUString OWizTypeSelectControl::getAutoIncrementValue() const
     208             : {
     209           0 :     return ((OWizTypeSelect*)GetParent())->m_sAutoIncrementValue;
     210             : }
     211             : 
     212             : #define IMG_PRIMARY_KEY 1
     213           0 : OWizTypeSelect::OWizTypeSelect( Window* pParent, SvStream* _pStream )
     214             :                :OWizardPage( pParent, ModuleRes( TAB_WIZ_TYPE_SELECT ))
     215             :                ,m_lbColumnNames( this, ModuleRes( LB_NEW_COLUMN_NAMES ) )
     216             :                ,m_flColumns( this, ModuleRes( FL_COLUMN_NAME ) )
     217             :                ,m_aTypeControl( this, ModuleRes( CONTROL_CONTAINER ))
     218             :                ,m_flAutoType( this, ModuleRes( FL_AUTO_TYPE ) )
     219             :                ,m_ftAuto( this, ModuleRes( FT_AUTO ) )
     220             :                ,m_etAuto( this, ModuleRes( ET_AUTO ) )
     221             :                ,m_pbAuto( this, ModuleRes( PB_AUTO ) )
     222             :                ,m_pParserStream( _pStream )
     223             :                ,m_nDisplayRow(0)
     224             :                ,m_bAutoIncrementEnabled(sal_False)
     225           0 :                ,m_bDuplicateName(sal_False)
     226             : {
     227           0 :     m_lbColumnNames.SetSelectHdl(LINK(this,OWizTypeSelect,ColumnSelectHdl));
     228             : 
     229           0 :     ModuleRes aModuleRes(IMG_JOINS);
     230           0 :     ImageList aImageList(aModuleRes);
     231           0 :     m_imgPKey = aImageList.GetImage(IMG_PRIMARY_KEY);
     232             : 
     233           0 :     m_aTypeControl.Show();
     234           0 :     m_aTypeControl.Init();
     235           0 :     m_etAuto.SetText(OUString("10"));
     236           0 :     m_etAuto.SetDecimalDigits(0);
     237           0 :     m_pbAuto.SetClickHdl(LINK(this,OWizTypeSelect,ButtonClickHdl));
     238           0 :     m_lbColumnNames.EnableMultiSelection(true);
     239             : 
     240             :     try
     241             :     {
     242           0 :         m_lbColumnNames.SetPKey( m_pParent->supportsPrimaryKey() );
     243           0 :         ::dbaui::fillAutoIncrementValue( m_pParent->m_xDestConnection, m_bAutoIncrementEnabled, m_sAutoIncrementValue );
     244             :     }
     245           0 :     catch(const Exception&)
     246             :     {
     247             :         DBG_UNHANDLED_EXCEPTION();
     248             :     }
     249             : 
     250           0 :     FreeResource();
     251           0 : }
     252             : 
     253           0 : OWizTypeSelect::~OWizTypeSelect()
     254             : {
     255           0 : }
     256             : 
     257           0 : OUString OWizTypeSelect::GetTitle() const
     258             : {
     259           0 :     return ModuleRes(STR_WIZ_TYPE_SELECT_TITEL);
     260             : }
     261             : 
     262           0 : void OWizTypeSelect::Resize()
     263             : {
     264           0 : }
     265             : 
     266           0 : IMPL_LINK( OWizTypeSelect, ColumnSelectHdl, MultiListBox *, /*pListBox*/ )
     267             : {
     268           0 :     OUString aColumnName( m_lbColumnNames.GetSelectEntry() );
     269             : 
     270           0 :     OFieldDescription* pField = static_cast<OFieldDescription*>(m_lbColumnNames.GetEntryData(m_lbColumnNames.GetEntryPos(aColumnName)));
     271           0 :     if(pField)
     272           0 :         m_aTypeControl.DisplayData(pField);
     273             : 
     274           0 :     m_aTypeControl.Enable(m_lbColumnNames.GetSelectEntryCount() == 1 );
     275           0 :     return 0;
     276             : }
     277             : 
     278           0 : void OWizTypeSelect::Reset()
     279             : {
     280             :     // restore original state
     281             : 
     282           0 :     while(m_lbColumnNames.GetEntryCount())
     283           0 :         m_lbColumnNames.RemoveEntry(0);
     284           0 :     m_lbColumnNames.Clear();
     285             :     sal_Int32 nBreakPos;
     286           0 :     m_pParent->CheckColumns(nBreakPos);
     287             : 
     288           0 :     const ODatabaseExport::TColumnVector* pDestColumns = m_pParent->getDestVector();
     289           0 :     ODatabaseExport::TColumnVector::const_iterator aIter = pDestColumns->begin();
     290           0 :     ODatabaseExport::TColumnVector::const_iterator aEnd = pDestColumns->end();
     291           0 :     for(;aIter != aEnd;++aIter)
     292             :     {
     293             :         sal_uInt16 nPos;
     294           0 :         if((*aIter)->second->IsPrimaryKey())
     295           0 :             nPos = m_lbColumnNames.InsertEntry((*aIter)->first, m_imgPKey );
     296             :         else
     297           0 :             nPos = m_lbColumnNames.InsertEntry((*aIter)->first);
     298           0 :         m_lbColumnNames.SetEntryData(nPos,(*aIter)->second);
     299             :     }
     300           0 :     m_bFirstTime = sal_False;
     301           0 : }
     302             : 
     303           0 : void OWizTypeSelect::ActivatePage( )
     304             : {
     305           0 :     sal_Bool bOldFirstTime = m_bFirstTime;
     306           0 :     Reset();
     307           0 :     m_bFirstTime = bOldFirstTime;
     308             : 
     309           0 :     m_lbColumnNames.SelectEntryPos(static_cast<sal_uInt16>(m_nDisplayRow));
     310           0 :     m_nDisplayRow = 0;
     311           0 :     m_lbColumnNames.GetSelectHdl().Call(&m_lbColumnNames);
     312           0 : }
     313             : 
     314           0 : sal_Bool OWizTypeSelect::LeavePage()
     315             : {
     316           0 :     OUString aColumnName( m_lbColumnNames.GetSelectEntry() );
     317             : 
     318           0 :     sal_Bool bDuplicateName = sal_False;
     319           0 :     OFieldDescription* pField = static_cast<OFieldDescription*>(m_lbColumnNames.GetEntryData(m_lbColumnNames.GetEntryPos(aColumnName)));
     320           0 :     if ( pField )
     321             :     {
     322           0 :         m_aTypeControl.SaveData(pField);
     323           0 :         bDuplicateName = m_bDuplicateName;
     324             :     }
     325           0 :     return !bDuplicateName;
     326             : }
     327             : 
     328           0 : void OWizTypeSelect::EnableAuto(sal_Bool bEnable)
     329             : {
     330           0 :     m_ftAuto.Show(bEnable);
     331           0 :     m_etAuto.Show(bEnable);
     332           0 :     m_pbAuto.Show(bEnable);
     333           0 :     m_flAutoType.Show(bEnable);
     334           0 : }
     335             : 
     336           0 : IMPL_LINK( OWizTypeSelect, ButtonClickHdl, Button *, /*pButton*/ )
     337             : {
     338             :     sal_Int32 nBreakPos;
     339           0 :     m_pParent->CheckColumns(nBreakPos);
     340           0 :     fillColumnList(m_etAuto.GetText().toInt32());
     341             : 
     342           0 :     ActivatePage();
     343             : 
     344           0 :     return 0;
     345             : }
     346             : 
     347           0 : sal_Bool OWizTypeSelectList::IsPrimaryKeyAllowed() const
     348             : {
     349           0 :     sal_uInt16 nCount = GetSelectEntryCount();
     350             :     sal_uInt16 j;
     351             : 
     352           0 :     for( j = 0; m_bPKey && j < nCount; ++j )
     353             :     {
     354           0 :         OFieldDescription* pField = static_cast<OFieldDescription*>(GetEntryData(GetSelectEntryPos(j)));
     355           0 :         if(!pField || pField->getTypeInfo()->nSearchType == ColumnSearch::NONE)
     356           0 :             break;
     357             :     }
     358           0 :     return j == nCount;
     359             : }
     360             : 
     361           0 : void OWizTypeSelectList::setPrimaryKey(OFieldDescription* _pFieldDescr,sal_uInt16 _nPos,sal_Bool _bSet)
     362             : {
     363           0 :     OUString sColumnName = GetEntry(_nPos);
     364           0 :     RemoveEntry(_nPos);
     365           0 :     _pFieldDescr->SetPrimaryKey(_bSet);
     366           0 :     if( _bSet )
     367           0 :         InsertEntry(sColumnName,((OWizTypeSelect*)GetParent())->m_imgPKey,_nPos);
     368           0 :     else if( _pFieldDescr->getTypeInfo()->bNullable )
     369             :     {
     370           0 :         _pFieldDescr->SetControlDefault(Any());
     371           0 :         InsertEntry(sColumnName,_nPos);
     372             :     }
     373           0 :     SetEntryData(_nPos,_pFieldDescr);
     374           0 : }
     375             : 
     376           0 : bool OWizTypeSelectList::PreNotify( NotifyEvent& rEvt )
     377             : {
     378           0 :     bool nDone = false;
     379           0 :     switch( rEvt.GetType() )
     380             :     {
     381             :         case EVENT_MOUSEBUTTONDOWN:
     382             :         {
     383           0 :             const MouseEvent* pMEvt = rEvt.GetMouseEvent();
     384           0 :             if(pMEvt->IsRight() && !pMEvt->GetModifier())
     385           0 :                 nDone = true;
     386             :         }
     387           0 :             break;
     388             :         case EVENT_COMMAND:
     389             :         {
     390           0 :             if(!IsPrimaryKeyAllowed())
     391           0 :                 break;
     392             : 
     393           0 :             const CommandEvent* pComEvt = rEvt.GetCommandEvent();
     394           0 :             if(pComEvt->GetCommand() != COMMAND_CONTEXTMENU)
     395           0 :                 break;
     396             :             // the place, at which was clicked
     397           0 :             Point ptWhere(0,0);
     398           0 :             if (pComEvt->IsMouseEvent())
     399           0 :                 ptWhere = pComEvt->GetMousePosPixel();
     400             : 
     401           0 :             PopupMenu aContextMenu(ModuleRes(RID_SBA_RTF_PKEYPOPUP));
     402           0 :             switch( aContextMenu.Execute( this, ptWhere ) )
     403             :             {
     404             :                 case SID_TABLEDESIGN_TABED_PRIMARYKEY:
     405             :                 {
     406           0 :                     sal_uInt16 nCount = GetEntryCount();
     407           0 :                     for(sal_uInt16 j = 0 ; j < nCount ; ++j)
     408             :                     {
     409           0 :                         OFieldDescription* pFieldDescr = static_cast<OFieldDescription*>(GetEntryData(j));
     410           0 :                         if( pFieldDescr )
     411             :                         {
     412           0 :                             if(pFieldDescr->IsPrimaryKey() && !IsEntryPosSelected(j))
     413           0 :                                 setPrimaryKey(pFieldDescr,j);
     414           0 :                             else if(IsEntryPosSelected(j))
     415             :                             {
     416           0 :                                 setPrimaryKey(pFieldDescr,j,!pFieldDescr->IsPrimaryKey());
     417           0 :                                 SelectEntryPos(j);
     418             :                             }
     419             :                         }
     420             :                     }
     421           0 :                     GetSelectHdl().Call(this);
     422             :                 }
     423           0 :                 break;
     424             :             }
     425           0 :             nDone = true;
     426             :         }
     427           0 :         break;
     428             :     }
     429           0 :     return nDone || MultiListBox::PreNotify(rEvt);
     430             : }
     431             : 
     432           0 : void OWizTypeSelect::fillColumnList(sal_uInt32 nRows)
     433             : {
     434           0 :     if(m_pParserStream)
     435             :     {
     436           0 :         sal_Size nTell = m_pParserStream->Tell(); // might change seek position of stream
     437             : 
     438           0 :         SvParser *pReader = createReader(nRows);
     439           0 :         if(pReader)
     440             :         {
     441           0 :             pReader->AddRef();
     442           0 :             pReader->CallParser();
     443           0 :             pReader->ReleaseRef();
     444             :         }
     445           0 :         m_pParserStream->Seek(nTell);
     446             :     }
     447           0 : }
     448             : 
     449             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10