FormComponents Service

From Apache OpenOffice Wiki
Jump to: navigation, search

In the level above, a single form component is a container for components. Stepping away from the document model, you are looking for a specific form component, such as the model of a control, you pass where all the control models are attached. This is the component. The service offers basic container functionality, namely an access to its elements by index or by name), and a possibility to enumerate its elements.

Provided that you have a container at hand, the access to its elements is straightforward. For example, assume you want to enumerate all the elements in the container, and apply a specific action for every element. The enumFormComponents() method below does this by recursively enumerating the elements in a container.

  /** enumerates and prints all the elements in the given container
  public static void enumFormComponents(XNameAccess xContainer, String sPrefix)
          throws java.lang.Exception {
      // loop through all the element names
      String aNames[] = xContainer.getElementNames();
      for (int i=0; i<aNames.length; ++i) {
          // print the child name
          System.out.println(sPrefix + aNames[i]);
          // check if it is a FormComponents component itself
          XServiceInfo xSI = (XServiceInfo)UnoRuntime.queryInterface(XServiceInfo.class,
          if (xSI.supportsService("")) {
              // yep, it is
              // -> step down
              XNameAccess xChildContainer = (XNameAccess)UnoRuntime.queryInterface(
                  XNameAccess.class, xSI);
              enumFormComponents(xChildContainer, new String(" ") + sPrefix);
  /** enumerates and prints all the elements in the given container, together with the container itself
  public static void enumFormComponents(XNameAccess xContainer) throws java.lang.Exception {
      XNamed xNameAcc = (XNamed)UnoRuntime.queryInterface(XNamed.class, xContainer);
      String sObjectName = xNameAcc.getName();
      System.out.println( new String("enumerating the container named \"") + sObjectName +
          new String("\"\n"));
      enumFormComponents(xContainer, " ");
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages