Difference between revisions of "Documentation/DevGuide/GUI/The Example Listings"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
m
Line 10: Line 10:
  
 
All coding examples that demonstrate how to insert controls into a dialog make use of the following method:
 
All coding examples that demonstrate how to insert controls into a dialog make use of the following method:
 
+
<source lang="java">
 
   /** makes a String unique by appending a numerical suffix
 
   /** makes a String unique by appending a numerical suffix
 
   * @param _xElementContainer the com.sun.star.container.XNameAccess container
 
   * @param _xElementContainer the com.sun.star.container.XNameAccess container
Line 30: Line 30:
 
       return _sElementName;
 
       return _sElementName;
 
   }
 
   }
 
+
</source>
 
As already explained, the dialog keeps the controls in a <code>NamedContainer</code> that implements <idl>com.sun.star.container.XNameAccess</idl>. It is absolutely necessary for the controls to have a unique name before they are added to the dialog to prevent a <idl>com.sun.star.container.ElementExistException</idl> . This method appends a suffix to the scheduled name of the control to make sure that the name is unique.
 
As already explained, the dialog keeps the controls in a <code>NamedContainer</code> that implements <idl>com.sun.star.container.XNameAccess</idl>. It is absolutely necessary for the controls to have a unique name before they are added to the dialog to prevent a <idl>com.sun.star.container.ElementExistException</idl> . This method appends a suffix to the scheduled name of the control to make sure that the name is unique.
  
 
{{PDL1}}
 
{{PDL1}}
 
[[Category: Graphical User Interfaces]]
 
[[Category: Graphical User Interfaces]]

Revision as of 13:28, 29 March 2008



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 sIncSuffix = "";
      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