LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - CollectionView.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 140 0.7 %
Date: 2014-11-03 Functions: 2 15 13.3 %
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 "CollectionView.hxx"
      21             : #include <tools/debug.hxx>
      22             : #include <tools/diagnose_ex.h>
      23             : #include "moduledbu.hxx"
      24             : #include "dbu_dlg.hrc"
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <comphelper/interaction.hxx>
      27             : #include <cppuhelper/exc_hlp.hxx>
      28             : #include <toolkit/helper/vclunohelper.hxx>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/container/XChild.hpp>
      31             : #include <com/sun/star/container/XNameContainer.hpp>
      32             : #include <com/sun/star/beans/PropertyValue.hpp>
      33             : #include <vcl/msgbox.hxx>
      34             : #include "dbustrings.hrc"
      35             : #include "UITools.hxx"
      36             : #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
      37             : #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
      38             : #include <com/sun/star/ucb/IOErrorCode.hpp>
      39             : #include <com/sun/star/task/InteractionHandler.hpp>
      40             : #include <com/sun/star/task/InteractionClassification.hpp>
      41             : #include <com/sun/star/sdbc/SQLException.hpp>
      42             : #include <com/sun/star/awt/XWindow.hpp>
      43             : #include <unotools/viewoptions.hxx>
      44             : #include <osl/thread.h>
      45             : #include <connectivity/dbexception.hxx>
      46             : 
      47             : namespace dbaui
      48             : {
      49             : 
      50             : using namespace ::com::sun::star::uno;
      51             : using namespace ::com::sun::star::ucb;
      52             : using namespace ::com::sun::star::lang;
      53             : using namespace ::com::sun::star::beans;
      54             : using namespace ::com::sun::star::container;
      55             : using namespace ::com::sun::star::task;
      56             : using namespace ::com::sun::star::sdbc;
      57             : using namespace comphelper;
      58           0 : OCollectionView::OCollectionView( vcl::Window * pParent
      59             :                                  ,const Reference< XContent>& _xContent
      60             :                                  ,const OUString& _sDefaultName
      61             :                                  ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
      62             :     : ModalDialog( pParent, "CollectionView", "dbaccess/ui/collectionviewdialog.ui")
      63             :     , m_xContent(_xContent)
      64             :     , m_xContext(_rxContext)
      65           0 :     , m_bCreateForm(true)
      66             : {
      67           0 :     get(m_pFTCurrentPath, "currentPathLabel");
      68           0 :     get(m_pNewFolder, "newFolderButton");
      69           0 :     get(m_pUp, "upButton");
      70           0 :     get(m_pView, "viewTreeview");
      71           0 :     get(m_pName, "fileNameEntry");
      72           0 :     get(m_pPB_OK, "ok");
      73             : 
      74             :     OSL_ENSURE(m_xContent.is(),"No valid content!");
      75           0 :     m_pView->Initialize(m_xContent,OUString());
      76           0 :     m_pFTCurrentPath->SetStyle( m_pFTCurrentPath->GetStyle() | WB_PATHELLIPSIS );
      77           0 :     initCurrentPath();
      78             : 
      79           0 :     m_pName->SetText(_sDefaultName);
      80           0 :     m_pName->GrabFocus();
      81             : 
      82           0 :     m_pNewFolder->SetStyle( m_pNewFolder->GetStyle() | WB_NOPOINTERFOCUS );
      83           0 :     m_pUp->SetModeImage(Image(ModuleRes(IMG_NAVIGATION_BTN_UP_SC)));
      84           0 :     m_pNewFolder->SetModeImage(Image(ModuleRes(IMG_NAVIGATION_CREATEFOLDER_SC)));
      85             : 
      86           0 :     m_pView->SetDoubleClickHdl( LINK( this, OCollectionView, Dbl_Click_FileView ) );
      87           0 :     m_pView->EnableAutoResize();
      88           0 :     m_pView->EnableDelete(true);
      89           0 :     m_pUp->SetClickHdl( LINK( this, OCollectionView, Up_Click ) );
      90           0 :     m_pNewFolder->SetClickHdl( LINK( this, OCollectionView, NewFolder_Click ) );
      91           0 :     m_pPB_OK->SetClickHdl( LINK( this, OCollectionView, Save_Click ) );
      92           0 : }
      93             : 
      94           0 : OCollectionView::~OCollectionView( )
      95             : {
      96           0 : }
      97             : 
      98             : 
      99           0 : IMPL_LINK_NOARG(OCollectionView, Save_Click)
     100             : {
     101           0 :     OUString sName = m_pName->GetText();
     102           0 :     if ( sName.isEmpty() )
     103           0 :         return 0;
     104             :     try
     105             :     {
     106           0 :         OUString sSubFolder = m_pView->GetCurrentURL();
     107           0 :         sal_Int32 nIndex = sName.lastIndexOf('/') + 1;
     108           0 :         if ( nIndex )
     109             :         {
     110           0 :             if ( nIndex == 1 ) // special handling for root
     111             :             {
     112           0 :                 Reference<XChild> xChild(m_xContent,UNO_QUERY);
     113           0 :                 Reference<XNameAccess> xNameAccess(xChild,UNO_QUERY);
     114           0 :                 while( xNameAccess.is() )
     115             :                 {
     116           0 :                     xNameAccess.set(xChild->getParent(),UNO_QUERY);
     117           0 :                     if ( xNameAccess.is() )
     118             :                     {
     119           0 :                         m_xContent.set(xNameAccess,UNO_QUERY);
     120           0 :                         xChild.set(m_xContent,UNO_QUERY);
     121             :                     }
     122             :                 }
     123           0 :                 m_pView->Initialize(m_xContent,OUString());
     124           0 :                 initCurrentPath();
     125             :             }
     126           0 :             sSubFolder = sName.copy(0,nIndex-1);
     127           0 :             sName = sName.copy(nIndex);
     128           0 :             Reference<XHierarchicalNameContainer> xHier(m_xContent,UNO_QUERY);
     129             :             OSL_ENSURE(xHier.is(),"XHierarchicalNameContainer not supported!");
     130           0 :             if ( !sSubFolder.isEmpty() && xHier.is() )
     131             :             {
     132           0 :                 if ( xHier->hasByHierarchicalName(sSubFolder) )
     133             :                 {
     134           0 :                     m_xContent.set(xHier->getByHierarchicalName(sSubFolder),UNO_QUERY);
     135             :                 }
     136             :                 else // sub folder doesn't exist
     137             :                 {
     138           0 :                     Sequence< Any > aValues(2);
     139           0 :                     PropertyValue aValue;
     140           0 :                     aValue.Name = "ResourceName";
     141           0 :                     aValue.Value <<= sSubFolder;
     142           0 :                     aValues[0] <<= aValue;
     143             : 
     144           0 :                     aValue.Name = "ResourceType";
     145           0 :                     aValue.Value <<= OUString("folder");
     146           0 :                     aValues[1] <<= aValue;
     147             : 
     148           0 :                     InteractionClassification eClass = InteractionClassification_ERROR;
     149           0 :                     ::com::sun::star::ucb::IOErrorCode eError = IOErrorCode_NOT_EXISTING_PATH;
     150           0 :                     OUString sTemp;
     151           0 :                     InteractiveAugmentedIOException aException(sTemp,Reference<XInterface>(),eClass,eError,aValues);
     152             : 
     153             :                     Reference<XInteractionHandler2> xHandler(
     154           0 :                         InteractionHandler::createWithParent(m_xContext, VCLUnoHelper::GetInterface( this )));
     155           0 :                     OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aException));
     156           0 :                     Reference< XInteractionRequest > xRequest(pRequest);
     157             : 
     158           0 :                     OInteractionApprove* pApprove = new OInteractionApprove;
     159           0 :                     pRequest->addContinuation(pApprove);
     160           0 :                     xHandler->handle(xRequest);
     161             : 
     162           0 :                     return 0;
     163             :                 }
     164           0 :             }
     165             :         }
     166           0 :         Reference<XNameContainer> xNameContainer(m_xContent,UNO_QUERY);
     167           0 :         if ( xNameContainer.is() )
     168             :         {
     169           0 :             Reference< XContent> xContent;
     170           0 :             if ( xNameContainer->hasByName(sName) )
     171             :             {
     172           0 :                 QueryBox aBox( this, WB_YES_NO, ModuleRes( STR_ALREADYEXISTOVERWRITE ) );
     173           0 :                 if ( aBox.Execute() != RET_YES )
     174           0 :                     return 0;
     175             :             }
     176           0 :             m_pName->SetText(sName);
     177           0 :             EndDialog( sal_True );
     178           0 :         }
     179             :     }
     180           0 :     catch( const Exception& )
     181             :     {
     182             :         DBG_UNHANDLED_EXCEPTION();
     183             :     }
     184           0 :     return 0;
     185             : }
     186             : 
     187           0 : IMPL_LINK_NOARG(OCollectionView, NewFolder_Click)
     188             : {
     189             :     try
     190             :     {
     191           0 :         Reference<XHierarchicalNameContainer> xNameContainer(m_xContent,UNO_QUERY);
     192           0 :         if ( dbaui::insertHierachyElement(this,m_xContext,xNameContainer,OUString(),m_bCreateForm) )
     193           0 :             m_pView->Initialize(m_xContent,OUString());
     194             :     }
     195           0 :     catch( const SQLException& )
     196             :     {
     197           0 :         showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), this, m_xContext );
     198             :     }
     199           0 :     catch( const Exception& )
     200             :     {
     201             :         DBG_UNHANDLED_EXCEPTION();
     202             :     }
     203           0 :     return 0;
     204             : }
     205             : 
     206           0 : IMPL_LINK_NOARG(OCollectionView, Up_Click)
     207             : {
     208             :     try
     209             :     {
     210           0 :         Reference<XChild> xChild(m_xContent,UNO_QUERY);
     211           0 :         if ( xChild.is() )
     212             :         {
     213           0 :             Reference<XNameAccess> xNameAccess(xChild->getParent(),UNO_QUERY);
     214           0 :             if ( xNameAccess.is() )
     215             :             {
     216           0 :                 m_xContent.set(xNameAccess,UNO_QUERY);
     217           0 :                 m_pView->Initialize(m_xContent,OUString());
     218           0 :                 initCurrentPath();
     219             :             }
     220             :             else
     221           0 :                 m_pUp->Disable();
     222           0 :         }
     223             :     }
     224           0 :     catch( const Exception& )
     225             :     {
     226             :         DBG_UNHANDLED_EXCEPTION();
     227             :     }
     228           0 :     return 0;
     229             : }
     230             : 
     231           0 : IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView)
     232             : {
     233             :     try
     234             :     {
     235           0 :         Reference<XNameAccess> xNameAccess(m_xContent,UNO_QUERY);
     236           0 :         if ( xNameAccess.is() )
     237             :         {
     238           0 :             OUString sSubFolder = m_pView->GetCurrentURL();
     239           0 :             sal_Int32 nIndex = sSubFolder.lastIndexOf('/') + 1;
     240           0 :             sSubFolder = sSubFolder.getToken(0,'/',nIndex);
     241           0 :             if ( !sSubFolder.isEmpty() )
     242             :             {
     243           0 :                 Reference< XContent> xContent;
     244           0 :                 if ( xNameAccess->hasByName(sSubFolder) )
     245           0 :                     xContent.set(xNameAccess->getByName(sSubFolder),UNO_QUERY);
     246           0 :                 if ( xContent.is() )
     247             :                 {
     248           0 :                     m_xContent = xContent;
     249           0 :                     m_pView->Initialize(m_xContent,OUString());
     250           0 :                     initCurrentPath();
     251           0 :                 }
     252           0 :             }
     253           0 :         }
     254             :     }
     255           0 :     catch( const Exception& )
     256             :     {
     257             :         DBG_UNHANDLED_EXCEPTION();
     258             :     }
     259           0 :     return 0;
     260             : }
     261             : 
     262           0 : void OCollectionView::initCurrentPath()
     263             : {
     264           0 :     bool bEnable = false;
     265             :     try
     266             :     {
     267           0 :         if ( m_xContent.is() )
     268             :         {
     269           0 :             const OUString sCID = m_xContent->getIdentifier()->getContentIdentifier();
     270           0 :             const static OUString s_sFormsCID("private:forms");
     271           0 :             const static OUString s_sReportsCID("private:reports");
     272           0 :             m_bCreateForm = s_sFormsCID == sCID ;
     273           0 :             OUString sPath("/");
     274           0 :             if ( m_bCreateForm && sCID.getLength() != s_sFormsCID.getLength())
     275           0 :                 sPath = sCID.copy(s_sFormsCID.getLength());
     276           0 :             else if ( !m_bCreateForm && sCID.getLength() != s_sReportsCID.getLength() )
     277           0 :                 sPath = sCID.copy(s_sReportsCID.getLength() - 2);
     278             : 
     279           0 :             m_pFTCurrentPath->SetText(sPath);
     280           0 :             Reference<XChild> xChild(m_xContent,UNO_QUERY);
     281           0 :             bEnable = xChild.is() && Reference<XNameAccess>(xChild->getParent(),UNO_QUERY).is();
     282             :         }
     283             :     }
     284           0 :     catch( const Exception& )
     285             :     {
     286             :         DBG_UNHANDLED_EXCEPTION();
     287             :     }
     288           0 :     m_pUp->Enable(bEnable);
     289           0 : }
     290             : 
     291           0 : OUString OCollectionView::getName() const
     292             : {
     293           0 :     return m_pName->GetText();
     294             : }
     295             : 
     296          72 : }   // namespace dbaui
     297             : 
     298             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10