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 org.eclipse.swt.widgets.Control;
  26 import org.eclipse.swt.widgets.MenuItem;
  27 import org.jemmy.Point;
  28 import org.jemmy.interfaces.Keyboard.KeyboardButtons;
  29 import org.jemmy.interfaces.MenuSelectable;
  30 import org.jemmy.interfaces.Mouse.MouseButtons;
  31 import org.jemmy.resources.StringComparePolicy;
  32 
  33 /**
  34  *
  35  * @author shura, erikgreijus
  36  */
  37 public class SWTPopupOwner extends StringPopupSelectableOwner<MenuItem> {
  38 
  39     SWTMenu menu;
  40     Wrap<? extends Control> owner;
  41 
  42     public SWTPopupOwner(Wrap<? extends Control> owner) {
  43         super(owner);
  44         this.owner = owner;
  45         menu = new SWTMenu(owner, false);
  46     }
  47 
  48     @Override
  49     public Class<MenuItem> getType() {
  50         return MenuItem.class;
  51     }
  52 
  53     @Override
  54     public MenuSelectable menu(Point p) {
  55         owner.mouse().click(1, p, MouseButtons.BUTTON3);
  56         menu.waitVisible(((ControlWrap)owner).menu());
  57         owner.keyboard().pushKey(KeyboardButtons.DOWN);
  58         owner.getEnvironment().getTimeout(SWTMenu.BETWEEN_KEYS_SLEEP).sleep();
  59         return menu;
  60     }
  61 
  62     @Override
  63     protected LookupCriteria<MenuItem> createCriteria(String text, StringComparePolicy policy) {
  64         return SWTMenu.createCriteria(text, policy);
  65     }
  66 
  67 }