Hello Calc Team!

(warning: it's a long post)

I'd like get your input on the new UNO API that I have introduced as
part of implementing the multi-string filter.  The relevant issue page
is here:

  http://qa.openoffice.org/issues/show_bug.cgi?id=77677

Currently, Calc only has one type of sheet filter, which is represented
by com.sun.star.sheet.TableFilterField.  And it is read from & written
to the document model all at once via getFilterFields and
setFilterFields in the XSheetFilterDescriptor interface.  Multiple
instances of this data are contained in css::uno::Sequence.

Because I needed to allow reading and writing of filters of different
types, which the current API doesn't allow, I created a new set of API
just for this.  Let me summarize the new API below.

First, the data structures.  In my draft implementation, I've
implemented the following three data structures (com::sun::star is
omitted to save space).

struct TableFilterFieldBase
{
    sheet::FilterConnection Connection;
    long Field;
};

struct TableFilterFieldMultiString: TableFilterFieldBase
{
    sequence< string > StringSet;
};

struct TableFilterFieldNormal: TableFilterFieldBase
{
    sheet::FilterOperator Operator;
    boolean IsNumeric;
    double NumericValue;
    string StringValue;
};

The presence of the base struct is to ease the handling of these
different filter types, so that the consumer of this API can store all
filters in a single container without sacrificing type safety too much.

These data structures are exchanged via XExtendedSheetFilterDescriptor,
which is exported by the existing SheetFilterDescriptor service.

interface XExtendedSheetFilterDescriptor
{
    void begin();

    void commit();

    void addFilterFieldNormal( 
        [in] sheet::TableFilterFieldNormal aField );

    void addFilterFieldMultiString( 
        [in] sheet::TableFilterFieldMultiString aField );

    TableFilterFieldType getFirstType();

    TableFilterFieldType getNextType();

    void getFilterFieldNormal( 
        [out] sheet::TableFilterFieldNormal aField );

    void getFilterFieldMultiString( 
        [out] sheet::TableFilterFieldMultiString aField );
};

There is also an enum type css.sheet.TableFilterFieldType:

enum TableFilterFieldType
{
    NORMAL,
    MULTI_STRING,
    NONE
};

To write a new set of filter fields, a typical code snippet might look
like this:

Reference<sheet::XExtendedSheetFilterDescriptor> xExtDescriptor(...,
UNO_QUERY);
xExtDescriptor->begin();

a bunch of
{
    {
        TableFilterFieldNormal aField;
        ...
        xExtDescriptor->addFilterFieldNormal(aField);
    } 
    or 
    {
        TableFilterFieldMultiString aField;
        ...
        xExtDescriptor->addFilterFieldMultiString(aField);
    }
}
xExtDescriptor->commit();

To read the existing filter set, a code snippet might look like this:

TableFilterFieldType eType = xExtDescriptor->getFirstType();
while ( eType != TableFilterFieldType_NONE )
{
    switch ( eType )
    {
        case TableFilterFieldType_NORMAL:
            TableFilterFieldNormal aField;
            xExtDescriptor->getFilterFieldNormal(aField);
            ...
        break;
        case TableFilterFieldType_MULTI_STRING:
            TableFilterFieldMultiString aField;
            xExtDescriptor->getFilterFieldMultiString(aField);
            ...
        break;
    }
    eType = xExtDescriptor->getNextType();
}

Before settling on this API, I had gone through two or three different
variations, and I like this one best.  It is already used in my draft
implementation of import & export of multi-string filter.  This design
also allows future additions of new types of filters when they arise.

There is one problem, however, regarding the published vs unpublished
state of these interface/struct/enum constructs.  Daniel and I have
discussed this before, and his advice was to add the new, unpublished
XExtendedSheetFilterDescriptor interface to SheetFilterDescriptor as an
[optional] interface.  He said that it should then allow the new
interface to remain unpublished.  But the compatibility check of the
offapi module build still complains, noting that "You cannot use an
unpublished interface in a published service".  Do you guys have any
suggestions on this?

Thanks a lot,
Kohei


-- 
Kohei Yoshida - OpenOffice.org Engineer - Novell, Inc.
<[EMAIL PROTECTED]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to