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

Generated by: LCOV version 1.10