Example usage for org.apache.wicket.markup.html.form FormComponentLabel setVisible

List of usage examples for org.apache.wicket.markup.html.form FormComponentLabel setVisible

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form FormComponentLabel setVisible.

Prototype

public final Component setVisible(final boolean visible) 

Source Link

Document

Sets whether this component and any children are visible.

Usage

From source file:org.sakaiproject.attendance.tool.panels.AttendanceGradePanel.java

License:Educational Community License

private Form<AttendanceGrade> createGradeForm() {
    Form<AttendanceGrade> gForm = new Form<AttendanceGrade>("attendance-grade", this.agIModel) {
        @Override/* w w w.j a va 2s.c o m*/
        public void onSubmit() {
            AttendanceGrade aG = (AttendanceGrade) getDefaultModelObject();

            boolean result;

            if (Boolean.TRUE.equals(attendanceSite.getUseAutoGrading())
                    && Boolean.FALSE.equals(aG.getOverride())) {
                result = attendanceLogic.regrade(aG, true) != null;
            } else {
                result = attendanceLogic.updateAttendanceGrade(aG);
            }

            String displayName = sakaiProxy.getUserSortName(aG.getUserID());

            if (result) {
                String grade = aG.getGrade() == null ? "null" : aG.getGrade().toString();
                getSession().info(new StringResourceModel("attendance.grade.update.success", null,
                        new String[] { grade, displayName }).getString());
            } else {
                getSession().error(new StringResourceModel("attendance.grade.update.failure", null,
                        new String[] { displayName }).getString());
            }

        }
    };

    final Double maximumGrade = this.attendanceSite.getMaximumGrade();

    NumberTextField<Double> points = new NumberTextField<Double>("grade") {
        @Override
        public boolean isEnabled() {
            return maximumGrade != null && (Boolean.FALSE.equals(attendanceSite.getUseAutoGrading())
                    || Boolean.TRUE.equals(agIModel.getObject().getOverride()));
        }
    };
    points.setMinimum(0.0);
    points.setStep(0.1);

    points.add(new AjaxFormSubmitBehavior(gForm, "input") {
        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(pageFeedbackPanel);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            if (target != null) {
                target.add(pageFeedbackPanel);
            }
        }
    });

    Label maximum;

    if (maximumGrade == null) {
        maximum = new Label("maximum", "/ -");
        points.add(new AttributeModifier("title", new StringResourceModel("attendance.grade.tooltip.disabled",
                null, new String[] { new ResourceModel("settings.link.label").getObject() })));
    } else {
        maximum = new Label("maximum", "/ " + maximumGrade.toString());
    }
    maximum.setVisible(!this.isEnabled());

    final CheckBox override = new CheckBox("override", new PropertyModel<>(gForm.getModelObject(), "override"));
    override.setVisible(this.attendanceSite.getUseAutoGrading() && this.isEnabled());
    override.add(new AjaxFormSubmitBehavior(gForm, "change") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            if (target != null) {
                target.add(pageFeedbackPanel);
                target.add(points);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(pageFeedbackPanel);
        }
    });
    gForm.add(override);

    final FormComponentLabel overrideLabel = new FormComponentLabel("overrideLabel", override);
    overrideLabel.setVisible(this.attendanceSite.getUseAutoGrading() && this.isEnabled());
    gForm.add(overrideLabel);

    gForm.add(maximum);
    gForm.add(points);

    return gForm;
}