/** * Obtains a list of components which are visible in the given tree. Repeated components will be returned multiple * times, one for each row which they are visible in. * * @param comp the root component to search from. * @return a list of components which are visible in the given context. */ public static List<ComponentWithContext> collateVisibles(final WComponent comp) { final List<ComponentWithContext> list = new ArrayList<>(); WComponentTreeVisitor visitor = new WComponentTreeVisitor() { @Override public VisitorResult visit(final WComponent comp) { // In traversing the tree, special components like WInvisbleContainer, WRepeatRoot are still traversed // (so ignore them) if (comp.isVisible()) { list.add(new ComponentWithContext(comp, UIContextHolder.getCurrent())); } return VisitorResult.CONTINUE; } }; traverseVisible(comp, visitor); return list; }
@Override public VisitorResult visit(final WComponent comp) { // In traversing the tree, special components like WInvisbleContainer, WRepeatRoot are still traversed // (so ignore them) if (comp.isVisible()) { list.add(new ComponentWithContext(comp, UIContextHolder.getCurrent())); } return VisitorResult.CONTINUE; } };
@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; } };
boolean cont = handleFoundMatch(new ComponentWithContext(comp, UIContextHolder.getCurrent())); return cont ? VisitorResult.CONTINUE : VisitorResult.ABORT;
/** * {@inheritDoc} */ @Override public VisitorResult visit(final WComponent comp) { // Match if (findId.equals(comp.getId())) { handleFoundMatch(new ComponentWithContext(comp, UIContextHolder.getCurrent())); return VisitorResult.ABORT; } // Check name context. If different, then never match VisitorResult check = checkCorrectNameContext(comp, findId); if (check != null) { return check; } return VisitorResult.CONTINUE; }
matchAtLevel.add(new ComponentWithContext(component, uic));
/** * 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(); }
/** * A convenience method to create an AJAX operation. * * @param target the component to target */ private void setActiveAjaxOperation(final WComponent target) { AjaxOperation operation = new AjaxOperation(target.getId(), target.getId()); AjaxHelper.setCurrentOperationDetails(operation, new ComponentWithContext(target, UIContextHolder.getCurrent())); } }