Update ooo320-m1
[ooovba.git] / dbaccess / source / ui / dlg / CollectionView.cxx
blobd1a713523b94023df54678f77c737c0516ec8e4c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CollectionView.cxx,v $
10 * $Revision: 1.11.50.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_COLLECTIONVIEW_HXX
34 #include "CollectionView.hxx"
35 #endif
36 #ifndef DBAUI_COLLECTIONVIEW_HRC
37 #include "CollectionView.hrc"
38 #endif
39 #ifndef _TOOLS_DEBUG_HXX
40 #include <tools/debug.hxx>
41 #endif
42 #ifndef TOOLS_DIAGNOSE_EX_H
43 #include <tools/diagnose_ex.h>
44 #endif
45 #ifndef _DBAUI_MODULE_DBU_HXX_
46 #include "moduledbu.hxx"
47 #endif
48 #ifndef _DBU_DLG_HRC_
49 #include "dbu_dlg.hrc"
50 #endif
51 #ifndef _COMPHELPER_INTERACTION_HXX_
52 #include <comphelper/interaction.hxx>
53 #endif
54 #ifndef _CPPUHELPER_EXC_HLP_HXX_
55 #include <cppuhelper/exc_hlp.hxx>
56 #endif
57 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
58 #include <toolkit/helper/vclunohelper.hxx>
59 #endif
60 #ifndef SVT_QUERYFOLDER_HXX
61 #include <svtools/QueryFolderName.hxx>
62 #endif
63 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
64 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
67 #include <com/sun/star/lang/XInitialization.hpp>
68 #endif
69 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
70 #include <com/sun/star/container/XChild.hpp>
71 #endif
72 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
73 #include <com/sun/star/container/XNameContainer.hpp>
74 #endif
75 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
76 #include <com/sun/star/beans/PropertyValue.hpp>
77 #endif
78 #ifndef _SV_MSGBOX_HXX
79 #include <vcl/msgbox.hxx>
80 #endif
81 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
82 #include "dbustrings.hrc"
83 #endif
84 #ifndef DBAUI_TOOLS_HXX
85 #include "UITools.hxx"
86 #endif
87 #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMECONTAINER_HPP_
88 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
89 #endif
90 #ifndef _COM_SUN_STAR_UCB_INTERACTIVEAUGMENTEDIOEXCEPTION_HPP_
91 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
92 #endif
93 #ifndef _COM_SUN_STAR_UCB_IOERRORCODE_HPP_
94 #include <com/sun/star/ucb/IOErrorCode.hpp>
95 #endif
96 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
97 #include <com/sun/star/task/XInteractionHandler.hpp>
98 #endif
99 #ifndef _COM_SUN_STAR_TASK_INTERACTIONCLASSIFICATION_HPP_
100 #include <com/sun/star/task/InteractionClassification.hpp>
101 #endif
102 #ifndef _COM_SUN_STAR_SDBC_SQLEXCEPTION_HPP_
103 #include <com/sun/star/sdbc/SQLException.hpp>
104 #endif
105 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
106 #include <com/sun/star/awt/XWindow.hpp>
107 #endif
108 #ifndef INCLUDED_SVTOOLS_VIEWOPTIONS_HXX
109 #include <svtools/viewoptions.hxx>
110 #endif
111 #ifndef _OSL_THREAD_H_
112 #include <osl/thread.h>
113 #endif
114 #ifndef _DBHELPER_DBEXCEPTION_HXX_
115 #include <connectivity/dbexception.hxx>
116 #endif
118 #define FILEDIALOG_DEF_IMAGEBORDER 10
119 //.........................................................................
120 namespace dbaui
122 //.........................................................................
124 using namespace ::com::sun::star::uno;
125 using namespace ::com::sun::star::ucb;
126 using namespace ::com::sun::star::lang;
127 using namespace ::com::sun::star::beans;
128 using namespace ::com::sun::star::container;
129 using namespace ::com::sun::star::ucb;
130 using namespace ::com::sun::star::task;
131 using namespace ::com::sun::star::sdbc;
132 using namespace comphelper;
133 // -----------------------------------------------------------------------------
134 DBG_NAME(OCollectionView)
135 OCollectionView::OCollectionView( Window * pParent
136 ,const Reference< XContent>& _xContent
137 ,const ::rtl::OUString& _sDefaultName
138 ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB)
139 : ModalDialog( pParent, ModuleRes(DLG_COLLECTION_VIEW))
140 , m_aFTCurrentPath( this, ModuleRes( FT_EXPLORERFILE_CURRENTPATH ) )
141 , m_aNewFolder( this, ModuleRes( BTN_EXPLORERFILE_NEWFOLDER ) )
142 , m_aUp( this, ModuleRes( BTN_EXPLORERFILE_UP ) )
143 , m_aView( this, ModuleRes( CTRL_VIEW ) ,FILEVIEW_SHOW_TITLE )
144 , m_aFTName( this, ModuleRes( FT_EXPLORERFILE_FILENAME ) )
145 , m_aName( this, ModuleRes( ED_EXPLORERFILE_FILENAME ) )
146 , m_aFL( this, ModuleRes( FL_1 ) )
147 , m_aPB_OK( this, ModuleRes( BTN_EXPLORERFILE_SAVE ) )
148 , m_aPB_CANCEL( this, ModuleRes( PB_CANCEL ) )
149 , m_aPB_HELP( this, ModuleRes( PB_HELP ) )
150 , m_sPath( ModuleRes( STR_PATHNAME ) )
151 , m_xContent(_xContent)
152 , m_xORB(_xORB)
153 , m_bCreateForm(sal_True)
155 DBG_CTOR(OCollectionView,NULL);
156 FreeResource();
158 OSL_ENSURE(m_xContent.is(),"No valid content!");
159 m_aView.Initialize(m_xContent,String());
160 m_aFTCurrentPath.SetStyle( m_aFTCurrentPath.GetStyle() | WB_PATHELLIPSIS );
161 initCurrentPath();
163 m_aName.SetText(_sDefaultName);
164 m_aName.GrabFocus();
166 m_aNewFolder.SetStyle( m_aNewFolder.GetStyle() | WB_NOPOINTERFOCUS );
167 m_aUp.SetModeImage(ModuleRes(IMG_NAVIGATION_BTN_UP_SC));
168 m_aUp.SetModeImage(ModuleRes(IMG_NAVIGATION_BTN_UP_SCH),BMP_COLOR_HIGHCONTRAST);
169 m_aNewFolder.SetModeImage(ModuleRes(IMG_NAVIGATION_CREATEFOLDER_SC));
170 m_aNewFolder.SetModeImage(ModuleRes(IMG_NAVIGATION_CREATEFOLDER_SCH),BMP_COLOR_HIGHCONTRAST);
172 m_aView.SetDoubleClickHdl( LINK( this, OCollectionView, Dbl_Click_FileView ) );
173 m_aView.EnableAutoResize();
174 m_aUp.SetClickHdl( LINK( this, OCollectionView, Up_Click ) );
175 m_aNewFolder.SetClickHdl( LINK( this, OCollectionView, NewFolder_Click ) );
176 m_aPB_OK.SetClickHdl( LINK( this, OCollectionView, Save_Click ) );
178 // -----------------------------------------------------------------------------
179 OCollectionView::~OCollectionView( )
181 DBG_DTOR(OCollectionView,NULL);
183 // -----------------------------------------------------------------------------
184 Reference< XContent> OCollectionView::getSelectedFolder() const
186 return m_xContent;
188 // -----------------------------------------------------------------------------
189 IMPL_LINK( OCollectionView, Save_Click, PushButton*, EMPTYARG )
191 ::rtl::OUString sName = m_aName.GetText();
192 if ( !sName.getLength() )
193 return 0;
196 ::rtl::OUString sSubFolder = m_aView.GetCurrentURL();
197 sal_Int32 nIndex = sName.lastIndexOf('/') + 1;
198 if ( nIndex )
200 if ( nIndex == 1 ) // special handling for root
202 Reference<XChild> xChild(m_xContent,UNO_QUERY);
203 Reference<XNameAccess> xNameAccess(xChild,UNO_QUERY);
204 while( xNameAccess.is() )
206 xNameAccess.set(xChild->getParent(),UNO_QUERY);
207 if ( xNameAccess.is() )
209 m_xContent.set(xNameAccess,UNO_QUERY);
210 xChild.set(m_xContent,UNO_QUERY);
213 m_aView.Initialize(m_xContent,String());
214 initCurrentPath();
216 sSubFolder = sName.copy(0,nIndex-1);
217 sName = sName.copy(nIndex);
218 Reference<XHierarchicalNameContainer> xHier(m_xContent,UNO_QUERY);
219 OSL_ENSURE(xHier.is(),"XHierarchicalNameContainer not supported!");
220 if ( sSubFolder.getLength() && xHier.is() )
222 if ( xHier->hasByHierarchicalName(sSubFolder) )
224 m_xContent.set(xHier->getByHierarchicalName(sSubFolder),UNO_QUERY);
226 else // sub folder doesn't exist
228 Sequence< Any > aValues(2);
229 PropertyValue aValue;
230 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ResourceName"));
231 aValue.Value <<= sSubFolder;
232 aValues[0] <<= aValue;
234 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ResourceType"));
235 aValue.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("folder"));
236 aValues[1] <<= aValue;
238 InteractionClassification eClass = InteractionClassification_ERROR;
239 ::com::sun::star::ucb::IOErrorCode eError = IOErrorCode_NOT_EXISTING_PATH;
240 ::rtl::OUString sTemp;
241 InteractiveAugmentedIOException aException(sTemp,Reference<XInterface>(),eClass,eError,aValues);
244 Reference<XInitialization> xIni(m_xORB->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler"))),UNO_QUERY);
245 if ( xIni.is() )
247 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
248 aValue.Value <<= VCLUnoHelper::GetInterface( this );
249 Sequence< Any > aArgs(1);
250 aArgs[0] <<= makeAny(aValue);
251 xIni->initialize(aArgs);
252 OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aException));
253 Reference< XInteractionRequest > xRequest(pRequest);
255 OInteractionApprove* pApprove = new OInteractionApprove;
256 pRequest->addContinuation(pApprove);
258 Reference< XInteractionHandler > xHandler(xIni,UNO_QUERY);
259 xHandler->handle(xRequest);
261 return 0;
265 Reference<XNameContainer> xNameContainer(m_xContent,UNO_QUERY);
266 if ( xNameContainer.is() )
268 Reference< XContent> xContent;
269 if ( xNameContainer->hasByName(sName) )
271 QueryBox aBox( this, WB_YES_NO, ModuleRes( STR_ALREADYEXISTOVERWRITE ) );
272 if ( aBox.Execute() != RET_YES )
273 return 0;
274 // xNameContainer->removeByName(sName);
276 m_aName.SetText(sName);
277 EndDialog( TRUE );
280 catch( const Exception& )
282 DBG_UNHANDLED_EXCEPTION();
284 return 0;
286 // -----------------------------------------------------------------------------
287 IMPL_LINK( OCollectionView, NewFolder_Click, PushButton*, EMPTYARG )
291 Reference<XHierarchicalNameContainer> xNameContainer(m_xContent,UNO_QUERY);
292 if ( dbaui::insertHierachyElement(this,m_xORB,xNameContainer,String(),m_bCreateForm) )
293 m_aView.Initialize(m_xContent,String());
295 catch( const SQLException& )
297 showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), this, m_xORB );
299 catch( const Exception& )
301 DBG_UNHANDLED_EXCEPTION();
303 return 0;
305 // -----------------------------------------------------------------------------
306 IMPL_LINK( OCollectionView, Up_Click, PushButton*, EMPTYARG )
310 Reference<XChild> xChild(m_xContent,UNO_QUERY);
311 if ( xChild.is() )
313 Reference<XNameAccess> xNameAccess(xChild->getParent(),UNO_QUERY);
314 if ( xNameAccess.is() )
316 m_xContent.set(xNameAccess,UNO_QUERY);
317 m_aView.Initialize(m_xContent,String());
318 initCurrentPath();
320 else
321 m_aUp.Disable();
324 catch( const Exception& )
326 DBG_UNHANDLED_EXCEPTION();
328 return 0;
330 // -----------------------------------------------------------------------------
331 IMPL_LINK( OCollectionView, Dbl_Click_FileView, SvtFileView*, EMPTYARG )
335 Reference<XNameAccess> xNameAccess(m_xContent,UNO_QUERY);
336 if ( xNameAccess.is() )
338 ::rtl::OUString sSubFolder = m_aView.GetCurrentURL();
339 sal_Int32 nIndex = sSubFolder.lastIndexOf('/') + 1;
340 sSubFolder = sSubFolder.getToken(0,'/',nIndex);
341 if ( sSubFolder.getLength() )
343 Reference< XContent> xContent;
344 if ( xNameAccess->hasByName(sSubFolder) )
345 xContent.set(xNameAccess->getByName(sSubFolder),UNO_QUERY);
346 if ( xContent.is() )
348 m_xContent = xContent;
349 m_aView.Initialize(m_xContent,String());
350 initCurrentPath();
355 catch( const Exception& )
357 DBG_UNHANDLED_EXCEPTION();
359 return 0;
361 // -----------------------------------------------------------------------------
362 void OCollectionView::initCurrentPath()
364 BOOL bEnable = FALSE;
367 if ( m_xContent.is() )
369 const ::rtl::OUString sCID = m_xContent->getIdentifier()->getContentIdentifier();
370 const static ::rtl::OUString s_sFormsCID(RTL_CONSTASCII_USTRINGPARAM("private:forms"));
371 const static ::rtl::OUString s_sReportsCID(RTL_CONSTASCII_USTRINGPARAM("private:reports"));
372 m_bCreateForm = s_sFormsCID.compareTo(sCID) == 0;
373 ::rtl::OUString sPath(RTL_CONSTASCII_USTRINGPARAM("/"));
374 if ( m_bCreateForm && sCID.getLength() != s_sFormsCID.getLength())
375 sPath = sCID.copy(s_sFormsCID.getLength());
376 else if ( !m_bCreateForm && sCID.getLength() != s_sReportsCID.getLength() )
377 sPath = sCID.copy(s_sReportsCID.getLength());
379 m_aFTCurrentPath.SetText(sPath);
380 Reference<XChild> xChild(m_xContent,UNO_QUERY);
381 bEnable = xChild.is() && Reference<XNameAccess>(xChild->getParent(),UNO_QUERY).is();
384 catch( const Exception& )
386 DBG_UNHANDLED_EXCEPTION();
388 m_aUp.Enable(bEnable);
390 // -----------------------------------------------------------------------------
391 ::rtl::OUString OCollectionView::getName() const
393 return m_aName.GetText();
395 // -----------------------------------------------------------------------------
396 //.........................................................................
397 } // namespace dbaui
398 //.........................................................................