Forms Container

From Apache OpenOffice Wiki
Jump to: navigation, search

In our model hierarchy, we have inner nodes called the logical forms, and the basic element called the form component. As in every tree, our hierarchy has a root, that is, an instance of the service. This is nothing more than an instance of In fact, the differentiation exists for a non-ambiguous runtime instantiation of a root.

Documentation note.png Note that the service does not state that components implementing it are a This means this service acts as a tree root only, as opposed to a that is a container, as well as an element, thus it can be placed anywhere in the tree.

Actually, it is not necessary for external components to instantiate a service directly. Every document has at least one instance of it. A root forms container is tied to a draw page, which is an element of the document model, as well. Refer to A page optionally supports the interface giving access to the collection. In the current implementation, Writer and Calc documents fully support draw pages supplying forms.

The following example shows how to obtain a root forms collection, if the document model is known which is denoted with s_aDocument.

  /** gets the <type scope="">DrawPage</type> of our sample document
  public static XDrawPage getDocumentDrawPage() throws java.lang.Exception {
      XDrawPage xReturn;
      // in case of a Writer document, this is rather easy: simply ask the XDrawPageSupplier
      XDrawPageSupplier xSuppPage = (XDrawPageSupplier)UnoRuntime.queryInterface(
          XDrawPageSupplier.class, s_aDocument);
      xReturn = xSuppPage.getDrawPage();
      if (null == xReturn) {
          // the model itself is no draw page supplier - then it may be an Impress or Calc
          // (or any other multi-page) document
          XDrawPagesSupplier xSuppPages = (XDrawPagesSupplier)UnoRuntime.queryInterface(
              XDrawPagesSupplier.class, s_aDocument);
          XDrawPages xPages = xSuppPages.getDrawPages();
          xReturn = (XdrawPage)UnoRuntime.queryInterface(XDrawPage.class, xPages.getByIndex(0));
          // Note that this is not really error-proof code: If the document model does not support the
          // XDrawPagesSupplier interface, or if the pages collection returned is empty, this will break.
      return xReturn;
  /** retrieves the root of the hierarchy of form components
  public static XNameContainer getFormComponentTreeRoot() throws java.lang.Exception {
      XFormsSupplier xSuppForms = (XFormsSupplier)UnoRuntime.queryInterface(
          XFormsSupplier.class, getDocumentDrawPage());
      XNameContainer xFormsCollection = null;
      if (null != xSuppForms) {
          xFormsCollection = xSuppForms.getForms();
      return xFormsCollection;
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages