LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - QTableWindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 86 0.0 %
Date: 2012-08-25 Functions: 0 10 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 162 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "QTableWindow.hxx"
      30                 :            : #include "QueryTableView.hxx"
      31                 :            : #include "dbustrings.hrc"
      32                 :            : #include <osl/diagnose.h>
      33                 :            : #include "dbaccess_helpid.hrc"
      34                 :            : #include "QueryDesignView.hxx"
      35                 :            : #include "browserids.hxx"
      36                 :            : #include "querycontroller.hxx"
      37                 :            : #include <vcl/image.hxx>
      38                 :            : #include "TableWindowListBox.hxx"
      39                 :            : #include "dbu_qry.hrc"
      40                 :            : #include "Query.hrc"
      41                 :            : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      42                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      43                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      44                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      45                 :            : #include <com/sun/star/sdbcx/KeyType.hpp>
      46                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      47                 :            : #include "TableFieldInfo.hxx"
      48                 :            : #include <comphelper/extract.hxx>
      49                 :            : #include <comphelper/string.hxx>
      50                 :            : #include <comphelper/uno3.hxx>
      51                 :            : #include "UITools.hxx"
      52                 :            : 
      53                 :            : 
      54                 :            : using namespace ::com::sun::star::sdbc;
      55                 :            : using namespace ::com::sun::star::sdbcx;
      56                 :            : using namespace ::com::sun::star::uno;
      57                 :            : using namespace ::com::sun::star::container;
      58                 :            : using namespace ::com::sun::star::beans;
      59                 :            : using namespace dbaui;
      60                 :            : //========================================================================
      61                 :            : // class OQueryTableWindow
      62                 :            : //========================================================================
      63                 :            : DBG_NAME(OQueryTableWindow)
      64                 :            : //------------------------------------------------------------------------------
      65                 :          0 : OQueryTableWindow::OQueryTableWindow( Window* pParent, const TTableWindowData::value_type& pTabWinData, sal_Unicode* pszInitialAlias)
      66                 :            :     :OTableWindow( pParent, pTabWinData )
      67                 :          0 :     ,m_nAliasNum(0)
      68                 :            : {
      69                 :            :     DBG_CTOR(OQueryTableWindow,NULL);
      70         [ #  # ]:          0 :     if (pszInitialAlias != NULL)
      71                 :          0 :         m_strInitialAlias = ::rtl::OUString(pszInitialAlias);
      72                 :            :     else
      73         [ #  # ]:          0 :         m_strInitialAlias = GetAliasName();
      74                 :            : 
      75                 :            :     // wenn der Tabellen- gleich dem Aliasnamen ist, dann darf ich das nicht an InitialAlias weiterreichen, denn das Anhaengen
      76                 :            :     // eines eventuelle Tokens nicht klappen ...
      77         [ #  # ]:          0 :     if (m_strInitialAlias == pTabWinData->GetTableName())
      78                 :          0 :         m_strInitialAlias = ::rtl::OUString();
      79                 :            : 
      80         [ #  # ]:          0 :     SetHelpId(HID_CTL_QRYDGNTAB);
      81                 :          0 : }
      82                 :            : 
      83                 :            : //------------------------------------------------------------------------------
      84                 :          0 : OQueryTableWindow::~OQueryTableWindow()
      85                 :            : {
      86                 :            :     DBG_DTOR(OQueryTableWindow,NULL);
      87         [ #  # ]:          0 : }
      88                 :            : 
      89                 :            : //------------------------------------------------------------------------------
      90                 :          0 : sal_Bool OQueryTableWindow::Init()
      91                 :            : {
      92         [ #  # ]:          0 :     sal_Bool bSuccess = OTableWindow::Init();
      93         [ #  # ]:          0 :     if(!bSuccess)
      94                 :          0 :         return bSuccess;
      95                 :            : 
      96         [ #  # ]:          0 :     OQueryTableView* pContainer = static_cast<OQueryTableView*>(getTableView());
      97                 :            : 
      98                 :            :     // zuerst Alias bestimmen
      99                 :          0 :     ::rtl::OUString sAliasName;
     100                 :            : 
     101         [ #  # ]:          0 :     TTableWindowData::value_type pWinData = GetData();
     102                 :            : 
     103         [ #  # ]:          0 :     if (!m_strInitialAlias.isEmpty() )
     104                 :            :         // Der Alias wurde explizit mit angegeben
     105                 :          0 :         sAliasName = m_strInitialAlias;
     106 [ #  # ][ #  # ]:          0 :     else if ( GetTable().is() )
     107 [ #  # ][ #  # ]:          0 :         GetTable()->getPropertyValue( PROPERTY_NAME ) >>= sAliasName;
         [ #  # ][ #  # ]
     108                 :            :     else
     109                 :          0 :         return sal_False;
     110                 :            : 
     111                 :            :     // Alias mit fortlaufender Nummer versehen
     112 [ #  # ][ #  # ]:          0 :     if (pContainer->CountTableAlias(sAliasName, m_nAliasNum))
         [ #  # ][ #  # ]
     113                 :            :     {
     114                 :          0 :         sAliasName += ::rtl::OUString('_');
     115                 :          0 :         sAliasName += ::rtl::OUString::valueOf(m_nAliasNum);
     116                 :            :     }
     117                 :            : 
     118                 :            : 
     119                 :          0 :     sAliasName = comphelper::string::remove(sAliasName, '"');
     120         [ #  # ]:          0 :     SetAliasName(sAliasName);
     121                 :            :         // SetAliasName reicht das als WinName weiter, dadurch benutzt es die Basisklasse
     122                 :            :     // reset the title
     123 [ #  # ][ #  # ]:          0 :     m_aTitle.SetText( pWinData->GetWinName() );
                 [ #  # ]
     124         [ #  # ]:          0 :     m_aTitle.Show();
     125                 :            : 
     126         [ #  # ]:          0 :     if (!bSuccess)
     127                 :            :     {   // es soll nur ein Dummy-Window aufgemacht werden ...
     128                 :            :         OSL_ENSURE(!GetAliasName().isEmpty(), "OQueryTableWindow::Init : kein Alias- UND kein Tabellenname geht nicht !");
     129                 :            :             // .. aber das braucht wenigstens einen Alias
     130                 :            : 
     131                 :            :         // ::com::sun::star::form::ListBox anlegen
     132         [ #  # ]:          0 :         if (!m_pListBox)
     133         [ #  # ]:          0 :             m_pListBox = CreateListBox();
     134                 :            : 
     135                 :            :         // Titel setzen
     136 [ #  # ][ #  # ]:          0 :         m_aTitle.SetText(GetAliasName());
         [ #  # ][ #  # ]
     137         [ #  # ]:          0 :         m_aTitle.Show();
     138                 :            : 
     139         [ #  # ]:          0 :         clearListBox();
     140                 :            :             // neu zu fuellen brauche ich die nicht, da ich ja keine Tabelle habe
     141         [ #  # ]:          0 :         m_pListBox->Show();
     142                 :            :     }
     143                 :            : 
     144 [ #  # ][ #  # ]:          0 :     getTableView()->getDesignView()->getController().InvalidateFeature(ID_BROWSER_QUERY_EXECUTE);
                 [ #  # ]
     145         [ #  # ]:          0 :     return bSuccess;
     146                 :            : }
     147                 :            : // -----------------------------------------------------------------------------
     148                 :          0 : void* OQueryTableWindow::createUserData(const Reference< XPropertySet>& _xColumn,bool _bPrimaryKey)
     149                 :            : {
     150         [ #  # ]:          0 :     OTableFieldInfo* pInfo = new OTableFieldInfo();
     151         [ #  # ]:          0 :     pInfo->SetKey(_bPrimaryKey ? TAB_PRIMARY_FIELD : TAB_NORMAL_FIELD);
     152         [ #  # ]:          0 :     if ( _xColumn.is() )
     153 [ #  # ][ #  # ]:          0 :         pInfo->SetDataType(::comphelper::getINT32(_xColumn->getPropertyValue(PROPERTY_TYPE)));
     154                 :          0 :     return pInfo;
     155                 :            : }
     156                 :            : // -----------------------------------------------------------------------------
     157                 :          0 : void OQueryTableWindow::deleteUserData(void*& _pUserData)
     158                 :            : {
     159         [ #  # ]:          0 :     delete static_cast<OTableFieldInfo*>(_pUserData);
     160                 :          0 :     _pUserData = NULL;
     161                 :          0 : }
     162                 :            : //------------------------------------------------------------------------------
     163                 :          0 : void OQueryTableWindow::OnEntryDoubleClicked(SvLBoxEntry* pEntry)
     164                 :            : {
     165                 :            :     OSL_ENSURE(pEntry != NULL, "OQueryTableWindow::OnEntryDoubleClicked : pEntry darf nicht NULL sein !");
     166                 :            :         // man koennte das auch abfragen und dann ein return hinsetzen, aber so weist es vielleicht auf Fehler bei Aufrufer hin
     167                 :            : 
     168 [ #  # ][ #  # ]:          0 :     if (getTableView()->getDesignView()->getController().isReadOnly())
                 [ #  # ]
     169                 :          0 :         return;
     170                 :            : 
     171                 :          0 :     OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData());
     172                 :            :     OSL_ENSURE(pInf != NULL, "OQueryTableWindow::OnEntryDoubleClicked : Feld hat keine FieldInfo !");
     173                 :            : 
     174                 :            :     // eine DragInfo aufbauen
     175 [ #  # ][ #  # ]:          0 :     OTableFieldDescRef aInfo = new OTableFieldDesc(GetTableName(),m_pListBox->GetEntryText(pEntry));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     176                 :          0 :     aInfo->SetTabWindow(this);
     177         [ #  # ]:          0 :     aInfo->SetAlias(GetAliasName());
     178         [ #  # ]:          0 :     aInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry));
     179                 :          0 :     aInfo->SetDataType(pInf->GetDataType());
     180                 :            : 
     181                 :            :     // und das entsprechende Feld einfuegen
     182 [ #  # ][ #  # ]:          0 :     static_cast<OQueryTableView*>(getTableView())->InsertField(aInfo);
                 [ #  # ]
     183                 :            : }
     184                 :            : 
     185                 :            : //------------------------------------------------------------------------------
     186                 :          0 : sal_Bool OQueryTableWindow::ExistsField(const ::rtl::OUString& strFieldName, OTableFieldDescRef& rInfo)
     187                 :            : {
     188                 :            :     OSL_ENSURE(m_pListBox != NULL, "OQueryTableWindow::ExistsField : habe keine ::com::sun::star::form::ListBox !");
     189                 :            :     OSL_ENSURE(rInfo.is(),"OQueryTableWindow::ExistsField: invlid argument for OTableFieldDescRef!");
     190 [ #  # ][ #  # ]:          0 :     Reference< XConnection> xConnection = getTableView()->getDesignView()->getController().getConnection();
     191                 :          0 :     sal_Bool bExists = sal_False;
     192         [ #  # ]:          0 :     if(xConnection.is())
     193                 :            :     {
     194         [ #  # ]:          0 :         SvLBoxEntry* pEntry = m_pListBox->First();
     195                 :            :         try
     196                 :            :         {
     197 [ #  # ][ #  # ]:          0 :             Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
     198 [ #  # ][ #  # ]:          0 :             ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
         [ #  # ][ #  # ]
     199                 :            : 
     200         [ #  # ]:          0 :             while (pEntry)
     201                 :            :             {
     202 [ #  # ][ #  # ]:          0 :                 if (bCase(strFieldName,::rtl::OUString(m_pListBox->GetEntryText(pEntry))))
         [ #  # ][ #  # ]
     203                 :            :                 {
     204                 :          0 :                     OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData());
     205                 :            :                     OSL_ENSURE(pInf != NULL, "OQueryTableWindow::ExistsField : Feld hat keine FieldInfo !");
     206                 :            : 
     207                 :          0 :                     rInfo->SetTabWindow(this);
     208                 :          0 :                     rInfo->SetField(strFieldName);
     209         [ #  # ]:          0 :                     rInfo->SetTable(GetTableName());
     210         [ #  # ]:          0 :                     rInfo->SetAlias(GetAliasName());
     211         [ #  # ]:          0 :                     rInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry));
     212                 :          0 :                     rInfo->SetDataType(pInf->GetDataType());
     213                 :          0 :                     bExists = sal_True;
     214                 :          0 :                     break;
     215                 :            :                 }
     216         [ #  # ]:          0 :                 pEntry = m_pListBox->Next(pEntry);
     217         [ #  # ]:          0 :             }
     218                 :            :         }
     219         [ #  # ]:          0 :         catch(SQLException&)
     220                 :            :         {
     221                 :            :         }
     222                 :            :     }
     223                 :            : 
     224                 :          0 :     return bExists;
     225                 :            : }
     226                 :            : 
     227                 :            : //------------------------------------------------------------------------------
     228                 :          0 : sal_Bool OQueryTableWindow::ExistsAVisitedConn() const
     229                 :            : {
     230                 :          0 :     return static_cast<const OQueryTableView*>(getTableView())->ExistsAVisitedConn(this);
     231                 :            : }
     232                 :            : 
     233                 :            : //------------------------------------------------------------------------------
     234                 :          0 : void OQueryTableWindow::KeyInput( const KeyEvent& rEvt )
     235                 :            : {
     236                 :          0 :     OTableWindow::KeyInput( rEvt );
     237                 :          0 : }
     238                 :            : // -----------------------------------------------------------------------------
     239                 :            : 
     240                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10