Example usage for org.apache.wicket.markup.html WebMarkupContainer iterator

List of usage examples for org.apache.wicket.markup.html WebMarkupContainer iterator

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html WebMarkupContainer iterator.

Prototype

@Override
public Iterator<Component> iterator() 

Source Link

Document

Gives an iterator that allow you to iterate through the children of this markup container in the order the children were added.

Usage

From source file:au.org.theark.core.web.form.AbstractArchiveDetailForm.java

License:Open Source License

protected void initialiseForm() {

    cancelButton = new AjaxButton(Constants.CANCEL) {

        private static final long serialVersionUID = 1L;

        @Override//w ww . ja  v a 2 s . c  om
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (isNew()) {
                editCancelProcess(target);
            } else {
                crudVO.getSearchResultPanelContainer().setVisible(true);// Hide the Search Result List Panel via the WebMarkupContainer
                crudVO.getDetailPanelContainer().setVisible(false);// Hide the Detail Panle via the WebMarkupContainer
                target.add(crudVO.getDetailPanelContainer());
                target.add(crudVO.getSearchResultPanelContainer());// Attach the resultListContainer WebMarkupContainer to be re-rendered
                onCancelPostProcess(target);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget arg0, Form<?> arg1) {

        }
    };

    saveButton = new AjaxButton(Constants.SAVE) {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return ArkPermissionHelper.isActionPermitted(Constants.SAVE);
        }

        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onSave(containerForm, target);
            target.add(crudVO.getDetailPanelContainer());
        }

        @SuppressWarnings("unchecked")
        public void onError(AjaxRequestTarget target, Form<?> form) {
            boolean setFocusError = false;
            WebMarkupContainer wmc = (WebMarkupContainer) form.get("detailFormContainer");
            for (Iterator iterator = wmc.iterator(); iterator.hasNext();) {
                Component component = (Component) iterator.next();
                if (component instanceof FormComponent) {
                    FormComponent formComponent = (FormComponent) component;

                    if (!formComponent.isValid()) {
                        if (!setFocusError) {
                            // Place focus on field in error (for the first field in error)
                            target.focusComponent(formComponent);
                            setFocusError = true;
                        }
                    }
                }
            }

            processErrors(target);
        }
    };

    addComponentsToForm();
}

From source file:au.org.theark.core.web.form.AbstractDetailForm.java

License:Open Source License

/**
 * Method to handle Save action, and handle for any errors, placing forcus on any component in error
 * /*  w  w  w .java2 s. c o m*/
 * @param target
 */
@SuppressWarnings("unchecked")
protected void saveOnErrorProcess(AjaxRequestTarget target) {
    boolean setFocusError = false;
    WebMarkupContainer wmc = arkCrudContainerVO.getDetailPanelContainer();
    for (Iterator iterator = wmc.iterator(); iterator.hasNext();) {
        Component component = (Component) iterator.next();
        if (component instanceof FormComponent) {
            FormComponent formComponent = (FormComponent) component;

            if (!formComponent.isValid()) {
                if (!setFocusError) {
                    // Place focus on field in error (for the first field in error)
                    target.focusComponent(formComponent);
                    setFocusError = true;
                }
            }
        }
    }

    processErrors(target);
}

From source file:au.org.theark.core.web.form.AbstractModalDetailForm.java

License:Open Source License

protected void saveOnErrorProcess(AjaxRequestTarget target) {
    boolean setFocusError = false;
    WebMarkupContainer wmc = arkCrudContainerVo.getDetailPanelFormContainer();
    for (Iterator iterator = wmc.iterator(); iterator.hasNext();) {
        Component component = (Component) iterator.next();
        if (component instanceof FormComponent) {
            FormComponent formComponent = (FormComponent) component;

            if (!formComponent.isValid()) {
                if (!setFocusError) {
                    // Place focus on field in error (for the first field in error)
                    target.focusComponent(formComponent);
                    setFocusError = true;
                }/*from   ww  w  .j a va 2 s .  co  m*/
            }
        }
    }
    target.focusComponent(feedbackPanel);
    processErrors(target);
}

