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