summaryrefslogtreecommitdiff
path: root/qadevOOo/runner/util/UITools.java
blob: c97c6d47c0089da21a264b01f0cf17cf1a54a120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

package util;

import java.awt.Robot;
import java.awt.event.InputEvent;
import java.io.PrintWriter;
import java.util.ArrayList;

import com.sun.star.accessibility.AccessibleRole;
import com.sun.star.accessibility.XAccessible;
import com.sun.star.accessibility.XAccessibleAction;
import com.sun.star.accessibility.XAccessibleComponent;
import com.sun.star.accessibility.XAccessibleContext;
import com.sun.star.accessibility.XAccessibleEditableText;
import com.sun.star.accessibility.XAccessibleSelection;
import com.sun.star.accessibility.XAccessibleText;
import com.sun.star.accessibility.XAccessibleValue;
import com.sun.star.awt.XExtendedToolkit;
import com.sun.star.awt.XTopWindow;
import com.sun.star.awt.XWindow;
import com.sun.star.frame.XModel;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;


/**
 * This class supports some functions to handle easily accessible objects
 */
public class UITools {

    private final XAccessible mXRoot;
    private final XMultiServiceFactory mMSF;

    public UITools(XMultiServiceFactory msf, XModel xModel)
    {
        mMSF = msf;
        mXRoot = makeRoot(xModel);
    }

    public UITools(XMultiServiceFactory msf, XTextDocument xTextDoc)
    {
        mMSF = msf;
        XModel xModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
        mXRoot = makeRoot(xModel);
    }

    public UITools(XMultiServiceFactory msf, XWindow xWindow)
    {
        mMSF = msf;
        mXRoot = makeRoot(xWindow);
    }

    private static XAccessible makeRoot(XModel aModel)
    {
        XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
        return AccessibilityTools.getAccessibleObject(xWindow);
    }


    private static String getString(XInterface xInt)
    {
        XAccessibleText oText = UnoRuntime.queryInterface(XAccessibleText.class, xInt);
        return oText.getText();
    }

    private static void setString(XInterface xInt, String cText)
    {
        XAccessibleEditableText oText = UnoRuntime.queryInterface(XAccessibleEditableText.class, xInt);

        oText.setText(cText);
    }

    private static Object getValue(XInterface xInt)
    {
         XAccessibleValue oValue = UnoRuntime.queryInterface(XAccessibleValue.class, xInt);
         return oValue.getCurrentValue();
    }

    private static XAccessible makeRoot(XWindow xWindow)
    {
        return AccessibilityTools.getAccessibleObject(xWindow);
    }

    /**
     * get the root element of the accessible tree
     * @return the root element
     */
    public XAccessible getRoot()
    {
        return mXRoot;
    }

    /**
     * Helper mathod: set a text into AccessibleEdit field
     * @param textfiledName is the name of the text field
     * @param stringToSet is the string to set
     * @throws java.lang.Exception if something fail
     */
    public void setTextEditFiledText(String textfiledName, String stringToSet)
                        throws java.lang.Exception
    {
        XInterface oTextField = AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                            AccessibleRole.TEXT, textfiledName);
        setString(oTextField, stringToSet);
    }

    /**
     * returns the button by the given name
     * @param buttonName is name name of the button to get
     * @return a XAccessibleContext of the button
     * @throws java.lang.Exception if something fail
     */
    public XAccessibleContext getButton(String buttonName) throws java.lang.Exception
    {
        return AccessibilityTools.getAccessibleObjectForRole
                                (mXRoot, AccessibleRole.PUSH_BUTTON, buttonName);
    }

    /**
     * Helper method: gets button via accessibility and 'click' it</code>
     * @param buttonName is name name of the button to click
     * @throws java.lang.Exception if something fail
     */

     public void clickButton(String buttonName) throws java.lang.Exception
     {

        XAccessibleContext oButton =AccessibilityTools.getAccessibleObjectForRole
                                (mXRoot, AccessibleRole.PUSH_BUTTON, buttonName);
        if (oButton == null){
            throw new Exception("Could not get button '" + buttonName + "'");
        }
        XAccessibleAction oAction = UnoRuntime.queryInterface(XAccessibleAction.class, oButton);

        // "click" the button
        try{
            oAction.doAccessibleAction(0);
        } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
          throw new Exception("Could not do accessible action with '" +
                               buttonName + "'" + e.toString());
        }
     }



    /**
     * Helper method: gets button via accessibility and 'click' it
     *  @param buttonName   The name of the button in the accessibility tree
     *  @param toBePressed  desired state of the toggle button
     *
     *  @return true if the state of the button could be changed in the desired manner
     */
     private boolean clickToggleButton(String buttonName, boolean toBePressed)
     {
        XAccessibleContext oButton =AccessibilityTools.getAccessibleObjectForRole
                                (mXRoot, AccessibleRole.TOGGLE_BUTTON, buttonName);

        if (oButton != null){
            boolean isChecked = oButton.getAccessibleStateSet().contains(com.sun.star.accessibility.AccessibleStateType.CHECKED);
            if((isChecked && !toBePressed) || (!isChecked && toBePressed)){
                XAccessibleAction oAction = UnoRuntime.queryInterface(XAccessibleAction.class, oButton);
                try{
                    // "click" the button
                    oAction.doAccessibleAction(0);
                    return true;
                } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
                  System.out.println("Could not do accessible action with '"
                        + buttonName + "'" + e.toString());
                  return false;
                }
            }else
                //no need to press togglebar, do nothing
                return true;
        } else{
            System.out.println("Could not get button '" + buttonName + "'");
            return false;
        }
     }

    /**
     * Deactivates toggle button via Accessibility
     *  @param buttonName   The name of the button in the Accessibility tree
     *
     *  @return true if the button could be set to deactivated
     */
    public boolean deactivateToggleButton(String buttonName){
        return clickToggleButton(buttonName, false);
    }

    /**
     * Activates toggle button via Accessibility
     *  @param buttonName   The name of the button in the Accessibility tree
     *
     *  @return true if the button could be set to activated
     */
    public boolean activateToggleButton(String buttonName){
        return clickToggleButton(buttonName, true);
    }

     /**
      * returns the value of named radio button
      * @param buttonName the name of the button to get the value of
      * @throws java.lang.Exception if something fail
      * @return Integer
      */
     public Integer getRadioButtonValue(String buttonName)
            throws java.lang.Exception
     {
        try {
            XInterface xRB =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                       AccessibleRole.RADIO_BUTTON, buttonName);

            return (Integer) getValue(xRB);
        } catch (Exception e) {
          throw new Exception("Could not get value from RadioButton '"
                                          + buttonName + "' : " + e.toString());
        }
     }

     /**
      * returns the named graphic
      * @param GraphicName the name of the graphic
      * @return XInterface
      * @throws java.lang.Exception if something fail
      */
     public XInterface getGraphic(String GraphicName) throws java.lang.Exception
     {
        return AccessibilityTools.getAccessibleObjectForRole(mXRoot, AccessibleRole.GRAPHIC,
                                             GraphicName);
     }


     /**
      * set a named radio button the a given value
      * @param buttonName the name of the button to set
      * @param iValue the value to set
      * @throws java.lang.Exception if something fail
      */
     public void setRadioButtonValue(String buttonName, int iValue)
            throws java.lang.Exception
     {
        try {
            XInterface xRB =AccessibilityTools.getAccessibleObjectForRole(mXRoot, AccessibleRole.RADIO_BUTTON, buttonName);
            if(xRB == null)
                System.out.println("AccessibleObjectForRole couldn't be found for " + buttonName);
            XAccessibleValue oValue = UnoRuntime.queryInterface(XAccessibleValue.class, xRB);
            if(oValue == null)
                System.out.println("XAccessibleValue couldn't be queried for " + buttonName);
            oValue.setCurrentValue(new Integer(iValue));
        } catch (Exception e) {
          e.printStackTrace();

          throw new Exception("Could not set value to RadioButton '"
                                          + buttonName + "' : " + e.toString());
        }

     }

     /**
      * select an item in nanmed listbox
      * @param ListBoxName the name of the listbox
      * @param nChildIndex the index of the item to set
      * @throws java.lang.Exception if something fail
      */
     public void selectListboxItem(String ListBoxName, int nChildIndex)
            throws java.lang.Exception
     {
        try {
            XAccessibleContext xListBox = null;

            xListBox =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                         AccessibleRole.COMBO_BOX, ListBoxName);
            if (xListBox == null){
                xListBox =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                             AccessibleRole.PANEL, ListBoxName);
            }
            XAccessible xListBoxAccess = UnoRuntime.queryInterface(XAccessible.class, xListBox);

            // if a List is not pulled to be open all entries are not visiblle, therefore the
            // boolean argument
            XAccessibleContext xList =AccessibilityTools.getAccessibleObjectForRole(
                                          xListBoxAccess, AccessibleRole.LIST, true);
            XAccessibleSelection xListSelect = UnoRuntime.queryInterface(XAccessibleSelection.class, xList);

            xListSelect.selectAccessibleChild(nChildIndex);

        } catch (Exception e) {
          throw new Exception("Could not select item '" +nChildIndex+
                        "' in listbox '" + ListBoxName + "' : " + e.toString());
        }
     }

     /**
      * This method returns all entries as XInterface of a list box
      * @param ListBoxName the name of the listbox
      * @return Object[] containing XInterface
      * @throws java.lang.Exception if something fail
      */

     public Object[] getListBoxObjects(String ListBoxName)
            throws java.lang.Exception
     {
         ArrayList<XInterface> Items = new ArrayList<XInterface>();
         try {
            XAccessibleContext xListBox = null;
            XAccessibleContext xList = null;

            xListBox =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                         AccessibleRole.COMBO_BOX, ListBoxName);
            if (xListBox == null){
                xListBox =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                             AccessibleRole.PANEL, ListBoxName);
            }

            if (xListBox == null){
                // get the list of TreeListBox
                xList =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                              AccessibleRole.TREE, ListBoxName);

            // all other list boxes have a children of kind of LIST
            } else {

                XAccessible xListBoxAccess = UnoRuntime.queryInterface(XAccessible.class, xListBox);
                // if a List is not pulled to be open all entries are not visiblle, therefore the
                // boolean argument
                xList =AccessibilityTools.getAccessibleObjectForRole(
                                              xListBoxAccess, AccessibleRole.LIST, true);
            }

            for (int i=0;i<xList.getAccessibleChildCount();i++) {
                try {
                    XAccessible xChild = xList.getAccessibleChild(i);
                    XAccessibleContext xChildCont =
                                                  xChild.getAccessibleContext();
                    XInterface xChildInterface = UnoRuntime.queryInterface(XInterface.class, xChildCont);
                    Items.add(xChildInterface);

                } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
                      throw new Exception("Could not get child form list of '"
                                         + ListBoxName + "' : " + e.toString());
                }
            }

         } catch (Exception e) {
            throw new Exception("Could not get list of items from '"
                                         + ListBoxName + "' : " + e.toString());
        }
        Object[]ret = new XInterface[Items.size()];
        for (int i=0;i<Items.size();i++){
            ret[i] = Items.get(i);
        }
        return ret;
     }

     /**
      * Helper method: returns the entry manes of a List-Box
      * @param ListBoxName the name of the listbox
      * @return the listbox entry names
      * @throws java.lang.Exception if something fail
      */

     public String[] getListBoxItems(String ListBoxName)
            throws java.lang.Exception
     {
         ArrayList<String> Items = new ArrayList<String>();
         try {
            XAccessibleContext xListBox = null;
            XAccessibleContext xList = null;

            xListBox =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                         AccessibleRole.COMBO_BOX, ListBoxName);
            if (xListBox == null){
                xListBox =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                             AccessibleRole.PANEL, ListBoxName);
            }

            if (xListBox == null){
                // get the list of TreeListBox
                xList =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                              AccessibleRole.TREE, ListBoxName);

            // all other list boxes have a children of kind of LIST
            } else {

                XAccessible xListBoxAccess = UnoRuntime.queryInterface(XAccessible.class, xListBox);
                // if a List is not pulled to be open all entries are not visiblle, therefore the
                // boolean argument
                xList =AccessibilityTools.getAccessibleObjectForRole(
                                              xListBoxAccess, AccessibleRole.LIST, true);
            }

            for (int i=0;i<xList.getAccessibleChildCount();i++) {
                try {
                    XAccessible xChild = xList.getAccessibleChild(i);
                    XAccessibleContext xChildCont =
                                                  xChild.getAccessibleContext();
                    XInterface xChildInterface = UnoRuntime.queryInterface(XInterface.class, xChildCont);
                    Items.add(getString(xChildInterface));

                } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
                      throw new Exception("Could not get child form list of '"
                                         + ListBoxName + "' : " + e.toString());
                }
            }

         } catch (Exception e) {
            throw new Exception("Could not get list of items from '"
                                         + ListBoxName + "' : " + e.toString());
        }
        String[]ret = new String[Items.size()];
        return Items.toArray(ret);
     }
     /**
      * set to a named nureric filed a given value
      * @param NumericFieldName the name of the nureic field
      * @param cValue the value to set
      * @throws java.lang.Exception if something fail
      */
     public void setNumericFieldValue(String NumericFieldName, String cValue)
        throws java.lang.Exception
     {
         try{
            XInterface xNumericField =AccessibilityTools.getAccessibleObjectForRole(
                                  mXRoot, AccessibleRole.TEXT, NumericFieldName);
            UnoRuntime.queryInterface(
             XAccessibleEditableText.class, xNumericField);

            setString(xNumericField, cValue);
         } catch (Exception e) {
          throw new Exception("Could not set value '" + cValue +
            "' into NumericField '" + NumericFieldName + "' : " + e.toString());
        }
     }

     /**
      * returns the value of a numeric field
      * @param NumericFieldName the name of the numreic field
      * @throws java.lang.Exception if something fail
      * @return the value of the named numeric filed
      */
     private String getNumericFieldValue(String NumericFieldName)
        throws java.lang.Exception
     {
         try{
            XInterface xNumericField =AccessibilityTools.getAccessibleObjectForRole(
                                  mXRoot, AccessibleRole.TEXT, NumericFieldName);
            return getString(xNumericField);

         } catch (Exception e) {
          throw new Exception("Could get value from NumericField '"
                                    + NumericFieldName + "' : " + e.toString());
        }
     }

     private String removeCharactersFromCurrencyString(String stringVal)
        throws java.lang.Exception
     {
         try{
            int beginIndex = 0;
            int endIndex = 0;
            // find the first numeric character in stringVal
            for(int i = 0; i < stringVal.length(); i++){
                int numVal = Character.getNumericValue(stringVal.charAt(i));
                // if ascii is a numeric value
                if (numVal != -1){
                    beginIndex = i;
                    break;
                }
            }
            // find the last numeric character in stringVal
            for(int i = stringVal.length()-1; i > 0; i--){
                int numVal = Character.getNumericValue(stringVal.charAt(i));
                if (numVal != -1){
                    endIndex = i+1;
                    break;
                }
            }
            String currencyVal = stringVal.substring(beginIndex, endIndex);

            currencyVal = currencyVal.substring(0, currencyVal.length()-3) +
                          "#" + currencyVal.substring(currencyVal.length()-2);

            currencyVal = currencyVal.replace(",", "");
            currencyVal = currencyVal.replace("\\.", "");
            currencyVal = currencyVal.replace("#", ".");

            return currencyVal;
         } catch (Exception e) {
          throw new Exception("Could get remove characters from currency string '"
                                    + stringVal + "' : " + e.toString());
        }

     }

     /**
      * returns the numeric value of a numeric filed. This is needed ie. for
      * fields include the moneytary unit.
      * @param NumericFieldName the name of the numeric filed
      * @return the value of the numeric filed
      * @throws java.lang.Exception if something fail
      */
     public Double getNumericFieldNumericValue(String NumericFieldName)
        throws java.lang.Exception
     {
         try{
            Double retValue = null;
            String sValue = getNumericFieldValue(NumericFieldName);
            String sAmount = removeCharactersFromCurrencyString(sValue);
            retValue = Double.valueOf(sAmount);

            return retValue;

         } catch (Exception e) {
          throw new Exception("Could get numeric value from NumericField '"
                                    + NumericFieldName + "' : " + e.toString());
        }
     }


      /**
       * returns the content of a TextBox
       * @param TextFieldName the name of the textbox
       * @return the value of the text box
       * @throws java.lang.Exception if something fail
       */
     public String getTextBoxText(String TextFieldName)
        throws java.lang.Exception
     {
        String TextFieldText = null;
        try{
            XAccessibleContext xTextField =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                     AccessibleRole.SCROLL_PANE, TextFieldName);
            XAccessible xTextFieldAccess = UnoRuntime.queryInterface(XAccessible.class, xTextField);
            XAccessibleContext xFrame =AccessibilityTools.getAccessibleObjectForRole(
                                   xTextFieldAccess, AccessibleRole.TEXT_FRAME);
            for (int i=0;i<xFrame.getAccessibleChildCount();i++) {
                try {
                    XAccessible xChild = xFrame.getAccessibleChild(i);
                    XAccessibleContext xChildCont =
                                                  xChild.getAccessibleContext();
                    XInterface xChildInterface = UnoRuntime.queryInterface(XInterface.class, xChildCont);
                    TextFieldText += (getString(xChildInterface));

                } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
                    throw new Exception("Could not get child fom TextFrame of '"
                                       + TextFieldName + "' : " + e.toString());
                }
            }
            return TextFieldText;
         } catch (Exception e) {
            throw new Exception("Could not get content fom Textbox '"
                                       + TextFieldName + "' : " + e.toString());
        }
     }

     /**
      * set a value to a named check box
      * @param CheckBoxName the name of the check box
      * @param Value the value to set
      *<ul>
      *    <li>0: not checked </li>
      *    <li>1: checked </li>
      *    <li>2: don't know </li>
      *</ul>
      * @throws java.lang.Exception if something fail
      */
     public void setCheckBoxValue(String CheckBoxName, Integer Value)
            throws java.lang.Exception
     {
         try {
            XInterface xCheckBox =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                     AccessibleRole.CHECK_BOX, CheckBoxName);
            XAccessibleValue xCheckBoxValue = UnoRuntime.queryInterface(XAccessibleValue.class, xCheckBox);
            xCheckBoxValue.setCurrentValue(Value);

         } catch (Exception e) {
            throw new Exception("Could not set value to CheckBox '"
                                       + CheckBoxName + "' : " + e.toString());
        }
     }

     /**
      * returns the value of the named check box
      * @param CheckBoxName the name of the check box
      * @return the value of the check box
      * @throws java.lang.Exception if something fail
      */
    public Integer getCheckBoxValue(String CheckBoxName)
            throws java.lang.Exception
     {
         try {
            XInterface xCheckBox =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                     AccessibleRole.CHECK_BOX, CheckBoxName);
            XAccessibleValue xCheckBoxValue = UnoRuntime.queryInterface(XAccessibleValue.class, xCheckBox);

            return (Integer) xCheckBoxValue.getCurrentValue();
         } catch (Exception e) {
            throw new Exception("Could not set value to CheckBox '"
                                       + CheckBoxName + "' : " + e.toString());
        }
     }

      /**
       * returns the message of a Basic-MessageBox
       * @return the message of a Basic-MessageBox
       * @throws java.lang.Exception if something fail
       */
     public String getMsgBoxText()
        throws java.lang.Exception
     {
        String cMessage = null;
        try{
            XAccessibleContext xMessage =AccessibilityTools.getAccessibleObjectForRole(mXRoot,
                                     AccessibleRole.LABEL);

            XInterface xMessageInterface = UnoRuntime.queryInterface(XInterface.class, xMessage);
            cMessage += (getString(xMessageInterface));


            return cMessage;
         } catch (Exception e) {
            throw new Exception("Could not get message from Basic-MessageBox: " + e.toString());
        }
     }

    /**
     * fetch the window which is equal to the given <CODE>WindowName</CODE>
     * @return the named window
     * @throws java.lang.Exception if something fail
     */
    public XWindow getTopWindow(String WindowName, boolean debug) throws java.lang.Exception
    {
        XInterface xToolKit = null;
        try {
            xToolKit = (XInterface) mMSF.createInstance("com.sun.star.awt.Toolkit") ;
        } catch (com.sun.star.uno.Exception e) {
          throw new Exception("Could not toolkit: " + e.toString());
        }
        XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class, xToolKit);

        int count = tk.getTopWindowCount();

        XTopWindow retWindow = null;

        if (debug) System.out.println("getTopWindow ->");

        for (int i=0; i < count ; i++){
            XTopWindow xTopWindow = tk.getTopWindow(i);
            XAccessible xAcc = AccessibilityTools.getAccessibleObject(xTopWindow);
            String accName = xAcc.getAccessibleContext().getAccessibleName();

            if (debug){
                System.out.println("AccessibleName: " + accName);
            }

            if (WindowName.equals(accName)){
                if (debug) System.out.println("-> found window with name '" + WindowName + "'");
                retWindow = xTopWindow;
            }
        }


        if (debug) {
            if (retWindow == null) System.out.println("could not found window with name '" + WindowName + "'");
            System.out.println("<- getTopWindow ");
        }
        return UnoRuntime.queryInterface(XWindow.class, retWindow);
    }

    public void clickMiddleOfAccessibleObject(short role, String name){

        XAccessibleContext xAcc =AccessibilityTools.getAccessibleObjectForRole(mXRoot, role, name);
        XAccessibleComponent aComp = UnoRuntime.queryInterface(
                                             XAccessibleComponent.class, xAcc);

        System.out.println(xAcc.getAccessibleRole() + "," +
                    xAcc.getAccessibleName() + "(" +
                    xAcc.getAccessibleDescription() + "):" +
                    utils.getImplName(xAcc));

        if (aComp != null) {
            aComp.getLocationOnScreen();
            String bounds = "(" + aComp.getBounds().X + "," +
                            aComp.getBounds().Y + ")" + " (" +
                            aComp.getBounds().Width + "," +
                            aComp.getBounds().Height + ")";
            System.out.println("The boundary Rectangle is " + bounds);
                try {
                    Robot rob = new Robot();
                    int x = aComp.getLocationOnScreen().X + (aComp.getBounds().Width / 2);
                    int y = aComp.getLocationOnScreen().Y + (aComp.getBounds().Height / 2);
                    System.out.println("try to click mouse button on x/y " + x + "/" + y);
                    rob.mouseMove(x, y);
                    rob.mousePress(InputEvent.BUTTON1_MASK);
                    rob.mouseRelease(InputEvent.BUTTON1_MASK);
                } catch (java.awt.AWTException e) {
                    System.out.println("couldn't press mouse button");
                }

        }
    }

    public void doubleClickMiddleOfAccessibleObject(short role, String name) {
        XAccessibleContext xAcc =AccessibilityTools.getAccessibleObjectForRole(mXRoot, role, name);
        XAccessibleComponent aComp = UnoRuntime.queryInterface(
                                             XAccessibleComponent.class, xAcc);

        System.out.println(xAcc.getAccessibleRole() + "," +
                    xAcc.getAccessibleName() + "(" +
                    xAcc.getAccessibleDescription() + "):" +
                    utils.getImplName(xAcc));

        if (aComp != null) {
            aComp.getLocationOnScreen();
            String bounds = "(" + aComp.getBounds().X + "," +
                            aComp.getBounds().Y + ")" + " (" +
                            aComp.getBounds().Width + "," +
                            aComp.getBounds().Height + ")";
            System.out.println("The boundary Rectangle is " + bounds);
                try {
                    Robot rob = new Robot();
                    int x = aComp.getLocationOnScreen().X + (aComp.getBounds().Width / 2);
                    int y = aComp.getLocationOnScreen().Y + (aComp.getBounds().Height / 2);
                    System.out.println("try to double click mouse button on x/y " + x + "/" + y);
                    rob.mouseMove(x, y);
                    rob.mousePress(InputEvent.BUTTON1_MASK);
                    rob.mouseRelease(InputEvent.BUTTON1_MASK);
                    utils.shortWait(100);
                    rob.mousePress(InputEvent.BUTTON1_MASK);
                    rob.mouseRelease(InputEvent.BUTTON1_MASK);
                } catch (java.awt.AWTException e) {
                    System.out.println("couldn't press mouse button");
                }

        }
    }

    /**
     * <B>DEPRECATED</B>
     * Since <CODE>AccessibilityTools</CODE> handle parameter <CODE>debugIsActive</CODE>
     * this function does not work anymore.
     * @deprecated Since <CODE>AccessibilityTools</CODE> handle parameter <CODE>debugIsActive</CODE>
     * this function does not work anymore.
     * @param log logWriter
     */
    public void printAccessibleTree(PrintWriter log)
    {
        AccessibilityTools.printAccessibleTree(log, mXRoot);
    }


    /**
     * Prints the accessible tree to the <CODE>logWriter</CODE> only if <CODE>debugIsActive</CODE>
     * is set to <CODE>true</CODE>
     * @param log logWriter
     * @param debugIsActive prints only if this parameter is set to TRUE
     */
    public void printAccessibleTree(PrintWriter log, boolean debugIsActive) {
        AccessibilityTools.printAccessibleTree(log, mXRoot, debugIsActive);
    }

}