Example usage for org.apache.wicket MarkupContainer visitChildren

List of usage examples for org.apache.wicket MarkupContainer visitChildren

Introduction

In this page you can find the example usage for org.apache.wicket MarkupContainer visitChildren.

Prototype

public final <S extends Component, R> R visitChildren(final Class<?> clazz, final IVisitor<S, R> visitor) 

Source Link

Document

Traverses all child components of the given class in this container, calling the visitor's visit method at each one.

Usage

From source file:com.evolveum.midpoint.gui.api.util.WebComponentUtil.java

License:Apache License

public static void refreshFeedbacks(MarkupContainer component, final AjaxRequestTarget target) {
    component.visitChildren(IFeedback.class, new IVisitor<Component, Void>() {

        @Override//from  ww w.  j  a  v  a 2s.c om
        public void component(final Component component, final IVisit<Void> visit) {
            target.add(component);
        }
    });
}

From source file:com.googlecode.wicketwebbeans.model.ComponentRegistry.java

License:Apache License

/**
 * Associate label with FormComponents that are descendants of component. 
 *
 * @param propertyMeta//from ww  w . ja  v a2  s.c  om
 * @param component
 */
private void associateLabelToFormComponents(final ElementMetaData propertyMeta, Component component) {
    if (component instanceof MarkupContainer) {
        MarkupContainer container = (MarkupContainer) component;
        container.visitChildren(FormComponent.class, new IVisitor<Component>() {
            public Object component(Component component) {
                FormComponent formComponent = (FormComponent) component;
                formComponent.setLabel(new Model(propertyMeta.getLabel()));
                formComponent.add(new ErrorHighlightingBehavior());
                return IVisitor.CONTINUE_TRAVERSAL;
            }
        });
    }
}

From source file:com.servoy.j2db.server.headlessclient.DesignModeBehavior.java

License:Open Source License

/**
 * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(org.apache.wicket.ajax.AjaxRequestTarget)
 *///w  ww  .  ja va  2  s .c  o  m
