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 ************************************************************************/
29 #include "queryorder.hrc"
30 #include "queryorder.hxx"
32 #include "dbustrings.hrc"
34 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
35 #include <com/sun/star/sdbc/ColumnSearch.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <tools/debug.hxx>
38 #include "moduledbu.hxx"
39 #include <connectivity/sqliterator.hxx>
40 #include <connectivity/dbtools.hxx>
41 #include <comphelper/extract.hxx>
42 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
44 #include <tools/diagnose_ex.h>
49 using namespace dbaui
;
50 using namespace connectivity
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::container
;
53 using namespace ::com::sun::star::util
;
54 using namespace ::com::sun::star::sdb
;
55 using namespace ::com::sun::star::sdbc
;
56 using namespace ::com::sun::star::sdbcx
;
57 using namespace ::com::sun::star::beans
;
59 DBG_NAME(DlgOrderCrit
)
60 //------------------------------------------------------------------------------
61 DlgOrderCrit::DlgOrderCrit( Window
* pParent
,
62 const Reference
< XConnection
>& _rxConnection
,
63 const Reference
< XSingleSelectQueryComposer
>& _rxComposer
,
64 const Reference
< XNameAccess
>& _rxCols
)
65 :ModalDialog( pParent
, ModuleRes(DLG_ORDERCRIT
) )
66 ,aLB_ORDERFIELD1( this, ModuleRes( LB_ORDERFIELD1
) )
67 ,aLB_ORDERVALUE1( this, ModuleRes( LB_ORDERVALUE1
) )
68 ,aLB_ORDERFIELD2( this, ModuleRes( LB_ORDERFIELD2
) )
69 ,aLB_ORDERVALUE2( this, ModuleRes( LB_ORDERVALUE2
) )
70 ,aLB_ORDERFIELD3( this, ModuleRes( LB_ORDERFIELD3
) )
71 ,aLB_ORDERVALUE3( this, ModuleRes( LB_ORDERVALUE3
) )
72 ,aFT_ORDERFIELD( this, ModuleRes( FT_ORDERFIELD
) )
73 ,aFT_ORDERAFTER1( this, ModuleRes( FT_ORDERAFTER1
) )
74 ,aFT_ORDERAFTER2( this, ModuleRes( FT_ORDERAFTER2
) )
75 ,aFT_ORDEROPER( this, ModuleRes( FT_ORDEROPER
) )
76 ,aFT_ORDERDIR( this, ModuleRes( FT_ORDERDIR
) )
77 ,aBT_OK( this, ModuleRes( BT_OK
) )
78 ,aBT_CANCEL( this, ModuleRes( BT_CANCEL
) )
79 ,aBT_HELP( this, ModuleRes( BT_HELP
) )
80 ,aFL_ORDER( this, ModuleRes( FL_ORDER
) )
81 ,aSTR_NOENTRY( ModuleRes( STR_NOENTRY
) )
82 ,m_xQueryComposer( _rxComposer
)
84 ,m_xConnection(_rxConnection
)
86 DBG_CTOR(DlgOrderCrit
,NULL
);
88 AllSettings
aSettings( GetSettings() );
89 StyleSettings
aStyle( aSettings
.GetStyleSettings() );
90 aStyle
.SetAutoMnemonic( sal_False
);
91 aSettings
.SetStyleSettings( aStyle
);
92 SetSettings( aSettings
);
94 m_aColumnList
[0] = &aLB_ORDERFIELD1
;
95 m_aColumnList
[1] = &aLB_ORDERFIELD2
;
96 m_aColumnList
[2] = &aLB_ORDERFIELD3
;
98 m_aValueList
[0] = &aLB_ORDERVALUE1
;
99 m_aValueList
[1] = &aLB_ORDERVALUE2
;
100 m_aValueList
[2] = &aLB_ORDERVALUE3
;
103 for(j
=0 ; j
< DOG_ROWS
; j
++ )
105 m_aColumnList
[j
]->InsertEntry( aSTR_NOENTRY
);
108 for( j
=0 ; j
< DOG_ROWS
; j
++ )
110 m_aColumnList
[j
]->SelectEntryPos(0);
111 m_aValueList
[j
]->SelectEntryPos(0);
115 // ... sowie auch die restlichen Felder
116 Sequence
< ::rtl::OUString
> aNames
= m_xColumns
->getElementNames();
117 const ::rtl::OUString
* pIter
= aNames
.getConstArray();
118 const ::rtl::OUString
* pEnd
= pIter
+ aNames
.getLength();
119 Reference
<XPropertySet
> xColumn
;
120 for(;pIter
!= pEnd
;++pIter
)
122 xColumn
.set(m_xColumns
->getByName(*pIter
),UNO_QUERY
);
123 OSL_ENSURE(xColumn
.is(),"Column is null!");
126 sal_Int32 nDataType
= 0;
127 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
128 sal_Int32 eColumnSearch
= dbtools::getSearchColumnFlag(m_xConnection
,nDataType
);
129 if(eColumnSearch
!= ColumnSearch::NONE
)
131 for( j
=0 ; j
< DOG_ROWS
; j
++ )
133 m_aColumnList
[j
]->InsertEntry(*pIter
);
139 m_sOrgOrder
= m_xQueryComposer
->getOrder();
140 impl_initializeOrderList_nothrow();
142 catch(const Exception
&)
144 DBG_UNHANDLED_EXCEPTION();
148 aLB_ORDERFIELD1
.SetSelectHdl(LINK(this,DlgOrderCrit
,FieldListSelectHdl
));
149 aLB_ORDERFIELD2
.SetSelectHdl(LINK(this,DlgOrderCrit
,FieldListSelectHdl
));
155 //------------------------------------------------------------------------------
156 DlgOrderCrit::~DlgOrderCrit()
158 DBG_DTOR(DlgOrderCrit
,NULL
);
161 //------------------------------------------------------------------------------
162 IMPL_LINK_INLINE_START( DlgOrderCrit
, FieldListSelectHdl
, ListBox
*, /*pListBox*/ )
164 DBG_CHKTHIS(DlgOrderCrit
,NULL
);
168 IMPL_LINK_INLINE_END( DlgOrderCrit
, FieldListSelectHdl
, ListBox
*, pListBox
)
170 //------------------------------------------------------------------------------
171 void DlgOrderCrit::impl_initializeOrderList_nothrow()
175 const ::rtl::OUString sNameProperty
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) );
176 const ::rtl::OUString sAscendingProperty
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAscending" ) );
178 Reference
< XIndexAccess
> xOrderColumns( m_xQueryComposer
->getOrderColumns(), UNO_QUERY_THROW
);
179 sal_Int32 nColumns
= xOrderColumns
->getCount();
180 if ( nColumns
> DOG_ROWS
)
183 for ( sal_Int32 i
= 0; i
< nColumns
; ++i
)
185 Reference
< XPropertySet
> xColumn( xOrderColumns
->getByIndex( i
), UNO_QUERY_THROW
);
187 ::rtl::OUString sColumnName
;
188 sal_Bool
bIsAscending( sal_True
);
190 xColumn
->getPropertyValue( sNameProperty
) >>= sColumnName
;
191 xColumn
->getPropertyValue( sAscendingProperty
) >>= bIsAscending
;
193 m_aColumnList
[i
]->SelectEntry( sColumnName
);
194 m_aValueList
[i
]->SelectEntryPos( bIsAscending
? 0 : 1 );
197 catch( const Exception
& )
199 DBG_UNHANDLED_EXCEPTION();
203 //------------------------------------------------------------------------------
204 void DlgOrderCrit::EnableLines()
206 DBG_CHKTHIS(DlgOrderCrit
,NULL
);
208 if ( aLB_ORDERFIELD1
.GetSelectEntryPos() == 0 )
210 aLB_ORDERFIELD2
.Disable();
211 aLB_ORDERVALUE2
.Disable();
213 aLB_ORDERFIELD2
.SelectEntryPos( 0 );
214 aLB_ORDERVALUE2
.SelectEntryPos( 0 );
218 aLB_ORDERFIELD2
.Enable();
219 aLB_ORDERVALUE2
.Enable();
222 if ( aLB_ORDERFIELD2
.GetSelectEntryPos() == 0 )
224 aLB_ORDERFIELD3
.Disable();
225 aLB_ORDERVALUE3
.Disable();
227 aLB_ORDERFIELD3
.SelectEntryPos( 0 );
228 aLB_ORDERVALUE3
.SelectEntryPos( 0 );
232 aLB_ORDERFIELD3
.Enable();
233 aLB_ORDERVALUE3
.Enable();
237 //------------------------------------------------------------------------------
238 ::rtl::OUString
DlgOrderCrit::GetOrderList( ) const
240 DBG_CHKTHIS(DlgOrderCrit
,NULL
);
241 Reference
<XDatabaseMetaData
> xMetaData
= m_xConnection
->getMetaData();
242 ::rtl::OUString sQuote
= xMetaData
.is() ? xMetaData
->getIdentifierQuoteString() : ::rtl::OUString();
243 static const ::rtl::OUString
sDESC(RTL_CONSTASCII_USTRINGPARAM(" DESC "));
244 static const ::rtl::OUString
sASC(RTL_CONSTASCII_USTRINGPARAM(" ASC "));
246 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
248 ::rtl::OUString sOrder
;
249 for( sal_uInt16 i
=0 ; i
<DOG_ROWS
; i
++ )
251 if(m_aColumnList
[i
]->GetSelectEntryPos() != 0)
253 if(!sOrder
.isEmpty())
254 sOrder
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
256 String sName
= m_aColumnList
[i
]->GetSelectEntry();
259 sal_Bool bFunction
= sal_False
;
260 Reference
< XPropertySet
> xColumn
;
261 if ( xColumns
.is() && xColumns
->hasByName( sName
) && (xColumns
->getByName( sName
) >>= xColumn
) && xColumn
.is() )
263 if ( xColumn
->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME
) )
265 ::rtl::OUString sRealName
;
266 xColumn
->getPropertyValue(PROPERTY_REALNAME
) >>= sRealName
;
268 static ::rtl::OUString
sFunction(RTL_CONSTASCII_USTRINGPARAM("Function"));
269 if ( xColumn
->getPropertySetInfo()->hasPropertyByName(sFunction
) )
270 xColumn
->getPropertyValue(sFunction
) >>= bFunction
;
276 sOrder
+= ::dbtools::quoteName(sQuote
,sName
);
278 catch(const Exception
&)
281 if(m_aValueList
[i
]->GetSelectEntryPos())
290 //------------------------------------------------------------------------------
291 void DlgOrderCrit::BuildOrderPart()
293 DBG_CHKTHIS(DlgOrderCrit
,NULL
);
294 m_xQueryComposer
->setOrder(GetOrderList());
296 // -----------------------------------------------------------------------------
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */