1 /* 2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.jemmy.swt; 24 25 import java.util.Arrays; 26 import org.eclipse.swt.widgets.List; 27 import org.jemmy.Point; 28 import org.jemmy.action.GetAction; 29 import org.jemmy.control.ControlType; 30 import org.jemmy.env.Environment; 31 import org.jemmy.input.KeyboardSelectable; 32 import org.jemmy.input.KeyboardSelector; 33 import org.jemmy.interfaces.Focusable; 34 import org.jemmy.interfaces.Selector; 35 36 /** 37 * 38 * @author shura 39 */ 40 @ControlType(List.class) 41 public class ListWrap<T extends List> extends ControlWrap<T> implements KeyboardSelectable<String>, Focusable { 42 43 private KeyboardSelector<String> selector = null; 44 45 public ListWrap(Environment env, T node) { 46 super(env, node); 47 } 48 49 public java.util.List<String> getStates() { 50 return new GetAction<java.util.List<String>>() { 51 52 @Override 53 public void run(Object... parameters) throws Exception { 54 setResult(Arrays.asList(getControl().getItems())); 55 } 56 }.dispatch(getEnvironment()); 57 } 58 59 public String getState() { 60 return new GetAction<String>() { 61 62 @Override 63 public void run(Object... parameters) throws Exception { 64 setResult(getControl().getSelection()[0]); 65 } 66 }.dispatch(getEnvironment()); 67 } 68 69 public int selection() { 70 return new GetAction<Integer>() { 71 72 @Override 73 public void run(Object... parameters) throws Exception { 74 setResult(getControl().getSelectionIndex()); 75 } 76 }.dispatch(getEnvironment()); 77 } 78 79 public boolean isVertical() { 80 return true; 81 } 82 83 public int index(String item) { 84 return getStates().indexOf(item); 85 } 86 87 public Selector<String> selector() { 88 if (selector == null) { 89 selector = new KeyboardSelector<String>(this, this); 90 } 91 return selector; 92 } 93 94 public Class<String> getType() { 95 return String.class; 96 } 97 98 @Override 99 public ClickFocus focuser() { 100 if (focuser == null) { 101 super.focuser().pnt = new Point(1, 1); 102 } 103 return focuser; 104 } 105 }