Control Models

From Apache OpenOffice Wiki
Jump to: navigation, search

As you know from Form Control Models, the base for all our control models is the service. Let us look at the most relevant elements of the declaration of this service and what a component must do to support it:

This service specifies that a form control model complies to everything required for a control model by the UNO windowing toolkit as described in module This means support for the interface, for property access and persistence.

This service requires a form control model is part of a form component hierarchy. Refer to chapter A Hierarchy of Models.

This optional interface allows the control model properties to have a default value. All known implementations of the FormControlModel service support this interface.


This property determines the class of a control model you have , and it assumes a value from the enumeration. The same is done using the interface that is supported by every component, and as shown below it can be indispensable. Using the <idlml></idlml> property is faster.
Documentation note.png Note that the service does not state anything about data awareness. It describes the requirements for a control model which can be part of a form layer.

See chapter Data Awareness for additional information about the controls which are data aware.

The following example shows how to determine the type of a control model using the ClassId property introduced above:

  /** retrieves the type of a form component.
      <p>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.</p>
  static public String classifyFormComponentType(XPropertySet xComponent)
          throws {
      String sType = "<unknown component>";
      XServiceInfo xSI = (XserviceInfo)UnoRuntime.queryInterface(XServiceInfo.class, xComponent);
      XPropertySetInfo xPSI = null;
      if (null != xComponent)
          xPSI = xComponent.getPropertySetInfo();
      if ( ( null != xPSI ) && xPSI.hasPropertyByName("ClassId")) {
          // get the ClassId property
          XPropertySet xCompProps = (XPropertySet)UnoRuntime.queryInterface(
              XPropertySet.class, 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(
                      "")) {
                      sType = "Formatted Field";
      else {
          if ((null != xSI) && xSI.supportsService("")) {
              sType = "Form";
      return sType;

Note the special handling for the value <idlml></idlml>. There are two different services where a component implementing them is required to act as text field, the and Both services describe a text component, thus both have a class id of <idlml></idlml>. To distinguish between them, ask the components for more details using the interface.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages