aInterfaceClass )
{
XControl xControl = UnoRuntime.queryInterface(
XControl.class, aControl );
XControlModel xModel = null;
if ( null != xControl )
xModel = xControl.getModel();
return UnoRuntime.queryInterface( aInterfaceClass, xModel );
}
/* ------------------------------------------------------------------ */
/** retrieves the type of a form component.
Speaking strictly, the function recognizes more than form components. Especially,
it survives a null argument. which means it can be safely applied to the a top-level
forms container; and it is able to classify grid columns (which are no form components)
as well.
*/
static public String classifyFormComponentType( XPropertySet xComponent ) throws com.sun.star.uno.Exception
{
String sType = "";
XServiceInfo xSI = UNO.queryServiceInfo( xComponent );
XPropertySetInfo xPSI = null;
if ( null != xComponent )
xPSI = xComponent.getPropertySetInfo();
if ( ( null != xPSI ) && xPSI.hasPropertyByName( "ClassId" ) )
{
// get the ClassId property
XPropertySet xCompProps = UNO.queryPropertySet( xComponent );
Short nClassId = (Short)xCompProps.getPropertyValue( "ClassId" );
switch ( nClassId.intValue() )
{
case FormComponentType.COMMANDBUTTON: sType = "Command button"; break;
case FormComponentType.RADIOBUTTON : sType = "Radio button"; break;
case FormComponentType.IMAGEBUTTON : sType = "Image button"; break;
case FormComponentType.CHECKBOX : sType = "Check Box"; break;
case FormComponentType.LISTBOX : sType = "List Box"; break;
case FormComponentType.COMBOBOX : sType = "Combo Box"; break;
case FormComponentType.GROUPBOX : sType = "Group Box"; break;
case FormComponentType.FIXEDTEXT : sType = "Fixed Text"; break;
case FormComponentType.GRIDCONTROL : sType = "Grid Control"; break;
case FormComponentType.FILECONTROL : sType = "File Control"; break;
case FormComponentType.HIDDENCONTROL: sType = "Hidden Control"; break;
case FormComponentType.IMAGECONTROL : sType = "Image Control"; break;
case FormComponentType.DATEFIELD : sType = "Date Field"; break;
case FormComponentType.TIMEFIELD : sType = "Time Field"; break;
case FormComponentType.NUMERICFIELD : sType = "Numeric Field"; break;
case FormComponentType.CURRENCYFIELD: sType = "Currency Field"; break;
case FormComponentType.PATTERNFIELD : sType = "Pattern Field"; break;
case FormComponentType.TEXTFIELD :
// there are two known services with this class id: the usual text field,
// and the formatted field
sType = "Text Field";
if ( ( null != xSI ) && xSI.supportsService( "com.sun.star.form.component.FormattedField" ) )
{
sType = "Formatted Field";
}
break;
default:
break;
}
}
else
{
if ( ( null != xSI ) && xSI.supportsService( "com.sun.star.form.component.DataForm" ) )
{
sType = "Form";
}
}
return sType;
}
};