From source file:au.org.theark.lims.web.component.inventory.form.AbstractInventoryDetailForm.java

License:Open Source License

/**
 * Initialise the form, with the general edit/save/cancel/delete buttons
 * /*  ww  w  .jav  a 2 s.c o  m*/
 */
protected void initialiseForm() {
    cancelButton = new AjaxButton(Constants.CANCEL) {

        private static final long serialVersionUID = 1684005199059571017L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            detailContainer.setVisible(false);
            target.add(detailContainer);
            processErrors(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }
    };

    saveButton = new ArkBusyAjaxButton(Constants.SAVE) {

        private static final long serialVersionUID = -423605230448635419L;

        @Override
        public boolean isVisible() {
            return ArkPermissionHelper.isActionPermitted(Constants.SAVE);
        }

        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onSave(containerForm, target);
            target.add(detailFormContainer);
            target.add(containerPanel);
        }

        @SuppressWarnings("unchecked")
        public void onError(AjaxRequestTarget target, Form<?> form) {
            boolean setFocusError = false;
            WebMarkupContainer wmc = (WebMarkupContainer) form.get("detailFormContainer");
            for (Iterator iterator = wmc.iterator(); iterator.hasNext();) {
                Component component = (Component) iterator.next();
                if (component instanceof FormComponent) {
                    FormComponent formComponent = (FormComponent) component;

                    if (!formComponent.isValid()) {
                        if (!setFocusError) {
                            // Place focus on field in error (for the first field in error)
                            target.focusComponent(formComponent);
                            setFocusError = true;
                        }
                    }
                }
            }

            processErrors(target);
        }
    };

    deleteButton = new AjaxDeleteButton(Constants.DELETE, new StringResourceModel("confirmDelete", this, null),
            new StringResourceModel(Constants.DELETE, this, null)) {

        private static final long serialVersionUID = 4005032637149080009L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onDeleteConfirmed(target);
            target.add(feedbackPanel);
            detailContainer.setVisible(false);
            target.add(detailContainer);

            // remove node
            DefaultTreeModel treeModel = (DefaultTreeModel) tree.getDefaultModelObject();
            for (Object selectedNode : tree.getTreeState().getSelectedNodes()) {
                treeModel.removeNodeFromParent((MutableTreeNode) selectedNode);
            }

            tree.updateTree(target);
        }

        @Override
        public boolean isVisible() {
            return (ArkPermissionHelper.isActionPermitted(Constants.DELETE) && !isNew());
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }

        @Override
        public boolean isEnabled() {
            return canDelete();
        }
    };

    //editButton.setDefaultFormProcessing(false);
    cancelButton.setDefaultFormProcessing(false);
    /* Defines a edit mode */
    editButtonContainer = new WebMarkupContainer("editButtonContainer");
    editButtonContainer.setOutputMarkupPlaceholderTag(true);
    editButtonContainer.setVisible(isNew());

    // Initialise in read only
    detailFormContainer = new WebMarkupContainer("detailFormContainer");
    detailFormContainer.setOutputMarkupPlaceholderTag(true);
    detailFormContainer.setEnabled(isNew());

    addComponentsToForm();
}

From source file:au.org.theark.lims.web.component.inventory.form.AbstractInventoryDetailForm.java

License:Open Source License

/**
 * Method to handle Save action, and handle for any errors, placing forcus on any component in error
 * /*w  w w  . j ava  2 s.  c  o  m*/
 * @param target
 */
