xref: /AOO41X/test/testcommon/source/org/openoffice/test/vcl/widgets/VclComboBox.java (revision 57caf934cc4bd0c33eda07ea95aabaebabf812db)
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 
24 package org.openoffice.test.vcl.widgets;
25 
26 import org.openoffice.test.vcl.client.Constant;
27 
28 /**
29  * Proxy used to access Vcl Combo Box
30  *
31  */
32 public class VclComboBox extends VclControl {
33 
VclComboBox(VclApp app, String id)34     public VclComboBox(VclApp app, String id) {
35         super(app, id);
36     }
37 
38     /**
39      * Get the item count
40      */
getItemCount()41     public int getItemCount() {
42         return ((Long) invoke(Constant.M_GetItemCount)).intValue();
43     }
44 
45     /**
46      * Get the text of the index-th item.
47      * @index The index starts from 0.
48      */
getItemText(int index)49     public String getItemText(int index) {
50         return (String) invoke(Constant.M_GetItemText, new Object[] {index + 1});
51     }
52 
53     /**
54      * Get the index of the selected item.
55      * @index The index starts from 0.
56      */
getSelIndex()57     public int getSelIndex() {
58         int index = ((Long) invoke(Constant.M_GetSelIndex)).intValue();
59         return index - 1;
60     }
61 
62     /**
63      * Get the text of the selected item.
64      */
getSelText()65     public String getSelText() {
66         return (String) invoke(Constant.M_GetSelText);
67     }
68 
69     /**
70      * Get the text in the combo box
71      */
getText()72     public String getText() {
73         // Fix: Use M_Caption to get the text. M_GetText does not work
74         return (invoke(Constant.M_Caption)).toString();
75     }
76 
77     /**
78      * Get the text of all items
79      */
getItemsText()80     public String[] getItemsText() {
81         int count = getItemCount();
82         String[] res = new String[count];
83         for (int i = 0; i < count; i++) {
84             res[i] = getItemText(i);
85         }
86         return res;
87     }
88 
89     /**
90      * Select the index-th item.
91      * @index The index starts from 0.
92      */
select(int index)93     public void select(int index) {
94         invoke(Constant.M_Select, new Object[] {index + 1});
95     }
96 
97     /**
98      * Select the item with the given text
99      */
select(String text)100     public void select(String text) {
101         invoke(Constant.M_Select, new Object[] {text});
102     }
103 
104     /**
105      * Sets no selection in a list (Sometimes this corresponds to the first
106      * entry in the list)
107      *
108      */
setNoSelection()109     public void setNoSelection() {
110         invoke(Constant.M_SetNoSelection);
111     }
112 
113     /**
114      * Set the text of the combo box
115      */
setText(String text)116     public void setText(String text) {
117         invoke(Constant.M_SetText, new Object[] {text});
118     }
119 
120     /**
121      * Check if the list box has the specified item
122      * @param str
123      * @return
124      */
hasItem(String str)125     public boolean hasItem(String str) {
126         int len = getItemCount();
127         for (int i = 0; i < len; i++) {
128             String text = getItemText(i);
129             if (str.equals(text))
130                 return true;
131         }
132         return false;
133     }
134 }
135