1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package org.openoffice.test.tools;
24 
25 import com.sun.star.container.XIndexAccess;
26 import com.sun.star.frame.XController;
27 import com.sun.star.lang.XMultiServiceFactory;
28 import com.sun.star.sheet.XSpreadsheet;
29 import com.sun.star.sheet.XSpreadsheetDocument;
30 import com.sun.star.sheet.XSpreadsheetView;
31 import com.sun.star.uno.UnoRuntime;
32 import java.util.logging.Level;
33 import java.util.logging.Logger;
34 
35 /**
36  * @author frank.schoenheit@oracle.com
37  */
38 public class SpreadsheetView extends OfficeDocumentView
39 {
40 
41     /** Creates a new instance of SpreadsheetView */
SpreadsheetView( XMultiServiceFactory orb, OfficeDocument document, XController controller )42     public SpreadsheetView( XMultiServiceFactory orb, OfficeDocument document, XController controller )
43     {
44         super( orb, document, controller );
45     }
46 
47     /** activates the sheet with the given index
48      */
activateSheet( int sheetIndex )49     void activateSheet( int sheetIndex )
50     {
51         try
52         {
53             // get the sheet to activate
54             XSpreadsheetDocument doc = UnoRuntime.queryInterface( XSpreadsheetDocument.class, getDocument().getDocument() );
55             XIndexAccess sheets = UnoRuntime.queryInterface( XIndexAccess.class, doc.getSheets() );
56 
57             XSpreadsheet sheet = UnoRuntime.queryInterface( XSpreadsheet.class, sheets.getByIndex( sheetIndex ) );
58 
59             // activate
60             XSpreadsheetView view = UnoRuntime.queryInterface( XSpreadsheetView.class, getController() );
61             view.setActiveSheet( sheet );
62         }
63         catch( com.sun.star.uno.Exception e )
64         {
65             Logger.getLogger( SpreadsheetView.class.getName() ).log( Level.SEVERE, "unable to activate the given sheet", e );
66         }
67     }
68 }
69