1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ValueBinding.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.beans
.XPropertySet
;
35 import com
.sun
.star
.text
.XTextDocument
;
36 import com
.sun
.star
.text
.XText
;
37 import com
.sun
.star
.text
.XTextTable
;
38 import com
.sun
.star
.text
.XTextCursor
;
39 import com
.sun
.star
.form
.binding
.XValueBinding
;
40 import com
.sun
.star
.form
.binding
.XBindableValue
;
42 public class ValueBinding
extends DocumentBasedExample
44 /** Creates a new instance of ValueBinding */
47 super( DocumentType
.WRITER
);
50 /* ------------------------------------------------------------------ */
51 protected void prepareDocument() throws com
.sun
.star
.uno
.Exception
, java
.lang
.Exception
53 super.prepareDocument();
55 // insert a table with exactly one cell. The content of this table will be synced with
56 // the content of a form control
57 XTextDocument textDoc
= (XTextDocument
)UnoRuntime
.queryInterface( XTextDocument
.class, m_document
.getDocument() );
58 XText documentText
= textDoc
.getText();
59 XTextCursor textCursor
= documentText
.createTextCursor();
60 documentText
.insertString( textCursor
, "Below, there's a table cell, and a text field. ", false );
61 documentText
.insertString( textCursor
, "Both are linked via an external value binding.\n", false );
62 documentText
.insertString( textCursor
, "That means that anything you insert into the table cell is reflected in the ", false );
63 documentText
.insertString( textCursor
, "text field, and vice versa.\n", false );
65 XTextTable table
= (XTextTable
)UnoRuntime
.queryInterface( XTextTable
.class,
66 m_document
.createInstance( "com.sun.star.text.TextTable" )
68 table
.initialize( 1, 1 );
69 documentText
.insertTextContent( textCursor
, table
, false );
71 // insert our sample control
72 XPropertySet textControl
= m_formLayer
.insertControlLine( "DatabaseTextField", "enter some text", "", 30 );
74 // create a value binding for the first cell of the table
75 XValueBinding cellBinding
= new TableCellTextBinding( table
.getCellByName( "A1" ) );
76 // and bind it to the control
77 XBindableValue bindable
= (XBindableValue
)UnoRuntime
.queryInterface(
78 XBindableValue
.class, textControl
80 bindable
.setValueBinding( cellBinding
);
83 /* ------------------------------------------------------------------ */
86 public static void main(String argv
[]) throws java
.lang
.Exception
88 ValueBinding aSample
= new ValueBinding();