@Override
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() instanceof WebComboBox) {

      if (((WebComboBox) e.getSource()).getActionCommand().equals("crewSelectedChanged")) {
        if (cmbCrew.getSelectedItem() instanceof Crew) {

          autoSave();

          currentCrew = (Crew) cmbCrew.getSelectedItem();

          if (currentCrew != null) {

            // calendar = null;
            // calendar = new ExWebCalendar(currentDate, currentCrew.getSignOnDate());

            calendar.refresh(currentCrew.getSignOnDate());

            errorReportEntry = new ErrorReportEntry();
            errorReportEntry.setEntryDate(getDate(currentDate));
            errorReportEntry.setCrew(currentCrew);
          }

          getSchedule(currentDate);
        }
      }

    } else {
      WebButton btnSource = (WebButton) e.getSource();

      if (btnSource.getClientProperty("command").equals("saveAndNext")) {

        if (currentCrew == null) {
          NotificationManager.showPopup(getOwner(), cmbCrew, new String[] {"Please select crew"});
          return;
        }

        // saveRestingHour();
        // calendar.moveToNext();
        // Calendar calNext = Calendar.getInstance();
        // calNext.setTime(currentDate);
        // calNext.add(Calendar.DAY_OF_MONTH, 1);

        // calendar.setDate(calNext.getTime());

      } else if (btnSource.getClientProperty("command").equals("new")) {

      } else if (btnSource.getClientProperty("command").equals("save")) {

        if (currentCrew == null) {
          NotificationManager.showPopup(getOwner(), cmbCrew, new String[] {"Please select crew"});
          return;
        }

        saveRestingHour();
      }
    }
  }
  @Override
  public void dateSelected(Date selectedDate) {

    autoSave();
    currentDate = selectedDate;

    if (currentCrew != null) {
      errorReportEntry = new ErrorReportEntry();
      errorReportEntry.setEntryDate(getDate(currentDate));
      errorReportEntry.setCrew(currentCrew);
    }

    getSchedule(selectedDate);
  }
  @Override
  public void changed(float totalRest, float totalWork) {
    txtHoursOfRest24Hrs.setText(Float.toString(totalRest));
    txtHoursOfWork24Hrs.setText(Float.toString(totalWork));

    Calendar cal = Calendar.getInstance();
    cal.setTime(currentDate);

    int month = cal.get(Calendar.MONTH);

    StringBuilder sb = new StringBuilder();
    sb.append("<html><ul>");

    if (currentCrew != null) {

      try {

        EntryTime time = new EntryTime();
        time.setSchedule(timeSheet.getSchedule());

        double totalWorkHours = 24 - time.getTotalRestHours();

        errorReportEntry = new ErrorReportEntry();
        errorReportEntry.setEntryDate(getDate(currentDate));
        errorReportEntry.setCrew(currentCrew);

        errorReportEntry.setRestIn24hours(time.getTotalRestHours());
        errorReportEntry.setWorkIn24hours(totalWorkHours);

        if (time.getTotalRestHours() < 10) {
          sb.append("<li>Total period of REST > 10 Hours</li>");

          errorReportEntry.setRestGreater10hrs(true);
        }

        if (totalWorkHours > 14) {
          sb.append("<li>Total period of WORK &lt; 14 Hours</li>");

          errorReportEntry.setWorkLess14hrs(true);
        }

        errorReport = new ErrorReport(currentCrew, null, month, cal.get(Calendar.YEAR));
        errorReport.generateReport();

        if (errorReport.getEntryTimeList().size() >= cal.get(Calendar.DAY_OF_MONTH) - 1) {
          errorReport
              .getEntryTimeList()
              .get(cal.get(Calendar.DAY_OF_MONTH) - 1)
              .setSchedule(timeSheet.getSchedule());
          errorReport.refresh();
        }

        if (errorReport.getContainMoreThan2RestPeriods(cal.get(Calendar.DAY_OF_MONTH)) == true) {
          sb.append("<li>Total number of REST periods are more than 2</li>");

          errorReportEntry.setTotalRestPeriods(
              errorReport.getRestPeriodCounter(cal.get(Calendar.DAY_OF_MONTH)));
        }

        if (!errorReport.contain6HourContinuousRest(cal.get(Calendar.DAY_OF_MONTH))) {
          sb.append("<li>At least one period of rest must be of 6 hours in length</li>");

          errorReportEntry.setOneRestPeriod6hrs(true);
        }

        double restHoursIn24Hours = errorReport.get24HourRestHours(cal.get(Calendar.DAY_OF_MONTH));
        if (restHoursIn24Hours < 10) {
          sb.append("<li>Any 24-hour Total Period of REST &gt; 10 Hours</li>");

          errorReportEntry.setAnyRest24hours(restHoursIn24Hours);

          errorReportEntry.setTotalRest24hrsGreater10hrs(true);
        }

        double restHoursIn7Days = errorReport.get7DayRestHours(cal.get(Calendar.DAY_OF_MONTH));
        if (restHoursIn7Days < 77) {
          sb.append("<li>Any 7-days Total Period of REST &gt; 77 Hours</li>");

          errorReportEntry.setRest7days(restHoursIn7Days);

          errorReportEntry.setTotalRest7daysGreater77hrs(true);
        }

        double last3DayTotalRestHours =
            errorReport.getLast3DayTotalRestHours(cal.get(Calendar.DAY_OF_MONTH));
        if (last3DayTotalRestHours < 36) {
          sb.append("<li>Rest hours in last 3 days are &lt; 36 Hours</li>");
        }
        errorReportEntry.setRestHour3daysGreater36hrs(last3DayTotalRestHours);

      } catch (Exception e) {
      }
    }

    sb.append("</ul></html>");

    lblNonConformities.setText(sb.toString());
    lblNonConformities.repaint();
  }