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