Example usage for org.apache.wicket Component setOutputMarkupPlaceholderTag

List of usage examples for org.apache.wicket Component setOutputMarkupPlaceholderTag

Introduction

In this page you can find the example usage for org.apache.wicket Component setOutputMarkupPlaceholderTag.

Prototype

public final Component setOutputMarkupPlaceholderTag(final boolean outputTag) 

Source Link

Document

Render a placeholder tag when the component is not visible.

Usage

From source file:com.doculibre.constellio.wicket.components.modal.NonAjaxModalWindow.java

License:Apache License

/**
 * Sets the content of the modal window.
 * //from w w  w  .  j av a 2s. co  m
 * @param component
 */
public void setContent(Component component) {
    if (component.getId().equals(getContentId()) == false) {
        throw new WicketRuntimeException("Modal window content id is wrong.");
    }
    component.setOutputMarkupPlaceholderTag(true);
    component.setVisible(false);
    replace(component);
    shown = false;
    pageCreator = null;
}

From source file:de.alpharogroup.wicket.behaviors.models.ListModelUpdateBehavior.java

License:Apache License

/**
 * {@inheritDoc}/* w  w  w .j a v a  2 s  .  c  o m*/
 */
@Override
public void bind(final Component component) {
    super.bind(component);
    component.setOutputMarkupPlaceholderTag(true);
}

From source file:de.flapdoodle.wicket.behavior.AjaxUpdateable.java

License:Apache License

@Override
public void bind(Component component) {
    super.bind(component);
    component.setOutputMarkupPlaceholderTag(true);
}

From source file:org.apache.isis.viewer.wicket.ui.components.widgets.buttons.ContainedButton.java

License:Apache License

public void addComponentToRerender(final Component component) {
    component.setOutputMarkupPlaceholderTag(true);
    componentsToRerender.add(component);
}

From source file:org.cipango.littleims.pcscf.oam.browser.DebugSessionPanel.java

License:Apache License

@SuppressWarnings("unchecked")
public DebugSessionPanel(String id, final DebugSession debugSession) {
    super(id);/*from ww  w  . ja  v  a 2s.co  m*/
    add(new Label("debugId", debugSession.getDebugId()));
    add(new Label("startTrigger", debugSession.getStartTriggerAsString()));
    add(new Label("stopTrigger", debugSession.getStoptTriggerAsString()));
    add(new HideableLink("hideLink", this));
    _debugId = debugSession.getDebugId();
    refreshLog();

    AjaxFallbackLink viewLink = new AjaxFallbackLink("viewLog") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            _viewLog = true;
            refreshLog();
            Component hideLink = getParent().get("hideLog");
            hideLink.setVisible(true);
            Component refresh = new Label("view", "Refresh log").setOutputMarkupId(true);
            replace(refresh);
            if (target != null) {
                target.addComponent(getParent().get("content"));
                target.addComponent(hideLink);
                target.addComponent(refresh);
            }
        }
    };
    add(viewLink);
    viewLink.setOutputMarkupId(true);
    viewLink.add(new Label("view", "View log").setOutputMarkupId(true));

    AjaxFallbackLink hideLink = new AjaxFallbackLink("hideLog") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            _viewLog = false;
            setVisible(false);
            Component refresh = new Label("view", "View log").setOutputMarkupId(true);
            ((WebMarkupContainer) getParent().get("viewLog")).replace(refresh);
            refreshLog();
            if (target != null) {
                target.addComponent(getParent().get("content"));
                target.addComponent(this);
                target.addComponent(refresh);
            }
        }
    };
    add(hideLink);
    hideLink.setVisible(false);
    hideLink.setOutputMarkupId(true);
    hideLink.setOutputMarkupPlaceholderTag(true);
}

From source file:org.hippoecm.frontend.plugins.cms.browse.SectionViewer.java

License:Apache License

public SectionViewer(final String id, final BrowserSections sections, IRenderService parentRenderService) {
    super(id, new Model<String>(null));

    setOutputMarkupId(true);/*from   www .j a  va2s . c  o  m*/

    add(new AttributeAppender("class", Model.of("section-viewer"), " "));

    this.parentService = parentRenderService;
    this.sections = sections;

    IDataProvider<String> sectionProvider = new IDataProvider<String>() {

        private transient List<String> names;

        private void load() {
            if (names == null) {
                names = new ArrayList<>(sections.getSections());
            }
        }

        @Override
        public Iterator<String> iterator(long first, long count) {
            load();
            return names.subList((int) first, (int) (first + count)).iterator();
        }

        @Override
        public IModel<String> model(String object) {
            return new Model<>(object);
        }

        @Override
        public long size() {
            return sections.getSections().size();
        }

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

    add(new AbstractView<String>("list", sectionProvider) {

        @Override
        protected void populateItem(final Item<String> item) {
            final IBrowserSection section = sections.getSection(item.getModelObject());

            section.bind(parentService, "section-view");

            final Component component = section.getComponent();
            component.setOutputMarkupId(true);
            component.setOutputMarkupPlaceholderTag(true);
            item.add(component);

            item.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    return sections.isActive(section) ? "selected" : "unselected";
                }
            }, " "));
        }

        @Override
        protected void destroyItem(Item<String> item) {
            IBrowserSection section = sections.getSection(item.getModelObject());
            section.unbind();
        }
    });

    String selectedBrowserSection = (String) getDefaultModelObject();
    if (selectedBrowserSection != null) {
        select(selectedBrowserSection);
    }

    final Form form = new Form("selection-form");
    add(form);

    final SectionNamesModel sectionNamesModel = new SectionNamesModel();
    this.sections.addListener(sectionNamesModel);

    final IModel<String> selectModel = new SelectedSectionModel();
    select = new DropDownChoice<>("select", selectModel, sectionNamesModel, new IChoiceRenderer<String>() {
        @Override
        public Object getDisplayValue(final String sectionId) {
            final IBrowserSection section = sections.getSection(sectionId);
            return section.getTitle().getObject();
        }

        @Override
        public String getIdValue(final String sectionId, final int index) {
            return sectionId;
        }
    });
    select.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            onSelect(selectModel.getObject());
        }
    });
    form.add(select);

    this.sections.addListener(new IChangeListener() {
        public void onChange() {
            select(sections.getActiveSectionName());
        }
    });
}

From source file:org.obiba.onyx.wicket.reusable.Dialog.java

License:Open Source License

/**
 * Sets the content of the dialog box./*  ww w .  ja v a 2  s . com*/
 * 
 * @param component
 */
@Override
public Dialog setContent(Component component) {
    if (component.getId().equals(getContentId()) == false) {
        throw new WicketRuntimeException("Dialog box content id is wrong.");
    }
    component.setOutputMarkupPlaceholderTag(true);
    component.setVisible(true);
    form.replace(component);
    return this;
}

