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 | 5055 | 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 | 164343 | 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 | 19497 | if (w.getClass().getName().equals("org.eclipse.swt.widgets.DateTime")) //$NON-NLS-1$ |
41 | 0 | return new ArrayList(); |
42 | 19497 | return hasChildren(w) ? Arrays.asList(((Composite) w).getChildren()) : new ArrayList(); |
43 | } | |
44 | ||
45 | public Widget getParent(Widget w) { | |
46 | 6308 | Composite parent = w instanceof Control ? ((Control) w).getParent() : null; |
47 | 6308 | if ((w instanceof Composite) && (parent instanceof TabFolder)) |
48 | 1218 | if (parent instanceof TabFolder) { |
49 | 1218 | TabItem[] items = ((TabFolder) parent).getItems(); |
50 | 1218 | return items[SWTUtils.widgetIndex(w)]; |
51 | } | |
52 | 5090 | return parent; |
53 | } | |
54 | ||
55 | public Class[] getResolvableClasses() { | |
56 | 5055 | 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 | 63372 | if (w.getClass().getName().equals("org.eclipse.swt.widgets.DateTime")) //$NON-NLS-1$ |
63 | 0 | return false; |
64 | 63372 | return canResolve(w) && ((Composite) w).getChildren().length > 0; |
65 | } | |
66 | ||
67 | public boolean hasParent(Widget w) { | |
68 | 4374 | return getParent(w) != null; |
69 | } | |
70 | } |