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 <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>
48 :
49 : //.........................................................................
50 : namespace dbaui
51 : {
52 : //.........................................................................
53 :
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 0 : 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 0 : , m_bCreateForm(sal_True)
83 : {
84 : DBG_CTOR(OCollectionView,NULL);
85 0 : FreeResource();
86 :
87 : OSL_ENSURE(m_xContent.is(),"No valid content!");
88 0 : m_aView.Initialize(m_xContent,String());
89 0 : m_aFTCurrentPath.SetStyle( m_aFTCurrentPath.GetStyle() | WB_PATHELLIPSIS );
90 0 : initCurrentPath();
91 :
92 0 : m_aName.SetText(_sDefaultName);
93 0 : m_aName.GrabFocus();
94 :
95 0 : m_aNewFolder.SetStyle( m_aNewFolder.GetStyle() | WB_NOPOINTERFOCUS );
96 0 : m_aUp.SetModeImage(ModuleRes(IMG_NAVIGATION_BTN_UP_SC));
97 0 : m_aNewFolder.SetModeImage(ModuleRes(IMG_NAVIGATION_CREATEFOLDER_SC));
98 :
99 0 : m_aView.SetDoubleClickHdl( LINK( this, OCollectionView, Dbl_Click_FileView ) );
100 0 : m_aView.EnableAutoResize();
101 0 : m_aUp.SetClickHdl( LINK( this, OCollectionView, Up_Click ) );
102 0 : m_aNewFolder.SetClickHdl( LINK( this, OCollectionView, NewFolder_Click ) );
103 0 : m_aPB_OK.SetClickHdl( LINK( this, OCollectionView, Save_Click ) );
104 0 : }
105 : // -----------------------------------------------------------------------------
106 0 : OCollectionView::~OCollectionView( )
107 : {
108 : DBG_DTOR(OCollectionView,NULL);
109 0 : }
110 : // -----------------------------------------------------------------------------
111 0 : Reference< XContent> OCollectionView::getSelectedFolder() const
112 : {
113 0 : return m_xContent;
114 : }
115 : // -----------------------------------------------------------------------------
116 0 : IMPL_LINK_NOARG(OCollectionView, Save_Click)
117 : {
118 0 : OUString sName = m_aName.GetText();
119 0 : if ( sName.isEmpty() )
120 0 : return 0;
121 : try
122 : {
123 0 : OUString sSubFolder = m_aView.GetCurrentURL();
124 0 : sal_Int32 nIndex = sName.lastIndexOf('/') + 1;
125 0 : if ( nIndex )
126 : {
127 0 : if ( nIndex == 1 ) // special handling for root
128 : {
129 0 : Reference<XChild> xChild(m_xContent,UNO_QUERY);
130 0 : Reference<XNameAccess> xNameAccess(xChild,UNO_QUERY);
131 0 : while( xNameAccess.is() )
132 : {
133 0 : xNameAccess.set(xChild->getParent(),UNO_QUERY);
134 0 : if ( xNameAccess.is() )
135 : {
136 0 : m_xContent.set(xNameAccess,UNO_QUERY);
137 0 : xChild.set(m_xContent,UNO_QUERY);
138 : }
139 : }
140 0 : m_aView.Initialize(m_xContent,String());
141 0 : initCurrentPath();
142 : }
143 0 : sSubFolder = sName.copy(0,nIndex-1);
144 0 : sName = sName.copy(nIndex);
145 0 : Reference<XHierarchicalNameContainer> xHier(m_xContent,UNO_QUERY);
146 : OSL_ENSURE(xHier.is(),"XHierarchicalNameContainer not supported!");
147 0 : if ( !sSubFolder.isEmpty() && xHier.is() )
148 : {
149 0 : if ( xHier->hasByHierarchicalName(sSubFolder) )
150 : {
151 0 : m_xContent.set(xHier->getByHierarchicalName(sSubFolder),UNO_QUERY);
152 : }
153 : else // sub folder doesn't exist
154 : {
155 0 : Sequence< Any > aValues(2);
156 0 : PropertyValue aValue;
157 0 : aValue.Name = OUString("ResourceName");
158 0 : aValue.Value <<= sSubFolder;
159 0 : aValues[0] <<= aValue;
160 :
161 0 : aValue.Name = OUString("ResourceType");
162 0 : aValue.Value <<= OUString("folder");
163 0 : aValues[1] <<= aValue;
164 :
165 0 : InteractionClassification eClass = InteractionClassification_ERROR;
166 0 : ::com::sun::star::ucb::IOErrorCode eError = IOErrorCode_NOT_EXISTING_PATH;
167 0 : OUString sTemp;
168 0 : InteractiveAugmentedIOException aException(sTemp,Reference<XInterface>(),eClass,eError,aValues);
169 :
170 :
171 : Reference<XInteractionHandler2> xHandler(
172 0 : InteractionHandler::createWithParent(m_xContext, VCLUnoHelper::GetInterface( this )));
173 0 : OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aException));
174 0 : Reference< XInteractionRequest > xRequest(pRequest);
175 :
176 0 : OInteractionApprove* pApprove = new OInteractionApprove;
177 0 : pRequest->addContinuation(pApprove);
178 0 : xHandler->handle(xRequest);
179 :
180 0 : return 0;
181 : }
182 0 : }
183 : }
184 0 : Reference<XNameContainer> xNameContainer(m_xContent,UNO_QUERY);
185 0 : if ( xNameContainer.is() )
186 : {
187 0 : Reference< XContent> xContent;
188 0 : if ( xNameContainer->hasByName(sName) )
189 : {
190 0 : QueryBox aBox( this, WB_YES_NO, ModuleRes( STR_ALREADYEXISTOVERWRITE ) );
191 0 : if ( aBox.Execute() != RET_YES )
192 0 : return 0;
193 : }
194 0 : m_aName.SetText(sName);
195 0 : EndDialog( sal_True );
196 0 : }
197 : }
198 0 : catch( const Exception& )
199 : {
200 : DBG_UNHANDLED_EXCEPTION();
201 : }
202 0 : return 0;
203 : }
204 : // -----------------------------------------------------------------------------
205 0 : IMPL_LINK_NOARG(OCollectionView, NewFolder_Click)
206 : {
207 : try
208 : {
209 0 : Reference<XHierarchicalNameContainer> xNameContainer(m_xContent,UNO_QUERY);
210 0 : if ( dbaui::insertHierachyElement(this,m_xContext,xNameContainer,String(),m_bCreateForm) )
211 0 : m_aView.Initialize(m_xContent,String());
212 : }
213 0 : catch( const SQLException& )
214 : {
215 0 : showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), this, m_xContext );
216 : }
217 0 : catch( const Exception& )
218 : {
219 : DBG_UNHANDLED_EXCEPTION();
220 : }
221 0 : return 0;
222 : }
223 : // -----------------------------------------------------------------------------
224 0 : IMPL_LINK_NOARG(OCollectionView, Up_Click)
225 : {
226 : try
227 : {
228 0 : Reference<XChild> xChild(m_xContent,UNO_QUERY);
229 0 : if ( xChild.is() )
230 : {
231 0 : Reference<XNameAccess> xNameAccess(xChild->getParent(),UNO_QUERY);
232 0 : if ( xNameAccess.is() )
233 : {
234 0 : m_xContent.set(xNameAccess,UNO_QUERY);
235 0 : m_aView.Initialize(m_xContent,String());
236 0 : initCurrentPath();
237 : }
238 : else
239 0 : m_aUp.Disable();
240 0 : }
241 : }
242 0 : catch( const Exception& )
243 : {
244 : DBG_UNHANDLED_EXCEPTION();
245 : }
246 0 : return 0;
247 : }
248 : // -----------------------------------------------------------------------------
249 0 : IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView)
250 : {
251 : try
252 : {
253 0 : Reference<XNameAccess> xNameAccess(m_xContent,UNO_QUERY);
254 0 : if ( xNameAccess.is() )
255 : {
256 0 : OUString sSubFolder = m_aView.GetCurrentURL();
257 0 : sal_Int32 nIndex = sSubFolder.lastIndexOf('/') + 1;
258 0 : sSubFolder = sSubFolder.getToken(0,'/',nIndex);
259 0 : if ( !sSubFolder.isEmpty() )
260 : {
261 0 : Reference< XContent> xContent;
262 0 : if ( xNameAccess->hasByName(sSubFolder) )
263 0 : xContent.set(xNameAccess->getByName(sSubFolder),UNO_QUERY);
264 0 : if ( xContent.is() )
265 : {
266 0 : m_xContent = xContent;
267 0 : m_aView.Initialize(m_xContent,String());
268 0 : initCurrentPath();
269 0 : }
270 0 : }
271 0 : }
272 : }
273 0 : catch( const Exception& )
274 : {
275 : DBG_UNHANDLED_EXCEPTION();
276 : }
277 0 : return 0;
278 : }
279 : // -----------------------------------------------------------------------------
280 0 : void OCollectionView::initCurrentPath()
281 : {
282 0 : sal_Bool bEnable = sal_False;
283 : try
284 : {
285 0 : if ( m_xContent.is() )
286 : {
287 0 : const OUString sCID = m_xContent->getIdentifier()->getContentIdentifier();
288 0 : const static OUString s_sFormsCID("private:forms");
289 0 : const static OUString s_sReportsCID("private:reports");
290 0 : m_bCreateForm = s_sFormsCID == sCID ;
291 0 : OUString sPath("/");
292 0 : if ( m_bCreateForm && sCID.getLength() != s_sFormsCID.getLength())
293 0 : sPath = sCID.copy(s_sFormsCID.getLength());
294 0 : else if ( !m_bCreateForm && sCID.getLength() != s_sReportsCID.getLength() )
295 0 : sPath = sCID.copy(s_sReportsCID.getLength());
296 :
297 0 : m_aFTCurrentPath.SetText(sPath);
298 0 : Reference<XChild> xChild(m_xContent,UNO_QUERY);
299 0 : bEnable = xChild.is() && Reference<XNameAccess>(xChild->getParent(),UNO_QUERY).is();
300 : }
301 : }
302 0 : catch( const Exception& )
303 : {
304 : DBG_UNHANDLED_EXCEPTION();
305 : }
306 0 : m_aUp.Enable(bEnable);
307 0 : }
308 : // -----------------------------------------------------------------------------
309 0 : OUString OCollectionView::getName() const
310 : {
311 0 : return m_aName.GetText();
312 : }
313 : // -----------------------------------------------------------------------------
314 : //.........................................................................
315 12 : } // namespace dbaui
316 : //.........................................................................
317 :
318 :
319 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|