1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "composerdialogs.hxx"
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>
28 #include <connectivity/dbtools.hxx>
29 #include <comphelper/diagnose_ex.hxx>
30 #include <osl/diagnose.h>
31 #include <vcl/svapp.hxx>
33 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
34 com_sun_star_uno_comp_sdb_RowsetOrderDialog_get_implementation(
35 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
37 return cppu::acquire(new ::dbaui::RowsetOrderDialog(context
));
39 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
40 com_sun_star_uno_comp_sdb_RowsetFilterDialog_get_implementation(
41 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
43 return cppu::acquire(new ::dbaui::RowsetFilterDialog(context
));
49 #define PROPERTY_ID_QUERYCOMPOSER 100
50 #define PROPERTY_ID_ROWSET 101
52 constexpr OUStringLiteral PROPERTY_QUERYCOMPOSER
= u
"QueryComposer";
53 constexpr OUStringLiteral PROPERTY_ROWSET
= u
"RowSet";
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
;
64 ComposerDialog::ComposerDialog(const Reference
< XComponentContext
>& _rxORB
)
65 :OGenericUnoDialog( _rxORB
)
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() );
74 ComposerDialog::~ComposerDialog()
79 css::uno::Sequence
<sal_Int8
> ComposerDialog::getImplementationId()
81 return css::uno::Sequence
<sal_Int8
>();
84 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
ComposerDialog::getPropertySetInfo()
86 Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
89 ::cppu::IPropertyArrayHelper
& ComposerDialog::getInfoHelper()
91 return *ComposerDialog::getArrayHelper();
93 ::cppu::IPropertyArrayHelper
* ComposerDialog::createArrayHelper( ) const
95 css::uno::Sequence
< css::beans::Property
> aProps
;
96 describeProperties(aProps
);
97 return new ::cppu::OPropertyArrayHelper(aProps
);
100 std::unique_ptr
<weld::DialogController
> ComposerDialog::createDialog(const css::uno::Reference
<css::awt::XWindow
>& rParent
)
102 // obtain all the objects needed for the dialog
103 Reference
< XConnection
> xConnection
;
104 Reference
< XNameAccess
> xColumns
;
107 // the connection the row set is working with
108 if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet
, xConnection
) )
110 Reference
< XPropertySet
> xRowsetProps( m_xRowSet
, UNO_QUERY
);
111 if ( xRowsetProps
.is() )
112 xRowsetProps
->getPropertyValue( PROPERTY_ACTIVE_CONNECTION
) >>= xConnection
;
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
);
119 // the columns of the row set
120 Reference
< XColumnsSupplier
> xSuppColumns( m_xRowSet
, UNO_QUERY
);
121 if ( xSuppColumns
.is() )
122 xColumns
= xSuppColumns
->getColumns();
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
128 xSuppColumns
.set(m_xComposer
, css::uno::UNO_QUERY
);
129 if ( xSuppColumns
.is() )
130 xColumns
= xSuppColumns
->getColumns();
133 OSL_ENSURE( xColumns
.is() && xColumns
->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
135 catch( const Exception
& )
137 DBG_UNHANDLED_EXCEPTION("dbaccess");
140 if ( !xConnection
.is() || !xColumns
.is() || !m_xComposer
.is() )
142 // can't create the dialog if I have improper settings
146 return createComposerDialog(Application::GetFrameWeld(rParent
), xConnection
, xColumns
);
149 // RowsetFilterDialog
150 RowsetFilterDialog::RowsetFilterDialog( const Reference
< XComponentContext
>& _rxORB
)
151 :ComposerDialog( _rxORB
)
155 OUString SAL_CALL
RowsetFilterDialog::getImplementationName()
157 return "com.sun.star.uno.comp.sdb.RowsetFilterDialog";
159 sal_Bool SAL_CALL
RowsetFilterDialog::supportsService(const OUString
& _rServiceName
)
161 const css::uno::Sequence
< OUString
> aSupported(getSupportedServiceNames());
162 for (const OUString
& s
: aSupported
)
163 if (s
== _rServiceName
)
168 css::uno::Sequence
< OUString
> SAL_CALL
RowsetFilterDialog::getSupportedServiceNames()
170 return { "com.sun.star.sdb.FilterDialog" };
173 std::unique_ptr
<weld::GenericDialogController
> RowsetFilterDialog::createComposerDialog(weld::Window
* _pParent
, const Reference
< XConnection
>& _rxConnection
, const Reference
< XNameAccess
>& _rxColumns
)
175 return std::make_unique
<DlgFilterCrit
>(_pParent
, m_aContext
, _rxConnection
, m_xComposer
, _rxColumns
);
178 void SAL_CALL
RowsetFilterDialog::initialize( const Sequence
< Any
>& aArguments
)
180 if( aArguments
.getLength() == 3 )
182 // this is the FilterDialog::createWithQuery method
183 Reference
<css::sdb::XSingleSelectQueryComposer
> xQueryComposer
;
184 aArguments
[0] >>= xQueryComposer
;
185 Reference
<css::sdbc::XRowSet
> xRowSet
;
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
) );
194 ComposerDialog::initialize(aArguments
);
197 void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult
)
199 ComposerDialog::executedDialog( _nExecutionResult
);
201 if ( _nExecutionResult
&& m_xDialog
)
202 static_cast<DlgFilterCrit
*>(m_xDialog
.get())->BuildWherePart();
206 RowsetOrderDialog::RowsetOrderDialog( const Reference
< XComponentContext
>& _rxORB
)
207 :ComposerDialog( _rxORB
)
211 OUString SAL_CALL
RowsetOrderDialog::getImplementationName()
213 return "com.sun.star.uno.comp.sdb.RowsetOrderDialog";
215 sal_Bool SAL_CALL
RowsetOrderDialog::supportsService(const OUString
& _rServiceName
)
217 const css::uno::Sequence
< OUString
> aSupported(getSupportedServiceNames());
218 for (const OUString
& s
: aSupported
)
219 if (s
== _rServiceName
)
224 css::uno::Sequence
< OUString
> SAL_CALL
RowsetOrderDialog::getSupportedServiceNames()
226 return { "com.sun.star.sdb.OrderDialog" };
229 std::unique_ptr
<weld::GenericDialogController
> RowsetOrderDialog::createComposerDialog(weld::Window
* pParent
, const Reference
< XConnection
>& rxConnection
, const Reference
< XNameAccess
>& rxColumns
)
231 return std::make_unique
<DlgOrderCrit
>(pParent
, rxConnection
, m_xComposer
, rxColumns
);
234 void SAL_CALL
RowsetOrderDialog::initialize( const Sequence
< Any
>& aArguments
)
236 if (aArguments
.getLength() == 2 || aArguments
.getLength() == 3)
238 Reference
<css::sdb::XSingleSelectQueryComposer
> xQueryComposer
;
239 aArguments
[0] >>= xQueryComposer
;
240 Reference
<css::beans::XPropertySet
> xRowSet
;
241 aArguments
[1] >>= xRowSet
;
242 setPropertyValue( "QueryComposer", Any( xQueryComposer
) );
243 setPropertyValue( "RowSet", Any( xRowSet
) );
244 if (aArguments
.getLength() == 3)
246 Reference
<css::awt::XWindow
> xParentWindow
;
247 aArguments
[2] >>= xParentWindow
;
248 setPropertyValue("ParentWindow", Any(xParentWindow
));
252 ComposerDialog::initialize(aArguments
);
255 void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult
)
257 ComposerDialog::executedDialog( _nExecutionResult
);
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());
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */