1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 <svtools/QueryFolderName.hxx>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/container/XChild.hpp>
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <vcl/msgbox.hxx>
36 #include "dbustrings.hrc"
37 #include "UITools.hxx"
38 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
39 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
40 #include <com/sun/star/ucb/IOErrorCode.hpp>
41 #include <com/sun/star/task/InteractionHandler.hpp>
42 #include <com/sun/star/task/InteractionClassification.hpp>
43 #include <com/sun/star/sdbc/SQLException.hpp>
44 #include <com/sun/star/awt/XWindow.hpp>
45 #include <unotools/viewoptions.hxx>
46 #include <osl/thread.h>
47 #include <connectivity/dbexception.hxx>
49 //.........................................................................
52 //.........................................................................
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::ucb
;
56 using namespace ::com::sun::star::lang
;
57 using namespace ::com::sun::star::beans
;
58 using namespace ::com::sun::star::container
;
59 using namespace ::com::sun::star::task
;
60 using namespace ::com::sun::star::sdbc
;
61 using namespace comphelper
;
62 // -----------------------------------------------------------------------------
63 DBG_NAME(OCollectionView
)
64 OCollectionView::OCollectionView( Window
* pParent
65 ,const Reference
< XContent
>& _xContent
66 ,const OUString
& _sDefaultName
67 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
)
68 : ModalDialog( pParent
, ModuleRes(DLG_COLLECTION_VIEW
))
69 , m_aFTCurrentPath( this, ModuleRes( FT_EXPLORERFILE_CURRENTPATH
) )
70 , m_aNewFolder( this, ModuleRes( BTN_EXPLORERFILE_NEWFOLDER
) )
71 , m_aUp( this, ModuleRes( BTN_EXPLORERFILE_UP
) )
72 , m_aView( this, ModuleRes( CTRL_VIEW
), FILEVIEW_SHOW_ONLYTITLE
)
73 , m_aFTName( this, ModuleRes( FT_EXPLORERFILE_FILENAME
) )
74 , m_aName( this, ModuleRes( ED_EXPLORERFILE_FILENAME
) )
75 , m_aFL( this, ModuleRes( FL_1
) )
76 , m_aPB_OK( this, ModuleRes( BTN_EXPLORERFILE_SAVE
) )
77 , m_aPB_CANCEL( this, ModuleRes( PB_CANCEL
) )
78 , m_aPB_HELP( this, ModuleRes( PB_HELP
) )
79 , m_sPath( ModuleRes( STR_PATHNAME
) )
80 , m_xContent(_xContent
)
81 , m_xContext(_rxContext
)
82 , m_bCreateForm(sal_True
)
84 DBG_CTOR(OCollectionView
,NULL
);
87 OSL_ENSURE(m_xContent
.is(),"No valid content!");
88 m_aView
.Initialize(m_xContent
,String());
89 m_aFTCurrentPath
.SetStyle( m_aFTCurrentPath
.GetStyle() | WB_PATHELLIPSIS
);
92 m_aName
.SetText(_sDefaultName
);
95 m_aNewFolder
.SetStyle( m_aNewFolder
.GetStyle() | WB_NOPOINTERFOCUS
);
96 m_aUp
.SetModeImage(ModuleRes(IMG_NAVIGATION_BTN_UP_SC
));
97 m_aNewFolder
.SetModeImage(ModuleRes(IMG_NAVIGATION_CREATEFOLDER_SC
));
99 m_aView
.SetDoubleClickHdl( LINK( this, OCollectionView
, Dbl_Click_FileView
) );
100 m_aView
.EnableAutoResize();
101 m_aUp
.SetClickHdl( LINK( this, OCollectionView
, Up_Click
) );
102 m_aNewFolder
.SetClickHdl( LINK( this, OCollectionView
, NewFolder_Click
) );
103 m_aPB_OK
.SetClickHdl( LINK( this, OCollectionView
, Save_Click
) );
105 // -----------------------------------------------------------------------------
106 OCollectionView::~OCollectionView( )
108 DBG_DTOR(OCollectionView
,NULL
);
110 // -----------------------------------------------------------------------------
111 Reference
< XContent
> OCollectionView::getSelectedFolder() const
115 // -----------------------------------------------------------------------------
116 IMPL_LINK_NOARG(OCollectionView
, Save_Click
)
118 OUString sName
= m_aName
.GetText();
119 if ( sName
.isEmpty() )
123 OUString sSubFolder
= m_aView
.GetCurrentURL();
124 sal_Int32 nIndex
= sName
.lastIndexOf('/') + 1;
127 if ( nIndex
== 1 ) // special handling for root
129 Reference
<XChild
> xChild(m_xContent
,UNO_QUERY
);
130 Reference
<XNameAccess
> xNameAccess(xChild
,UNO_QUERY
);
131 while( xNameAccess
.is() )
133 xNameAccess
.set(xChild
->getParent(),UNO_QUERY
);
134 if ( xNameAccess
.is() )
136 m_xContent
.set(xNameAccess
,UNO_QUERY
);
137 xChild
.set(m_xContent
,UNO_QUERY
);
140 m_aView
.Initialize(m_xContent
,String());
143 sSubFolder
= sName
.copy(0,nIndex
-1);
144 sName
= sName
.copy(nIndex
);
145 Reference
<XHierarchicalNameContainer
> xHier(m_xContent
,UNO_QUERY
);
146 OSL_ENSURE(xHier
.is(),"XHierarchicalNameContainer not supported!");
147 if ( !sSubFolder
.isEmpty() && xHier
.is() )
149 if ( xHier
->hasByHierarchicalName(sSubFolder
) )
151 m_xContent
.set(xHier
->getByHierarchicalName(sSubFolder
),UNO_QUERY
);
153 else // sub folder doesn't exist
155 Sequence
< Any
> aValues(2);
156 PropertyValue aValue
;
157 aValue
.Name
= OUString("ResourceName");
158 aValue
.Value
<<= sSubFolder
;
159 aValues
[0] <<= aValue
;
161 aValue
.Name
= OUString("ResourceType");
162 aValue
.Value
<<= OUString("folder");
163 aValues
[1] <<= aValue
;
165 InteractionClassification eClass
= InteractionClassification_ERROR
;
166 ::com::sun::star::ucb::IOErrorCode eError
= IOErrorCode_NOT_EXISTING_PATH
;
168 InteractiveAugmentedIOException
aException(sTemp
,Reference
<XInterface
>(),eClass
,eError
,aValues
);
171 Reference
<XInteractionHandler2
> xHandler(
172 InteractionHandler::createWithParent(m_xContext
, VCLUnoHelper::GetInterface( this )));
173 OInteractionRequest
* pRequest
= new OInteractionRequest(makeAny(aException
));
174 Reference
< XInteractionRequest
> xRequest(pRequest
);
176 OInteractionApprove
* pApprove
= new OInteractionApprove
;
177 pRequest
->addContinuation(pApprove
);
178 xHandler
->handle(xRequest
);
184 Reference
<XNameContainer
> xNameContainer(m_xContent
,UNO_QUERY
);
185 if ( xNameContainer
.is() )
187 Reference
< XContent
> xContent
;
188 if ( xNameContainer
->hasByName(sName
) )
190 QueryBox
aBox( this, WB_YES_NO
, ModuleRes( STR_ALREADYEXISTOVERWRITE
) );
191 if ( aBox
.Execute() != RET_YES
)
194 m_aName
.SetText(sName
);
195 EndDialog( sal_True
);
198 catch( const Exception
& )
200 DBG_UNHANDLED_EXCEPTION();
204 // -----------------------------------------------------------------------------
205 IMPL_LINK_NOARG(OCollectionView
, NewFolder_Click
)
209 Reference
<XHierarchicalNameContainer
> xNameContainer(m_xContent
,UNO_QUERY
);
210 if ( dbaui::insertHierachyElement(this,m_xContext
,xNameContainer
,String(),m_bCreateForm
) )
211 m_aView
.Initialize(m_xContent
,String());
213 catch( const SQLException
& )
215 showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), this, m_xContext
);
217 catch( const Exception
& )
219 DBG_UNHANDLED_EXCEPTION();
223 // -----------------------------------------------------------------------------
224 IMPL_LINK_NOARG(OCollectionView
, Up_Click
)
228 Reference
<XChild
> xChild(m_xContent
,UNO_QUERY
);
231 Reference
<XNameAccess
> xNameAccess(xChild
->getParent(),UNO_QUERY
);
232 if ( xNameAccess
.is() )
234 m_xContent
.set(xNameAccess
,UNO_QUERY
);
235 m_aView
.Initialize(m_xContent
,String());
242 catch( const Exception
& )
244 DBG_UNHANDLED_EXCEPTION();
248 // -----------------------------------------------------------------------------
249 IMPL_LINK_NOARG(OCollectionView
, Dbl_Click_FileView
)
253 Reference
<XNameAccess
> xNameAccess(m_xContent
,UNO_QUERY
);
254 if ( xNameAccess
.is() )
256 OUString sSubFolder
= m_aView
.GetCurrentURL();
257 sal_Int32 nIndex
= sSubFolder
.lastIndexOf('/') + 1;
258 sSubFolder
= sSubFolder
.getToken(0,'/',nIndex
);
259 if ( !sSubFolder
.isEmpty() )
261 Reference
< XContent
> xContent
;
262 if ( xNameAccess
->hasByName(sSubFolder
) )
263 xContent
.set(xNameAccess
->getByName(sSubFolder
),UNO_QUERY
);
266 m_xContent
= xContent
;
267 m_aView
.Initialize(m_xContent
,String());
273 catch( const Exception
& )
275 DBG_UNHANDLED_EXCEPTION();
279 // -----------------------------------------------------------------------------
280 void OCollectionView::initCurrentPath()
282 sal_Bool bEnable
= sal_False
;
285 if ( m_xContent
.is() )
287 const OUString sCID
= m_xContent
->getIdentifier()->getContentIdentifier();
288 const static OUString
s_sFormsCID("private:forms");
289 const static OUString
s_sReportsCID("private:reports");
290 m_bCreateForm
= s_sFormsCID
== sCID
;
292 if ( m_bCreateForm
&& sCID
.getLength() != s_sFormsCID
.getLength())
293 sPath
= sCID
.copy(s_sFormsCID
.getLength());
294 else if ( !m_bCreateForm
&& sCID
.getLength() != s_sReportsCID
.getLength() )
295 sPath
= sCID
.copy(s_sReportsCID
.getLength());
297 m_aFTCurrentPath
.SetText(sPath
);
298 Reference
<XChild
> xChild(m_xContent
,UNO_QUERY
);
299 bEnable
= xChild
.is() && Reference
<XNameAccess
>(xChild
->getParent(),UNO_QUERY
).is();
302 catch( const Exception
& )
304 DBG_UNHANDLED_EXCEPTION();
306 m_aUp
.Enable(bEnable
);
308 // -----------------------------------------------------------------------------
309 OUString
OCollectionView::getName() const
311 return m_aName
.GetText();
313 // -----------------------------------------------------------------------------
314 //.........................................................................
316 //.........................................................................
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */