LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - selectdbtabledialog.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 111 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 16 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(DragDropMode::NONE);
      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 = VclPtr<SwAddressTable>::Create(*pHeaderTreeContainer);
     109           0 :     long aStaticTabs[]= { 2, 0, 0 };
     110           0 :     m_pTable->SetTabs( aStaticTabs );
     111           0 :     m_pTable->InsertHeaderItem(1, m_sName, HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER);
     112           0 :     m_pTable->InsertHeaderItem(2, m_sType, HeaderBarItemBits::LEFT | HeaderBarItemBits::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> xTables = xTSupplier->getTables();
     120           0 :         Sequence<OUString> aTables = xTables->getElementNames();
     121           0 :         const OUString* pTables = aTables.getConstArray();
     122           0 :         for(long i = 0; i < aTables.getLength(); i++)
     123             :         {
     124           0 :             OUString sEntry = pTables[i];
     125           0 :             sEntry += "\t";
     126           0 :             sEntry += m_sTable;
     127           0 :             SvTreeListEntry* pEntry = m_pTable->InsertEntry(sEntry);
     128           0 :             pEntry->SetUserData(nullptr);
     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(reinterpret_cast<void*>(1));
     144           0 :         }
     145           0 :     }
     146           0 : }
     147             : 
     148           0 : SwSelectDBTableDialog::~SwSelectDBTableDialog()
     149             : {
     150           0 :     disposeOnce();
     151           0 : }
     152             : 
     153           0 : void SwSelectDBTableDialog::dispose()
     154             : {
     155           0 :     m_pTable.disposeAndClear();
     156           0 :     m_pPreviewPB.clear();
     157           0 :     SfxModalDialog::dispose();
     158           0 : }
     159             : 
     160           0 : IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, PushButton*, pButton)
     161             : {
     162           0 :     SvTreeListEntry* pEntry = m_pTable->FirstSelected();
     163           0 :     if(pEntry)
     164             :     {
     165           0 :         OUString sTableOrQuery = SvTabListBox::GetEntryText(pEntry, 0);
     166           0 :         sal_Int32 nCommandType = 0 == pEntry->GetUserData() ? 0 : 1;
     167             : 
     168           0 :         OUString sDataSourceName;
     169           0 :         Reference<XChild> xChild(m_xConnection, UNO_QUERY);
     170           0 :         if(xChild.is())
     171             :         {
     172           0 :             Reference<XDataSource> xSource(xChild->getParent(), UNO_QUERY);
     173           0 :             Reference<XPropertySet> xPrSet(xSource, UNO_QUERY);
     174           0 :             xPrSet->getPropertyValue("Name") >>= sDataSourceName;
     175             :         }
     176             :         OSL_ENSURE(!sDataSourceName.isEmpty(), "no data source found");
     177           0 :         Sequence<PropertyValue> aProperties(5);
     178           0 :         PropertyValue* pProperties = aProperties.getArray();
     179           0 :         pProperties[0].Name = "DataSourceName";
     180           0 :         pProperties[0].Value <<= sDataSourceName;
     181           0 :         pProperties[1].Name = "Command";
     182           0 :         pProperties[1].Value <<= sTableOrQuery;
     183           0 :         pProperties[2].Name = "CommandType";
     184           0 :         pProperties[2].Value <<= nCommandType;
     185           0 :         pProperties[3].Name = "ShowTreeView";
     186           0 :         pProperties[3].Value <<= sal_False;
     187           0 :         pProperties[4].Name = "ShowTreeViewButton";
     188           0 :         pProperties[4].Value <<= sal_False;
     189             : 
     190           0 :         VclPtrInstance< SwDBTablePreviewDialog > pDlg(pButton, aProperties);
     191           0 :         pDlg->Execute();
     192             :     }
     193             : 
     194           0 :     return 0;
     195             : }
     196             : 
     197           0 : OUString    SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable)
     198             : {
     199           0 :     SvTreeListEntry* pEntry = m_pTable->FirstSelected();
     200           0 :     bIsTable = pEntry->GetUserData() == nullptr;
     201           0 :     return SvTabListBox::GetEntryText(pEntry, 0);
     202             : }
     203             : 
     204           0 : void   SwSelectDBTableDialog::SetSelectedTable(const OUString& rTable, bool bIsTable)
     205             : {
     206           0 :     SvTreeListEntry*    pEntry = m_pTable->First();
     207           0 :     while(pEntry)
     208             :     {
     209           0 :         if((SvTabListBox::GetEntryText(pEntry, 0) == rTable) &&
     210           0 :            ((pEntry->GetUserData() == 0 ) == bIsTable))
     211             :         {
     212           0 :             m_pTable->Select(pEntry);
     213           0 :             break;
     214             :         }
     215           0 :         pEntry = m_pTable->Next( pEntry );
     216             :     }
     217           0 : }
     218             : 
     219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11