Esempio n. 1
0
 /*
  * (non-Javadoc)
  *
  * @see
  * com.vaadin.addon.calendar.event.CalendarEditableEventProvider#addEvent
  * (com.vaadin.addon.calendar.event.CalendarEvent)
  */
 @Override
 public void addEvent(CalendarEvent event) {
   Item item;
   try {
     item = container.addItem(event);
   } catch (UnsupportedOperationException uop) {
     // Thrown if container does not support adding items with custom
     // ids. JPAContainer for example.
     item = container.getItem(container.addItem());
   }
   if (item != null) {
     item.getItemProperty(getCaptionProperty()).setValue(event.getCaption());
     item.getItemProperty(getStartDateProperty()).setValue(event.getStart());
     item.getItemProperty(getEndDateProperty()).setValue(event.getEnd());
     item.getItemProperty(getStyleNameProperty()).setValue(event.getStyleName());
     item.getItemProperty(getDescriptionProperty()).setValue(event.getDescription());
   }
 }
Esempio n. 2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * com.vaadin.addon.calendar.ui.CalendarComponentEvents.EventMoveHandler
   * #eventMove
   * (com.vaadin.addon.calendar.ui.CalendarComponentEvents.MoveEvent)
   */
  @Override
  public void eventMove(MoveEvent event) {
    CalendarEvent ce = event.getCalendarEvent();
    if (eventCache.contains(ce)) {
      int index;
      if (ce instanceof ContainerCalendarEvent) {
        index = ((ContainerCalendarEvent) ce).getContainerIndex();
      } else {
        index = container.indexOfId(ce);
      }

      long eventLength = ce.getEnd().getTime() - ce.getStart().getTime();
      Date newEnd = new Date(event.getNewStart().getTime() + eventLength);

      ignoreContainerEvents();
      Item item = container.getItem(container.getIdByIndex(index));
      item.getItemProperty(startDateProperty).setValue(event.getNewStart());
      item.getItemProperty(endDateProperty).setValue(newEnd);
      listenToContainerEvents();
    }
  }