The Example Listings

From Apache OpenOffice Wiki
Jump to: navigation, search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.



As is generally known, an example is worth a thousand words. This is especially true for UNO. Sourcecode written in UNO is very often self-explanatory and for this reason the following sections provide a large set of example listings. Some of them are ready-to-use, whereas the focus of other examples is on demonstrating concepts.

All coding examples that demonstrate how to insert controls into a dialog make use of the following method:

  /** makes a String unique by appending a numerical suffix
   * @param _xElementContainer the com.sun.star.container.XNameAccess container
   * that the new Element is going to be inserted to
   * @param _sElementName the StemName of the Element
   */
  public static String createUniqueName(XNameAccess _xElementContainer, String _sElementName) {
      boolean bElementexists = true;
      int i = 1;
      String BaseName = _sElementName;
      while (bElementexists) {
          bElementexists = _xElementContainer.hasByName(_sElementName);
          if (bElementexists) {
              i += 1;
              _sElementName = BaseName + Integer.toString(i);
          }
      }
      return _sElementName;
  }

As already explained, the dialog keeps the controls in a NamedContainer that implements com.sun.star.container.XNameAccess. It is absolutely necessary for the controls to have a unique name before they are added to the dialog to prevent a com.sun.star.container.ElementExistException. This method appends a suffix to the scheduled name of the control to make sure that the name is unique.

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