Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Resolvable |
|
| 1.6;1.6 |
1 | /******************************************************************************* | |
2 | * Copyright (c) 2008,2011 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 | *******************************************************************************/ | |
11 | package org.eclipse.swtbot.swt.finder.resolvers; | |
12 | ||
13 | import org.eclipse.swt.widgets.Widget; | |
14 | ||
15 | /** | |
16 | * Finds a resolver that can resolve the parent anc children of a widget. | |
17 | * | |
18 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
19 | * @version $Id$ | |
20 | */ | |
21 | public class Resolvable implements IResolvable { | |
22 | ||
23 | /** The resolver */ | |
24 | protected Resolver resolver; | |
25 | ||
26 | /** | |
27 | * Create a resolvable instance, with some default resolvers. | |
28 | */ | |
29 | public Resolvable() { | |
30 | 5053 | this(new Resolver()); |
31 | 5053 | resolver.addResolver(new ExpandBarResolver()); |
32 | 5053 | resolver.addResolver(new ExpandItemResolver()); |
33 | 5053 | resolver.addResolver(new CTabFolderResolver()); |
34 | 5053 | resolver.addResolver(new TabFolderResolver()); |
35 | 5053 | resolver.addResolver(new CTabItemResolver()); |
36 | 5053 | resolver.addResolver(new TabItemResolver()); |
37 | 5053 | resolver.addResolver(new ToolbarResolver()); |
38 | 5053 | resolver.addResolver(new CompositeResolver()); |
39 | 5053 | resolver.addResolver(new NullResolver()); |
40 | 5053 | } |
41 | ||
42 | /** | |
43 | * Creates a resolvable using the given resolvable item. It is recommended that the default construction be used. | |
44 | * | |
45 | * @param resolver the resolver | |
46 | */ | |
47 | 5053 | public Resolvable(Resolver resolver) { |
48 | 5053 | this.resolver = resolver; |
49 | 5053 | } |
50 | ||
51 | /** | |
52 | * Returns {@code true} if any of the resolvers can resolve the widget. | |
53 | * | |
54 | * @see org.eclipse.swtbot.swt.finder.resolvers.IResolvable#canResolve(org.eclipse.swt.widgets.Widget) | |
55 | * @param w The widget to resolve. | |
56 | * @return <code>true</code> if any of the resolvers can resolve the widget. Otherwise <code>false</code>. | |
57 | */ | |
58 | public boolean canResolve(Widget w) { | |
59 | 0 | Class<?>[] resolvableClasses = getResolvableClasses(); |
60 | 0 | for (Class<?> clazz : resolvableClasses) { |
61 | 0 | if (w.getClass().equals(clazz)) |
62 | 0 | return true; |
63 | } | |
64 | ||
65 | 0 | return false; |
66 | } | |
67 | ||
68 | /** | |
69 | * Gets the complete list of widget types that this object can resolve. | |
70 | * | |
71 | * @return the types that this resolver can resolve | |
72 | */ | |
73 | public Class<?>[] getResolvableClasses() { | |
74 | 0 | return resolver.getResolvableClasses(); |
75 | } | |
76 | ||
77 | /** | |
78 | * Gets the resolver. | |
79 | * | |
80 | * @return the resolver. | |
81 | */ | |
82 | public Resolver getResolver() { | |
83 | 6016 | return resolver; |
84 | } | |
85 | ||
86 | } |