LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - selectdbtabledialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 106 0.0 %
Date: 2014-11-03 Functions: 0 15 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/simptabl.hxx>
      24             : #include <svtools/treelistentry.hxx>
      25             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      26             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : #include <com/sun/star/beans/PropertyValue.hpp>
      29             : #include <com/sun/star/container/XChild.hpp>
      30             : #include <com/sun/star/sdbc/XDataSource.hpp>
      31             : 
      32             : #include <unomid.h>
      33             : 
      34             : #include <dbui.hrc>
      35             : #include <helpid.h>
      36             : #include <boost/scoped_ptr.hpp>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::sdbcx;
      40             : using namespace ::com::sun::star::sdbc;
      41             : using namespace ::com::sun::star::sdb;
      42             : using namespace ::com::sun::star::uno;
      43             : using namespace ::com::sun::star::container;
      44             : using namespace ::com::sun::star::beans;
      45             : 
      46           0 : class SwAddressTable : public SvSimpleTable
      47             : {
      48             : public:
      49             :     SwAddressTable(SvSimpleTableContainer& rParent, WinBits nBits = 0);
      50             :     void InsertHeaderItem(sal_uInt16 nColumn, const OUString& rText, HeaderBarItemBits nBits);
      51             :     virtual void Resize() SAL_OVERRIDE;
      52             :     void setColSizes();
      53             : };
      54             : 
      55           0 : SwAddressTable::SwAddressTable(SvSimpleTableContainer& rParent, WinBits nBits)
      56           0 :     : SvSimpleTable(rParent, nBits)
      57             : {
      58           0 :     SetSpaceBetweenEntries(3);
      59           0 :     SetSelectionMode(SINGLE_SELECTION);
      60           0 :     SetDragDropMode(0);
      61           0 :     EnableAsyncDrag(false);
      62           0 : }
      63             : 
      64           0 : void SwAddressTable::InsertHeaderItem(sal_uInt16 nColumn, const OUString& rText, HeaderBarItemBits nBits)
      65             : {
      66           0 :     GetTheHeaderBar().InsertItem( nColumn, rText, 0, nBits );
      67           0 : }
      68             : 
      69           0 : void SwAddressTable::Resize()
      70             : {
      71           0 :     SvSimpleTable::Resize();
      72           0 :     setColSizes();
      73           0 : }
      74             : 
      75           0 : void SwAddressTable::setColSizes()
      76             : {
      77           0 :     HeaderBar &rHB = GetTheHeaderBar();
      78           0 :     if (rHB.GetItemCount() < 2)
      79           0 :         return;
      80             : 
      81           0 :     long nWidth = rHB.GetSizePixel().Width();
      82           0 :     nWidth /= 2;
      83             : 
      84             :     long nTabs_Impl[3];
      85             : 
      86           0 :     nTabs_Impl[0] = 2;
      87           0 :     nTabs_Impl[1] = 0;
      88           0 :     nTabs_Impl[2] = nWidth;
      89             : 
      90           0 :     SvSimpleTable::SetTabs(&nTabs_Impl[0], MAP_PIXEL);
      91             : }
      92             : 
      93           0 : SwSelectDBTableDialog::SwSelectDBTableDialog(vcl::Window* pParent,
      94             :         const uno::Reference< sdbc::XConnection>& rConnection)
      95             :     : SfxModalDialog(pParent, "SelectTableDialog", "modules/swriter/ui/selecttabledialog.ui")
      96             :     , m_sName(SW_RES(ST_NAME))
      97             :     , m_sType(SW_RES(ST_TYPE))
      98             :     , m_sTable(SW_RES(ST_TABLE))
      99             :     , m_sQuery(SW_RES(ST_QUERY))
     100           0 :     , m_xConnection(rConnection)
     101             : {
     102           0 :     get(m_pPreviewPB, "preview");
     103             : 
     104           0 :     SvSimpleTableContainer *pHeaderTreeContainer = get<SvSimpleTableContainer>("table");
     105           0 :     Size aSize = pHeaderTreeContainer->LogicToPixel(Size(238 , 50), MAP_APPFONT);
     106           0 :     pHeaderTreeContainer->set_width_request(aSize.Width());
     107           0 :     pHeaderTreeContainer->set_height_request(aSize.Height());
     108           0 :     m_pTable = new SwAddressTable(*pHeaderTreeContainer);
     109           0 :     long aStaticTabs[]= { 2, 0, 0 };
     110           0 :     m_pTable->SetTabs( aStaticTabs );
     111           0 :     m_pTable->InsertHeaderItem(1, m_sName, HIB_LEFT | HIB_VCENTER);
     112           0 :     m_pTable->InsertHeaderItem(2, m_sType, HIB_LEFT | HIB_VCENTER);
     113             : 
     114           0 :     m_pPreviewPB->SetClickHdl(LINK(this, SwSelectDBTableDialog, PreviewHdl));
     115             : 
     116           0 :     Reference<XTablesSupplier> xTSupplier(m_xConnection, UNO_QUERY);
     117           0 :     if (xTSupplier.is())
     118             :     {
     119           0 :         Reference<XNameAccess> xTbls = xTSupplier->getTables();
     120           0 :         Sequence<OUString> aTbls = xTbls->getElementNames();
     121           0 :         const OUString* pTbls = aTbls.getConstArray();
     122           0 :         for(long i = 0; i < aTbls.getLength(); i++)
     123             :         {
     124           0 :             OUString sEntry = pTbls[i];
     125           0 :             sEntry += "\t";
     126           0 :             sEntry += m_sTable;
     127           0 :             SvTreeListEntry* pEntry = m_pTable->InsertEntry(sEntry);
     128           0 :             pEntry->SetUserData((void*)0);
     129           0 :         }
     130             :     }
     131           0 :     Reference<XQueriesSupplier> xQSupplier(m_xConnection, UNO_QUERY);
     132           0 :     if (xQSupplier.is())
     133             :     {
     134           0 :         Reference<XNameAccess> xQueries = xQSupplier->getQueries();
     135           0 :         Sequence<OUString> aQueries = xQueries->getElementNames();
     136           0 :         const OUString* pQueries = aQueries.getConstArray();
     137           0 :         for(long i = 0; i < aQueries.getLength(); i++)
     138             :         {
     139           0 :             OUString sEntry = pQueries[i];
     140           0 :             sEntry += "\t";
     141           0 :             sEntry += m_sQuery;
     142           0 :             SvTreeListEntry* pEntry = m_pTable->InsertEntry(sEntry);
     143           0 :             pEntry->SetUserData((void*)1);
     144           0 :         }
     145           0 :     }
     146           0 : }
     147             : 
     148           0 : SwSelectDBTableDialog::~SwSelectDBTableDialog()
     149             : {
     150           0 :     delete m_pTable;
     151           0 : }
     152             : 
     153           0 : IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, PushButton*, pButton)
     154             : {
     155           0 :     SvTreeListEntry* pEntry = m_pTable->FirstSelected();
     156           0 :     if(pEntry)
     157             :     {
     158           0 :         OUString sTableOrQuery = m_pTable->GetEntryText(pEntry, 0);
     159           0 :         sal_Int32 nCommandType = 0 == pEntry->GetUserData() ? 0 : 1;
     160             : 
     161           0 :         OUString sDataSourceName;
     162           0 :         Reference<XChild> xChild(m_xConnection, UNO_QUERY);
     163           0 :         if(xChild.is())
     164             :         {
     165           0 :             Reference<XDataSource> xSource(xChild->getParent(), UNO_QUERY);
     166           0 :             Reference<XPropertySet> xPrSet(xSource, UNO_QUERY);
     167           0 :             xPrSet->getPropertyValue("Name") >>= sDataSourceName;
     168             :         }
     169             :         OSL_ENSURE(!sDataSourceName.isEmpty(), "no data source found");
     170           0 :         Sequence<PropertyValue> aProperties(5);
     171           0 :         PropertyValue* pProperties = aProperties.getArray();
     172           0 :         pProperties[0].Name = "DataSourceName";
     173           0 :         pProperties[0].Value <<= sDataSourceName;
     174           0 :         pProperties[1].Name = "Command";
     175           0 :         pProperties[1].Value <<= sTableOrQuery;
     176           0 :         pProperties[2].Name = "CommandType";
     177           0 :         pProperties[2].Value <<= nCommandType;
     178           0 :         pProperties[3].Name = "ShowTreeView";
     179           0 :         pProperties[3].Value <<= sal_False;
     180           0 :         pProperties[4].Name = "ShowTreeViewButton";
     181           0 :         pProperties[4].Value <<= sal_False;
     182             : 
     183           0 :         boost::scoped_ptr<SwDBTablePreviewDialog> pDlg(new SwDBTablePreviewDialog(pButton, aProperties));
     184           0 :         pDlg->Execute();
     185             :     }
     186             : 
     187           0 :     return 0;
     188             : }
     189             : 
     190           0 : OUString    SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable)
     191             : {
     192           0 :     SvTreeListEntry* pEntry = m_pTable->FirstSelected();
     193           0 :     bIsTable = pEntry->GetUserData() ? false : true;
     194           0 :     return m_pTable->GetEntryText(pEntry, 0);
     195             : }
     196             : 
     197           0 : void   SwSelectDBTableDialog::SetSelectedTable(const OUString& rTable, bool bIsTable)
     198             : {
     199           0 :     SvTreeListEntry*    pEntry = m_pTable->First();
     200           0 :     while(pEntry)
     201             :     {
     202           0 :         if((m_pTable->GetEntryText(pEntry, 0) == rTable) &&
     203           0 :                  ((pEntry->GetUserData() == 0 ) == bIsTable))
     204             :         {
     205           0 :             m_pTable->Select(pEntry);
     206           0 :             break;
     207             :         }
     208           0 :         pEntry = m_pTable->Next( pEntry );
     209             :     }
     210           0 : }
     211             : 
     212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10