package org.jboss.reddeer.swt.condition;

import org.jboss.reddeer.common.condition.AbstractWaitCondition;
import org.jboss.reddeer.swt.api.Tree;
import org.jboss.reddeer.swt.impl.tree.DefaultTreeItem;

public class TreeContainsItem extends AbstractWaitCondition {

	private Tree tree;
	private String[] itemPath;

	/**
	 * Constructs TreeContainsItem wait condition. Condition is met when the
	 * specified tree contains the tree item with specified text.
	 * 
	 * @param tree tree where to look for an item
	 * @param item item to find in the specified tree
	 */
	public TreeContainsItem(Tree tree, String... itemPath) {
		this.tree = tree;
		this.itemPath = itemPath;
	}

	@Override
	public boolean test() {
		try{
			new DefaultTreeItem(tree, itemPath);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public String description() {
		return "tree contains item '" + itemPath;
	}

}

@@ -35,16 +35,42 @@
 ition;%0A%0A
+import java.util.Arrays;%0A%0A
 import o
@@ -920,24 +920,40 @@
 em '%22 + 
+Arrays.toString(
 itemPath
 ;%0A%09%7D%0A%0A%7D%0A
@@ -940,20 +940,21 @@
 ing(itemPath
+)
 ;%0A%09%7D%0A%0A%7D%0A

Improve TreeContainsItem description message. Fixes #1438 (#1438)