Example #1
0
  /**
   * If the onEventUpdate event is called. <br>
   * Handles the resizing or movement of an calendarEvent. Saves the new data to db.
   *
   * @param event
   */
  public void onEventUpdate$cal(CalendarsEvent evt) {

    // SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/d");
    // sdf1.setTimeZone(cal.getDefaultTimeZone());

    int left = evt.getX();
    int top = evt.getY();
    if (top + 100 > evt.getDesktopHeight()) top = evt.getDesktopHeight() - 100;
    if (left + 330 > evt.getDesktopWidth()) left = evt.getDesktopWidth() - 330;

    SimpleCalendarModel m = (SimpleCalendarModel) cal.getModel();
    MySimpleCalendarEvent sce = (MySimpleCalendarEvent) evt.getCalendarEvent();
    sce.setBeginDate(evt.getBeginDate());
    sce.setEndDate(evt.getEndDate());
    // update the model
    // m.update(sce); <-- if activated, later an error occurs

    // prepare the backend Bean
    MyCalendarEvent calEvt = getCalendarEventService().getNewCalendarEvent();
    calEvt.setId(sce.getId());
    calEvt.setSecUser(sce.getUser());
    calEvt.setVersion(sce.getVersion());
    calEvt.setTitle(sce.getTitle());
    calEvt.setContent(sce.getContent());
    calEvt.setBeginDate(sce.getBeginDate());
    calEvt.setEndDate(sce.getEndDate());
    calEvt.setHeaderColor(sce.getHeaderColor());
    calEvt.setContentColor(sce.getContentColor());
    // Save the calendar event to database
    try {
      getCalendarEventService().saveOrUpdate(calEvt);
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      synchronizeModel();
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Example #2
0
  public void synchronizeModel() throws ParseException {

    SimpleCalendarModel cm = null;
    MySimpleCalendarEvent sce = null;
    Date beginDate = cal.getBeginDate();
    Date endDate = cal.getEndDate();

    // first, delete old stuff
    cm = (SimpleCalendarModel) cal.getModel();

    if (cm != null) {
      cm.clear();
    }

    final SecUser user =
        ((UserImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
            .getSecUser();
    // List<MyCalendarEvent> list =
    // getCalendarEventService().getAllCalendarEvents(user.getId());
    List<MyCalendarEvent> list =
        getCalendarEventService().getCalendarEventsFromToDate(beginDate, endDate, user.getId());

    cm = new SimpleCalendarModel();

    for (MyCalendarEvent myCalendarEvent : list) {
      sce = new MySimpleCalendarEvent();
      sce.setId(myCalendarEvent.getId());
      sce.setUser(myCalendarEvent.getSecUser());
      sce.setVersion(myCalendarEvent.getVersion());
      sce.setBeginDate(myCalendarEvent.getBeginDate());
      sce.setContent(myCalendarEvent.getContent());
      sce.setContentColor(myCalendarEvent.getContentColor());
      sce.setEndDate(myCalendarEvent.getEndDate());
      sce.setHeaderColor(myCalendarEvent.getHeaderColor());
      sce.setLocked(myCalendarEvent.isLocked());
      sce.setTitle(myCalendarEvent.getTitle());

      cm.add(sce);
    }
    setCalModel(cm);

    cal.setModel(cm);
    cal.invalidate();
  }