Example usage for org.apache.wicket.markup.html.list ListView ListView

List of usage examples for org.apache.wicket.markup.html.list ListView ListView

Introduction

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

Prototype

public ListView(final String id, final List<T> list) 

Source Link

Usage

From source file:au.org.theark.disease.web.component.affection.form.DetailForm.java

License:Open Source License

@SuppressWarnings("unchecked")
public void initialiseDetailForm() {

    initDiseaseDDC();//from   ww w  .jav a 2s . co  m
    initAffectionStatusDDC();

    detachableModel = new LoadableDetachableModel<List<Position>>() {

        @Override
        protected List<Position> load() {
            List<Position> positions = iArkDiseaseService
                    .getPositions(containerForm.getModelObject().getAffection());
            return positions;
        }
    };

    positionListEditor = new ListView<Position>("positionListEditor", detachableModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<Position> item) {
            final Position position = item.getModelObject();
            if (position != null) {
                position_storage.put(item.getIndex(), position);
            }

            List<Gene> availableGenes = new ArrayList<Gene>();
            if (containerForm.getModelObject().getAffection().getDisease() != null
                    && containerForm.getModelObject().getAffection().getDisease().getGenes() != null) {
                availableGenes = new ArrayList<Gene>(
                        containerForm.getModelObject().getAffection().getDisease().getGenes());
            }
            final DropDownChoice<Gene> geneDDC = new DropDownChoice<Gene>("affection.disease.genes",
                    new Model<Gene>(position.getGene()), availableGenes,
                    new ChoiceRenderer<Gene>("name", "id"));
            geneDDC.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                private static final long serialVersionUID = 1L;

                protected void onUpdate(AjaxRequestTarget target) {
                    Gene selectedGene = iArkDiseaseService.getGeneByID(Long.parseLong(geneDDC.getValue()));
                    positionDDC.setChoices(new ArrayList<Position>(selectedGene.getPositions()));
                    target.add(positionDDC);
                }
            });

            geneDDC.setOutputMarkupId(true);
            item.add(geneDDC);

            List<Position> availablePositions = new ArrayList<Position>();
            if (geneDDC.getModelObject() != null) {
                availablePositions = new ArrayList<Position>(geneDDC.getModelObject().getPositions());
            }
            LoadableDetachableModel<Position> positionModel = new LoadableDetachableModel<Position>(position) {

                @Override
                protected Position load() {
                    return position;
                }
            };
            if (position != null) {
                positionModel.setObject(position);
            }
            positionDDC = new DropDownChoice<Position>("affection.positions", positionModel, availablePositions,
                    new ChoiceRenderer<Position>("name", "id")) {
                @Override
                protected void onBeforeRender() {
                    if (geneDDC.getModelObject() != null && geneDDC.getModelObject().getId() != null
                            && !geneDDC.getModelObject().getPositions().isEmpty()) {
                        this.setChoices(new ArrayList<Position>(geneDDC.getModelObject().getPositions()));
                    }
                    if (this.getModelObject().getName() != null) {
                        position_storage.put(item.getIndex(), this.getModelObject());
                    }
                    super.onBeforeRender();
                }
            };
            positionDDC.setOutputMarkupId(true);
            positionDDC.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                private static final long serialVersionUID = 1L;

                protected void onUpdate(AjaxRequestTarget target) {
                    Position selectedPosition = positionDDC.getModelObject();
                    if (selectedPosition.getName() != null) {
                        position_storage.put(item.getIndex(), selectedPosition);
                    }
                }
            });
            item.add(positionDDC);

            item.add(new AjaxDeleteButton(Constants.DELETE, new Model<String>("Are you sure?"),
                    new Model<String>("Delete")) {

                private static final long serialVersionUID = 1L;

                protected void onDeleteConfirmed(AjaxRequestTarget target, Form<?> form) {
                    try {
                        //need to remove save containerform post position removal
                        position_storage.remove(item.getIndex());
                        positionListEditor.getModelObject().remove(position);
                        containerForm.getModelObject().setAffection(iArkDiseaseService
                                .getAffectionByID(containerForm.getModelObject().getAffection().getId()));

                        save(containerForm, target);
                        target.add(dataViewPanel);
                        deleteCompleted("Row '" + position.getName() + "' deleted successfully.", true);
                    } catch (Exception e) {
                        e.printStackTrace();
                        target.add(form);
                        deleteCompleted("Error deleting row '" + position.getName()
                                + "'. Row has data associated with it.", false);
                    }
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    onDeleteConfirmed(target, form);
                    target.add(form);
                    target.add(feedBackPanel);
                }
            });

            item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel() {
                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? Constants.EVEN : Constants.ODD;
                }
            }));
        }
    };

    positionListEditor.setOutputMarkupId(true);

    newPositionBtn = new AjaxEditorButton(Constants.NEW) {

        private static final long serialVersionUID = 1L;

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

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            positionListEditor.getModelObject().add(new Position());
            target.add(form);
        }
    }.setDefaultFormProcessing(false);

    arkCrudContainerVO.getDetailPanelFormContainer().add(newPositionBtn);

    PropertyModel<Date> recordDateModel = new PropertyModel<Date>(containerForm.getModel(),
            "affection.recordDate");
    recordDateTxtFld = new DateTextField("recordDate", recordDateModel) {
        @Override
        protected void onBeforeRender() {
            this.setModel(new PropertyModel<Date>(containerForm.getModel(), "affection.recordDate"));
            super.onBeforeRender();
        }
    };
    ArkDatePicker recordDatePicker = new ArkDatePicker();
    recordDatePicker.bind(recordDateTxtFld);
    recordDateTxtFld.add(recordDatePicker);

    AffectionCustomDataVO affectionCustomDataVO = new AffectionCustomDataVO();
    affectionCustomDataVO.setCustomFieldDataList(new ArrayList<AffectionCustomFieldData>(
            cpModel.getObject().getAffection().getAffectionCustomFieldDataSets()));

    final CompoundPropertyModel<AffectionCustomDataVO> affectionCustomDataModel = new CompoundPropertyModel<AffectionCustomDataVO>(
            affectionCustomDataVO);
    dataViewPanel = new AffectionCustomDataDataViewPanel("dataViewPanel", affectionCustomDataModel)
            .initialisePanel(
                    iArkCommonService.getUserConfig(Constants.CONFIG_CUSTOM_FIELDS_PER_PAGE).getIntValue());
    customFieldForm = new AbstractCustomDataEditorForm<AffectionCustomDataVO>("customFieldForm",
            affectionCustomDataModel, feedBackPanel) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onEditSave(AjaxRequestTarget target, Form<?> form) {
            for (AffectionCustomFieldData acfd : this.cpModel.getObject().getCustomFieldDataList()) {
                iArkDiseaseService.save(acfd);
            }
        }

        @Override
        public void onBeforeRender() {
            if (!isNew()) {
                this.setModelObject(new AffectionCustomDataVO(iArkDiseaseService
                        .getAffectionCustomFieldData(containerForm.getModelObject().getAffection())));
            }
            this.buttonsPanelWMC.setVisible(false);
            super.onBeforeRender();
        }
    }.initialiseForm();

    pageNavigator = new AjaxPagingNavigator("navigator", dataViewPanel.getDataView()) {
        @Override
        protected void onAjaxEvent(AjaxRequestTarget target) {
            target.add(customFieldForm.getDataViewWMC());
            target.add(this);
        }
    };
    pageNavigator.setOutputMarkupId(true);
    customFieldForm.getDataViewWMC().add(dataViewPanel);
    arkCrudContainerVO.getDetailPanelFormContainer().add(pageNavigator);
    attachValidators();
    addDetailFormComponents();

    deleteButton.setVisible(false);
}

