1 import com
.sun
.star
.sheet
.DataPilotFieldFilter
;
3 /*************************************************************************
5 * The Contents of this file are made available subject to the terms of
8 * Copyright 2000, 2010 Oracle and/or its affiliates.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
30 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
33 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *************************************************************************/
37 // Example DataPilot source component
39 // helper class to hold the settings
43 static public final int nDimensionCount
= 6;
44 static public final int nValueDimension
= 4;
45 static public final int nDataDimension
= 5;
46 static public final String
[] aDimensionNames
= {
47 "ones", "tens", "hundreds", "thousands", "value", "" };
49 static public final String
getMemberName( int nMember
)
51 return String
.valueOf( nMember
);
54 public int nMemberCount
= 3;
55 public java
.util
.List
<Integer
> aColDimensions
= new java
.util
.ArrayList
<Integer
>();
56 public java
.util
.List
<Integer
> aRowDimensions
= new java
.util
.ArrayList
<Integer
>();
59 // XPropertySetInfo implementation for getPropertySetInfo
61 class ExamplePropertySetInfo
implements com
.sun
.star
.beans
.XPropertySetInfo
63 private final com
.sun
.star
.beans
.Property
[] aProperties
;
65 public ExamplePropertySetInfo( com
.sun
.star
.beans
.Property
[] aProps
)
70 public com
.sun
.star
.beans
.Property
[] getProperties()
75 public com
.sun
.star
.beans
.Property
getPropertyByName( String aName
)
76 throws com
.sun
.star
.beans
.UnknownPropertyException
78 for ( int i
=0; i
<aProperties
.length
; i
++ )
79 if ( aProperties
[i
].Name
.equals( aName
) )
80 return aProperties
[i
];
81 throw new com
.sun
.star
.beans
.UnknownPropertyException();
84 public boolean hasPropertyByName( String aName
)
86 for ( int i
=0; i
<aProperties
.length
; i
++ )
87 if ( aProperties
[i
].Name
.equals( aName
) )
93 // implementation of com.sun.star.sheet.DataPilotSourceMember
95 class ExampleMember
implements com
.sun
.star
.container
.XNamed
,
96 com
.sun
.star
.beans
.XPropertySet
98 private final int nMember
;
100 public ExampleMember( int nMbr
)
107 public String
getName()
109 return ExampleSettings
.getMemberName( nMember
);
112 public void setName( String aName
)
119 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
121 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
122 new com
.sun
.star
.beans
.Property( "IsVisible", -1,
123 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0),
124 new com
.sun
.star
.beans
.Property( "ShowDetails", -1,
125 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0) });
128 public void setPropertyValue( String aPropertyName
, Object aValue
)
129 throws com
.sun
.star
.beans
.UnknownPropertyException
131 if ( aPropertyName
.equals( "IsVisible" ) ||
132 aPropertyName
.equals( "ShowDetails" ) )
137 throw new com
.sun
.star
.beans
.UnknownPropertyException();
140 public Object
getPropertyValue( String aPropertyName
)
141 throws com
.sun
.star
.beans
.UnknownPropertyException
143 if ( aPropertyName
.equals( "IsVisible" ) ||
144 aPropertyName
.equals( "ShowDetails" ) )
146 return Boolean
.TRUE
; // always true
149 throw new com
.sun
.star
.beans
.UnknownPropertyException();
152 public void addPropertyChangeListener(
153 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
156 public void removePropertyChangeListener(
157 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
160 public void addVetoableChangeListener(
161 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
164 public void removeVetoableChangeListener(
165 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
170 // implementation of com.sun.star.sheet.DataPilotSourceMembers
172 class ExampleMembers
implements com
.sun
.star
.container
.XNameAccess
174 private final ExampleSettings aSettings
;
175 private ExampleMember
[] aMembers
;
177 public ExampleMembers( ExampleSettings aSet
)
180 aMembers
= new ExampleMember
[ aSettings
.nMemberCount
];
185 public com
.sun
.star
.uno
.Type
getElementType()
187 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
190 public boolean hasElements()
192 return true; // always has elements
195 public Object
getByName( String aName
)
196 throws com
.sun
.star
.container
.NoSuchElementException
198 int nCount
= aSettings
.nMemberCount
;
199 for ( int i
=0; i
<nCount
; i
++ )
200 if ( aName
.equals( ExampleSettings
.getMemberName( i
) ) )
202 if ( aMembers
[i
] == null )
203 aMembers
[i
] = new ExampleMember( i
);
206 throw new com
.sun
.star
.container
.NoSuchElementException();
209 public String
[] getElementNames()
211 int nCount
= aSettings
.nMemberCount
;
212 String
[] aNames
= new String
[ nCount
];
213 for ( int i
=0; i
<nCount
; i
++ )
214 aNames
[i
] = ExampleSettings
.getMemberName( i
);
218 public boolean hasByName( String aName
)
220 int nCount
= aSettings
.nMemberCount
;
221 for ( int i
=0; i
<nCount
; i
++ )
222 if ( aName
.equals( ExampleSettings
.getMemberName( i
) ) )
228 // implementation of com.sun.star.sheet.DataPilotSourceLevel
230 class ExampleLevel
implements
231 com
.sun
.star
.container
.XNamed
,
232 com
.sun
.star
.sheet
.XMembersSupplier
,
233 com
.sun
.star
.sheet
.XDataPilotMemberResults
,
234 com
.sun
.star
.beans
.XPropertySet
236 private final ExampleSettings aSettings
;
237 private final int nDimension
;
238 private ExampleMembers aMembers
;
240 public ExampleLevel( ExampleSettings aSet
, int nDim
)
248 public String
getName()
250 return ExampleSettings
.aDimensionNames
[ nDimension
];
253 public void setName( String aName
)
260 public com
.sun
.star
.container
.XNameAccess
getMembers()
262 if ( aMembers
== null )
263 aMembers
= new ExampleMembers( aSettings
);
267 // XDataPilotMemberResults
269 public com
.sun
.star
.sheet
.MemberResult
[] getResults()
272 int nPosition
= aSettings
.aColDimensions
.indexOf( Integer
.valueOf(nDimension
));
273 if ( nPosition
>= 0 )
274 nDimensions
= aSettings
.aColDimensions
.size();
277 nPosition
= aSettings
.aRowDimensions
.indexOf( Integer
.valueOf(nDimension
));
278 if ( nPosition
>= 0 )
279 nDimensions
= aSettings
.aRowDimensions
.size();
283 return new com
.sun
.star
.sheet
.MemberResult
[0];
285 int nMembers
= aSettings
.nMemberCount
;
288 for ( int i
=0; i
<nDimensions
; i
++ )
292 else if ( i
> nPosition
)
295 int nSize
= nRepeat
* nMembers
* nFill
;
297 com
.sun
.star
.sheet
.MemberResult
[] aResults
=
298 new com
.sun
.star
.sheet
.MemberResult
[nSize
];
300 for (int nOuter
=0; nOuter
<nRepeat
; nOuter
++)
302 for (int nMember
=0; nMember
<nMembers
; nMember
++)
304 aResults
[nResultPos
] = new com
.sun
.star
.sheet
.MemberResult();
305 aResults
[nResultPos
].Name
= ExampleSettings
.getMemberName(nMember
);
306 aResults
[nResultPos
].Caption
= aResults
[nResultPos
].Name
;
307 aResults
[nResultPos
].Flags
=
308 com
.sun
.star
.sheet
.MemberResultFlags
.HASMEMBER
;
311 for (int nInner
=1; nInner
<nFill
; nInner
++)
313 aResults
[nResultPos
] = new com
.sun
.star
.sheet
.MemberResult();
314 aResults
[nResultPos
].Flags
=
315 com
.sun
.star
.sheet
.MemberResultFlags
.CONTINUE
;
325 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
327 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
328 new com
.sun
.star
.beans
.Property( "SubTotals", -1,
329 new com
.sun
.star
.uno
.Type(
330 com
.sun
.star
.sheet
.GeneralFunction
[].class ),
332 new com
.sun
.star
.beans
.Property( "ShowEmpty", -1,
333 new com
.sun
.star
.uno
.Type( Boolean
.class ),
337 public void setPropertyValue( String aPropertyName
, Object aValue
)
338 throws com
.sun
.star
.beans
.UnknownPropertyException
340 if ( aPropertyName
.equals( "SubTotals" ) ||
341 aPropertyName
.equals( "ShowEmpty" ) )
346 throw new com
.sun
.star
.beans
.UnknownPropertyException();
349 public Object
getPropertyValue( String aPropertyName
)
350 throws com
.sun
.star
.beans
.UnknownPropertyException
352 if ( aPropertyName
.equals( "SubTotals" ) )
353 return new com
.sun
.star
.sheet
.GeneralFunction
[0];
354 else if ( aPropertyName
.equals( "ShowEmpty" ) )
357 throw new com
.sun
.star
.beans
.UnknownPropertyException();
360 public void addPropertyChangeListener(
361 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
364 public void removePropertyChangeListener(
365 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
368 public void addVetoableChangeListener(
369 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
372 public void removeVetoableChangeListener(
373 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
378 // implementation of com.sun.star.sheet.DataPilotSourceLevels
380 class ExampleLevels
implements com
.sun
.star
.container
.XNameAccess
382 private final ExampleSettings aSettings
;
383 private final int nDimension
;
384 private ExampleLevel aLevel
;
386 public ExampleLevels( ExampleSettings aSet
, int nDim
)
394 public com
.sun
.star
.uno
.Type
getElementType()
396 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
399 public boolean hasElements()
401 return true; // always has elements
404 public Object
getByName( String aName
)
405 throws com
.sun
.star
.container
.NoSuchElementException
407 // there's only one level with the same name as the dimension / hierarchy
408 if ( aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] ) )
410 if ( aLevel
== null )
411 aLevel
= new ExampleLevel( aSettings
, nDimension
);
414 throw new com
.sun
.star
.container
.NoSuchElementException();
417 public String
[] getElementNames()
419 String
[] aNames
= new String
[ 1 ];
420 aNames
[0] = ExampleSettings
.aDimensionNames
[nDimension
];
424 public boolean hasByName( String aName
)
426 return aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] );
430 // implementation of com.sun.star.sheet.DataPilotSourceHierarchy
432 class ExampleHierarchy
implements com
.sun
.star
.container
.XNamed
,
433 com
.sun
.star
.sheet
.XLevelsSupplier
435 private final ExampleSettings aSettings
;
436 private final int nDimension
;
437 private ExampleLevels aLevels
;
439 public ExampleHierarchy( ExampleSettings aSet
, int nDim
)
447 public String
getName()
449 return ExampleSettings
.aDimensionNames
[ nDimension
];
452 public void setName( String aName
)
459 public com
.sun
.star
.container
.XNameAccess
getLevels()
461 if ( aLevels
== null )
462 aLevels
= new ExampleLevels( aSettings
, nDimension
);
467 // implementation of com.sun.star.sheet.DataPilotSourceHierarchies
469 class ExampleHierarchies
implements com
.sun
.star
.container
.XNameAccess
471 private final ExampleSettings aSettings
;
472 private final int nDimension
;
473 private ExampleHierarchy aHierarchy
;
475 public ExampleHierarchies( ExampleSettings aSet
, int nDim
)
483 public com
.sun
.star
.uno
.Type
getElementType()
485 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
488 public boolean hasElements()
490 return true; // always has elements
493 public Object
getByName( String aName
)
494 throws com
.sun
.star
.container
.NoSuchElementException
496 // there's only one hierarchy with the same name as the dimension
497 if ( aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] ) )
499 if ( aHierarchy
== null )
500 aHierarchy
= new ExampleHierarchy( aSettings
, nDimension
);
503 throw new com
.sun
.star
.container
.NoSuchElementException();
506 public String
[] getElementNames()
508 String
[] aNames
= new String
[ 1 ];
509 aNames
[0] = ExampleSettings
.aDimensionNames
[nDimension
];
513 public boolean hasByName( String aName
)
515 return aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] );
519 // implementation of com.sun.star.sheet.DataPilotSourceDimension
521 class ExampleDimension
implements
522 com
.sun
.star
.container
.XNamed
,
523 com
.sun
.star
.sheet
.XHierarchiesSupplier
,
524 com
.sun
.star
.util
.XCloneable
,
525 com
.sun
.star
.beans
.XPropertySet
527 private final ExampleSettings aSettings
;
528 private final int nDimension
;
529 private ExampleHierarchies aHierarchies
;
530 private com
.sun
.star
.sheet
.DataPilotFieldOrientation eOrientation
;
532 public ExampleDimension( ExampleSettings aSet
, int nDim
)
536 eOrientation
= ( nDim
== ExampleSettings
.nValueDimension
) ?
537 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
:
538 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.HIDDEN
;
543 public String
getName()
545 return ExampleSettings
.aDimensionNames
[ nDimension
];
548 public void setName( String aName
)
553 // XHierarchiesSupplier
555 public com
.sun
.star
.container
.XNameAccess
getHierarchies()
557 if ( aHierarchies
== null )
558 aHierarchies
= new ExampleHierarchies( aSettings
, nDimension
);
564 public com
.sun
.star
.util
.XCloneable
createClone()
566 return null; // not supported
571 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
573 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
574 new com
.sun
.star
.beans
.Property( "Original", -1,
575 new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class),
576 com
.sun
.star
.beans
.PropertyAttribute
.READONLY
),
577 new com
.sun
.star
.beans
.Property( "IsDataLayoutDimension", -1,
578 new com
.sun
.star
.uno
.Type( Boolean
.class),
579 com
.sun
.star
.beans
.PropertyAttribute
.READONLY
),
580 new com
.sun
.star
.beans
.Property( "Orientation", -1,
581 new com
.sun
.star
.uno
.Type(
582 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.class), (short) 0),
583 new com
.sun
.star
.beans
.Property( "Position", -1,
584 new com
.sun
.star
.uno
.Type( Integer
.class ), (short) 0),
585 new com
.sun
.star
.beans
.Property( "Function", -1,
586 new com
.sun
.star
.uno
.Type(com
.sun
.star
.sheet
.GeneralFunction
.class),
588 new com
.sun
.star
.beans
.Property( "UsedHierarchy", -1,
589 new com
.sun
.star
.uno
.Type( Integer
.class ), (short) 0 ),
590 new com
.sun
.star
.beans
.Property( "Filter", -1,
591 new com
.sun
.star
.uno
.Type(
592 com
.sun
.star
.sheet
.TableFilterField
[].class), (short) 0) });
595 public void setPropertyValue( String aPropertyName
, Object aValue
)
596 throws com
.sun
.star
.beans
.UnknownPropertyException
598 if ( aPropertyName
.equals( "Orientation" ) )
600 com
.sun
.star
.sheet
.DataPilotFieldOrientation eNewOrient
=
601 (com
.sun
.star
.sheet
.DataPilotFieldOrientation
) aValue
;
602 if ( nDimension
!= ExampleSettings
.nValueDimension
&&
603 nDimension
!= ExampleSettings
.nDataDimension
&&
604 eNewOrient
!= com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
)
606 // remove from list for old orientation and add for new one
607 Integer aDimInt
= Integer
.valueOf(nDimension
);
608 if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
609 aSettings
.aColDimensions
.remove( aDimInt
);
610 else if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
611 aSettings
.aRowDimensions
.remove( aDimInt
);
612 if ( eNewOrient
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
613 aSettings
.aColDimensions
.add( aDimInt
);
614 else if ( eNewOrient
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
615 aSettings
.aRowDimensions
.add( aDimInt
);
617 // change orientation
618 eOrientation
= eNewOrient
;
621 else if ( aPropertyName
.equals( "Position" ) )
623 int nNewPos
= ((Integer
) aValue
).intValue();
624 Integer aDimInt
= Integer
.valueOf(nDimension
);
625 if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
627 aSettings
.aColDimensions
.remove( aDimInt
);
628 aSettings
.aColDimensions
.add( nNewPos
, aDimInt
);
630 else if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
632 aSettings
.aRowDimensions
.remove( aDimInt
);
633 aSettings
.aRowDimensions
.add( nNewPos
, aDimInt
);
636 else if ( aPropertyName
.equals( "Function" ) || aPropertyName
.equals( "UsedHierarchy" ) ||
637 aPropertyName
.equals( "Filter" ) )
642 throw new com
.sun
.star
.beans
.UnknownPropertyException();
645 public Object
getPropertyValue( String aPropertyName
)
646 throws com
.sun
.star
.beans
.UnknownPropertyException
648 if ( aPropertyName
.equals( "Original" ) )
650 else if ( aPropertyName
.equals( "IsDataLayoutDimension" ) )
651 return Boolean
.valueOf( nDimension
== ExampleSettings
.nDataDimension
);
652 else if ( aPropertyName
.equals( "Orientation" ) )
654 else if ( aPropertyName
.equals( "Position" ) )
657 if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
658 nPosition
= aSettings
.aColDimensions
.indexOf( Integer
.valueOf(nDimension
) );
659 else if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
660 nPosition
= aSettings
.aRowDimensions
.indexOf( Integer
.valueOf(nDimension
) );
662 nPosition
= nDimension
;
663 return Integer
.valueOf( nPosition
);
665 else if ( aPropertyName
.equals( "Function" ) )
666 return com
.sun
.star
.sheet
.GeneralFunction
.SUM
;
667 else if ( aPropertyName
.equals( "UsedHierarchy" ) )
668 return Integer
.valueOf(0);
669 else if ( aPropertyName
.equals( "Filter" ) )
670 return new com
.sun
.star
.sheet
.TableFilterField
[0];
672 throw new com
.sun
.star
.beans
.UnknownPropertyException();
675 public void addPropertyChangeListener(
676 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
679 public void removePropertyChangeListener(
680 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
683 public void addVetoableChangeListener(
684 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
687 public void removeVetoableChangeListener(
688 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
693 // implementation of com.sun.star.sheet.DataPilotSourceDimensions
695 class ExampleDimensions
implements com
.sun
.star
.container
.XNameAccess
697 private final ExampleSettings aSettings
;
698 private ExampleDimension
[] aDimensions
;
700 public ExampleDimensions( ExampleSettings aSet
)
707 public com
.sun
.star
.uno
.Type
getElementType()
709 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
712 public boolean hasElements()
714 return true; // always has elements
717 public Object
getByName( String aName
)
718 throws com
.sun
.star
.container
.NoSuchElementException
720 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
721 if ( aName
.equals( ExampleSettings
.aDimensionNames
[i
] ) )
723 if ( aDimensions
== null )
724 aDimensions
= new ExampleDimension
[ ExampleSettings
.nDimensionCount
];
725 if ( aDimensions
[i
] == null )
726 aDimensions
[i
] = new ExampleDimension( aSettings
, i
);
727 return aDimensions
[i
];
729 throw new com
.sun
.star
.container
.NoSuchElementException();
732 public String
[] getElementNames()
734 String
[] aNames
= new String
[ ExampleSettings
.nDimensionCount
];
735 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
736 aNames
[ i
] = ExampleSettings
.aDimensionNames
[i
];
740 public boolean hasByName( String aName
)
742 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
743 if ( aName
.equals( ExampleSettings
.aDimensionNames
[i
] ) )
749 // outer class for service implementation
751 public class ExampleDataPilotSource
753 // implementation of com.sun.star.sheet.DataPilotSource
755 static public class _ExampleDataPilotSource
implements
756 com
.sun
.star
.sheet
.XDimensionsSupplier
,
757 com
.sun
.star
.sheet
.XDataPilotResults
,
758 com
.sun
.star
.util
.XRefreshable
,
759 com
.sun
.star
.beans
.XPropertySet
,
760 com
.sun
.star
.lang
.XInitialization
,
761 com
.sun
.star
.lang
.XServiceInfo
763 static private final String aServiceName
= "com.sun.star.sheet.DataPilotSource";
764 static private final String aImplName
= _ExampleDataPilotSource
.class.getName();
766 private final ExampleSettings aSettings
= new ExampleSettings();
767 private ExampleDimensions aDimensions
;
769 public _ExampleDataPilotSource( com
.sun
.star
.lang
.XMultiServiceFactory xFactory
)
775 public void initialize( Object
[] aArguments
)
777 // If the first argument (Source) is a number between 2 and 10,
778 // use it as member count, otherwise keep the default value.
781 if ( aArguments
.length
>= 1 )
783 String aSource
= com
.sun
.star
.uno
.AnyConverter
.toString(aArguments
[0]);
784 if ( aSource
!= null && aSource
.length() > 0)
786 int nValue
= Integer
.parseInt( aSource
);
787 if ( nValue
>= 2 && nValue
<= 10 )
788 aSettings
.nMemberCount
= nValue
;
792 catch ( NumberFormatException e
)
794 System
.out
.println( "Error: caught exception in " +
795 "ExampleDataPilotSource.initialize!\nException Message = "
799 catch ( com
.sun
.star
.lang
.IllegalArgumentException e
)
801 System
.out
.println( "Error: caught exception in " +
802 "ExampleDataPilotSource.initialize!\nException Message = "
810 public com
.sun
.star
.sheet
.DataResult
[][] getResults()
812 int[] nDigits
= new int[ExampleSettings
.nDimensionCount
];
814 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
820 int nMemberCount
= aSettings
.nMemberCount
;
821 int nRowDimCount
= aSettings
.aRowDimensions
.size();
822 int nColDimCount
= aSettings
.aColDimensions
.size();
825 for (int i
=0; i
<nRowDimCount
; i
++)
826 nRows
*= nMemberCount
;
828 for (int i
=0; i
<nColDimCount
; i
++)
829 nColumns
*= nMemberCount
;
831 com
.sun
.star
.sheet
.DataResult
[][] aResults
= new com
.sun
.star
.sheet
.DataResult
[nRows
][];
832 for (int nRow
=0; nRow
<nRows
; nRow
++)
836 for (int nRowDim
=0; nRowDim
<nRowDimCount
; nRowDim
++)
838 int nDim
= aSettings
.aRowDimensions
.get(nRowDimCount
-nRowDim
-1).intValue();
839 nRowResult
+= ( nRowVal
% nMemberCount
) * nDigits
[nDim
];
840 nRowVal
/= nMemberCount
;
843 aResults
[nRow
] = new com
.sun
.star
.sheet
.DataResult
[nColumns
];
844 for (int nCol
=0; nCol
<nColumns
; nCol
++)
847 int nResult
= nRowResult
;
848 for (int nColDim
=0; nColDim
<nColDimCount
; nColDim
++)
850 int nDim
= aSettings
.aColDimensions
.get(nColDimCount
-nColDim
-1).intValue();
851 nResult
+= ( nColVal
% nMemberCount
) * nDigits
[nDim
];
852 nColVal
/= nMemberCount
;
855 aResults
[nRow
][nCol
] = new com
.sun
.star
.sheet
.DataResult();
856 aResults
[nRow
][nCol
].Flags
= com
.sun
.star
.sheet
.DataResultFlags
.HASDATA
;
857 aResults
[nRow
][nCol
].Value
= nResult
;
863 public double[] getFilteredResults(DataPilotFieldFilter
[] aFilters
) {
865 return new double[0];
868 // XDimensionsSupplier
870 public com
.sun
.star
.container
.XNameAccess
getDimensions()
872 if ( aDimensions
== null )
873 aDimensions
= new ExampleDimensions( aSettings
);
879 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
881 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
882 new com
.sun
.star
.beans
.Property( "ColumnGrand", -1,
883 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0),
884 new com
.sun
.star
.beans
.Property( "RowGrand", -1,
885 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0) });
888 public void setPropertyValue( String aPropertyName
, Object aValue
)
889 throws com
.sun
.star
.beans
.UnknownPropertyException
891 if ( aPropertyName
.equals( "ColumnGrand" ) ||
892 aPropertyName
.equals( "RowGrand" ) )
897 throw new com
.sun
.star
.beans
.UnknownPropertyException();
900 public Object
getPropertyValue( String aPropertyName
)
901 throws com
.sun
.star
.beans
.UnknownPropertyException
903 if ( aPropertyName
.equals( "ColumnGrand" ) ||
904 aPropertyName
.equals( "RowGrand" ) )
906 return Boolean
.FALSE
; // always false
909 throw new com
.sun
.star
.beans
.UnknownPropertyException();
912 public void addPropertyChangeListener(
913 String aPropertyName
,
914 com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
917 public void removePropertyChangeListener(
918 String aPropertyName
,
919 com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
922 public void addVetoableChangeListener(
924 com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
927 public void removeVetoableChangeListener(
929 com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
935 public void refresh()
938 public void addRefreshListener( com
.sun
.star
.util
.XRefreshListener l
)
941 public void removeRefreshListener( com
.sun
.star
.util
.XRefreshListener l
)
947 public String
getImplementationName()
952 public String
[] getSupportedServiceNames()
954 String
[] aSupportedServices
= new String
[ 1 ];
955 aSupportedServices
[ 0 ] = aServiceName
;
956 return aSupportedServices
;
959 public boolean supportsService( String aService
)
961 return aService
.equals( aServiceName
);
965 public static com
.sun
.star
.lang
.XSingleServiceFactory
__getServiceFactory(
967 com
.sun
.star
.lang
.XMultiServiceFactory multiFactory
,
968 com
.sun
.star
.registry
.XRegistryKey regKey
)
970 com
.sun
.star
.lang
.XSingleServiceFactory xSingleServiceFactory
= null;
972 if ( implName
.equals(_ExampleDataPilotSource
.aImplName
) )
973 xSingleServiceFactory
=
974 com
.sun
.star
.comp
.loader
.FactoryHelper
.getServiceFactory(
975 _ExampleDataPilotSource
.class,
976 _ExampleDataPilotSource
.aServiceName
, multiFactory
, regKey
);
978 return xSingleServiceFactory
;