Forms and Reports

From Apache OpenOffice Wiki
Jump to: navigation, search



Since OpenOffice.org 2.0.0, you can not only link to documents that belong to a data source, but you can store your forms and reports within the OpenOffice database file.

The interface com.sun.star.sdb.XFormDocumentsSupplier, supplied by the DataSource, provides access to the forms stored in the database file of the data source. It has one method:

  com::sun::star::container::XNameAccess getFormDocuments()

The interface com.sun.star.sdb.XReportDocumentsSupplier provides access to the reports stored in the database file of the data source. It has one method:

  com::sun::star::container::XNameAccess getReportDocuments()

The returned service is a com.sun.star.sdb.DocumentContainer. The DocumentContainer is not only an XNameAccess, but a com.sun.star.container.XNameContainer, which means that new forms or reports are added using insertByName() as described in the First Steps chapter. To support the creation of hierarchies, the service com.sun.star.sdb.DocumentContainer additionally supplies the interfaces com.sun.star.container.XHierarchicalNameContainer and com.sun.star.container.XHierarchicalNameAccess. The interfaces com.sun.star.container.XHierarchicalNameContainer and com.sun.star.container.XHierarchicalNameAccess can be used to create folder hierarchies and to organize forms or reports in different sub folders.

Along with the name access, forms and reports are obtained through com.sun.star.container.XIndexAccess, and com.sun.star.container.XEnumerationAccess.

The interface com.sun.star.lang.XMultiServiceFactory is used to create new forms or reports. The method createInstanceWithArguments() of XMultiServiceFactory creates a new document definition. Whether the document is a form or a report depends on the container where this object is inserted.

Relation design of Reports and Forms

The following are the allowed properties for the document definition:

Arguments of createInstanceWithArguments method with com.sun.star.sdb.DocumentDefinition as service name
PropertyValue Name: Name

Value: string - Defines the name of the document.

PropertyValue Name: URL

Value: string - Points to a extern document.

PropertyValue Name: ActiveConnection

Value: com.sun.star.sdbc.XConnection - The connection to be used by the document.

PropertyValue Name: EmbeddedObject

Value: com.sun.star.sdb.DocumentDefinition - The document definition that is to be copied.

To create a new document definition, only the Name and the ActiveConnection must be set. If an existing document from the file system is to be included, the URL property must be filled with the file URL. To copy document definitions, the EmbeddedObject must be filled with the document definition to be copied.

The following are the allowed properties for the document container:

Arguments of createInstanceWithArguments method with com.sun.star.sdb.Forms or com.sun.star.sdb.Reports as service name
PropertyValue Name: Name

Value: string - Defines the name of the document.

PropertyValue Name: EmbeddedObject

Value: com.sun.star.sdb.DocumentDefinition or com.sun.star.sdb.DocumentContainer - The document definition (form or report object) or a document container (form container or report container) which is to be copied.

When creating a sub folder inside the forms or reports hierarchy, it is enough to set the Name property. If the EmbeddedObject property is set, then it is copied. If the EmbeddedObject supports the XHierarchicalNameAccess, the children are also copied. The EmbeddedObject can be a document definition or a document container.

The service com.sun.star.sdb.DocumentContainer additionally defines the interface com.sun.star.frame.XComponentLoader that is used to get access to the contained document inside the DocumentDefinition and it has one method:

  com::sun::star::lang::XComponent loadComponentFromURL(
          [in] string URL,
          [in] string TargetFrameName,
          [in] long SearchFlags,
          [in] sequence<com::sun::star::beans::PropertyValue> Arguments)
          raises( com::sun::star::io::IOException,
                  com::sun::star::lang::IllegalArgumentException );
  • URL: describes the name of the document definition to load,
  • TargetFrameName: is not used.
  • SearchFlags: is not used.
  • Arguments:
    1. PropertyValue
    2. PropertyValue
      • Name = OpenMode
      • Value = string, "open" if the document is to be opened in live mode (editing is not possible), "openDesign" if the document is to be opened in design mode (editing is possible)
  // opens a form in design mode
      public static void openFormInDesignMode(XMultiServiceFactory _rMSF) throws com.sun.star.uno.Exception
      {
          XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class,
          _rMSF.createInstance("com.sun.star.sdb.DatabaseContext"));
          // we use the first datasource
          XDataSource xDS = (XDataSource)UnoRuntime.queryInterface(
          XDataSource.class, xNameAccess.getByName( "Bibliography" )); 
          XConnection con = xDS.getConnection("","");
          XFormsSupplier xSup = (XFormsSupplier)UnoRuntime.queryInterface(XFormsSupplier.class, xDS); 
 
          XNameAccess xForms = xSup.getFormDocuments();
          if ( xForms.hasByName("Form1") ){
              Object form = xForms.getByName("Form1"); // to hold ref
              {
                  XComponentLoader loader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, xForms); 
                  PropertyValue[] args = new PropertyValue[]{PropertyValue("OpenMode",0,"openDesign")
                  ,PropertyValue("ActiveConnection",0,con)};
                  XComponent formdocument = loader.loadComponentFromURL("Form1","",0,args);
              }
          }
      }

The returned object is a com.sun.star.text.TextDocument service. For forms, see Forms

Documentation note.png The document definition object is the owner of the accessed com.sun.star.text.TextDocument. When the document definition is released (last reference gone), the text document is also closed.

The returned form or report documents are com.sun.star.sdb.DocumentDefinition services. These are the properties of the com.sun.star.sdb.DocumentDefinition service.

Properties of com.sun.star.sdb.DocumentDefinition
Name string - Defines the name of the document.
AsTemplate boolean - Indicates if the document is to be used as template, for example, if a report is to be filled with data.

In addition to these properties, the com.sun.star.sdb.DocumentDefinition service offers a com.sun.star.sdbcx.XRename to rename a DocumentDefinition.

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