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 "composerdialogs.hxx"
21 :
22 : #include "dbu_reghelper.hxx"
23 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
24 : #include "dbustrings.hrc"
25 : #include "queryfilter.hxx"
26 : #include "queryorder.hxx"
27 : #include <comphelper/processfactory.hxx>
28 : #include <connectivity/dbtools.hxx>
29 : #include <tools/diagnose_ex.h>
30 : #include <osl/diagnose.h>
31 :
32 0 : extern "C" void SAL_CALL createRegistryInfo_ComposerDialogs()
33 : {
34 0 : static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetOrderDialog > aOrderDialogRegistration;
35 0 : static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetFilterDialog > aFilterDialogRegistration;
36 0 : }
37 :
38 : namespace dbaui
39 : {
40 :
41 : #define PROPERTY_ID_QUERYCOMPOSER 100
42 : #define PROPERTY_ID_ROWSET 101
43 :
44 : #define PROPERTY_QUERYCOMPOSER "QueryComposer"
45 : #define PROPERTY_ROWSET "RowSet"
46 :
47 : using namespace ::com::sun::star::uno;
48 : using namespace ::com::sun::star::lang;
49 : using namespace ::com::sun::star::beans;
50 : using namespace ::com::sun::star::container;
51 : using namespace ::com::sun::star::sdbcx;
52 : using namespace ::com::sun::star::sdbc;
53 : using namespace ::com::sun::star::sdb;
54 :
55 : // ComposerDialog
56 0 : ComposerDialog::ComposerDialog(const Reference< XComponentContext >& _rxORB)
57 0 : :OGenericUnoDialog( _rxORB )
58 : {
59 :
60 : registerProperty( PROPERTY_QUERYCOMPOSER, PROPERTY_ID_QUERYCOMPOSER, PropertyAttribute::TRANSIENT,
61 0 : &m_xComposer, ::getCppuType( &m_xComposer ) );
62 : registerProperty( PROPERTY_ROWSET, PROPERTY_ID_ROWSET, PropertyAttribute::TRANSIENT,
63 0 : &m_xRowSet, ::getCppuType( &m_xRowSet ) );
64 0 : }
65 :
66 0 : ComposerDialog::~ComposerDialog()
67 : {
68 :
69 0 : }
70 :
71 0 : css::uno::Sequence<sal_Int8> ComposerDialog::getImplementationId()
72 : throw (css::uno::RuntimeException, std::exception)
73 : {
74 0 : return css::uno::Sequence<sal_Int8>();
75 : }
76 :
77 0 : IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ComposerDialog )
78 :
79 0 : Dialog* ComposerDialog::createDialog(Window* _pParent)
80 : {
81 : // obtain all the objects needed for the dialog
82 0 : Reference< XConnection > xConnection;
83 0 : Reference< XNameAccess > xColumns;
84 : try
85 : {
86 : // the connection the row set is working with
87 0 : if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet, xConnection ) )
88 : {
89 0 : Reference< XPropertySet > xRowsetProps( m_xRowSet, UNO_QUERY );
90 0 : if ( xRowsetProps.is() )
91 0 : xRowsetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConnection;
92 : }
93 :
94 : // fallback: if there is a connection and thus a row set, but no composer, create one
95 0 : if ( xConnection.is() && !m_xComposer.is() )
96 0 : m_xComposer = ::dbtools::getCurrentSettingsComposer( Reference< XPropertySet >( m_xRowSet, UNO_QUERY ), m_aContext );
97 :
98 : // the columns of the row set
99 0 : Reference< XColumnsSupplier > xSuppColumns( m_xRowSet, UNO_QUERY );
100 0 : if ( xSuppColumns.is() )
101 0 : xColumns = xSuppColumns->getColumns();
102 :
103 0 : if ( !xColumns.is() || !xColumns->hasElements() )
104 : { // perhaps the composer can supply us with columns? This is necessary for cases
105 : // where the dialog is invoked for a rowset which is not yet loaded
106 : // #i22878#
107 0 : xSuppColumns = xSuppColumns.query( m_xComposer );
108 0 : if ( xSuppColumns.is() )
109 0 : xColumns = xSuppColumns->getColumns();
110 : }
111 :
112 0 : OSL_ENSURE( xColumns.is() && xColumns->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
113 : }
114 0 : catch( const Exception& )
115 : {
116 : DBG_UNHANDLED_EXCEPTION();
117 : }
118 :
119 0 : if ( !xConnection.is() || !xColumns.is() || !m_xComposer.is() )
120 : // can't create the dialog if I have improper settings
121 0 : return NULL;
122 :
123 0 : return createComposerDialog( _pParent, xConnection, xColumns );
124 : }
125 :
126 : // RowsetFilterDialog
127 0 : RowsetFilterDialog::RowsetFilterDialog( const Reference< XComponentContext >& _rxORB )
128 0 : :ComposerDialog( _rxORB )
129 : {
130 0 : }
131 :
132 0 : IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(RowsetFilterDialog, "com.sun.star.uno.comp.sdb.RowsetFilterDialog")
133 0 : IMPLEMENT_SERVICE_INFO_SUPPORTS(RowsetFilterDialog)
134 0 : IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(RowsetFilterDialog, "com.sun.star.sdb.FilterDialog")
135 :
136 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
137 0 : SAL_CALL RowsetFilterDialog::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB)
138 : {
139 0 : return static_cast< XServiceInfo* >(new RowsetFilterDialog( comphelper::getComponentContext(_rxORB)));
140 : }
141 :
142 0 : Dialog* RowsetFilterDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
143 : {
144 0 : return new DlgFilterCrit( _pParent, m_aContext, _rxConnection, m_xComposer, _rxColumns );
145 : }
146 :
147 0 : void SAL_CALL RowsetFilterDialog::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException, std::exception)
148 : {
149 0 : if( aArguments.getLength() == 3 )
150 : {
151 : // this is the FilterDialog::createWithQuery method
152 0 : Reference<com::sun::star::sdb::XSingleSelectQueryComposer> xQueryComposer;
153 0 : aArguments[0] >>= xQueryComposer;
154 0 : Reference<com::sun::star::sdbc::XRowSet> xRowSet;
155 0 : aArguments[1] >>= xRowSet;
156 0 : Reference<com::sun::star::awt::XWindow> xParentWindow;
157 0 : aArguments[2] >>= xParentWindow;
158 0 : setPropertyValue( "QueryComposer", makeAny( xQueryComposer ) );
159 0 : setPropertyValue( "RowSet", makeAny( xRowSet ) );
160 0 : setPropertyValue( "ParentWindow", makeAny( xParentWindow ) );
161 : }
162 : else
163 0 : ComposerDialog::initialize(aArguments);
164 0 : }
165 :
166 0 : void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult )
167 : {
168 0 : ComposerDialog::executedDialog( _nExecutionResult );
169 :
170 0 : if ( _nExecutionResult && m_pDialog )
171 0 : static_cast< DlgFilterCrit* >( m_pDialog )->BuildWherePart();
172 0 : }
173 :
174 : // RowsetOrderDialog
175 0 : RowsetOrderDialog::RowsetOrderDialog( const Reference< XComponentContext >& _rxORB )
176 0 : :ComposerDialog( _rxORB )
177 : {
178 0 : }
179 :
180 0 : IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(RowsetOrderDialog, "com.sun.star.uno.comp.sdb.RowsetOrderDialog")
181 0 : IMPLEMENT_SERVICE_INFO_SUPPORTS(RowsetOrderDialog)
182 0 : IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(RowsetOrderDialog, "com.sun.star.sdb.OrderDialog")
183 :
184 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
185 0 : SAL_CALL RowsetOrderDialog::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB)
186 : {
187 0 : return static_cast< XServiceInfo* >(new RowsetOrderDialog( comphelper::getComponentContext(_rxORB)));
188 : }
189 :
190 0 : Dialog* RowsetOrderDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
191 : {
192 0 : return new DlgOrderCrit( _pParent, _rxConnection, m_xComposer, _rxColumns );
193 : }
194 :
195 0 : void SAL_CALL RowsetOrderDialog::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException, std::exception)
196 : {
197 0 : if( aArguments.getLength() == 2 )
198 : {
199 0 : Reference<com::sun::star::sdb::XSingleSelectQueryComposer> xQueryComposer;
200 0 : aArguments[0] >>= xQueryComposer;
201 0 : Reference<com::sun::star::beans::XPropertySet> xRowSet;
202 0 : aArguments[1] >>= xRowSet;
203 0 : setPropertyValue( "QueryComposer", makeAny( xQueryComposer ) );
204 0 : setPropertyValue( "RowSet", makeAny( xRowSet ) );
205 : }
206 : else
207 0 : ComposerDialog::initialize(aArguments);
208 0 : }
209 :
210 0 : void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult )
211 : {
212 0 : ComposerDialog::executedDialog( _nExecutionResult );
213 :
214 0 : if ( !m_pDialog )
215 0 : return;
216 :
217 0 : if ( _nExecutionResult )
218 0 : static_cast< DlgOrderCrit* >( m_pDialog )->BuildOrderPart();
219 0 : else if ( m_xComposer.is() )
220 0 : m_xComposer->setOrder( static_cast< DlgOrderCrit* >( m_pDialog )->GetOrignalOrder() );
221 : }
222 :
223 : } // namespace dbaui
224 :
225 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|