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