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 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 ExampleSettings aSettings
;
99 private int nDimension
;
102 public ExampleMember( ExampleSettings aSet
, int nDim
, int nMbr
)
111 public String
getName()
113 return ExampleSettings
.getMemberName( nMember
);
116 public void setName( String aName
)
123 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
125 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
126 new com
.sun
.star
.beans
.Property( "IsVisible", -1,
127 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0),
128 new com
.sun
.star
.beans
.Property( "ShowDetails", -1,
129 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0) });
132 public void setPropertyValue( String aPropertyName
, Object aValue
)
133 throws com
.sun
.star
.beans
.UnknownPropertyException
135 if ( aPropertyName
.equals( "IsVisible" ) ||
136 aPropertyName
.equals( "ShowDetails" ) )
141 throw new com
.sun
.star
.beans
.UnknownPropertyException();
144 public Object
getPropertyValue( String aPropertyName
)
145 throws com
.sun
.star
.beans
.UnknownPropertyException
147 if ( aPropertyName
.equals( "IsVisible" ) ||
148 aPropertyName
.equals( "ShowDetails" ) )
150 return new Boolean( true ); // always true
153 throw new com
.sun
.star
.beans
.UnknownPropertyException();
156 public void addPropertyChangeListener(
157 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
160 public void removePropertyChangeListener(
161 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
164 public void addVetoableChangeListener(
165 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
168 public void removeVetoableChangeListener(
169 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
174 // implementation of com.sun.star.sheet.DataPilotSourceMembers
176 class ExampleMembers
implements com
.sun
.star
.container
.XNameAccess
178 private ExampleSettings aSettings
;
179 private int nDimension
;
180 private ExampleMember
[] aMembers
;
182 public ExampleMembers( ExampleSettings aSet
, int nDim
)
186 aMembers
= new ExampleMember
[ aSettings
.nMemberCount
];
191 public com
.sun
.star
.uno
.Type
getElementType()
193 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
196 public boolean hasElements()
198 return true; // always has elements
201 public Object
getByName( String aName
)
202 throws com
.sun
.star
.container
.NoSuchElementException
204 int nCount
= aSettings
.nMemberCount
;
205 for ( int i
=0; i
<nCount
; i
++ )
206 if ( aName
.equals( ExampleSettings
.getMemberName( i
) ) )
208 if ( aMembers
[i
] == null )
209 aMembers
[i
] = new ExampleMember( aSettings
, nDimension
, i
);
212 throw new com
.sun
.star
.container
.NoSuchElementException();
215 public String
[] getElementNames()
217 int nCount
= aSettings
.nMemberCount
;
218 String
[] aNames
= new String
[ nCount
];
219 for ( int i
=0; i
<nCount
; i
++ )
220 aNames
[i
] = ExampleSettings
.getMemberName( i
);
224 public boolean hasByName( String aName
)
226 int nCount
= aSettings
.nMemberCount
;
227 for ( int i
=0; i
<nCount
; i
++ )
228 if ( aName
.equals( ExampleSettings
.getMemberName( i
) ) )
234 // implementation of com.sun.star.sheet.DataPilotSourceLevel
236 class ExampleLevel
implements
237 com
.sun
.star
.container
.XNamed
,
238 com
.sun
.star
.sheet
.XMembersSupplier
,
239 com
.sun
.star
.sheet
.XDataPilotMemberResults
,
240 com
.sun
.star
.beans
.XPropertySet
242 private ExampleSettings aSettings
;
243 private int nDimension
;
244 private ExampleMembers aMembers
;
246 public ExampleLevel( ExampleSettings aSet
, int nDim
)
254 public String
getName()
256 return ExampleSettings
.aDimensionNames
[ nDimension
];
259 public void setName( String aName
)
266 public com
.sun
.star
.container
.XNameAccess
getMembers()
268 if ( aMembers
== null )
269 aMembers
= new ExampleMembers( aSettings
, nDimension
);
273 // XDataPilotMemberResults
275 public com
.sun
.star
.sheet
.MemberResult
[] getResults()
278 int nPosition
= aSettings
.aColDimensions
.indexOf( new Integer(nDimension
));
279 if ( nPosition
>= 0 )
280 nDimensions
= aSettings
.aColDimensions
.size();
283 nPosition
= aSettings
.aRowDimensions
.indexOf( new Integer(nDimension
));
284 if ( nPosition
>= 0 )
285 nDimensions
= aSettings
.aRowDimensions
.size();
289 return new com
.sun
.star
.sheet
.MemberResult
[0];
291 int nMembers
= aSettings
.nMemberCount
;
294 for ( int i
=0; i
<nDimensions
; i
++ )
298 else if ( i
> nPosition
)
301 int nSize
= nRepeat
* nMembers
* nFill
;
303 com
.sun
.star
.sheet
.MemberResult
[] aResults
=
304 new com
.sun
.star
.sheet
.MemberResult
[nSize
];
306 for (int nOuter
=0; nOuter
<nRepeat
; nOuter
++)
308 for (int nMember
=0; nMember
<nMembers
; nMember
++)
310 aResults
[nResultPos
] = new com
.sun
.star
.sheet
.MemberResult();
311 aResults
[nResultPos
].Name
= ExampleSettings
.getMemberName(nMember
);
312 aResults
[nResultPos
].Caption
= aResults
[nResultPos
].Name
;
313 aResults
[nResultPos
].Flags
=
314 com
.sun
.star
.sheet
.MemberResultFlags
.HASMEMBER
;
317 for (int nInner
=1; nInner
<nFill
; nInner
++)
319 aResults
[nResultPos
] = new com
.sun
.star
.sheet
.MemberResult();
320 aResults
[nResultPos
].Flags
=
321 com
.sun
.star
.sheet
.MemberResultFlags
.CONTINUE
;
331 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
333 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
334 new com
.sun
.star
.beans
.Property( "SubTotals", -1,
335 new com
.sun
.star
.uno
.Type(
336 com
.sun
.star
.sheet
.GeneralFunction
[].class ),
338 new com
.sun
.star
.beans
.Property( "ShowEmpty", -1,
339 new com
.sun
.star
.uno
.Type( Boolean
.class ),
343 public void setPropertyValue( String aPropertyName
, Object aValue
)
344 throws com
.sun
.star
.beans
.UnknownPropertyException
346 if ( aPropertyName
.equals( "SubTotals" ) ||
347 aPropertyName
.equals( "ShowEmpty" ) )
352 throw new com
.sun
.star
.beans
.UnknownPropertyException();
355 public Object
getPropertyValue( String aPropertyName
)
356 throws com
.sun
.star
.beans
.UnknownPropertyException
358 if ( aPropertyName
.equals( "SubTotals" ) )
359 return new com
.sun
.star
.sheet
.GeneralFunction
[0];
360 else if ( aPropertyName
.equals( "ShowEmpty" ) )
361 return new Boolean( true );
363 throw new com
.sun
.star
.beans
.UnknownPropertyException();
366 public void addPropertyChangeListener(
367 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
370 public void removePropertyChangeListener(
371 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
374 public void addVetoableChangeListener(
375 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
378 public void removeVetoableChangeListener(
379 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
384 // implementation of com.sun.star.sheet.DataPilotSourceLevels
386 class ExampleLevels
implements com
.sun
.star
.container
.XNameAccess
388 private ExampleSettings aSettings
;
389 private int nDimension
;
390 private ExampleLevel aLevel
;
392 public ExampleLevels( ExampleSettings aSet
, int nDim
)
400 public com
.sun
.star
.uno
.Type
getElementType()
402 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
405 public boolean hasElements()
407 return true; // always has elements
410 public Object
getByName( String aName
)
411 throws com
.sun
.star
.container
.NoSuchElementException
413 // there's only one level with the same name as the dimension / hierarchy
414 if ( aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] ) )
416 if ( aLevel
== null )
417 aLevel
= new ExampleLevel( aSettings
, nDimension
);
420 throw new com
.sun
.star
.container
.NoSuchElementException();
423 public String
[] getElementNames()
425 String
[] aNames
= new String
[ 1 ];
426 aNames
[0] = ExampleSettings
.aDimensionNames
[nDimension
];
430 public boolean hasByName( String aName
)
432 return aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] );
436 // implementation of com.sun.star.sheet.DataPilotSourceHierarchy
438 class ExampleHierarchy
implements com
.sun
.star
.container
.XNamed
,
439 com
.sun
.star
.sheet
.XLevelsSupplier
441 private ExampleSettings aSettings
;
442 private int nDimension
;
443 private ExampleLevels aLevels
;
445 public ExampleHierarchy( ExampleSettings aSet
, int nDim
)
453 public String
getName()
455 return ExampleSettings
.aDimensionNames
[ nDimension
];
458 public void setName( String aName
)
465 public com
.sun
.star
.container
.XNameAccess
getLevels()
467 if ( aLevels
== null )
468 aLevels
= new ExampleLevels( aSettings
, nDimension
);
473 // implementation of com.sun.star.sheet.DataPilotSourceHierarchies
475 class ExampleHierarchies
implements com
.sun
.star
.container
.XNameAccess
477 private ExampleSettings aSettings
;
478 private int nDimension
;
479 private ExampleHierarchy aHierarchy
;
481 public ExampleHierarchies( ExampleSettings aSet
, int nDim
)
489 public com
.sun
.star
.uno
.Type
getElementType()
491 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
494 public boolean hasElements()
496 return true; // always has elements
499 public Object
getByName( String aName
)
500 throws com
.sun
.star
.container
.NoSuchElementException
502 // there's only one hierarchy with the same name as the dimension
503 if ( aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] ) )
505 if ( aHierarchy
== null )
506 aHierarchy
= new ExampleHierarchy( aSettings
, nDimension
);
509 throw new com
.sun
.star
.container
.NoSuchElementException();
512 public String
[] getElementNames()
514 String
[] aNames
= new String
[ 1 ];
515 aNames
[0] = ExampleSettings
.aDimensionNames
[nDimension
];
519 public boolean hasByName( String aName
)
521 return aName
.equals( ExampleSettings
.aDimensionNames
[nDimension
] );
525 // implementation of com.sun.star.sheet.DataPilotSourceDimension
527 class ExampleDimension
implements
528 com
.sun
.star
.container
.XNamed
,
529 com
.sun
.star
.sheet
.XHierarchiesSupplier
,
530 com
.sun
.star
.util
.XCloneable
,
531 com
.sun
.star
.beans
.XPropertySet
533 private ExampleSettings aSettings
;
534 private int nDimension
;
535 private ExampleHierarchies aHierarchies
;
536 private com
.sun
.star
.sheet
.DataPilotFieldOrientation eOrientation
;
538 public ExampleDimension( ExampleSettings aSet
, int nDim
)
542 eOrientation
= ( nDim
== ExampleSettings
.nValueDimension
) ?
543 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
:
544 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.HIDDEN
;
549 public String
getName()
551 return ExampleSettings
.aDimensionNames
[ nDimension
];
554 public void setName( String aName
)
559 // XHierarchiesSupplier
561 public com
.sun
.star
.container
.XNameAccess
getHierarchies()
563 if ( aHierarchies
== null )
564 aHierarchies
= new ExampleHierarchies( aSettings
, nDimension
);
570 public com
.sun
.star
.util
.XCloneable
createClone()
572 return null; // not supported
577 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
579 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
580 new com
.sun
.star
.beans
.Property( "Original", -1,
581 new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class),
582 com
.sun
.star
.beans
.PropertyAttribute
.READONLY
),
583 new com
.sun
.star
.beans
.Property( "IsDataLayoutDimension", -1,
584 new com
.sun
.star
.uno
.Type( Boolean
.class),
585 com
.sun
.star
.beans
.PropertyAttribute
.READONLY
),
586 new com
.sun
.star
.beans
.Property( "Orientation", -1,
587 new com
.sun
.star
.uno
.Type(
588 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.class), (short) 0),
589 new com
.sun
.star
.beans
.Property( "Position", -1,
590 new com
.sun
.star
.uno
.Type( Integer
.class ), (short) 0),
591 new com
.sun
.star
.beans
.Property( "Function", -1,
592 new com
.sun
.star
.uno
.Type(com
.sun
.star
.sheet
.GeneralFunction
.class),
594 new com
.sun
.star
.beans
.Property( "UsedHierarchy", -1,
595 new com
.sun
.star
.uno
.Type( Integer
.class ), (short) 0 ),
596 new com
.sun
.star
.beans
.Property( "Filter", -1,
597 new com
.sun
.star
.uno
.Type(
598 com
.sun
.star
.sheet
.TableFilterField
[].class), (short) 0) });
601 public void setPropertyValue( String aPropertyName
, Object aValue
)
602 throws com
.sun
.star
.beans
.UnknownPropertyException
604 if ( aPropertyName
.equals( "Orientation" ) )
606 com
.sun
.star
.sheet
.DataPilotFieldOrientation eNewOrient
=
607 (com
.sun
.star
.sheet
.DataPilotFieldOrientation
) aValue
;
608 if ( nDimension
!= ExampleSettings
.nValueDimension
&&
609 nDimension
!= ExampleSettings
.nDataDimension
&&
610 eNewOrient
!= com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
)
612 // remove from list for old orientation and add for new one
613 Integer aDimInt
= new Integer(nDimension
);
614 if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
615 aSettings
.aColDimensions
.remove( aDimInt
);
616 else if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
617 aSettings
.aRowDimensions
.remove( aDimInt
);
618 if ( eNewOrient
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
619 aSettings
.aColDimensions
.add( aDimInt
);
620 else if ( eNewOrient
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
621 aSettings
.aRowDimensions
.add( aDimInt
);
623 // change orientation
624 eOrientation
= eNewOrient
;
627 else if ( aPropertyName
.equals( "Position" ) )
629 int nNewPos
= ((Integer
) aValue
).intValue();
630 Integer aDimInt
= new Integer(nDimension
);
631 if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
633 aSettings
.aColDimensions
.remove( aDimInt
);
634 aSettings
.aColDimensions
.add( nNewPos
, aDimInt
);
636 else if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
638 aSettings
.aRowDimensions
.remove( aDimInt
);
639 aSettings
.aRowDimensions
.add( nNewPos
, aDimInt
);
642 else if ( aPropertyName
.equals( "Function" ) || aPropertyName
.equals( "UsedHierarchy" ) ||
643 aPropertyName
.equals( "Filter" ) )
648 throw new com
.sun
.star
.beans
.UnknownPropertyException();
651 public Object
getPropertyValue( String aPropertyName
)
652 throws com
.sun
.star
.beans
.UnknownPropertyException
654 if ( aPropertyName
.equals( "Original" ) )
656 else if ( aPropertyName
.equals( "IsDataLayoutDimension" ) )
657 return new Boolean( nDimension
== ExampleSettings
.nDataDimension
);
658 else if ( aPropertyName
.equals( "Orientation" ) )
660 else if ( aPropertyName
.equals( "Position" ) )
663 if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
)
664 nPosition
= aSettings
.aColDimensions
.indexOf( new Integer(nDimension
) );
665 else if ( eOrientation
== com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
)
666 nPosition
= aSettings
.aRowDimensions
.indexOf( new Integer(nDimension
) );
668 nPosition
= nDimension
;
669 return new Integer( nPosition
);
671 else if ( aPropertyName
.equals( "Function" ) )
672 return com
.sun
.star
.sheet
.GeneralFunction
.SUM
;
673 else if ( aPropertyName
.equals( "UsedHierarchy" ) )
674 return new Integer(0);
675 else if ( aPropertyName
.equals( "Filter" ) )
676 return new com
.sun
.star
.sheet
.TableFilterField
[0];
678 throw new com
.sun
.star
.beans
.UnknownPropertyException();
681 public void addPropertyChangeListener(
682 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
685 public void removePropertyChangeListener(
686 String aPropertyName
, com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
689 public void addVetoableChangeListener(
690 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
693 public void removeVetoableChangeListener(
694 String PropertyName
, com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
699 // implementation of com.sun.star.sheet.DataPilotSourceDimensions
701 class ExampleDimensions
implements com
.sun
.star
.container
.XNameAccess
703 private ExampleSettings aSettings
;
704 private ExampleDimension
[] aDimensions
;
706 public ExampleDimensions( ExampleSettings aSet
)
713 public com
.sun
.star
.uno
.Type
getElementType()
715 return new com
.sun
.star
.uno
.Type( com
.sun
.star
.container
.XNamed
.class );
718 public boolean hasElements()
720 return true; // always has elements
723 public Object
getByName( String aName
)
724 throws com
.sun
.star
.container
.NoSuchElementException
726 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
727 if ( aName
.equals( ExampleSettings
.aDimensionNames
[i
] ) )
729 if ( aDimensions
== null )
730 aDimensions
= new ExampleDimension
[ ExampleSettings
.nDimensionCount
];
731 if ( aDimensions
[i
] == null )
732 aDimensions
[i
] = new ExampleDimension( aSettings
, i
);
733 return aDimensions
[i
];
735 throw new com
.sun
.star
.container
.NoSuchElementException();
738 public String
[] getElementNames()
740 String
[] aNames
= new String
[ ExampleSettings
.nDimensionCount
];
741 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
742 aNames
[ i
] = ExampleSettings
.aDimensionNames
[i
];
746 public boolean hasByName( String aName
)
748 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
749 if ( aName
.equals( ExampleSettings
.aDimensionNames
[i
] ) )
755 // outer class for service implementation
757 public class ExampleDataPilotSource
759 // implementation of com.sun.star.sheet.DataPilotSource
761 static public class _ExampleDataPilotSource
implements
762 com
.sun
.star
.sheet
.XDimensionsSupplier
,
763 com
.sun
.star
.sheet
.XDataPilotResults
,
764 com
.sun
.star
.util
.XRefreshable
,
765 com
.sun
.star
.beans
.XPropertySet
,
766 com
.sun
.star
.lang
.XInitialization
,
767 com
.sun
.star
.lang
.XServiceInfo
769 static private final String aServiceName
= "com.sun.star.sheet.DataPilotSource";
770 static private final String aImplName
= _ExampleDataPilotSource
.class.getName();
772 private ExampleSettings aSettings
= new ExampleSettings();
773 private ExampleDimensions aDimensions
;
775 public _ExampleDataPilotSource( com
.sun
.star
.lang
.XMultiServiceFactory xFactory
)
781 public void initialize( Object
[] aArguments
)
783 // If the first argument (Source) is a number between 2 and 10,
784 // use it as member count, otherwise keep the default value.
787 if ( aArguments
.length
>= 1 )
789 String aSource
= com
.sun
.star
.uno
.AnyConverter
.toString(aArguments
[0]);
790 if ( aSource
!= null && aSource
.length() > 0)
792 int nValue
= Integer
.parseInt( aSource
);
793 if ( nValue
>= 2 && nValue
<= 10 )
794 aSettings
.nMemberCount
= nValue
;
798 catch ( NumberFormatException e
)
800 System
.out
.println( "Error: caught exception in " +
801 "ExampleDataPilotSource.initialize!\nException Message = "
805 catch ( com
.sun
.star
.lang
.IllegalArgumentException e
)
807 System
.out
.println( "Error: caught exception in " +
808 "ExampleDataPilotSource.initialize!\nException Message = "
816 public com
.sun
.star
.sheet
.DataResult
[][] getResults()
818 int[] nDigits
= new int[ExampleSettings
.nDimensionCount
];
820 for (int i
=0; i
<ExampleSettings
.nDimensionCount
; i
++)
826 int nMemberCount
= aSettings
.nMemberCount
;
827 int nRowDimCount
= aSettings
.aRowDimensions
.size();
828 int nColDimCount
= aSettings
.aColDimensions
.size();
831 for (int i
=0; i
<nRowDimCount
; i
++)
832 nRows
*= nMemberCount
;
834 for (int i
=0; i
<nColDimCount
; i
++)
835 nColumns
*= nMemberCount
;
837 com
.sun
.star
.sheet
.DataResult
[][] aResults
= new com
.sun
.star
.sheet
.DataResult
[nRows
][];
838 for (int nRow
=0; nRow
<nRows
; nRow
++)
842 for (int nRowDim
=0; nRowDim
<nRowDimCount
; nRowDim
++)
844 int nDim
= aSettings
.aRowDimensions
.get(nRowDimCount
-nRowDim
-1).intValue();
845 nRowResult
+= ( nRowVal
% nMemberCount
) * nDigits
[nDim
];
846 nRowVal
/= nMemberCount
;
849 aResults
[nRow
] = new com
.sun
.star
.sheet
.DataResult
[nColumns
];
850 for (int nCol
=0; nCol
<nColumns
; nCol
++)
853 int nResult
= nRowResult
;
854 for (int nColDim
=0; nColDim
<nColDimCount
; nColDim
++)
856 int nDim
= aSettings
.aColDimensions
.get(nColDimCount
-nColDim
-1).intValue();
857 nResult
+= ( nColVal
% nMemberCount
) * nDigits
[nDim
];
858 nColVal
/= nMemberCount
;
861 aResults
[nRow
][nCol
] = new com
.sun
.star
.sheet
.DataResult();
862 aResults
[nRow
][nCol
].Flags
= com
.sun
.star
.sheet
.DataResultFlags
.HASDATA
;
863 aResults
[nRow
][nCol
].Value
= nResult
;
869 public double[] getFilteredResults(DataPilotFieldFilter
[] aFilters
) {
871 return new double[0];
874 // XDimensionsSupplier
876 public com
.sun
.star
.container
.XNameAccess
getDimensions()
878 if ( aDimensions
== null )
879 aDimensions
= new ExampleDimensions( aSettings
);
885 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo()
887 return new ExamplePropertySetInfo( new com
.sun
.star
.beans
.Property
[] {
888 new com
.sun
.star
.beans
.Property( "ColumnGrand", -1,
889 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0),
890 new com
.sun
.star
.beans
.Property( "RowGrand", -1,
891 new com
.sun
.star
.uno
.Type( Boolean
.class ), (short) 0) });
894 public void setPropertyValue( String aPropertyName
, Object aValue
)
895 throws com
.sun
.star
.beans
.UnknownPropertyException
897 if ( aPropertyName
.equals( "ColumnGrand" ) ||
898 aPropertyName
.equals( "RowGrand" ) )
903 throw new com
.sun
.star
.beans
.UnknownPropertyException();
906 public Object
getPropertyValue( String aPropertyName
)
907 throws com
.sun
.star
.beans
.UnknownPropertyException
909 if ( aPropertyName
.equals( "ColumnGrand" ) ||
910 aPropertyName
.equals( "RowGrand" ) )
912 return new Boolean( false ); // always false
915 throw new com
.sun
.star
.beans
.UnknownPropertyException();
918 public void addPropertyChangeListener(
919 String aPropertyName
,
920 com
.sun
.star
.beans
.XPropertyChangeListener xListener
)
923 public void removePropertyChangeListener(
924 String aPropertyName
,
925 com
.sun
.star
.beans
.XPropertyChangeListener aListener
)
928 public void addVetoableChangeListener(
930 com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
933 public void removeVetoableChangeListener(
935 com
.sun
.star
.beans
.XVetoableChangeListener aListener
)
941 public void refresh()
944 public void addRefreshListener( com
.sun
.star
.util
.XRefreshListener l
)
947 public void removeRefreshListener( com
.sun
.star
.util
.XRefreshListener l
)
953 public String
getImplementationName()
958 public String
[] getSupportedServiceNames()
960 String
[] aSupportedServices
= new String
[ 1 ];
961 aSupportedServices
[ 0 ] = aServiceName
;
962 return aSupportedServices
;
965 public boolean supportsService( String aService
)
967 return aService
.equals( aServiceName
);
971 public static com
.sun
.star
.lang
.XSingleServiceFactory
__getServiceFactory(
973 com
.sun
.star
.lang
.XMultiServiceFactory multiFactory
,
974 com
.sun
.star
.registry
.XRegistryKey regKey
)
976 com
.sun
.star
.lang
.XSingleServiceFactory xSingleServiceFactory
= null;
978 if ( implName
.equals(_ExampleDataPilotSource
.aImplName
) )
979 xSingleServiceFactory
=
980 com
.sun
.star
.comp
.loader
.FactoryHelper
.getServiceFactory(
981 _ExampleDataPilotSource
.class,
982 _ExampleDataPilotSource
.aServiceName
, multiFactory
, regKey
);
984 return xSingleServiceFactory
;
987 // This method not longer necessary since OOo 3.4 where the component registration
988 // was changed to passive component registration. For more details see
989 // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
991 // public static boolean __writeRegistryServiceInfo(
992 // com.sun.star.registry.XRegistryKey regKey)
994 // return com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo(
995 // _ExampleDataPilotSource.aImplName,
996 // _ExampleDataPilotSource.aServiceName, regKey);