Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DefaultChildrenResolver |
|
| 6.5;6.5 |
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 | *******************************************************************************/ | |
11 | package org.eclipse.swtbot.swt.finder.resolvers; | |
12 | ||
13 | import java.util.ArrayList; | |
14 | import java.util.Iterator; | |
15 | import java.util.List; | |
16 | ||
17 | import org.eclipse.swt.widgets.Widget; | |
18 | ||
19 | /** | |
20 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
21 | * @version $Id$ | |
22 | */ | |
23 | 2527 | public class DefaultChildrenResolver extends Resolvable implements IChildrenResolver { |
24 | ||
25 | public List getChildren(Widget w) { | |
26 | 115718 | List result = new ArrayList(); |
27 | ||
28 | 115718 | if (!hasChildren(w)) |
29 | 63955 | return result; |
30 | ||
31 | 51763 | List resolvers = resolver.getResolvers(w.getClass()); |
32 | ||
33 | 103526 | for (Iterator iterator = resolvers.iterator(); iterator.hasNext();) { |
34 | 51763 | IChildrenResolver resolver = (IChildrenResolver) iterator.next(); |
35 | 51763 | if (resolver.canResolve(w) && resolver.hasChildren(w)) { |
36 | 51763 | List children = resolver.getChildren(w); |
37 | 51763 | if (children != null) { |
38 | 51763 | result.addAll(children); |
39 | 51763 | return result; |
40 | } | |
41 | } | |
42 | } | |
43 | 0 | return result; |
44 | } | |
45 | ||
46 | public boolean hasChildren(Widget w) { | |
47 | 115718 | List resolvers = resolver.getResolvers(w.getClass()); |
48 | 293413 | for (Iterator iterator = resolvers.iterator(); iterator.hasNext();) { |
49 | 113740 | IChildrenResolver resolver = (IChildrenResolver) iterator.next(); |
50 | 113740 | if (resolver.canResolve(w) && resolver.hasChildren(w)) |
51 | 51763 | return true; |
52 | } | |
53 | ||
54 | 63955 | return false; |
55 | } | |
56 | ||
57 | } |