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: conditionupdater.cxx,v $
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 #include "conditionupdater.hxx"
32 #include "reportformula.hxx"
34 /** === begin UNO includes === **/
35 #include <com/sun/star/report/XFormatCondition.hpp>
36 /** === end UNO includes === **/
38 #include <tools/diagnose_ex.h>
40 //........................................................................
43 //........................................................................
45 /** === begin UNO using === **/
46 using ::com::sun::star::beans::PropertyChangeEvent
;
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::report::XReportControlModel
;
49 using ::com::sun::star::uno::UNO_QUERY
;
50 using ::com::sun::star::report::XFormatCondition
;
51 using ::com::sun::star::uno::UNO_QUERY_THROW
;
52 using ::com::sun::star::uno::Exception
;
53 /** === end UNO using === **/
55 //====================================================================
57 //====================================================================
58 //--------------------------------------------------------------------
59 ConditionUpdater::ConditionUpdater()
63 //--------------------------------------------------------------------
64 ConditionUpdater::~ConditionUpdater()
68 //--------------------------------------------------------------------
69 void ConditionUpdater::notifyPropertyChange( const PropertyChangeEvent
& _rEvent
)
71 if ( !impl_lateInit_nothrow() )
74 Reference
< XReportControlModel
> xRptControlModel( _rEvent
.Source
, UNO_QUERY
);
75 if ( xRptControlModel
.is() && _rEvent
.PropertyName
.equalsAscii( "DataField" ) )
77 ::rtl::OUString sOldDataSource
, sNewDataSource
;
78 OSL_VERIFY( _rEvent
.OldValue
>>= sOldDataSource
);
79 OSL_VERIFY( _rEvent
.NewValue
>>= sNewDataSource
);
80 impl_adjustFormatConditions_nothrow( xRptControlModel
, sOldDataSource
, sNewDataSource
);
84 //--------------------------------------------------------------------
85 bool ConditionUpdater::impl_lateInit_nothrow()
87 if ( !m_aConditionalExpressions
.empty() )
90 ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions
);
94 //--------------------------------------------------------------------
95 void ConditionUpdater::impl_adjustFormatConditions_nothrow( const Reference
< XReportControlModel
>& _rxRptControlModel
,
96 const ::rtl::OUString
& _rOldDataSource
, const ::rtl::OUString
& _rNewDataSource
)
100 ReportFormula
aOldContentFormula( _rOldDataSource
);
101 ::rtl::OUString
sOldUnprefixed( aOldContentFormula
.getBracketedFieldOrExpression() );
102 ReportFormula
aNewContentFormula( _rNewDataSource
);
103 ::rtl::OUString
sNewUnprefixed( aNewContentFormula
.getBracketedFieldOrExpression() );
105 sal_Int32
nCount( _rxRptControlModel
->getCount() );
106 Reference
< XFormatCondition
> xFormatCondition
;
107 ::rtl::OUString sFormulaExpression
, sLHS
, sRHS
;
108 for ( sal_Int32 i
=0; i
<nCount
; ++i
)
110 xFormatCondition
.set( _rxRptControlModel
->getByIndex( i
), UNO_QUERY_THROW
);
111 ReportFormula
aFormula( xFormatCondition
->getFormula() );
112 sFormulaExpression
= aFormula
.getExpression();
114 for ( ConditionalExpressions::const_iterator loop
= m_aConditionalExpressions
.begin();
115 loop
!= m_aConditionalExpressions
.end();
119 if ( !loop
->second
->matchExpression( sFormulaExpression
, sOldUnprefixed
, sLHS
, sRHS
) )
122 // the expression matches -> translate it to the new data source of the report control model
123 sFormulaExpression
= loop
->second
->assembleExpression( sNewUnprefixed
, sLHS
, sRHS
);
124 aFormula
= ReportFormula( ReportFormula::Expression
, sFormulaExpression
);
125 xFormatCondition
->setFormula( aFormula
.getCompleteFormula() );
130 catch( const Exception
& )
132 DBG_UNHANDLED_EXCEPTION();
136 //........................................................................
138 //........................................................................