xref: /trunk/test/testcommon/source/org/openoffice/test/vcl/widgets/VclListBox.java (revision 3309286857f19787ae62bd793a98b5af4edd2ad3)
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 public class VclListBox extends VclControl  {
30 
VclListBox(VclApp app, String id)31     public VclListBox(VclApp app, String id) {
32         super(app, id);
33     }
34 
35 
36     /**
37      * Returns the number of entries in a TreeListBox.
38      *
39      * @return Number of list box entries. Error if the return value is -1.
40      */
getItemCount()41     public int getItemCount() {
42         return ((Long) invoke(Constant.M_GetItemCount)).intValue();
43     }
44 
45     /**
46      * Get the text of the specified entry in the tree list box Notice:
47      * index,col starting from 0
48      *
49      * @param index
50      * @param col
51      * @return
52      */
getItemText(int index, int col)53     public String getItemText(int index, int col) {
54         return (String) invoke(Constant.M_GetItemText, new Object[] { new Integer(index + 1), new Integer(col + 1) });
55     }
56 
57     /**
58      * Get the text of the specified node Notice: index starting from 0
59      *
60      * @param index
61      * @return
62      */
getItemText(int index)63     public String getItemText(int index) {
64         return getItemText(index, 0);
65     }
66 
67     /**
68      * Returns the number of selected entries in a TreeListbox(you can select
69      * more than one entry).
70      *
71      * @return The number of selected entries. Error is the return value is -1.
72      */
getSelCount()73     public int getSelCount() {
74         return ((Long) invoke(Constant.M_GetSelCount)).intValue();
75     }
76 
77     /**
78      * Returns the index number of the selected entry in the TreeListBox.
79      * Notice: index starting from 0
80      *
81      * @return The index number of selected entries. Error is the return value
82      *         is -1.
83      */
getSelIndex()84     public int getSelIndex() {
85         return ((Long) invoke(Constant.M_GetSelIndex)).intValue() - 1;
86     }
87 
88     /**
89      * Get the text of the selected item
90      */
getSelText()91     public String getSelText() {
92         return (String) invoke(Constant.M_GetSelText);
93     }
94 
95     /**
96      * Select the specified node via its index Notice: index starting from 0
97      *
98      * @param index
99      */
select(int index)100     public void select(int index) {
101         invoke(Constant.M_Select, new Object[] { new Integer(index + 1) });
102     }
103 
104     /**
105      * Selects the text of an entry.
106      *
107      * @param str
108      *            the item string
109      */
select(String text)110     public void select(String text) {
111         if (getType() == 324) {
112             int count = getItemCount();
113             for (int i = 0; i < count; i++) {
114                 if (text.equals(getItemText(i))) {
115                     select(i);
116                     return;
117                 }
118             }
119 
120             throw new RuntimeException(text + " is not found in the list box");
121         } else {
122             invoke(Constant.M_Select, new Object[] { text });
123         }
124     }
125 
126     /**
127      * Append one item to be selected after selected some items.
128      *
129      * @param i
130      *            the index of the item
131      */
multiSelect(int i)132     public void multiSelect(int i) {
133         invoke(Constant.M_MultiSelect, new Object[] { new Integer(i + 1) });
134     }
135 
136     /**
137      * Append one item to be selected after selected some items.
138      *
139      * @param text
140      *            the text of the item
141      */
multiSelect(String text)142     public void multiSelect(String text) {
143         invoke(Constant.M_MultiSelect, new Object[] { text });
144     }
145 
146     /**
147      * get all items'text.
148      *
149      */
getItemsText()150     public String[] getItemsText() {
151         int count = getItemCount();
152         String[] res = new String[count];
153         for (int i = 0; i < count; i++) {
154             res[i] = getItemText(i);
155         }
156         return res;
157     }
158 
159     /**
160      *
161      * @param text
162      * @return
163      */
getItemIndex(String text)164     public int getItemIndex(String text) {
165         int count = getItemCount();
166         for (int i = 0; i < count; i++) {
167             if (text.equals(getItemText(i)))
168                 return i;
169         }
170 
171         throw new RuntimeException(text + " is not found in the list box");
172     }
173 
174 
175     /**
176      * Check if the list box has the specified item
177      *
178      * @param str
179      * @return
180      */
hasItem(String str)181     public boolean hasItem(String str) {
182         int len = getItemCount();
183         for (int i = 0; i < len; i++) {
184             String text = getItemText(i);
185             if (str.equals(text))
186                 return true;
187         }
188         return false;
189     }
190 }
191