2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import com
.sun
.star
.uno
.UnoRuntime
;
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import com
.sun
.star
.text
.XTextDocument
;
23 import com
.sun
.star
.text
.XText
;
24 import com
.sun
.star
.text
.XTextTable
;
25 import com
.sun
.star
.text
.XTextCursor
;
26 import com
.sun
.star
.form
.binding
.XValueBinding
;
27 import com
.sun
.star
.form
.binding
.XBindableValue
;
29 public class ValueBinding
extends DocumentBasedExample
31 /** Creates a new instance of ValueBinding */
34 super( DocumentType
.WRITER
);
37 /* ------------------------------------------------------------------ */
39 protected void prepareDocument() throws com
.sun
.star
.uno
.Exception
, java
.lang
.Exception
41 super.prepareDocument();
43 // insert a table with exactly one cell. The content of this table will be synced with
44 // the content of a form control
45 XTextDocument textDoc
= UnoRuntime
.queryInterface( XTextDocument
.class, m_document
.getDocument() );
46 XText documentText
= textDoc
.getText();
47 XTextCursor textCursor
= documentText
.createTextCursor();
48 documentText
.insertString( textCursor
, "Below, there's a table cell, and a text field. ", false );
49 documentText
.insertString( textCursor
, "Both are linked via an external value binding.\n", false );
50 documentText
.insertString( textCursor
, "That means that anything you insert into the table cell is reflected in the ", false );
51 documentText
.insertString( textCursor
, "text field, and vice versa.\n", false );
53 XTextTable table
= UnoRuntime
.queryInterface( XTextTable
.class,
54 m_document
.createInstance( "com.sun.star.text.TextTable" )
56 table
.initialize( 1, 1 );
57 documentText
.insertTextContent( textCursor
, table
, false );
59 // insert our sample control
60 XPropertySet textControl
= m_formLayer
.insertControlLine( "DatabaseTextField", "enter some text", "", 30 );
62 // create a value binding for the first cell of the table
63 XValueBinding cellBinding
= new TableCellTextBinding( table
.getCellByName( "A1" ) );
64 // and bind it to the control
65 XBindableValue bindable
= UnoRuntime
.queryInterface(
66 XBindableValue
.class, textControl
68 bindable
.setValueBinding( cellBinding
);
71 /* ------------------------------------------------------------------ */
74 public static void main(String argv
[]) throws java
.lang
.Exception
76 ValueBinding aSample
= new ValueBinding();