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