LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/dbui - selectdbtabledialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 97 0.0 %
Date: 2013-07-09 Functions: 0 9 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 <swtypes.hxx>
      21             : #include <selectdbtabledialog.hxx>
      22             : #include <dbtablepreviewdialog.hxx>
      23             : #include "svtools/treelistentry.hxx"
      24             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      25             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/beans/PropertyValue.hpp>
      28             : #include <com/sun/star/container/XChild.hpp>
      29             : #include <com/sun/star/sdbc/XDataSource.hpp>
      30             : 
      31             : #include <unomid.h>
      32             : 
      33             : #include <selectdbtabledialog.hrc>
      34             : #include <dbui.hrc>
      35             : #include <helpid.h>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::sdbcx;
      39             : using namespace ::com::sun::star::sdbc;
      40             : using namespace ::com::sun::star::sdb;
      41             : using namespace ::com::sun::star::uno;
      42             : using namespace ::com::sun::star::container;
      43             : using namespace ::com::sun::star::beans;
      44             : 
      45           0 : SwSelectDBTableDialog::SwSelectDBTableDialog(Window* pParent,
      46             :         const uno::Reference< sdbc::XConnection>& rConnection) :
      47             :     SfxModalDialog(pParent, SW_RES(DLG_MM_SELECTDBTABLEDDIALOG)),
      48             : #ifdef _MSC_VER
      49             : #pragma warning (disable : 4355)
      50             : #endif
      51             :     m_aSelectFI( this, SW_RES(       FI_SELECT     )),
      52             :     m_aTableHB( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
      53             :     m_aTableLB( this, SW_RES(        LB_TABLE      )),
      54             :     m_aPreviewPB( this, SW_RES(      PB_PREVIEW    )),
      55             :     m_aSeparatorFL(this, SW_RES(    FL_SEPARATOR      )),
      56             :     m_aOK( this, SW_RES(             PB_OK         )),
      57             :     m_aCancel( this, SW_RES(         PB_CANCEL     )),
      58             :     m_aHelp( this, SW_RES(           PB_HELP       )),
      59             : #ifdef _MSC_VER
      60             : #pragma warning (default : 4355)
      61             : #endif
      62             :     m_sName( SW_RES( ST_NAME )),
      63             :     m_sType( SW_RES( ST_TYPE )),
      64             :     m_sTable( SW_RES( ST_TABLE )),
      65             :     m_sQuery( SW_RES( ST_QUERY )),
      66           0 :     m_xConnection(rConnection)
      67             : {
      68           0 :     FreeResource();
      69             : 
      70           0 :     Size aLBSize(m_aTableLB.GetSizePixel());
      71           0 :     m_aTableHB.SetSizePixel(aLBSize);
      72           0 :     Size aHeadSize(m_aTableHB.CalcWindowSizePixel());
      73           0 :     aHeadSize.Width() = aLBSize.Width();
      74           0 :     m_aTableHB.SetSizePixel(aHeadSize);
      75           0 :     Point aLBPos(m_aTableLB.GetPosPixel());
      76           0 :     m_aTableHB.SetPosPixel(aLBPos);
      77           0 :     aLBPos.Y() += aHeadSize.Height();
      78           0 :     aLBSize.Height() -= aHeadSize.Height();
      79           0 :     m_aTableLB.SetPosSizePixel(aLBPos, aLBSize);
      80             : 
      81           0 :     Size aSz(m_aTableHB.GetOutputSizePixel());
      82             :     m_aTableHB.InsertItem( 1, m_sName,
      83           0 :                             aSz.Width()/2,
      84           0 :                             HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
      85             :     m_aTableHB.InsertItem( 2, m_sType,
      86           0 :                             aSz.Width()/2,
      87           0 :                             HIB_LEFT | HIB_VCENTER /*| HIB_CLICKABLE | HIB_UPARROW */);
      88           0 :     m_aTableHB.SetHelpId(HID_MM_ADDRESSLIST_HB );
      89           0 :     m_aTableHB.Show();
      90             : 
      91           0 :     static long nTabs[] = {3, 0, aSz.Width()/2, aSz.Width() };
      92           0 :     m_aTableLB.SetTabs(&nTabs[0], MAP_PIXEL);
      93           0 :     m_aTableLB.SetHelpId(HID_MM_SELECTDBTABLEDDIALOG_LISTBOX);
      94           0 :     m_aTableLB.SetStyle( m_aTableLB.GetStyle() | WB_CLIPCHILDREN );
      95           0 :     m_aTableLB.SetSpaceBetweenEntries(3);
      96           0 :     m_aTableLB.SetSelectionMode( SINGLE_SELECTION );
      97           0 :     m_aTableLB.SetDragDropMode(   0 );
      98           0 :     m_aTableLB.EnableAsyncDrag(sal_False);
      99             : 
     100           0 :     m_aPreviewPB.SetClickHdl(LINK(this, SwSelectDBTableDialog, PreviewHdl));
     101             : 
     102           0 :     Reference<XTablesSupplier> xTSupplier(m_xConnection, UNO_QUERY);
     103           0 :     if(xTSupplier.is())
     104             :     {
     105           0 :         Reference<XNameAccess> xTbls = xTSupplier->getTables();
     106           0 :         Sequence<OUString> aTbls = xTbls->getElementNames();
     107           0 :         const OUString* pTbls = aTbls.getConstArray();
     108           0 :         for(long i = 0; i < aTbls.getLength(); i++)
     109             :         {
     110           0 :             String sEntry = pTbls[i];
     111           0 :             sEntry += '\t';
     112           0 :             sEntry += m_sTable;
     113           0 :             SvTreeListEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
     114           0 :             pEntry->SetUserData((void*)0);
     115           0 :         }
     116             :     }
     117           0 :     Reference<XQueriesSupplier> xQSupplier(m_xConnection, UNO_QUERY);
     118           0 :     if(xQSupplier.is())
     119             :     {
     120           0 :         Reference<XNameAccess> xQueries = xQSupplier->getQueries();
     121           0 :         Sequence<OUString> aQueries = xQueries->getElementNames();
     122           0 :         const OUString* pQueries = aQueries.getConstArray();
     123           0 :         for(long i = 0; i < aQueries.getLength(); i++)
     124             :         {
     125           0 :             String sEntry = pQueries[i];
     126           0 :             sEntry += '\t';
     127           0 :             sEntry += m_sQuery;
     128           0 :             SvTreeListEntry* pEntry = m_aTableLB.InsertEntry(sEntry);
     129           0 :             pEntry->SetUserData((void*)1);
     130           0 :         }
     131           0 :     }
     132           0 : }
     133             : 
     134           0 : SwSelectDBTableDialog::~SwSelectDBTableDialog()
     135             : {
     136           0 : }
     137             : 
     138           0 : IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, PushButton*, pButton)
     139             : {
     140           0 :     SvTreeListEntry* pEntry = m_aTableLB.FirstSelected();
     141           0 :     if(pEntry)
     142             :     {
     143           0 :         OUString sTableOrQuery = m_aTableLB.GetEntryText(pEntry, 0);
     144           0 :         sal_Int32 nCommandType = 0 == pEntry->GetUserData() ? 0 : 1;
     145             : 
     146           0 :         OUString sDataSourceName;
     147           0 :         Reference<XChild> xChild(m_xConnection, UNO_QUERY);
     148           0 :         if(xChild.is())
     149             :         {
     150           0 :             Reference<XDataSource> xSource(xChild->getParent(), UNO_QUERY);
     151           0 :             Reference<XPropertySet> xPrSet(xSource, UNO_QUERY);
     152           0 :             xPrSet->getPropertyValue("Name") >>= sDataSourceName;
     153             :         }
     154             :         OSL_ENSURE(!sDataSourceName.isEmpty(), "no data source found");
     155           0 :         Sequence<PropertyValue> aProperties(5);
     156           0 :         PropertyValue* pProperties = aProperties.getArray();
     157           0 :         pProperties[0].Name = "DataSourceName";
     158           0 :         pProperties[0].Value <<= sDataSourceName;
     159           0 :         pProperties[1].Name = "Command";
     160           0 :         pProperties[1].Value <<= sTableOrQuery;
     161           0 :         pProperties[2].Name = "CommandType";
     162           0 :         pProperties[2].Value <<= nCommandType;
     163           0 :         pProperties[3].Name = "ShowTreeView";
     164           0 :         pProperties[3].Value <<= sal_False;
     165           0 :         pProperties[4].Name = "ShowTreeViewButton";
     166           0 :         pProperties[4].Value <<= sal_False;
     167             : 
     168           0 :         SwDBTablePreviewDialog* pDlg = new SwDBTablePreviewDialog(pButton, aProperties);
     169           0 :         pDlg->Execute();
     170           0 :         delete pDlg;
     171             :     }
     172             : 
     173           0 :     return 0;
     174             : }
     175             : 
     176           0 : String      SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable)
     177             : {
     178           0 :     SvTreeListEntry* pEntry = m_aTableLB.FirstSelected();
     179           0 :     bIsTable = pEntry->GetUserData() ? false : true;
     180           0 :     return pEntry ? m_aTableLB.GetEntryText(pEntry, 0) : String();
     181             : }
     182             : 
     183           0 : void   SwSelectDBTableDialog::SetSelectedTable(const String& rTable, bool bIsTable)
     184             : {
     185           0 :     SvTreeListEntry*    pEntry = m_aTableLB.First();
     186           0 :     while(pEntry)
     187             :     {
     188           0 :         if((m_aTableLB.GetEntryText(pEntry, 0) == rTable) &&
     189           0 :                  ((pEntry->GetUserData() == 0 ) == bIsTable))
     190             :         {
     191           0 :             m_aTableLB.Select(pEntry);
     192           0 :             break;
     193             :         }
     194           0 :         pEntry = m_aTableLB.Next( pEntry );
     195             :     }
     196           0 : }
     197             : 
     198             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10