@SuppressWarnings("unchecked")
protected void saveOnErrorProcess(AjaxRequestTarget target) {
    boolean setFocusError = false;
    WebMarkupContainer wmc = getDetailContainer();
    for (Iterator iterator = wmc.iterator(); iterator.hasNext();) {
        Component component = (Component) iterator.next();
        if (component instanceof FormComponent) {
            FormComponent formComponent = (FormComponent) component;

            if (!formComponent.isValid()) {
                if (!setFocusError) {
                    // Place focus on field in error (for the first field in error)
                    target.focusComponent(formComponent);
                    setFocusError = true;
                }
            }
        }
    }

    processErrors(target);
}

From source file:org.efaps.ui.wicket.components.form.command.AjaxCmdBehavior.java

License:Apache License

/**
 * @param _container    container the model is searched for
 * @param _name         name/*  www .  j  a  v a 2  s.  c  o m*/
 * @return component
 */
private Component getModelFromChild(final WebMarkupContainer _container, final String _name) {
    Component ret = null;
    final Iterator<? extends Component> iter = _container.iterator();
    while (iter.hasNext() && ret == null) {
        final Component comp = iter.next();

        if (comp.getDefaultModelObject() instanceof UIField) {
            final UIField cell = (UIField) comp.getDefaultModelObject();
            if (_name.equals(cell.getFieldConfiguration().getName())) {
                ret = comp;
            }
        }
        if (ret == null && comp instanceof WebMarkupContainer) {
            ret = getModelFromChild((WebMarkupContainer) comp, _name);
        }
    }
    return ret;
}

From source file:org.sakaiproject.dash.tool.panels.CalendarLinksPanel.java

License:Educational Community License

/**
 * @param rl//  w  ww  .  j a va2  s . c o m
 * @param calendarLinksDiv
 * @param calendarDataView
 */
protected void renderItemCounter(WebMarkupContainer calendarLinksDiv, DataView<CalendarLink> calendarDataView) {

    ResourceLoader rl = new ResourceLoader("dash_entity");

    if (calendarLinksCountId != null) {
        Iterator itx = calendarLinksDiv.iterator();
        while (itx.hasNext()) {
            Component child = (Component) itx.next();
            if (calendarLinksCountId.equals(child.getId())) {
                calendarLinksDiv.remove(child);
                break;
            }
        }
    }

    int itemCount = 0;
    String pagerStatus = "";
    if (calendarDataView != null) {
        int first = 0;
        int last = 0;
        itemCount = calendarDataView.getItemCount();
        int pageSize = calendarDataView.getItemsPerPage();
        if (itemCount > pageSize) {
            int page = calendarDataView.getCurrentPage();
            first = page * pageSize + 1;
            last = Math.min(itemCount, (page + 1) * pageSize);
            if (first == last) {
                pagerStatus = rl.getFormattedMessage("dash.calendar.linksCount2",
                        new Object[] { new Integer(first), new Integer(itemCount) });
            } else {
                pagerStatus = rl.getFormattedMessage("dash.calendar.linksCount3",
                        new Object[] { new Integer(first), new Integer(last), new Integer(itemCount) });
            }
        } else if (itemCount > 1) {
            pagerStatus = rl.getFormattedMessage("dash.calendar.linksCount3",
                    new Object[] { new Integer(1), new Integer(itemCount), new Integer(itemCount) });
        } else if (itemCount > 0) {
            pagerStatus = rl.getString("dash.calendar.linksCount1");
        } else {
            pagerStatus = rl.getString("dash.calendar.linksCount0");
        }
    }
    Label calendarLinksCount = new Label("calendarLinksCount", pagerStatus);
    // add the count to the calendarLinksDiv
    calendarLinksDiv.add(calendarLinksCount);
    calendarLinksCountId = calendarLinksCount.getId();
}

From source file:org.sakaiproject.dash.tool.panels.MOTDPanel.java

License:Educational Community License

/**
 * @param rl/*w w  w  . ja va 2s  .co  m*/
 * @param motdDiv
 * @param newsDataView
 */
