From Apache OpenOffice Wiki
Jump to: navigation, search

The com.sun.star.sheet.DataPilotSourceDimensions service contains an entry for each dimension that can be used as column, row or page dimension, for each possible data (measure) dimension, and one for the "data layout" dimension that contains the names of the data dimensions.

The example below initializes a dimension's orientation as DATA for the data dimension, and is otherwise HIDDEN. Thus, when the user creates a new DataPilot table using the example component, the data dimension is already present in the "Data" area of the DataPilot dialog.

 private ExampleSettings aSettings;
 private int nDimension;
 private com.sun.star.sheet.DataPilotFieldOrientation eOrientation;
 public ExampleDimension(ExampleSettings aSet, int nDim) {
     aSettings = aSet;
     nDimension = nDim;
     eOrientation = (nDim == ExampleSettings.nValueDimension) ?
         com.sun.star.sheet.DataPilotFieldOrientation.DATA :

The com.sun.star.sheet.DataPilotSourceDimension service contains a com.sun.star.beans.XPropertySet interface that is used for the following properties of a dimension:

  • Original (read-only) contains the dimension object from which a dimension was cloned, or null if it was not cloned. A description of the com.sun.star.util.XCloneable interface is described below.
  • IsDataLayoutDimension (read-only) must contain true if the dimension is the "data layout" dimension, otherwise false.
  • Orientation controls how a dimension is used in the DataPilot table. If it contains the com.sun.star.sheet.DataPilotFieldOrientation enum values COLUMN or ROW, the dimension is used as a column or row dimension, respectively. If the value is DATA, the dimension is used as data (measure) dimension. The PAGE designates a page dimension, but is not currently used in OpenOffice.org API Calc. If the value is HIDDEN, the dimension is not used.
  • Position contains the position of the dimension within the orientation. This controls the order of the dimensions. If a dimension's orientation is changed, it is added at the end of the dimensions for that orientation, and the Position property reflects that position.
  • Function specifies the function that is used to aggregate data for a data dimension.
  • UsedHierarchy selects which of the dimension's hierarchies is used in the DataPilot table. See the section on hierarchies below.
  • Filter specifies a list of filter criteria to be applied to the source data before processing. It is currently not used by OpenOffice.org API Calc.

In the following example, the setPropertyValue() method for the dimension only implements the modification of Orientation and Position, using two lists to store the order of column and row dimensions. Page dimensions are not supported in the example.

 public void setPropertyValue(String aPropertyName, Object aValue)
         throws com.sun.star.beans.UnknownPropertyException {
     if (aPropertyName.equals("Orientation")) {
         com.sun.star.sheet.DataPilotFieldOrientation eNewOrient =
             (com.sun.star.sheet.DataPilotFieldOrientation) aValue;
         if (nDimension != ExampleSettings.nValueDimension &&
                 nDimension != ExampleSettings.nDataDimension &&
                 eNewOrient != com.sun.star.sheet.DataPilotFieldOrientation.DATA) {
             // remove from list for old orientation and add for new one
             Integer aDimInt = new Integer(nDimension);
             if (eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.COLUMN)
             else if (eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.ROW)
             if (eNewOrient == com.sun.star.sheet.DataPilotFieldOrientation.COLUMN)
             else if (eNewOrient == com.sun.star.sheet.DataPilotFieldOrientation.ROW)
             // change orientation
             eOrientation = eNewOrient;
     } else if (aPropertyName.equals("Position")) {
         int nNewPos = ((Integer) aValue).intValue();
         Integer aDimInt = new Integer(nDimension);
         if (eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.COLUMN) {
             aSettings.aColDimensions.add( nNewPos, aDimInt );
         else if (eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.ROW) {
             aSettings.aRowDimensions.add(nNewPos, aDimInt);
     } else if (aPropertyName.equals("Function") || aPropertyName.equals("UsedHierarchy") ||
             aPropertyName.equals("Filter")) {
         // ignored
     } else
         throw new com.sun.star.beans.UnknownPropertyException();

The associated getPropertyValue() method returns the stored values for Orientation and Position. If it is the data layout dimension, then IsDataLayoutDimension is true, and the values default for the remaining properties.

 public Object getPropertyValue(String aPropertyName)
         throws com.sun.star.beans.UnknownPropertyException {
     if (aPropertyName.equals("Original"))
         return null;
     else if (aPropertyName.equals( "IsDataLayoutDimension"))
         return new Boolean(nDimension == ExampleSettings.nDataDimension);
     else if (aPropertyName.equals("Orientation"))
         return eOrientation;
     else if (aPropertyName.equals("Position")) {
         int nPosition;
         if (eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.COLUMN)
             nPosition = aSettings.aColDimensions.indexOf(new Integer(nDimension));
         else if (eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.ROW)
             nPosition = aSettings.aRowDimensions.indexOf(new Integer(nDimension));
             nPosition = nDimension;
         return new Integer(nPosition);
     else if (aPropertyName.equals("Function"))
         return com.sun.star.sheet.GeneralFunction.SUM;
     else if (aPropertyName.equals("UsedHierarchy"))
         return new Integer(0);
     else if (aPropertyName.equals("Filter"))
         return new com.sun.star.sheet.TableFilterField[0];
          throw new com.sun.star.beans.UnknownPropertyException();

The dimension's com.sun.star.util.XCloneable interface is required when a dimension is used in multiple positions. The DataPilot dialog allows the use of a column or row dimension additionally as data dimension, and it also allows multiple use of a data dimension by assigning several functions to it. In both cases, additional dimension objects are created from the original one by calling the createClone() method. Each clone is given a new name using the com.sun.star.container.XNamed interface's setName() method, then the different settings are applied to the objects. A dimension object that was created using the createClone() method must return the original object that it was created from in the Original property.

The example does not support multiple uses of a dimension, so it always returns null from the createClone() method, and the Original property is also always null.

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