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

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(4 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/GUI/Label Field
 
|NextPage=Documentation/DevGuide/GUI/Label Field
 
}}
 
}}
{{DISPLAYTITLE:The Example Listings}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/GUI/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:The Example Listings}}
 
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.  
 
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:
 
All coding examples that demonstrate how to insert controls into a dialog make use of the following method:
<source lang="java">
+
<syntaxhighlight 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 19: Line 20:
 
       boolean bElementexists = true;
 
       boolean bElementexists = true;
 
       int i = 1;
 
       int i = 1;
      String sIncSuffix = "";
 
 
       String BaseName = _sElementName;
 
       String BaseName = _sElementName;
 
       while (bElementexists) {
 
       while (bElementexists) {
Line 30: Line 30:
 
       return _sElementName;
 
       return _sElementName;
 
   }
 
   }
</source>
+
</syntaxhighlight>
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:Documentation/Developer's Guide/Graphical User Interfaces]]

Latest revision as of 18:52, 21 December 2020



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