1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "composerdialogs.hxx"
32 /** === begin UNO includes === **/
33 #include "dbu_reghelper.hxx"
34 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
35 /** === end UNO includes === **/
36 #include "dbustrings.hrc"
37 #include "queryfilter.hxx"
38 #include "queryorder.hxx"
39 #include <connectivity/dbtools.hxx>
40 #include <tools/diagnose_ex.h>
41 #include <osl/diagnose.h>
43 extern "C" void SAL_CALL
createRegistryInfo_ComposerDialogs()
45 static ::dbaui::OMultiInstanceAutoRegistration
< ::dbaui::RowsetOrderDialog
> aOrderDialogRegistration
;
46 static ::dbaui::OMultiInstanceAutoRegistration
< ::dbaui::RowsetFilterDialog
> aFilterDialogRegistration
;
49 //.........................................................................
52 //.........................................................................
54 #define PROPERTY_ID_QUERYCOMPOSER 100
55 #define PROPERTY_ID_ROWSET 101
57 IMPLEMENT_CONSTASCII_USTRING( PROPERTY_QUERYCOMPOSER
, "QueryComposer" );
58 IMPLEMENT_CONSTASCII_USTRING( PROPERTY_ROWSET
, "RowSet" );
60 using namespace ::com::sun::star::uno
;
61 using namespace ::com::sun::star::lang
;
62 using namespace ::com::sun::star::beans
;
63 using namespace ::com::sun::star::container
;
64 using namespace ::com::sun::star::sdbcx
;
65 using namespace ::com::sun::star::sdbc
;
66 using namespace ::com::sun::star::sdb
;
68 //=====================================================================
70 //=====================================================================
71 DBG_NAME(ComposerDialog
)
72 //---------------------------------------------------------------------
73 ComposerDialog::ComposerDialog(const Reference
< XMultiServiceFactory
>& _rxORB
)
74 :ComposerDialog_BASE( _rxORB
)
76 DBG_CTOR(ComposerDialog
,NULL
);
78 registerProperty( PROPERTY_QUERYCOMPOSER
, PROPERTY_ID_QUERYCOMPOSER
, PropertyAttribute::TRANSIENT
,
79 &m_xComposer
, ::getCppuType( &m_xComposer
) );
80 registerProperty( PROPERTY_ROWSET
, PROPERTY_ID_ROWSET
, PropertyAttribute::TRANSIENT
,
81 &m_xRowSet
, ::getCppuType( &m_xRowSet
) );
84 //---------------------------------------------------------------------
85 ComposerDialog::~ComposerDialog()
88 DBG_DTOR(ComposerDialog
,NULL
);
91 //---------------------------------------------------------------------
92 IMPLEMENT_IMPLEMENTATION_ID( ComposerDialog
)
94 //---------------------------------------------------------------------
95 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ComposerDialog
)
97 //---------------------------------------------------------------------
98 Dialog
* ComposerDialog::createDialog(Window
* _pParent
)
100 // obtain all the objects needed for the dialog
101 Reference
< XConnection
> xConnection
;
102 Reference
< XNameAccess
> xColumns
;
105 // the connection the row set is working with
106 if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet
, xConnection
) )
108 Reference
< XPropertySet
> xRowsetProps( m_xRowSet
, UNO_QUERY
);
109 if ( xRowsetProps
.is() )
110 xRowsetProps
->getPropertyValue( PROPERTY_ACTIVE_CONNECTION
) >>= xConnection
;
113 // fallback: if there is a connection and thus a row set, but no composer, create one
114 if ( xConnection
.is() && !m_xComposer
.is() )
115 m_xComposer
= ::dbtools::getCurrentSettingsComposer( Reference
< XPropertySet
>( m_xRowSet
, UNO_QUERY
), m_aContext
.getLegacyServiceFactory() );
117 // the columns of the row set
118 Reference
< XColumnsSupplier
> xSuppColumns( m_xRowSet
, UNO_QUERY
);
119 if ( xSuppColumns
.is() )
120 xColumns
= xSuppColumns
->getColumns();
122 if ( !xColumns
.is() || !xColumns
->hasElements() )
123 { // perhaps the composer can supply us with columns? This is necessary for cases
124 // where the dialog is invoked for a rowset which is not yet loaded
126 xSuppColumns
= xSuppColumns
.query( m_xComposer
);
127 if ( xSuppColumns
.is() )
128 xColumns
= xSuppColumns
->getColumns();
131 OSL_ENSURE( xColumns
.is() && xColumns
->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
133 catch( const Exception
& )
135 DBG_UNHANDLED_EXCEPTION();
138 if ( !xConnection
.is() || !xColumns
.is() || !m_xComposer
.is() )
139 // can't create the dialog if I have improper settings
142 return createComposerDialog( _pParent
, xConnection
, xColumns
);
145 //=====================================================================
146 //= RowsetFilterDialog
147 //=====================================================================
148 //---------------------------------------------------------------------
149 RowsetFilterDialog::RowsetFilterDialog( const Reference
< XMultiServiceFactory
>& _rxORB
)
150 :ComposerDialog( _rxORB
)
154 //---------------------------------------------------------------------
155 IMPLEMENT_SERVICE_INFO1_STATIC( RowsetFilterDialog
, "com.sun.star.uno.comp.sdb.RowsetFilterDialog", "com.sun.star.sdb.FilterDialog" )
157 //---------------------------------------------------------------------
158 Dialog
* RowsetFilterDialog::createComposerDialog( Window
* _pParent
, const Reference
< XConnection
>& _rxConnection
, const Reference
< XNameAccess
>& _rxColumns
)
160 return new DlgFilterCrit( _pParent
, m_aContext
.getLegacyServiceFactory(), _rxConnection
, m_xComposer
, _rxColumns
);
163 //---------------------------------------------------------------------
164 void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult
)
166 ComposerDialog::executedDialog( _nExecutionResult
);
168 if ( _nExecutionResult
&& m_pDialog
)
169 static_cast< DlgFilterCrit
* >( m_pDialog
)->BuildWherePart();
172 //=====================================================================
173 //= RowsetOrderDialog
174 //=====================================================================
175 //---------------------------------------------------------------------
176 RowsetOrderDialog::RowsetOrderDialog( const Reference
< XMultiServiceFactory
>& _rxORB
)
177 :ComposerDialog( _rxORB
)
181 //---------------------------------------------------------------------
182 IMPLEMENT_SERVICE_INFO1_STATIC( RowsetOrderDialog
, "com.sun.star.uno.comp.sdb.RowsetOrderDialog", "com.sun.star.sdb.OrderDialog" )
184 //---------------------------------------------------------------------
185 Dialog
* RowsetOrderDialog::createComposerDialog( Window
* _pParent
, const Reference
< XConnection
>& _rxConnection
, const Reference
< XNameAccess
>& _rxColumns
)
187 return new DlgOrderCrit( _pParent
, _rxConnection
, m_xComposer
, _rxColumns
);
190 //---------------------------------------------------------------------
191 void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult
)
193 ComposerDialog::executedDialog( _nExecutionResult
);
198 if ( _nExecutionResult
)
199 static_cast< DlgOrderCrit
* >( m_pDialog
)->BuildOrderPart();
200 else if ( m_xComposer
.is() )
201 m_xComposer
->setOrder( static_cast< DlgOrderCrit
* >( m_pDialog
)->GetOrignalOrder() );
204 //.........................................................................
206 //.........................................................................
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */