LibreOffice Module dbaccess (master) 1
composerdialogs.cxx
Go to the documentation of this file.
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 <com/sun/star/awt/XWindow.hpp>
23#include <com/sun/star/beans/PropertyAttribute.hpp>
24#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
25#include <queryfilter.hxx>
26#include <queryorder.hxx>
27#include <strings.hxx>
30#include <osl/diagnose.h>
31#include <vcl/svapp.hxx>
32
33extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
35 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
36{
37 return cppu::acquire(new ::dbaui::RowsetOrderDialog(context));
38}
39extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
41 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
42{
43 return cppu::acquire(new ::dbaui::RowsetFilterDialog(context));
44}
45
46namespace dbaui
47{
48
49#define PROPERTY_ID_QUERYCOMPOSER 100
50#define PROPERTY_ID_ROWSET 101
51
52constexpr OUStringLiteral PROPERTY_QUERYCOMPOSER = u"QueryComposer";
53constexpr OUStringLiteral PROPERTY_ROWSET = u"RowSet";
54
55 using namespace ::com::sun::star::uno;
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::sdbcx;
60 using namespace ::com::sun::star::sdbc;
61 using namespace ::com::sun::star::sdb;
62
63 // ComposerDialog
65 :OGenericUnoDialog( _rxORB )
66 {
67
68 registerProperty( PROPERTY_QUERYCOMPOSER, PROPERTY_ID_QUERYCOMPOSER, PropertyAttribute::TRANSIENT,
69 &m_xComposer, cppu::UnoType<decltype(m_xComposer)>::get() );
70 registerProperty( PROPERTY_ROWSET, PROPERTY_ID_ROWSET, PropertyAttribute::TRANSIENT,
71 &m_xRowSet, cppu::UnoType<decltype(m_xRowSet)>::get() );
72 }
73
75 {
76
77 }
78
79 css::uno::Sequence<sal_Int8> ComposerDialog::getImplementationId()
80 {
81 return css::uno::Sequence<sal_Int8>();
82 }
83
84 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL ComposerDialog::getPropertySetInfo()
85 {
86 Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
87 return xInfo;
88 }
90 {
92 }
94 {
95 css::uno::Sequence< css::beans::Property > aProps;
96 describeProperties(aProps);
97 return new ::cppu::OPropertyArrayHelper(aProps);
98 }
99
100 std::unique_ptr<weld::DialogController> ComposerDialog::createDialog(const css::uno::Reference<css::awt::XWindow>& rParent)
101 {
102 // obtain all the objects needed for the dialog
103 Reference< XConnection > xConnection;
105 try
106 {
107 // the connection the row set is working with
108 if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet, xConnection ) )
109 {
110 Reference< XPropertySet > xRowsetProps( m_xRowSet, UNO_QUERY );
111 if ( xRowsetProps.is() )
112 xRowsetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConnection;
113 }
114
115 // fallback: if there is a connection and thus a row set, but no composer, create one
116 if ( xConnection.is() && !m_xComposer.is() )
117 m_xComposer = ::dbtools::getCurrentSettingsComposer( Reference< XPropertySet >( m_xRowSet, UNO_QUERY ), m_aContext, rParent );
118
119 // the columns of the row set
120 Reference< XColumnsSupplier > xSuppColumns( m_xRowSet, UNO_QUERY );
121 if ( xSuppColumns.is() )
122 xColumns = xSuppColumns->getColumns();
123
124 if ( !xColumns.is() || !xColumns->hasElements() )
125 { // perhaps the composer can supply us with columns? This is necessary for cases
126 // where the dialog is invoked for a rowset which is not yet loaded
127 // #i22878#
128 xSuppColumns.set(m_xComposer, css::uno::UNO_QUERY);
129 if ( xSuppColumns.is() )
130 xColumns = xSuppColumns->getColumns();
131 }
132
133 OSL_ENSURE( xColumns.is() && xColumns->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
134 }
135 catch( const Exception& )
136 {
137 DBG_UNHANDLED_EXCEPTION("dbaccess");
138 }
139
140 if ( !xConnection.is() || !xColumns.is() || !m_xComposer.is() )
141 {
142 // can't create the dialog if I have improper settings
143 return nullptr;
144 }
145
146 return createComposerDialog(Application::GetFrameWeld(rParent), xConnection, xColumns);
147 }
148
149 // RowsetFilterDialog
151 :ComposerDialog( _rxORB )
152 {
153 }
154
156 {
157 return "com.sun.star.uno.comp.sdb.RowsetFilterDialog";
158 }
159 sal_Bool SAL_CALL RowsetFilterDialog::supportsService(const OUString& _rServiceName)
160 {
161 const css::uno::Sequence< OUString > aSupported(getSupportedServiceNames());
162 for (const OUString& s : aSupported)
163 if (s == _rServiceName)
164 return true;
165
166 return false;
167 }
168 css::uno::Sequence< OUString > SAL_CALL RowsetFilterDialog::getSupportedServiceNames()
169 {
170 return { "com.sun.star.sdb.FilterDialog" };
171 }
172
173 std::unique_ptr<weld::GenericDialogController> RowsetFilterDialog::createComposerDialog(weld::Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
174 {
175 return std::make_unique<DlgFilterCrit>(_pParent, m_aContext, _rxConnection, m_xComposer, _rxColumns);
176 }
177
179 {
180 if( aArguments.getLength() == 3 )
181 {
182 // this is the FilterDialog::createWithQuery method
184 aArguments[0] >>= xQueryComposer;
186 aArguments[1] >>= xRowSet;
187 Reference<css::awt::XWindow> xParentWindow;
188 aArguments[2] >>= xParentWindow;
189 setPropertyValue( "QueryComposer", Any( xQueryComposer ) );
190 setPropertyValue( "RowSet", Any( xRowSet ) );
191 setPropertyValue( "ParentWindow", Any( xParentWindow ) );
192 }
193 else
195 }
196
197 void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult )
198 {
199 ComposerDialog::executedDialog( _nExecutionResult );
200
201 if ( _nExecutionResult && m_xDialog )
202 static_cast<DlgFilterCrit*>(m_xDialog.get())->BuildWherePart();
203 }
204
205 // RowsetOrderDialog
207 :ComposerDialog( _rxORB )
208 {
209 }
210
212 {
213 return "com.sun.star.uno.comp.sdb.RowsetOrderDialog";
214 }
215 sal_Bool SAL_CALL RowsetOrderDialog::supportsService(const OUString& _rServiceName)
216 {
217 const css::uno::Sequence< OUString > aSupported(getSupportedServiceNames());
218 for (const OUString& s : aSupported)
219 if (s == _rServiceName)
220 return true;
221
222 return false;
223 }
224 css::uno::Sequence< OUString > SAL_CALL RowsetOrderDialog::getSupportedServiceNames()
225 {
226 return { "com.sun.star.sdb.OrderDialog" };
227 }
228
229 std::unique_ptr<weld::GenericDialogController> RowsetOrderDialog::createComposerDialog(weld::Window* pParent, const Reference< XConnection >& rxConnection, const Reference< XNameAccess >& rxColumns)
230 {
231 return std::make_unique<DlgOrderCrit>(pParent, rxConnection, m_xComposer, rxColumns);
232 }
233
235 {
236 if (aArguments.getLength() == 2 || aArguments.getLength() == 3)
237 {
239 aArguments[0] >>= xQueryComposer;
241 aArguments[1] >>= xRowSet;
242 setPropertyValue( "QueryComposer", Any( xQueryComposer ) );
243 setPropertyValue( "RowSet", Any( xRowSet ) );
244 if (aArguments.getLength() == 3)
245 {
246 Reference<css::awt::XWindow> xParentWindow;
247 aArguments[2] >>= xParentWindow;
248 setPropertyValue("ParentWindow", Any(xParentWindow));
249 }
250 }
251 else
253 }
254
255 void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult )
256 {
257 ComposerDialog::executedDialog( _nExecutionResult );
258
259 if ( !m_xDialog )
260 return;
261
262 if ( _nExecutionResult )
263 static_cast<DlgOrderCrit*>(m_xDialog.get())->BuildOrderPart();
264 else if ( m_xComposer.is() )
265 m_xComposer->setOrder(static_cast<DlgOrderCrit*>(m_xDialog.get())->GetOriginalOrder());
266 }
267
268} // namespace dbaui
269
270/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
::cppu::IPropertyArrayHelper * getArrayHelper()
css::uno::Reference< css::sdbc::XRowSet > m_xRowSet
ComposerDialog(const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xComposer
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual ~ComposerDialog() override
virtual std::unique_ptr< weld::GenericDialogController > createComposerDialog(weld::Window *_pParent, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::container::XNameAccess > &_rxColumns)=0
virtual std::unique_ptr< weld::DialogController > createDialog(const css::uno::Reference< css::awt::XWindow > &rParent) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
const OUString & GetOriginalOrder() const
Definition: queryorder.hxx:74
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual void executedDialog(sal_Int16 _nExecutionResult) override
virtual std::unique_ptr< weld::GenericDialogController > createComposerDialog(weld::Window *_pParent, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::container::XNameAccess > &_rxColumns) override
RowsetFilterDialog(const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual std::unique_ptr< weld::GenericDialogController > createComposerDialog(weld::Window *_pParent, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::container::XNameAccess > &_rxColumns) override
RowsetOrderDialog(const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
virtual void executedDialog(sal_Int16 _nExecutionResult) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override=0
std::unique_ptr< weld::DialogController > m_xDialog
virtual void executedDialog(sal_Int16)
virtual OUString SAL_CALL getImplementationName() override=0
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
css::uno::Reference< css::uno::XComponentContext > m_aContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
#define PROPERTY_ID_QUERYCOMPOSER
#define PROPERTY_ID_ROWSET
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_uno_comp_sdb_RowsetFilterDialog_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_uno_comp_sdb_RowsetOrderDialog_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define DBG_UNHANDLED_EXCEPTION(...)
float u
Sequence< PropertyValue > aArguments
Definition: intercept.cxx:88
@ Exception
constexpr OUStringLiteral PROPERTY_QUERYCOMPOSER
constexpr OUStringLiteral PROPERTY_ROWSET
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
constexpr OUStringLiteral PROPERTY_ACTIVE_CONNECTION(u"ActiveConnection")
unsigned char sal_Bool