@Override
 @PreAuthorize("checkPermission('StudentSchedulingStatusTypeEdit')")
 public void save(Record record, SessionContext context, Session hibSession) {
   StudentSectioningStatus status = new StudentSectioningStatus();
   int value = 0;
   for (int i = 0; i < StatusOption.values().length; i++)
     if ("true".equals(record.getField(2 + i)))
       value += StatusOption.values()[i].getOption().toggle();
   status.setTypes(new HashSet<CourseType>());
   List<CourseType> courseTypes = CourseTypeDAO.getInstance().findAll(Order.asc("reference"));
   if (!courseTypes.isEmpty()) {
     for (int i = 0; i < courseTypes.size(); i++)
       if ("true".equals(record.getField(3 + StatusOption.values().length + i)))
         status.getTypes().add(courseTypes.get(i));
     if (!"true".equals(record.getField(3 + StatusOption.values().length + courseTypes.size())))
       value += StudentSectioningStatus.Option.notype.toggle();
   }
   status.setReference(record.getField(0));
   status.setLabel(record.getField(1));
   status.setStatus(value);
   status.setMessage(record.getField(2 + StatusOption.values().length));
   record.setUniqueId((Long) hibSession.save(status));
   ChangeLog.addChange(
       hibSession,
       context,
       status,
       status.getReference() + " " + status.getLabel(),
       Source.SIMPLE_EDIT,
       Operation.CREATE,
       null,
       null);
 }
 @Override
 @PreAuthorize("checkPermission('StudentSchedulingStatusTypes')")
 public SimpleEditInterface load(SessionContext context, Session hibSession) {
   List<CourseType> courseTypes = CourseTypeDAO.getInstance().findAll(Order.asc("reference"));
   SimpleEditInterface.Field[] fields =
       new SimpleEditInterface.Field
           [courseTypes.isEmpty()
               ? 3 + StatusOption.values().length
               : 4 + StatusOption.values().length + courseTypes.size()];
   int idx = 0;
   fields[idx++] = new Field(MESSAGES.fieldAbbreviation(), FieldType.text, 160, 20, Flag.UNIQUE);
   fields[idx++] = new Field(MESSAGES.fieldName(), FieldType.text, 300, 60, Flag.UNIQUE);
   for (StatusOption t : StatusOption.values())
     fields[idx++] = new Field(t.getLabel(), FieldType.toggle, 40);
   fields[idx++] = new Field(MESSAGES.fieldMessage(), FieldType.text, 400, 200);
   if (!courseTypes.isEmpty()) {
     for (int i = 0; i < courseTypes.size(); i++)
       fields[idx++] = new Field(courseTypes.get(i).getReference(), FieldType.toggle, 40);
     fields[idx++] = new Field(MESSAGES.toggleNoCourseType(), FieldType.toggle, 40);
   }
   SimpleEditInterface data = new SimpleEditInterface(fields);
   data.setSortBy(0, 1);
   for (StudentSectioningStatus status : StudentSectioningStatusDAO.getInstance().findAll()) {
     Record r = data.addRecord(status.getUniqueId());
     idx = 0;
     r.setField(idx++, status.getReference());
     r.setField(idx++, status.getLabel());
     for (StatusOption t : StatusOption.values())
       r.setField(idx++, status.hasOption(t.getOption()) ? "true" : "false");
     r.setField(idx++, status.getMessage());
     if (!courseTypes.isEmpty()) {
       for (int i = 0; i < courseTypes.size(); i++)
         r.setField(idx++, status.getTypes().contains(courseTypes.get(i)) ? "true" : "false");
       r.setField(
           idx++, status.hasOption(StudentSectioningStatus.Option.notype) ? "false" : "true");
     }
   }
   data.setEditable(context.hasPermission(Right.StudentSchedulingStatusTypeEdit));
   return data;
 }
 protected void update(
     StudentSectioningStatus status, Record record, SessionContext context, Session hibSession) {
   if (status == null) return;
   int value = 0;
   for (int i = 0; i < StatusOption.values().length; i++)
     if ("true".equals(record.getField(2 + i)))
       value += StatusOption.values()[i].getOption().toggle();
   Set<CourseType> types = new HashSet<CourseType>();
   List<CourseType> courseTypes = CourseTypeDAO.getInstance().findAll(Order.asc("reference"));
   if (!courseTypes.isEmpty()) {
     for (int i = 0; i < courseTypes.size(); i++)
       if ("true".equals(record.getField(3 + StatusOption.values().length + i)))
         types.add(courseTypes.get(i));
     if (!"true".equals(record.getField(3 + StatusOption.values().length + courseTypes.size())))
       value += StudentSectioningStatus.Option.notype.toggle();
   }
   boolean changed =
       !ToolBox.equals(status.getReference(), record.getField(0))
           || !ToolBox.equals(status.getLabel(), record.getField(1))
           || !ToolBox.equals(status.getStatus(), value)
           || !ToolBox.equals(status.getTypes(), types)
           || !ToolBox.equals(
               status.getMessage(), record.getField(2 + StatusOption.values().length));
   status.setReference(record.getField(0));
   status.setLabel(record.getField(1));
   status.setStatus(value);
   status.setTypes(types);
   status.setMessage(record.getField(2 + StatusOption.values().length));
   hibSession.saveOrUpdate(status);
   if (changed)
     ChangeLog.addChange(
         hibSession,
         context,
         status,
         status.getReference() + " " + status.getLabel(),
         Source.SIMPLE_EDIT,
         Operation.UPDATE,
         null,
         null);
 }