From source file:au.org.theark.study.web.component.manageuser.form.DetailForm.java

License:Open Source License

@SuppressWarnings("unchecked")
public void initialiseDetailForm() {
    userNameTxtField = new TextField<String>(Constants.USER_NAME);
    userNameTxtField.setOutputMarkupId(true);
    firstNameTxtField = new TextField<String>(Constants.FIRST_NAME);
    lastNameTxtField = new TextField<String>(Constants.LAST_NAME);
    emailTxtField = new TextField<String>(Constants.EMAIL);
    userPasswordField = new PasswordTextField(Constants.PASSWORD);
    confirmPasswordField = new PasswordTextField(Constants.CONFIRM_PASSWORD);
    oldPasswordField = new PasswordTextField(Constants.OLD_PASSWORD);
    groupPasswordContainer = new WebMarkupContainer("groupPasswordContainer");

    IModel<List<ArkUserRole>> iModel = new LoadableDetachableModel() {
        private static final long serialVersionUID = 1L;

        @Override/*from w  w w  .j  a  v  a2 s . c o  m*/
        protected Object load() {
            return containerForm.getModelObject().getArkUserRoleList();
        }
    };

    ListView listView = new ListView("arkUserRoleList", iModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem item) {
            // Each item will be ArkModuleVO use that to build the Module name and the drop down
            ArkUserRole arkUserRole = (ArkUserRole) item.getModelObject();
            ArkModule arkModule = arkUserRole.getArkModule();
            // Acts as the data source for ArkRoles
            ArrayList<ArkRole> arkRoleSourceList = iArkCommonService.getArkRoleLinkedToModule(arkModule);
            if (arkUserRole.getArkUser() == null
                    && arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_STUDY)) {
                // If the ArkUserRole is not assigned and the module is Study then set the default Role
                ArkRole arkRole = iArkCommonService
                        .getArkRoleByName(au.org.theark.core.Constants.ARK_STUDY_DEFAULT_ROLE);
                arkUserRole.setArkRole(arkRole);
            }

            PropertyModel arkUserRolePm = new PropertyModel(arkUserRole, "arkRole");
            ChoiceRenderer<ArkRole> defaultChoiceRenderer = new ChoiceRenderer<ArkRole>(Constants.NAME, "id");

            DropDownChoice<ArkRole> ddc = new DropDownChoice<ArkRole>("arkRole", arkUserRolePm,
                    arkRoleSourceList, defaultChoiceRenderer);

            item.add(new Label("moduleName", arkModule.getName()));// arkModule within ArkUserRole
            item.add(ddc);

        }
    };

    listView.setReuseItems(true);
    arkCrudContainerVO.getWmcForarkUserAccountPanel().add(listView);
    confirmationAnswer = new ConfirmationAnswer(false);
    confirmModal = new ModalWindow("modalWindow");
    confirmModal.setCookieName("yesNoPanel");
    confirmModal.setContent(
            new YesNoPanel(confirmModal.getContentId(), modalText, confirmModal, confirmationAnswer));
    confirmModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
        private static final long serialVersionUID = 1L;

        public void onClose(AjaxRequestTarget target) {
            if (confirmationAnswer.isAnswer()) {
                //Add new roles for module wise to study
                iUserService.updateArkUserRoleListForExsistingUser(containerForm.getModelObject());
                //Up date for all the child studies.
                reNewArkUserRoleForChildStudies(containerForm);
                containerForm.getModelObject().setMode(Constants.MODE_EDIT);
                //onSavePostProcess(target);
                successModal.show(target);
            } else {//if no nothing be done.Just close I guess
            }
        }
    });
    successModal = new ModalWindow("successModalWindow");
    successModal.setCookieName("okPanel");
    successModal.setContent(new SuccessFullySaved(confirmModal.getContentId(),
            "The exsisting user added sucessfully to the Study", successModal));
    initChildStudyPalette();
    attachValidators();
    addDetailFormComponents();

}

