@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 boolean dropFeature(
      Long featureId,
      Long sessionId,
      org.hibernate.Session hibSession,
      SessionContext context,
      boolean future) {
    RoomFeature rf = lookupFeature(hibSession, featureId, future, sessionId);
    if (rf == null) {
      if (!future) throw new GwtRpcException(MESSAGES.errorRoomFeatureDoesNotExist(featureId));
      return false;
    }

    if (rf instanceof GlobalRoomFeature) context.checkPermission(rf, Right.GlobalRoomFeatureDelete);
    else context.checkPermission(rf, Right.DepartmenalRoomFeatureDelete);

    ChangeLog.addChange(
        hibSession,
        context,
        rf,
        ChangeLog.Source.ROOM_FEATURE_EDIT,
        ChangeLog.Operation.DELETE,
        null,
        rf instanceof DepartmentRoomFeature ? ((DepartmentRoomFeature) rf).getDepartment() : null);

    for (Location location : rf.getRooms()) {
      location.getFeatures().remove(rf);
      hibSession.saveOrUpdate(location);
    }

    for (RoomFeaturePref p :
        (List<RoomFeaturePref>)
            hibSession
                .createQuery("from RoomFeaturePref p where p.roomFeature.uniqueId = :id")
                .setLong("id", rf.getUniqueId())
                .list()) {
      p.getOwner().getPreferences().remove(p);
      hibSession.delete(p);
      hibSession.saveOrUpdate(p.getOwner());
    }

    hibSession.delete(rf);
    return true;
  }
  protected RoomFeature createOrUpdateFeature(
      FeatureInterface feature,
      List<Long> add,
      List<Long> drop,
      Long sessionId,
      org.hibernate.Session hibSession,
      SessionContext context,
      boolean future) {
    Department d =
        feature.isDepartmental()
            ? lookuDepartment(hibSession, feature.getDepartment(), future, sessionId)
            : null;
    if (feature.isDepartmental() && d == null) return null;

    RoomFeature rf =
        (feature.getId() == null ? null : lookupFeature(hibSession, feature, future, sessionId));

    if (rf == null) {
      if (!future && feature.getId() != null)
        throw new GwtRpcException(MESSAGES.errorRoomFeatureDoesNotExist(feature.getId()));
      if (d == null) {
        context.checkPermission(Right.GlobalRoomFeatureAdd);
        rf = new GlobalRoomFeature();
        ((GlobalRoomFeature) rf).setSession(SessionDAO.getInstance().get(sessionId));
      } else {
        context.checkPermission(d, Right.DepartmentRoomFeatureAdd);
        rf = new DepartmentRoomFeature();
        ((DepartmentRoomFeature) rf).setDepartment(d);
      }
      rf.setRooms(new HashSet<Location>());
    } else {
      if (rf instanceof GlobalRoomFeature) {
        context.checkPermission(rf, Right.GlobalRoomFeatureEdit);
      } else {
        context.checkPermission(rf, Right.DepartmenalRoomFeatureEdit);
        ((DepartmentRoomFeature) rf).setDepartment(d);
      }
    }

    for (Iterator i = RoomFeature.getAllGlobalRoomFeatures(sessionId).iterator(); i.hasNext(); ) {
      RoomFeature x = (RoomFeature) i.next();
      if ((x.getLabel().equalsIgnoreCase(feature.getLabel())
              || x.getAbbv().equalsIgnoreCase(feature.getAbbreviation()))
          && !x.getUniqueId().equals(rf.getUniqueId()))
        throw new GwtRpcException(
            MESSAGES.errorRoomFeatureAlreadyExists(
                feature.getLabel(), SessionDAO.getInstance().get(sessionId).getLabel()));
    }

    if (rf instanceof DepartmentRoomFeature) {
      for (Iterator i = RoomFeature.getAllDepartmentRoomFeatures(d).iterator(); i.hasNext(); ) {
        RoomFeature x = (RoomFeature) i.next();
        if ((x.getLabel().equalsIgnoreCase(feature.getLabel())
                || x.getAbbv().equalsIgnoreCase(feature.getAbbreviation()))
            && !x.getUniqueId().equals(rf.getUniqueId()))
          throw new GwtRpcException(
              MESSAGES.errorRoomFeatureAlreadyExists(
                  feature.getLabel(), d.getSession().getLabel()));
      }
    }

    rf.setAbbv(feature.getAbbreviation());
    rf.setLabel(feature.getLabel());
    rf.setFeatureType(
        feature.getType() == null
            ? null
            : RoomFeatureTypeDAO.getInstance().get(feature.getType().getId(), hibSession));

    hibSession.saveOrUpdate(rf);

    if (add != null && !add.isEmpty())
      for (Location location : lookupLocations(hibSession, add, future, sessionId)) {
        rf.getRooms().add(location);
        location.getFeatures().add(rf);
        hibSession.saveOrUpdate(location);
      }

    if (drop != null && !drop.isEmpty())
      for (Location location : lookupLocations(hibSession, drop, future, sessionId)) {
        rf.getRooms().remove(location);
        location.getFeatures().remove(rf);
        hibSession.saveOrUpdate(location);
      }

    hibSession.saveOrUpdate(rf);

    ChangeLog.addChange(
        hibSession,
        context,
        rf,
        ChangeLog.Source.ROOM_FEATURE_EDIT,
        (feature.getId() == null ? ChangeLog.Operation.CREATE : ChangeLog.Operation.UPDATE),
        null,
        rf instanceof DepartmentRoomFeature ? ((DepartmentRoomFeature) rf).getDepartment() : null);

    return rf;
  }
 @Override
 public PageName name() {
   return new PageName(
       MESSAGES.pageStudentSchedulingStatusType(), MESSAGES.pageStudentSchedulingStatusTypes());
 }