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: queryorder.cxx,v $
10 * $Revision: 1.20.172.2 $
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"
33 #ifndef DBAUI_QUERYORDER_HRC
34 #include "queryorder.hrc"
36 #ifndef DBAUI_QUERYORDER_HXX
37 #include "queryorder.hxx"
40 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
41 #include "dbustrings.hrc"
44 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
45 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
47 #ifndef _COM_SUN_STAR_SDBC_COLUMNSEARCH_HPP_
48 #include <com/sun/star/sdbc/ColumnSearch.hpp>
50 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
51 #include <com/sun/star/container/XNameAccess.hpp>
53 #ifndef _TOOLS_DEBUG_HXX
54 #include <tools/debug.hxx>
56 #ifndef _DBAUI_MODULE_DBU_HXX_
57 #include "moduledbu.hxx"
59 #ifndef _CONNECTIVITY_PARSE_SQLITERATOR_HXX_
60 #include <connectivity/sqliterator.hxx>
62 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
63 #include <connectivity/dbtools.hxx>
65 #ifndef _COMPHELPER_EXTRACT_HXX_
66 #include <comphelper/extract.hxx>
68 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
69 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
72 #ifndef TOOLS_DIAGNOSE_EX_H
73 #include <tools/diagnose_ex.h>
79 using namespace dbaui
;
80 using namespace connectivity
;
81 using namespace ::com::sun::star::uno
;
82 using namespace ::com::sun::star::container
;
83 using namespace ::com::sun::star::util
;
84 using namespace ::com::sun::star::sdb
;
85 using namespace ::com::sun::star::sdbc
;
86 using namespace ::com::sun::star::sdbcx
;
87 using namespace ::com::sun::star::beans
;
89 DBG_NAME(DlgOrderCrit
)
90 //------------------------------------------------------------------------------
91 DlgOrderCrit::DlgOrderCrit( Window
* pParent
,
92 const Reference
< XConnection
>& _rxConnection
,
93 const Reference
< XSingleSelectQueryComposer
>& _rxComposer
,
94 const Reference
< XNameAccess
>& _rxCols
)
95 :ModalDialog( pParent
, ModuleRes(DLG_ORDERCRIT
) )
96 ,aLB_ORDERFIELD1( this, ModuleRes( LB_ORDERFIELD1
) )
97 ,aLB_ORDERVALUE1( this, ModuleRes( LB_ORDERVALUE1
) )
98 ,aLB_ORDERFIELD2( this, ModuleRes( LB_ORDERFIELD2
) )
99 ,aLB_ORDERVALUE2( this, ModuleRes( LB_ORDERVALUE2
) )
100 ,aLB_ORDERFIELD3( this, ModuleRes( LB_ORDERFIELD3
) )
101 ,aLB_ORDERVALUE3( this, ModuleRes( LB_ORDERVALUE3
) )
102 ,aFT_ORDERFIELD( this, ModuleRes( FT_ORDERFIELD
) )
103 ,aFT_ORDERAFTER1( this, ModuleRes( FT_ORDERAFTER1
) )
104 ,aFT_ORDERAFTER2( this, ModuleRes( FT_ORDERAFTER2
) )
105 ,aFT_ORDEROPER( this, ModuleRes( FT_ORDEROPER
) )
106 ,aFT_ORDERDIR( this, ModuleRes( FT_ORDERDIR
) )
107 ,aBT_OK( this, ModuleRes( BT_OK
) )
108 ,aBT_CANCEL( this, ModuleRes( BT_CANCEL
) )
109 ,aBT_HELP( this, ModuleRes( BT_HELP
) )
110 ,aFL_ORDER( this, ModuleRes( FL_ORDER
) )
111 ,aSTR_NOENTRY( ModuleRes( STR_NOENTRY
) )
112 ,m_xQueryComposer( _rxComposer
)
114 ,m_xConnection(_rxConnection
)
116 DBG_CTOR(DlgOrderCrit
,NULL
);
118 AllSettings
aSettings( GetSettings() );
119 StyleSettings
aStyle( aSettings
.GetStyleSettings() );
120 aStyle
.SetAutoMnemonic( FALSE
);
121 aSettings
.SetStyleSettings( aStyle
);
122 SetSettings( aSettings
);
124 m_aColumnList
[0] = &aLB_ORDERFIELD1
;
125 m_aColumnList
[1] = &aLB_ORDERFIELD2
;
126 m_aColumnList
[2] = &aLB_ORDERFIELD3
;
128 m_aValueList
[0] = &aLB_ORDERVALUE1
;
129 m_aValueList
[1] = &aLB_ORDERVALUE2
;
130 m_aValueList
[2] = &aLB_ORDERVALUE3
;
133 for(j
=0 ; j
< DOG_ROWS
; j
++ )
135 m_aColumnList
[j
]->InsertEntry( aSTR_NOENTRY
);
138 for( j
=0 ; j
< DOG_ROWS
; j
++ )
140 m_aColumnList
[j
]->SelectEntryPos(0);
141 m_aValueList
[j
]->SelectEntryPos(0);
145 // ... sowie auch die restlichen Felder
146 Sequence
< ::rtl::OUString
> aNames
= m_xColumns
->getElementNames();
147 const ::rtl::OUString
* pIter
= aNames
.getConstArray();
148 const ::rtl::OUString
* pEnd
= pIter
+ aNames
.getLength();
149 Reference
<XPropertySet
> xColumn
;
150 for(;pIter
!= pEnd
;++pIter
)
152 xColumn
.set(m_xColumns
->getByName(*pIter
),UNO_QUERY
);
153 OSL_ENSURE(xColumn
.is(),"Column is null!");
156 sal_Int32 nDataType
= 0;
157 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
158 sal_Int32 eColumnSearch
= dbtools::getSearchColumnFlag(m_xConnection
,nDataType
);
159 if(eColumnSearch
!= ColumnSearch::NONE
)
161 for( j
=0 ; j
< DOG_ROWS
; j
++ )
163 m_aColumnList
[j
]->InsertEntry(*pIter
);
169 m_sOrgOrder
= m_xQueryComposer
->getOrder();
170 impl_initializeOrderList_nothrow();
172 catch(const Exception
&)
174 DBG_UNHANDLED_EXCEPTION();
178 aLB_ORDERFIELD1
.SetSelectHdl(LINK(this,DlgOrderCrit
,FieldListSelectHdl
));
179 aLB_ORDERFIELD2
.SetSelectHdl(LINK(this,DlgOrderCrit
,FieldListSelectHdl
));
185 //------------------------------------------------------------------------------
187 #define LbText(x) ((x).GetSelectEntry())
188 #define LbPos(x) ((x).GetSelectEntryPos())
190 //------------------------------------------------------------------------------
191 DlgOrderCrit::~DlgOrderCrit()
193 DBG_DTOR(DlgOrderCrit
,NULL
);
196 //------------------------------------------------------------------------------
197 IMPL_LINK_INLINE_START( DlgOrderCrit
, FieldListSelectHdl
, ListBox
*, /*pListBox*/ )
199 DBG_CHKTHIS(DlgOrderCrit
,NULL
);
203 IMPL_LINK_INLINE_END( DlgOrderCrit
, FieldListSelectHdl
, ListBox
*, pListBox
)
205 //------------------------------------------------------------------------------
206 void DlgOrderCrit::impl_initializeOrderList_nothrow()
210 const ::rtl::OUString sNameProperty
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) );
211 const ::rtl::OUString sAscendingProperty
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAscending" ) );
213 Reference
< XIndexAccess
> xOrderColumns( m_xQueryComposer
->getOrderColumns(), UNO_QUERY_THROW
);
214 sal_Int32 nColumns
= xOrderColumns
->getCount();
215 if ( nColumns
> DOG_ROWS
)
218 for ( sal_Int32 i
= 0; i
< nColumns
; ++i
)
220 Reference
< XPropertySet
> xColumn( xOrderColumns
->getByIndex( i
), UNO_QUERY_THROW
);
222 ::rtl::OUString sColumnName
;
223 sal_Bool
bIsAscending( sal_True
);
225 xColumn
->getPropertyValue( sNameProperty
) >>= sColumnName
;
226 xColumn
->getPropertyValue( sAscendingProperty
) >>= bIsAscending
;
228 m_aColumnList
[i
]->SelectEntry( sColumnName
);
229 m_aValueList
[i
]->SelectEntryPos( bIsAscending
? 0 : 1 );
232 catch( const Exception
& )
234 DBG_UNHANDLED_EXCEPTION();
238 //------------------------------------------------------------------------------
239 void DlgOrderCrit::EnableLines()
241 DBG_CHKTHIS(DlgOrderCrit
,NULL
);
243 if ( aLB_ORDERFIELD1
.GetSelectEntryPos() == 0 )
245 aLB_ORDERFIELD2
.Disable();
246 aLB_ORDERVALUE2
.Disable();
248 aLB_ORDERFIELD2
.SelectEntryPos( 0 );
249 aLB_ORDERVALUE2
.SelectEntryPos( 0 );
253 aLB_ORDERFIELD2
.Enable();
254 aLB_ORDERVALUE2
.Enable();
257 if ( aLB_ORDERFIELD2
.GetSelectEntryPos() == 0 )
259 aLB_ORDERFIELD3
.Disable();
260 aLB_ORDERVALUE3
.Disable();
262 aLB_ORDERFIELD3
.SelectEntryPos( 0 );
263 aLB_ORDERVALUE3
.SelectEntryPos( 0 );
267 aLB_ORDERFIELD3
.Enable();
268 aLB_ORDERVALUE3
.Enable();
272 //------------------------------------------------------------------------------
273 ::rtl::OUString
DlgOrderCrit::GetOrderList( ) const
275 DBG_CHKTHIS(DlgOrderCrit
,NULL
);
276 Reference
<XDatabaseMetaData
> xMetaData
= m_xConnection
->getMetaData();
277 ::rtl::OUString sQuote
= xMetaData
.is() ? xMetaData
->getIdentifierQuoteString() : ::rtl::OUString();
278 static const ::rtl::OUString sDESC
= ::rtl::OUString::createFromAscii(" DESC ");
279 static const ::rtl::OUString sASC
= ::rtl::OUString::createFromAscii(" ASC ");
281 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
283 ::rtl::OUString sOrder
;
284 for( sal_uInt16 i
=0 ; i
<DOG_ROWS
; i
++ )
286 if(m_aColumnList
[i
]->GetSelectEntryPos() != 0)
288 if(sOrder
.getLength())
289 sOrder
+= ::rtl::OUString::createFromAscii(",");
291 String sName
= m_aColumnList
[i
]->GetSelectEntry();
294 sal_Bool bFunction
= sal_False
;
295 Reference
< XPropertySet
> xColumn
;
296 if ( xColumns
.is() && xColumns
->hasByName( sName
) && (xColumns
->getByName( sName
) >>= xColumn
) && xColumn
.is() )
298 if ( xColumn
->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME
) )
300 ::rtl::OUString sRealName
;
301 xColumn
->getPropertyValue(PROPERTY_REALNAME
) >>= sRealName
;
303 static ::rtl::OUString
sAgg(RTL_CONSTASCII_USTRINGPARAM("AggregateFunction"));
304 static ::rtl::OUString
sFunction(RTL_CONSTASCII_USTRINGPARAM("Function"));
305 if ( xColumn
->getPropertySetInfo()->hasPropertyByName(sFunction
) )
306 xColumn
->getPropertyValue(sFunction
) >>= bFunction
;
312 sOrder
+= ::dbtools::quoteName(sQuote
,sName
);
317 if(m_aValueList
[i
]->GetSelectEntryPos())
326 //------------------------------------------------------------------------------
327 void DlgOrderCrit::BuildOrderPart()
329 DBG_CHKTHIS(DlgOrderCrit
,NULL
);
330 m_xQueryComposer
->setOrder(GetOrderList());
332 // -----------------------------------------------------------------------------