xref: /trunk/main/dbaccess/source/ui/uno/composerdialogs.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #ifndef DBACCESS_SOURCE_UI_UNO_COMPOSERDIALOGS_HXX
32 #include "composerdialogs.hxx"
33 #endif
34 
35 /** === begin UNO includes === **/
36 #ifndef _DBU_REGHELPER_HXX_
37 #include "dbu_reghelper.hxx"
38 #endif
39 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
40 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
41 #endif
42 /** === end UNO includes === **/
43 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
44 #include "dbustrings.hrc"
45 #endif
46 #ifndef DBAUI_QUERYFILTER_HXX
47 #include "queryfilter.hxx"
48 #endif
49 #ifndef DBAUI_QUERYORDER_HXX
50 #include "queryorder.hxx"
51 #endif
52 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
53 #include <connectivity/dbtools.hxx>
54 #endif
55 #ifndef _TOOLS_DEBUG_HXX
56 #include <tools/debug.hxx>
57 #endif
58 #ifndef TOOLS_DIAGNOSE_EX_H
59 #include <tools/diagnose_ex.h>
60 #endif
61 
62 extern "C" void SAL_CALL createRegistryInfo_ComposerDialogs()
63 {
64     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetOrderDialog > aOrderDialogRegistration;
65     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetFilterDialog > aFilterDialogRegistration;
66 }
67 
68 //.........................................................................
69 namespace dbaui
70 {
71 //.........................................................................
72 
73 #define PROPERTY_ID_QUERYCOMPOSER       100
74 #define PROPERTY_ID_ROWSET              101
75 
76     IMPLEMENT_CONSTASCII_USTRING( PROPERTY_QUERYCOMPOSER,   "QueryComposer" );
77     IMPLEMENT_CONSTASCII_USTRING( PROPERTY_ROWSET,          "RowSet" );
78 
79     using namespace ::com::sun::star::uno;
80     using namespace ::com::sun::star::lang;
81     using namespace ::com::sun::star::beans;
82     using namespace ::com::sun::star::container;
83     using namespace ::com::sun::star::sdbcx;
84     using namespace ::com::sun::star::sdbc;
85     using namespace ::com::sun::star::sdb;
86 
87     //=====================================================================
88     //= ComposerDialog
89     //=====================================================================
90     DBG_NAME(ComposerDialog)
91     //---------------------------------------------------------------------
92     ComposerDialog::ComposerDialog(const Reference< XMultiServiceFactory >& _rxORB)
93         :ComposerDialog_BASE( _rxORB )
94     {
95         DBG_CTOR(ComposerDialog,NULL);
96 
97         registerProperty( PROPERTY_QUERYCOMPOSER, PROPERTY_ID_QUERYCOMPOSER, PropertyAttribute::TRANSIENT,
98             &m_xComposer, ::getCppuType( &m_xComposer ) );
99         registerProperty( PROPERTY_ROWSET, PROPERTY_ID_ROWSET, PropertyAttribute::TRANSIENT,
100             &m_xRowSet, ::getCppuType( &m_xRowSet ) );
101     }
102 
103     //---------------------------------------------------------------------
104     ComposerDialog::~ComposerDialog()
105     {
106 
107         DBG_DTOR(ComposerDialog,NULL);
108     }
109 
110     //---------------------------------------------------------------------
111     IMPLEMENT_IMPLEMENTATION_ID( ComposerDialog )
112 
113     //---------------------------------------------------------------------
114     IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ComposerDialog )
115 
116     //---------------------------------------------------------------------
117     Dialog* ComposerDialog::createDialog(Window* _pParent)
118     {
119         // obtain all the objects needed for the dialog
120         Reference< XConnection > xConnection;
121         Reference< XNameAccess > xColumns;
122         try
123         {
124             // the connection the row set is working with
125             if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet, xConnection ) )
126             {
127                 Reference< XPropertySet > xRowsetProps( m_xRowSet, UNO_QUERY );
128                 if ( xRowsetProps.is() )
129                     xRowsetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConnection;
130             }
131 
132             // fallback: if there is a connection and thus a row set, but no composer, create one
133             if ( xConnection.is() && !m_xComposer.is() )
134                 m_xComposer = ::dbtools::getCurrentSettingsComposer( Reference< XPropertySet >( m_xRowSet, UNO_QUERY ), m_aContext.getLegacyServiceFactory() );
135 
136             // the columns of the row set
137             Reference< XColumnsSupplier > xSuppColumns( m_xRowSet, UNO_QUERY );
138             if ( xSuppColumns.is() )
139                 xColumns = xSuppColumns->getColumns();
140 
141             if ( !xColumns.is() || !xColumns->hasElements() )
142             {   // perhaps the composer can supply us with columns? This is necessary for cases
143                 // where the dialog is invoked for a rowset which is not yet loaded
144                 // #i22878# - 2003-12-16 - fs@openoffice.org
145                 xSuppColumns = xSuppColumns.query( m_xComposer );
146                 if ( xSuppColumns.is() )
147                     xColumns = xSuppColumns->getColumns();
148             }
149 
150             DBG_ASSERT( xColumns.is() && xColumns->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
151         }
152         catch( const Exception& )
153         {
154             DBG_UNHANDLED_EXCEPTION();
155         }
156 
157         if ( !xConnection.is() || !xColumns.is() || !m_xComposer.is() )
158             // can't create the dialog if I have improper settings
159             return NULL;
160 
161         return createComposerDialog( _pParent, xConnection, xColumns );
162     }
163 
164     //=====================================================================
165     //= RowsetFilterDialog
166     //=====================================================================
167     //---------------------------------------------------------------------
168     RowsetFilterDialog::RowsetFilterDialog( const Reference< XMultiServiceFactory >& _rxORB )
169         :ComposerDialog( _rxORB )
170     {
171     }
172 
173     //---------------------------------------------------------------------
174     IMPLEMENT_SERVICE_INFO1_STATIC( RowsetFilterDialog, "com.sun.star.uno.comp.sdb.RowsetFilterDialog", "com.sun.star.sdb.FilterDialog" )
175 
176     //---------------------------------------------------------------------
177     Dialog* RowsetFilterDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
178     {
179         return new DlgFilterCrit( _pParent, m_aContext.getLegacyServiceFactory(), _rxConnection, m_xComposer, _rxColumns );
180     }
181 
182     //---------------------------------------------------------------------
183     void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult )
184     {
185         ComposerDialog::executedDialog( _nExecutionResult );
186 
187         if ( _nExecutionResult && m_pDialog )
188             static_cast< DlgFilterCrit* >( m_pDialog )->BuildWherePart();
189     }
190 
191     //=====================================================================
192     //= RowsetOrderDialog
193     //=====================================================================
194     //---------------------------------------------------------------------
195     RowsetOrderDialog::RowsetOrderDialog( const Reference< XMultiServiceFactory >& _rxORB )
196         :ComposerDialog( _rxORB )
197     {
198     }
199 
200     //---------------------------------------------------------------------
201     IMPLEMENT_SERVICE_INFO1_STATIC( RowsetOrderDialog, "com.sun.star.uno.comp.sdb.RowsetOrderDialog", "com.sun.star.sdb.OrderDialog" )
202 
203     //---------------------------------------------------------------------
204     Dialog* RowsetOrderDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
205     {
206         return new DlgOrderCrit( _pParent, _rxConnection, m_xComposer, _rxColumns );
207     }
208 
209     //---------------------------------------------------------------------
210     void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult )
211     {
212         ComposerDialog::executedDialog( _nExecutionResult );
213 
214         if ( !m_pDialog )
215             return;
216 
217         if ( _nExecutionResult )
218             static_cast< DlgOrderCrit* >( m_pDialog )->BuildOrderPart();
219         else if ( m_xComposer.is() )
220             m_xComposer->setOrder( static_cast< DlgOrderCrit* >( m_pDialog )->GetOrignalOrder() );
221     }
222 
223 //.........................................................................
224 }   // namespace dbaui
225 //.........................................................................
226 
227 
228