Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / odk / examples / DevelopersGuide / Forms / SpreadsheetDocument.java
blobb227b2d5f00808482db433058ae5f931ce6cc923
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com.sun.star.uno.*;
21 import com.sun.star.lang.XComponent;
22 import com.sun.star.table.XCellRange;
23 import com.sun.star.table.CellAddress;
24 import com.sun.star.table.CellRangeAddress;
25 import com.sun.star.container.XIndexAccess;
26 import com.sun.star.sheet.XSpreadsheetDocument;
27 import com.sun.star.beans.NamedValue;
29 public class SpreadsheetDocument extends DocumentHelper
31 /** Creates a new blank spreadsheet document */
32 public SpreadsheetDocument( XComponentContext xCtx ) throws com.sun.star.uno.Exception
34 super( xCtx, implCreateBlankDocument( xCtx, "private:factory/scalc" ) );
37 public SpreadsheetDocument( XComponentContext xCtx, XComponent document )
39 super( xCtx, document );
42 public XCellRange getSheet( int index ) throws com.sun.star.uno.Exception
44 XSpreadsheetDocument spreadsheetDoc = UnoRuntime.queryInterface( XSpreadsheetDocument.class,
45 m_documentComponent
47 XIndexAccess sheets = UnoRuntime.queryInterface( XIndexAccess.class,
48 spreadsheetDoc.getSheets()
50 return UnoRuntime.queryInterface( XCellRange.class,
51 sheets.getByIndex( index )
55 /** creates a value binding for a given cell
57 public com.sun.star.form.binding.XValueBinding createCellBinding( short sheet, short column, short row )
59 return createCellBinding( sheet, column, row, false );
62 /** creates a value binding which can be used to exchange a list box selection <em>index</em> with a cell
64 public com.sun.star.form.binding.XValueBinding createListIndexBinding( short sheet, short column, short row )
66 return createCellBinding( sheet, column, row, true );
69 /** creates a value binding for a given cell, with or without support for integer value exchange
71 private com.sun.star.form.binding.XValueBinding createCellBinding( short sheet, short column, short row, boolean supportIntegerValues )
73 com.sun.star.form.binding.XValueBinding cellBinding = null;
74 try
76 CellAddress address = new CellAddress( sheet, column, row );
77 Object[] initParam = new Object[] { new NamedValue( "BoundCell", address ) };
78 cellBinding = UnoRuntime.queryInterface(
79 com.sun.star.form.binding.XValueBinding.class,
80 createInstanceWithArguments(
81 supportIntegerValues ? "com.sun.star.table.ListPositionCellBinding"
82 : "com.sun.star.table.CellValueBinding",
83 initParam
87 catch( com.sun.star.uno.Exception e )
89 System.err.println( e );
90 e.printStackTrace( System.err );
92 return cellBinding;
95 /** creates a source of list entries associated with a (one-column) cell range
97 public com.sun.star.form.binding.XListEntrySource createListEntrySource( short sheet, short column,
98 short topRow, short bottomRow )
100 com.sun.star.form.binding.XListEntrySource entrySource = null;
103 CellRangeAddress rangeAddress = new CellRangeAddress( sheet, column,
104 topRow, column, bottomRow );
105 Object[] initParam = new Object[] { new NamedValue( "CellRange", rangeAddress ) };
106 entrySource = UnoRuntime.queryInterface(
107 com.sun.star.form.binding.XListEntrySource.class,
108 createInstanceWithArguments(
109 "com.sun.star.table.CellRangeListSource", initParam ) );
111 catch( com.sun.star.uno.Exception e )
113 System.err.println( e );
114 e.printStackTrace( System.err );
116 return entrySource;
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */