1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: composerdialogs.cxx,v $
10 * $Revision: 1.9.32.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBACCESS_SOURCE_UI_UNO_COMPOSERDIALOGS_HXX
35 #include "composerdialogs.hxx"
38 /** === begin UNO includes === **/
39 #ifndef _DBU_REGHELPER_HXX_
40 #include "dbu_reghelper.hxx"
42 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
43 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
45 /** === end UNO includes === **/
46 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
47 #include "dbustrings.hrc"
49 #ifndef DBAUI_QUERYFILTER_HXX
50 #include "queryfilter.hxx"
52 #ifndef DBAUI_QUERYORDER_HXX
53 #include "queryorder.hxx"
55 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
56 #include <connectivity/dbtools.hxx>
58 #ifndef _TOOLS_DEBUG_HXX
59 #include <tools/debug.hxx>
61 #ifndef TOOLS_DIAGNOSE_EX_H
62 #include <tools/diagnose_ex.h>
65 extern "C" void SAL_CALL
createRegistryInfo_ComposerDialogs()
67 static ::dbaui::OMultiInstanceAutoRegistration
< ::dbaui::RowsetOrderDialog
> aOrderDialogRegistration
;
68 static ::dbaui::OMultiInstanceAutoRegistration
< ::dbaui::RowsetFilterDialog
> aFilterDialogRegistration
;
71 //.........................................................................
74 //.........................................................................
76 #define PROPERTY_ID_QUERYCOMPOSER 100
77 #define PROPERTY_ID_ROWSET 101
79 IMPLEMENT_CONSTASCII_USTRING( PROPERTY_QUERYCOMPOSER
, "QueryComposer" );
80 IMPLEMENT_CONSTASCII_USTRING( PROPERTY_ROWSET
, "RowSet" );
82 using namespace ::com::sun::star::uno
;
83 using namespace ::com::sun::star::lang
;
84 using namespace ::com::sun::star::beans
;
85 using namespace ::com::sun::star::container
;
86 using namespace ::com::sun::star::sdbcx
;
87 using namespace ::com::sun::star::sdbc
;
88 using namespace ::com::sun::star::sdb
;
90 //=====================================================================
92 //=====================================================================
93 DBG_NAME(ComposerDialog
)
94 //---------------------------------------------------------------------
95 ComposerDialog::ComposerDialog(const Reference
< XMultiServiceFactory
>& _rxORB
)
96 :ComposerDialog_BASE( _rxORB
)
98 DBG_CTOR(ComposerDialog
,NULL
);
100 registerProperty( PROPERTY_QUERYCOMPOSER
, PROPERTY_ID_QUERYCOMPOSER
, PropertyAttribute::TRANSIENT
,
101 &m_xComposer
, ::getCppuType( &m_xComposer
) );
102 registerProperty( PROPERTY_ROWSET
, PROPERTY_ID_ROWSET
, PropertyAttribute::TRANSIENT
,
103 &m_xRowSet
, ::getCppuType( &m_xRowSet
) );
106 //---------------------------------------------------------------------
107 ComposerDialog::~ComposerDialog()
110 DBG_DTOR(ComposerDialog
,NULL
);
113 //---------------------------------------------------------------------
114 IMPLEMENT_IMPLEMENTATION_ID( ComposerDialog
)
116 //---------------------------------------------------------------------
117 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ComposerDialog
)
119 //---------------------------------------------------------------------
120 Dialog
* ComposerDialog::createDialog(Window
* _pParent
)
122 // obtain all the objects needed for the dialog
123 Reference
< XConnection
> xConnection
;
124 Reference
< XNameAccess
> xColumns
;
127 // the connection the row set is working with
128 if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet
, xConnection
) )
130 Reference
< XPropertySet
> xRowsetProps( m_xRowSet
, UNO_QUERY
);
131 if ( xRowsetProps
.is() )
132 xRowsetProps
->getPropertyValue( PROPERTY_ACTIVE_CONNECTION
) >>= xConnection
;
135 // fallback: if there is a connection and thus a row set, but no composer, create one
136 if ( xConnection
.is() && !m_xComposer
.is() )
137 m_xComposer
= ::dbtools::getCurrentSettingsComposer( Reference
< XPropertySet
>( m_xRowSet
, UNO_QUERY
), m_aContext
.getLegacyServiceFactory() );
139 // the columns of the row set
140 Reference
< XColumnsSupplier
> xSuppColumns( m_xRowSet
, UNO_QUERY
);
141 if ( xSuppColumns
.is() )
142 xColumns
= xSuppColumns
->getColumns();
144 if ( !xColumns
.is() || !xColumns
->hasElements() )
145 { // perhaps the composer can supply us with columns? This is necessary for cases
146 // where the dialog is invoked for a rowset which is not yet loaded
147 // #i22878# - 2003-12-16 - fs@openoffice.org
148 xSuppColumns
= xSuppColumns
.query( m_xComposer
);
149 if ( xSuppColumns
.is() )
150 xColumns
= xSuppColumns
->getColumns();
153 DBG_ASSERT( xColumns
.is() && xColumns
->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
155 catch( const Exception
& )
157 DBG_UNHANDLED_EXCEPTION();
160 if ( !xConnection
.is() || !xColumns
.is() || !m_xComposer
.is() )
161 // can't create the dialog if I have improper settings
164 return createComposerDialog( _pParent
, xConnection
, xColumns
);
167 //=====================================================================
168 //= RowsetFilterDialog
169 //=====================================================================
170 //---------------------------------------------------------------------
171 RowsetFilterDialog::RowsetFilterDialog( const Reference
< XMultiServiceFactory
>& _rxORB
)
172 :ComposerDialog( _rxORB
)
176 //---------------------------------------------------------------------
177 IMPLEMENT_SERVICE_INFO1_STATIC( RowsetFilterDialog
, "com.sun.star.uno.comp.sdb.RowsetFilterDialog", "com.sun.star.sdb.FilterDialog" )
179 //---------------------------------------------------------------------
180 Dialog
* RowsetFilterDialog::createComposerDialog( Window
* _pParent
, const Reference
< XConnection
>& _rxConnection
, const Reference
< XNameAccess
>& _rxColumns
)
182 return new DlgFilterCrit( _pParent
, m_aContext
.getLegacyServiceFactory(), _rxConnection
, m_xComposer
, _rxColumns
);
185 //---------------------------------------------------------------------
186 void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult
)
188 ComposerDialog::executedDialog( _nExecutionResult
);
190 if ( _nExecutionResult
&& m_pDialog
)
191 static_cast< DlgFilterCrit
* >( m_pDialog
)->BuildWherePart();
194 //=====================================================================
195 //= RowsetOrderDialog
196 //=====================================================================
197 //---------------------------------------------------------------------
198 RowsetOrderDialog::RowsetOrderDialog( const Reference
< XMultiServiceFactory
>& _rxORB
)
199 :ComposerDialog( _rxORB
)
203 //---------------------------------------------------------------------
204 IMPLEMENT_SERVICE_INFO1_STATIC( RowsetOrderDialog
, "com.sun.star.uno.comp.sdb.RowsetOrderDialog", "com.sun.star.sdb.OrderDialog" )
206 //---------------------------------------------------------------------
207 Dialog
* RowsetOrderDialog::createComposerDialog( Window
* _pParent
, const Reference
< XConnection
>& _rxConnection
, const Reference
< XNameAccess
>& _rxColumns
)
209 return new DlgOrderCrit( _pParent
, _rxConnection
, m_xComposer
, _rxColumns
);
212 //---------------------------------------------------------------------
213 void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult
)
215 ComposerDialog::executedDialog( _nExecutionResult
);
220 if ( _nExecutionResult
)
221 static_cast< DlgOrderCrit
* >( m_pDialog
)->BuildOrderPart();
222 else if ( m_xComposer
.is() )
223 m_xComposer
->setOrder( static_cast< DlgOrderCrit
* >( m_pDialog
)->GetOrignalOrder() );
226 //.........................................................................
228 //.........................................................................