| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| CompositeResolver |
|
| 3.0;3 |
| 1 | /******************************************************************************* | |
| 2 | * Copyright (c) 2008 Ketan Padegaonkar and others. | |
| 3 | * All rights reserved. This program and the accompanying materials | |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | |
| 5 | * which accompanies this distribution, and is available at | |
| 6 | * http://www.eclipse.org/legal/epl-v10.html | |
| 7 | * | |
| 8 | * Contributors: | |
| 9 | * Ketan Padegaonkar - initial API and implementation | |
| 10 | * Hans Schwaebli - http://swtbot.org/bugzilla/show_bug.cgi?id=81 | |
| 11 | *******************************************************************************/ | |
| 12 | package org.eclipse.swtbot.swt.finder.resolvers; | |
| 13 | ||
| 14 | import java.util.ArrayList; | |
| 15 | import java.util.Arrays; | |
| 16 | import java.util.List; | |
| 17 | ||
| 18 | import org.eclipse.swt.widgets.Composite; | |
| 19 | import org.eclipse.swt.widgets.Control; | |
| 20 | import org.eclipse.swt.widgets.TabFolder; | |
| 21 | import org.eclipse.swt.widgets.TabItem; | |
| 22 | import org.eclipse.swt.widgets.Widget; | |
| 23 | import org.eclipse.swtbot.swt.finder.utils.SWTUtils; | |
| 24 | ||
| 25 | /** | |
| 26 | * Resolves {@link Composite}s and {@link Control}s | |
| 27 | * | |
| 28 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
| 29 | * @version $Id$ | |
| 30 | */ | |
| 31 | 8107 | public class CompositeResolver implements IChildrenResolver, IParentResolver { |
| 32 | ||
| 33 | public boolean canResolve(Widget w) { | |
| 34 | // FIXME https://bugs.eclipse.org/bugs/show_bug.cgi?id=206868 | |
| 35 | 214839 | return (w instanceof Composite) && !(w.getClass().getName().equals("org.eclipse.swt.widgets.DateTime")); //$NON-NLS-1$ |
| 36 | } | |
| 37 | ||
| 38 | public List getChildren(Widget w) { | |
| 39 | // FIXME https://bugs.eclipse.org/bugs/show_bug.cgi?id=206868 | |
| 40 | 25317 | if (w.getClass().getName().equals("org.eclipse.swt.widgets.DateTime")) //$NON-NLS-1$ |
| 41 | 0 | return new ArrayList(); |
| 42 | 25317 | return hasChildren(w) ? Arrays.asList(((Composite) w).getChildren()) : new ArrayList(); |
| 43 | } | |
| 44 | ||
| 45 | public Widget getParent(Widget w) { | |
| 46 | 8363 | Composite parent = w instanceof Control ? ((Control) w).getParent() : null; |
| 47 | 8363 | if ((w instanceof Composite) && (parent instanceof TabFolder)) |
| 48 | 1731 | if (parent instanceof TabFolder) { |
| 49 | 1731 | TabItem[] items = ((TabFolder) parent).getItems(); |
| 50 | 1731 | return items[SWTUtils.widgetIndex(w)]; |
| 51 | } | |
| 52 | 6632 | return parent; |
| 53 | } | |
| 54 | ||
| 55 | public Class[] getResolvableClasses() { | |
| 56 | 8107 | return new Class[] { Composite.class, Control.class }; |
| 57 | } | |
| 58 | ||
| 59 | public boolean hasChildren(Widget w) { | |
| 60 | // FIXME https://bugs.eclipse.org/bugs/show_bug.cgi?id=206868 | |
| 61 | // No "instanceof DateTime" is used in order to be compatible with PDE 3.2. | |
| 62 | 82551 | if (w.getClass().getName().equals("org.eclipse.swt.widgets.DateTime")) //$NON-NLS-1$ |
| 63 | 0 | return false; |
| 64 | 82551 | return canResolve(w) && ((Composite) w).getChildren().length > 0; |
| 65 | } | |
| 66 | ||
| 67 | public boolean hasParent(Widget w) { | |
| 68 | 5801 | return getParent(w) != null; |
| 69 | } | |
| 70 | } |