/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
bool SbaExternalSourceBrowser::LoadForm()
{ // as we don't have a main form (yet), we have nothing to do // we don't call FormLoaded, because this expects a working data source returntrue;
}
// multiplex this event to all my listeners
css::lang::EventObject aEvt(*this);
m_aModifyListeners.notifyEach( &css::util::XModifyListener::modified, aEvt );
}
void SAL_CALL SbaExternalSourceBrowser::dispatch(const css::util::URL& aURL, const Sequence< css::beans::PropertyValue>& aArgs)
{ if ( aURL.Complete == ".uno:FormSlots/AddGridColumn" )
{ // search the argument describing the column to create
OUString sControlType;
sal_Int32 nControlPos = -1;
Sequence< css::beans::PropertyValue> aControlProps; for ( const css::beans::PropertyValue& rArgument : aArgs )
{ if ( rArgument.Name == "ColumnType" )
{ auto s = o3tl::tryAccess<OUString>(rArgument.Value);
OSL_ENSURE(s, "invalid type for argument \"ColumnType\" !"); if (s)
sControlType = *s;
} elseif ( rArgument.Name == "ColumnPosition" )
{ auto n = o3tl::tryAccess<sal_Int16>(rArgument.Value);
OSL_ENSURE(n, "invalid type for argument \"ColumnPosition\" !"); if (n)
nControlPos = *n;
} elseif ( rArgument.Name == "ColumnProperties" )
{ auto s = o3tl::tryAccess<Sequence<css::beans::PropertyValue>>(
rArgument.Value);
OSL_ENSURE(s, "invalid type for argument \"ColumnProperties\" !"); if (s)
aControlProps = *s;
} else
SAL_WARN("dbaccess.ui", "SbaExternalSourceBrowser::dispatch(AddGridColumn) : unknown argument (" << rArgument.Name << ") !");
} if (sControlType.isEmpty())
{
SAL_WARN("dbaccess.ui", "SbaExternalSourceBrowser::dispatch(AddGridColumn) : missing argument (ColumnType) !");
sControlType = "TextField";
}
OSL_ENSURE(aControlProps.hasElements(), "SbaExternalSourceBrowser::dispatch(AddGridColumn) : missing argument (ColumnProperties) !");
// create the col
Reference< css::form::XGridColumnFactory > xColFactory(getControlModel(), UNO_QUERY);
Reference< css::beans::XPropertySet > xNewCol = xColFactory->createColumn(sControlType);
Reference< XPropertySetInfo > xNewColProperties; if (xNewCol.is())
xNewColProperties = xNewCol->getPropertySetInfo(); // set its properties if (xNewColProperties.is())
{ for (const css::beans::PropertyValue& rControlProp : aControlProps)
{ try
{ if (xNewColProperties->hasPropertyByName(rControlProp.Name))
xNewCol->setPropertyValue(rControlProp.Name, rControlProp.Value);
} catch (const Exception&)
{
SAL_WARN("dbaccess.ui", "SbaExternalSourceBrowser::dispatch : could not set a column property (" << rControlProp.Name << ")!");
}
}
}
// correct the position
Reference< css::container::XIndexContainer > xColContainer(getControlModel(), UNO_QUERY);
if (nControlPos > xColContainer->getCount())
nControlPos = xColContainer->getCount(); if (nControlPos < 0)
nControlPos = 0;
Reference< XRowSet > xMasterForm; // search the arguments for the master form for (const css::beans::PropertyValue& rArgument : aArgs)
{ if ( (rArgument.Name == "MasterForm") && (rArgument.Value.getValueTypeClass() == TypeClass_INTERFACE) )
{
xMasterForm.set(rArgument.Value, UNO_QUERY); break;
}
} if (!xMasterForm.is())
{
SAL_WARN("dbaccess.ui", "SbaExternalSourceBrowser::dispatch(FormSlots/AttachToForm) : please specify a form to attach to as argument !"); return;
}
if ( ( aURL.Complete == ".uno:FormSlots/AttachToForm" ) // attach a new external form
|| ( aURL.Complete == ".uno:FormSlots/AddGridColumn" ) // add a column to the grid
|| ( aURL.Complete == ".uno:FormSlots/ClearView" ) // clear the grid
)
xReturn = static_cast<css::frame::XDispatch*>(this);
// split the css::util::URL
OSL_ENSURE( m_xUrlTransformer.is(), "SbaExternalSourceBrowser::queryDispatch : could not create a URLTransformer !" ); if ( m_xUrlTransformer.is() )
m_xUrlTransformer->parseStrict( aNewUrl );
// set a new mark
aNewUrl.Mark = "DB/FormGridView"; // this controller is instantiated when somebody dispatches the ".component:DB/FormGridView" in any // frame, so we use "FormGridView" as mark that a dispatch request came from this view
if (m_xUrlTransformer.is())
m_xUrlTransformer->assemble(aNewUrl);
try
{ // switch the control to design mode if (getBrowserView() && getBrowserView()->getGridControl().is())
getBrowserView()->getGridControl()->setDesignMode(true);
// the grid will move the form's cursor to the first record, but we want the form to remain unchanged // restore the old position if (xCursor.is() && xMaster.is())
{
bBeforeFirst = xMaster->isBeforeFirst();
bAfterLast = xMaster->isAfterLast(); if(!bBeforeFirst && !bAfterLast)
aOldPos = xCursor->getBookmark();
}
// at this point we have to reset the formatter for the new form
initFormatter(); // assume that the master form is already loaded #if OSL_DEBUG_LEVEL > 0
{
Reference< XLoadable > xLoadable( xMaster, UNO_QUERY );
OSL_ENSURE( xLoadable.is() && xLoadable->isLoaded(), "SbaExternalSourceBrowser::Attach: master is not loaded!" );
} #endif
void SbaExternalSourceBrowser::ClearView()
{ // set a new (empty) datasource
Attach(Reference< XRowSet > ());
// clear all cols in the grid
Reference< css::container::XIndexContainer > xColContainer(getControlModel(), UNO_QUERY); while (xColContainer->getCount() > 0)
xColContainer->removeByIndex(0);
}
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.