protected void renderItemCounter(final WebMarkupContainer motdDiv, final DataView<NewsItem> newsDataView) {

    ResourceLoader rl = new ResourceLoader("dash_entity");

    if (motdCountId != null) {
        Iterator itx = motdDiv.iterator();
        while (itx.hasNext()) {
            Component child = (Component) itx.next();
            if (motdCountId.equals(child.getId())) {
                motdDiv.remove(child);
                break;
            }
        }
    }

    int itemCount = 0;
    String pagerStatus = "";
    if (newsDataView != null) {
        int first = 0;
        int last = 0;
        itemCount = newsDataView.getItemCount();
        int pageSize = newsDataView.getItemsPerPage();
        if (itemCount > pageSize) {
            int page = newsDataView.getCurrentPage();
            first = page * pageSize + 1;
            last = Math.min(itemCount, (page + 1) * pageSize);
            if (first == last) {
                pagerStatus = rl.getFormattedMessage("dash.news.linksCount2",
                        new Object[] { new Integer(first), new Integer(itemCount) });
            } else {
                pagerStatus = rl.getFormattedMessage("dash.news.linksCount3",
                        new Object[] { new Integer(first), new Integer(last), new Integer(itemCount) });
            }
        } else if (itemCount > 1) {
            pagerStatus = rl.getFormattedMessage("dash.news.linksCount3",
                    new Object[] { new Integer(1), new Integer(itemCount), new Integer(itemCount) });
        } else if (itemCount > 0) {
            pagerStatus = rl.getString("dash.news.linksCount1");
        } else {
            pagerStatus = rl.getString("dash.news.linksCount0");
        }
    }
    Label motdCount = new Label("motdCount", pagerStatus);
    motdCount.setOutputMarkupId(true);
    // add the count to the motdDiv
    motdDiv.add(motdCount);

    motdCountId = motdCount.getId();
}

From source file:org.sakaiproject.dash.tool.panels.NewsLinksPanel.java

License:Educational Community License

/**
 * @param rl/*from  www. java  2 s.c  o m*/
 * @param newsLinksDiv
 * @param newsDataView
 */
protected void renderItemCounter(final WebMarkupContainer newsLinksDiv, final DataView<NewsLink> newsDataView) {

    ResourceLoader rl = new ResourceLoader("dash_entity");

    if (newsLinksCountId != null) {
        Iterator itx = newsLinksDiv.iterator();
        while (itx.hasNext()) {
            Component child = (Component) itx.next();
            if (newsLinksCountId.equals(child.getId())) {
                newsLinksDiv.remove(child);
                break;
            }
        }
    }

    int itemCount = 0;
    String pagerStatus = "";
    if (newsDataView != null) {
        int first = 0;
        int last = 0;
        itemCount = newsDataView.getItemCount();
        int pageSize = newsDataView.getItemsPerPage();
        if (itemCount > pageSize) {
            int page = newsDataView.getCurrentPage();
            first = page * pageSize + 1;
            last = Math.min(itemCount, (page + 1) * pageSize);
            if (first == last) {
                pagerStatus = rl.getFormattedMessage("dash.news.linksCount2",
                        new Object[] { new Integer(first), new Integer(itemCount) });
            } else {
                pagerStatus = rl.getFormattedMessage("dash.news.linksCount3",
                        new Object[] { new Integer(first), new Integer(last), new Integer(itemCount) });
            }
        } else if (itemCount > 1) {
            pagerStatus = rl.getFormattedMessage("dash.news.linksCount3",
                    new Object[] { new Integer(1), new Integer(itemCount), new Integer(itemCount) });
        } else if (itemCount > 0) {
            pagerStatus = rl.getString("dash.news.linksCount1");
        } else {
            pagerStatus = rl.getString("dash.news.linksCount0");
        }
    }
    Label newsLinksCount = new Label("newsLinksCount", pagerStatus);
    newsLinksCount.setOutputMarkupId(true);
    // add the count to the newsLinksDiv
    newsLinksDiv.add(newsLinksCount);

    newsLinksCountId = newsLinksCount.getId();
}