LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - QTableWindow.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 79 1.3 %
Date: 2014-11-03 Functions: 2 12 16.7 %
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 "QTableWindow.hxx"
      21             : #include "QueryTableView.hxx"
      22             : #include "dbustrings.hrc"
      23             : #include <osl/diagnose.h>
      24             : #include "dbaccess_helpid.hrc"
      25             : #include "QueryDesignView.hxx"
      26             : #include "browserids.hxx"
      27             : #include "querycontroller.hxx"
      28             : #include <vcl/image.hxx>
      29             : #include "TableWindowListBox.hxx"
      30             : #include "dbu_qry.hrc"
      31             : #include "Query.hrc"
      32             : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      33             : #include <com/sun/star/container/XNameAccess.hpp>
      34             : #include <com/sun/star/container/XIndexAccess.hpp>
      35             : #include <com/sun/star/beans/XPropertySet.hpp>
      36             : #include <com/sun/star/sdbcx/KeyType.hpp>
      37             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      38             : #include "TableFieldInfo.hxx"
      39             : #include <comphelper/extract.hxx>
      40             : #include <comphelper/string.hxx>
      41             : #include <comphelper/uno3.hxx>
      42             : #include "UITools.hxx"
      43             : #include "svtools/treelistentry.hxx"
      44             : 
      45             : using namespace ::com::sun::star::sdbc;
      46             : using namespace ::com::sun::star::sdbcx;
      47             : using namespace ::com::sun::star::uno;
      48             : using namespace ::com::sun::star::container;
      49             : using namespace ::com::sun::star::beans;
      50             : using namespace dbaui;
      51             : // class OQueryTableWindow
      52           0 : OQueryTableWindow::OQueryTableWindow( vcl::Window* pParent, const TTableWindowData::value_type& pTabWinData, sal_Unicode* pszInitialAlias)
      53             :     :OTableWindow( pParent, pTabWinData )
      54           0 :     ,m_nAliasNum(0)
      55             : {
      56           0 :     if (pszInitialAlias != NULL)
      57           0 :         m_strInitialAlias = OUString(pszInitialAlias);
      58             :     else
      59           0 :         m_strInitialAlias = GetAliasName();
      60             : 
      61             :     // if table name matches alias, do not pass to InitialAlias,
      62             :     // as the appending of a possible token could not succeed...
      63           0 :     if (m_strInitialAlias == pTabWinData->GetTableName())
      64           0 :         m_strInitialAlias = OUString();
      65             : 
      66           0 :     SetHelpId(HID_CTL_QRYDGNTAB);
      67           0 : }
      68             : 
      69           0 : OQueryTableWindow::~OQueryTableWindow()
      70             : {
      71           0 : }
      72             : 
      73           0 : bool OQueryTableWindow::Init()
      74             : {
      75           0 :     bool bSuccess = OTableWindow::Init();
      76           0 :     if (!bSuccess)
      77           0 :         return bSuccess;
      78             : 
      79           0 :     OQueryTableView* pContainer = static_cast<OQueryTableView*>(getTableView());
      80             : 
      81             :     // first determine Alias
      82           0 :     OUString sAliasName;
      83             : 
      84           0 :     TTableWindowData::value_type pWinData = GetData();
      85             : 
      86           0 :     if (!m_strInitialAlias.isEmpty() )
      87             :         // Alias was explicitly given
      88           0 :         sAliasName = m_strInitialAlias;
      89           0 :     else if ( GetTable().is() )
      90           0 :         GetTable()->getPropertyValue( PROPERTY_NAME ) >>= sAliasName;
      91             :     else
      92           0 :         return false;
      93             : 
      94             :     // Alias with successive number
      95           0 :     if (pContainer->CountTableAlias(sAliasName, m_nAliasNum))
      96             :     {
      97           0 :         sAliasName += OUString('_');
      98           0 :         sAliasName += OUString::number(m_nAliasNum);
      99             :     }
     100             : 
     101           0 :     sAliasName = comphelper::string::remove(sAliasName, '"');
     102           0 :     SetAliasName(sAliasName);
     103             :         // SetAliasName passes it as WinName, hence it uses the base class
     104             :     // reset the title
     105           0 :     m_aTitle.SetText( pWinData->GetWinName() );
     106           0 :     m_aTitle.Show();
     107             : 
     108           0 :     getTableView()->getDesignView()->getController().InvalidateFeature(ID_BROWSER_QUERY_EXECUTE);
     109           0 :     return bSuccess;
     110             : }
     111             : 
     112           0 : void* OQueryTableWindow::createUserData(const Reference< XPropertySet>& _xColumn,bool _bPrimaryKey)
     113             : {
     114           0 :     OTableFieldInfo* pInfo = new OTableFieldInfo();
     115           0 :     pInfo->SetKey(_bPrimaryKey ? TAB_PRIMARY_FIELD : TAB_NORMAL_FIELD);
     116           0 :     if ( _xColumn.is() )
     117           0 :         pInfo->SetDataType(::comphelper::getINT32(_xColumn->getPropertyValue(PROPERTY_TYPE)));
     118           0 :     return pInfo;
     119             : }
     120             : 
     121           0 : void OQueryTableWindow::deleteUserData(void*& _pUserData)
     122             : {
     123           0 :     delete static_cast<OTableFieldInfo*>(_pUserData);
     124           0 :     _pUserData = NULL;
     125           0 : }
     126             : 
     127           0 : void OQueryTableWindow::OnEntryDoubleClicked(SvTreeListEntry* pEntry)
     128             : {
     129             :     OSL_ENSURE(pEntry != NULL, "OQueryTableWindow::OnEntryDoubleClicked : pEntry must not be NULL !");
     130             :         // you could also scan that and then return, but like this it could possibly hint to faults at the caller
     131             : 
     132           0 :     if (getTableView()->getDesignView()->getController().isReadOnly())
     133           0 :         return;
     134             : 
     135           0 :     OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData());
     136             :     OSL_ENSURE(pInf != NULL, "OQueryTableWindow::OnEntryDoubleClicked : field doesn't have FieldInfo !");
     137             : 
     138             :     // build up DragInfo
     139           0 :     OTableFieldDescRef aInfo = new OTableFieldDesc(GetTableName(),m_pListBox->GetEntryText(pEntry));
     140           0 :     aInfo->SetTabWindow(this);
     141           0 :     aInfo->SetAlias(GetAliasName());
     142           0 :     aInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry));
     143           0 :     aInfo->SetDataType(pInf->GetDataType());
     144             : 
     145             :     // and insert corresponding field
     146           0 :     static_cast<OQueryTableView*>(getTableView())->InsertField(aInfo);
     147             : }
     148             : 
     149           0 : bool OQueryTableWindow::ExistsField(const OUString& strFieldName, OTableFieldDescRef& rInfo)
     150             : {
     151             :     OSL_ENSURE(m_pListBox != NULL, "OQueryTableWindow::ExistsField : doesn't have ::com::sun::star::form::ListBox !");
     152             :     OSL_ENSURE(rInfo.is(),"OQueryTableWindow::ExistsField: invalid argument for OTableFieldDescRef!");
     153           0 :     Reference< XConnection> xConnection = getTableView()->getDesignView()->getController().getConnection();
     154           0 :     bool bExists = false;
     155           0 :     if(xConnection.is())
     156             :     {
     157           0 :         SvTreeListEntry* pEntry = m_pListBox->First();
     158             :         try
     159             :         {
     160           0 :             Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
     161           0 :             ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
     162             : 
     163           0 :             while (pEntry)
     164             :             {
     165           0 :                 if (bCase(strFieldName,OUString(m_pListBox->GetEntryText(pEntry))))
     166             :                 {
     167           0 :                     OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData());
     168             :                     assert(pInf && "OQueryTableWindow::ExistsField : field doesn't have FieldInfo !");
     169             : 
     170           0 :                     rInfo->SetTabWindow(this);
     171           0 :                     rInfo->SetField(strFieldName);
     172           0 :                     rInfo->SetTable(GetTableName());
     173           0 :                     rInfo->SetAlias(GetAliasName());
     174           0 :                     rInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry));
     175           0 :                     rInfo->SetDataType(pInf->GetDataType());
     176           0 :                     bExists = true;
     177           0 :                     break;
     178             :                 }
     179           0 :                 pEntry = m_pListBox->Next(pEntry);
     180           0 :             }
     181             :         }
     182           0 :         catch(SQLException&)
     183             :         {
     184             :         }
     185             :     }
     186             : 
     187           0 :     return bExists;
     188             : }
     189             : 
     190           0 : bool OQueryTableWindow::ExistsAVisitedConn() const
     191             : {
     192           0 :     return static_cast<const OQueryTableView*>(getTableView())->ExistsAVisitedConn(this);
     193             : }
     194             : 
     195           0 : void OQueryTableWindow::KeyInput( const KeyEvent& rEvt )
     196             : {
     197           0 :     OTableWindow::KeyInput( rEvt );
     198          72 : }
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10