1 /*
   2  * Copyright (c) 2007, 2017 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.input;
  24 
  25 import org.jemmy.control.Wrap;
  26 import org.jemmy.interfaces.Menu;
  27 import org.jemmy.interfaces.MenuOwner;
  28 import org.jemmy.lookup.LookupCriteria;
  29 
  30 /**
  31  * In most cases menu has a text associated with every menu item. This interface 
  32  * makes it easy to push the menu based on that text information.
  33  * @author shura
  34  */
  35 public abstract class StringMenuOwner<T> extends StringCriteriaList<T>
  36         implements MenuOwner<T> {
  37     
  38     private static final String MENU_PATH_LENGTH_ERROR = "Menu path length should be greater than 0";
  39 
  40     public StringMenuOwner(Wrap<?> menuOwner) {
  41         super(menuOwner.getEnvironment());
  42     }
  43 
  44     /**
  45      * Pushes the menu using one string for one level of the menu. Comparison 
  46      * is done according to the policy.
  47      * @param texts 
  48      * @see #getPolicy() 
  49      */
  50     public void push(String... texts) {
  51         if(texts.length == 0) {
  52             throw new IllegalArgumentException(MENU_PATH_LENGTH_ERROR);
  53         }
  54         menu().push(createCriteriaList(texts));
  55     }
  56 
  57     /**
  58      * A shortcut to <code>menu().push(LookupCriteria<T> ...)</code>
  59      * @see #menu() 
  60      * @see Menu#push(org.jemmy.lookup.LookupCriteria<T>[]) 
  61      * @param criteria 
  62      */
  63     public void push(LookupCriteria<T>... criteria) {
  64         menu().push(criteria);
  65     }
  66 
  67     /**
  68      * Select a menu item using one string for one level of the menu. Comparison 
  69      * is done according to the policy.
  70      * @param texts 
  71      * @return wrap for the last selected item
  72      * @see #getPolicy() 
  73      */
  74     public Wrap<? extends T> select(String... texts) {
  75         if(texts.length == 0) {
  76             throw new IllegalArgumentException(MENU_PATH_LENGTH_ERROR);
  77         }
  78         return menu().select(createCriteriaList(texts));
  79     }
  80 
  81     /**
  82      * A shortcut to <code>menu().select(LookupCriteria<T> ...)</code>
  83      * @see #menu() 
  84      * @see Menu#select(org.jemmy.lookup.LookupCriteria<T>[]) 
  85      * @param criteria 
  86      */
  87     public Wrap<? extends T> select(LookupCriteria<T>... criteria) {
  88         return menu().select(criteria);
  89     }
  90 
  91 }