Bump version to 6.4-15
[LibreOffice.git] / odk / examples / DevelopersGuide / Forms / ValueBinding.java
blob273f04cdade55f821507bbc73634928491404de3
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.UnoRuntime;
22 import com.sun.star.beans.XPropertySet;
23 import com.sun.star.text.XTextDocument;
24 import com.sun.star.text.XText;
25 import com.sun.star.text.XTextTable;
26 import com.sun.star.text.XTextCursor;
27 import com.sun.star.form.binding.XValueBinding;
28 import com.sun.star.form.binding.XBindableValue;
30 public class ValueBinding extends DocumentBasedExample
32 /** Creates a new instance of ValueBinding */
33 public ValueBinding()
35 super( DocumentType.WRITER );
38 /* ------------------------------------------------------------------ */
39 @Override
40 protected void prepareDocument() throws com.sun.star.uno.Exception, java.lang.Exception
42 super.prepareDocument();
44 // insert a table with exactly one cell. The content of this table will be synced with
45 // the content of a form control
46 XTextDocument textDoc = UnoRuntime.queryInterface( XTextDocument.class, m_document.getDocument() );
47 XText documentText = textDoc.getText();
48 XTextCursor textCursor = documentText.createTextCursor();
49 documentText.insertString( textCursor, "Below, there's a table cell, and a text field. ", false );
50 documentText.insertString( textCursor, "Both are linked via an external value binding.\n", false );
51 documentText.insertString( textCursor, "That means that anything you insert into the table cell is reflected in the ", false );
52 documentText.insertString( textCursor, "text field, and vice versa.\n", false );
54 XTextTable table = UnoRuntime.queryInterface( XTextTable.class,
55 m_document.createInstance( "com.sun.star.text.TextTable" )
57 table.initialize( 1, 1 );
58 documentText.insertTextContent( textCursor, table, false );
60 // insert our sample control
61 XPropertySet textControl = m_formLayer.insertControlLine( "DatabaseTextField", "enter some text", "", 30 );
63 // create a value binding for the first cell of the table
64 XValueBinding cellBinding = new TableCellTextBinding( table.getCellByName( "A1" ) );
65 // and bind it to the control
66 XBindableValue bindable = UnoRuntime.queryInterface(
67 XBindableValue.class, textControl
69 bindable.setValueBinding( cellBinding );
72 /* ------------------------------------------------------------------ */
73 /** class entry point
75 public static void main(String argv[]) throws java.lang.Exception
77 ValueBinding aSample = new ValueBinding();
78 aSample.run( argv );
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */