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