From source file:org.patientview.radar.web.panels.firstvisit.ClinicalPicturePanel.java

License:Open Source License

public ClinicalPicturePanel(String id, final IModel<Long> radarNumberModel, final boolean isFirstVisit) {

    super(id);/*  w  ww.  j  a  v a 2  s  .  c om*/
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);

    // set srns elements to hide
    srnsElementsToHide = Arrays.asList(URTICARIA_CONTAINER_ID, URTICARIA_DETAIL_CONTAINER_ID,
            PARTIAL_LIPODYSTROPHY_CONTAINER_ID, PRECEEDING_INFECTION_CONTAINER_ID,
            PRECEEDING_INFECTION_DETAIL_CONTAINER_ID, CHRONIC_INFECTION_ACTIVE_CONTAINER_ID,
            CHRONIC_INFECTION_DETAIL_CONTAINER_ID);

    // set mpgn elements to hide
    mpgnElementsToHide = Arrays.asList(THROMBOSIS_CONTAINER_ID, PERITONITIS_CONTAINER_ID,
            PULMONARY_OEDEMA_CONTAINER_ID, DIABETES_TYPE_CONTAINER_ID, RASH_CONTAINER_ID,
            RASH_DETAIL_CONTAINER_ID, POSSIBLE_IMMUNISATION_TRIGGER_CONTAINER_ID, PHENOTYPE_CONTAINER_1,
            PHENOTYPE_CONTAINER_2, PHENOTYPE_CONTAINER_3, PHENOTYPE_CONTAINER_4);

    // set srns elements to hide on follow up
    srnsElementsToHideFollowup = Arrays.asList(PATIENT_DETAILS_CONTAINER);

    final WebMarkupContainer clinicalPictureContainer = new WebMarkupContainer("clinicalPictureContainer");
    clinicalPictureContainer.setVisible(isFirstVisit);
    clinicalPictureContainer.setOutputMarkupId(true);
    clinicalPictureContainer.setOutputMarkupPlaceholderTag(true);
    add(clinicalPictureContainer);

    final TextField<Double> diastolicBloodPressure = new TextField<Double>("diastolicBloodPressure");

    final CompoundPropertyModel<ClinicalData> firstVisitModel = new CompoundPropertyModel<ClinicalData>(
            new LoadableDetachableModel<ClinicalData>() {
                @Override
                protected ClinicalData load() {
                    if (radarNumberModel.getObject() != null) {
                        // If we have a radar number get the list from DAO
                        ClinicalData clinicalData;
                        clinicalData = clinicalDataManager
                                .getFirstClinicalDataByRadarNumber(radarNumberModel.getObject());

                        if (clinicalData != null) {
                            return clinicalData;
                        }
                    }
                    // By default just return new one
                    ClinicalData clinicalDataNew = new ClinicalData();
                    clinicalDataNew.setSequenceNumber(1);
                    return clinicalDataNew;
                }
            });

    final IModel<ClinicalData> followUpModel = new LoadableDetachableModel<ClinicalData>() {
        private Long id;

        @Override
        protected ClinicalData load() {
            if (id == null) {
                return new ClinicalData();
            } else {
                return clinicalDataManager.getClinicalData(id);
            }
        }

        @Override
        public void detach() {
            ClinicalData clinicalData = getObject();
            if (clinicalData != null) {
                id = clinicalData.getId();
            }
            super.detach();
        }
    };

    final IModel<ClinicalData> formModel;
    if (isFirstVisit) {
        formModel = firstVisitModel;
    } else {
        formModel = new CompoundPropertyModel<ClinicalData>(followUpModel);
    }

    IModel<List> clinicalPictureListModel = new AbstractReadOnlyModel<List>() {
        @Override
        public List getObject() {

            if (radarNumberModel.getObject() != null) {
                List list = clinicalDataManager.getClinicalDataByRadarNumber(radarNumberModel.getObject());
                return !list.isEmpty() ? list : Collections.emptyList();
            }

            return Collections.emptyList();
        }
    };

    WebMarkupContainer followupContainer = new WebMarkupContainer("followupContainer");
    followupContainer.setVisible(!isFirstVisit);
    followupContainer.setOutputMarkupPlaceholderTag(true);

    final DropDownChoice clinicalPicturesSwitcher = new DropDownChoice("clinicalPicturesSwitcher",
            followUpModel, clinicalPictureListModel, new DateChoiceRenderer("clinicalPictureDate", "id") {
                @Override
                protected Date getDate(Object object) {
                    return ((ClinicalData) object).getClinicalPictureDate();
                }
            });

    clinicalPicturesSwitcher.setNullValid(true);

    clinicalPicturesSwitcher.setOutputMarkupId(true);
    clinicalPictureContainer.setOutputMarkupPlaceholderTag(true);
    followupContainer.add(clinicalPicturesSwitcher);
    clinicalPicturesSwitcher.add(new AjaxFormComponentUpdatingBehavior("onChange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            clinicalPictureContainer.setVisible(true);
            target.add(clinicalPictureContainer);

        }
    });

    AjaxLink addNew = new AjaxLink("addNew") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            ClinicalData clinicalData = new ClinicalData();
            Diagnosis daignosis = RadarModelFactory.getDiagnosisModel(radarNumberModel, diagnosisManager)
                    .getObject();
            if (daignosis != null) {
                clinicalData.setSignificantDiagnosis1(daignosis.getSignificantDiagnosis1());
                clinicalData.setSignificantDiagnosis2(daignosis.getSignificantDiagnosis2());
            }

            ClinicalData firstClinicalData = clinicalDataManager
                    .getFirstClinicalDataByRadarNumber(radarNumberModel.getObject());
            if (firstClinicalData != null) {
                clinicalData.setPhenotype1(firstClinicalData.getPhenotype1());
                clinicalData.setPhenotype2(firstClinicalData.getPhenotype2());
                clinicalData.setPhenotype3(firstClinicalData.getPhenotype3());
                clinicalData.setPhenotype4(firstClinicalData.getPhenotype4());
            }

            formModel.setObject(clinicalData);
            clinicalPictureContainer.setVisible(true);
            clinicalPicturesSwitcher.clearInput();
            target.add(clinicalPictureContainer, clinicalPicturesSwitcher);

        }
    };

    followupContainer.add(addNew);
    add(followupContainer);

    final List<Component> componentsToUpdate = new ArrayList<Component>();
    if (clinicalPicturesSwitcher.isVisible()) {
        componentsToUpdate.add(clinicalPicturesSwitcher);
    }

    final Form<ClinicalData> form = new Form<ClinicalData>("form", formModel) {
        @Override
        protected void onValidateModelObjects() {
            super.onValidateModelObjects();
            ClinicalData clinicalData = getModelObject();
            Integer systolicBloodPressureVal = clinicalData.getSystolicBloodPressure();
            Integer diastolicBloodPressureVal = clinicalData.getDiastolicBloodPressure();
            if (systolicBloodPressureVal != null && diastolicBloodPressureVal != null) {
                if (!(systolicBloodPressureVal.compareTo(diastolicBloodPressureVal) > 0)) {
                    diastolicBloodPressure.error("This value has to be less than the first value");
                }
            }

        }

        @Override
        protected void onSubmit() {
            ClinicalData clinicalData = getModelObject();
            Long radarNumber;

            if (clinicalData.getRadarNumber() == null) {
                try {
                    radarNumber = radarNumberModel.getObject();
                } catch (ClassCastException e) {
                    Object obj = radarNumberModel.getObject();
                    radarNumber = Long.parseLong((String) obj);
                }

                clinicalData.setRadarNumber(radarNumber);
            }
            clinicalDataManager.saveClinicalDate(clinicalData);

            // if first visit - follow through phenotypes to following visit records
            if (isFirstVisit) {
                List<ClinicalData> clinicalDatas = clinicalDataManager
                        .getClinicalDataByRadarNumber(clinicalData.getRadarNumber());

                for (ClinicalData cd : clinicalDatas) {
                    // ignore first visit
                    if (clinicalData.getId().equals(cd.getId())) {
                        continue;
                    }
                    cd.setPhenotype1(clinicalData.getPhenotype1());
                    cd.setPhenotype2(clinicalData.getPhenotype2());
                    cd.setPhenotype3(clinicalData.getPhenotype3());
                    cd.setPhenotype4(clinicalData.getPhenotype4());
                    clinicalDataManager.saveClinicalDate(cd);
                }
            }
        }
    };

    clinicalPictureContainer.add(form);

    final IModel<Boolean> isSrnsModel = new AbstractReadOnlyModel<Boolean>() {
        private DiagnosisCode diagnosisCode = null;

        @Override
        public Boolean getObject() {
            if (diagnosisCode == null) {
                if (radarNumberModel.getObject() != null) {
                    Diagnosis diagnosis = diagnosisManager
                            .getDiagnosisByRadarNumber(radarNumberModel.getObject());
                    diagnosisCode = diagnosis != null ? diagnosis.getDiagnosisCode() : null;
                }
            }

            if (diagnosisCode != null) {
                return diagnosisCode.getId().equals(DiagnosisPanel.SRNS_ID);
            }
            return false;
        }
    };

    Label successLabel = RadarComponentFactory.getSuccessMessageLabel("successMessage", form,
            componentsToUpdate);
    Label successLabelDown = RadarComponentFactory.getSuccessMessageLabel("successMessageDown", form,
            componentsToUpdate);

    Label errorLabel = RadarComponentFactory.getErrorMessageLabel("errorMessage", form, componentsToUpdate);
    Label errorLabelDown = RadarComponentFactory.getErrorMessageLabel("errorMessageDown", form,
            componentsToUpdate);

    TextField<Long> radarNumber = new TextField<Long>("radarNumber", radarNumberModel);
    radarNumber.setEnabled(false);
    form.add(radarNumber);

    form.add(new TextField("hospitalNumber",
            RadarModelFactory.getHospitalNumberModel(radarNumberModel, patientManager)));

    form.add(new TextField("diagnosis", new PropertyModel(
            RadarModelFactory.getDiagnosisCodeModel(radarNumberModel, diagnosisManager), "abbreviation")));

    form.add(new TextField("firstName", RadarModelFactory.getFirstNameModel(radarNumberModel, patientManager)));

    form.add(new TextField("surname", RadarModelFactory.getSurnameModel(radarNumberModel, patientManager)));

    form.add(new DateTextField("dob", RadarModelFactory.getDobModel(radarNumberModel, patientManager),
            RadarApplication.DATE_PATTERN));

    RadarRequiredDateTextField clinicalPictureDate = new RadarRequiredDateTextField("clinicalPictureDate", form,
            componentsToUpdate);
    form.add(clinicalPictureDate);

    RadarTextFieldWithValidation height = new RadarTextFieldWithValidation("height",
            new RangeValidator<Double>(RadarApplication.MIN_HEIGHT, RadarApplication.MAX_HEIGHT), form,
            componentsToUpdate);
    form.add(height);

    RadarTextFieldWithValidation weight = new RadarTextFieldWithValidation("weight",
            new RangeValidator<Double>(3.0, 100.0), form, componentsToUpdate);
    form.add(weight);
    // Blood pressure
    TextField<Double> systolicBloodPressure = new TextField("systolicBloodPressure");
    systolicBloodPressure.add(new RangeValidator<Integer>(50, 200));
    form.add(systolicBloodPressure);

    final ComponentFeedbackPanel systolicBloodPressureFeedback = new ComponentFeedbackPanel(
            "systolicBloodPressureFeedback", systolicBloodPressure);
    systolicBloodPressureFeedback.setOutputMarkupId(true);
    systolicBloodPressureFeedback.setOutputMarkupPlaceholderTag(true);
    form.add(systolicBloodPressureFeedback);

    diastolicBloodPressure.add(new RangeValidator<Integer>(20, 150));
    form.add(diastolicBloodPressure);

    final ComponentFeedbackPanel diastolicBloodPressureFeedback = new ComponentFeedbackPanel(
            "diastolicBloodPressureFeedback", diastolicBloodPressure);
    diastolicBloodPressureFeedback.setOutputMarkupId(true);
    diastolicBloodPressureFeedback.setOutputMarkupPlaceholderTag(true);
    form.add(diastolicBloodPressureFeedback);

    Component meanArterialPressure = new TextField("meanArterialPressure").setEnabled(false);
    meanArterialPressure.setOutputMarkupPlaceholderTag(true);
    meanArterialPressure.setOutputMarkupId(true);
    form.add(meanArterialPressure);
    componentsToUpdate.add(meanArterialPressure);

    WebMarkupContainer phenotypeContainer1 = new WebMarkupContainer(PHENOTYPE_CONTAINER_1) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    WebMarkupContainer phenotypeContainer2 = new WebMarkupContainer(PHENOTYPE_CONTAINER_2) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    WebMarkupContainer phenotypeContainer3 = new WebMarkupContainer(PHENOTYPE_CONTAINER_3) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    WebMarkupContainer phenotypeContainer4 = new WebMarkupContainer(PHENOTYPE_CONTAINER_4) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    phenotypeContainer1.add(new PhenotypeChooser("phenotype1"));
    phenotypeContainer2.add(new PhenotypeChooser("phenotype2"));
    phenotypeContainer3.add(new PhenotypeChooser("phenotype3"));
    phenotypeContainer4.add(new PhenotypeChooser("phenotype4"));

    form.add(phenotypeContainer1);
    form.add(phenotypeContainer2);
    form.add(phenotypeContainer3);
    form.add(phenotypeContainer4);

    form.add(new TextArea("comments"));
    form.add(new TextField("significantDiagnosis1"));
    form.add(new TextField("significantDiagnosis2"));

    // Yes/No/Unknown for the following
    WebMarkupContainer patientDetailsContainer = new WebMarkupContainer(PATIENT_DETAILS_CONTAINER) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    patientDetailsContainer.setOutputMarkupPlaceholderTag(true);
    form.add(patientDetailsContainer);

    patientDetailsContainer.add(new YesNoRadioGroup("oedema", true));
    patientDetailsContainer.add(new YesNoRadioGroup("hypovalaemia", true));
    patientDetailsContainer.add(new YesNoRadioGroup("fever", true));

    WebMarkupContainer thrombosisContainer = new WebMarkupContainer(THROMBOSIS_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    YesNoRadioGroup thrombosis = new YesNoRadioGroup("thrombosis", true);
    thrombosisContainer.add(thrombosis);
    patientDetailsContainer.add(thrombosisContainer);

    WebMarkupContainer peritonitisContainer = new WebMarkupContainer(PERITONITIS_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    peritonitisContainer.add(new YesNoRadioGroup("peritonitis", true));
    patientDetailsContainer.add(peritonitisContainer);

    WebMarkupContainer pulmonaryOedemaContainer = new WebMarkupContainer(PULMONARY_OEDEMA_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return isSrnsModel.getObject();
        }
    };
    pulmonaryOedemaContainer.add(new YesNoRadioGroup("pulmonaryOedema", true));
    patientDetailsContainer.add(pulmonaryOedemaContainer);
    patientDetailsContainer.add(new YesNoRadioGroup("hypertension", true));

    //urticaria
    boolean showUrticariaOnInit = form.getModelObject().getUrticaria() != null
            ? form.getModelObject().getUrticaria()
            : false;

    // only show if diag is mpgn/dd
    if (isSrnsModel.getObject().equals(true)) {
        showUrticariaOnInit = false;
    }

    final IModel<Boolean> showUrticariaIModel = new Model<Boolean>(showUrticariaOnInit);

    MarkupContainer urticariaDetailContainer = new WebMarkupContainer(URTICARIA_DETAIL_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            if (!hideElement(isFirstVisit, isSrnsModel.getObject(), getId())) {
                return showUrticariaIModel.getObject();
            }
            return false;
        }
    };
    componentsToUpdate.add(urticariaDetailContainer);

    urticariaDetailContainer.add(new TextArea("rashDetail")); // shares same field in db as rash detail It seems
    patientDetailsContainer.add(urticariaDetailContainer);
    urticariaDetailContainer.setOutputMarkupId(true);
    urticariaDetailContainer.setOutputMarkupPlaceholderTag(true);

    // More yes/no options
    WebMarkupContainer urticariaContainer = new WebMarkupContainer(URTICARIA_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    YesNoRadioGroup urticaria = new YesNoRadioGroup("urticaria", true);
    urticariaContainer.add(urticaria);
    patientDetailsContainer.add(urticariaContainer);
    urticaria.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showUrticariaIModel.setObject(Boolean.TRUE.equals(form.getModelObject().getUrticaria()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });

    // Diabetes
    WebMarkupContainer diabetesTypeContainer = new WebMarkupContainer(DIABETES_TYPE_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    diabetesTypeContainer.add(new DropDownChoice<ClinicalData.DiabetesType>("diabetesType",
            Arrays.asList(ClinicalData.DiabetesType.TYPE_I, ClinicalData.DiabetesType.TYPE_II,
                    ClinicalData.DiabetesType.NO),
            new ChoiceRenderer<ClinicalData.DiabetesType>("label", "id")));
    patientDetailsContainer.add(diabetesTypeContainer);

    boolean showRashDetailsOnInit = form.getModelObject().getRash() != null ? form.getModelObject().getRash()
            : false;
    // only show if diag is srns
    if (isSrnsModel.getObject().equals(false)) {
        showRashDetailsOnInit = false;
    }

    final IModel<Boolean> showRashDetailsIModel = new Model<Boolean>(showRashDetailsOnInit);

    // Rash details needs show/hide
    final MarkupContainer rashDetailContainer = new WebMarkupContainer(RASH_DETAIL_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            if (!hideElement(isFirstVisit, isSrnsModel.getObject(), getId())) {
                return showRashDetailsIModel.getObject();
            }
            return false;
        }
    };

    rashDetailContainer.add(new TextArea("rashDetail"));
    patientDetailsContainer.add(rashDetailContainer);
    rashDetailContainer.setOutputMarkupId(true);
    rashDetailContainer.setOutputMarkupPlaceholderTag(true);
    componentsToUpdate.add(rashDetailContainer);

    // More yes/no options
    WebMarkupContainer rashContainer = new WebMarkupContainer(RASH_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    YesNoRadioGroup rash = new YesNoRadioGroup("rash", true);
    rashContainer.add(rash);
    patientDetailsContainer.add(rashContainer);

    rash.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showRashDetailsIModel.setObject(Boolean.TRUE.equals(form.getModelObject().getRash()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });

    WebMarkupContainer possibleImmunisationTriggerContainer = new WebMarkupContainer(
            POSSIBLE_IMMUNISATION_TRIGGER_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    YesNoRadioGroup possibleImmunisationTrigger = new YesNoRadioGroup("possibleImmunisationTrigger", true);
    possibleImmunisationTriggerContainer.add(possibleImmunisationTrigger);
    patientDetailsContainer.add(possibleImmunisationTriggerContainer);

    WebMarkupContainer partialLipodystrophyContainer = new WebMarkupContainer(
            PARTIAL_LIPODYSTROPHY_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    YesNoRadioGroup partialLipodystrophy = new YesNoRadioGroup("partialLipodystrophy", true);

    partialLipodystrophyContainer.add(partialLipodystrophy);
    patientDetailsContainer.add(partialLipodystrophyContainer);

    WebMarkupContainer preceedingInfectionContainer = new WebMarkupContainer(
            PRECEEDING_INFECTION_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    // preceding infection
    boolean showPrecedingInfectionOnInit = form.getModelObject().getPreceedingInfection() != null
            ? form.getModelObject().getPreceedingInfection()
            : false;

    // only show if diag is mpgn/dd
    if (isSrnsModel.getObject().equals(true)) {
        showPrecedingInfectionOnInit = false;
    }

    final IModel<Boolean> showPrecedingInfectioModel = new Model<Boolean>(showPrecedingInfectionOnInit);

    YesNoRadioGroup preceedingInfection = new YesNoRadioGroup("preceedingInfection", true);
    preceedingInfectionContainer.add(preceedingInfection);
    preceedingInfection.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showPrecedingInfectioModel
                    .setObject(Boolean.TRUE.equals(form.getModelObject().getPreceedingInfection()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });
    patientDetailsContainer.add(preceedingInfectionContainer);

    // Preceeding infection show/hide
    MarkupContainer preceedingInfectionDetailContainer = new WebMarkupContainer(
            PRECEEDING_INFECTION_DETAIL_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return showPrecedingInfectioModel.getObject();
        }
    };
    TextAreaWithHelpText preceedingInfectionDetail = new TextAreaWithHelpText("preceedingInfectionDetail",
            "Enter details") {
        @Override
        public String getModelData() {
            ClinicalData clinicalData = formModel.getObject();
            return clinicalData != null ? clinicalData.getPreceedingInfectionDetail() != null
                    ? clinicalData.getPreceedingInfectionDetail()
                    : "" : "";
        }

        @Override
        public void setModelData(String data) {
            ClinicalData clinicalData = formModel.getObject();
            if (clinicalData != null) {
                clinicalData.setPreceedingInfectionDetail(data);
            }
        }
    };
    preceedingInfectionDetail.initBehaviour();
    preceedingInfectionDetailContainer.add(preceedingInfectionDetail);
    patientDetailsContainer.add(preceedingInfectionDetailContainer);
    componentsToUpdate.add(preceedingInfectionDetailContainer);
    preceedingInfectionDetailContainer.setOutputMarkupId(true);
    preceedingInfectionDetailContainer.setOutputMarkupPlaceholderTag(true);

    // chronic infection
    boolean showChronicOnInit = form.getModelObject().getChronicInfection() != null
            ? form.getModelObject().getChronicInfection()
            : false;

    // only show if diag is mpgn/dd
    if (isSrnsModel.getObject().equals(true)) {
        showChronicOnInit = false;
    }

    final IModel<Boolean> showChronicModel = new Model<Boolean>(showChronicOnInit);

    WebMarkupContainer chronicInfectionActiveContainer = new WebMarkupContainer(
            CHRONIC_INFECTION_ACTIVE_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    YesNoRadioGroup chronicInfection = new YesNoRadioGroup("chronicInfection", true);
    chronicInfection.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showChronicModel.setObject(Boolean.TRUE.equals(form.getModelObject().getChronicInfection()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });
    chronicInfectionActiveContainer.add(chronicInfection);
    patientDetailsContainer.add(chronicInfectionActiveContainer);

    // Chronic infection show/hide
    MarkupContainer chronicInfectionDetailContainer = new WebMarkupContainer(
            CHRONIC_INFECTION_DETAIL_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            if (!hideElement(isFirstVisit, isSrnsModel.getObject(), getId())) {
                return showChronicModel.getObject();
            }
            return false;
        }
    };
    TextAreaWithHelpText chronicInfectionDetail = new TextAreaWithHelpText("chronicInfectionDetail",
            "Enter Details") {
        @Override
        public String getModelData() {
            ClinicalData clinicalData = formModel.getObject();
            return clinicalData != null ? clinicalData.getChronicInfectionDetail() != null
                    ? clinicalData.getChronicInfectionDetail()
                    : "" : "";
        }

        @Override
        public void setModelData(String data) {
            ClinicalData clinicalData = formModel.getObject();
            if (clinicalData != null) {
                clinicalData.setChronicInfectionDetail(data);
            }
        }
    };

    chronicInfectionDetail.initBehaviour();

    chronicInfectionDetailContainer.add(chronicInfectionDetail);
    componentsToUpdate.add(chronicInfectionDetailContainer);
    chronicInfectionDetailContainer.setOutputMarkupId(true);
    chronicInfectionDetailContainer.setOutputMarkupPlaceholderTag(true);

    patientDetailsContainer.add(chronicInfectionDetailContainer);

    boolean showOphthalmoscopyDetailsOnInit = form.getModelObject().getOphthalmoscopy() != null
            ? form.getModelObject().getOphthalmoscopy()
            : false;

    final IModel<Boolean> showOphthalmoscopyDetailsIModel = new Model<Boolean>(showOphthalmoscopyDetailsOnInit);

    YesNoRadioGroup ophthalmoscopy = new YesNoRadioGroup("ophthalmoscopy", true);
    patientDetailsContainer.add(ophthalmoscopy);
    ophthalmoscopy.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showOphthalmoscopyDetailsIModel
                    .setObject(Boolean.TRUE.equals(form.getModelObject().getOphthalmoscopy()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });

    // Ophthalmoscopy show/hide
    MarkupContainer ophthalmoscopyDetailContainer = new WebMarkupContainer("ophthalmoscopyDetailContainer") {
        @Override
        public boolean isVisible() {
            return showOphthalmoscopyDetailsIModel.getObject();
        }
    };
    ophthalmoscopyDetailContainer.setOutputMarkupId(true);
    ophthalmoscopyDetailContainer.setOutputMarkupPlaceholderTag(true);
    componentsToUpdate.add(ophthalmoscopyDetailContainer);

    TextAreaWithHelpText ophthalmoscopyDetail = new TextAreaWithHelpText("ophthalmoscopyDetail",
            ClinicalData.OPHTHALMOSCOPY_HELP_TEXT) {
        @Override
        public String getModelData() {
            ClinicalData clinicalData = formModel.getObject();
            return clinicalData != null
                    ? clinicalData.getOphthalmoscopyDetail() != null ? clinicalData.getOphthalmoscopyDetail()
                            : ""
                    : "";
        }

        @Override
        public void setModelData(String data) {
            ClinicalData clinicalData = formModel.getObject();
            if (clinicalData != null) {
                clinicalData.setOphthalmoscopyDetail(data);
            }
        }
    };

    ophthalmoscopyDetail.initBehaviour();

    ophthalmoscopyDetailContainer.add(ophthalmoscopyDetail);

    patientDetailsContainer.add(ophthalmoscopyDetailContainer);

    componentsToUpdate.add(systolicBloodPressureFeedback);
    componentsToUpdate.add(diastolicBloodPressureFeedback);

    // Complications
    WebMarkupContainer complicationsContainer = new WebMarkupContainer("complicationsContainer") {
        @Override
        public boolean isVisible() {
            return !isFirstVisit && isSrnsModel.getObject();
        }
    };

    complicationsContainer.add(new YesNoRadioGroup("infectionNecessitatingHospitalisation", false, false));
    MarkupContainer infectionDetailContainer = new WebMarkupContainer("infectionDetailContainer");
    infectionDetailContainer.add(new TextArea("infectionDetail"));
    complicationsContainer.add(infectionDetailContainer);

    complicationsContainer.add(new YesNoRadioGroup("complicationThrombosis", false, false));
    MarkupContainer complicationThrombosisDetailContainer = new WebMarkupContainer(
            "complicationThrombosisContainer");
    complicationThrombosisDetailContainer.add(new TextArea("complicationThrombosisDetail"));
    complicationsContainer.add(complicationThrombosisDetailContainer);

    // Hypertension
    complicationsContainer.add(new YesNoRadioGroup("hypertension", true));

    // CKD stage
    complicationsContainer.add(new CkdStageRadioGroup("ckdStage"));
    form.add(complicationsContainer);

    // Listed for transplant?

    WebMarkupContainer listedForTransplantContainer = new WebMarkupContainer("listedForTransplantContainer") {
        @Override
        public boolean isVisible() {
            return !isFirstVisit && isSrnsModel.getObject();
        }
    };

    form.add(listedForTransplantContainer);
    listedForTransplantContainer.add(new YesNoRadioGroup("listedForTransplant"));

    ClinicalAjaxSubmitLink save = new ClinicalAjaxSubmitLink("save") {
        @Override
        protected List<? extends Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    };

    ClinicalAjaxSubmitLink saveDown = new ClinicalAjaxSubmitLink("saveDown") {
        @Override
        protected List<? extends Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    };

    form.add(save, saveDown);
}

From source file:org.patientview.radar.web.panels.generic.GenericDemographicsPanel.java

License:Open Source License

private void init(Patient patient) {
    setOutputMarkupId(true);//from   w w  w.j a v a2s .  com
    setOutputMarkupPlaceholderTag(true);

    List<Component> nonEditableComponents = new ArrayList<Component>();

    final ProfessionalUser user = (ProfessionalUser) RadarSecuredSession.get().getUser();

    if (patient.getDateReg() == null) {
        patient.setDateReg(new Date());
    }

    // components to update on ajax refresh
    final List<Component> componentsToUpdateList = new ArrayList<Component>();

    // add form
    final IModel<Patient> model = new Model(patient);

    //Error Message
    String message = "Please complete all mandatory fields";
    final LabelMessage labelMessage = new LabelMessage();
    labelMessage.setMessage(message);
    final PropertyModel<LabelMessage> messageModel = new PropertyModel<LabelMessage>(labelMessage, "message");

    // no exist data in patient table, then use the user name to populate.
    if (patient.getSurname() == null || patient.getForename() == null) {

        String name = utilityManager.getUserName(patient.getNhsno());

        if (name != null && !"".equals(name)) {
            // split the user name with a space
            String[] names = name.split(" ");
            if (names != null && names.length >= 2) {
                patient.setForename(name.substring(0, name.indexOf(names[names.length - 1])));
                patient.setSurname(names[names.length - 1]);

            } else {
                patient.setForename(name);
            }
        }
    }

    Form<Patient> form = new Form<Patient>("form", new CompoundPropertyModel(model)) {
        @Override
        protected void onSubmit() {

            Patient patient = getModel().getObject();

            // check dob exists
            if (patient.getDob() != null) {
                // make sure diagnosis date is after dob
                if (patient.getDateOfGenericDiagnosis() != null
                        && patient.getDateOfGenericDiagnosis().compareTo(patient.getDob()) < 0) {
                    get("dateOfGenericDiagnosisContainer:dateOfGenericDiagnosis")
                            .error("Your diagnosis date cannot be before your date of birth");
                }
            }

            // Leaving this in, saved to the DB table
            patient.setGeneric(true);

            try {
                /** At this point we either have
                 1) A new patient we would like to register
                 2) A link patient we would like to register
                 3) An existing linked patient we would like to update changes to the Patient table
                 4) An existing patient we would like to update changes to the Patient table **/
                userManager.addPatientUserOrUpdatePatient(patient);

            } catch (RegisterException re) {
                LOGGER.error("Registration Exception", re);
                String message = "Failed to register patient: " + re.getMessage();
                labelMessage.setMessage(message);
                error(message);
            } catch (Exception e) {
                String message = "Error registering new patient to accompany this demographic";
                LOGGER.error("Unknown error", e);
                error(message);
            }
        }
    };

    add(form);

    WebMarkupContainer patientDetail = new PatientDetailPanel("patientDetail", patient, "Demographics");
    patientDetail.setOutputMarkupId(true);
    patientDetail.setOutputMarkupPlaceholderTag(true);
    form.add(patientDetail);
    componentsToUpdateList.add(patientDetail);

    RadarRequiredTextField surname = new RadarRequiredTextField("surname", form, componentsToUpdateList);
    RadarRequiredTextField forename = new RadarRequiredTextField("forename", form, componentsToUpdateList);
    TextField alias = new TextField("surnameAlias");
    RadarRequiredDateTextField dateOfBirth = new RadarRequiredDateTextField("dob", form,
            componentsToUpdateList);

    form.add(surname, forename, alias, dateOfBirth);
    nonEditableComponents.add(surname);
    nonEditableComponents.add(forename);
    nonEditableComponents.add(dateOfBirth);
    // Sex
    RadarRequiredDropdownChoice sex = new RadarRequiredDropdownChoice("sexModel", patientManager.getSexes(),
            new ChoiceRenderer<Sex>("type", "id"), form, componentsToUpdateList);

    nonEditableComponents.add(sex);

    // Ethnicity
    DropDownChoice<Ethnicity> ethnicity = new DropDownChoice<Ethnicity>("ethnicity",
            utilityManager.getEthnicities(), new ChoiceRenderer<Ethnicity>("name", "id"));
    form.add(sex, ethnicity);

    // Address fields
    TextField address1 = new TextField("address1");
    TextField address2 = new TextField("address2");
    TextField address3 = new TextField("address3");
    TextField address4 = new TextField("address4");
    RadarTextFieldWithValidation postcode = new RadarTextFieldWithValidation("postcode",
            new PatternValidator("[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$"), form,
            componentsToUpdateList);
    form.add(address1, address2, address3, address4, postcode);

    nonEditableComponents.add(address1);
    nonEditableComponents.add(address2);
    nonEditableComponents.add(address3);
    nonEditableComponents.add(address4);
    nonEditableComponents.add(postcode);
    // More info
    Label nhsNumber = new Label("nhsno");

    WebMarkupContainer nhsNumberContainer = new WebMarkupContainer("nhsNumberContainer");

    nhsNumberContainer.add(nhsNumber);

    // add new ids section
    final List<Component> addIdComponentsToUpdate = new ArrayList<Component>();

    IModel<AddIdModel> addIdModel = new Model<AddIdModel>(new AddIdModel());
    Form<AddIdModel> addIdForm = new Form<AddIdModel>("addIdForm", new CompoundPropertyModel(addIdModel)) {
        @Override
        protected void onSubmit() {
            AddIdModel idModel = getModel().getObject();
            Patient patient = model.getObject();
            String id = idModel.getId();
            if (idModel.getIdType() != null) {
                if (idModel.getIdType().equals(IdType.CHANNELS_ISLANDS)) {
                    patient.setChannelIslandsId(id);
                }
                if (idModel.getIdType().equals(IdType.HOSPITAL_NUMBER)) {
                    patient.setHospitalnumber(id);
                }
                if (idModel.getIdType().equals(IdType.INDIA)) {
                    patient.setIndiaId(id);
                }
                if (idModel.getIdType().equals(IdType.RENAL_REGISTRY_NUMBER)) {
                    patient.setRrNo(id);
                }
                if (idModel.getIdType().equals(IdType.REPUBLIC_OF_IRELAND)) {
                    patient.setRepublicOfIrelandId(id);
                }
                if (idModel.getIdType().equals(IdType.UK_TRANSPLANT_NUMBER)) {
                    patient.setUktNo(id);
                }
            }
        }

    };

    AjaxSubmitLink addIdSubmit = new AjaxSubmitLink("addIdSubmit") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, addIdComponentsToUpdate);
        }

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

    TextField addIdValue = new TextField("id");

    DropDownChoice addIdType = null;

    // Link patients should not be able to add hospital numbers
    if (!patient.isLinked()) {
        addIdType = new DropDownChoice("idType",
                Arrays.asList(IdType.HOSPITAL_NUMBER, IdType.RENAL_REGISTRY_NUMBER, IdType.UK_TRANSPLANT_NUMBER,
                        IdType.REPUBLIC_OF_IRELAND, IdType.CHANNELS_ISLANDS, IdType.INDIA),
                new ChoiceRenderer());
    } else {
        addIdType = new DropDownChoice("idType",
                Arrays.asList(IdType.RENAL_REGISTRY_NUMBER, IdType.UK_TRANSPLANT_NUMBER,
                        IdType.REPUBLIC_OF_IRELAND, IdType.CHANNELS_ISLANDS, IdType.INDIA),
                new ChoiceRenderer());
    }

    addIdForm.add(addIdValue, addIdType, addIdSubmit);
    form.add(addIdForm);

    TextField hospitalNumber = new TextField("hospitalnumber");
    WebMarkupContainer hospitalNumberContainer = new WebMarkupContainer("hospitalNumberContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getHospitalnumber() != null) {
                if (!model.getObject().getHospitalnumber().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };

    hospitalNumberContainer.add(hospitalNumber);
    nonEditableComponents.add(hospitalNumber);

    TextField renalRegistryNumber = new TextField("rrNo");
    WebMarkupContainer renalRegistryNumberContainer = new WebMarkupContainer("renalRegistryNumberContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getRrNo() != null) {
                if (!model.getObject().getRrNo().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    renalRegistryNumberContainer.add(renalRegistryNumber);

    TextField ukTransplantNumber = new TextField("uktNo");

    WebMarkupContainer ukTransplantNumberContainer = new WebMarkupContainer("ukTransplantNumberContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getUktNo() != null) {
                if (!model.getObject().getUktNo().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    ukTransplantNumberContainer.add(ukTransplantNumber);

    // add other generic ids
    TextField republicOfIrelandId = new TextField("republicOfIrelandId");

    WebMarkupContainer republicOfIrelandIdContainer = new WebMarkupContainer("republicOfIrelandIdContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getRepublicOfIrelandId() != null) {
                if (!model.getObject().getRepublicOfIrelandId().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    republicOfIrelandIdContainer.add(republicOfIrelandId);

    TextField isleOfManId = new TextField("isleOfManId");

    WebMarkupContainer isleOfManIdContainer = new WebMarkupContainer("isleOfManIdContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getIsleOfManId() != null) {
                if (!model.getObject().getIsleOfManId().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };

    isleOfManIdContainer.add(isleOfManId);

    TextField channelIslandsId = new TextField("channelIslandsId");

    WebMarkupContainer channelIslandsIdContainer = new WebMarkupContainer("channelIslandsIdContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getChannelIslandsId() != null) {
                if (!model.getObject().getChannelIslandsId().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    channelIslandsIdContainer.add(channelIslandsId);

    TextField indiaId = new TextField("indiaId");

    WebMarkupContainer indiaIdContainer = new WebMarkupContainer("indiaIdContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getIndiaId() != null) {
                if (!model.getObject().getIndiaId().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    indiaIdContainer.add(indiaId);

    addIdComponentsToUpdate.add(hospitalNumberContainer);
    addIdComponentsToUpdate.add(renalRegistryNumberContainer);
    addIdComponentsToUpdate.add(ukTransplantNumberContainer);
    addIdComponentsToUpdate.add(republicOfIrelandIdContainer);
    addIdComponentsToUpdate.add(isleOfManIdContainer);
    addIdComponentsToUpdate.add(channelIslandsIdContainer);
    addIdComponentsToUpdate.add(indiaIdContainer);

    for (Component component : Arrays.asList(hospitalNumberContainer, renalRegistryNumberContainer,
            ukTransplantNumberContainer, republicOfIrelandIdContainer, isleOfManIdContainer,
            channelIslandsIdContainer, indiaIdContainer)) {
        component.setOutputMarkupPlaceholderTag(true);
    }

    form.add(hospitalNumberContainer, nhsNumberContainer, renalRegistryNumberContainer,
            ukTransplantNumberContainer);
    form.add(republicOfIrelandIdContainer, isleOfManIdContainer, channelIslandsIdContainer, indiaIdContainer);

    // Consultant and renal unit
    final ClinicianDropDown clinician = new ClinicianDropDown("clinician", user, form.getModelObject());
    form.add(clinician);

    Label sourceUnitCodeLabel = new Label("sourceUnitCodeLabel", "Linked to") {
        @Override
        public boolean isVisible() {
            return model.getObject().isLinked();

        }

    };

    String sourceUnitNameLabelValue = model.getObject().getPatientLinkUnitCode() != null
            ? utilityManager.getCentre(model.getObject().getPatientLinkUnitCode()).getName()
            : "";

    Label sourceUnitCode = new Label("sourceUnitCode", sourceUnitNameLabelValue) {
        @Override
        public boolean isVisible() {
            return model.getObject().isLinked();

        }
    };
    form.add(sourceUnitCodeLabel, sourceUnitCode);

    final DropDownChoice<Centre> renalUnit = new PatientCentreDropDown("renalUnit", user, patient, form,
            componentsToUpdateList);

    renalUnit.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            Patient patient = model.getObject();
            if (patient != null) {
                clinician.updateCentre(
                        patient.getRenalUnit() != null ? patient.getRenalUnit().getUnitCode() : null);
            }

            // re-render the component
            clinician.clearInput();
            target.add(clinician);
        }
    });

    form.add(renalUnit);

    final IModel<String> consentUserModel = new Model<String>(
            utilityManager.getUserFullName(patient.getRadarConsentConfirmedByUserId()));

    final Label tickConsentUser = new Label("radarConsentConfirmedByUserId", consentUserModel) {
        @Override
        public boolean isVisible() {
            return StringUtils.isNotEmpty(consentUserModel.getObject());
        }
    };
    tickConsentUser.setOutputMarkupId(true);
    tickConsentUser.setOutputMarkupPlaceholderTag(true);
    form.add(tickConsentUser);

    final RadarRequiredCheckBox consent = new RadarRequiredCheckBox("consent", form, componentsToUpdateList);

    consent.add(new AjaxFormComponentUpdatingBehavior("onclick") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            target.add(tickConsentUser);

            if (consent.getModel().getObject().equals(Boolean.TRUE)) {
                model.getObject()
                        .setRadarConsentConfirmedByUserId(RadarSecuredSession.get().getUser().getUserId());
                consentUserModel.setObject(RadarSecuredSession.get().getUser().getName());
                tickConsentUser.setVisible(true);

            } else {
                tickConsentUser.setVisible(false);
            }
        }
    });

    form.add(consent);

    form.add(new ExternalLink("consentFormsLink", "http://www.rarerenal.org/join/criteria-and-consent/"));

    // add generic fields
    TextField emailAddress = new TextField("emailAddress");
    TextField phone1 = new TextField("telephone1");
    TextField phone2 = new TextField("telephone2");

    nonEditableComponents.add(phone1);

    RadarTextFieldWithValidation mobile = new RadarTextFieldWithValidation("mobile",
            new PatternValidator(MetaPattern.DIGITS), form, componentsToUpdateList);

    RadarRequiredDropdownChoice genericDiagnosis = new RadarRequiredDropdownChoice("genericDiagnosisModel",
            genericDiagnosisManager.getByDiseaseGroup(patient.getDiseaseGroup()),
            new ChoiceRenderer("term", "id"), form, componentsToUpdateList);

    final IModel<Boolean> diagnosisDateVisibility = new Model<Boolean>(Boolean.FALSE);

    final CheckBox diagnosisDateSelect = new CheckBox("diagnosisDateSelect", new Model<Boolean>(Boolean.FALSE));
    model.getObject().setDiagnosisDateSelect(model.getObject().getDiagnosisDateSelect() == Boolean.TRUE);

    diagnosisDateSelect.add(new AjaxFormComponentUpdatingBehavior("onClick") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            diagnosisDateVisibility.setObject(diagnosisDateSelect.getModel().getObject());
            target.add(componentsToUpdateList.toArray(new Component[componentsToUpdateList.size()]));
        }
    });

    RadarRequiredDateTextField dateOfGenericDiagnosis = new RadarRequiredDateTextField("dateOfGenericDiagnosis",
            form, componentsToUpdateList);

    form.add(diagnosisDateSelect);

    MarkupContainer dateOfGenericDiagnosisContainer = new WebMarkupContainer(
            "dateOfGenericDiagnosisContainer") {
        @Override
        public boolean isVisible() {
            if (diagnosisDateVisibility.getObject()) {
                return false;
            } else {
                return true;
            }
        }
    };
    dateOfGenericDiagnosisContainer.add(dateOfGenericDiagnosis);
    componentsToUpdateList.add(dateOfGenericDiagnosisContainer);
    dateOfGenericDiagnosisContainer.setOutputMarkupId(true);
    dateOfGenericDiagnosisContainer.setOutputMarkupPlaceholderTag(true);

    this.dateOfGenericDiagnosisContainer = dateOfGenericDiagnosisContainer;

    TextArea otherClinicianAndContactInfo = new TextArea("otherClinicianAndContactInfo");
    TextArea comments = new TextArea("comments");

    form.add(emailAddress, phone1, phone2, mobile, genericDiagnosis, dateOfGenericDiagnosisContainer,
            otherClinicianAndContactInfo, comments);

    RadioGroup<Patient.RRTModality> rrtModalityRadioGroup = new RadioGroup<Patient.RRTModality>(
            "rrtModalityEunm");
    rrtModalityRadioGroup.add(new Radio("hd", new Model(Patient.RRTModality.HD)));
    rrtModalityRadioGroup.add(new Radio("pd", new Model(Patient.RRTModality.PD)));
    rrtModalityRadioGroup.add(new Radio("tx", new Model(Patient.RRTModality.Tx)));
    rrtModalityRadioGroup.add(new Radio("none", new Model(Patient.RRTModality.NONE)));

    form.add(rrtModalityRadioGroup);

    RadarComponentFactory.getSuccessMessageLabel("successMessage", form, componentsToUpdateList);

    RadarComponentFactory.getSuccessMessageLabel("successMessageUp", form, componentsToUpdateList);

    RadarComponentFactory.getMessageLabel("errorMessage", form, messageModel, componentsToUpdateList);
    RadarComponentFactory.getMessageLabel("errorMessageUp", form, messageModel, componentsToUpdateList);

    AjaxSubmitLink ajaxSubmitLinkTop = new AjaxSubmitLink("saveTop") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT);
        }

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

    AjaxSubmitLink ajaxSubmitLinkBottom = new AjaxSubmitLink("saveBottom") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT);
        }

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

    form.add(ajaxSubmitLinkTop);
    form.add(ajaxSubmitLinkBottom);

    if (patient.isLinked()) {
        for (Component component : nonEditableComponents) {
            component.setEnabled(false);
        }
    }

}

From source file:org.wicketopia.persistence.component.scaffold.Scaffold.java

License:Apache License

private void refreshContent(AjaxRequestTarget target) {
    final Component content = createContent();
    content.setOutputMarkupPlaceholderTag(true);
    addOrReplace(content);//from  www  .  j  a  v a2s.com
    if (target != null) {
        target.add(this);
    }
}