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 com.company.test;
  24 
  25 import org.jemmy.control.ControlInterfaces;
  26 import org.jemmy.control.ControlType;
  27 import org.jemmy.control.MethodProperties;
  28 import org.jemmy.dock.DefaultParent;
  29 import org.jemmy.dock.DockInfo;
  30 import org.jemmy.dock.PreferredParent;
  31 import org.jemmy.dock.Shortcut;
  32 import org.jemmy.env.Environment;
  33 import org.jemmy.interfaces.Parent;
  34 import org.jemmy.interfaces.Selectable;
  35 import org.jemmy.interfaces.Selector;
  36 
  37 import java.util.Collection;
  38 import java.util.List;
  39 
  40 @ControlType(List.class)
  41 @DockInfo
  42 @MethodProperties({"iterator"})
  43 @ControlInterfaces({Selectable.class})
  44 @PreferredParent(CollectionWrap.class)
  45 public class ListWrap<T extends List> extends CollectionWrap<T> implements Selectable<Object> {
  46 
  47     @DefaultParent("collections")
  48     public static <C extends Collection> Parent<? super Collection> getRoot(Class<C> cType) {
  49         return CollectionRoot.PARENT;
  50     }
  51 
  52     protected ListWrap(Environment env, T node) {
  53         super(env, node);
  54     }
  55 
  56     @Override
  57     public List<Object> getStates() {
  58         return getControl();
  59     }
  60 
  61     private volatile Object state = null;
  62 
  63     @Override
  64     @Shortcut
  65     public Object getState() {
  66         return state;
  67     }
  68 
  69     @Override
  70     @Shortcut
  71     public Selector<Object> selector() {
  72         return new Selector<Object>() {
  73             @Override
  74             public void select(Object o) {
  75                 if(getControl().contains(o))
  76                     state = o;
  77                 else
  78                     throw new IllegalStateException(o + "is not contained");
  79             }
  80         };
  81     }
  82 
  83     @Override
  84     public Class<Object> getType() {
  85         return Object.class;
  86     }
  87 }