package org.odlabs.wiquery.core.util;

import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.Component.IVisitor;

/**
 * $Id$
 * <p>
 * Class to retrieve the Wicket component with the specified markup identifiant
 * </p>
 * 
 * @author Julien Roche
 * @since 1.0
 */
public class MarkupIdVisitor implements IVisitor<Component> {
	// Properties
	private String id;
	private Component foundComponent;

	/**Constructor
	 * @param id Markup identifiant
	 */
	public MarkupIdVisitor(String id) {
		this.id = id;
	}
	
	/* (non-Javadoc)
	 * @see org.apache.wicket.Component.IVisitor#component(org.apache.wicket.Component)
	 */
	public Object component(Component component) {
		if (component.getMarkupId().equals(this.id)) {
			this.foundComponent = component;
			return IVisitor.STOP_TRAVERSAL;
		}
		if (component instanceof MarkupContainer) {
			return ((MarkupContainer) component).visitChildren(this);
		}
		return IVisitor.CONTINUE_TRAVERSAL;
	}

	/**
	 * @return the markup identifiant
	 */
	public String getId() {
		return id;
	}

	/**
	 * @return the Wicket component that have been found
	 */
	public Component getFoundComponent() {
		return foundComponent;
	}
}
@@ -838,119 +838,8 @@
 %09%09%7D%0A
-%09%09if (component instanceof MarkupContainer) %7B%0A%09%09%09return ((MarkupContainer) component).visitChildren(this);%0A%09%09%7D%0A
 %09%09re

remove useless visitor, wicket already visits all components.