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 "sqlmessage.hxx"
21 : #include "unosqlmessage.hxx"
22 : #include "dbu_reghelper.hxx"
23 : #include "dbustrings.hrc"
24 : #include <comphelper/processfactory.hxx>
25 : #include <cppuhelper/typeprovider.hxx>
26 : #include <connectivity/dbexception.hxx>
27 :
28 : using namespace dbaui;
29 : using namespace dbtools;
30 :
31 : using namespace ::com::sun::star::sdbc;
32 : using namespace ::com::sun::star::sdb;
33 :
34 0 : extern "C" void SAL_CALL createRegistryInfo_OSQLMessageDialog()
35 : {
36 0 : static OMultiInstanceAutoRegistration< OSQLMessageDialog > aAutoRegistration;
37 0 : }
38 :
39 : namespace dbaui
40 : {
41 :
42 : using namespace ::com::sun::star::uno;
43 : using namespace ::com::sun::star::lang;
44 : using namespace ::com::sun::star::beans;
45 :
46 0 : OSQLMessageDialog::OSQLMessageDialog(const Reference< XComponentContext >& _rxORB)
47 0 : :OSQLMessageDialogBase(_rxORB)
48 : {
49 : registerMayBeVoidProperty(PROPERTY_SQLEXCEPTION, PROPERTY_ID_SQLEXCEPTION, PropertyAttribute::TRANSIENT | PropertyAttribute::MAYBEVOID,
50 0 : &m_aException, ::getCppuType(static_cast<SQLException*>(NULL)));
51 : registerProperty( PROPERTY_HELP_URL, PROPERTY_ID_HELP_URL, PropertyAttribute::TRANSIENT,
52 0 : &m_sHelpURL, ::getCppuType( &m_sHelpURL ) );
53 0 : }
54 :
55 0 : Sequence<sal_Int8> SAL_CALL OSQLMessageDialog::getImplementationId( ) throw(RuntimeException, std::exception)
56 : {
57 0 : return css::uno::Sequence<sal_Int8>();
58 : }
59 :
60 0 : Reference< XInterface > SAL_CALL OSQLMessageDialog::Create(const Reference< XMultiServiceFactory >& _rxFactory)
61 : {
62 0 : return *(new OSQLMessageDialog( comphelper::getComponentContext(_rxFactory) ));
63 : }
64 :
65 0 : OUString SAL_CALL OSQLMessageDialog::getImplementationName() throw(RuntimeException, std::exception)
66 : {
67 0 : return getImplementationName_Static();
68 : }
69 :
70 0 : OUString OSQLMessageDialog::getImplementationName_Static() throw(RuntimeException)
71 : {
72 0 : return OUString("org.openoffice.comp.dbu.OSQLMessageDialog");
73 : }
74 :
75 0 : ::comphelper::StringSequence SAL_CALL OSQLMessageDialog::getSupportedServiceNames() throw(RuntimeException, std::exception)
76 : {
77 0 : return getSupportedServiceNames_Static();
78 : }
79 :
80 0 : ::comphelper::StringSequence OSQLMessageDialog::getSupportedServiceNames_Static() throw(RuntimeException)
81 : {
82 0 : ::comphelper::StringSequence aSupported(1);
83 0 : aSupported.getArray()[0] = "com.sun.star.sdb.ErrorMessageDialog";
84 0 : return aSupported;
85 : }
86 :
87 0 : void OSQLMessageDialog::initialize(Sequence<Any> const & args) throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException, std::exception)
88 : {
89 0 : OUString title;
90 0 : Reference< com::sun::star::awt::XWindow > parentWindow;
91 0 : com::sun::star::uno::Any sqlException;
92 :
93 0 : if ((args.getLength() == 3) && (args[0] >>= title) && (args[1] >>= parentWindow) && (args[2] >>= sqlException)) {
94 0 : Sequence<Any> s(3);
95 0 : s[0] <<= PropertyValue( "Title", -1, makeAny(title), PropertyState_DIRECT_VALUE);
96 0 : s[1] <<= PropertyValue( "ParentWindow", -1, makeAny(parentWindow), PropertyState_DIRECT_VALUE);
97 0 : s[2] <<= PropertyValue( "SQLException", -1, sqlException, PropertyState_DIRECT_VALUE);
98 0 : OGenericUnoDialog::initialize(s);
99 : } else {
100 0 : OGenericUnoDialog::initialize(args);
101 0 : }
102 0 : }
103 :
104 0 : sal_Bool SAL_CALL OSQLMessageDialog::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue) throw(IllegalArgumentException)
105 : {
106 0 : switch (_nHandle)
107 : {
108 : case PROPERTY_ID_SQLEXCEPTION:
109 : {
110 0 : SQLExceptionInfo aInfo(_rValue);
111 0 : if (!aInfo.isValid())
112 0 : throw IllegalArgumentException();
113 :
114 0 : _rOldValue = m_aException;
115 0 : _rConvertedValue = aInfo.get();
116 :
117 0 : return sal_True;
118 : // always assume "modified", don't bother with with comparing the two values
119 : }
120 : default:
121 0 : return OSQLMessageDialogBase::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue);
122 : }
123 : }
124 :
125 0 : Reference<XPropertySetInfo> SAL_CALL OSQLMessageDialog::getPropertySetInfo() throw(RuntimeException, std::exception)
126 : {
127 0 : Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
128 0 : return xInfo;
129 : }
130 :
131 0 : ::cppu::IPropertyArrayHelper& OSQLMessageDialog::getInfoHelper()
132 : {
133 0 : return *const_cast<OSQLMessageDialog*>(this)->getArrayHelper();
134 : }
135 :
136 0 : ::cppu::IPropertyArrayHelper* OSQLMessageDialog::createArrayHelper( ) const
137 : {
138 0 : Sequence< Property > aProps;
139 0 : describeProperties(aProps);
140 0 : return new ::cppu::OPropertyArrayHelper(aProps);
141 : }
142 :
143 0 : Dialog* OSQLMessageDialog::createDialog(Window* _pParent)
144 : {
145 0 : if ( m_aException.hasValue() )
146 0 : return new OSQLMessageBox( _pParent, SQLExceptionInfo( m_aException ), WB_OK | WB_DEF_OK, m_sHelpURL );
147 :
148 : OSL_FAIL("OSQLMessageDialog::createDialog : You should use the SQLException property to specify the error to display!");
149 0 : return new OSQLMessageBox(_pParent, SQLException());
150 : }
151 :
152 : } // namespace dbaui
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|