package net.sourceforge.fenixedu.presentationTier.renderers.iscte; import java.util.Collection; import net.sourceforge.fenixedu.dataTransferObject.administrativeOffice.dismissal.ISCTEDismissalBean; import net.sourceforge.fenixedu.dataTransferObject.administrativeOffice.dismissal.ISCTEDismissalBean.DismissalType; import net.sourceforge.fenixedu.domain.ExecutionPeriod; import net.sourceforge.fenixedu.domain.StudentCurricularPlan; import net.sourceforge.fenixedu.domain.degreeStructure.Context; import net.sourceforge.fenixedu.domain.degreeStructure.CourseGroup; import net.sourceforge.fenixedu.domain.degreeStructure.CycleType; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.CycleCurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.NoCourseGroupCurriculumGroup; import net.sourceforge.fenixedu.presentationTier.renderers.converters.DomainObjectKeyConverter; import net.sourceforge.fenixedu.presentationTier.renderers.providers.academicAdminOffice.DismissalDismissalsProvider; import pt.ist.fenixWebFramework.renderers.DataProvider; import pt.ist.fenixWebFramework.renderers.InputRenderer; import pt.ist.fenixWebFramework.renderers.components.HtmlBlockContainer; import pt.ist.fenixWebFramework.renderers.components.HtmlComponent; import pt.ist.fenixWebFramework.renderers.components.HtmlLabel; import pt.ist.fenixWebFramework.renderers.components.HtmlMenu; import pt.ist.fenixWebFramework.renderers.components.HtmlRadioButton; import pt.ist.fenixWebFramework.renderers.components.HtmlRadioButtonGroup; import pt.ist.fenixWebFramework.renderers.components.HtmlTable; import pt.ist.fenixWebFramework.renderers.components.HtmlTableCell; import pt.ist.fenixWebFramework.renderers.components.HtmlTableRow; import pt.ist.fenixWebFramework.renderers.components.HtmlText; import pt.ist.fenixWebFramework.renderers.layouts.Layout; import pt.ist.fenixWebFramework.renderers.model.MetaObject; import pt.ist.fenixWebFramework.renderers.model.MetaObjectFactory; import pt.ist.fenixWebFramework.renderers.schemas.Schema; import pt.ist.fenixWebFramework.renderers.utils.RenderUtils; public final class ISCTEStudentDismissalRenderer extends InputRenderer { private Integer initialWidth = 60; private Integer widthDecreasePerLevel = 3; private String tablesClasses = "showinfo3 mvert0"; private String groupRowClasses = "bgcolor2"; private String curricularCourseRowClasses = ""; private String groupCellClasses = "smalltxt, aright"; private String curricularCourseCellClasses = ", aright"; public Integer getInitialWidth() { return initialWidth; } public void setInitialWidth(Integer initialWidth) { this.initialWidth = initialWidth; } public Integer getWidthDecreasePerLevel() { return widthDecreasePerLevel; } public void setWidthDecreasePerLevel(Integer widthDecreasePerLevel) { this.widthDecreasePerLevel = widthDecreasePerLevel; } public String getTablesClasses() { return tablesClasses; } public void setTablesClasses(String tablesClasses) { this.tablesClasses = tablesClasses; } public String getGroupRowClasses() { return groupRowClasses; } public void setGroupRowClasses(String groupRowClasses) { this.groupRowClasses = groupRowClasses; } public String getCurricularCourseRowClasses() { return curricularCourseRowClasses; } public void setCurricularCourseRowClasses(String curricularCourseRowClasses) { this.curricularCourseRowClasses = curricularCourseRowClasses; } private String[] getGroupCellClasses() { return groupCellClasses.split(","); } public void setGroupCellClasses(String groupCellClasses) { this.groupCellClasses = groupCellClasses; } public String getGroupNameClasses() { return getGroupCellClasses()[0]; } public String getGroupRadioClasses() { return getGroupCellClasses()[1]; } private String[] getCurricularCourseCellClasses() { return curricularCourseCellClasses.split(","); } public void setCurricularCourseCellClasses(String curricularCourseCellClasses) { this.curricularCourseCellClasses = curricularCourseCellClasses; } public String getCurricularCourseNameClasses() { return getCurricularCourseCellClasses()[0]; } public String getCurricularCourseCheckBoxClasses() { return getCurricularCourseCellClasses()[1]; } public ISCTEStudentDismissalRenderer() { super(); } @Override protected Layout getLayout(Object object, Class type) { return new ISCTEStudentDismissalLayout(); } private class ISCTEStudentDismissalLayout extends Layout { private ISCTEDismissalBean bean = null; private HtmlRadioButtonGroup radioButtonGroup = null; @Override public HtmlComponent createComponent(Object object, Class type) { bean = (ISCTEDismissalBean) object; if (bean == null || bean.getExecutionPeriod() == null || bean.getStudentCurricularPlan().getStartExecutionPeriod().isAfter(bean.getExecutionPeriod())) { return new HtmlText(); } HtmlBlockContainer container = new HtmlBlockContainer(); DismissalType dismissalType = bean.getDismissalType(); if (dismissalType == DismissalType.CURRICULAR_COURSE_CREDITS) { HtmlLabel label = new HtmlLabel(); label.setFor(getInputContext().getMetaObject().getKey().toString()); label.setText(RenderUtils.getResourceString("ACADEMIC_OFFICE_RESOURCES", "label.dismissal.destiny")); container.addChild(label); HtmlMenu menu = new HtmlMenu(); menu.bind(getInputContext().getMetaObject(), "dismissalEntry"); menu.setConverter(new DomainObjectKeyConverter()); menu.setStyle("width: 450px;"); container.addChild(menu); menu.createDefaultOption(RenderUtils.getResourceString("renderers.menu.default.title")); for (ISCTEDismissalBean.SelectedDismissalEntry entry : getDataProviderData()) { MetaObject metaObject = MetaObjectFactory.createObject(entry, null); String text = RenderUtils.getFormattedProperties("${curricularCourse.code} - ${curricularCourse.name}", metaObject.getObject()); menu.createOption(text).setValue(metaObject.getKey().toString()); } } else if (dismissalType == DismissalType.CURRICULUM_GROUP_CREDITS) { radioButtonGroup = new HtmlRadioButtonGroup(); radioButtonGroup.bind(getInputContext().getMetaObject(), "courseGroup"); // slot // refered // by // name radioButtonGroup.setConverter(new DomainObjectKeyConverter()); container.addChild(radioButtonGroup); generateCourseGroupToApplyCredits(container, bean.getStudentCurricularPlan(), bean.getExecutionPeriod()); } else { radioButtonGroup = new HtmlRadioButtonGroup(); radioButtonGroup.bind(getInputContext().getMetaObject(), "curriculumGroup"); // slot // refered // by // name radioButtonGroup.setConverter(new DomainObjectKeyConverter()); container.addChild(radioButtonGroup); generateNoCourseGroupCurriculumGroups(container, bean.getStudentCurricularPlan()); } return container; } @SuppressWarnings("unchecked") private Collection getDataProviderData() { DataProvider provider = null; try { Class providerCass = (Class) Class.forName(DismissalDismissalsProvider.class .getName()); provider = (DataProvider) providerCass.newInstance(); } catch (Exception e) { new RuntimeException("exception while executing data provider", e); } Object source = getInputContext().getMetaObject().getObject(); return (Collection) provider.provide(source, null); } private void generateCourseGroupToApplyCredits(final HtmlBlockContainer blockContainer, final StudentCurricularPlan studentCurricularPlan, final ExecutionPeriod executionPeriod) { if (studentCurricularPlan.isBolonhaDegree()) { final Collection toCollect = studentCurricularPlan.getCourseGroupsToApplyDismissals(); for (final CourseGroup courseGroup : toCollect) { generateCourseGroups(blockContainer, studentCurricularPlan, courseGroup, executionPeriod, 0); } } else { generateCourseGroups(blockContainer, studentCurricularPlan, studentCurricularPlan.getRoot().getDegreeModule(), executionPeriod, 0); } } private void generateCourseGroups(final HtmlBlockContainer blockContainer, final StudentCurricularPlan studentCurricularPlan, final CourseGroup courseGroup, final ExecutionPeriod executionPeriod, int depth) { final HtmlTable groupTable = new HtmlTable(); blockContainer.addChild(groupTable); groupTable.setClasses(getTablesClasses()); groupTable.setStyle("width: " + (getInitialWidth() - depth) + "em; margin-left: " + depth + "em;"); final HtmlTableRow htmlTableRow = groupTable.createRow(); htmlTableRow.setClasses(getGroupRowClasses()); final HtmlTableCell nameCell = htmlTableRow.createCell(); nameCell.setBody(new HtmlText(courseGroup.getName())); nameCell.setClasses(getGroupNameClasses()); final HtmlTableCell currentCreditsCell = htmlTableRow.createCell(); final double ectsCreditsForCourseGroup = studentCurricularPlan.getCreditsConcludedForCourseGroup(courseGroup) .doubleValue(); if (ectsCreditsForCourseGroup == 0d) { currentCreditsCell.setBody(new HtmlText("ECTS: -")); } else { currentCreditsCell.setBody(new HtmlText("ECTS: " + ectsCreditsForCourseGroup)); } currentCreditsCell.setClasses("smalltxt"); currentCreditsCell.setStyle("width: 6em;"); final HtmlTableCell creditsMinCell = htmlTableRow.createCell(); creditsMinCell.setBody(new HtmlText("Min: " + courseGroup.getMinEctsCredits(executionPeriod))); creditsMinCell.setClasses("smalltxt"); creditsMinCell.setStyle("width: 6em;"); final HtmlTableCell creditsMaxCell = htmlTableRow.createCell(); creditsMaxCell.setBody(new HtmlText("Max: " + courseGroup.getMaxEctsCredits(executionPeriod))); creditsMaxCell.setClasses("smalltxt"); creditsMaxCell.setStyle("width: 6em;"); final HtmlTableCell radioButtonCell = htmlTableRow.createCell(); final HtmlRadioButton radioButton = radioButtonGroup.createRadioButton(); radioButton.setUserValue(MetaObjectFactory.createObject(courseGroup, new Schema(CourseGroup.class)).getKey() .toString()); radioButton.setChecked(courseGroup == bean.getCourseGroup()); radioButtonCell.setBody(radioButton); radioButtonCell.setClasses(getGroupRadioClasses()); radioButtonCell.setStyle("width: 2em;"); for (final Context context : courseGroup.getSortedOpenChildContextsWithCourseGroups(executionPeriod)) { generateCourseGroups(blockContainer, studentCurricularPlan, (CourseGroup) context.getChildDegreeModule(), executionPeriod, depth + getWidthDecreasePerLevel()); } } private CourseGroup getCourseGroupWithCycleType(final StudentCurricularPlan studentCurricularPlan, final CycleType cycleType) { final CycleCurriculumGroup curriculumGroup = studentCurricularPlan.getCycle(cycleType); return curriculumGroup != null ? curriculumGroup.getDegreeModule() : studentCurricularPlan.getDegreeCurricularPlan() .getCycleCourseGroup(cycleType); } private void generateNoCourseGroupCurriculumGroups(HtmlBlockContainer container, StudentCurricularPlan studentCurricularPlan) { for (NoCourseGroupCurriculumGroup noCourseGroupCurriculumGroup : studentCurricularPlan .getNoCourseGroupCurriculumGroups()) { generateNoCourseGroupCurriculumGroup(container, studentCurricularPlan, noCourseGroupCurriculumGroup, 0); } } private void generateNoCourseGroupCurriculumGroup(HtmlBlockContainer container, StudentCurricularPlan studentCurricularPlan, CurriculumGroup curriculumGroup, int depth) { final HtmlTable groupTable = new HtmlTable(); container.addChild(groupTable); groupTable.setClasses(getTablesClasses()); groupTable.setStyle("width: " + (getInitialWidth() - depth) + "em; margin-left: " + depth + "em;"); final HtmlTableRow htmlTableRow = groupTable.createRow(); htmlTableRow.setClasses(getGroupRowClasses()); final HtmlTableCell nameCell = htmlTableRow.createCell(); nameCell.setBody(new HtmlText(curriculumGroup.getFullPath())); nameCell.setClasses(getGroupNameClasses()); final HtmlTableCell radioButtonCell = htmlTableRow.createCell(); final HtmlRadioButton radioButton = radioButtonGroup.createRadioButton(); radioButton.setUserValue(MetaObjectFactory.createObject(curriculumGroup, new Schema(CurriculumGroup.class)).getKey() .toString()); radioButton.setChecked(curriculumGroup == bean.getCurriculumGroup()); radioButtonCell.setBody(radioButton); radioButtonCell.setClasses(getGroupRadioClasses()); radioButtonCell.setStyle("width: 2em;"); } } }