using ::dbtools::SQLExceptionInfo; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::XComponentContext; using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Any; using ::com::sun::star::uno::XInterface; using ::com::sun::star::sdbc::XRowSet; using ::com::sun::star::sdbc::XResultSetUpdate; using ::com::sun::star::form::runtime::XFormController; using ::com::sun::star::form::runtime::XFormOperations; using ::com::sun::star::form::runtime::XFeatureInvalidation; using ::com::sun::star::form::runtime::FeatureState; using ::com::sun::star::lang::IllegalArgumentException; using ::com::sun::star::sdbc::SQLException; usingnamespace ::com::sun::star::sdbc; using ::com::sun::star::form::XForm; using ::com::sun::star::ucb::AlreadyInitializedException; using ::com::sun::star::uno::UNO_QUERY; using ::com::sun::star::lang::EventObject; using ::com::sun::star::beans::PropertyChangeEvent; using ::com::sun::star::lang::XMultiServiceFactory; using ::com::sun::star::lang::DisposedException; using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::awt::XControl; using ::com::sun::star::form::XGrid; using ::com::sun::star::container::XIndexAccess; using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::form::XBoundControl; using ::com::sun::star::form::XBoundComponent; using ::com::sun::star::sdbcx::XRowLocate; using ::com::sun::star::form::XConfirmDeleteListener; using ::com::sun::star::sdb::RowChangeEvent; usingnamespace ::com::sun::star::sdb; using ::com::sun::star::form::XReset; using ::com::sun::star::beans::XMultiPropertySet; using ::com::sun::star::lang::WrappedTargetException; using ::com::sun::star::ui::dialogs::XExecutableDialog; using ::com::sun::star::beans::NamedValue; using ::com::sun::star::util::XRefreshable; using ::com::sun::star::awt::XControlModel;
case FormFeature::DeleteRecord: // already deleted ? if ( m_xCursor->rowDeleted() )
aState.Enabled = false; else
{ // allowed to delete the row ?
aState.Enabled = !impl_isInsertionRow_throw() && ::dbtools::canDelete( m_xCursorProperties );
} break;
case FormFeature::MoveToInsertRow: // if we are inserting we can move to the next row if the current record or control is modified
aState.Enabled = impl_isInsertionRow_throw()
? impl_isModifiedRow_throw() || m_bActiveControlModified
: ::dbtools::canInsert( m_xCursorProperties ); break;
case FormFeature::ReloadForm:
{ // there must be an active connection
aState.Enabled = ::dbtools::getConnection( m_xCursor ).is();
// and an active command
OUString sActiveCommand;
m_xCursorProperties->getPropertyValue( PROPERTY_ACTIVECOMMAND ) >>= sActiveCommand;
aState.Enabled = aState.Enabled && !sActiveCommand.isEmpty();
} break;
case FormFeature::SaveRecordChanges: case FormFeature::UndoRecordChanges:
aState.Enabled = impl_isModifiedRow_throw() || m_bActiveControlModified; break;
case FormFeature::RemoveFilterAndSort: if ( impl_isParseable_throw() && impl_hasFilterOrOrder_throw() )
aState.Enabled = !impl_isInsertOnlyForm_throw(); break;
case FormFeature::SortAscending: case FormFeature::SortDescending: case FormFeature::AutoFilter: if ( m_xController.is() && impl_isParseable_throw() )
{ bool bIsDeleted = m_xCursor->rowDeleted();
case FormFeature::InteractiveSort: case FormFeature::InteractiveFilter: if ( impl_isParseable_throw() )
aState.Enabled = !impl_isInsertOnlyForm_throw(); break;
bool commit1Form(const Reference< XForm >& xFrm, bool &needConfirmation, bool &shouldCommit)
{
Reference< XPropertySet > xProps(xFrm, UNO_QUERY_THROW); // nothing to do if the record is not modified if(!lcl_safeGetPropertyValue_throw( xProps, PROPERTY_ISMODIFIED, false )) returntrue;
bool commitFormAndSubforms(const Reference< XForm >& xFrm, bool needConfirmation)
{ // No control... do what we can with the models bool shouldCommit(true);
Reference< XIndexAccess > xFormComps(xFrm, UNO_QUERY_THROW);
case FormFeature::MoveToNext:
impl_moveRight_throw( ); break;
case FormFeature::MoveToPrevious:
impl_moveLeft_throw( ); break;
case FormFeature::MoveToLast:
{ /* // TODO: re-implement this... // run in an own thread if... // ... the data source is thread safe... sal_BoolbAllowOwnThread=sal_False; if(::comphelper::hasProperty(PROPERTY_THREADSAFE,m_xCursorProperties)) m_xCursorProperties->getPropertyValue(PROPERTY_THREADSAFE)>>=bAllowOwnThread;
// ... the record count is unknown sal_BoolbNeedOwnThreadsal_False; if(::comphelper::hasProperty(PROPERTY_ROWCOUNTFINAL,m_xCursorProperties)) m_xCursorProperties->getPropertyValue(PROPERTY_ROWCOUNTFINAL)>>=bNeedOwnThread;
case FormFeature::ReloadForm: if ( m_xLoadableForm.is() )
{
weld::WaitObject aWO(Application::GetFrameWeld(GetDialogParent()));
m_xLoadableForm->reload();
// refresh all controls in the form (and sub forms) which can be refreshed // #i90914#
::comphelper::IndexAccessIterator aIter( m_xLoadableForm );
Reference< XInterface > xElement( aIter.Next() ); while ( xElement.is() )
{
Reference< XRefreshable > xRefresh( xElement, UNO_QUERY ); if ( xRefresh.is() )
xRefresh->refresh();
xElement = aIter.Next();
}
} break;
case FormFeature::RefreshCurrentControl:
{
Reference< XRefreshable > xControlModelRefresh( impl_getCurrentControlModel_throw(), UNO_QUERY );
OSL_ENSURE( xControlModelRefresh.is(), "FormOperations::execute: how did you reach this?" ); if ( xControlModelRefresh.is() )
xControlModelRefresh->refresh();
} break;
case FormFeature::DeleteRecord:
{
sal_uInt32 nCount = impl_getRowCount_throw();
// delete it if ( bSuccess )
m_xUpdateCursor->deleteRow();
} catch( const Exception& )
{
bSuccess = false;
}
if ( bSuccess )
{ if ( bLeft || bRight )
m_xCursor->relative( bRight ? 1 : -1 ); else
{ bool bCanInsert = ::dbtools::canInsert( m_xCursorProperties ); // is it possible to insert another record? if ( bCanInsert )
m_xUpdateCursor->moveToInsertRow(); else // move record to update status
m_xCursor->first();
}
}
} break;
case FormFeature::SaveRecordChanges: case FormFeature::UndoRecordChanges:
{ bool bInserting = impl_isInsertionRow_throw();
if ( FormFeature::UndoRecordChanges == _nFeature )
{ if ( !bInserting )
m_xUpdateCursor->cancelRowUpdates();
// reset all controls for this form
impl_resetAllControls_nothrow( );
if ( bInserting ) // back to insertion mode for this form
m_xUpdateCursor->moveToInsertRow();
} else
{ if ( bInserting )
{
m_xUpdateCursor->insertRow();
m_xCursor->last();
} else
m_xUpdateCursor->updateRow();
}
} break;
case FormFeature::MoveToInsertRow: // move to the last row before moving to the insert row
m_xCursor->last();
m_xUpdateCursor->moveToInsertRow(); break;
case FormFeature::RemoveFilterAndSort:
{ // simultaneously reset Filter and Order property
Reference< XMultiPropertySet > xProperties( m_xCursorProperties, UNO_QUERY );
OSL_ENSURE( xProperties.is(), "FormOperations::execute: no multi property access!" ); if ( xProperties.is() )
{
Sequence< OUString > aNames{ PROPERTY_FILTER, PROPERTY_HAVINGCLAUSE,
PROPERTY_SORT };
// at the moment we have only one feature which supports execution parameters if ( !lcl_isExecutableFeature( _nFeature ) ) throw IllegalArgumentException( ResourceManager::loadString(RID_STR_FEATURE_NOT_EXECUTABLE), *this, 1 );
bool FormOperations::impl_commitCurrentRecord_throw( sal_Bool* _pRecordInserted ) const
{ #ifdef DBG_UTIL
DBG_ASSERT( m_nMethodNestingLevel, "FormOperations::impl_commitCurrentRecord_throw: to be called within a MethodGuard'ed section only!" ); #endif
if ( !impl_hasCursor_nothrow() ) returnfalse;
// nothing to do if the record is not modified bool bResult = !impl_isModifiedRow_throw(); if ( !bResult )
{ // insert respectively update the row if ( impl_isInsertionRow_throw() )
{
m_xUpdateCursor->insertRow(); if ( _pRecordInserted )
*_pRecordInserted = true;
} else
m_xUpdateCursor->updateRow();
bResult = true;
} return bResult;
}
bool FormOperations::impl_commitCurrentControl_throw() const
{ #ifdef DBG_UTIL
DBG_ASSERT( m_nMethodNestingLevel, "FormOperations::impl_commitCurrentControl_throw: to be called within a MethodGuard'ed section only!" ); #endif
OSL_PRECOND( m_xController.is(), "FormOperations::commitCurrentControl: no controller!" ); if ( !m_xController.is() ) returnfalse;
// check whether the control is locked
Reference< XBoundControl > xCheckLock( xCurrentControl, UNO_QUERY ); bool bControlIsLocked = xCheckLock.is() && xCheckLock->getLock();
// commit if necessary
bSuccess = true; if ( xCurrentControl.is() && !bControlIsLocked )
{ // both the control and its model can be committable, so try both
Reference< XBoundComponent > xBound( xCurrentControl, UNO_QUERY ); if ( !xBound.is() )
xBound.set(xCurrentControl->getModel(), css::uno::UNO_QUERY); // and now really commit if ( xBound.is() )
bSuccess = xBound->commit();
}
void SAL_CALL FormOperations::disposing( const EventObject& /*_Source*/ )
{ // TODO: should we react on this? Or is this the responsibility of our owner to dispose us?
}
// start listening at the order/sort properties at the form, so // we can keep our parser in sync
m_xCursorProperties->addPropertyChangeListener( PROPERTY_ACTIVECOMMAND, this );
m_xCursorProperties->addPropertyChangeListener( PROPERTY_FILTER, this );
m_xCursorProperties->addPropertyChangeListener( PROPERTY_HAVINGCLAUSE, this );
m_xCursorProperties->addPropertyChangeListener( PROPERTY_SORT, this );
}
} catch( const Exception& )
{
TOOLS_WARN_EXCEPTION( "forms.runtime", "FormOperations::impl_ensureInitializedParser_nothrow" );
}
m_bInitializedParser = true;
}
void FormOperations::impl_disposeParser_nothrow()
{ try
{ // if we have a parser (and a cursor), then we're listening at the cursor's // properties to keep the parser in sync with the cursor if ( m_xParser.is() && m_xCursorProperties.is() )
{
m_xCursorProperties->removePropertyChangeListener( PROPERTY_FILTER, this );
m_xCursorProperties->removePropertyChangeListener( PROPERTY_HAVINGCLAUSE, this );
m_xCursorProperties->removePropertyChangeListener( PROPERTY_ACTIVECOMMAND, this );
m_xCursorProperties->removePropertyChangeListener( PROPERTY_SORT, this );
}
sal_Int32 FormOperations::impl_gridView2ModelPos_nothrow( const Reference< XIndexAccess >& _rxColumns, sal_Int16 _nViewPos )
{
OSL_PRECOND( _rxColumns.is(), "FormOperations::impl_gridView2ModelPos_nothrow: invalid columns container!" ); try
{ // loop through all columns
sal_Int32 col = 0;
Reference< XPropertySet > xCol; bool bHidden( false ); for ( col = 0; col < _rxColumns->getCount(); ++col )
{
_rxColumns->getByIndex( col ) >>= xCol;
OSL_VERIFY( xCol->getPropertyValue( PROPERTY_HIDDEN ) >>= bHidden ); if ( bHidden ) continue;
// for every visible col : if nViewPos is greater zero, decrement it, else we // have found the model position if ( !_nViewPos ) break; else
--_nViewPos;
} if ( col < _rxColumns->getCount() ) return col;
} catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("forms.runtime");
} return -1;
}
void FormOperations::impl_moveLeft_throw( ) const
{
OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_moveLeft_throw: no cursor!" ); if ( !impl_hasCursor_nothrow() ) return;
if ( bRecordInserted )
{ // retrieve the bookmark of the new record and move to the record preceding this bookmark
Reference< XRowLocate > xLocate( m_xCursor, UNO_QUERY );
OSL_ENSURE( xLocate.is(), "FormOperations::impl_moveLeft_throw: no XRowLocate!" ); if ( xLocate.is() )
xLocate->moveRelativeToBookmark( xLocate->getBookmark(), -1 );
} else
{ if ( impl_isInsertionRow_throw() )
{ // we assume that the inserted record is now the last record in the // result set
m_xCursor->last();
} else
m_xCursor->previous();
}
}
void FormOperations::impl_moveRight_throw( ) const
{
OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_moveRight_throw: no cursor!" ); if ( !impl_hasCursor_nothrow() ) return;
try
{
Reference< XReset > xReset;
sal_Int32 nCount( xContainer->getCount() ); for ( sal_Int32 i = 0; i < nCount; ++i )
{ if ( xContainer->getByIndex( i ) >>= xReset )
{ // no resets on sub forms
Reference< XForm > xAsForm( xReset, UNO_QUERY ); if ( !xAsForm.is() )
xReset->reset();
}
}
} catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("forms.runtime");
}
}
void FormOperations::impl_executeAutoSort_throw( bool _bUp ) const
{
OSL_PRECOND( m_xController.is(), "FormOperations::impl_executeAutoSort_throw: need a controller for this!" );
OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_executeAutoSort_throw: need a cursor for this!" );
OSL_PRECOND( impl_isParseable_throw(), "FormOperations::impl_executeAutoSort_throw: need a parseable statement for this!" ); if ( !m_xController.is() || !impl_hasCursor_nothrow() || !impl_isParseable_throw() ) return;
weld::WaitObject aWO(Application::GetFrameWeld(GetDialogParent())); try
{
m_xCursorProperties->setPropertyValue( PROPERTY_SORT, Any( m_xParser->getOrder() ) );
m_xLoadableForm->reload();
} catch( const Exception& )
{
TOOLS_WARN_EXCEPTION( "forms.runtime", "FormOperations::impl_executeAutoSort_throw: caught an exception while setting the parser properties!" );
}
if ( !m_xLoadableForm->isLoaded() )
{ // something went wrong -> restore the original state try
{
m_xParser->setOrder( sOriginalSort );
m_xCursorProperties->setPropertyValue( PROPERTY_SORT, Any( m_xParser->getOrder() ) );
m_xLoadableForm->reload();
} catch( const Exception& )
{
OSL_FAIL( "FormOperations::impl_executeAutoSort_throw: could not reset the form to its original state!" );
}
void FormOperations::impl_executeAutoFilter_throw( ) const
{
OSL_PRECOND( m_xController.is(), "FormOperations::impl_executeAutoFilter_throw: need a controller for this!" );
OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_executeAutoFilter_throw: need a cursor for this!" );
OSL_PRECOND( impl_isParseable_throw(), "FormOperations::impl_executeAutoFilter_throw: need a parseable statement for this!" ); if ( !m_xController.is() || !impl_hasCursor_nothrow() || !impl_isParseable_throw() ) return;
// if we have a filter, but it's not applied, then we have to overwrite it, else append one if ( !bApplied )
{
m_xParser->setFilter( OUString() );
m_xParser->setHavingClause( OUString() );
}
//tdf#122152 extract parent for dialog if (m_xController.is())
{
css::uno::Reference<css::awt::XControl> xContainerControl(m_xController->getContainer(), css::uno::UNO_QUERY); if (xContainerControl.is())
{
css::uno::Reference<css::awt::XWindowPeer> xContainerPeer = xContainerControl->getPeer();
xDialogParent = css::uno::Reference<css::awt::XWindow>(xContainerPeer, css::uno::UNO_QUERY);
}
}
return xDialogParent;
}
void FormOperations::impl_executeFilterOrSort_throw( bool _bFilter ) const
{
OSL_PRECOND( m_xController.is(), "FormOperations::impl_executeFilterOrSort_throw: need a controller for this!" );
OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_executeFilterOrSort_throw: need a cursor for this!" );
OSL_PRECOND( impl_isParseable_throw(), "FormOperations::impl_executeFilterOrSort_throw: need a parseable statement for this!" ); if ( !m_xController.is() || !impl_hasCursor_nothrow() || !impl_isParseable_throw() ) return;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.