Java Code Examples for org.apache.wicket.MarkupContainer#visitChildren()
The following examples show how to use
org.apache.wicket.MarkupContainer#visitChildren() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WicketPageTestBase.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
/** * Searches ContentMenuEntryPanels. * @param container * @param accessKey * @return Found component with the given label or null if no such component found. * @see FormComponent#getModelObject() * @see LabeledWebMarkupContainer#getLabel() * @see ContentMenuEntryPanel#getLabel() */ public Component findComponentByAccessKey(final MarkupContainer container, final char accessKey) { final Component[] component = new Component[1]; container.visitChildren(new IVisitor<Component, Void>() { @Override public void component(final Component object, final IVisit<Void> visit) { if (object instanceof AbstractLink) { final AbstractLink link = (AbstractLink) object; final AttributeModifier attrMod = WicketUtils.getAttributeModifier(link, "accesskey"); if (attrMod == null || attrMod.toString().contains("object=[n]") == false) { return; } component[0] = object; visit.stop(); } } }); return component[0]; }
Example 2
Source File: WicketPageTestBase.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * Searches FormComponents (model object), LabeledWebmarkupContainers (label model) and ContentMenuEntryPanels (label). * @param container * @param label i18n key of the label or label (for buttons). * @return Found component with the given label or null if no such component found. * @see FormComponent#getModelObject() * @see LabeledWebMarkupContainer#getLabel() * @see ContentMenuEntryPanel#getLabel() */ public Component findComponentByLabel(final MarkupContainer container, final String label) { String str = label; try { str = container.getString(label); } catch (final MissingResourceException ex) { // OK } final String locLabel = str; final Component[] component = new Component[1]; container.visitChildren(new IVisitor<Component, Void>() { @Override public void component(final Component object, final IVisit<Void> visit) { if (object instanceof AbstractLink) { final MarkupContainer parent = object.getParent(); if (parent instanceof ContentMenuEntryPanel) { if (labelEquals(((ContentMenuEntryPanel) parent).getLabel(), label, locLabel) == true) { component[0] = object; visit.stop(); } } else if (object.getId().equals(locLabel) == true) { component[0] = object; visit.stop(); } } else { if (object instanceof LabeledWebMarkupContainer) { final IModel<String> labelModel = ((LabeledWebMarkupContainer) object).getLabel(); if (labelModel != null) { if (labelEquals(labelModel.getObject(), label, locLabel) == true) { component[0] = object; visit.stop(); } } } if (object instanceof FormComponent< ? >) { final Object modelObject = ((FormComponent< ? >) object).getModelObject(); if (modelObject instanceof String) { if (labelEquals((String) modelObject, label, locLabel) == true) { component[0] = object; visit.stop(); } } } } } }); return component[0]; }