From source file:au.org.theark.study.web.component.subject.ChildStudySubjectPanel.java

License:Open Source License

/**
 * Constructor//ww  w  .  j  a  v  a  2 s.c om
 * 
 * @param id
 * @param feedbackPanel
 * @param studyCrudContainerVO
 * @param iModel
 */
public ChildStudySubjectPanel(String id, final IModel<SubjectVO> iModel, WebMarkupContainer arkContextMarkup,
        ContainerForm containerForm, ArkCrudContainerVO arkCrudContainerVO) {
    super(id, iModel);

    this.subjectContainerForm = containerForm;
    this.arkContextMarkup = arkContextMarkup;
    this.arkCrudContainerVO = arkCrudContainerVO;

    LinkSubjectStudy lss = new LinkSubjectStudy();
    lss = iModel.getObject().getLinkSubjectStudy();
    List<Study> studies = iModel.getObject().getSelectedChildStudies();

    for (Iterator<Study> iterator = studies.iterator(); iterator.hasNext();) {
        Study study = (Study) iterator.next();
        try {
            if (!lss.getSubjectStatus().getName().equalsIgnoreCase("Archive")) {
                childSubjectIds.add(iArkCommonService.getSubject(lss.getPerson().getId(), study));
            }
        } catch (EntityNotFoundException e) {
            e.printStackTrace();
        }
    }

    Label label = new Label("linkChildSubjectLabel", "Link to Child Study Subject:") {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public boolean isVisible() {
            return !childSubjectIds.isEmpty();
        };
    };
    listView = new ListView<LinkSubjectStudy>("list", childSubjectIds) {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<LinkSubjectStudy> item) {
            ArkBusyAjaxLink<String> link = new ArkBusyAjaxLink<String>("link") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    iModel.getObject().setLinkSubjectStudy(item.getModelObject());
                    setSubjectIntoContext(target, iModel.getObject());
                }
            };

            Label label = new Label("label", item.getModelObject().getStudy().getName());
            link.add(label);
            item.add(link);
        }
    };

    add(label);
    add(listView);
}

