use of com.github.bordertech.wcomponents.util.visitor.FindComponentByIdVisitor in project wcomponents by BorderTech.
the class TreeUtil method getComponentWithContextForId.
/**
* Retrieves the context for the component with the given Id.
*
* @param root the root component to search from.
* @param id the id to search for.
* @param visibleOnly true if process visible only
* @return the context for the component with the given id, or null if not found.
*/
public static ComponentWithContext getComponentWithContextForId(final WComponent root, final String id, final boolean visibleOnly) {
FindComponentByIdVisitor visitor = new FindComponentByIdVisitor(id);
doTraverse(root, visibleOnly, visitor);
return visitor.getResult();
}
use of com.github.bordertech.wcomponents.util.visitor.FindComponentByIdVisitor in project wcomponents by BorderTech.
the class TreeUtil method getClosestContextForId.
/**
* Retrieves the closest context for the component with the given Id.
*
* @param root the root component to search from.
* @param id the id to search for.
* @param visibleOnly true if process visible only
* @return the closest context for the component with the given id, or null if not found.
*/
public static UIContext getClosestContextForId(final WComponent root, final String id, final boolean visibleOnly) {
FindComponentByIdVisitor visitor = new FindComponentByIdVisitor(id) {
@Override
public VisitorResult visit(final WComponent comp) {
VisitorResult result = super.visit(comp);
if (result == VisitorResult.CONTINUE) {
// Save closest UIC as processing tree
setResult(new ComponentWithContext(comp, UIContextHolder.getCurrent()));
}
return result;
}
};
doTraverse(root, visibleOnly, visitor);
return visitor.getResult() == null ? null : visitor.getResult().getContext();
}
use of com.github.bordertech.wcomponents.util.visitor.FindComponentByIdVisitor in project wcomponents by BorderTech.
the class TreeUtil method isIdFocusable.
/**
* Check if this ID is focusable.
* <p>
* Considered focusable if the component and all its ancestors are visible and not hidden.
* </p>
*
* @param root the root component to search from.
* @param id the id to search for.
* @return the component with context if it is focusable, otherwise null
*/
public static boolean isIdFocusable(final WComponent root, final String id) {
FindComponentByIdVisitor visitor = new FindComponentByIdVisitor(id) {
@Override
public VisitorResult visit(final WComponent comp) {
VisitorResult result = super.visit(comp);
// If hidden then abort branch
if (result == VisitorResult.CONTINUE && comp.isHidden()) {
return VisitorResult.ABORT_BRANCH;
}
return result;
}
};
// Only traverse visible
doTraverse(root, true, visitor);
// Check if matching component is hidden
ComponentWithContext result = visitor.getResult();
return result == null ? false : !result.getComponent().isHidden();
}
Aggregations