External List Sources

From Apache OpenOffice Wiki
Jump to: navigation, search



The previous chapter introduced an abstraction of the data aware mechanism for form controls: They can not exchange their value with database columns or with arbitrary value bindings, without recognizing anything except UNO interfaces.

When you look at what controls can do with database content, you may find list and combo boxes useful. They are able to retrieve the content of their lists from a database.

Similar to the value binding mechanism, there is also an abstraction available for components supplying list entries to form controls: com.sun.star.form.binding.ListEntrySource and com.sun.star.form.binding.XListEntrySink.

The relationship between XListEntrySources and XListEntrySinks is shown in the illustration below.

Interfaces and services involved with external list sources

As with value bindings, Apache OpenOffice already makes use of this concept in spreadsheet documents. The following piece of code, for instance, creates a CellRangeListSource, and binds it to a list box. After that, the list boxes content will always be synchronized with the content in the chosen cell range.

  CellRangeAddress rangeAddress = new CellRangeAddress( sheet, column,
      topRow, column, bottomRow );
  Object[] initParam = new Object[] { new NamedValue( "CellRange", rangeAddress ) };
  XListEntrySource entrySource = (XListEntrySource)UnoRuntime.queryInterface(
      XListEntrySource.class, m_document.createInstanceWithArguments(
          "com.sun.star.table.CellRangeListSource", initParam ) );
 
  XListEntrySink consumer = (XListEntrySink)UnoRuntime.queryInterface(
      XListEntrySink.class, listBox );
  consumer.setListEntrySource( entrySource );

Note that a CellRangeListSource can not be obtained at a global service manager. Instead, you have to retrieve it from the document to whose cells you want to bind the list box.

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