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