From source file:ca.travelagency.components.formdetail.DetailsPanel.java

License:Apache License

public DetailsPanel(String id, IModel<T> model) {
    super(id, model);
    setOutputMarkupId(true);/*from  www  . ja  va2  s  . co  m*/

    webMarkupContainer = new WebMarkupContainer(ROWS_CONTAINER);
    webMarkupContainer.setOutputMarkupId(true);
    add(webMarkupContainer);

    webMarkupContainer.add(makeDetailFormPanel(FORM).setVisible(isEditable()));
    webMarkupContainer.add(makeDetailHeaderPanel(HEADER));

    LoadableDetachableModel<List<D>> listModel = new LoadableDetachableModel<List<D>>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected List<D> load() {
            return getDetails();
        }
    };

    details = new ListView<D>(ROWS, listModel) {
        private static final long serialVersionUID = 1L;

        @Override
        protected ListItem<D> newItem(int index, IModel<D> itemModel) {
            return new OddEvenListItem<D>(index, itemModel);
        }

        @Override
        protected void populateItem(ListItem<D> item) {
            item.setModel(DaoEntityModelFactory.make(item.getModelObject()));
            item.add(makeDetailRowPanel(ROW, item.getModel()));
        }
    };

    webMarkupContainer.add(details);
}

From source file:ca.travelagency.invoice.InvoiceDestinationsPanel.java

License:Apache License

public InvoiceDestinationsPanel(String id, IModel<Invoice> model) {
    super(id);/*  w  w w.ja v a 2s  . c  o  m*/
    List<InvoiceDestination> destinations = Lists.newArrayList(model.getObject().getInvoiceDestinations());
    ListView<InvoiceDestination> listView = new ListView<InvoiceDestination>(
            Invoice.Properties.invoiceDestinations.name(), destinations) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<InvoiceDestination> item) {
            item.add(new Label(DaoEntity.PROPERTY_NAME, item.getModelObject().getName()));
        }
    };
    add(listView);
}

From source file:ca.travelagency.invoice.InvoiceTravelersPanel.java

License:Apache License

public InvoiceTravelersPanel(String id, IModel<Invoice> model) {
    super(id);/*from   w  ww . jav a2s  .  co m*/
    List<InvoiceTraveler> travellers = Lists.newArrayList(model.getObject().getInvoiceTravelers());
    ListView<InvoiceTraveler> listView = new ListView<InvoiceTraveler>(
            Invoice.Properties.invoiceTravelers.name(), travellers) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<InvoiceTraveler> item) {
            item.add(new Label(DaoEntity.PROPERTY_NAME, item.getModelObject().getName()));
        }
    };
    add(listView);
}

From source file:ca.travelagency.invoice.view.InvoicePanel.java

License:Apache License

