--- /dev/null 2018-01-17 13:51:43.000000000 -0800 +++ new/SWT/JemmySWT/src/org/jemmy/swt/CompositeWrap.java 2018-01-17 13:51:43.000000000 -0800 @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.jemmy.swt; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.jemmy.action.GetAction; +import org.jemmy.control.ControlType; +import org.jemmy.env.Environment; +import org.jemmy.lookup.Any; +import org.jemmy.lookup.ControlHierarchy; +import org.jemmy.lookup.HierarchyLookup; +import org.jemmy.lookup.Lookup; +import org.jemmy.lookup.LookupCriteria; + +/** + * + * @author shura, erikgreijus + * @param + */ +@ControlType(Composite.class) +public class CompositeWrap extends ControlWrap implements Parent { + + private final SWTHierarchy swth; + public CompositeWrap(Environment env, T node) { + super(env, node); + swth = new SWTHierarchy(); + } + + public Lookup lookup(Class controlClass, LookupCriteria criteria) { + return new HierarchyLookup(getEnvironment(), swth, Shells.SHELLS.swtWrapper, controlClass, criteria); + } + + public Lookup lookup(Class controlClass) { + return lookup(controlClass, new Any()); + } + + public Lookup lookup(LookupCriteria criteria) { + return lookup(getType(), criteria); + } + + public Lookup lookup() { + return lookup(new Any()); + } + + public Class getType() { + return org.eclipse.swt.widgets.Control.class; + } + + private class SWTHierarchy implements ControlHierarchy { + + public List getControls() { + GetAction action = new GetAction() { + public void run(Object... parameters) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + if (!getControl().isDisposed()) { + setResult(getControl().getChildren()); + } else { + setResult(new Control[0]); + } + } + }); + } + }; + getEnvironment().getExecutor().execute(getEnvironment(), true, action); + return Arrays.asList(action.getResult()); + } + + public List getChildren(final Object subParent) { + if(!(subParent instanceof Composite)) return null; + GetAction action = new GetAction() { + public void run(Object... parameters) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + Composite subParentComposite = Composite.class.cast(subParent); + if (!subParentComposite.isDisposed()) { + setResult(subParentComposite.getChildren()); + } else { + setResult(new Control[0]); + } + } + }); + } + }; + getEnvironment().getExecutor().execute(getEnvironment(), true, action); + return Arrays.asList(action.getResult()); + } + + public Object getParent(final Object child) { + GetAction action = new GetAction() { + public void run(Object... parameters) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + Widget childComposite = Widget.class.cast(child); + if (!childComposite.isDisposed()) { + setResult(((org.eclipse.swt.widgets.Control)child).getParent()); + } else { + setResult(null); + } + } + }); + } + }; + getEnvironment().getExecutor().execute(getEnvironment(), true, action); + return action.getResult(); + } + } + +}