@Override
protected void respond(AjaxRequestTarget target) {
    Request request = RequestCycle.get().getRequest();
    String action = request.getParameter(DraggableBehavior.PARAM_ACTION);
    String id = extractId(request.getParameter(DraggableBehavior.PARAM_DRAGGABLE_ID));
    if (id != null) {
        final String finalId = id.endsWith(TemplateGenerator.WRAPPER_SUFFIX) ? id.substring(0, id.length() - 8)
                : id;
        MarkupContainer comp = (MarkupContainer) getComponent();
        Component child = (Component) comp.visitChildren(Component.class, new IVisitor<Component>() {
            public Object component(Component component) {
                String markupId = component.getMarkupId();
                if (finalId.equals(markupId))
                    return component;
                return IVisitor.CONTINUE_TRAVERSAL;
            }
        });
        if (action != null) {
            int height = stripUnitPart(request.getParameter(PARAM_RESIZE_HEIGHT));
            int width = stripUnitPart(request.getParameter(PARAM_RESIZE_WIDTH));
            int x = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_X));
            int y = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_Y));

            if (action.equals(ACTION_SELECT)) {
                if (!(child instanceof IComponent))
                    onSelectComponents.clear();
                else {
                    boolean isSelectionRemove = false;
                    if (!Boolean.parseBoolean(request.getParameter(PARAM_IS_CTRL_KEY)))
                        onSelectComponents.clear();
                    else {
                        isSelectionRemove = onSelectComponents.remove(child) != null;
                    }

                    IComponent[] param = onSelectComponents.keySet()
                            .toArray(new IComponent[isSelectionRemove ? onSelectComponents.size()
                                    : onSelectComponents.size() + 1]);
                    if (!isSelectionRemove)
                        param[onSelectComponents.size()] = (IComponent) child;

                    Object ret = callback
                            .executeOnSelect(getJSEvent(EventType.action, 0, new Point(x, y), param));
                    if (ret instanceof Boolean && !((Boolean) ret).booleanValue()) {
                        onSelectComponents.clear();
                    } else {
                        if (!isSelectionRemove)
                            onSelectComponents.put((IComponent) child, id);
                        StringBuilder idsArray = new StringBuilder("new Array(");
                        Iterator<String> idsIte = onSelectComponents.values().iterator();
                        while (idsIte.hasNext()) {
                            idsArray.append('\'').append(idsIte.next()).append('\'');
                            if (idsIte.hasNext())
                                idsArray.append(',');
                        }
                        idsArray.append(')');
                        target.appendJavascript(
                                "Servoy.ClientDesign.attachElements(" + idsArray.toString() + ");");

                    }
                    if (Boolean.parseBoolean(request.getParameter(PARAM_IS_RIGHTCLICK))) {
                        callback.executeOnRightClick(
                                getJSEvent(EventType.rightClick, 0, new Point(x, y), param));
                    } else if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
                        callback.executeOnDblClick(
                                getJSEvent(EventType.doubleClick, 0, new Point(x, y), param));
                    }
                }

                WebEventExecutor.generateResponse(target, getComponent().getPage());
                target.appendJavascript("Servoy.ClientDesign.clearClickTimer();");
                return;
            }

            if (child instanceof IComponent) {
                if (!onSelectComponents.containsKey(child)) {
                    onSelectComponents.put((IComponent) child, id);
                }
                if (action.equals(ACTION_RESIZE)) {
                    if (width != -1 && height != -1) {
                        if (child instanceof ISupportWebBounds) {
                            Insets paddingAndBorder = ((ISupportWebBounds) child).getPaddingAndBorder();
                            if (paddingAndBorder != null) {
                                height += paddingAndBorder.bottom + paddingAndBorder.top;
                                width += paddingAndBorder.left + paddingAndBorder.right;
                            }
                        }
                        if (child instanceof IScriptableProvider) {
                            ((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setSize(width,
                                    height);
                            ((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x,
                                    y);
                        }
                        if (child instanceof IProviderStylePropertyChanges)
                            ((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
                    }
                    callback.executeOnResize(getJSEvent(EventType.onDrop, 0, new Point(x, y),
                            new IComponent[] { (IComponent) child }));
                } else if (action.equals(DraggableBehavior.ACTION_DRAG_START)) {
                    Object onDragAllowed = callback.executeOnDrag(getJSEvent(EventType.onDrag, 0,
                            new Point(x, y),
                            onSelectComponents.keySet().toArray(new IComponent[onSelectComponents.size()])));
                    if ((onDragAllowed instanceof Boolean && !((Boolean) onDragAllowed).booleanValue())
                            || (onDragAllowed instanceof Number
                                    && ((Number) onDragAllowed).intValue() == DRAGNDROP.NONE)) {
                        onDragComponent = null;
                    } else {
                        onDragComponent = (IComponent) child;
                    }
                    WebEventExecutor.generateResponse(target, getComponent().getPage());
                    return;
                } else {
                    if (child == onDragComponent) {
                        if (x != -1 && y != -1) {
                            ((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x,
                                    y);
                            if (child instanceof IProviderStylePropertyChanges) {
                                // test if it is wrapped
                                if ((child).getParent() instanceof WrapperContainer) {
                                    // call for the changes on the wrapper container so that it will copy the right values over
                                    WrapperContainer wrapper = (WrapperContainer) (child).getParent();
                                    wrapper.getStylePropertyChanges().getChanges();
                                    wrapper.getStylePropertyChanges().setRendered();

                                }
                                ((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
                            }
                        }
                        callback.executeOnDrop(
                                getJSEvent(EventType.onDrop, 0, new Point(x, y), onSelectComponents.keySet()
                                        .toArray(new IComponent[onSelectComponents.size()])));
                    }

                    if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
                        callback.executeOnDblClick(getJSEvent(EventType.doubleClick, 0, new Point(x, y),
                                new IComponent[] { (IComponent) child }));
                    }
                }
            }
        }
    }
    WebEventExecutor.generateResponse(target, getComponent().getPage());
    target.appendJavascript("Servoy.ClientDesign.reattach();");
}

From source file:com.wiquery.plugins.jqgrid.component.XMLDataRequestTarget.java

License:Apache License

/**
 * Visits all children of the specified parent container and adds them to the target if they are
 * of same type as <code>childCriteria</code>
 * // ww  w  .j  a va2s . c o  m
 * @param parent
 * @param childCriteria
 */
public final void addChildren(MarkupContainer parent, Class<?> childCriteria) {
    if (parent == null) {
        throw new IllegalArgumentException("Argument `parent` cannot be null");
    }
    if (childCriteria == null) {
        throw new IllegalArgumentException(
                "Argument `childCriteria` cannot be null. If you want to traverse all components use `"
                        + Component.class.getName() + ".class` as the value for this argument");
    }

    parent.visitChildren(childCriteria, new Component.IVisitor<Component>() {

        public Object component(Component component) {
            addComponent(component);
            return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
        }
    });
}

From source file:net.rrm.ehour.ui.common.event.EventPublisher.java

License:Open Source License

/**
 * Publish ajax event to children of parent container
 *
 * @param parent//from w ww.  jav a2 s .co m
 * @param event
 */
public static void publishAjaxEventToParentChildren(MarkupContainer parent, AjaxEvent event) {
    notifyHook(event);

    parent.visitChildren(AjaxEventListener.class, new AjaxEventVisitor(event));
}

From source file:org.artifactory.common.wicket.util.ComponentPersister.java

License:Open Source License

public static void loadChildren(MarkupContainer container) {
    container.visitChildren(FormComponent.class, new IVisitor<FormComponent, Void>() {
        @Override/*w w  w  .j  a  va2 s . c  o  m*/
        public void component(FormComponent formComponent, IVisit iVisit) {
            if (isPersistent(formComponent)) {
                load(formComponent);
            }
        }
    });
}

From source file:org.artifactory.common.wicket.util.ComponentPersister.java

License:Open Source License

public static void saveChildren(MarkupContainer container) {
    container.visitChildren(FormComponent.class, new IVisitor<FormComponent, Void>() {
        @Override// w w w . j  a  va2 s  . c o m
        public void component(FormComponent formComponent, IVisit iVisit) {
            if (isPersistent(formComponent)) {
                save(formComponent);
            }
        }
    });
}

From source file:org.geoserver.web.GeoServerWicketTestSupport.java

License:Open Source License

/**
 * Finds the component whose model value equals to the specified content, and
 * the component class is equal, subclass or implementor of the specified class
 * @param root the component under which the search is to be performed
 * @param content /* ww  w  .  j  a  v  a2  s  .c  o m*/
 * @param componentClass the target class, or null if any component will do
 * @return
 */
public Component findComponentByContent(MarkupContainer root, Object content, Class componentClass) {
    ComponentContentFinder finder = new ComponentContentFinder(content);
    root.visitChildren(componentClass, finder);
    return finder.candidate;
}

From source file:org.hippoecm.addon.workflow.MenuButton.java

License:Apache License

MenuButton(String id, String name, final MenuHierarchy menu, final List<MenuDescription> descriptions,
        IPluginConfig config) {//w w  w. j a  v  a 2s . c  o  m
    super(id);
    setOutputMarkupId(true);
    add(content = new MenuList("item", menu, config));
    content.setOutputMarkupId(true);
    content.setVisible(false);

    AbstractLink link;
    add(link = new AjaxLink("link") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners().add(new EventStoppingDecorator());
        }

        void updateContent() {
            if (descriptions != null) {
                menu.clear();
                MenuVisitor visitor = new MenuVisitor(menu, "list");
                for (MenuDescription description : descriptions) {
                    MarkupContainer descriptionContent = description.getContent();
                    if (descriptionContent != null) {
                        descriptionContent.visitChildren(Panel.class, visitor);
                    }
                }
                menu.flatten();
                content.update();
            }
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            content.setVisible(!content.isVisible());
            target.add(MenuButton.this);
            if (content.isVisible()) {
                updateContent();
                IContextMenuManager manager = getContextMenuManager();
                manager.showContextMenu(MenuButton.this);
            }
        }
    });

    link.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            return content.isVisible() ? "menu-item-active" : "menu-item-inactive";
        }
    }, " "));

    Component label = null;
    if (descriptions != null) {
        label = descriptions.get(0).getLabel();
    }
    if (label == null) {
        link.add(new Label("label", new ResourceBundleModel("hippo:workflows", name, name)));
    } else {
        if (!"label".equals(label.getId())) {
            throw new WicketRuntimeException(
                    "Menu label component doesn't have correct id.  Should be 'label', but was '"
                            + label.getId() + "'");
        }
        link.add(label);
    }

    link.add(HippoIcon.fromSprite("icon", Icon.CHEVRON_DOWN, IconSize.S));
}

From source file:org.hippoecm.frontend.editor.workflow.MenuTester.java

License:Apache License

static IDataProvider getProvider(final MarkupContainer container) {
    return new IDataProvider() {
        private static final long serialVersionUID = 1L;

        private List<WorkflowAction> list;

        @Override/*  ww  w .j  a va  2s. co  m*/
        public Iterator iterator(final long first, final long count) {
            attach();

            long toIndex = first + count;
            if (toIndex > list.size()) {
                toIndex = list.size();
            }
            return list.subList((int) first, (int) toIndex).listIterator();
        }

        @Override
        public IModel model(Object object) {
            return new Model((Serializable) object);
        }

        @Override
        public long size() {
            attach();
            return list.size();
        }

        @SuppressWarnings({ "unchecked", "deprecation" })
        void attach() {
            if (list == null) {
                list = new LinkedList<WorkflowAction>();
                container.visitChildren(WorkflowAction.class, new IVisitor<WorkflowAction, Void>() {

                    @Override
                    public void component(WorkflowAction component, IVisit<Void> visit) {
                        list.add(component);
                    }
                });
            }
        }

        @Override
        public void detach() {
            list = null;
        }

    };
}