private Component addInvoiceItems(IModel<Invoice> model) {
    ListView<InvoiceItem> listView = new ListView<InvoiceItem>(Invoice.Properties.invoiceItems.name(),
            model.getObject().getInvoiceItems()) {
        private static final long serialVersionUID = 1L;

        @Override//from  ww w .j ava 2  s  . co  m
        protected ListItem<InvoiceItem> newItem(int index, IModel<InvoiceItem> itemModel) {
            return new OddEvenListItem<InvoiceItem>(index, itemModel);
        }

        @Override
        protected void populateItem(ListItem<InvoiceItem> item) {
            item.setModel(DaoEntityModelFactory.make(item.getModelObject()));

            item.add(new Label(InvoiceItem.Properties.description.name()));
            item.add(new Label(InvoiceItem.Properties.supplier.name()));
            item.add(new Label(InvoiceItem.Properties.commissionAsString.name()));
            item.add(new Label(InvoiceItem.Properties.salesAmounts.name() + Condition.SEPARATOR
                    + SalesAmounts.Properties.commissionAsString));
            item.add(new Label(InvoiceItem.Properties.taxOnCommissionAsString.name()));
            item.add(new Label(InvoiceItem.Properties.priceAsString.name()));
            item.add(new Label(InvoiceItem.Properties.taxAsString.name()));
            item.add(new Label(InvoiceItem.Properties.cancelBeforeDeparture.name()));
            item.add(new Label(InvoiceItem.Properties.changeBeforeDeparture.name()));
            item.add(new Label(InvoiceItem.Properties.changeAfterDeparture.name()));
            item.add(new Label(InvoiceItem.Properties.qty.name()));
            item.add(new Label(InvoiceItem.Properties.salesAmounts.name() + Condition.SEPARATOR
                    + SalesAmounts.Properties.saleAsString.name()));
            item.add(new Label(InvoiceItem.Properties.bookingNumber.name()));
            item.add(DateLabel.forDateStyle(InvoiceItem.Properties.bookingDate.name(), DateUtils.DATE_STYLE));
            item.add(new Label(InvoiceItem.Properties.commissionStatus.name()));
        }
    };

    return listView;
}

From source file:ch.bd.qv.quiz.panels.LangPanel.java

License:Apache License

public LangPanel(String id) {
    super(id);/*w  w  w .  j  a  va  2s .  c  o  m*/
    LOGGER.debug("lang received on panel: " + Joiner.on(":").join(supportedLocales.iterator()));
    add(new ListView<Locale>("list", supportedLocales) {
        @Override
        protected void populateItem(final ListItem<Locale> item) {

            AjaxLink<Void> langLink = new AjaxLink<Void>("lang") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    getSession().setLocale(item.getModelObject());
                    BasePanel bp = findParent(BasePanel.class);
                    bp.driveNavigation();
                    target.add(bp);
                }
            };
            langLink.add(new Label("label", new LoadableDetachableModel<String>() {
                @Override
                protected String load() {
                    LOGGER.debug("item: " + item.getModelObject());
                    return item.getModelObject().getLanguage().toUpperCase();
                }
            }));
            item.add(langLink);
        }
    });

}

From source file:ch.bd.qv.quiz.panels.RadioQuestionPanel.java

License:Apache License

public RadioQuestionPanel(String inner, RadioQuestion bq) {
    super(inner, bq);
    this.radioQuestion = bq;
    RadioGroup<String> rg = new RadioGroup<>("radiogroup", input);
    rg.add(new ListView<String>("repeater", Lists.newArrayList(bq.getAnswerKeys())) {

        @Override// www.  j  a  va2 s .c  om
        protected void populateItem(ListItem<String> item) {
            item.add(new Radio("radio", item.getModel()));
            item.add(new Label("radio_label", new ResourceModel(item.getModelObject())));
        }
    });
    rg.setRequired(true);
    add(rg);
}

From source file:ch.qos.mistletoe.wicket.TestReportPanel.java

License:Open Source License

void handleDescriptionWithChildren() {
    ListView<TestReport> listView = new ListView<TestReport>(Constants.PAYLOAD_ID, testReport.getChildren()) {
        private static final long serialVersionUID = 1L;

        @Override//from   w w  w . j a  va  2 s . c  om
        protected void populateItem(ListItem<TestReport> item) {
            TestReport childNode = item.getModelObject();
            item.add(new TestReportPanel(Constants.NODE_ID, childNode)).setOutputMarkupId(true);
        }
    };
    listView.setOutputMarkupId(true);
    add(listView);
}