update dev300-m58
[ooovba.git] / dbaccess / source / ui / uno / dbinteraction.cxx
blobe0ca05ce6a7d500e383e6a797a72f32bb8c74d77
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: dbinteraction.cxx,v $
10 * $Revision: 1.17.6.2 $
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"
34 #ifndef _DBAUI_INTERACTION_HXX_
35 #include "dbinteraction.hxx"
36 #endif
37 #ifndef _DBU_REGHELPER_HXX_
38 #include "dbu_reghelper.hxx"
39 #endif
40 #ifndef _TOOLS_DEBUG_HXX
41 #include <tools/debug.hxx>
42 #endif
43 #ifndef TOOLS_DIAGNOSE_EX_H
44 #include <tools/diagnose_ex.h>
45 #endif
46 #ifndef _SV_MSGBOX_HXX
47 #include <vcl/msgbox.hxx>
48 #endif
49 #ifndef _DBHELPER_DBEXCEPTION_HXX_
50 #include <connectivity/dbexception.hxx>
51 #endif
52 #ifndef _DBAUI_SQLMESSAGE_HXX_
53 #include "sqlmessage.hxx"
54 #endif
55 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONAPPROVE_HPP_
56 #include <com/sun/star/task/XInteractionApprove.hpp>
57 #endif
58 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONDISAPPROVE_HPP_
59 #include <com/sun/star/task/XInteractionDisapprove.hpp>
60 #endif
61 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONRETRY_HPP_
62 #include <com/sun/star/task/XInteractionRetry.hpp>
63 #endif
64 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONABORT_HPP_
65 #include <com/sun/star/task/XInteractionAbort.hpp>
66 #endif
67 #ifndef _COM_SUN_STAR_SDB_XINTERACTIONSUPPLYPARAMETERS_HPP_
68 #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp>
69 #endif
70 #ifndef _COM_SUN_STAR_SDB_XINTERACTIONDOCUMENTSAVE_HPP_
71 #include <com/sun/star/sdb/XInteractionDocumentSave.hpp>
72 #endif
73 #ifndef _SVTOOLS_LOGINDLG_HXX_
74 #include <svtools/logindlg.hxx>
75 #endif
76 #ifndef SFX_QUERYSAVEDOCUMENT_HXX
77 #include <sfx2/QuerySaveDocument.hxx>
78 #endif
79 #ifndef _DBU_UNO_HRC_
80 #include "dbu_uno.hrc"
81 #endif
82 #ifndef _DBAUI_PARAMDIALOG_HXX_
83 #include "paramdialog.hxx"
84 #endif
85 #ifndef _SV_SVAPP_HXX
86 #include <vcl/svapp.hxx>
87 #endif
88 #ifndef _VOS_MUTEX_HXX_
89 #include <vos/mutex.hxx>
90 #endif
91 #ifndef DBAUI_COLLECTIONVIEW_HXX
92 #include "CollectionView.hxx"
93 #endif
94 #ifndef DBAUI_TOOLS_HXX
95 #include "UITools.hxx"
96 #endif
99 //==========================================================================
101 extern "C" void SAL_CALL createRegistryInfo_OInteractionHandler()
103 static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OInteractionHandler > aOInteractionHandler_AutoRegistration;
106 //.........................................................................
107 namespace dbaui
109 //.........................................................................
110 using namespace ::com::sun::star::uno;
111 using namespace ::com::sun::star::ucb;
112 using namespace ::com::sun::star::sdb;
113 using namespace ::com::sun::star::lang;
114 using namespace ::com::sun::star::task;
115 using namespace ::com::sun::star::beans;
116 using namespace ::dbtools;
118 //=========================================================================
119 //= OInteractionHandler
120 //=========================================================================
121 //-------------------------------------------------------------------------
122 OInteractionHandler::OInteractionHandler(const Reference< XMultiServiceFactory >& _rxORB)
123 :m_xORB(_rxORB)
127 //-------------------------------------------------------------------------
128 IMPLEMENT_SERVICE_INFO1_STATIC(OInteractionHandler, "com.sun.star.comp.dbu.OInteractionHandler", "com.sun.star.sdb.InteractionHandler");
130 //-------------------------------------------------------------------------
131 void SAL_CALL OInteractionHandler::handle(const Reference< XInteractionRequest >& _rxRequest) throw(RuntimeException)
133 Any aRequest;
134 if (_rxRequest.is())
136 try { aRequest = _rxRequest->getRequest(); }
137 catch(RuntimeException&) { }
139 DBG_ASSERT(aRequest.hasValue(), "OInteractionHandler::handle: invalid request!");
140 if (!aRequest.hasValue())
141 // no request -> no handling
142 return;
144 Sequence< Reference< XInteractionContinuation > > aContinuations;
145 try { aContinuations = _rxRequest->getContinuations(); }
146 catch(RuntimeException&) { }
148 // try to extract an SQLException (or one of it's derived members
149 SQLExceptionInfo aInfo(aRequest);
150 if (aInfo.isValid())
152 implHandle(aInfo, aContinuations);
153 return;
156 ParametersRequest aParamRequest;
157 if (aRequest >>= aParamRequest)
158 { // it's an authentication request
159 implHandle(aParamRequest, aContinuations);
160 return;
163 DocumentSaveRequest aDocuRequest;
164 if (aRequest >>= aDocuRequest)
165 { // it's an document request
166 implHandle(aDocuRequest, aContinuations);
167 return;
170 OSL_VERIFY( implHandleUnknown( _rxRequest ) );
173 //-------------------------------------------------------------------------
174 void OInteractionHandler::implHandle(const ParametersRequest& _rParamRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
176 ::vos::OGuard aGuard(Application::GetSolarMutex());
177 // want to open a dialog ....
179 sal_Int32 nAbortPos = getContinuation(ABORT, _rContinuations);
180 sal_Int32 nParamPos = getContinuation(SUPPLY_PARAMETERS, _rContinuations);
182 Reference< XInteractionSupplyParameters > xParamCallback;
183 if (-1 != nParamPos)
184 xParamCallback = Reference< XInteractionSupplyParameters >(_rContinuations[nParamPos], UNO_QUERY);
185 DBG_ASSERT(xParamCallback.is(), "OInteractionHandler::implHandle(ParametersRequest): can't set the parameters without an appropriate interaction handler!s");
187 // determine the style of the dialog, dependent on the present continuation types
188 WinBits nDialogStyle = WB_OK | WB_DEF_OK;
189 if (-1 != nAbortPos)
190 nDialogStyle = WB_OK_CANCEL;
192 OParameterDialog aDlg(NULL, _rParamRequest.Parameters, _rParamRequest.Connection, m_xORB);
193 sal_Int16 nResult = aDlg.Execute();
196 switch (nResult)
198 case RET_OK:
199 if (xParamCallback.is())
201 xParamCallback->setParameters(aDlg.getValues());
202 xParamCallback->select();
204 break;
205 default:
206 if (-1 != nAbortPos)
207 _rContinuations[nAbortPos]->select();
208 break;
211 catch( const Exception& )
213 DBG_UNHANDLED_EXCEPTION();
217 //-------------------------------------------------------------------------
218 void OInteractionHandler::implHandle(const SQLExceptionInfo& _rSqlInfo, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
220 ::vos::OGuard aGuard(Application::GetSolarMutex());
221 // want to open a dialog ....
223 sal_Int32 nApprovePos = getContinuation(APPROVE, _rContinuations);
224 sal_Int32 nDisapprovePos = getContinuation(DISAPPROVE, _rContinuations);
225 sal_Int32 nAbortPos = getContinuation(ABORT, _rContinuations);
226 sal_Int32 nRetryPos = getContinuation(RETRY, _rContinuations);
228 // determine the style of the dialog, dependent on the present continuation types
229 WinBits nDialogStyle = 0;
230 bool bHaveCancel = nAbortPos != -1;
231 // "approve" means "Yes", "disapprove" means "No"
232 // VCL only supports having both (which makes sense ...)
233 if ( ( nApprovePos != -1 ) || ( nDisapprovePos != -1 ) )
234 nDialogStyle = ( bHaveCancel ? WB_YES_NO_CANCEL : WB_YES_NO ) | WB_DEF_YES;
235 else
237 // if there's no yes/no, then use a default OK button
238 nDialogStyle = ( bHaveCancel ? WB_OK_CANCEL : WB_OK ) | WB_DEF_OK;
241 // If there's a "Retry" continuation, have a "Retry" button
242 if ( nRetryPos != -1 )
244 nDialogStyle = WB_RETRY_CANCEL | WB_DEF_RETRY;
247 // excute the dialog
248 OSQLMessageBox aDialog(NULL, _rSqlInfo, nDialogStyle);
249 // TODO: need a way to specify the parent window
250 sal_Int16 nResult = aDialog.Execute();
253 switch (nResult)
255 case RET_YES:
256 case RET_OK:
257 if ( nApprovePos != -1 )
258 _rContinuations[ nApprovePos ]->select();
259 else
260 OSL_ENSURE( nResult != RET_YES, "OInteractionHandler::implHandle: no handler for YES!" );
261 break;
263 case RET_NO:
264 if ( nDisapprovePos != -1 )
265 _rContinuations[ nDisapprovePos ]->select();
266 else
267 OSL_ENSURE( false, "OInteractionHandler::implHandle: no handler for NO!" );
268 break;
270 case RET_CANCEL:
271 if ( nAbortPos != -1 )
272 _rContinuations[ nAbortPos ]->select();
273 else if ( nDisapprovePos != -1 )
274 _rContinuations[ nDisapprovePos ]->select();
275 else
276 OSL_ENSURE( false, "OInteractionHandler::implHandle: no handler for CANCEL!" );
277 break;
278 case RET_RETRY:
279 if ( nRetryPos != -1 )
280 _rContinuations[ nRetryPos ]->select();
281 else
282 OSL_ENSURE( false, "OInteractionHandler::implHandle: where does the RETRY come from?" );
283 break;
286 catch( const Exception& )
288 DBG_UNHANDLED_EXCEPTION();
291 //-------------------------------------------------------------------------
292 void OInteractionHandler::implHandle(const DocumentSaveRequest& _rDocuRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
294 ::vos::OGuard aGuard(Application::GetSolarMutex());
295 // want to open a dialog ....
297 sal_Int32 nApprovePos = getContinuation(APPROVE, _rContinuations);
298 sal_Int32 nDisApprovePos = getContinuation(DISAPPROVE, _rContinuations);
299 sal_Int32 nAbortPos = getContinuation(ABORT, _rContinuations);
301 short nRet = RET_YES;
302 if ( -1 != nApprovePos )
304 // fragen, ob gespeichert werden soll
305 nRet = ExecuteQuerySaveDocument(NULL,_rDocuRequest.Name);
308 if ( RET_CANCEL == nRet )
310 if (-1 != nAbortPos)
311 _rContinuations[nAbortPos]->select();
312 return;
314 else if ( RET_YES == nRet )
316 sal_Int32 nDocuPos = getContinuation(SUPPLY_DOCUMENTSAVE, _rContinuations);
318 if (-1 != nDocuPos)
320 Reference< XInteractionDocumentSave > xCallback(_rContinuations[nDocuPos], UNO_QUERY);
321 DBG_ASSERT(xCallback.is(), "OInteractionHandler::implHandle(DocumentSaveRequest): can't save document without an appropriate interaction handler!s");
323 // determine the style of the dialog, dependent on the present continuation types
324 WinBits nDialogStyle = WB_OK | WB_DEF_OK;
325 if (-1 != nAbortPos)
326 nDialogStyle = WB_OK_CANCEL;
328 OCollectionView aDlg(NULL,_rDocuRequest.Content,_rDocuRequest.Name,m_xORB);
329 sal_Int16 nResult = aDlg.Execute();
332 switch (nResult)
334 case RET_OK:
335 if (xCallback.is())
337 xCallback->setName(aDlg.getName(),aDlg.getSelectedFolder());
338 xCallback->select();
340 break;
341 default:
342 if (-1 != nAbortPos)
343 _rContinuations[nAbortPos]->select();
344 break;
347 catch( const Exception& )
349 DBG_UNHANDLED_EXCEPTION();
352 else if ( -1 != nApprovePos )
353 _rContinuations[nApprovePos]->select();
355 else if ( -1 != nDisApprovePos )
356 _rContinuations[nDisApprovePos]->select();
359 //-------------------------------------------------------------------------
360 bool OInteractionHandler::implHandleUnknown( const Reference< XInteractionRequest >& _rxRequest )
362 Reference< XInteractionHandler > xFallbackHandler;
363 if ( m_xORB.is() )
364 xFallbackHandler = xFallbackHandler.query( m_xORB->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ) );
365 if ( xFallbackHandler.is() )
367 xFallbackHandler->handle( _rxRequest );
368 return true;
370 return false;
373 //-------------------------------------------------------------------------
374 sal_Int32 OInteractionHandler::getContinuation(Continuation _eCont, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
376 const Reference< XInteractionContinuation >* pContinuations = _rContinuations.getConstArray();
377 for (sal_Int32 i=0; i<_rContinuations.getLength(); ++i, ++pContinuations)
379 switch (_eCont)
381 case APPROVE:
382 if (Reference< XInteractionApprove >(*pContinuations, UNO_QUERY).is())
383 return i;
384 break;
385 case DISAPPROVE:
386 if (Reference< XInteractionDisapprove >(*pContinuations, UNO_QUERY).is())
387 return i;
388 break;
389 case RETRY:
390 if (Reference< XInteractionRetry >(*pContinuations, UNO_QUERY).is())
391 return i;
392 break;
393 case ABORT:
394 if (Reference< XInteractionAbort >(*pContinuations, UNO_QUERY).is())
395 return i;
396 break;
397 case SUPPLY_PARAMETERS:
398 if (Reference< XInteractionSupplyParameters >(*pContinuations, UNO_QUERY).is())
399 return i;
400 break;
401 case SUPPLY_DOCUMENTSAVE:
402 if (Reference< XInteractionDocumentSave >(*pContinuations, UNO_QUERY).is())
403 return i;
404 break;
408 return -1;
412 //.........................................................................
413 } // namespace dbaui
414 //.........................................................................