1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  The Contents of this file are made available subject to the terms of
4*cdf0e10cSrcweir  *  the BSD license.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *  All rights reserved.
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  Redistribution and use in source and binary forms, with or without
10*cdf0e10cSrcweir  *  modification, are permitted provided that the following conditions
11*cdf0e10cSrcweir  *  are met:
12*cdf0e10cSrcweir  *  1. Redistributions of source code must retain the above copyright
13*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer.
14*cdf0e10cSrcweir  *  2. Redistributions in binary form must reproduce the above copyright
15*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer in the
16*cdf0e10cSrcweir  *     documentation and/or other materials provided with the distribution.
17*cdf0e10cSrcweir  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18*cdf0e10cSrcweir  *     contributors may be used to endorse or promote products derived
19*cdf0e10cSrcweir  *     from this software without specific prior written permission.
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*cdf0e10cSrcweir  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*cdf0e10cSrcweir  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*cdf0e10cSrcweir  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25*cdf0e10cSrcweir  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*cdf0e10cSrcweir  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*cdf0e10cSrcweir  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28*cdf0e10cSrcweir  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*cdf0e10cSrcweir  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30*cdf0e10cSrcweir  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31*cdf0e10cSrcweir  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*cdf0e10cSrcweir  *
33*cdf0e10cSrcweir  *************************************************************************/
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir //  Example DataPilot source component
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir //  helper class to hold the settings
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir class ExampleSettings
40*cdf0e10cSrcweir {
41*cdf0e10cSrcweir     static public final int nDimensionCount = 6;
42*cdf0e10cSrcweir     static public final int nValueDimension = 4;
43*cdf0e10cSrcweir     static public final int nDataDimension = 5;
44*cdf0e10cSrcweir     static public final String [] aDimensionNames = {
45*cdf0e10cSrcweir         "ones", "tens", "hundreds", "thousands", "value", "" };
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir     static public final String getMemberName( int nMember )
48*cdf0e10cSrcweir     {
49*cdf0e10cSrcweir         return String.valueOf( nMember );
50*cdf0e10cSrcweir     }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir     public int nMemberCount = 3;
53*cdf0e10cSrcweir     public java.util.List aColDimensions = new java.util.ArrayList();
54*cdf0e10cSrcweir     public java.util.List aRowDimensions = new java.util.ArrayList();
55*cdf0e10cSrcweir }
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir //  XPropertySetInfo implementation for getPropertySetInfo
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir class ExamplePropertySetInfo implements com.sun.star.beans.XPropertySetInfo
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     private com.sun.star.beans.Property[] aProperties;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     public ExamplePropertySetInfo( com.sun.star.beans.Property[] aProps )
64*cdf0e10cSrcweir     {
65*cdf0e10cSrcweir         aProperties = aProps;
66*cdf0e10cSrcweir     }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     public com.sun.star.beans.Property[] getProperties()
69*cdf0e10cSrcweir     {
70*cdf0e10cSrcweir         return aProperties;
71*cdf0e10cSrcweir     }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     public com.sun.star.beans.Property getPropertyByName( String aName )
74*cdf0e10cSrcweir                     throws com.sun.star.beans.UnknownPropertyException
75*cdf0e10cSrcweir     {
76*cdf0e10cSrcweir         for ( int i=0; i<aProperties.length; i++ )
77*cdf0e10cSrcweir             if ( aProperties[i].Name.equals( aName ) )
78*cdf0e10cSrcweir                 return aProperties[i];
79*cdf0e10cSrcweir         throw new com.sun.star.beans.UnknownPropertyException();
80*cdf0e10cSrcweir     }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     public boolean hasPropertyByName( String aName )
83*cdf0e10cSrcweir     {
84*cdf0e10cSrcweir         for ( int i=0; i<aProperties.length; i++ )
85*cdf0e10cSrcweir             if ( aProperties[i].Name.equals( aName ) )
86*cdf0e10cSrcweir                 return true;
87*cdf0e10cSrcweir         return false;
88*cdf0e10cSrcweir     }
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir //  implementation of com.sun.star.sheet.DataPilotSourceMember
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir class ExampleMember implements com.sun.star.container.XNamed,
94*cdf0e10cSrcweir       com.sun.star.beans.XPropertySet
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir     private ExampleSettings aSettings;
97*cdf0e10cSrcweir     private int nDimension;
98*cdf0e10cSrcweir     private int nMember;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     public ExampleMember( ExampleSettings aSet, int nDim, int nMbr )
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         aSettings = aSet;
103*cdf0e10cSrcweir         nDimension = nDim;
104*cdf0e10cSrcweir         nMember = nMbr;
105*cdf0e10cSrcweir     }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     //  XNamed
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     public String getName()
110*cdf0e10cSrcweir     {
111*cdf0e10cSrcweir         return ExampleSettings.getMemberName( nMember );
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     public void setName( String aName )
115*cdf0e10cSrcweir     {
116*cdf0e10cSrcweir         // ignored
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     //  XPropertySet
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     public com.sun.star.beans.XPropertySetInfo getPropertySetInfo()
122*cdf0e10cSrcweir     {
123*cdf0e10cSrcweir         return new ExamplePropertySetInfo( new com.sun.star.beans.Property[] {
124*cdf0e10cSrcweir             new com.sun.star.beans.Property( "IsVisible",   -1,
125*cdf0e10cSrcweir                         new com.sun.star.uno.Type( Boolean.class ), (short) 0),
126*cdf0e10cSrcweir             new com.sun.star.beans.Property( "ShowDetails", -1,
127*cdf0e10cSrcweir                         new com.sun.star.uno.Type( Boolean.class ), (short) 0) });
128*cdf0e10cSrcweir     }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     public void setPropertyValue( String aPropertyName, Object aValue )
131*cdf0e10cSrcweir         throws com.sun.star.beans.UnknownPropertyException
132*cdf0e10cSrcweir     {
133*cdf0e10cSrcweir         if ( aPropertyName.equals( "IsVisible" ) ||
134*cdf0e10cSrcweir              aPropertyName.equals( "ShowDetails" ) )
135*cdf0e10cSrcweir         {
136*cdf0e10cSrcweir             // ignored
137*cdf0e10cSrcweir         }
138*cdf0e10cSrcweir         else
139*cdf0e10cSrcweir             throw new com.sun.star.beans.UnknownPropertyException();
140*cdf0e10cSrcweir     }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir     public Object getPropertyValue( String aPropertyName )
143*cdf0e10cSrcweir         throws com.sun.star.beans.UnknownPropertyException
144*cdf0e10cSrcweir     {
145*cdf0e10cSrcweir         if ( aPropertyName.equals( "IsVisible" ) ||
146*cdf0e10cSrcweir              aPropertyName.equals( "ShowDetails" ) )
147*cdf0e10cSrcweir         {
148*cdf0e10cSrcweir             return new Boolean( true );     // always true
149*cdf0e10cSrcweir         }
150*cdf0e10cSrcweir         else
151*cdf0e10cSrcweir             throw new com.sun.star.beans.UnknownPropertyException();
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     public void addPropertyChangeListener(
155*cdf0e10cSrcweir         String aPropertyName, com.sun.star.beans.XPropertyChangeListener xListener)
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir     }
158*cdf0e10cSrcweir     public void removePropertyChangeListener(
159*cdf0e10cSrcweir         String aPropertyName, com.sun.star.beans.XPropertyChangeListener aListener)
160*cdf0e10cSrcweir     {
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir     public void addVetoableChangeListener(
163*cdf0e10cSrcweir         String PropertyName, com.sun.star.beans.XVetoableChangeListener aListener)
164*cdf0e10cSrcweir     {
165*cdf0e10cSrcweir     }
166*cdf0e10cSrcweir     public void removeVetoableChangeListener(
167*cdf0e10cSrcweir         String PropertyName, com.sun.star.beans.XVetoableChangeListener aListener)
168*cdf0e10cSrcweir     {
169*cdf0e10cSrcweir     }
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir //  implementation of com.sun.star.sheet.DataPilotSourceMembers
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir class ExampleMembers implements com.sun.star.container.XNameAccess
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir     private ExampleSettings aSettings;
177*cdf0e10cSrcweir     private int nDimension;
178*cdf0e10cSrcweir     private ExampleMember[] aMembers;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     public ExampleMembers( ExampleSettings aSet, int nDim )
181*cdf0e10cSrcweir     {
182*cdf0e10cSrcweir         aSettings = aSet;
183*cdf0e10cSrcweir         nDimension = nDim;
184*cdf0e10cSrcweir         aMembers = new ExampleMember[ aSettings.nMemberCount ];
185*cdf0e10cSrcweir     }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     //  XNameAccess
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     public com.sun.star.uno.Type getElementType()
190*cdf0e10cSrcweir     {
191*cdf0e10cSrcweir         return new com.sun.star.uno.Type( com.sun.star.container.XNamed.class );
192*cdf0e10cSrcweir     }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     public boolean hasElements()
195*cdf0e10cSrcweir     {
196*cdf0e10cSrcweir         return true;    // always has elements
197*cdf0e10cSrcweir     }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     public Object getByName( String aName )
200*cdf0e10cSrcweir         throws com.sun.star.container.NoSuchElementException
201*cdf0e10cSrcweir     {
202*cdf0e10cSrcweir         int nCount = aSettings.nMemberCount;
203*cdf0e10cSrcweir         for ( int i=0; i<nCount; i++ )
204*cdf0e10cSrcweir             if ( aName.equals( ExampleSettings.getMemberName( i ) ) )
205*cdf0e10cSrcweir             {
206*cdf0e10cSrcweir                 if ( aMembers[i] == null )
207*cdf0e10cSrcweir                     aMembers[i] = new ExampleMember( aSettings, nDimension, i );
208*cdf0e10cSrcweir                 return aMembers[i];
209*cdf0e10cSrcweir             }
210*cdf0e10cSrcweir         throw new com.sun.star.container.NoSuchElementException();
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     public String[] getElementNames()
214*cdf0e10cSrcweir     {
215*cdf0e10cSrcweir         int nCount = aSettings.nMemberCount;
216*cdf0e10cSrcweir         String [] aNames = new String[ nCount ];
217*cdf0e10cSrcweir         for ( int i=0; i<nCount; i++ )
218*cdf0e10cSrcweir             aNames[i] = ExampleSettings.getMemberName( i );
219*cdf0e10cSrcweir         return aNames;
220*cdf0e10cSrcweir     }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir     public boolean hasByName( String aName )
223*cdf0e10cSrcweir     {
224*cdf0e10cSrcweir         int nCount = aSettings.nMemberCount;
225*cdf0e10cSrcweir         for ( int i=0; i<nCount; i++ )
226*cdf0e10cSrcweir             if ( aName.equals( ExampleSettings.getMemberName( i ) ) )
227*cdf0e10cSrcweir                 return true;
228*cdf0e10cSrcweir         return false;
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir //  implementation of com.sun.star.sheet.DataPilotSourceLevel
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir class ExampleLevel implements
235*cdf0e10cSrcweir                     com.sun.star.container.XNamed,
236*cdf0e10cSrcweir                     com.sun.star.sheet.XMembersSupplier,
237*cdf0e10cSrcweir                     com.sun.star.sheet.XDataPilotMemberResults,
238*cdf0e10cSrcweir                     com.sun.star.beans.XPropertySet
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir     private ExampleSettings aSettings;
241*cdf0e10cSrcweir     private int nDimension;
242*cdf0e10cSrcweir     private ExampleMembers aMembers;
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir     public ExampleLevel( ExampleSettings aSet, int nDim )
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir         aSettings = aSet;
247*cdf0e10cSrcweir         nDimension = nDim;
248*cdf0e10cSrcweir     }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     // XNamed
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir     public String getName()
253*cdf0e10cSrcweir     {
254*cdf0e10cSrcweir         return ExampleSettings.aDimensionNames[ nDimension ];
255*cdf0e10cSrcweir     }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir     public void setName( String aName )
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir         // ignored
260*cdf0e10cSrcweir     }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     // XMembersSupplier
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     public com.sun.star.container.XNameAccess getMembers()
265*cdf0e10cSrcweir     {
266*cdf0e10cSrcweir         if ( aMembers == null )
267*cdf0e10cSrcweir             aMembers = new ExampleMembers( aSettings, nDimension );
268*cdf0e10cSrcweir         return aMembers;
269*cdf0e10cSrcweir     }
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir     // XDataPilotMemberResults
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     public com.sun.star.sheet.MemberResult[] getResults()
274*cdf0e10cSrcweir     {
275*cdf0e10cSrcweir         int nDimensions = 0;
276*cdf0e10cSrcweir         int nPosition = aSettings.aColDimensions.indexOf( new Integer(nDimension));
277*cdf0e10cSrcweir         if ( nPosition >= 0 )
278*cdf0e10cSrcweir             nDimensions = aSettings.aColDimensions.size();
279*cdf0e10cSrcweir         else
280*cdf0e10cSrcweir         {
281*cdf0e10cSrcweir             nPosition = aSettings.aRowDimensions.indexOf( new Integer(nDimension));
282*cdf0e10cSrcweir             if ( nPosition >= 0 )
283*cdf0e10cSrcweir                 nDimensions = aSettings.aRowDimensions.size();
284*cdf0e10cSrcweir         }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         if ( nPosition < 0 )
287*cdf0e10cSrcweir             return new com.sun.star.sheet.MemberResult[0];
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir         int nMembers = aSettings.nMemberCount;
290*cdf0e10cSrcweir         int nRepeat = 1;
291*cdf0e10cSrcweir         int nFill = 1;
292*cdf0e10cSrcweir         for ( int i=0; i<nDimensions; i++ )
293*cdf0e10cSrcweir         {
294*cdf0e10cSrcweir             if ( i < nPosition )
295*cdf0e10cSrcweir                 nRepeat *= nMembers;
296*cdf0e10cSrcweir             else if ( i > nPosition )
297*cdf0e10cSrcweir                 nFill *= nMembers;
298*cdf0e10cSrcweir         }
299*cdf0e10cSrcweir         int nSize = nRepeat * nMembers * nFill;
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir         com.sun.star.sheet.MemberResult[] aResults =
302*cdf0e10cSrcweir             new com.sun.star.sheet.MemberResult[nSize];
303*cdf0e10cSrcweir         int nResultPos = 0;
304*cdf0e10cSrcweir         for (int nOuter=0; nOuter<nRepeat; nOuter++)
305*cdf0e10cSrcweir         {
306*cdf0e10cSrcweir             for (int nMember=0; nMember<nMembers; nMember++)
307*cdf0e10cSrcweir             {
308*cdf0e10cSrcweir                 aResults[nResultPos] = new com.sun.star.sheet.MemberResult();
309*cdf0e10cSrcweir                 aResults[nResultPos].Name = ExampleSettings.getMemberName(nMember);
310*cdf0e10cSrcweir                 aResults[nResultPos].Caption = aResults[nResultPos].Name;
311*cdf0e10cSrcweir                 aResults[nResultPos].Flags =
312*cdf0e10cSrcweir                     com.sun.star.sheet.MemberResultFlags.HASMEMBER;
313*cdf0e10cSrcweir                 ++nResultPos;
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir                 for (int nInner=1; nInner<nFill; nInner++)
316*cdf0e10cSrcweir                 {
317*cdf0e10cSrcweir                     aResults[nResultPos] = new com.sun.star.sheet.MemberResult();
318*cdf0e10cSrcweir                     aResults[nResultPos].Flags =
319*cdf0e10cSrcweir                         com.sun.star.sheet.MemberResultFlags.CONTINUE;
320*cdf0e10cSrcweir                     ++nResultPos;
321*cdf0e10cSrcweir                 }
322*cdf0e10cSrcweir             }
323*cdf0e10cSrcweir         }
324*cdf0e10cSrcweir         return aResults;
325*cdf0e10cSrcweir     }
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     //  XPropertySet
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     public com.sun.star.beans.XPropertySetInfo getPropertySetInfo()
330*cdf0e10cSrcweir     {
331*cdf0e10cSrcweir         return new ExamplePropertySetInfo( new com.sun.star.beans.Property[] {
332*cdf0e10cSrcweir             new com.sun.star.beans.Property( "SubTotals", -1,
333*cdf0e10cSrcweir                             new com.sun.star.uno.Type(
334*cdf0e10cSrcweir                                 com.sun.star.sheet.GeneralFunction[].class ),
335*cdf0e10cSrcweir                                              (short) 0 ),
336*cdf0e10cSrcweir             new com.sun.star.beans.Property( "ShowEmpty", -1,
337*cdf0e10cSrcweir                              new com.sun.star.uno.Type( Boolean.class ),
338*cdf0e10cSrcweir                                              (short) 0 ) } );
339*cdf0e10cSrcweir     }
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir     public void setPropertyValue( String aPropertyName, Object aValue )
342*cdf0e10cSrcweir         throws com.sun.star.beans.UnknownPropertyException
343*cdf0e10cSrcweir     {
344*cdf0e10cSrcweir         if ( aPropertyName.equals( "SubTotals" ) ||
345*cdf0e10cSrcweir              aPropertyName.equals( "ShowEmpty" ) )
346*cdf0e10cSrcweir         {
347*cdf0e10cSrcweir             // ignored
348*cdf0e10cSrcweir         }
349*cdf0e10cSrcweir         else
350*cdf0e10cSrcweir             throw new com.sun.star.beans.UnknownPropertyException();
351*cdf0e10cSrcweir     }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir     public Object getPropertyValue( String aPropertyName )
354*cdf0e10cSrcweir         throws com.sun.star.beans.UnknownPropertyException
355*cdf0e10cSrcweir     {
356*cdf0e10cSrcweir         if ( aPropertyName.equals( "SubTotals" ) )
357*cdf0e10cSrcweir             return new com.sun.star.sheet.GeneralFunction[0];
358*cdf0e10cSrcweir         else if ( aPropertyName.equals( "ShowEmpty" ) )
359*cdf0e10cSrcweir             return new Boolean( true );
360*cdf0e10cSrcweir         else
361*cdf0e10cSrcweir             throw new com.sun.star.beans.UnknownPropertyException();
362*cdf0e10cSrcweir     }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     public void addPropertyChangeListener(
365*cdf0e10cSrcweir         String aPropertyName, com.sun.star.beans.XPropertyChangeListener xListener)
366*cdf0e10cSrcweir     {
367*cdf0e10cSrcweir     }
368*cdf0e10cSrcweir     public void removePropertyChangeListener(
369*cdf0e10cSrcweir         String aPropertyName, com.sun.star.beans.XPropertyChangeListener aListener)
370*cdf0e10cSrcweir     {
371*cdf0e10cSrcweir     }
372*cdf0e10cSrcweir     public void addVetoableChangeListener(
373*cdf0e10cSrcweir         String PropertyName, com.sun.star.beans.XVetoableChangeListener aListener)
374*cdf0e10cSrcweir     {
375*cdf0e10cSrcweir     }
376*cdf0e10cSrcweir     public void removeVetoableChangeListener(
377*cdf0e10cSrcweir         String PropertyName, com.sun.star.beans.XVetoableChangeListener aListener)
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir     }
380*cdf0e10cSrcweir }
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir //  implementation of com.sun.star.sheet.DataPilotSourceLevels
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir class ExampleLevels implements com.sun.star.container.XNameAccess
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir     private ExampleSettings aSettings;
387*cdf0e10cSrcweir     private int nDimension;
388*cdf0e10cSrcweir     private ExampleLevel aLevel;
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     public ExampleLevels( ExampleSettings aSet, int nDim )
391*cdf0e10cSrcweir     {
392*cdf0e10cSrcweir         aSettings = aSet;
393*cdf0e10cSrcweir         nDimension = nDim;
394*cdf0e10cSrcweir     }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir     // XNameAccess
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     public com.sun.star.uno.Type getElementType()
399*cdf0e10cSrcweir     {
400*cdf0e10cSrcweir         return new com.sun.star.uno.Type( com.sun.star.container.XNamed.class );
401*cdf0e10cSrcweir     }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir     public boolean hasElements()
404*cdf0e10cSrcweir     {
405*cdf0e10cSrcweir         return true;    // always has elements
406*cdf0e10cSrcweir     }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir     public Object getByName( String aName )
409*cdf0e10cSrcweir         throws com.sun.star.container.NoSuchElementException
410*cdf0e10cSrcweir     {
411*cdf0e10cSrcweir         //  there's only one level with the same name as the dimension / hierarchy
412*cdf0e10cSrcweir         if ( aName.equals( ExampleSettings.aDimensionNames[nDimension] ) )
413*cdf0e10cSrcweir         {
414*cdf0e10cSrcweir             if ( aLevel == null )
415*cdf0e10cSrcweir                 aLevel = new ExampleLevel( aSettings, nDimension );
416*cdf0e10cSrcweir             return aLevel;
417*cdf0e10cSrcweir         }
418*cdf0e10cSrcweir         throw new com.sun.star.container.NoSuchElementException();
419*cdf0e10cSrcweir     }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir     public String[] getElementNames()
422*cdf0e10cSrcweir     {
423*cdf0e10cSrcweir         String [] aNames = new String[ 1 ];
424*cdf0e10cSrcweir         aNames[0] = ExampleSettings.aDimensionNames[nDimension];
425*cdf0e10cSrcweir         return aNames;
426*cdf0e10cSrcweir     }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir     public boolean hasByName( String aName )
429*cdf0e10cSrcweir     {
430*cdf0e10cSrcweir         return aName.equals( ExampleSettings.aDimensionNames[nDimension] );
431*cdf0e10cSrcweir     }
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir //  implementation of com.sun.star.sheet.DataPilotSourceHierarchy
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir class ExampleHierarchy implements com.sun.star.container.XNamed,
437*cdf0e10cSrcweir       com.sun.star.sheet.XLevelsSupplier
438*cdf0e10cSrcweir {
439*cdf0e10cSrcweir     private ExampleSettings aSettings;
440*cdf0e10cSrcweir     private int nDimension;
441*cdf0e10cSrcweir     private ExampleLevels aLevels;
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir     public ExampleHierarchy( ExampleSettings aSet, int nDim )
444*cdf0e10cSrcweir     {
445*cdf0e10cSrcweir         aSettings = aSet;
446*cdf0e10cSrcweir         nDimension = nDim;
447*cdf0e10cSrcweir     }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir     // XNamed
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir     public String getName()
452*cdf0e10cSrcweir     {
453*cdf0e10cSrcweir         return ExampleSettings.aDimensionNames[ nDimension ];
454*cdf0e10cSrcweir     }
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir     public void setName( String aName )
457*cdf0e10cSrcweir     {
458*cdf0e10cSrcweir         // ignored
459*cdf0e10cSrcweir     }
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir     // XLevelsSupplier
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir     public com.sun.star.container.XNameAccess getLevels()
464*cdf0e10cSrcweir     {
465*cdf0e10cSrcweir         if ( aLevels == null )
466*cdf0e10cSrcweir             aLevels = new ExampleLevels( aSettings, nDimension );
467*cdf0e10cSrcweir         return aLevels;
468*cdf0e10cSrcweir     }
469*cdf0e10cSrcweir }
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir //  implementation of com.sun.star.sheet.DataPilotSourceHierarchies
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir class ExampleHierarchies implements com.sun.star.container.XNameAccess
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir     private ExampleSettings aSettings;
476*cdf0e10cSrcweir     private int nDimension;
477*cdf0e10cSrcweir     private ExampleHierarchy aHierarchy;
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir     public ExampleHierarchies( ExampleSettings aSet, int nDim )
480*cdf0e10cSrcweir     {
481*cdf0e10cSrcweir         aSettings = aSet;
482*cdf0e10cSrcweir         nDimension = nDim;
483*cdf0e10cSrcweir     }
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir     //  XNameAccess
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir     public com.sun.star.uno.Type getElementType()
488*cdf0e10cSrcweir     {
489*cdf0e10cSrcweir         return new com.sun.star.uno.Type( com.sun.star.container.XNamed.class );
490*cdf0e10cSrcweir     }
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir     public boolean hasElements()
493*cdf0e10cSrcweir     {
494*cdf0e10cSrcweir         return true;    // always has elements
495*cdf0e10cSrcweir     }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir     public Object getByName( String aName )
498*cdf0e10cSrcweir         throws com.sun.star.container.NoSuchElementException
499*cdf0e10cSrcweir     {
500*cdf0e10cSrcweir         //  there's only one hierarchy with the same name as the dimension
501*cdf0e10cSrcweir         if ( aName.equals( ExampleSettings.aDimensionNames[nDimension] ) )
502*cdf0e10cSrcweir         {
503*cdf0e10cSrcweir             if ( aHierarchy == null )
504*cdf0e10cSrcweir                 aHierarchy = new ExampleHierarchy( aSettings, nDimension );
505*cdf0e10cSrcweir             return aHierarchy;
506*cdf0e10cSrcweir         }
507*cdf0e10cSrcweir         throw new com.sun.star.container.NoSuchElementException();
508*cdf0e10cSrcweir     }
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir     public String[] getElementNames()
511*cdf0e10cSrcweir     {
512*cdf0e10cSrcweir         String [] aNames = new String[ 1 ];
513*cdf0e10cSrcweir         aNames[0] = ExampleSettings.aDimensionNames[nDimension];
514*cdf0e10cSrcweir         return aNames;
515*cdf0e10cSrcweir     }
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir     public boolean hasByName( String aName )
518*cdf0e10cSrcweir     {
519*cdf0e10cSrcweir         return aName.equals( ExampleSettings.aDimensionNames[nDimension] );
520*cdf0e10cSrcweir     }
521*cdf0e10cSrcweir }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir //  implementation of com.sun.star.sheet.DataPilotSourceDimension
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir class ExampleDimension implements
526*cdf0e10cSrcweir                     com.sun.star.container.XNamed,
527*cdf0e10cSrcweir                     com.sun.star.sheet.XHierarchiesSupplier,
528*cdf0e10cSrcweir                     com.sun.star.util.XCloneable,
529*cdf0e10cSrcweir                     com.sun.star.beans.XPropertySet
530*cdf0e10cSrcweir {
531*cdf0e10cSrcweir     private ExampleSettings aSettings;
532*cdf0e10cSrcweir     private int nDimension;
533*cdf0e10cSrcweir     private ExampleHierarchies aHierarchies;
534*cdf0e10cSrcweir     private com.sun.star.sheet.DataPilotFieldOrientation eOrientation;
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir     public ExampleDimension( ExampleSettings aSet, int nDim )
537*cdf0e10cSrcweir     {
538*cdf0e10cSrcweir         aSettings = aSet;
539*cdf0e10cSrcweir         nDimension = nDim;
540*cdf0e10cSrcweir         eOrientation = ( nDim == ExampleSettings.nValueDimension ) ?
541*cdf0e10cSrcweir             com.sun.star.sheet.DataPilotFieldOrientation.DATA :
542*cdf0e10cSrcweir             com.sun.star.sheet.DataPilotFieldOrientation.HIDDEN;
543*cdf0e10cSrcweir     }
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir     //  XNamed
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir     public String getName()
548*cdf0e10cSrcweir     {
549*cdf0e10cSrcweir         return ExampleSettings.aDimensionNames[ nDimension ];
550*cdf0e10cSrcweir     }
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir     public void setName( String aName )
553*cdf0e10cSrcweir     {
554*cdf0e10cSrcweir         // ignored
555*cdf0e10cSrcweir     }
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir     //  XHierarchiesSupplier
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir     public com.sun.star.container.XNameAccess getHierarchies()
560*cdf0e10cSrcweir     {
561*cdf0e10cSrcweir         if ( aHierarchies == null )
562*cdf0e10cSrcweir             aHierarchies = new ExampleHierarchies( aSettings, nDimension );
563*cdf0e10cSrcweir         return aHierarchies;
564*cdf0e10cSrcweir     }
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir     //  XCloneable
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir     public com.sun.star.util.XCloneable createClone()
569*cdf0e10cSrcweir     {
570*cdf0e10cSrcweir         return null;        // not supported
571*cdf0e10cSrcweir     }
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir     //  XPropertySet
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir     public com.sun.star.beans.XPropertySetInfo getPropertySetInfo()
576*cdf0e10cSrcweir     {
577*cdf0e10cSrcweir         return new ExamplePropertySetInfo( new com.sun.star.beans.Property[] {
578*cdf0e10cSrcweir             new com.sun.star.beans.Property( "Original", -1,
579*cdf0e10cSrcweir                 new com.sun.star.uno.Type( com.sun.star.container.XNamed.class),
580*cdf0e10cSrcweir                 (short) com.sun.star.beans.PropertyAttribute.READONLY ),
581*cdf0e10cSrcweir             new com.sun.star.beans.Property( "IsDataLayoutDimension", -1,
582*cdf0e10cSrcweir                 new com.sun.star.uno.Type( Boolean.class),
583*cdf0e10cSrcweir                 (short) com.sun.star.beans.PropertyAttribute.READONLY ),
584*cdf0e10cSrcweir             new com.sun.star.beans.Property( "Orientation", -1,
585*cdf0e10cSrcweir                 new com.sun.star.uno.Type(
586*cdf0e10cSrcweir                   com.sun.star.sheet.DataPilotFieldOrientation.class), (short) 0),
587*cdf0e10cSrcweir             new com.sun.star.beans.Property( "Position", -1,
588*cdf0e10cSrcweir                 new com.sun.star.uno.Type( Integer.class ), (short) 0),
589*cdf0e10cSrcweir             new com.sun.star.beans.Property( "Function", -1,
590*cdf0e10cSrcweir                 new com.sun.star.uno.Type(com.sun.star.sheet.GeneralFunction.class),
591*cdf0e10cSrcweir                                              (short) 0 ),
592*cdf0e10cSrcweir             new com.sun.star.beans.Property( "UsedHierarchy", -1,
593*cdf0e10cSrcweir                 new com.sun.star.uno.Type( Integer.class ), (short) 0 ),
594*cdf0e10cSrcweir             new com.sun.star.beans.Property( "Filter", -1,
595*cdf0e10cSrcweir                 new com.sun.star.uno.Type(
596*cdf0e10cSrcweir                     com.sun.star.sheet.TableFilterField[].class), (short) 0) });
597*cdf0e10cSrcweir     }
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir     public void setPropertyValue( String aPropertyName, Object aValue )
600*cdf0e10cSrcweir                     throws com.sun.star.beans.UnknownPropertyException
601*cdf0e10cSrcweir     {
602*cdf0e10cSrcweir         if ( aPropertyName.equals( "Orientation" ) )
603*cdf0e10cSrcweir         {
604*cdf0e10cSrcweir             com.sun.star.sheet.DataPilotFieldOrientation eNewOrient =
605*cdf0e10cSrcweir                         (com.sun.star.sheet.DataPilotFieldOrientation) aValue;
606*cdf0e10cSrcweir             if ( nDimension != ExampleSettings.nValueDimension &&
607*cdf0e10cSrcweir                  nDimension != ExampleSettings.nDataDimension &&
608*cdf0e10cSrcweir                  eNewOrient != com.sun.star.sheet.DataPilotFieldOrientation.DATA )
609*cdf0e10cSrcweir             {
610*cdf0e10cSrcweir                 // remove from list for old orientation and add for new one
611*cdf0e10cSrcweir                 Integer aDimInt = new Integer(nDimension);
612*cdf0e10cSrcweir                 if ( eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.COLUMN )
613*cdf0e10cSrcweir                     aSettings.aColDimensions.remove( aDimInt );
614*cdf0e10cSrcweir                 else if ( eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.ROW )
615*cdf0e10cSrcweir                     aSettings.aRowDimensions.remove( aDimInt );
616*cdf0e10cSrcweir                 if ( eNewOrient == com.sun.star.sheet.DataPilotFieldOrientation.COLUMN )
617*cdf0e10cSrcweir                     aSettings.aColDimensions.add( aDimInt );
618*cdf0e10cSrcweir                 else if ( eNewOrient == com.sun.star.sheet.DataPilotFieldOrientation.ROW )
619*cdf0e10cSrcweir                     aSettings.aRowDimensions.add( aDimInt );
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir                 // change orientation
622*cdf0e10cSrcweir                 eOrientation = eNewOrient;
623*cdf0e10cSrcweir             }
624*cdf0e10cSrcweir         }
625*cdf0e10cSrcweir         else if ( aPropertyName.equals( "Position" ) )
626*cdf0e10cSrcweir         {
627*cdf0e10cSrcweir             int nNewPos = ((Integer) aValue).intValue();
628*cdf0e10cSrcweir             Integer aDimInt = new Integer(nDimension);
629*cdf0e10cSrcweir             if ( eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.COLUMN )
630*cdf0e10cSrcweir             {
631*cdf0e10cSrcweir                 aSettings.aColDimensions.remove( aDimInt );
632*cdf0e10cSrcweir                 aSettings.aColDimensions.add( nNewPos, aDimInt );
633*cdf0e10cSrcweir             }
634*cdf0e10cSrcweir             else if ( eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.ROW )
635*cdf0e10cSrcweir             {
636*cdf0e10cSrcweir                 aSettings.aRowDimensions.remove( aDimInt );
637*cdf0e10cSrcweir                 aSettings.aRowDimensions.add( nNewPos, aDimInt );
638*cdf0e10cSrcweir             }
639*cdf0e10cSrcweir         }
640*cdf0e10cSrcweir         else if ( aPropertyName.equals( "Function" ) || aPropertyName.equals( "UsedHierarchy" ) ||
641*cdf0e10cSrcweir                   aPropertyName.equals( "Filter" ) )
642*cdf0e10cSrcweir         {
643*cdf0e10cSrcweir             // ignored
644*cdf0e10cSrcweir         }
645*cdf0e10cSrcweir         else
646*cdf0e10cSrcweir             throw new com.sun.star.beans.UnknownPropertyException();
647*cdf0e10cSrcweir     }
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir     public Object getPropertyValue( String aPropertyName )
650*cdf0e10cSrcweir                     throws com.sun.star.beans.UnknownPropertyException
651*cdf0e10cSrcweir     {
652*cdf0e10cSrcweir         if ( aPropertyName.equals( "Original" ) )
653*cdf0e10cSrcweir             return null;
654*cdf0e10cSrcweir         else if ( aPropertyName.equals( "IsDataLayoutDimension" ) )
655*cdf0e10cSrcweir             return new Boolean( nDimension == ExampleSettings.nDataDimension );
656*cdf0e10cSrcweir         else if ( aPropertyName.equals( "Orientation" ) )
657*cdf0e10cSrcweir             return eOrientation;
658*cdf0e10cSrcweir         else if ( aPropertyName.equals( "Position" ) )
659*cdf0e10cSrcweir         {
660*cdf0e10cSrcweir             int nPosition;
661*cdf0e10cSrcweir             if ( eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.COLUMN )
662*cdf0e10cSrcweir                 nPosition = aSettings.aColDimensions.indexOf( new Integer(nDimension) );
663*cdf0e10cSrcweir             else if ( eOrientation == com.sun.star.sheet.DataPilotFieldOrientation.ROW )
664*cdf0e10cSrcweir                 nPosition = aSettings.aRowDimensions.indexOf( new Integer(nDimension) );
665*cdf0e10cSrcweir             else
666*cdf0e10cSrcweir                 nPosition = nDimension;
667*cdf0e10cSrcweir             return new Integer( nPosition );
668*cdf0e10cSrcweir         }
669*cdf0e10cSrcweir         else if ( aPropertyName.equals( "Function" ) )
670*cdf0e10cSrcweir             return com.sun.star.sheet.GeneralFunction.SUM;
671*cdf0e10cSrcweir         else if ( aPropertyName.equals( "UsedHierarchy" ) )
672*cdf0e10cSrcweir             return new Integer(0);
673*cdf0e10cSrcweir         else if ( aPropertyName.equals( "Filter" ) )
674*cdf0e10cSrcweir             return new com.sun.star.sheet.TableFilterField[0];
675*cdf0e10cSrcweir         else
676*cdf0e10cSrcweir             throw new com.sun.star.beans.UnknownPropertyException();
677*cdf0e10cSrcweir     }
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir     public void addPropertyChangeListener(
680*cdf0e10cSrcweir         String aPropertyName, com.sun.star.beans.XPropertyChangeListener xListener)
681*cdf0e10cSrcweir     {
682*cdf0e10cSrcweir     }
683*cdf0e10cSrcweir     public void removePropertyChangeListener(
684*cdf0e10cSrcweir         String aPropertyName, com.sun.star.beans.XPropertyChangeListener aListener)
685*cdf0e10cSrcweir     {
686*cdf0e10cSrcweir     }
687*cdf0e10cSrcweir     public void addVetoableChangeListener(
688*cdf0e10cSrcweir         String PropertyName, com.sun.star.beans.XVetoableChangeListener aListener)
689*cdf0e10cSrcweir     {
690*cdf0e10cSrcweir     }
691*cdf0e10cSrcweir     public void removeVetoableChangeListener(
692*cdf0e10cSrcweir         String PropertyName, com.sun.star.beans.XVetoableChangeListener aListener)
693*cdf0e10cSrcweir     {
694*cdf0e10cSrcweir     }
695*cdf0e10cSrcweir }
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir //  implementation of com.sun.star.sheet.DataPilotSourceDimensions
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir class ExampleDimensions implements com.sun.star.container.XNameAccess
700*cdf0e10cSrcweir {
701*cdf0e10cSrcweir     private ExampleSettings aSettings;
702*cdf0e10cSrcweir     private ExampleDimension[] aDimensions;
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir     public ExampleDimensions( ExampleSettings aSet )
705*cdf0e10cSrcweir     {
706*cdf0e10cSrcweir         aSettings = aSet;
707*cdf0e10cSrcweir     }
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir     //  XNameAccess
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir     public com.sun.star.uno.Type getElementType()
712*cdf0e10cSrcweir     {
713*cdf0e10cSrcweir         return new com.sun.star.uno.Type( com.sun.star.container.XNamed.class );
714*cdf0e10cSrcweir     }
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir     public boolean hasElements()
717*cdf0e10cSrcweir     {
718*cdf0e10cSrcweir         return true;    // always has elements
719*cdf0e10cSrcweir     }
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir     public Object getByName( String aName )
722*cdf0e10cSrcweir         throws com.sun.star.container.NoSuchElementException
723*cdf0e10cSrcweir     {
724*cdf0e10cSrcweir         for (int i=0; i<ExampleSettings.nDimensionCount; i++)
725*cdf0e10cSrcweir             if ( aName.equals( ExampleSettings.aDimensionNames[i] ) )
726*cdf0e10cSrcweir             {
727*cdf0e10cSrcweir                 if ( aDimensions == null )
728*cdf0e10cSrcweir                     aDimensions = new ExampleDimension[ ExampleSettings.nDimensionCount ];
729*cdf0e10cSrcweir                 if ( aDimensions[i] == null )
730*cdf0e10cSrcweir                     aDimensions[i] = new ExampleDimension( aSettings, i );
731*cdf0e10cSrcweir                 return aDimensions[i];
732*cdf0e10cSrcweir             }
733*cdf0e10cSrcweir         throw new com.sun.star.container.NoSuchElementException();
734*cdf0e10cSrcweir     }
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir     public String[] getElementNames()
737*cdf0e10cSrcweir     {
738*cdf0e10cSrcweir         String [] aNames = new String[ ExampleSettings.nDimensionCount ];
739*cdf0e10cSrcweir         for (int i=0; i<ExampleSettings.nDimensionCount; i++)
740*cdf0e10cSrcweir             aNames[ i ] = ExampleSettings.aDimensionNames[i];
741*cdf0e10cSrcweir         return aNames;
742*cdf0e10cSrcweir     }
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir     public boolean hasByName( String aName )
745*cdf0e10cSrcweir     {
746*cdf0e10cSrcweir         for (int i=0; i<ExampleSettings.nDimensionCount; i++)
747*cdf0e10cSrcweir             if ( aName.equals( ExampleSettings.aDimensionNames[i] ) )
748*cdf0e10cSrcweir                 return true;
749*cdf0e10cSrcweir         return false;
750*cdf0e10cSrcweir     }
751*cdf0e10cSrcweir }
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir //  outer class for service implementation
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir public class ExampleDataPilotSource
756*cdf0e10cSrcweir {
757*cdf0e10cSrcweir     //  implementation of com.sun.star.sheet.DataPilotSource
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir     static public class _ExampleDataPilotSource implements
760*cdf0e10cSrcweir                         com.sun.star.sheet.XDimensionsSupplier,
761*cdf0e10cSrcweir                         com.sun.star.sheet.XDataPilotResults,
762*cdf0e10cSrcweir                         com.sun.star.util.XRefreshable,
763*cdf0e10cSrcweir                         com.sun.star.beans.XPropertySet,
764*cdf0e10cSrcweir                         com.sun.star.lang.XInitialization,
765*cdf0e10cSrcweir                         com.sun.star.lang.XServiceInfo
766*cdf0e10cSrcweir     {
767*cdf0e10cSrcweir         static private final String aServiceName = "com.sun.star.sheet.DataPilotSource";
768*cdf0e10cSrcweir         static private final String aImplName =  _ExampleDataPilotSource.class.getName();
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir         private ExampleSettings aSettings = new ExampleSettings();
771*cdf0e10cSrcweir         private ExampleDimensions aDimensions;
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir         public _ExampleDataPilotSource( com.sun.star.lang.XMultiServiceFactory xFactory )
774*cdf0e10cSrcweir         {
775*cdf0e10cSrcweir         }
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir         //  XInitialization
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir         public void initialize( Object[] aArguments )
780*cdf0e10cSrcweir         {
781*cdf0e10cSrcweir             //  If the first argument (Source) is a number between 2 and 10,
782*cdf0e10cSrcweir             //  use it as member count, otherwise keep the default value.
783*cdf0e10cSrcweir             try
784*cdf0e10cSrcweir             {
785*cdf0e10cSrcweir 		if ( aArguments.length >= 1 )
786*cdf0e10cSrcweir 		{
787*cdf0e10cSrcweir 		    String aSource = com.sun.star.uno.AnyConverter.toString(aArguments[0]);
788*cdf0e10cSrcweir 		    if ( aSource != null && aSource.length() > 0)
789*cdf0e10cSrcweir 		    {
790*cdf0e10cSrcweir 			int nValue = Integer.parseInt( aSource );
791*cdf0e10cSrcweir 			if ( nValue >= 2 && nValue <= 10 )
792*cdf0e10cSrcweir 			    aSettings.nMemberCount = nValue;
793*cdf0e10cSrcweir 		    }
794*cdf0e10cSrcweir 		}
795*cdf0e10cSrcweir 	    }
796*cdf0e10cSrcweir 	    catch ( NumberFormatException e )
797*cdf0e10cSrcweir 	    {
798*cdf0e10cSrcweir 		System.out.println( "Error: caught exception in " +
799*cdf0e10cSrcweir 				    "ExampleDataPilotSource.initialize!\nException Message = "
800*cdf0e10cSrcweir 				    + e.getMessage());
801*cdf0e10cSrcweir 		e.printStackTrace();
802*cdf0e10cSrcweir 	    }
803*cdf0e10cSrcweir 	    catch ( com.sun.star.lang.IllegalArgumentException e )
804*cdf0e10cSrcweir 	    {
805*cdf0e10cSrcweir 		System.out.println( "Error: caught exception in " +
806*cdf0e10cSrcweir 				    "ExampleDataPilotSource.initialize!\nException Message = "
807*cdf0e10cSrcweir 				    + e.getMessage());
808*cdf0e10cSrcweir 		e.printStackTrace();
809*cdf0e10cSrcweir 	    }
810*cdf0e10cSrcweir         }
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir         //  XDataPilotResults
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir         public com.sun.star.sheet.DataResult[][] getResults()
815*cdf0e10cSrcweir         {
816*cdf0e10cSrcweir             int[] nDigits = new int[ExampleSettings.nDimensionCount];
817*cdf0e10cSrcweir             int nValue = 1;
818*cdf0e10cSrcweir             for (int i=0; i<ExampleSettings.nDimensionCount; i++)
819*cdf0e10cSrcweir             {
820*cdf0e10cSrcweir                 nDigits[i] = nValue;
821*cdf0e10cSrcweir                 nValue *= 10;
822*cdf0e10cSrcweir             }
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir             int nMemberCount = aSettings.nMemberCount;
825*cdf0e10cSrcweir             int nRowDimCount = aSettings.aRowDimensions.size();
826*cdf0e10cSrcweir             int nColDimCount = aSettings.aColDimensions.size();
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir             int nRows = 1;
829*cdf0e10cSrcweir             for (int i=0; i<nRowDimCount; i++)
830*cdf0e10cSrcweir                 nRows *= nMemberCount;
831*cdf0e10cSrcweir             int nColumns = 1;
832*cdf0e10cSrcweir             for (int i=0; i<nColDimCount; i++)
833*cdf0e10cSrcweir                 nColumns *= nMemberCount;
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir             com.sun.star.sheet.DataResult[][] aResults = new com.sun.star.sheet.DataResult[nRows][];
836*cdf0e10cSrcweir             for (int nRow=0; nRow<nRows; nRow++)
837*cdf0e10cSrcweir             {
838*cdf0e10cSrcweir                 int nRowVal = nRow;
839*cdf0e10cSrcweir                 int nRowResult = 0;
840*cdf0e10cSrcweir                 for (int nRowDim=0; nRowDim<nRowDimCount; nRowDim++)
841*cdf0e10cSrcweir                 {
842*cdf0e10cSrcweir                     int nDim = ((Integer)aSettings.aRowDimensions.get(nRowDimCount-nRowDim-1)).intValue();
843*cdf0e10cSrcweir                     nRowResult += ( nRowVal % nMemberCount ) * nDigits[nDim];
844*cdf0e10cSrcweir                     nRowVal /= nMemberCount;
845*cdf0e10cSrcweir                 }
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir                 aResults[nRow] = new com.sun.star.sheet.DataResult[nColumns];
848*cdf0e10cSrcweir                 for (int nCol=0; nCol<nColumns; nCol++)
849*cdf0e10cSrcweir                 {
850*cdf0e10cSrcweir                     int nColVal = nCol;
851*cdf0e10cSrcweir                     int nResult = nRowResult;
852*cdf0e10cSrcweir                     for (int nColDim=0; nColDim<nColDimCount; nColDim++)
853*cdf0e10cSrcweir                     {
854*cdf0e10cSrcweir                         int nDim = ((Integer)aSettings.aColDimensions.get(nColDimCount-nColDim-1)).intValue();
855*cdf0e10cSrcweir                         nResult += ( nColVal % nMemberCount ) * nDigits[nDim];
856*cdf0e10cSrcweir                         nColVal /= nMemberCount;
857*cdf0e10cSrcweir                     }
858*cdf0e10cSrcweir 
859*cdf0e10cSrcweir                     aResults[nRow][nCol] = new com.sun.star.sheet.DataResult();
860*cdf0e10cSrcweir                     aResults[nRow][nCol].Flags = com.sun.star.sheet.DataResultFlags.HASDATA;
861*cdf0e10cSrcweir                     aResults[nRow][nCol].Value = nResult;
862*cdf0e10cSrcweir                 }
863*cdf0e10cSrcweir             }
864*cdf0e10cSrcweir             return aResults;
865*cdf0e10cSrcweir         }
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir         //  XDimensionsSupplier
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir         public com.sun.star.container.XNameAccess getDimensions()
870*cdf0e10cSrcweir         {
871*cdf0e10cSrcweir             if ( aDimensions == null )
872*cdf0e10cSrcweir                 aDimensions = new ExampleDimensions( aSettings );
873*cdf0e10cSrcweir             return aDimensions;
874*cdf0e10cSrcweir         }
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir         //  XPropertySet
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir         public com.sun.star.beans.XPropertySetInfo getPropertySetInfo()
879*cdf0e10cSrcweir         {
880*cdf0e10cSrcweir             return new ExamplePropertySetInfo( new com.sun.star.beans.Property[] {
881*cdf0e10cSrcweir                 new com.sun.star.beans.Property( "ColumnGrand", -1,
882*cdf0e10cSrcweir                        new com.sun.star.uno.Type( Boolean.class ), (short) 0),
883*cdf0e10cSrcweir                 new com.sun.star.beans.Property( "RowGrand", -1,
884*cdf0e10cSrcweir                        new com.sun.star.uno.Type( Boolean.class ), (short) 0) });
885*cdf0e10cSrcweir         }
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir         public void setPropertyValue( String aPropertyName, Object aValue )
888*cdf0e10cSrcweir             throws com.sun.star.beans.UnknownPropertyException
889*cdf0e10cSrcweir         {
890*cdf0e10cSrcweir             if ( aPropertyName.equals( "ColumnGrand" ) ||
891*cdf0e10cSrcweir                  aPropertyName.equals( "RowGrand" ) )
892*cdf0e10cSrcweir             {
893*cdf0e10cSrcweir                 // ignored
894*cdf0e10cSrcweir             }
895*cdf0e10cSrcweir             else
896*cdf0e10cSrcweir                 throw new com.sun.star.beans.UnknownPropertyException();
897*cdf0e10cSrcweir         }
898*cdf0e10cSrcweir 
899*cdf0e10cSrcweir         public Object getPropertyValue( String aPropertyName )
900*cdf0e10cSrcweir             throws com.sun.star.beans.UnknownPropertyException
901*cdf0e10cSrcweir         {
902*cdf0e10cSrcweir             if ( aPropertyName.equals( "ColumnGrand" ) ||
903*cdf0e10cSrcweir                  aPropertyName.equals( "RowGrand" ) )
904*cdf0e10cSrcweir             {
905*cdf0e10cSrcweir                 return new Boolean( false );        // always false
906*cdf0e10cSrcweir             }
907*cdf0e10cSrcweir             else
908*cdf0e10cSrcweir                 throw new com.sun.star.beans.UnknownPropertyException();
909*cdf0e10cSrcweir         }
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir         public void addPropertyChangeListener(
912*cdf0e10cSrcweir             String aPropertyName,
913*cdf0e10cSrcweir             com.sun.star.beans.XPropertyChangeListener xListener )
914*cdf0e10cSrcweir         {
915*cdf0e10cSrcweir         }
916*cdf0e10cSrcweir         public void removePropertyChangeListener(
917*cdf0e10cSrcweir             String aPropertyName,
918*cdf0e10cSrcweir             com.sun.star.beans.XPropertyChangeListener aListener )
919*cdf0e10cSrcweir         {
920*cdf0e10cSrcweir         }
921*cdf0e10cSrcweir         public void addVetoableChangeListener(
922*cdf0e10cSrcweir             String PropertyName,
923*cdf0e10cSrcweir             com.sun.star.beans.XVetoableChangeListener aListener )
924*cdf0e10cSrcweir         {
925*cdf0e10cSrcweir         }
926*cdf0e10cSrcweir         public void removeVetoableChangeListener(
927*cdf0e10cSrcweir             String PropertyName,
928*cdf0e10cSrcweir             com.sun.star.beans.XVetoableChangeListener aListener )
929*cdf0e10cSrcweir         {
930*cdf0e10cSrcweir         }
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir         //  XRefreshable
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir         public void refresh()
935*cdf0e10cSrcweir         {
936*cdf0e10cSrcweir         }
937*cdf0e10cSrcweir         public void addRefreshListener( com.sun.star.util.XRefreshListener l )
938*cdf0e10cSrcweir         {
939*cdf0e10cSrcweir         }
940*cdf0e10cSrcweir         public void removeRefreshListener( com.sun.star.util.XRefreshListener l )
941*cdf0e10cSrcweir         {
942*cdf0e10cSrcweir         }
943*cdf0e10cSrcweir 
944*cdf0e10cSrcweir         //  XServiceInfo
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir         public String getImplementationName()
947*cdf0e10cSrcweir         {
948*cdf0e10cSrcweir             return aImplName;
949*cdf0e10cSrcweir         }
950*cdf0e10cSrcweir 
951*cdf0e10cSrcweir         public String[] getSupportedServiceNames()
952*cdf0e10cSrcweir         {
953*cdf0e10cSrcweir             String [] aSupportedServices = new String[ 1 ];
954*cdf0e10cSrcweir             aSupportedServices[ 0 ] = aServiceName;
955*cdf0e10cSrcweir             return aSupportedServices;
956*cdf0e10cSrcweir         }
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir         public boolean supportsService( String aService )
959*cdf0e10cSrcweir         {
960*cdf0e10cSrcweir             return aService.equals( aServiceName );
961*cdf0e10cSrcweir         }
962*cdf0e10cSrcweir     }
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir     public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory(
965*cdf0e10cSrcweir         String implName,
966*cdf0e10cSrcweir         com.sun.star.lang.XMultiServiceFactory multiFactory,
967*cdf0e10cSrcweir         com.sun.star.registry.XRegistryKey regKey)
968*cdf0e10cSrcweir     {
969*cdf0e10cSrcweir         com.sun.star.lang.XSingleServiceFactory xSingleServiceFactory = null;
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir         if ( implName.equals(_ExampleDataPilotSource.aImplName) )
972*cdf0e10cSrcweir             xSingleServiceFactory =
973*cdf0e10cSrcweir                 com.sun.star.comp.loader.FactoryHelper.getServiceFactory(
974*cdf0e10cSrcweir                     _ExampleDataPilotSource.class,
975*cdf0e10cSrcweir                     _ExampleDataPilotSource.aServiceName, multiFactory, regKey);
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir         return xSingleServiceFactory;
978*cdf0e10cSrcweir     }
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir     // This method not longer necessary since OOo 3.4 where the component registration
981*cdf0e10cSrcweir     // was changed to passive component registration. For more details see
982*cdf0e10cSrcweir     // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir //     public static boolean __writeRegistryServiceInfo(
985*cdf0e10cSrcweir //         com.sun.star.registry.XRegistryKey regKey)
986*cdf0e10cSrcweir //     {
987*cdf0e10cSrcweir //         return com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo(
988*cdf0e10cSrcweir //                     _ExampleDataPilotSource.aImplName,
989*cdf0e10cSrcweir //                     _ExampleDataPilotSource.aServiceName, regKey);
990*cdf0e10cSrcweir //     }
991*cdf0e10cSrcweir }
992*cdf0e10cSrcweir 
993