1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 import com
.sun
.star
.sheet
.DataPilotFieldFilter
;
4 /*************************************************************************
6 * The Contents of this file are made available subject to the terms of
9 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
31 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
34 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *************************************************************************/
38 // Example DataPilot source component
40 // helper class to hold the settings
44 public static final int nDimensionCount
= 6;
45 public static final int nValueDimension
= 4;
46 public static final int nDataDimension
= 5;
47 public static final String
[] aDimensionNames
= {
48 "ones", "tens", "hundreds", "thousands", "value", "" };
50 public static final String
getMemberName( int nMember
)
52 return String
.valueOf( nMember
);
55 public int nMemberCount
= 3;
56 public java
.util
.List
<Integer
> aColDimensions
= new java
.util
.ArrayList
<Integer
>();
57 public java
.util
.List
<Integer
> aRowDimensions
= new java
.util
.ArrayList
<Integer
>();
60 // XPropertySetInfo implementation for getPropertySetInfo
62 class ExamplePropertySetInfo
implements com
.sun
.star
.beans
.XPropertySetInfo
64 private final com
.sun
.star
.beans
.Property
[] aProperties
;
66 public ExamplePropertySetInfo( com
.sun
.star
.beans
.Property
[] aProps
)
71 public com
.sun
.star
.beans
.Property
[] getProperties()
76 public com
.sun
.star
.beans
.Property
getPropertyByName( String aName
)
77 throws com
.sun
.star
.beans
.UnknownPropertyException
79 for ( int i
=0; i
<aProperties
.length
; i
++ )
80 if ( aProperties
[i
].Name
.equals( aName
) )
81 return aProperties
[i
];
82 throw new com
.sun
.star
.beans
.UnknownPropertyException();
85 public boolean hasPropertyByName( String aName
)
87 for ( int i
=0; i
<aProperties
.length
; i
++ )
88 if ( aProperties
[i
].Name
.equals( aName
) )
94 // implementation of com.sun.star.sheet.DataPilotSourceMember
96 class ExampleMember
implements com
.sun
.star
.container
.XNamed
,
97 com
.sun
.star
.beans
.XPropertySet
99 private final int nMember
;
101 public ExampleMember( int nMbr
)
108 public String
getName()
110 return ExampleSettings
.getMemberName( nMember
);
113 public void setName( String aName
)
120 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
122 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
123 new com
.sun
.star
.beans
.Property( "IsVisible", -1,
124 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0),
125 new com
.sun
.star
.beans
.Property( "ShowDetails", -1,
126 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0) });
129 public void setPropertyValue( String aPropertyName
, Object aValue
)
130 throws com
.sun
.star
.beans
.UnknownPropertyException
132 if ( aPropertyName
.equals( "IsVisible" ) ||
133 aPropertyName
.equals( "ShowDetails" ) )
138 throw new com
.sun
.star
.beans
.UnknownPropertyException();
141 public Object
getPropertyValue( String aPropertyName
)
142 throws com
.sun
.star
.beans
.UnknownPropertyException
144 if ( aPropertyName
.equals( "IsVisible" ) ||
145 aPropertyName
.equals( "ShowDetails" ) )
147 return Boolean
.TRUE
; // always true
150 throw new com
.sun
.star
.beans
.UnknownPropertyException();
153 public void addPropertyChangeListener(
154 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
157 public void removePropertyChangeListener(
158 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
161 public void addVetoableChangeListener(
162 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
165 public void removeVetoableChangeListener(
166 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
171 // implementation of com.sun.star.sheet.DataPilotSourceMembers
173 class ExampleMembers
implements com
.sun
.star
.sheet
.XMembersAccess
175 private final ExampleSettings aSettings
;
176 private ExampleMember
[] aMembers
;
178 public ExampleMembers( ExampleSettings aSet
)
181 aMembers
= new ExampleMember
[ aSettings
.nMemberCount
];
186 public com
.sun
.star
.uno
.Type
getElementType()
188 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
191 public boolean hasElements()
193 return true; // always has elements
196 public Object
getByName( String aName
)
197 throws com
.sun
.star
.container
.NoSuchElementException
199 int nCount
= aSettings
.nMemberCount
;
200 for ( int i
=0; i
<nCount
; i
++ )
201 if ( aName
.equals( ExampleSettings
.getMemberName( i
) ) )
203 if ( aMembers
[i
] == null )
204 aMembers
[i
] = new ExampleMember( i
);
207 throw new com
.sun
.star
.container
.NoSuchElementException();
210 public String
[] getElementNames()
212 int nCount
= aSettings
.nMemberCount
;
213 String
[] aNames
= new String
[ nCount
];
214 for ( int i
=0; i
<nCount
; i
++ )
215 aNames
[i
] = ExampleSettings
.getMemberName( i
);
219 public boolean hasByName( String aName
)
221 int nCount
= aSettings
.nMemberCount
;
222 for ( int i
=0; i
<nCount
; i
++ )
223 if ( aName
.equals( ExampleSettings
.getMemberName( i
) ) )
230 public String
[] getLocaleIndependentElementNames()
232 return getElementNames();
236 // implementation of com.sun.star.sheet.DataPilotSourceLevel
238 class ExampleLevel
implements
239 com
.sun
.star
.container
.XNamed
,
240 com
.sun
.star
.sheet
.XMembersSupplier
,
241 com
.sun
.star
.sheet
.XDataPilotMemberResults
,
242 com
.sun
.star
.beans
.XPropertySet
244 private final ExampleSettings aSettings
;
245 private final int nDimension
;
246 private ExampleMembers aMembers
;
248 public ExampleLevel( ExampleSettings aSet
, int nDim
)
256 public String
getName()
258 return ExampleSettings
.aDimensionNames
[ nDimension
];
261 public void setName( String aName
)
268 public com
.sun
.star
.sheet
.XMembersAccess
getMembers()
270 if ( aMembers
== null )
271 aMembers
= new ExampleMembers( aSettings
);
275 // XDataPilotMemberResults
277 public com
.sun
.star
.sheet
.MemberResult
[] getResults()
280 int nPosition
= aSettings
.aColDimensions
.indexOf( Integer
.valueOf(nDimension
));
281 if ( nPosition
>= 0 )
282 nDimensions
= aSettings
.aColDimensions
.size();
285 nPosition
= aSettings
.aRowDimensions
.indexOf( Integer
.valueOf(nDimension
));
286 if ( nPosition
>= 0 )
287 nDimensions
= aSettings
.aRowDimensions
.size();
291 return new com
.sun
.star
.sheet
.MemberResult
[0];
293 int nMembers
= aSettings
.nMemberCount
;
296 for ( int i
=0; i
<nDimensions
; i
++ )
300 else if ( i
> nPosition
)
303 int nSize
= nRepeat
* nMembers
* nFill
;
305 com
.sun
.star
.sheet
.MemberResult
[] aResults
=
306 new com
.sun
.star
.sheet
.MemberResult
[nSize
];
308 for (int nOuter
=0; nOuter
<nRepeat
; nOuter
++)
310 for (int nMember
=0; nMember
<nMembers
; nMember
++)
312 aResults
[nResultPos
] = new com
.sun
.star
.sheet
.MemberResult();
313 aResults
[nResultPos
].Name
= ExampleSettings
.getMemberName(nMember
);
314 aResults
[nResultPos
].Caption
= aResults
[nResultPos
].Name
;
315 aResults
[nResultPos
].Flags
=
316 com
.sun
.star
.sheet
.MemberResultFlags
.HASMEMBER
;
319 for (int nInner
=1; nInner
<nFill
; nInner
++)
321 aResults
[nResultPos
] = new com
.sun
.star
.sheet
.MemberResult();
322 aResults
[nResultPos
].Flags
=
323 com
.sun
.star
.sheet
.MemberResultFlags
.CONTINUE
;
333 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
335 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
336 new com
.sun
.star
.beans
.Property( "SubTotals", -1,
337 new com
.sun
.star
.uno
.Type(
338 com
.sun
.star
.sheet
.GeneralFunction
[].class ),
340 new com
.sun
.star
.beans
.Property( "ShowEmpty", -1,
341 new com
.sun
.star
.uno
.Type( Boolean
.class ),
345 public void setPropertyValue( String aPropertyName
, Object aValue
)
346 throws com
.sun
.star
.beans
.UnknownPropertyException
348 if ( aPropertyName
.equals( "SubTotals" ) ||
349 aPropertyName
.equals( "ShowEmpty" ) )
354 throw new com
.sun
.star
.beans
.UnknownPropertyException();
357 public Object
getPropertyValue( String aPropertyName
)
358 throws com
.sun
.star
.beans
.UnknownPropertyException
360 if ( aPropertyName
.equals( "SubTotals" ) )
361 return new com
.sun
.star
.sheet
.GeneralFunction
[0];
362 else if ( aPropertyName
.equals( "ShowEmpty" ) )
365 throw new com
.sun
.star
.beans
.UnknownPropertyException();
368 public void addPropertyChangeListener(
369 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
372 public void removePropertyChangeListener(
373 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
376 public void addVetoableChangeListener(
377 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
380 public void removeVetoableChangeListener(
381 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
386 // implementation of com.sun.star.sheet.DataPilotSourceLevels
388 class ExampleLevels
implements com
.sun
.star
.container
.XNameAccess
390 private final ExampleSettings aSettings
;
391 private final int nDimension
;
392 private ExampleLevel aLevel
;
394 public ExampleLevels( ExampleSettings aSet
, int nDim
)
402 public com
.sun
.star
.uno
.Type
getElementType()
404 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
407 public boolean hasElements()
409 return true; // always has elements
412 public Object
getByName( String aName
)
413 throws com
.sun
.star
.container
.NoSuchElementException
415 // there's only one level with the same name as the dimension / hierarchy
416 if ( aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] ) )
418 if ( aLevel
== null )
419 aLevel
= new ExampleLevel( aSettings
, nDimension
);
422 throw new com
.sun
.star
.container
.NoSuchElementException();
425 public String
[] getElementNames()
427 String
[] aNames
= new String
[ 1 ];
428 aNames
[0] = ExampleSettings
.aDimensionNames
[nDimension
];
432 public boolean hasByName( String aName
)
434 return aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] );
438 // implementation of com.sun.star.sheet.DataPilotSourceHierarchy
440 class ExampleHierarchy
implements com
.sun
.star
.container
.XNamed
,
441 com
.sun
.star
.sheet
.XLevelsSupplier
443 private final ExampleSettings aSettings
;
444 private final int nDimension
;
445 private ExampleLevels aLevels
;
447 public ExampleHierarchy( ExampleSettings aSet
, int nDim
)
455 public String
getName()
457 return ExampleSettings
.aDimensionNames
[ nDimension
];
460 public void setName( String aName
)
467 public com
.sun
.star
.container
.XNameAccess
getLevels()
469 if ( aLevels
== null )
470 aLevels
= new ExampleLevels( aSettings
, nDimension
);
475 // implementation of com.sun.star.sheet.DataPilotSourceHierarchies
477 class ExampleHierarchies
implements com
.sun
.star
.container
.XNameAccess
479 private final ExampleSettings aSettings
;
480 private final int nDimension
;
481 private ExampleHierarchy aHierarchy
;
483 public ExampleHierarchies( ExampleSettings aSet
, int nDim
)
491 public com
.sun
.star
.uno
.Type
getElementType()
493 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
496 public boolean hasElements()
498 return true; // always has elements
501 public Object
getByName( String aName
)
502 throws com
.sun
.star
.container
.NoSuchElementException
504 // there's only one hierarchy with the same name as the dimension
505 if ( aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] ) )
507 if ( aHierarchy
== null )
508 aHierarchy
= new ExampleHierarchy( aSettings
, nDimension
);
511 throw new com
.sun
.star
.container
.NoSuchElementException();
514 public String
[] getElementNames()
516 String
[] aNames
= new String
[ 1 ];
517 aNames
[0] = ExampleSettings
.aDimensionNames
[nDimension
];
521 public boolean hasByName( String aName
)
523 return aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] );
527 // implementation of com.sun.star.sheet.DataPilotSourceDimension
529 class ExampleDimension
implements
530 com
.sun
.star
.container
.XNamed
,
531 com
.sun
.star
.sheet
.XHierarchiesSupplier
,
532 com
.sun
.star
.util
.XCloneable
,
533 com
.sun
.star
.beans
.XPropertySet
535 private final ExampleSettings aSettings
;
536 private final int nDimension
;
537 private ExampleHierarchies aHierarchies
;
538 private com
.sun
.star
.sheet
.DataPilotFieldOrientation eOrientation
;
540 public ExampleDimension( ExampleSettings aSet
, int nDim
)
544 eOrientation
= ( nDim
== ExampleSettings
.nValueDimension
) ?
545 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
:
546 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.HIDDEN
;
551 public String
getName()
553 return ExampleSettings
.aDimensionNames
[ nDimension
];
556 public void setName( String aName
)
561 // XHierarchiesSupplier
563 public com
.sun
.star
.container
.XNameAccess
getHierarchies()
565 if ( aHierarchies
== null )
566 aHierarchies
= new ExampleHierarchies( aSettings
, nDimension
);
572 public com
.sun
.star
.util
.XCloneable
createClone()
574 return null; // not supported
579 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
581 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
582 new com
.sun
.star
.beans
.Property( "Original", -1,
583 new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class),
584 com
.sun
.star
.beans
.PropertyAttribute
.READONLY
),
585 new com
.sun
.star
.beans
.Property( "IsDataLayoutDimension", -1,
586 new com
.sun
.star
.uno
.Type( Boolean
.class),
587 com
.sun
.star
.beans
.PropertyAttribute
.READONLY
),
588 new com
.sun
.star
.beans
.Property( "Orientation", -1,
589 new com
.sun
.star
.uno
.Type(
590 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.class), (short) 0),
591 new com
.sun
.star
.beans
.Property( "Position", -1,
592 new com
.sun
.star
.uno
.Type( Integer
.class ), (short) 0),
593 new com
.sun
.star
.beans
.Property( "Function", -1,
594 new com
.sun
.star
.uno
.Type(com
.sun
.star
.sheet
.GeneralFunction
.class),
596 new com
.sun
.star
.beans
.Property( "UsedHierarchy", -1,
597 new com
.sun
.star
.uno
.Type( Integer
.class ), (short) 0 ),
598 new com
.sun
.star
.beans
.Property( "Filter", -1,
599 new com
.sun
.star
.uno
.Type(
600 com
.sun
.star
.sheet
.TableFilterField
[].class), (short) 0) });
603 public void setPropertyValue( String aPropertyName
, Object aValue
)
604 throws com
.sun
.star
.beans
.UnknownPropertyException
606 if ( aPropertyName
.equals( "Orientation" ) )
608 com
.sun
.star
.sheet
.DataPilotFieldOrientation eNewOrient
=
609 (com
.sun
.star
.sheet
.DataPilotFieldOrientation
) aValue
;
610 if ( nDimension
!= ExampleSettings
.nValueDimension
&&
611 nDimension
!= ExampleSettings
.nDataDimension
&&
612 eNewOrient
!= com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
)
614 // remove from list for old orientation and add for new one
615 Integer aDimInt
= Integer
.valueOf(nDimension
);
616 if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
617 aSettings
.aColDimensions
.remove( aDimInt
);
618 else if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
619 aSettings
.aRowDimensions
.remove( aDimInt
);
620 if ( eNewOrient
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
621 aSettings
.aColDimensions
.add( aDimInt
);
622 else if ( eNewOrient
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
623 aSettings
.aRowDimensions
.add( aDimInt
);
625 // change orientation
626 eOrientation
= eNewOrient
;
629 else if ( aPropertyName
.equals( "Position" ) )
631 int nNewPos
= ((Integer
) aValue
).intValue();
632 Integer aDimInt
= Integer
.valueOf(nDimension
);
633 if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
635 aSettings
.aColDimensions
.remove( aDimInt
);
636 aSettings
.aColDimensions
.add( nNewPos
, aDimInt
);
638 else if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
640 aSettings
.aRowDimensions
.remove( aDimInt
);
641 aSettings
.aRowDimensions
.add( nNewPos
, aDimInt
);
644 else if ( aPropertyName
.equals( "Function" ) || aPropertyName
.equals( "UsedHierarchy" ) ||
645 aPropertyName
.equals( "Filter" ) )
650 throw new com
.sun
.star
.beans
.UnknownPropertyException();
653 public Object
getPropertyValue( String aPropertyName
)
654 throws com
.sun
.star
.beans
.UnknownPropertyException
656 if ( aPropertyName
.equals( "Original" ) )
658 else if ( aPropertyName
.equals( "IsDataLayoutDimension" ) )
659 return Boolean
.valueOf( nDimension
== ExampleSettings
.nDataDimension
);
660 else if ( aPropertyName
.equals( "Orientation" ) )
662 else if ( aPropertyName
.equals( "Position" ) )
665 if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
666 nPosition
= aSettings
.aColDimensions
.indexOf( Integer
.valueOf(nDimension
) );
667 else if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
668 nPosition
= aSettings
.aRowDimensions
.indexOf( Integer
.valueOf(nDimension
) );
670 nPosition
= nDimension
;
671 return Integer
.valueOf( nPosition
);
673 else if ( aPropertyName
.equals( "Function" ) )
674 return com
.sun
.star
.sheet
.GeneralFunction
.SUM
;
675 else if ( aPropertyName
.equals( "UsedHierarchy" ) )
676 return Integer
.valueOf(0);
677 else if ( aPropertyName
.equals( "Filter" ) )
678 return new com
.sun
.star
.sheet
.TableFilterField
[0];
680 throw new com
.sun
.star
.beans
.UnknownPropertyException();
683 public void addPropertyChangeListener(
684 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
687 public void removePropertyChangeListener(
688 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
691 public void addVetoableChangeListener(
692 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
695 public void removeVetoableChangeListener(
696 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
701 // implementation of com.sun.star.sheet.DataPilotSourceDimensions
703 class ExampleDimensions
implements com
.sun
.star
.container
.XNameAccess
705 private final ExampleSettings aSettings
;
706 private ExampleDimension
[] aDimensions
;
708 public ExampleDimensions( ExampleSettings aSet
)
715 public com
.sun
.star
.uno
.Type
getElementType()
717 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
720 public boolean hasElements()
722 return true; // always has elements
725 public Object
getByName( String aName
)
726 throws com
.sun
.star
.container
.NoSuchElementException
728 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
729 if ( aName
.equals( ExampleSettings
.aDimensionNames
[i
] ) )
731 if ( aDimensions
== null )
732 aDimensions
= new ExampleDimension
[ ExampleSettings
.nDimensionCount
];
733 if ( aDimensions
[i
] == null )
734 aDimensions
[i
] = new ExampleDimension( aSettings
, i
);
735 return aDimensions
[i
];
737 throw new com
.sun
.star
.container
.NoSuchElementException();
740 public String
[] getElementNames()
742 String
[] aNames
= new String
[ ExampleSettings
.nDimensionCount
];
743 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
744 aNames
[ i
] = ExampleSettings
.aDimensionNames
[i
];
748 public boolean hasByName( String aName
)
750 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
751 if ( aName
.equals( ExampleSettings
.aDimensionNames
[i
] ) )
757 // outer class for service implementation
759 public class ExampleDataPilotSource
761 // implementation of com.sun.star.sheet.DataPilotSource
763 public static class _ExampleDataPilotSource
implements
764 com
.sun
.star
.sheet
.XDimensionsSupplier
,
765 com
.sun
.star
.sheet
.XDataPilotResults
,
766 com
.sun
.star
.util
.XRefreshable
,
767 com
.sun
.star
.beans
.XPropertySet
,
768 com
.sun
.star
.lang
.XInitialization
,
769 com
.sun
.star
.lang
.XServiceInfo
771 private static final String aServiceName
= "com.sun.star.sheet.DataPilotSource";
772 private static final String aImplName
= _ExampleDataPilotSource
.class.getName();
774 private final ExampleSettings aSettings
= new ExampleSettings();
775 private ExampleDimensions aDimensions
;
777 public _ExampleDataPilotSource( com
.sun
.star
.lang
.XMultiServiceFactory xFactory
)
783 public void initialize( Object
[] aArguments
)
785 // If the first argument (Source) is a number between 2 and 10,
786 // use it as member count, otherwise keep the default value.
789 if ( aArguments
.length
>= 1 )
791 String aSource
= com
.sun
.star
.uno
.AnyConverter
.toString(aArguments
[0]);
792 if ( aSource
!= null && aSource
.length() > 0)
794 int nValue
= Integer
.parseInt( aSource
);
795 if ( nValue
>= 2 && nValue
<= 10 )
796 aSettings
.nMemberCount
= nValue
;
800 catch ( NumberFormatException e
)
802 System
.out
.println( "Error: caught exception in " +
803 "ExampleDataPilotSource.initialize!\nException Message = "
807 catch ( com
.sun
.star
.lang
.IllegalArgumentException e
)
809 System
.out
.println( "Error: caught exception in " +
810 "ExampleDataPilotSource.initialize!\nException Message = "
818 public com
.sun
.star
.sheet
.DataResult
[][] getResults()
820 int[] nDigits
= new int[ExampleSettings
.nDimensionCount
];
822 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
828 int nMemberCount
= aSettings
.nMemberCount
;
829 int nRowDimCount
= aSettings
.aRowDimensions
.size();
830 int nColDimCount
= aSettings
.aColDimensions
.size();
833 for (int i
=0; i
<nRowDimCount
; i
++)
834 nRows
*= nMemberCount
;
836 for (int i
=0; i
<nColDimCount
; i
++)
837 nColumns
*= nMemberCount
;
839 com
.sun
.star
.sheet
.DataResult
[][] aResults
= new com
.sun
.star
.sheet
.DataResult
[nRows
][];
840 for (int nRow
=0; nRow
<nRows
; nRow
++)
844 for (int nRowDim
=0; nRowDim
<nRowDimCount
; nRowDim
++)
846 int nDim
= aSettings
.aRowDimensions
.get(nRowDimCount
-nRowDim
-1).intValue();
847 nRowResult
+= ( nRowVal
% nMemberCount
) * nDigits
[nDim
];
848 nRowVal
/= nMemberCount
;
851 aResults
[nRow
] = new com
.sun
.star
.sheet
.DataResult
[nColumns
];
852 for (int nCol
=0; nCol
<nColumns
; nCol
++)
855 int nResult
= nRowResult
;
856 for (int nColDim
=0; nColDim
<nColDimCount
; nColDim
++)
858 int nDim
= aSettings
.aColDimensions
.get(nColDimCount
-nColDim
-1).intValue();
859 nResult
+= ( nColVal
% nMemberCount
) * nDigits
[nDim
];
860 nColVal
/= nMemberCount
;
863 aResults
[nRow
][nCol
] = new com
.sun
.star
.sheet
.DataResult();
864 aResults
[nRow
][nCol
].Flags
= com
.sun
.star
.sheet
.DataResultFlags
.HASDATA
;
865 aResults
[nRow
][nCol
].Value
= nResult
;
871 public double[] getFilteredResults(DataPilotFieldFilter
[] aFilters
) {
873 return new double[0];
876 // XDimensionsSupplier
878 public com
.sun
.star
.container
.XNameAccess
getDimensions()
880 if ( aDimensions
== null )
881 aDimensions
= new ExampleDimensions( aSettings
);
887 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
889 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
890 new com
.sun
.star
.beans
.Property( "ColumnGrand", -1,
891 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0),
892 new com
.sun
.star
.beans
.Property( "RowGrand", -1,
893 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0) });
896 public void setPropertyValue( String aPropertyName
, Object aValue
)
897 throws com
.sun
.star
.beans
.UnknownPropertyException
899 if ( aPropertyName
.equals( "ColumnGrand" ) ||
900 aPropertyName
.equals( "RowGrand" ) )
905 throw new com
.sun
.star
.beans
.UnknownPropertyException();
908 public Object
getPropertyValue( String aPropertyName
)
909 throws com
.sun
.star
.beans
.UnknownPropertyException
911 if ( aPropertyName
.equals( "ColumnGrand" ) ||
912 aPropertyName
.equals( "RowGrand" ) )
914 return Boolean
.FALSE
; // always false
917 throw new com
.sun
.star
.beans
.UnknownPropertyException();
920 public void addPropertyChangeListener(
921 String aPropertyName
,
922 com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
925 public void removePropertyChangeListener(
926 String aPropertyName
,
927 com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
930 public void addVetoableChangeListener(
932 com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
935 public void removeVetoableChangeListener(
937 com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
943 public void refresh()
946 public void addRefreshListener( com
.sun
.star
.util
.XRefreshListener l
)
949 public void removeRefreshListener( com
.sun
.star
.util
.XRefreshListener l
)
955 public String
getImplementationName()
960 public String
[] getSupportedServiceNames()
962 String
[] aSupportedServices
= new String
[ 1 ];
963 aSupportedServices
[ 0 ] = aServiceName
;
964 return aSupportedServices
;
967 public boolean supportsService( String aService
)
969 return aService
.equals( aServiceName
);
973 public static com
.sun
.star
.lang
.XSingleServiceFactory
__getServiceFactory(
975 com
.sun
.star
.lang
.XMultiServiceFactory multiFactory
,
976 com
.sun
.star
.registry
.XRegistryKey regKey
)
978 com
.sun
.star
.lang
.XSingleServiceFactory xSingleServiceFactory
= null;
980 if ( implName
.equals(_ExampleDataPilotSource
.aImplName
) )
981 xSingleServiceFactory
=
982 com
.sun
.star
.comp
.loader
.FactoryHelper
.getServiceFactory(
983 _ExampleDataPilotSource
.class,
984 _ExampleDataPilotSource
.aServiceName
, multiFactory
, regKey
);
986 return xSingleServiceFactory
;
990 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */