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.Display;
  26 import org.jemmy.action.AbstractExecutor;
  27 import org.jemmy.action.Action;
  28 import org.jemmy.env.Environment;
  29 
  30 /**
  31  *
  32  * @author shura
  33  */
  34 public class SWTExecutor extends AbstractExecutor {
  35         
  36     @Override
  37     public void executeQueue(Environment env, final Action action, final Object[] parameters) {
  38         if (!isInAction()) {
  39             env.getOutput(QUEUE_ACTION_OUTPUT).println("Running action on event queue: " + action);
  40         }
  41         /*
  42         if (isInAction()) {
  43             action.execute(parameters);
  44         } else {
  45          *
  46          */
  47             Display.getDefault().syncExec(new Runnable() {
  48 
  49                 public void run() {
  50                     action.execute(parameters);
  51                 }
  52             });
  53         //}
  54     }
  55 
  56     @Override
  57     public void executeQueueDetached(Environment env, final Action action, final Object[] parameters) {
  58         if (!isInAction()) {
  59             env.getOutput().println("Running detached action on event queue: " + action);
  60         }
  61         Display.getDefault().asyncExec(new Runnable() {
  62 
  63             public void run() {
  64                 action.execute(parameters);
  65             }
  66         });
  67     }
  68 
  69     @Override
  70     public boolean isOnQueue() {
  71         return Display.getDefault().getThread() == Thread.currentThread();
  72     }
  73 
  74     @Override
  75     protected boolean isQuiet() {
  76         return true;
  77     }
  78 }