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 * CellBinding.java 24 * 25 * Created on 12. Mai 2004, 15:15 26 */ 27 28 package integration.forms; 29 30 import com.sun.star.uno.*; 31 import com.sun.star.util.*; 32 import com.sun.star.lang.*; 33 import com.sun.star.beans.*; 34 import com.sun.star.form.binding.*; 35 import com.sun.star.accessibility.*; 36 import com.sun.star.awt.XListBox; 37 import com.sun.star.table.CellAddress; 38 import com.sun.star.table.XCell; 39 import com.sun.star.sheet.XCellRangeData; 40 import com.sun.star.sheet.XCellRangeFormula; 41 import com.sun.star.table.CellRangeAddress; 42 import com.sun.star.text.XTextRange; 43 44 import org.junit.After; 45 import org.junit.AfterClass; 46 import org.junit.Before; 47 import org.junit.BeforeClass; 48 import org.junit.Test; 49 import static org.junit.Assert.*; 50 import org.openoffice.test.OfficeConnection; 51 52 /** 53 * 54 * @author fs93730 55 */ 56 public class CellBinding 57 { 58 private static final OfficeConnection officeConnection = new OfficeConnection(); 59 /** the test document our form layer lives in */ 60 private SpreadsheetDocument m_document; 61 /** our form layer */ 62 private FormLayer m_formLayer; 63 /** our service factory */ 64 private XMultiServiceFactory m_orb; 65 66 @BeforeClass beforeClass()67 public static void beforeClass() throws java.lang.Exception 68 { 69 officeConnection.setUp(); 70 } 71 72 @AfterClass afterClass()73 public static void afterClass() throws java.lang.Exception 74 { 75 officeConnection.tearDown(); 76 } 77 78 /** Creates a new instance of CellBinding */ CellBinding()79 public CellBinding() 80 { 81 } 82 83 /* ------------------------------------------------------------------ */ 84 /** closes our document, if we have an open one 85 */ closeDocument()86 private void closeDocument() 87 { 88 try 89 { 90 // close our document 91 if ( m_document != null ) 92 { 93 XCloseable closeDoc = (XCloseable)UnoRuntime.queryInterface( XCloseable.class, 94 m_document.getDocument() ); 95 closeDoc.close( true ); 96 } 97 } 98 catch ( com.sun.star.uno.Exception e ) 99 { 100 } 101 } 102 103 /* ------------------------------------------------------------------ */ 104 @Before before()105 public void before() throws com.sun.star.uno.Exception, java.lang.Exception 106 { 107 m_orb = UnoRuntime.queryInterface(XMultiServiceFactory.class, officeConnection.getComponentContext().getServiceManager()); 108 m_document = new SpreadsheetDocument( m_orb ); 109 m_formLayer = new FormLayer( m_document ); 110 } 111 112 /* ------------------------------------------------------------------ */ 113 @After after()114 public void after() throws com.sun.star.uno.Exception, java.lang.Exception 115 { 116 closeDocument(); 117 } 118 119 /* ------------------------------------------------------------------ */ 120 @Test checkTextFieldBinding( )121 public void checkTextFieldBinding( ) throws com.sun.star.uno.Exception, java.lang.Exception 122 { 123 final short col = 0; 124 final short row = 2; 125 final String text = new String( "content" ); 126 final String otherText = new String( "something else" ); 127 final String yetAnotherText = new String( "yet another text" ); 128 129 // cretae a normal text control 130 XPropertySet controlModel = m_formLayer.createControlAndShape( "DatabaseTextField", 30, 9, 30, 6 ); 131 132 // bind it to cell A1 133 bindToCell( controlModel, col, row ); 134 135 // switch to alive mode 136 m_document.getCurrentView().toggleFormDesignMode(); 137 138 // test the data transfer control -> cell 139 simulateUserTextInput( controlModel, text ); 140 verifyStringCellContent( col, row, text, "A text field does not forward its user input to the cell." ); 141 142 // the same, but this time changing the control value programmatically 143 controlModel.setPropertyValue( "Text", otherText ); 144 verifyStringCellContent( col, row, otherText, "A text field does not forward programmatic changes to the cell." ); 145 146 // the other way round: cell->control 147 setCellText( col, row, yetAnotherText ); 148 String controlText = (String)controlModel.getPropertyValue( "Text" ); 149 if ( !controlText.equals( yetAnotherText ) ) 150 fail( "Changes in the cell are not forwarded to the text field." ); 151 } 152 /* ------------------------------------------------------------------ */ 153 @Test checkBooleanRadioBinding( )154 public void checkBooleanRadioBinding( ) throws com.sun.star.uno.Exception, java.lang.Exception 155 { 156 // two radio buttons 157 XPropertySet primaryRadio = createRadio( 28, "radio button no. 1", "radio group", "primary" ); 158 XPropertySet secondaryRadio = createRadio( 33, "radio button no. 2", "radio group", "secodary" ); 159 160 // bind them 161 short col = (short)0; 162 short row1 = (short)6; 163 short row2 = (short)7; 164 bindToCell( primaryRadio, col, row1 ); 165 bindToCell( secondaryRadio, col, row2 ); 166 167 // check the first button 168 simulateUserRadioCheck( primaryRadio ); 169 // check the cell content 170 verifyNumericCellContent( col, row1, 1, "Radio buttons do not forward their (boolean) values to cells (1)." ); 171 verifyNumericCellContent( col, row2, 0, "Radio buttons do not forward their (boolean) values to cells (2)." ); 172 // check the second button 173 simulateUserRadioCheck( secondaryRadio ); 174 // check the cell content 175 verifyNumericCellContent( col, row1, 0, "Radio buttons do not forward their (boolean) values to cells (3)." ); 176 verifyNumericCellContent( col, row2, 1, "Radio buttons do not forward their (boolean) values to cells (4)." ); 177 178 // the other way round: writing values into the cell 179 setCellValue( col, row1, 1.0 ); 180 // setting this should have checked the primary radio, which should have unchecked the secondary radio, 181 // which should have been propagated to the second cell 182 verifyNumericCellContent( col, row2, 0, "Changing primary cell is not propagated to the secondary cell (via the radio buttons)." ); 183 184 // setting an empty cell should result in the radio being unchecked 185 setCellEmpty( col, row1 ); 186 if ( ((Short)primaryRadio.getPropertyValue( "State" )).shortValue() != 0 ) 187 fail( "Setting a cell to 'empty' does not reset the bound radio button." ); 188 } 189 190 /* ------------------------------------------------------------------ */ 191 @Test checkStringRadioBinding( )192 public void checkStringRadioBinding( ) throws com.sun.star.uno.Exception, java.lang.Exception 193 { 194 // two radio buttons 195 XPropertySet primaryRadio = createRadio( 46, "radio button A", "radio ref group", "primary" ); 196 XPropertySet secondaryRadio = createRadio( 51, "radio button B", "radio ref group", "secodary" ); 197 198 // give the ref values 199 String refValueA = new String( "ref value A" ); 200 String refValueB = new String( "ref value B" ); 201 primaryRadio.setPropertyValue( "RefValue", refValueA ); 202 secondaryRadio.setPropertyValue( "RefValue", refValueB ); 203 204 // bind them to the same cell 205 short col = (short)0; 206 short row = (short)10; 207 bindToCell( primaryRadio, col, row ); 208 bindToCell( secondaryRadio, col, row ); 209 210 // checking a radio should set the respective ref value at the cell 211 simulateUserRadioCheck( primaryRadio ); 212 verifyStringCellContent( col, row, refValueA, "A bound radio button with a reference value does not pass this value to the cell upon checking (1)." ); 213 simulateUserRadioCheck( secondaryRadio ); 214 verifyStringCellContent( col, row, refValueB, "A bound radio button with a reference value does not pass this value to the cell upon checking (2)." ); 215 216 // changing the cell should check the buttons if the cell text equals the ref value 217 setCellText( col, row, "no ref value" ); 218 verifyRadioStates( primaryRadio, secondaryRadio, (short)0, (short)0, "Radio button not unchecked, though the bound cell value does not equal ref value." ); 219 220 setCellText( col, row, refValueA ); 221 verifyRadioStates( primaryRadio, secondaryRadio, (short)1, (short)0, "Radio button not properly un/checked according to the cell and ref value (1)." ); 222 223 setCellText( col, row, refValueB ); 224 verifyRadioStates( primaryRadio, secondaryRadio, (short)0, (short)1, "Radio button not properly un/checked according to the cell and ref value (2)." ); 225 } 226 227 /* ------------------------------------------------------------------ */ 228 @Test checkBooleanCheckBoxBinding( )229 public void checkBooleanCheckBoxBinding( ) throws com.sun.star.uno.Exception, java.lang.Exception 230 { 231 XPropertySet checkBox = m_formLayer.createControlAndShape( "DatabaseCheckBox", 30, 59, 40, 4 ); 232 checkBox.setPropertyValue( "Label", "check box" ); 233 checkBox.setPropertyValue( "TriState", new Boolean( true ) ); 234 235 short col = (short)0; 236 short row = (short)13; 237 bindToCell( checkBox, col, row ); 238 239 // initialize with "not checked" 240 checkBox.setPropertyValue( "State", new Short( (short)0 ) ); 241 verifyNumericCellContent( col, row, 0, "programmatically unchecking the check box is not propagated to the cell." ); 242 243 // first click: "not checked" -> "checked" 244 simulateUserCheckBoxCheck( checkBox, (short)1 ); 245 verifyNumericCellContent( col, row, 1, "moving the check box state to 'checked' is not propagated to the cell." ); 246 247 // second click: "checked" -> "indetermined" 248 simulateUserCheckBoxCheck( checkBox, (short)2 ); 249 verifyVoidCell( col, row, "propagating the 'indetermined' state to the cell does not work." ); 250 251 // third click: "indetermined" -> "not checked" 252 simulateUserCheckBoxCheck( checkBox, (short)0 ); 253 verifyNumericCellContent( col, row, 0, "unchecking a check box via UI is not propagated to the cell." ); 254 } 255 256 /* ------------------------------------------------------------------ */ 257 @Test checkStringCheckBoxBinding( )258 public void checkStringCheckBoxBinding( ) throws com.sun.star.uno.Exception, java.lang.Exception 259 { 260 String refValue = new String( "checked " ); 261 262 XPropertySet checkBox = m_formLayer.createControlAndShape( "DatabaseCheckBox", 30, 68, 40, 4 ); 263 checkBox.setPropertyValue( "Label", "check box with ref value" ); 264 checkBox.setPropertyValue( "TriState", new Boolean( true ) ); 265 checkBox.setPropertyValue( "RefValue", refValue ); 266 267 short col = (short)0; 268 short row = (short)15; 269 bindToCell( checkBox, col, row ); 270 271 // initialize with "not checked" 272 checkBox.setPropertyValue( "State", new Short( (short)0 ) ); 273 verifyNumericCellContent( col, row, 0, "programmatically unchecking the check box is not propagated to the cell." ); 274 275 // first click: "not checked" -> "checked" 276 simulateUserCheckBoxCheck( checkBox, (short)1 ); 277 verifyStringCellContent( col, row, refValue, "moving the check box state to 'checked' does not propagated the ref value to the cell." ); 278 279 // second click: "checked" -> "indetermined" 280 simulateUserCheckBoxCheck( checkBox, (short)2 ); 281 verifyVoidCell( col, row, "propagating the 'indetermined' state to the cell does not work, when exchanging ref values." ); 282 283 // third click: "indetermined" -> "not checked" 284 simulateUserCheckBoxCheck( checkBox, (short)0 ); 285 verifyStringCellContent( col, row, "", "unchecking a check box via UI does not propagated the ref value to the cell." ); 286 } 287 288 /* ------------------------------------------------------------------ */ 289 /** verifies that a list box, which is bound via an ordinary value binding, 290 * works as expected 291 */ 292 @Test checkListBoxBinding( )293 public void checkListBoxBinding( ) throws com.sun.star.uno.Exception, java.lang.Exception 294 { 295 XPropertySet listBox = m_formLayer.createControlAndShape( "DatabaseListBox", 30, 80, 40, 6 ); 296 listBox.setPropertyValue( "Dropdown", new Boolean( true ) ); 297 listBox.setPropertyValue( "StringItemList", new String[] { "Apples", "Oranges", "Peaches" } ); 298 299 short col = (short)0; 300 short row = (short)18; 301 302 // ............................................................... 303 // add a list entry source which fills the list boxes list from cells in the 304 // spreadsheet 305 short sourceCol = (short)4; 306 setCellText( sourceCol, (short)( row - 1 ), "Apples" ); 307 setCellText( sourceCol, (short)( row + 0 ), "Oranges" ); 308 setCellText( sourceCol, (short)( row + 1 ), "Peaches" ); 309 310 //setListSource( listBox, sourceCol, row, (short)( row + 2 ) ); 311 // TODO: this is currently prone to deadlocks 312 313 // ............................................................... 314 // bind to a cell 315 bindToCell( listBox, col, row ); 316 317 // ............................................................... 318 // do the tests 319 listBox.setPropertyValue( "SelectedItems", new short[] { (short)0 } ); 320 verifyStringCellContent( col, row, "Apples", "programmatically selecting a list entry is not propagated to the cell." ); 321 322 simulateUserListBoxSelection( listBox, "Oranges" ); 323 verifyStringCellContent( col, row, "Oranges", "UI-selecting a list entry is not propagated to the cell." ); 324 325 setCellText( col, row, "Peaches" ); 326 short[] selectedItems = (short[])listBox.getPropertyValue( "SelectedItems" ); 327 assertEquals( "changes in the cell bound to a list box are not propagated to the list box selection", 328 2, selectedItems[0] ); 329 } 330 331 /* ------------------------------------------------------------------ */ 332 /** verifies that a list box, which is bound via a value binding exchanging the <b>index</b> 333 * of the selected entry, works as expected 334 */ 335 @Test checkListBoxIndexBinding()336 public void checkListBoxIndexBinding() throws com.sun.star.uno.Exception, java.lang.Exception 337 { 338 XPropertySet listBox = m_formLayer.createControlAndShape( "DatabaseListBox", 30, 94, 40, 6 ); 339 listBox.setPropertyValue( "Dropdown", new Boolean( true ) ); 340 listBox.setPropertyValue( "StringItemList", new String[] { "Pears", "Bananas", "Strawberries" } ); 341 342 short col = (short)0; 343 short row = (short)21; 344 345 // ............................................................... 346 // add a list entry source which fills the list boxes list from cells in the 347 // spreadsheet 348 short sourceCol = (short)4; 349 setCellText( sourceCol, (short)( row - 1 ), "Pears" ); 350 setCellText( sourceCol, (short)( row + 0 ), "Bananas" ); 351 setCellText( sourceCol, (short)( row + 1 ), "Strawberries" ); 352 353 //setListSource( listBox, sourceCol, row, (short)( row + 2 ) ); 354 // TODO: this is currently prone to deadlocks 355 356 // ............................................................... 357 // bind to a cell 358 bindToCell( listBox, col, row, "com.sun.star.table.ListPositionCellBinding" ); 359 360 // ............................................................... 361 // do the tests 362 listBox.setPropertyValue( "SelectedItems", new short[] { (short)0 } ); 363 verifyNumericCellContent( col, row, 1, "programmatically selecting a list entry is not propagated (as index) to the cell." ); 364 365 simulateUserListBoxSelection( listBox, "Bananas" ); 366 verifyNumericCellContent( col, row, 2, "UI-selecting a list entry is not propagated (as index) to the cell." ); 367 368 setCellValue( col, row, 3 ); 369 short[] selectedItems = (short[])listBox.getPropertyValue( "SelectedItems" ); 370 assertEquals( "changes in the cell bound to a list box via list index are not propagated to the list box selection", 371 2, selectedItems[0] ); 372 } 373 374 /* ------------------------------------------------------------------ */ 375 /** verifies that the content of a given cell equals a given string 376 */ createRadio( int yPos, String label, String name, String tag )377 private XPropertySet createRadio( int yPos, String label, String name, String tag ) throws com.sun.star.uno.Exception, java.lang.Exception 378 { 379 XPropertySet radio = m_formLayer.createControlAndShape( "DatabaseRadioButton", 30, yPos, 40, 4 ); 380 radio.setPropertyValue( "Label", label ); 381 radio.setPropertyValue( "Name", name ); 382 radio.setPropertyValue( "Tag", tag ); 383 return radio; 384 } 385 386 /* ------------------------------------------------------------------ */ 387 /** verifies the states of two radio button 388 */ verifyRadioStates( XPropertySet radio1, XPropertySet radio2, short value1, short value2, String errorMessage )389 private boolean verifyRadioStates( XPropertySet radio1, XPropertySet radio2, short value1, short value2, 390 String errorMessage ) throws com.sun.star.uno.Exception, java.lang.Exception 391 { 392 if ( ( ((Short)radio1.getPropertyValue( "State" )).shortValue() != value1 ) 393 || ( ((Short)radio2.getPropertyValue( "State" )).shortValue() != value2 ) 394 ) 395 { 396 fail( errorMessage ); 397 return false; 398 } 399 return true; 400 } 401 402 /* ------------------------------------------------------------------ */ 403 /** verifies that the content of a given cell equals a given string 404 */ verifyVoidCell( short col, short row, String failErrorMessage )405 private boolean verifyVoidCell( short col, short row, String failErrorMessage ) throws com.sun.star.uno.Exception 406 { 407 XCellRangeData cell = (XCellRangeData)UnoRuntime.queryInterface( XCellRangeData.class, 408 m_document.getSheet( 0 ).getCellByPosition( col, row ) 409 ); 410 Object cellContent = cell.getDataArray()[0][0]; 411 if ( ((com.sun.star.uno.Any)cellContent).getType().getTypeClass() != com.sun.star.uno.TypeClass.VOID ) 412 { 413 fail( failErrorMessage ); 414 return false; 415 } 416 return true; 417 } 418 419 /* ------------------------------------------------------------------ */ 420 /** verifies that the content of a given cell equals a given string 421 */ verifyNumericCellContent( short col, short row, double value, String failErrorMessage )422 private boolean verifyNumericCellContent( short col, short row, double value, String failErrorMessage ) throws com.sun.star.uno.Exception 423 { 424 XCell cell = (XCell)UnoRuntime.queryInterface( XCell.class, 425 m_document.getSheet( 0 ).getCellByPosition( col, row ) 426 ); 427 if ( cell.getValue() != value ) 428 { 429 fail( failErrorMessage ); 430 return false; 431 } 432 return true; 433 } 434 435 /* ------------------------------------------------------------------ */ 436 /** verifies that the content of a given cell equals a given string 437 */ verifyStringCellContent( short col, short row, String text, String failErrorMessage )438 private boolean verifyStringCellContent( short col, short row, String text, String failErrorMessage ) throws com.sun.star.uno.Exception 439 { 440 XTextRange cell = (XTextRange)UnoRuntime.queryInterface( XTextRange.class, 441 m_document.getSheet( 0 ).getCellByPosition( col, row ) 442 ); 443 if ( !cell.getString().equals( text ) ) 444 { 445 fail( failErrorMessage ); 446 return false; 447 } 448 return true; 449 } 450 451 /* ------------------------------------------------------------------ */ 452 /** sets the text of a given cell to a given string 453 */ setCellText( short col, short row, String text )454 private void setCellText( short col, short row, String text ) throws com.sun.star.uno.Exception 455 { 456 XTextRange cell = (XTextRange)UnoRuntime.queryInterface( XTextRange.class, 457 m_document.getSheet( 0 ).getCellByPosition( col, row ) 458 ); 459 cell.setString( text ); 460 } 461 462 /* ------------------------------------------------------------------ */ 463 /** sets a numeric value in a given cell 464 */ setCellValue( short col, short row, double value )465 private void setCellValue( short col, short row, double value ) throws com.sun.star.uno.Exception 466 { 467 XCell cell = (XCell)UnoRuntime.queryInterface( XCell.class, 468 m_document.getSheet( 0 ).getCellByPosition( col, row ) 469 ); 470 cell.setValue( value ); 471 } 472 473 /* ------------------------------------------------------------------ */ 474 /** sets a numeric value in a given cell 475 */ setCellEmpty( short col, short row )476 private void setCellEmpty( short col, short row ) throws com.sun.star.uno.Exception 477 { 478 // as long as #i29130# is not fixed, we do not set the cell to "empty", but to 479 // an invalid formular, which serves well for our purpose 480 XCellRangeFormula cell = (XCellRangeFormula)UnoRuntime.queryInterface( XCellRangeFormula.class, 481 m_document.getSheet( 0 ).getCellByPosition( col, row ) 482 ); 483 String[][] args = new String[][] { new String[] { "=INVALID_FUNCTION()" } }; 484 cell.setFormulaArray( args ); 485 } 486 487 /* ------------------------------------------------------------------ */ 488 /** binds the given control model to the given cell in the first sheet, 489 * using the given service name for the binding 490 */ bindToCell( XPropertySet controlModel, short column, short row, String _bindingServiceName )491 private void bindToCell( XPropertySet controlModel, short column, short row, String _bindingServiceName ) throws com.sun.star.uno.Exception 492 { 493 XBindableValue bindableModel = (XBindableValue)UnoRuntime.queryInterface( XBindableValue.class, 494 controlModel 495 ); 496 497 CellAddress address = new CellAddress(); 498 address.Column = column; 499 address.Row = row; 500 address.Sheet = 0; 501 502 NamedValue[] parameters = new NamedValue[] { new NamedValue() }; 503 parameters[0].Name = "BoundCell"; 504 parameters[0].Value = address; 505 506 XValueBinding cellBinding = (XValueBinding)UnoRuntime.queryInterface( XValueBinding.class, 507 m_document.createInstanceWithArguments( _bindingServiceName, parameters ) 508 ); 509 510 bindableModel.setValueBinding( cellBinding ); 511 } 512 513 /* ------------------------------------------------------------------ */ 514 /** binds the given control model to the given cell in the first sheet 515 */ bindToCell( XPropertySet _controlModel, short _column, short _row )516 private void bindToCell( XPropertySet _controlModel, short _column, short _row ) throws com.sun.star.uno.Exception 517 { 518 bindToCell( _controlModel, _column, _row, "com.sun.star.table.CellValueBinding" ); 519 } 520 521 /* ------------------------------------------------------------------ */ 522 /** sets the given cell range as list entry source for the given control 523 */ setListSource( XPropertySet _listSink, short _sourceCol, short _rowStart, short _rowEnd )524 private void setListSource( XPropertySet _listSink, short _sourceCol, short _rowStart, short _rowEnd ) throws com.sun.star.uno.Exception 525 { 526 CellRangeAddress listSourceAddress = new CellRangeAddress( (short)0, (int)_sourceCol, (int)_rowStart, (int)_sourceCol, (int)_rowEnd ); 527 NamedValue addressParameter = new NamedValue( "CellRange", listSourceAddress ); 528 529 XListEntrySource listSource = (XListEntrySource)UnoRuntime.queryInterface( XListEntrySource.class, 530 m_document.createInstanceWithArguments( "com.sun.star.table.CellRangeListSource", new NamedValue[]{ addressParameter } ) 531 ); 532 XListEntrySink listSink = (XListEntrySink)UnoRuntime.queryInterface( XListEntrySink.class, 533 _listSink ); 534 listSink.setListEntrySource( listSource ); 535 } 536 537 /* ------------------------------------------------------------------ */ 538 /** simulates a user action to check a radio button 539 */ simulateUserRadioCheck( XPropertySet radioModel )540 private void simulateUserRadioCheck( XPropertySet radioModel ) throws com.sun.star.uno.Exception 541 { 542 XAccessible accessible = (XAccessible)UnoRuntime.queryInterface( 543 XAccessible.class, m_document.getCurrentView().getControl( radioModel ) ); 544 545 XAccessibleValue xValue = (XAccessibleValue)UnoRuntime.queryInterface( 546 XAccessibleValue.class, accessible.getAccessibleContext() ); 547 548 Integer newValue = new Integer( 1 ); 549 xValue.setCurrentValue( newValue ); 550 } 551 552 /* ------------------------------------------------------------------ */ 553 /** simulates a user action to check a radio button 554 */ simulateUserCheckBoxCheck( XPropertySet checkBox, short state )555 private void simulateUserCheckBoxCheck( XPropertySet checkBox, short state ) throws com.sun.star.uno.Exception 556 { 557 XAccessible accessible = (XAccessible)UnoRuntime.queryInterface( 558 XAccessible.class, m_document.getCurrentView().getControl( checkBox ) ); 559 560 XAccessibleValue xValue = (XAccessibleValue)UnoRuntime.queryInterface( 561 XAccessibleValue.class, accessible.getAccessibleContext() ); 562 563 xValue.setCurrentValue( new Short( state ) ); 564 } 565 566 /* ------------------------------------------------------------------ */ 567 /** simulates a user selecting an entry in a list box 568 */ simulateUserListBoxSelection( XPropertySet _listBox, String _selectEntry )569 private void simulateUserListBoxSelection( XPropertySet _listBox, String _selectEntry ) throws com.sun.star.uno.Exception 570 { 571 XListBox listBoxControl = (XListBox)UnoRuntime.queryInterface( 572 XListBox.class, m_document.getCurrentView().getControl( _listBox ) ); 573 listBoxControl.selectItem( _selectEntry, true ); 574 } 575 576 /* ------------------------------------------------------------------ */ 577 /** simulates text input into the control belonging to the given model 578 */ simulateUserTextInput( XPropertySet controlModel, String text )579 private void simulateUserTextInput( XPropertySet controlModel, String text ) throws com.sun.star.uno.Exception 580 { 581 XAccessible accessible = (XAccessible)UnoRuntime.queryInterface( 582 XAccessible.class, m_document.getCurrentView().getControl( controlModel ) ); 583 584 XAccessibleContext context = accessible.getAccessibleContext(); 585 XServiceInfo si = (XServiceInfo)UnoRuntime.queryInterface( XServiceInfo.class, 586 accessible.getAccessibleContext() ); 587 588 XAccessibleEditableText textAccess = (XAccessibleEditableText)UnoRuntime.queryInterface( 589 XAccessibleEditableText.class, accessible.getAccessibleContext() ); 590 591 textAccess.setText( text ); 592 } 593 } 594