*
* Effectively, this test case verifies the issues #i106574# and #i105235# did not creep back in.
*/
public void checkDetailFormDefaults() throws Exception
{
CRMDatabase database = null;
XCommandProcessor subComponentCommands = null;
try
{
// create our standard CRM database document
database = new CRMDatabase( m_orb, true );
// create a form document therein
XFormDocumentsSupplier formDocSupp = UnoRuntime.queryInterface( XFormDocumentsSupplier.class, database.getDatabase().getModel() );
XMultiServiceFactory formFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, formDocSupp.getFormDocuments() );
NamedValue[] loadArgs = new NamedValue[] {
new NamedValue( "ActiveConnection", database.getConnection().getXConnection() ),
new NamedValue( "MediaType", "application/vnd.oasis.opendocument.text" )
};
subComponentCommands = UnoRuntime.queryInterface(
XCommandProcessor.class,
formFactory.createInstanceWithArguments( "com.sun.star.sdb.DocumentDefinition", loadArgs ) );
Command command = new Command();
command.Name = "openDesign";
command.Argument = new Short( OpenMode.DOCUMENT );
DocumentHelper subDocument = new DocumentHelper( m_orb,
UnoRuntime.queryInterface( XComponent.class,
subComponentCommands.execute( command, subComponentCommands.createCommandIdentifier(), null )
)
);
FormLayer formLayer = new FormLayer( subDocument );
XPropertySet controlModel = formLayer.insertControlLine( "DatabaseNumericField", "ID", "", 10 );
formLayer.insertControlLine( "DatabaseTextField", "Name", "", 20 );
formLayer.insertControlLine( "DatabaseTextField", "Description", "", 30 );
m_masterForm = (XPropertySet)dbfTools.getParent( controlModel, XPropertySet.class );
m_masterForm.setPropertyValue( "Command", "categories" );
m_masterForm.setPropertyValue( "CommandType", new Integer( CommandType.TABLE ) );
// create a detail form
m_detailForm = UnoRuntime.queryInterface( XPropertySet.class, subDocument.createSubForm( m_masterForm, "products" ) );
m_detailForm.setPropertyValue( "Command", "SELECT \"ID\", \"Name\", \"CategoryID\" FROM \"products\"" );
m_detailForm.setPropertyValue( "CommandType", new Integer( CommandType.COMMAND ) );
m_detailForm.setPropertyValue( "MasterFields", new String[] { "ID" } );
m_detailForm.setPropertyValue( "DetailFields", new String[] { "CategoryID" } );
// create a grid control in the detail form, with some columns
XPropertySet gridControlModel = formLayer.createControlAndShape( "GridControl", 20, 40, 130, 50, m_detailForm );
gridControlModel.setPropertyValue( "Name", "product list" );
XIndexContainer gridColumns = UnoRuntime.queryInterface( XIndexContainer.class, gridControlModel );
impl_createGridColumn( gridColumns, "TextField", "ID" );
XPropertySet nameColumn = impl_createGridColumn( gridColumns, "TextField", "Name" );
nameColumn.setPropertyValue( "Width", new Integer( 600 ) ); // 6 cm
nameColumn.setPropertyValue( "DefaultText", "default text" );
// go live
m_masterResult = new ResultSet( m_masterForm );
m_detailResult = new ResultSet( m_detailForm );
XLoadable loadDetail = UnoRuntime.queryInterface( XLoadable.class, m_detailForm );
loadDetail.addLoadListener( this );
subDocument.getCurrentView().toggleFormDesignMode();
impl_waitForLoadedEvent();
// now that we set up this, do the actual tests
// First, http://www.openoffice.org/issues/show_bug.cgi?id=105235 described the problem
// that default values in the sub form didn't work when the master form was navigated to a row
// for which no detail records were present, and the default of the column/control is the same
// as the last known value.
// so, take the current value of the "Name" column, and set it as default value ...
String defaultValue = m_detailResult.getString( 2 );
nameColumn.setPropertyValue( "DefaultText", defaultValue );
// ... then move to the second main form row ...
m_masterResult.absolute( 2 );
impl_waitForLoadedEvent();
// ... which should result in an empty sub form ...
assure( "test precondition not met: The second master form record is expected to have no detail records, " +
"else the test becomes meaningless", impl_isNewRecord( m_detailForm ) );
// ... and in the "Name" column having the proper text
String actualValue = (String)nameColumn.getPropertyValue( "Text" );
assureEquals( "#i105235#: default value in sub form not working (not propagated to column model)", defaultValue, actualValue );
// However, checking the column model's value alone is not enough - we need to ensure it is properly
// propagated to the control.
XGridFieldDataSupplier gridData = (XGridFieldDataSupplier)subDocument.getCurrentView().getControl(
gridControlModel, XGridFieldDataSupplier.class );
actualValue = (String)(gridData.queryFieldData( 0, Type.STRING )[1]);
assureEquals( "#i105235#: default value in sub form not working (not propagated to column)", defaultValue, actualValue );
}
finally
{
if ( subComponentCommands != null )
{
XComponentSupplier componentSupplier = UnoRuntime.queryInterface( XComponentSupplier.class, subComponentCommands );
XModifiable modifySubComponent = UnoRuntime.queryInterface( XModifiable.class, componentSupplier.getComponent() );
modifySubComponent.setModified( false );
Command command = new Command();
command.Name = "close";
subComponentCommands.execute( command, subComponentCommands.createCommandIdentifier(), null );
}
if ( database != null )
database.saveAndClose();
impl_cleanUpStep();
}
}