List of usage examples for org.apache.wicket MarkupContainer visitChildren
public final <R> R visitChildren(final IVisitor<Component, R> visitor)
From source file:com.francetelecom.clara.cloud.presentation.utils.PaasWicketTester.java
License:Apache License
public String lookupPath(final MarkupContainer markupContainer, final String path) { // try to look it up directly if (markupContainer.get(path) != null) return path; // if that fails, traverse the component hierarchy looking for it final List<Component> candidates = new ArrayList<Component>(); markupContainer.visitChildren(new IVisitor<Component, List<Component>>() { Set<Component> visited = new HashSet<Component>(); @Override//from w ww .ja v a 2 s .c o m public void component(Component c, IVisit<List<Component>> visit) { if (!visited.contains(c)) { visited.add(c); if (c.getId().equals(path)) { candidates.add(c); } else { if (c.getPath().endsWith(path)) { candidates.add(c); } } } } }); // if its unambiguous, then return the full path if (candidates.isEmpty()) { fail("path: '" + path + "' not found for " + Classes.simpleName(markupContainer.getClass())); return null; } else if (candidates.size() == 1) { String pathToContainer = markupContainer.getPath(); String pathToComponent = candidates.get(0).getPath(); return pathToComponent.replaceFirst(pathToContainer + ":", ""); } else { String message = "path: '" + path + "' is ambiguous for " + Classes.simpleName(markupContainer.getClass()) + ". Possible candidates are: "; for (Component c : candidates) { message += "[" + c.getPath() + "]"; } fail(message); return null; } }
From source file:com.googlecode.wicketwebbeans.containers.BeanForm.java
License:Apache License
private void refreshComponent(final AjaxRequestTarget target, Component targetComponent) { // Refresh this field. We have to find the parent Field to do this. MarkupContainer field; if (targetComponent instanceof Field) { field = (MarkupContainer) targetComponent; } else {/*from w w w .j a v a 2 s . c om*/ field = targetComponent.findParent(AbstractField.class); } if (field != null) { if (!field.getRenderBodyOnly()) { target.addComponent(field); } else { // Field is RenderBodyOnly, have to add children individually field.visitChildren(new IVisitor<Component>() { public Object component(Component component) { if (!component.getRenderBodyOnly()) { target.addComponent(component); } return IVisitor.CONTINUE_TRAVERSAL; } }); } } else { target.addComponent(targetComponent); } }
From source file:com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.java
License:Open Source License
private void enableChildrenInContainer(MarkupContainer container, final boolean b) { container.visitChildren(new IVisitor<Component>() { public Object component(Component component) { if (component.isEnabled() != b) { if (component instanceof IComponent) { if (b) { // component may be disabled by scripting, do not enable it return CONTINUE_TRAVERSAL; }/*from w w w . j av a 2 s .c om*/ ((IComponent) component).setComponentEnabled(b); } else { component.setEnabled(b); } } return CONTINUE_TRAVERSAL; } }); }
From source file:com.userweave.components.notification.AjaxUpdateEvent.java
License:Open Source License
private void visitComponents(MarkupContainer page) { NotifyVisitor visitor = new NotifyVisitor(this); visitor.component(page, new Visit<Void>()); page.visitChildren(visitor); }
From source file:de.micromata.genome.junittools.wicket.TpsbWicketTools.java
License:Apache License
/** * Internal finder./*from www . j av a 2 s. c o m*/ * * @param <X> the generic type * @param tester the tester * @param startComponent the start component * @param componentClass the component class * @param matcher the matcher * @return the list */ private static <X extends Component> List<X> internalFinder(WicketTester tester, MarkupContainer startComponent, Class<X> componentClass, final Matcher<Component> matcher) { final List<X> results = new LinkedList<X>(); Page lastRenderedPage = tester.getLastRenderedPage(); if (lastRenderedPage == null) { throw new IllegalStateException("You must call #goToPage before you can find components."); } if (componentClass == null) { componentClass = (Class<X>) Component.class; } final Class<? extends Component> searchComponent = componentClass; IVisitor<Component, Object> visitor = new IVisitor<Component, Object>() { @Override public void component(Component object, IVisit<Object> visit) { if (LOG.isDebugEnabled() == true) { LOG.debug("candite for wicket internalFinder: " + object.getClass().getSimpleName() + "|" + object.getId() + "|" + object.getPath()); } if (searchComponent.isAssignableFrom(object.getClass()) == true) { if (matcher.match(object) == true) { if (matcher instanceof TpsbWicketMatchSelector) { results.add((X) ((TpsbWicketMatchSelector) matcher).selectMatched(object)); } else { results.add((X) object); } } } } }; if (startComponent == null) { lastRenderedPage.visitChildren(visitor); } else { startComponent.visitChildren(visitor); } return results; }
From source file:de.micromata.genome.junittools.wicket.TpsbWicketTools.java
License:Apache License
/** * Find components for property model property. * //www . j av a2s . co m * @param <X> the generic type * @param tester the tester * @param startComponent the start component * @param componentClass the component class * @param property the property * @return the list * @deprecated use TpsbWicketMatchSelector */ @Deprecated public static <X extends Component> List<X> _findComponentsForPropertyModelProperty(WicketTester tester, final MarkupContainer startComponent, final Class<X> componentClass, final String property) { final List<X> results = new LinkedList<X>(); Page lastRenderedPage = tester.getLastRenderedPage(); if (lastRenderedPage == null) { throw new IllegalStateException("You must call #goToPage before you can find components."); } if (componentClass == null || property == null) { throw new IllegalArgumentException("You must provide not null arguments."); } IVisitor<Component, Object> visitor = new IVisitor<Component, Object>() { @Override public void component(Component object, IVisit<Object> visit) { if (LOG.isDebugEnabled() == true) { LOG.debug("candite for wicket internalFinder: " + object.getClass().getSimpleName() + "|" + object.getId() + "|" + object.getPath()); } if (componentClass.isAssignableFrom(object.getClass()) == true) { IModel<?> defaultModel = object.getDefaultModel(); if (defaultModel instanceof AbstractPropertyModel == true) { AbstractPropertyModel propertyModel = (AbstractPropertyModel) defaultModel; if (StringUtils.equals(property, propertyModel.getPropertyExpression()) == true) { results.add((X) object); } } } } }; if (startComponent == null) { lastRenderedPage.visitChildren(visitor); } else { startComponent.visitChildren(visitor); } return results; }
From source file:org.apache.isis.viewer.wicket.ui.panels.FormExecutorDefault.java
License:Apache License
private void addComponentsToRedraw(final AjaxRequestTarget target) { final List<Component> componentsToRedraw = Lists.newArrayList(); final List<Component> componentsNotToRedraw = Lists.newArrayList(); final Page page = target.getPage(); page.visitChildren(new IVisitor<Component, Object>() { @Override/*from www. ja va2 s .co m*/ public void component(final Component component, final IVisit<Object> visit) { if (component.getOutputMarkupId() && !(component instanceof Page)) { List<Component> listToAddTo = shouldRedraw(component) ? componentsToRedraw : componentsNotToRedraw; listToAddTo.add(component); } } private boolean shouldRedraw(final Component component) { // hmm... this doesn't work, because I think that the components // get removed after they've been added to target. // so.. still getting WARN log messages from XmlPartialPageUpdate // final Page page = component.findParent(Page.class); // if(page == null) { // // as per logic in XmlPartialPageUpdate, this has already been // // removed from page so don't attempt to redraw it // return false; // } final Object defaultModel = component.getDefaultModel(); if (!(defaultModel instanceof ScalarModel)) { return true; } final ScalarModel scalarModel = (ScalarModel) defaultModel; final UnchangingFacet unchangingFacet = scalarModel.getFacet(UnchangingFacet.class); return unchangingFacet == null || !unchangingFacet.value(); } }); for (Component componentNotToRedraw : componentsNotToRedraw) { MarkupContainer parent = componentNotToRedraw.getParent(); while (parent != null) { parent = parent.getParent(); } componentNotToRedraw.visitParents(MarkupContainer.class, new IVisitor<MarkupContainer, Object>() { @Override public void component(final MarkupContainer parent, final IVisit<Object> visit) { componentsToRedraw.remove(parent); // no-op if not in that list } }); if (componentNotToRedraw instanceof MarkupContainer) { final MarkupContainer containerNotToRedraw = (MarkupContainer) componentNotToRedraw; containerNotToRedraw.visitChildren(new IVisitor<Component, Object>() { @Override public void component(final Component parent, final IVisit<Object> visit) { componentsToRedraw.remove(parent); // no-op if not in that list } }); } } if (LOG.isDebugEnabled()) { debug(componentsToRedraw, componentsNotToRedraw); } for (Component component : componentsToRedraw) { target.add(component); } }
From source file:org.artifactory.addon.wicket.WicketAddonsImpl.java
License:Open Source License
private static void disableAll(MarkupContainer container) { container.setEnabled(false);/*from w ww .j a va 2 s . c o m*/ container.visitChildren(new SetEnableVisitor(false)); }
From source file:org.dcm4chee.web.common.markup.BaseForm.java
License:LGPL
public static void addFormComponentsToAjaxRequestTarget(final AjaxRequestTarget target, final MarkupContainer form) { IVisitor<Component> visitor = new IVisitor<Component>() { public Object component(Component c) { if (c.getOutputMarkupId()) { target.addComponent(c);/*from w ww. j a v a 2 s . c o m*/ } return IVisitor.CONTINUE_TRAVERSAL; } }; form.visitChildren(visitor); }
From source file:org.hippoecm.frontend.plugins.yui.layout.WireframeBehavior.java
License:Apache License
@Override protected void onRenderHead(final IHeaderResponse response) { if (isRendered()) { return;/*from w w w . j a v a 2s . c om*/ } final String markupId = getComponent().getMarkupId(true); updateAjaxSettings(); settings.setMarkupId(markupId); IWireframe parentWireframe = getParentWireframe(); if (parentWireframe != null) { settings.setParentId(parentWireframe.getYuiId()); } //Visit child components in order to find components that contain a {@link UnitBehavior}. If another wireframe //or unit is encountered, stop going deeper. MarkupContainer cont = (MarkupContainer) getComponent(); cont.visitChildren(new IVisitor<Component, Void>() { public void component(Component component, IVisit<Void> visit) { for (Object behavior : component.getBehaviors()) { if (behavior instanceof IWireframe) { visit.dontGoDeeper(); } else if (behavior instanceof UnitBehavior) { String position = ((UnitBehavior) behavior).getPosition(); UnitSettings unit = settings.getUnit(position); if (unit != null) { YuiId body = unit.getBody(); if (body != null) { body.setParentId(null); body.setId(component.getMarkupId()); } } else { throw new RuntimeException("Invalid UnitBehavior position " + position); } visit.dontGoDeeper(); } } } }); rendered = true; response.render(getHeaderItem()); }