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