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"
21 #include "uiservices.hxx"
23 #include "dbu_reghelper.hxx"
24 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
25 #include "dbustrings.hrc"
26 #include "queryfilter.hxx"
27 #include "queryorder.hxx"
28 #include <comphelper/processfactory.hxx>
29 #include <connectivity/dbtools.hxx>
30 #include <tools/diagnose_ex.h>
31 #include <osl/diagnose.h>
33 extern "C" void SAL_CALL
createRegistryInfo_ComposerDialogs()
35 static ::dbaui::OMultiInstanceAutoRegistration
< ::dbaui::RowsetOrderDialog
> aOrderDialogRegistration
;
36 static ::dbaui::OMultiInstanceAutoRegistration
< ::dbaui::RowsetFilterDialog
> aFilterDialogRegistration
;
42 #define PROPERTY_ID_QUERYCOMPOSER 100
43 #define PROPERTY_ID_ROWSET 101
45 #define PROPERTY_QUERYCOMPOSER "QueryComposer"
46 #define PROPERTY_ROWSET "RowSet"
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::lang
;
50 using namespace ::com::sun::star::beans
;
51 using namespace ::com::sun::star::container
;
52 using namespace ::com::sun::star::sdbcx
;
53 using namespace ::com::sun::star::sdbc
;
54 using namespace ::com::sun::star::sdb
;
57 ComposerDialog::ComposerDialog(const Reference
< XComponentContext
>& _rxORB
)
58 :OGenericUnoDialog( _rxORB
)
61 registerProperty( PROPERTY_QUERYCOMPOSER
, PROPERTY_ID_QUERYCOMPOSER
, PropertyAttribute::TRANSIENT
,
62 &m_xComposer
, cppu::UnoType
<decltype(m_xComposer
)>::get() );
63 registerProperty( PROPERTY_ROWSET
, PROPERTY_ID_ROWSET
, PropertyAttribute::TRANSIENT
,
64 &m_xRowSet
, cppu::UnoType
<decltype(m_xRowSet
)>::get() );
67 ComposerDialog::~ComposerDialog()
72 css::uno::Sequence
<sal_Int8
> ComposerDialog::getImplementationId()
73 throw (css::uno::RuntimeException
, std::exception
)
75 return css::uno::Sequence
<sal_Int8
>();
78 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ComposerDialog
)
80 VclPtr
<Dialog
> ComposerDialog::createDialog(vcl::Window
* _pParent
)
82 // obtain all the objects needed for the dialog
83 Reference
< XConnection
> xConnection
;
84 Reference
< XNameAccess
> xColumns
;
87 // the connection the row set is working with
88 if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet
, xConnection
) )
90 Reference
< XPropertySet
> xRowsetProps( m_xRowSet
, UNO_QUERY
);
91 if ( xRowsetProps
.is() )
92 xRowsetProps
->getPropertyValue( PROPERTY_ACTIVE_CONNECTION
) >>= xConnection
;
95 // fallback: if there is a connection and thus a row set, but no composer, create one
96 if ( xConnection
.is() && !m_xComposer
.is() )
97 m_xComposer
= ::dbtools::getCurrentSettingsComposer( Reference
< XPropertySet
>( m_xRowSet
, UNO_QUERY
), m_aContext
);
99 // the columns of the row set
100 Reference
< XColumnsSupplier
> xSuppColumns( m_xRowSet
, UNO_QUERY
);
101 if ( xSuppColumns
.is() )
102 xColumns
= xSuppColumns
->getColumns();
104 if ( !xColumns
.is() || !xColumns
->hasElements() )
105 { // perhaps the composer can supply us with columns? This is necessary for cases
106 // where the dialog is invoked for a rowset which is not yet loaded
108 xSuppColumns
.set(m_xComposer
, css::uno::UNO_QUERY
);
109 if ( xSuppColumns
.is() )
110 xColumns
= xSuppColumns
->getColumns();
113 OSL_ENSURE( xColumns
.is() && xColumns
->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
115 catch( const Exception
& )
117 DBG_UNHANDLED_EXCEPTION();
120 if ( !xConnection
.is() || !xColumns
.is() || !m_xComposer
.is() )
121 // can't create the dialog if I have improper settings
124 return createComposerDialog( _pParent
, xConnection
, xColumns
);
127 // RowsetFilterDialog
128 RowsetFilterDialog::RowsetFilterDialog( const Reference
< XComponentContext
>& _rxORB
)
129 :ComposerDialog( _rxORB
)
133 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(RowsetFilterDialog
, "com.sun.star.uno.comp.sdb.RowsetFilterDialog")
134 IMPLEMENT_SERVICE_INFO_SUPPORTS(RowsetFilterDialog
)
135 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(RowsetFilterDialog
, "com.sun.star.sdb.FilterDialog")
137 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
138 SAL_CALL
RowsetFilterDialog::Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxORB
)
140 return static_cast< XServiceInfo
* >(new RowsetFilterDialog( comphelper::getComponentContext(_rxORB
)));
143 VclPtr
<Dialog
> RowsetFilterDialog::createComposerDialog( vcl::Window
* _pParent
, const Reference
< XConnection
>& _rxConnection
, const Reference
< XNameAccess
>& _rxColumns
)
145 return VclPtr
<DlgFilterCrit
>::Create( _pParent
, m_aContext
, _rxConnection
, m_xComposer
, _rxColumns
);
148 void SAL_CALL
RowsetFilterDialog::initialize( const Sequence
< Any
>& aArguments
) throw (Exception
, RuntimeException
, std::exception
)
150 if( aArguments
.getLength() == 3 )
152 // this is the FilterDialog::createWithQuery method
153 Reference
<com::sun::star::sdb::XSingleSelectQueryComposer
> xQueryComposer
;
154 aArguments
[0] >>= xQueryComposer
;
155 Reference
<com::sun::star::sdbc::XRowSet
> xRowSet
;
156 aArguments
[1] >>= xRowSet
;
157 Reference
<com::sun::star::awt::XWindow
> xParentWindow
;
158 aArguments
[2] >>= xParentWindow
;
159 setPropertyValue( "QueryComposer", makeAny( xQueryComposer
) );
160 setPropertyValue( "RowSet", makeAny( xRowSet
) );
161 setPropertyValue( "ParentWindow", makeAny( xParentWindow
) );
164 ComposerDialog::initialize(aArguments
);
167 void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult
)
169 ComposerDialog::executedDialog( _nExecutionResult
);
171 if ( _nExecutionResult
&& m_pDialog
)
172 static_cast< DlgFilterCrit
* >( m_pDialog
.get() )->BuildWherePart();
176 RowsetOrderDialog::RowsetOrderDialog( const Reference
< XComponentContext
>& _rxORB
)
177 :ComposerDialog( _rxORB
)
181 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(RowsetOrderDialog
, "com.sun.star.uno.comp.sdb.RowsetOrderDialog")
182 IMPLEMENT_SERVICE_INFO_SUPPORTS(RowsetOrderDialog
)
183 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(RowsetOrderDialog
, "com.sun.star.sdb.OrderDialog")
185 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
186 SAL_CALL
RowsetOrderDialog::Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxORB
)
188 return static_cast< XServiceInfo
* >(new RowsetOrderDialog( comphelper::getComponentContext(_rxORB
)));
191 VclPtr
<Dialog
> RowsetOrderDialog::createComposerDialog( vcl::Window
* _pParent
, const Reference
< XConnection
>& _rxConnection
, const Reference
< XNameAccess
>& _rxColumns
)
193 return VclPtr
<DlgOrderCrit
>::Create( _pParent
, _rxConnection
, m_xComposer
, _rxColumns
);
196 void SAL_CALL
RowsetOrderDialog::initialize( const Sequence
< Any
>& aArguments
) throw (Exception
, RuntimeException
, std::exception
)
198 if( aArguments
.getLength() == 2 )
200 Reference
<com::sun::star::sdb::XSingleSelectQueryComposer
> xQueryComposer
;
201 aArguments
[0] >>= xQueryComposer
;
202 Reference
<com::sun::star::beans::XPropertySet
> xRowSet
;
203 aArguments
[1] >>= xRowSet
;
204 setPropertyValue( "QueryComposer", makeAny( xQueryComposer
) );
205 setPropertyValue( "RowSet", makeAny( xRowSet
) );
208 ComposerDialog::initialize(aArguments
);
211 void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult
)
213 ComposerDialog::executedDialog( _nExecutionResult
);
218 if ( _nExecutionResult
)
219 static_cast< DlgOrderCrit
* >( m_pDialog
.get() )->BuildOrderPart();
220 else if ( m_xComposer
.is() )
221 m_xComposer
->setOrder( static_cast< DlgOrderCrit
* >( m_pDialog
.get() )->GetOrignalOrder() );
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */