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 integration.forms; 24 25 import com.sun.star.uno.UnoRuntime; 26 27 import com.sun.star.lang.XMultiServiceFactory; 28 import com.sun.star.beans.XPropertySet; 29 import com.sun.star.text.XTextDocument; 30 import com.sun.star.text.XText; 31 import com.sun.star.text.XTextTable; 32 import com.sun.star.text.XTextCursor; 33 import com.sun.star.form.binding.XValueBinding; 34 import com.sun.star.form.binding.XBindableValue; 35 36 import integration.forms.DocumentHelper; 37 import integration.forms.TableCellTextBinding; 38 39 public class ValueBinding extends integration.forms.TestCase 40 { 41 /** Creates a new instance of ValueBinding */ ValueBinding()42 public ValueBinding() 43 { 44 super( DocumentType.WRITER ); 45 } 46 isInteractiveTest()47 public static boolean isInteractiveTest() 48 { 49 return true; 50 } 51 52 /* ------------------------------------------------------------------ */ getTestMethodNames()53 public String[] getTestMethodNames() 54 { 55 return new String[] { 56 "checkBindingProperties" 57 }; 58 } 59 60 /* ------------------------------------------------------------------ */ getTestObjectName()61 public String getTestObjectName() 62 { 63 return "Form Control Value Binding Test"; 64 } 65 66 /* ------------------------------------------------------------------ */ before()67 public void before() throws com.sun.star.uno.Exception, java.lang.Exception 68 { 69 super.before(); 70 prepareDocument(); 71 } 72 73 /* ------------------------------------------------------------------ */ after()74 public void after() throws com.sun.star.uno.Exception, java.lang.Exception 75 { 76 super.waitForUserInput(); 77 super.closeDocument(); 78 } 79 80 /* ------------------------------------------------------------------ */ checkBindingProperties()81 public void checkBindingProperties() throws com.sun.star.uno.Exception, java.lang.Exception 82 { 83 } 84 85 /* ------------------------------------------------------------------ */ prepareDocument()86 protected void prepareDocument() throws com.sun.star.uno.Exception, java.lang.Exception 87 { 88 super.prepareDocument(); 89 90 // insert a table with exactly one cell. The content of this table will be synced with 91 // the content of a form control 92 XTextDocument textDoc = (XTextDocument)UnoRuntime.queryInterface( XTextDocument.class, m_document.getDocument() ); 93 XText documentText = textDoc.getText(); 94 XTextCursor textCursor = documentText.createTextCursor(); 95 96 XTextTable table = (XTextTable)UnoRuntime.queryInterface( XTextTable.class, 97 m_document.createInstance( "com.sun.star.text.TextTable" ) 98 ); 99 table.initialize( 1, 1 ); 100 documentText.insertTextContent( textCursor, table, false ); 101 102 // insert our sample control 103 XPropertySet textControl = m_formLayer.insertControlLine( "DatabaseTextField", "Test", "", 10 ); 104 105 // create a value binding for the first cell of the table 106 XValueBinding cellBinding = new TableCellTextBinding( table.getCellByName( "A1" ) ); 107 // and bind it to the control 108 XBindableValue bindable = (XBindableValue)UnoRuntime.queryInterface( 109 XBindableValue.class, textControl 110 ); 111 bindable.setValueBinding( cellBinding ); 112 113 // toggle the view to alive mode 114 m_document.getCurrentView( ).toggleFormDesignMode( ); 115 } 116 } 117