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 import org.openoffice.test.vcl.client.Constant; 26 27 28 public class VclTreeListBox extends VclControl { 29 VclTreeListBox(VclApp app, String id)30 public VclTreeListBox(VclApp app, String id) { 31 super(app, id); 32 } 33 34 /** 35 * Returns the number of entries in a TreeListBox. Namely all the expanded node. 36 * 37 * @return Number of list box entries. Error if the return value is -1. 38 */ getItemCount()39 public int getItemCount() { 40 return ((Long)invoke(Constant.M_GetItemCount)).intValue(); 41 } 42 43 /** 44 * Get the text of the specified entry in the tree list box 45 * Notice: index,col starting from 0. <br> 46 * In some tree list box, there is a hidden column, so if you can get the item text, pls add 1 to the column 47 * @param row 48 * @param col 49 * @return 50 */ getItemText(int row, int col)51 public String getItemText(int row, int col) { 52 return (String) invoke(Constant.M_GetItemText, new Object[]{row + 1, col + 1}); 53 } 54 55 /** 56 * Returns the text of the first string column of the row at the given index 57 * Notice: index starting from 0 58 * @param index 59 * @return 60 */ getItemText(int index)61 public String getItemText(int index) { 62 return (String) invoke(Constant.M_GetItemText, new Object[] {index + 1}); 63 } 64 65 /** 66 * Returns the number of selected entries in a TreeListbox(you can select 67 * more than one entry). 68 * 69 * @return The number of selected entries. Error is the return value is -1. 70 */ getSelCount()71 public int getSelCount() { 72 return ((Long)invoke(Constant.M_GetSelCount)).intValue(); 73 } 74 75 /** 76 * Returns the index number of the selected entry in the TreeListBox. 77 * Notice: index starting from 0 78 * @return The index number of selected entries. Error is the return value 79 * is -1. 80 */ getSelIndex()81 public int getSelIndex() { 82 int index = ((Long) invoke(Constant.M_GetSelIndex)).intValue(); 83 return index - 1; 84 } 85 86 /** 87 * Returns the text of the first string column of the first selected entry 88 * 89 * @return 90 */ getSelText()91 public String getSelText() { 92 return (String) invoke(Constant.M_GetSelText, new Object[]{1}); 93 } 94 95 /** 96 * Returns the text of the n-th column of the first selected entry. 97 * If the column is not a string, a VCLException will be throwed. 98 * @param col the column index starting from 0 99 * @return 100 */ getSelText(int col)101 public String getSelText(int col) { 102 return (String) invoke(Constant.M_GetSelText, new Object[]{col + 1}); 103 } 104 105 /** 106 * Returns the text of the n-th column of the n-th selected entry. 107 * @param index the selected entry index starting from 0 108 * @param col the column index starting from 0 109 * @return 110 */ getSelText(int index, int col)111 public String getSelText(int index, int col) { 112 return invoke(Constant.M_GetSelText, new Object[]{(index + 1), (col + 1)}).toString(); 113 } 114 115 116 /** 117 * Select the entry at the given index 118 * @param index starting from 0 119 */ select(int index)120 public void select(int index) { 121 invoke(Constant.M_Select, new Object[]{index+1}); 122 } 123 124 /** 125 * Unselect the entry at the given index 126 * @param index starting from 0 127 */ unselect(int index)128 public void unselect(int index) { 129 invoke(Constant.M_Select, new Object[]{index + 1, false}); 130 } 131 132 /** 133 * Collapse the specified entry 134 * Notice: index starting from 0 135 * @param index the node index 136 */ collapse(int index)137 public void collapse(int index) { 138 // select(index); 139 // Tester.typeKeys("<left>"); 140 invoke(Constant.M_Collapse, new Object[]{index + 1, false}); 141 } 142 collapse()143 public void collapse() { 144 collapse(getSelIndex()); 145 } 146 collapse(String text)147 public void collapse(String text) { 148 String[] items = getAllItemsText(); 149 for (int i = 0; i < items.length; i++) { 150 if (text.equals(items[i])) 151 collapse(i); 152 } 153 } 154 155 /** 156 * Expand the specified entry 157 * Notice: index starting from 0 158 * @param index the entry index 159 */ expand(int index)160 public void expand(int index) { 161 // select(index); 162 // Tester.typeKeys("<right>"); 163 invoke(Constant.M_Expand, new Object[]{index + 1, false}); 164 } 165 expand()166 public void expand() { 167 expand(getSelIndex()); 168 } 169 expand(String text)170 public void expand(String text) { 171 String[] items = getAllItemsText(); 172 for (int i = 0; i < items.length; i++) { 173 if (text.equals(items[i])) 174 expand(i); 175 } 176 } 177 178 /** 179 * Select the node via its text 180 * @param str 181 * @return the index of the node 182 */ select(String str)183 public void select(String str) { 184 select(str, 0); 185 } 186 187 /** 188 * Select the entry with the given string and after the given index 189 * @param str 190 * @param start 191 */ select(String str, int start)192 public void select(String str, int start) { 193 int len = getItemCount(); 194 for (int i = start; i < len; i++) { 195 String text = getItemText(i); 196 if (str.equals(text)) { 197 select(i); 198 return; 199 } 200 } 201 throw new RuntimeException(str + " is not found in the tree"); 202 } 203 204 205 /** 206 * Return the text of all items 207 * @return A String[] includes all items text 208 */ getAllItemsText()209 public String[] getAllItemsText() { 210 int len = getItemCount(); 211 String[] ret = new String[len]; 212 for (int i = 0; i < len; i++) { 213 ret[i] = getItemText(i); 214 } 215 return ret; 216 } 217 218 /** 219 * Check if the list box has the specified item 220 * @param str 221 * @return 222 */ hasItem(String str)223 public boolean hasItem(String str) { 224 int len = getItemCount(); 225 for (int i = 0; i < len; i++) { 226 String text = getItemText(i); 227 if (str.equals(text)) 228 return true; 229 } 230 return false; 231 } 232 /** 233 * 234 * @return 235 */ isChecked(int row)236 public boolean isChecked(int row) { 237 return ((Boolean)invoke(Constant.M_IsChecked, new Object[]{new Integer(row+1)})).booleanValue(); 238 } 239 isChecked(int row, int col)240 public boolean isChecked(int row, int col) { 241 return ((Boolean)invoke(Constant.M_IsChecked, new Object[]{new Integer(row+1), new Integer(col+1)})).booleanValue(); 242 } 243 244 /** 245 * @param 246 * @return 247 */ isShowing(String str)248 public boolean isShowing(String str) { 249 boolean ret = false; 250 int len = getItemCount(); 251 for (int i = 0; i < len; i++) { 252 String text = getItemText(i); 253 if (str.equals(text)) { 254 ret = true; 255 } 256 } 257 return ret; 258 } 259 260 /** 261 * Check if the selected node is tristate 262 * @return 263 */ isTristate(int row)264 public boolean isTristate(int row) { 265 return ((Boolean)invoke(Constant.M_IsTristate, new Object[]{new Integer(row+1)})).booleanValue(); 266 } 267 isTristate(int row, int col)268 public boolean isTristate(int row, int col) { 269 return ((Boolean)invoke(Constant.M_IsTristate, new Object[]{new Integer(row+1), new Integer(col+1)})).booleanValue(); 270 } 271 272 /** 273 * Check if the selected node is tristate 274 * @return 275 */ isTristate()276 public boolean isTristate() { 277 return ((Boolean)invoke(Constant.M_IsTristate)).booleanValue(); 278 } 279 280 /** 281 * Get the state of the selected node 282 * @return 283 */ getState()284 public int getState() { 285 return ((Long)invoke(Constant.M_GetState)).intValue(); 286 } 287 288 /** 289 * Get the state of the selected node 290 * @return 291 */ getState(int row)292 public int getState(int row) { 293 return ((Long)invoke(Constant.M_GetState, new Object[]{new Integer(row+1)})).intValue(); 294 } 295 getState(int row, int col)296 public int getState(int row, int col) { 297 return ((Long)invoke(Constant.M_GetState, new Object[]{new Integer(row+1), new Integer(col+1)})).intValue(); 298 } 299 300 /** 301 * check the selected node 302 * 303 */ check()304 public void check() { 305 invoke(Constant.M_Check); 306 } 307 check(int row)308 public void check(int row) { 309 invoke(Constant.M_Check, new Object[]{new Integer(row+1)}); 310 } 311 check(int row, int col)312 public void check(int row, int col) { 313 invoke(Constant.M_Check, new Object[]{new Integer(row+1), new Integer(col+1)}); 314 } 315 316 /** 317 * uncheck the selected node 318 * 319 */ unCheck()320 public void unCheck() { 321 invoke(Constant.M_UnCheck); 322 } 323 unCheck(int row)324 public void unCheck(int row) { 325 invoke(Constant.M_UnCheck, new Object[]{new Integer(row+1)}); 326 } 327 unCheck(int row, int col)328 public void unCheck(int row, int col) { 329 invoke(Constant.M_UnCheck, new Object[]{new Integer(row+1), new Integer(col+1)}); 330 } 331 332 /** 333 * Set the selected node to tristate 334 * 335 */ triState()336 public void triState() { 337 invoke(Constant.M_TriState); 338 } 339 340 triState(int row)341 public void triState(int row) { 342 invoke(Constant.M_TriState, new Object[]{new Integer(row+1)}); 343 } 344 triState(int row, int col)345 public void triState(int row, int col) { 346 invoke(Constant.M_TriState, new Object[]{new Integer(row+1), new Integer(col+1)}); 347 } 348 349 /** 350 * Collapse all nodes in the tree list box. 351 * 352 */ collapseAll()353 public void collapseAll() {//?after expandAll, can not collapse the first node 354 for (int i = 0; i < getItemCount(); i++) { 355 collapse(i); 356 } 357 } 358 359 /** 360 * Expand all nodes in the tree list box 361 * 362 */ expandAll()363 public void expandAll() { 364 for (int i = 0; i < getItemCount(); i++) { 365 expand(i); 366 } 367 } 368 369 /** 370 * Select the specified node by path. 371 * @param path The node path likes "Node1->Node2->Node3" 372 * @return true if the node exists, false otherwise 373 */ selectByPath(String path)374 public void selectByPath(String path) { 375 collapseAll(); 376 String[] items = path.split("->"); 377 int i = 0; 378 for (String s : items) { 379 int len = getItemCount(); 380 for (; i < len; i++) { 381 String text = getItemText(i); 382 if (s.equals(text)) { 383 expand(i); 384 break; 385 } 386 } 387 if (i == len) { 388 throw new RuntimeException("Menu item '" + path + "' is not found in the tree"); 389 } 390 } 391 } 392 393 /** 394 * Get the column type of the given row 395 * @param row 396 * @param col 397 * @return 398 */ getItemType(int row, int col)399 public int getItemType(int row, int col) { 400 return (Integer)invoke(Constant.M_GetItemType, new Object[]{row + 1, col + 1}); 401 } 402 } 403