/** * Creates a ByWComponentPath which searches for a path to a component. * * @param componentWithContext the component to search for. * @param path the path to traverse. * @param visibleOnly only look for components that are visible */ public ByWComponentPath(final ComponentWithContext componentWithContext, final String path, final boolean visibleOnly) { this(componentWithContext.getComponent(), componentWithContext.getContext(), path, visibleOnly); }
matchAtLevel.add(new ComponentWithContext(component, uic)); int index = parts.length == 2 ? Integer.parseInt(parts[1]) : -1; FindComponentsByClassVisitor visitor = new FindComponentsByClassVisitor(comp.getComponent(), className, i == 0); UIContextHolder.pushContext(comp.getContext()); TreeUtil.traverseVisible(comp.getComponent(), visitor); } else { TreeUtil.traverse(comp.getComponent(), visitor);
/** * 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(); }
/** * Retrieves 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 component with the given id, or null if not found. */ public static WComponent getComponentWithId(final WComponent root, final String id, final boolean visibleOnly) { ComponentWithContext comp = getComponentWithContextForId(root, id, visibleOnly); return comp == null ? null : comp.getComponent(); }
/** * 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 UIContext getContextForId(final WComponent root, final String id, final boolean visibleOnly) { ComponentWithContext comp = getComponentWithContextForId(root, id, visibleOnly); return comp == null ? null : comp.getContext(); }
@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; } };
/** * 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(); }
/** * {@inheritDoc} */ @Override public void preparePaint(final Request request) { ComponentWithContext target = WebUtilities.getComponentById(targetId, true); if (target == null) { throw new SystemException("No target component found for id " + targetId); } UIContextHolder.pushContext(target.getContext()); try { super.preparePaint(request); } finally { UIContextHolder.popContext(); } }
/** * 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; }
/** * Creates a ByWComponentPath which searches for a path to a component. * * @param componentWithContext the component to search for. * @param path the path to traverse. */ public ByWComponentPath(final ComponentWithContext componentWithContext, final String path) { this(componentWithContext.getComponent(), componentWithContext.getContext(), path); }
throw new SystemException("No component found for AJAX trigger " + triggerId + "."); WComponent triggerComponent = trigger.getComponent(); if (ajaxOperation == null && trigger.getComponent() instanceof AjaxInternalTrigger) {
/** * {@inheritDoc} */ @Override public void paint(final RenderContext renderContext) { ComponentWithContext target = WebUtilities.getComponentById(targetId, true); if (target == null) { throw new SystemException("No target component found for id " + targetId); } UIContextHolder.pushContext(target.getContext()); try { super.paint(renderContext); } finally { UIContextHolder.popContext(); } }
boolean cont = handleFoundMatch(new ComponentWithContext(comp, UIContextHolder.getCurrent())); return cont ? VisitorResult.CONTINUE : VisitorResult.ABORT;
/** * Creates a ByWComponent which searches for a component instance in the given context. If searching for a repeated * component, the <code>context</code> should be the row context for the row you want to return. * * @param componentWithContext the component to search for. */ public ByWComponent(final ComponentWithContext componentWithContext) { this(componentWithContext.getComponent(), componentWithContext.getContext(), null); }
ComponentWithContext target = WebUtilities.getComponentById(targetId, true); if (target != null) { writeDebugInfo(target.getComponent(), xml);
/** * Temporarily replaces the environment while the UI prepares to render. * * @param request the request being responded to. */ @Override public void preparePaint(final Request request) { if (windowId == null) { super.preparePaint(request); } else { // Get the window component ComponentWithContext target = WebUtilities.getComponentById(windowId, true); if (target == null) { throw new SystemException("No window component for id " + windowId); } UIContext uic = UIContextHolder.getCurrentPrimaryUIContext(); Environment originalEnvironment = uic.getEnvironment(); uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target)); UIContextHolder.pushContext(target.getContext()); try { super.preparePaint(request); } finally { uic.setEnvironment(originalEnvironment); UIContextHolder.popContext(); } } }
@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; } };
/** * Indicates whether the list contains the given component and context. * * @param components the list of components to check. * @param component the component to search for. * @param uic the component context to search for. * @return true if the component is in the list with the given context, false otherwise. */ private boolean isInList(final List<ComponentWithContext> components, final WComponent component, final UIContext uic) { for (ComponentWithContext comp : components) { if (comp.getComponent() == component && comp.getContext() == uic) { return true; } } return false; }
@Test public void testRefocusWDropdown() { SeleniumWComponentsWebDriver driver = getDriver(); String path = "WDropdownSubmitOnChangeExample/WDropdown[0]"; driver.findWDropdown(byWComponentPath(path)).click(); UIContext uic = getUserContextForSession(); UIContextHolder.pushContext(uic); try { // The dropdowns in the example need something to be selected to trigger the submit WComponent comp = TreeUtil.findWComponent(getUi(), path.split("/")).getComponent(); if (comp instanceof WDropdown) { WDropdown dropdown = (WDropdown) comp; driver.findElement(byWComponentPath(path, dropdown.getOptions().get(1))).click(); } } finally { UIContextHolder.popContext(); } Assert.assertEquals("Incorrect focus", driver.findWDropdown(byWComponentPath(path)).getActiveId(), driver.switchTo(true).activeElement().getAttribute("id")); } }
/** * Temporarily replaces the environment while the UI is being rendered. * * @param renderContext the context to render to. */ @Override public void paint(final RenderContext renderContext) { if (windowId == null) { super.paint(renderContext); } else { // Get the window component ComponentWithContext target = WebUtilities.getComponentById(windowId, true); if (target == null) { throw new SystemException("No window component for id " + windowId); } UIContext uic = UIContextHolder.getCurrentPrimaryUIContext(); Environment originalEnvironment = uic.getEnvironment(); uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target)); UIContextHolder.pushContext(target.getContext()); try { super.paint(renderContext); } finally { uic.setEnvironment(originalEnvironment); UIContextHolder.popContext(); } } }