Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / dlg / CollectionView.cxx
blob432ea32561e24bcee6bbf52e19fda77272132567
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "CollectionView.hxx"
30 #include "CollectionView.hrc"
31 #include <tools/debug.hxx>
32 #include <tools/diagnose_ex.h>
33 #include "moduledbu.hxx"
34 #include "dbu_dlg.hrc"
35 #include <comphelper/interaction.hxx>
36 #include <cppuhelper/exc_hlp.hxx>
37 #include <toolkit/helper/vclunohelper.hxx>
38 #include <svtools/QueryFolderName.hxx>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/lang/XInitialization.hpp>
41 #include <com/sun/star/container/XChild.hpp>
42 #include <com/sun/star/container/XNameContainer.hpp>
43 #include <com/sun/star/beans/PropertyValue.hpp>
44 #include <vcl/msgbox.hxx>
45 #include "dbustrings.hrc"
46 #include "UITools.hxx"
47 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
48 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
49 #include <com/sun/star/ucb/IOErrorCode.hpp>
50 #include <com/sun/star/task/XInteractionHandler.hpp>
51 #include <com/sun/star/task/InteractionClassification.hpp>
52 #include <com/sun/star/sdbc/SQLException.hpp>
53 #include <com/sun/star/awt/XWindow.hpp>
54 #include <unotools/viewoptions.hxx>
55 #include <osl/thread.h>
56 #include <connectivity/dbexception.hxx>
58 #define FILEDIALOG_DEF_IMAGEBORDER 10
59 //.........................................................................
60 namespace dbaui
62 //.........................................................................
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::ucb;
66 using namespace ::com::sun::star::lang;
67 using namespace ::com::sun::star::beans;
68 using namespace ::com::sun::star::container;
69 using namespace ::com::sun::star::ucb;
70 using namespace ::com::sun::star::task;
71 using namespace ::com::sun::star::sdbc;
72 using namespace comphelper;
73 // -----------------------------------------------------------------------------
74 DBG_NAME(OCollectionView)
75 OCollectionView::OCollectionView( Window * pParent
76 ,const Reference< XContent>& _xContent
77 ,const ::rtl::OUString& _sDefaultName
78 ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB)
79 : ModalDialog( pParent, ModuleRes(DLG_COLLECTION_VIEW))
80 , m_aFTCurrentPath( this, ModuleRes( FT_EXPLORERFILE_CURRENTPATH ) )
81 , m_aNewFolder( this, ModuleRes( BTN_EXPLORERFILE_NEWFOLDER ) )
82 , m_aUp( this, ModuleRes( BTN_EXPLORERFILE_UP ) )
83 , m_aView( this, ModuleRes( CTRL_VIEW ), FILEVIEW_SHOW_ONLYTITLE )
84 , m_aFTName( this, ModuleRes( FT_EXPLORERFILE_FILENAME ) )
85 , m_aName( this, ModuleRes( ED_EXPLORERFILE_FILENAME ) )
86 , m_aFL( this, ModuleRes( FL_1 ) )
87 , m_aPB_OK( this, ModuleRes( BTN_EXPLORERFILE_SAVE ) )
88 , m_aPB_CANCEL( this, ModuleRes( PB_CANCEL ) )
89 , m_aPB_HELP( this, ModuleRes( PB_HELP ) )
90 , m_sPath( ModuleRes( STR_PATHNAME ) )
91 , m_xContent(_xContent)
92 , m_xORB(_xORB)
93 , m_bCreateForm(sal_True)
95 DBG_CTOR(OCollectionView,NULL);
96 FreeResource();
98 OSL_ENSURE(m_xContent.is(),"No valid content!");
99 m_aView.Initialize(m_xContent,String());
100 m_aFTCurrentPath.SetStyle( m_aFTCurrentPath.GetStyle() | WB_PATHELLIPSIS );
101 initCurrentPath();
103 m_aName.SetText(_sDefaultName);
104 m_aName.GrabFocus();
106 m_aNewFolder.SetStyle( m_aNewFolder.GetStyle() | WB_NOPOINTERFOCUS );
107 m_aUp.SetModeImage(ModuleRes(IMG_NAVIGATION_BTN_UP_SC));
108 m_aNewFolder.SetModeImage(ModuleRes(IMG_NAVIGATION_CREATEFOLDER_SC));
110 m_aView.SetDoubleClickHdl( LINK( this, OCollectionView, Dbl_Click_FileView ) );
111 m_aView.EnableAutoResize();
112 m_aUp.SetClickHdl( LINK( this, OCollectionView, Up_Click ) );
113 m_aNewFolder.SetClickHdl( LINK( this, OCollectionView, NewFolder_Click ) );
114 m_aPB_OK.SetClickHdl( LINK( this, OCollectionView, Save_Click ) );
116 // -----------------------------------------------------------------------------
117 OCollectionView::~OCollectionView( )
119 DBG_DTOR(OCollectionView,NULL);
121 // -----------------------------------------------------------------------------
122 Reference< XContent> OCollectionView::getSelectedFolder() const
124 return m_xContent;
126 // -----------------------------------------------------------------------------
127 IMPL_LINK_NOARG(OCollectionView, Save_Click)
129 ::rtl::OUString sName = m_aName.GetText();
130 if ( sName.isEmpty() )
131 return 0;
134 ::rtl::OUString sSubFolder = m_aView.GetCurrentURL();
135 sal_Int32 nIndex = sName.lastIndexOf('/') + 1;
136 if ( nIndex )
138 if ( nIndex == 1 ) // special handling for root
140 Reference<XChild> xChild(m_xContent,UNO_QUERY);
141 Reference<XNameAccess> xNameAccess(xChild,UNO_QUERY);
142 while( xNameAccess.is() )
144 xNameAccess.set(xChild->getParent(),UNO_QUERY);
145 if ( xNameAccess.is() )
147 m_xContent.set(xNameAccess,UNO_QUERY);
148 xChild.set(m_xContent,UNO_QUERY);
151 m_aView.Initialize(m_xContent,String());
152 initCurrentPath();
154 sSubFolder = sName.copy(0,nIndex-1);
155 sName = sName.copy(nIndex);
156 Reference<XHierarchicalNameContainer> xHier(m_xContent,UNO_QUERY);
157 OSL_ENSURE(xHier.is(),"XHierarchicalNameContainer not supported!");
158 if ( !sSubFolder.isEmpty() && xHier.is() )
160 if ( xHier->hasByHierarchicalName(sSubFolder) )
162 m_xContent.set(xHier->getByHierarchicalName(sSubFolder),UNO_QUERY);
164 else // sub folder doesn't exist
166 Sequence< Any > aValues(2);
167 PropertyValue aValue;
168 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ResourceName"));
169 aValue.Value <<= sSubFolder;
170 aValues[0] <<= aValue;
172 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ResourceType"));
173 aValue.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("folder"));
174 aValues[1] <<= aValue;
176 InteractionClassification eClass = InteractionClassification_ERROR;
177 ::com::sun::star::ucb::IOErrorCode eError = IOErrorCode_NOT_EXISTING_PATH;
178 ::rtl::OUString sTemp;
179 InteractiveAugmentedIOException aException(sTemp,Reference<XInterface>(),eClass,eError,aValues);
182 Reference<XInitialization> xIni(m_xORB->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler"))),UNO_QUERY);
183 if ( xIni.is() )
185 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
186 aValue.Value <<= VCLUnoHelper::GetInterface( this );
187 Sequence< Any > aArgs(1);
188 aArgs[0] <<= makeAny(aValue);
189 xIni->initialize(aArgs);
190 OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aException));
191 Reference< XInteractionRequest > xRequest(pRequest);
193 OInteractionApprove* pApprove = new OInteractionApprove;
194 pRequest->addContinuation(pApprove);
196 Reference< XInteractionHandler > xHandler(xIni,UNO_QUERY);
197 xHandler->handle(xRequest);
199 return 0;
203 Reference<XNameContainer> xNameContainer(m_xContent,UNO_QUERY);
204 if ( xNameContainer.is() )
206 Reference< XContent> xContent;
207 if ( xNameContainer->hasByName(sName) )
209 QueryBox aBox( this, WB_YES_NO, ModuleRes( STR_ALREADYEXISTOVERWRITE ) );
210 if ( aBox.Execute() != RET_YES )
211 return 0;
213 m_aName.SetText(sName);
214 EndDialog( sal_True );
217 catch( const Exception& )
219 DBG_UNHANDLED_EXCEPTION();
221 return 0;
223 // -----------------------------------------------------------------------------
224 IMPL_LINK_NOARG(OCollectionView, NewFolder_Click)
228 Reference<XHierarchicalNameContainer> xNameContainer(m_xContent,UNO_QUERY);
229 if ( dbaui::insertHierachyElement(this,m_xORB,xNameContainer,String(),m_bCreateForm) )
230 m_aView.Initialize(m_xContent,String());
232 catch( const SQLException& )
234 showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), this, m_xORB );
236 catch( const Exception& )
238 DBG_UNHANDLED_EXCEPTION();
240 return 0;
242 // -----------------------------------------------------------------------------
243 IMPL_LINK_NOARG(OCollectionView, Up_Click)
247 Reference<XChild> xChild(m_xContent,UNO_QUERY);
248 if ( xChild.is() )
250 Reference<XNameAccess> xNameAccess(xChild->getParent(),UNO_QUERY);
251 if ( xNameAccess.is() )
253 m_xContent.set(xNameAccess,UNO_QUERY);
254 m_aView.Initialize(m_xContent,String());
255 initCurrentPath();
257 else
258 m_aUp.Disable();
261 catch( const Exception& )
263 DBG_UNHANDLED_EXCEPTION();
265 return 0;
267 // -----------------------------------------------------------------------------
268 IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView)
272 Reference<XNameAccess> xNameAccess(m_xContent,UNO_QUERY);
273 if ( xNameAccess.is() )
275 ::rtl::OUString sSubFolder = m_aView.GetCurrentURL();
276 sal_Int32 nIndex = sSubFolder.lastIndexOf('/') + 1;
277 sSubFolder = sSubFolder.getToken(0,'/',nIndex);
278 if ( !sSubFolder.isEmpty() )
280 Reference< XContent> xContent;
281 if ( xNameAccess->hasByName(sSubFolder) )
282 xContent.set(xNameAccess->getByName(sSubFolder),UNO_QUERY);
283 if ( xContent.is() )
285 m_xContent = xContent;
286 m_aView.Initialize(m_xContent,String());
287 initCurrentPath();
292 catch( const Exception& )
294 DBG_UNHANDLED_EXCEPTION();
296 return 0;
298 // -----------------------------------------------------------------------------
299 void OCollectionView::initCurrentPath()
301 sal_Bool bEnable = sal_False;
304 if ( m_xContent.is() )
306 const ::rtl::OUString sCID = m_xContent->getIdentifier()->getContentIdentifier();
307 const static ::rtl::OUString s_sFormsCID(RTL_CONSTASCII_USTRINGPARAM("private:forms"));
308 const static ::rtl::OUString s_sReportsCID(RTL_CONSTASCII_USTRINGPARAM("private:reports"));
309 m_bCreateForm = s_sFormsCID.compareTo(sCID) == 0;
310 ::rtl::OUString sPath(RTL_CONSTASCII_USTRINGPARAM("/"));
311 if ( m_bCreateForm && sCID.getLength() != s_sFormsCID.getLength())
312 sPath = sCID.copy(s_sFormsCID.getLength());
313 else if ( !m_bCreateForm && sCID.getLength() != s_sReportsCID.getLength() )
314 sPath = sCID.copy(s_sReportsCID.getLength());
316 m_aFTCurrentPath.SetText(sPath);
317 Reference<XChild> xChild(m_xContent,UNO_QUERY);
318 bEnable = xChild.is() && Reference<XNameAccess>(xChild->getParent(),UNO_QUERY).is();
321 catch( const Exception& )
323 DBG_UNHANDLED_EXCEPTION();
325 m_aUp.Enable(bEnable);
327 // -----------------------------------------------------------------------------
328 ::rtl::OUString OCollectionView::getName() const
330 return m_aName.GetText();
332 // -----------------------------------------------------------------------------
333 //.........................................................................
334 } // namespace dbaui
335 //.........................................................................
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */